Debian Codegraph @

tools/quake3/q3map2/fixaas.c

raw symbols SCIP
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 return Com_BlockChecksum( buffer, length );
43 }
44
45 /*
46 FixAASMain()
47 resets an aas checksum to match the given BSP
48 */
49
50 int FixAASMain( int argc, char **argv ){
51 int length, checksum;
52 void *buffer;
53 FILE *file;
54 char aas[ 1024 ], **ext;
55 char *exts[] =
56 {
57 ".aas",
58 "_b0.aas",
59 "_b1.aas",
60 NULL
61 };
62
63
64 /* arg checking */
65 if ( argc < 2 ) {
66 Sys_Printf( "Usage: q3map -fixaas [-v] <mapname>\n" );
67 return 0;
68 }
69
70 /* do some path mangling */
71 strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
72 StripExtension( source );
73 DefaultExtension( source, ".bsp" );
74
75 /* note it */
76 Sys_Printf( "--- FixAAS ---\n" );
77
78 /* load the bsp */
79 Sys_Printf( "Loading %s\n", source );
80 length = LoadFile( source, &buffer );
81
82 /* create bsp checksum */
83 Sys_Printf( "Creating checksum...\n" );
84 checksum = LittleLong( MD4BlockChecksum( buffer, length ) );
85
86 /* write checksum to aas */
87 ext = exts;
88 while ( *ext )
89 {
90 /* mangle name */
91 strcpy( aas, source );
92 StripExtension( aas );
93 strcat( aas, *ext );
94 Sys_Printf( "Trying %s\n", aas );
95 ext++;
96
97 /* fix it */
98 file = fopen( aas, "r+b" );
99 if ( !file ) {
100 continue;
101 }
102 if ( fwrite( &checksum, 4, 1, file ) != 1 ) {
103 Error( "Error writing checksum to %s", aas );
104 }
105 fclose( file );
106 }
107
108 /* return to sender */
109 return 0;
110 }