summaryrefslogtreecommitdiff
path: root/devtools/bin/vtf_flags_convert.pl
blob: 033e58acac1b3279d628a203556ad07ee414259f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#
#   Arguments parsing
#

local $script = $0;

while ( 1 )
{
	local $arg = shift;
	if ( $arg =~ /^-patch$/i )
		{	goto RUN_PATCH;	}
	if ( $arg =~ /^-patchall$/i )
		{	goto RUN_PATCH_ALL;	}

	# default mode - forward to -patch:
	exit system( "dir /s /b *.vtf | perl $script -patchall" );
}




RUN_PATCH_ALL:
#
#   -----------  Patch a list of VTF files --------
#

while ( <> )
{
	local $line = $_;
	$line =~ s/^\s*(.*)\s*$/$1/;
	PatchVtfFile( $line );
}
exit 0;


RUN_PATCH:
#
#   -----------  Patch a VTF file --------
#

local $filename = shift;
exit PatchVtfFile( $filename );

sub PatchVtfFile
{

local *fileptr;
local $filename = shift;
local $vtfFlags;

print "$filename ... ";
`p4 edit "$filename" >nul 2>&1`;

if ( !open( fileptr, "+<$filename" ) )
{
	print "ERROR!\n";
	return 1;
}
binmode( fileptr );

seek( fileptr, 5 * 4, 0 );
read( fileptr, $vtfFlags, 4 );
$vtfFlags = unpack( "I", $vtfFlags );

# dropping the NOCOMPRESS flag that will be used for SRGB
# dropping all the removed flags too
$vtfFlags = $vtfFlags & 0x2E87FFBF; # mask and

seek( fileptr, 5 * 4, 0 );
print fileptr pack( "I", $vtfFlags );

close( fileptr );

print "ok.\n";
return 0;

}