Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

179 lines
3.6 KiB

  1. BEGIN {use File::Basename; push @INC, dirname($0); }
  2. require "valve_perl_helpers.pl";
  3. use Cwd;
  4. use String::CRC32;
  5. sub ReadInputFileWithIncludes
  6. {
  7. local( $filename ) = shift;
  8. local( *INPUT );
  9. local( $output );
  10. open INPUT, "<$filename" || die;
  11. local( $line );
  12. local( $linenum ) = 1;
  13. while( $line = <INPUT> )
  14. {
  15. if( $line =~ m/\#include\s+\"(.*)\"/i )
  16. {
  17. $output.= ReadInputFileWithIncludes( $1 );
  18. }
  19. else
  20. {
  21. $output .= $line;
  22. }
  23. }
  24. close INPUT;
  25. return $output;
  26. }
  27. sub PatchCRC
  28. {
  29. my $filename = shift;
  30. my $crc = shift;
  31. # print STDERR "*** PatchCRC( $filename, $crc )\n";
  32. local( *FP );
  33. open FP, "+<$filename" || die;
  34. binmode( FP );
  35. seek FP, 6 * 4, 0;
  36. my $uInt = "I";
  37. if ( ( $filename =~ m/\.ps3\./ ) || ( $filename =~ m/\.360\./ ) )
  38. {
  39. # print STDERR "*** PatchCRC found ps3 or 360\n";
  40. $uInt = "N";
  41. }
  42. print FP pack $uInt, $crc;
  43. close FP;
  44. }
  45. my $txtfilename = shift;
  46. my $arg = shift;
  47. my $is360 = 0;
  48. my $isPS3 = 0;
  49. my $platformextension = "";
  50. if( $arg =~ m/-x360/i )
  51. {
  52. $is360 = 1;
  53. $platformextension = ".360";
  54. }
  55. elsif( $arg =~ m/-ps3/i )
  56. {
  57. $isPS3 = 1;
  58. $platformextension = ".ps3";
  59. }
  60. # Get the changelist number for the Shader Auto Checkout changelist. Will create the changelist if it doesn't exist.
  61. my $changelistnumber = `valve_p4_create_changelist.cmd ..\\..\\..\\game\\platform\\shaders \"Shader Auto Checkout VCS\"`;
  62. # Get rid of the newline
  63. $changelistnumber =~ s/\n//g;
  64. my $changelistarg = "";
  65. if( $changelistnumber != 0 )
  66. {
  67. $changelistarg = "-c $changelistnumber"
  68. }
  69. open TXTFILE, "<$txtfilename";
  70. my $src;
  71. my $dst;
  72. while( $src = <TXTFILE> )
  73. {
  74. # get rid of comments
  75. $src =~ s,//.*,,g;
  76. # skip blank lines
  77. if( $src =~ m/^\s*$/ )
  78. {
  79. next;
  80. }
  81. # Get rid of newlines.
  82. $src =~ s/\n//g;
  83. # Save off the shader source filename.
  84. my $shadersrcfilename = $src;
  85. $shadersrcfilename =~ s/-----.*$//;
  86. # use only target basename.
  87. $src =~ s/^.*-----//;
  88. # where the binary vcs file is
  89. my $spath = "";
  90. if ( $shadersrcfilename =~ m@\.fxc@i )
  91. {
  92. $spath = "shaders\\fxc\\";
  93. }
  94. if ( $shadersrcfilename =~ m@\.vsh@i )
  95. {
  96. $spath = "shaders\\vsh\\";
  97. }
  98. if ( $shadersrcfilename =~ m@\.psh@i )
  99. {
  100. $spath = "shaders\\psh\\";
  101. }
  102. # make the source have path and extension
  103. $src = $spath . $src . $platformextension . ".vcs";
  104. # build the dest filename.
  105. $dst = $src;
  106. $dst =~ s/shaders\\/..\\..\\..\\game\\platform\\shaders\\/i;
  107. # Does the dst exist?
  108. my $dstexists = -e $dst;
  109. my $srcexists = -e $src;
  110. # What are the time stamps for the src and dst?
  111. my $srcmodtime = ( stat $src )[9];
  112. my $dstmodtime = ( stat $dst )[9];
  113. # Write $dst to a file so that we can do perforce stuff to it later.
  114. local( *VCSLIST );
  115. open VCSLIST, ">>vcslist.txt" || die;
  116. print VCSLIST $dst . "\n";
  117. close VCSLIST;
  118. # Open for edit or add if different than what is in perforce already.
  119. if( !$dstexists || ( $srcmodtime != $dstmodtime ) )
  120. {
  121. if ( $srcexists && $shadersrcfilename =~ m@\.fxc@i )
  122. {
  123. # Get the CRC for the source file.
  124. my $srccode = ReadInputFileWithIncludes( $shadersrcfilename );
  125. my $crc = crc32( $srccode );
  126. # Patch the source VCS file with the CRC32 of the source code used to build that file.
  127. PatchCRC( $src, $crc );
  128. }
  129. # Make the target vcs writable if it exists
  130. if( $dstexists )
  131. {
  132. MakeFileWritable( $dst );
  133. }
  134. my $dir = $dst;
  135. $dir =~ s,([^/\\]*$),,; # rip the filename off the end
  136. my $filename = $1;
  137. # create the target directory if it doesn't exist
  138. if( !$dstexists )
  139. {
  140. &MakeDirHier( $dir, 0777 );
  141. }
  142. # copy the file to its targets. . . we want to see STDERR here if there is an error.
  143. my $cmd = "copy $src $dst > nul";
  144. # print STDERR "$cmd\n";
  145. system $cmd;
  146. MakeFileReadOnly( $dst );
  147. }
  148. }
  149. close TXTFILE;