Skip to content

Commit d58490f

Browse files
committed
split fixaas stuff from q3map2
1 parent cd07f71 commit d58490f

File tree

6 files changed

+132
-81
lines changed

6 files changed

+132
-81
lines changed

tools/quake3/q3map2/fixaas.c

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/* -------------------------------------------------------------------------------
2+
3+
Copyright (C) 1999-2007 id Software, Inc. and contributors.
4+
For a list of contributors, see the accompanying CONTRIBUTORS file.
5+
6+
This file is part of GtkRadiant.
7+
8+
GtkRadiant is free software; you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License as published by
10+
the Free Software Foundation; either version 2 of the License, or
11+
(at your option) any later version.
12+
13+
GtkRadiant is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Public License for more details.
17+
18+
You should have received a copy of the GNU General Public License
19+
along with GtkRadiant; if not, write to the Free Software
20+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21+
22+
-------------------------------------------------------------------------------
23+
24+
This code has been altered significantly from its original form, to support
25+
several games based on the Quake III Arena engine, in the form of "Q3Map2."
26+
27+
------------------------------------------------------------------------------- */
28+
29+
30+
31+
/* dependencies */
32+
#include "q3map2.h"
33+
34+
35+
36+
/*
37+
MD4BlockChecksum()
38+
calculates an md4 checksum for a block of data
39+
*/
40+
41+
static int MD4BlockChecksum( void * buffer, int length ) {
42+
unsigned char digest[16];
43+
int checksum;
44+
45+
md4_get_digest( buffer, length, digest );
46+
/* I suppose it has to be done that way for legacy reasons? */
47+
checksum = digest[0] & ( digest[1] << 8 ) & ( digest[2] << 16 ) & ( digest[3] << 24 );
48+
checksum ^= digest[4] & ( digest[5] << 8 ) & ( digest[6] << 16 ) & ( digest[7] << 24 );
49+
checksum ^= digest[8] & ( digest[9] << 8 ) & ( digest[10] << 16 ) & ( digest[11] << 24 );
50+
checksum ^= digest[12] & ( digest[13] << 8 ) & ( digest[14] << 16 ) & ( digest[15] << 24 );
51+
return checksum;
52+
}
53+
54+
/*
55+
FixAASMain()
56+
resets an aas checksum to match the given BSP
57+
*/
58+
59+
int FixAASMain( int argc, char **argv ){
60+
int length, checksum;
61+
void *buffer;
62+
FILE *file;
63+
char aas[ 1024 ], **ext;
64+
char *exts[] =
65+
{
66+
".aas",
67+
"_b0.aas",
68+
"_b1.aas",
69+
NULL
70+
};
71+
72+
73+
/* arg checking */
74+
if ( argc < 2 ) {
75+
Sys_Printf( "Usage: q3map -fixaas [-v] <mapname>\n" );
76+
return 0;
77+
}
78+
79+
/* do some path mangling */
80+
strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
81+
StripExtension( source );
82+
DefaultExtension( source, ".bsp" );
83+
84+
/* note it */
85+
Sys_Printf( "--- FixAAS ---\n" );
86+
87+
/* load the bsp */
88+
Sys_Printf( "Loading %s\n", source );
89+
length = LoadFile( source, &buffer );
90+
91+
/* create bsp checksum */
92+
Sys_Printf( "Creating checksum...\n" );
93+
checksum = LittleLong( MD4BlockChecksum( buffer, length ) );
94+
95+
/* write checksum to aas */
96+
ext = exts;
97+
while ( *ext )
98+
{
99+
/* mangle name */
100+
strcpy( aas, source );
101+
StripExtension( aas );
102+
strcat( aas, *ext );
103+
Sys_Printf( "Trying %s\n", aas );
104+
ext++;
105+
106+
/* fix it */
107+
file = fopen( aas, "r+b" );
108+
if ( !file ) {
109+
continue;
110+
}
111+
if ( fwrite( &checksum, 4, 1, file ) != 1 ) {
112+
Error( "Error writing checksum to %s", aas );
113+
}
114+
fclose( file );
115+
}
116+
117+
/* return to sender */
118+
return 0;
119+
}

tools/quake3/q3map2/main.c

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -91,86 +91,6 @@ static void ExitQ3Map( void ){
9191
}
9292
}
9393

