From d58490f20bc4b1455312f8f22e48cf9a62dc187e Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 12 Feb 2016 20:31:15 +0100 Subject: [PATCH] split fixaas stuff from q3map2 --- tools/quake3/q3map2/fixaas.c | 119 +++++++++++++++++++++ tools/quake3/q3map2/main.c | 82 +------------- tools/quake3/q3map2/q3map2.h | 4 + tools/quake3/q3map2/q3map2.vcproj | 4 + tools/quake3/q3map2/q3map2.vcxproj | 1 + tools/quake3/q3map2/q3map2.vcxproj.filters | 3 + 6 files changed, 132 insertions(+), 81 deletions(-) create mode 100644 tools/quake3/q3map2/fixaas.c diff --git a/tools/quake3/q3map2/fixaas.c b/tools/quake3/q3map2/fixaas.c new file mode 100644 index 00000000..fc4eb94b --- /dev/null +++ b/tools/quake3/q3map2/fixaas.c @@ -0,0 +1,119 @@ +/* ------------------------------------------------------------------------------- + + Copyright (C) 1999-2007 id Software, Inc. and contributors. + For a list of contributors, see the accompanying CONTRIBUTORS file. + + This file is part of GtkRadiant. + + GtkRadiant is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + GtkRadiant is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GtkRadiant; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + ------------------------------------------------------------------------------- + + This code has been altered significantly from its original form, to support + several games based on the Quake III Arena engine, in the form of "Q3Map2." + + ------------------------------------------------------------------------------- */ + + + +/* dependencies */ +#include "q3map2.h" + + + +/* + MD4BlockChecksum() + calculates an md4 checksum for a block of data + */ + +static int MD4BlockChecksum( void * buffer, int length ) { + unsigned char digest[16]; + int checksum; + + md4_get_digest( buffer, length, digest ); + /* I suppose it has to be done that way for legacy reasons? */ + checksum = digest[0] & ( digest[1] << 8 ) & ( digest[2] << 16 ) & ( digest[3] << 24 ); + checksum ^= digest[4] & ( digest[5] << 8 ) & ( digest[6] << 16 ) & ( digest[7] << 24 ); + checksum ^= digest[8] & ( digest[9] << 8 ) & ( digest[10] << 16 ) & ( digest[11] << 24 ); + checksum ^= digest[12] & ( digest[13] << 8 ) & ( digest[14] << 16 ) & ( digest[15] << 24 ); + return checksum; +} + +/* + FixAASMain() + resets an aas checksum to match the given BSP + */ + +int FixAASMain( int argc, char **argv ){ + int length, checksum; + void *buffer; + FILE *file; + char aas[ 1024 ], **ext; + char *exts[] = + { + ".aas", + "_b0.aas", + "_b1.aas", + NULL + }; + + + /* arg checking */ + if ( argc < 2 ) { + Sys_Printf( "Usage: q3map -fixaas [-v] \n" ); + return 0; + } + + /* do some path mangling */ + strcpy( source, ExpandArg( argv[ argc - 1 ] ) ); + StripExtension( source ); + DefaultExtension( source, ".bsp" ); + + /* note it */ + Sys_Printf( "--- FixAAS ---\n" ); + + /* load the bsp */ + Sys_Printf( "Loading %s\n", source ); + length = LoadFile( source, &buffer ); + + /* create bsp checksum */ + Sys_Printf( "Creating checksum...\n" ); + checksum = LittleLong( MD4BlockChecksum( buffer, length ) ); + + /* write checksum to aas */ + ext = exts; + while ( *ext ) + { + /* mangle name */ + strcpy( aas, source ); + StripExtension( aas ); + strcat( aas, *ext ); + Sys_Printf( "Trying %s\n", aas ); + ext++; + + /* fix it */ + file = fopen( aas, "r+b" ); + if ( !file ) { + continue; + } + if ( fwrite( &checksum, 4, 1, file ) != 1 ) { + Error( "Error writing checksum to %s", aas ); + } + fclose( file ); + } + + /* return to sender */ + return 0; +} diff --git a/tools/quake3/q3map2/main.c b/tools/quake3/q3map2/main.c index d172059b..1729773e 100644 --- a/tools/quake3/q3map2/main.c +++ b/tools/quake3/q3map2/main.c @@ -91,86 +91,6 @@ static void ExitQ3Map( void ){ } } -static int MD4BlockChecksum( void * buffer, int length ) { - unsigned char digest[16]; - int checksum; - - md4_get_digest( buffer, length, digest ); - /* I suppose it has to be done that way for legacy reasons? */ - checksum = digest[0] & ( digest[1] << 8 ) & ( digest[2] << 16 ) & ( digest[3] << 24 ); - checksum ^= digest[4] & ( digest[5] << 8 ) & ( digest[6] << 16 ) & ( digest[7] << 24 ); - checksum ^= digest[8] & ( digest[9] << 8 ) & ( digest[10] << 16 ) & ( digest[11] << 24 ); - checksum ^= digest[12] & ( digest[13] << 8 ) & ( digest[14] << 16 ) & ( digest[15] << 24 ); - return checksum; -} - -/* - FixAAS() - resets an aas checksum to match the given BSP - */ - -int FixAAS( int argc, char **argv ){ - int length, checksum; - void *buffer; - FILE *file; - char aas[ 1024 ], **ext; - char *exts[] = - { - ".aas", - "_b0.aas", - "_b1.aas", - NULL - }; - - - /* arg checking */ - if ( argc < 2 ) { - Sys_Printf( "Usage: q3map -fixaas [-v] \n" ); - return 0; - } - - /* do some path mangling */ - strcpy( source, ExpandArg( argv[ argc - 1 ] ) ); - StripExtension( source ); - DefaultExtension( source, ".bsp" ); - - /* note it */ - Sys_Printf( "--- FixAAS ---\n" ); - - /* load the bsp */ - Sys_Printf( "Loading %s\n", source ); - length = LoadFile( source, &buffer ); - - /* create bsp checksum */ - Sys_Printf( "Creating checksum...\n" ); - checksum = LittleLong( MD4BlockChecksum( buffer, length ) ); - - /* write checksum to aas */ - ext = exts; - while ( *ext ) - { - /* mangle name */ - strcpy( aas, source ); - StripExtension( aas ); - strcat( aas, *ext ); - Sys_Printf( "Trying %s\n", aas ); - ext++; - - /* fix it */ - file = fopen( aas, "r+b" ); - if ( !file ) { - continue; - } - if ( fwrite( &checksum, 4, 1, file ) != 1 ) { - Error( "Error writing checksum to %s", aas ); - } - fclose( file ); - } - - /* return to sender */ - return 0; -} - /* main() @@ -273,7 +193,7 @@ int main( int argc, char **argv ){ /* fixaas */ if ( !strcmp( argv[ 1 ], "-fixaas" ) ) { - r = FixAAS( argc - 1, argv + 1 ); + r = FixAASMain( argc - 1, argv + 1 ); } /* analyze */ diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 45e42f07..39959228 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -1471,6 +1471,10 @@ game_t *GetGame( char *arg ); void InitPaths( int *argc, char **argv ); +/* fixaas.c */ +int FixAASMain( int argc, char **argv ); + + /* bsp.c */ int BSPMain( int argc, char **argv ); diff --git a/tools/quake3/q3map2/q3map2.vcproj b/tools/quake3/q3map2/q3map2.vcproj index 23844596..b71a4459 100644 --- a/tools/quake3/q3map2/q3map2.vcproj +++ b/tools/quake3/q3map2/q3map2.vcproj @@ -242,6 +242,10 @@ RelativePath=".\facebsp.c" > + + diff --git a/tools/quake3/q3map2/q3map2.vcxproj b/tools/quake3/q3map2/q3map2.vcxproj index fa811221..b383b74f 100644 --- a/tools/quake3/q3map2/q3map2.vcxproj +++ b/tools/quake3/q3map2/q3map2.vcxproj @@ -179,6 +179,7 @@ + diff --git a/tools/quake3/q3map2/q3map2.vcxproj.filters b/tools/quake3/q3map2/q3map2.vcxproj.filters index 4c77bc67..b98e973f 100644 --- a/tools/quake3/q3map2/q3map2.vcxproj.filters +++ b/tools/quake3/q3map2/q3map2.vcxproj.filters @@ -65,6 +65,9 @@ src + + src + src