Team Fortress 2 Source Code as on 22/4/2020
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.

80 lines
1.1 KiB

  1. #
  2. # Arguments parsing
  3. #
  4. local $script = $0;
  5. while ( 1 )
  6. {
  7. local $arg = shift;
  8. if ( $arg =~ /^-patch$/i )
  9. { goto RUN_PATCH; }
  10. if ( $arg =~ /^-patchall$/i )
  11. { goto RUN_PATCH_ALL; }
  12. # default mode - forward to -patch:
  13. exit system( "dir /s /b *.vtf | perl $script -patchall" );
  14. }
  15. RUN_PATCH_ALL:
  16. #
  17. # ----------- Patch a list of VTF files --------
  18. #
  19. while ( <> )
  20. {
  21. local $line = $_;
  22. $line =~ s/^\s*(.*)\s*$/$1/;
  23. PatchVtfFile( $line );
  24. }
  25. exit 0;
  26. RUN_PATCH:
  27. #
  28. # ----------- Patch a VTF file --------
  29. #
  30. local $filename = shift;
  31. exit PatchVtfFile( $filename );
  32. sub PatchVtfFile
  33. {
  34. local *fileptr;
  35. local $filename = shift;
  36. local $vtfFlags;
  37. print "$filename ... ";
  38. `p4 edit "$filename" >nul 2>&1`;
  39. if ( !open( fileptr, "+<$filename" ) )
  40. {
  41. print "ERROR!\n";
  42. return 1;
  43. }
  44. binmode( fileptr );
  45. seek( fileptr, 5 * 4, 0 );
  46. read( fileptr, $vtfFlags, 4 );
  47. $vtfFlags = unpack( "I", $vtfFlags );
  48. # dropping the NOCOMPRESS flag that will be used for SRGB
  49. # dropping all the removed flags too
  50. $vtfFlags = $vtfFlags & 0x2E87FFBF; # mask and
  51. seek( fileptr, 5 * 4, 0 );
  52. print fileptr pack( "I", $vtfFlags );
  53. close( fileptr );
  54. print "ok.\n";
  55. return 0;
  56. }