94-
static int MD4BlockChecksum( void * buffer, int length ) {
95-
unsigned char digest[16];
96-
int checksum;
97-
98-
md4_get_digest( buffer, length, digest );
99-
/* I suppose it has to be done that way for legacy reasons? */
100-
checksum = digest[0] & ( digest[1] << 8 ) & ( digest[2] << 16 ) & ( digest[3] << 24 );
101-
checksum ^= digest[4] & ( digest[5] << 8 ) & ( digest[6] << 16 ) & ( digest[7] << 24 );
102-
checksum ^= digest[8] & ( digest[9] << 8 ) & ( digest[10] << 16 ) & ( digest[11] << 24 );
103-
checksum ^= digest[12] & ( digest[13] << 8 ) & ( digest[14] << 16 ) & ( digest[15] << 24 );
104-
return checksum;
105-
}
106-
107-
/*
108-
FixAAS()
109-
resets an aas checksum to match the given BSP
110-
*/
111-
112-
int FixAAS( int argc, char **argv ){
113-
int length, checksum;
114-
void *buffer;
115-
FILE *file;
116-
char aas[ 1024 ], **ext;
117-
char *exts[] =
118-
{
119-
".aas",
120-
"_b0.aas",
121-
"_b1.aas",
122-
NULL
123-
};
124-
125-
126-
/* arg checking */
127-
if ( argc < 2 ) {
128-
Sys_Printf( "Usage: q3map -fixaas [-v] <mapname>\n" );
129-
return 0;
130-
}
131-
132-
/* do some path mangling */
133-
strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
134-
StripExtension( source );
135-
DefaultExtension( source, ".bsp" );
136-
137-
/* note it */
138-
Sys_Printf( "--- FixAAS ---\n" );
139-
140-
/* load the bsp */
141-
Sys_Printf( "Loading %s\n", source );
142-
length = LoadFile( source, &buffer );
143-
144-
/* create bsp checksum */
145-
Sys_Printf( "Creating checksum...\n" );
146-
checksum = LittleLong( MD4BlockChecksum( buffer, length ) );
147-
148-
/* write checksum to aas */
149-
ext = exts;
150-
while ( *ext )
151-
{
152-
/* mangle name */
153-
strcpy( aas, source );
154-
StripExtension( aas );
155-
strcat( aas, *ext );
156-
Sys_Printf( "Trying %s\n", aas );
157-
ext++;
158-
159-
/* fix it */
160-
file = fopen( aas, "r+b" );
161-
if ( !file ) {
162-
continue;
163-
}
164-
if ( fwrite( &checksum, 4, 1, file ) != 1 ) {
165-
Error( "Error writing checksum to %s", aas );
166-
}
167-
fclose( file );
168-
}
169-
170-
/* return to sender */
171-
return 0;
172-
}
173-
17494

17595
/*
17696
main()
@@ -273,7 +193,7 @@ int main( int argc, char **argv ){
273193

274194
/* fixaas */
275195
if ( !strcmp( argv[ 1 ], "-fixaas" ) ) {
276-
r = FixAAS( argc - 1, argv + 1 );
196+
r = FixAASMain( argc - 1, argv + 1 );
277197
}
278198

279199
/* analyze */

tools/quake3/q3map2/q3map2.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,10 @@ game_t *GetGame( char *arg );
14711471
void InitPaths( int *argc, char **argv );
14721472

14731473

1474+
/* fixaas.c */
1475+
int FixAASMain( int argc, char **argv );
1476+
1477+
14741478
/* bsp.c */
14751479
int BSPMain( int argc, char **argv );
14761480

tools/quake3/q3map2/q3map2.vcproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@
242242
RelativePath=".\facebsp.c"
243243
>
244244
</File>
245+
<File
246+
RelativePath=".\fixaas.c"
247+
>
248+
</File>
245249
<File
246250
RelativePath=".\fog.c"
247251
>

tools/quake3/q3map2/q3map2.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
<ClCompile Include="bsp_info.c" />
180180
<ClCompile Include="decals.c" />
181181
<ClCompile Include="facebsp.c" />
182+
<ClCompile Include="fixaas.c" />
182183
<ClCompile Include="fog.c" />
183184
<ClCompile Include="leakfile.c" />
184185
<ClCompile Include="map.c" />

tools/quake3/q3map2/q3map2.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
<ClCompile Include="facebsp.c">
6666
<Filter>src</Filter>
6767
</ClCompile>
68+
<ClCompile Include="fixaas.c">
69+
<Filter>src</Filter>
70+
</ClCompile>
6871
<ClCompile Include="fog.c">
6972
<Filter>src</Filter>
7073
</ClCompile>

0 commit comments

Comments
 (0)