From 5384ed54db660638430663ecde8b954bf29adb9a Mon Sep 17 00:00:00 2001 From: uis Date: Fri, 16 Aug 2024 05:23:58 +0300 Subject: [PATCH] tools: deduplicate common files between q2, h2 and q3 Another cosmetical change --- tools/heretic2/common/her2_threads.h | 36 +-- tools/heretic2/common/inout.h | 65 +----- tools/heretic2/common/md4.c | 220 +------------------ tools/heretic2/common/md4.h | 57 +---- tools/quake2/common/inout.h | 65 +----- tools/quake2/common/l3dslib.c | 312 +------------------------- tools/quake2/common/l3dslib.h | 25 +-- tools/quake2/common/md4.c | 220 +------------------ tools/quake2/common/md4.h | 57 +---- tools/quake2/common/q2_threads.h | 35 +-- tools/quake3/common/cmdlib.h | 1 - tools/quake3/common/inout.h | 65 +----- tools/quake3/common/l3dslib.c | 313 +-------------------------- tools/quake3/common/l3dslib.h | 26 +-- tools/quake3/common/md4.c | 220 +------------------ tools/quake3/common/md4.h | 57 +---- tools/quake3/common/qthreads.h | 31 +-- tools/shared/common/inout.h | 65 ++++++ tools/shared/common/l3dslib.c | 312 ++++++++++++++++++++++++++ tools/shared/common/l3dslib.h | 25 +++ tools/shared/common/md4.c | 219 +++++++++++++++++++ tools/shared/common/md4.h | 56 +++++ tools/shared/common/qthreads.h | 34 +++ 23 files changed, 727 insertions(+), 1789 deletions(-) mode change 100644 => 120000 tools/heretic2/common/her2_threads.h mode change 100644 => 120000 tools/heretic2/common/inout.h mode change 100644 => 120000 tools/heretic2/common/md4.c mode change 100644 => 120000 tools/heretic2/common/md4.h mode change 100644 => 120000 tools/quake2/common/inout.h mode change 100644 => 120000 tools/quake2/common/l3dslib.c mode change 100644 => 120000 tools/quake2/common/l3dslib.h mode change 100644 => 120000 tools/quake2/common/md4.c mode change 100644 => 120000 tools/quake2/common/md4.h mode change 100644 => 120000 tools/quake2/common/q2_threads.h mode change 100644 => 120000 tools/quake3/common/inout.h mode change 100644 => 120000 tools/quake3/common/l3dslib.c mode change 100644 => 120000 tools/quake3/common/l3dslib.h mode change 100644 => 120000 tools/quake3/common/md4.c mode change 100644 => 120000 tools/quake3/common/md4.h mode change 100644 => 120000 tools/quake3/common/qthreads.h create mode 100644 tools/shared/common/inout.h create mode 100644 tools/shared/common/l3dslib.c create mode 100644 tools/shared/common/l3dslib.h create mode 100644 tools/shared/common/md4.c create mode 100644 tools/shared/common/md4.h create mode 100644 tools/shared/common/qthreads.h diff --git a/tools/heretic2/common/her2_threads.h b/tools/heretic2/common/her2_threads.h deleted file mode 100644 index 6027a695..00000000 --- a/tools/heretic2/common/her2_threads.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - 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 - */ -#ifndef _THREADS_H - -#define _THREADS_H - - -extern int numthreads; - -void ThreadSetDefault( void ); -int GetThreadWork( void ); -void RunThreadsOnIndividual( int workcnt, qboolean showpacifier, void ( *func )( int ) ); -void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ); -void ThreadLock( void ); -void ThreadUnlock( void ); - -#endif //_THREADS_H diff --git a/tools/heretic2/common/her2_threads.h b/tools/heretic2/common/her2_threads.h new file mode 120000 index 00000000..443a8d97 --- /dev/null +++ b/tools/heretic2/common/her2_threads.h @@ -0,0 +1 @@ +../../shared/common/qthreads.h \ No newline at end of file diff --git a/tools/heretic2/common/inout.h b/tools/heretic2/common/inout.h deleted file mode 100644 index 934189f2..00000000 --- a/tools/heretic2/common/inout.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - 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 - */ - -#ifndef __INOUT__ -#define __INOUT__ - -#include "globaldefs.h" -// inout is the only stuff relying on xml, include the headers there -#include "libxml/tree.h" -#include "mathlib.h" - -// some useful xml routines -xmlNodePtr xml_NodeForVec( vec3_t v ); -void xml_SendNode( xmlNodePtr node ); -// print a message in q3map output and send the corresponding select information down the xml stream -// bError: do we end with an error on this one or do we go ahead? -void xml_Select( char *msg, int entitynum, int brushnum, qboolean bError ); -// end q3map with an error message and send a point information in the xml stream -// note: we might want to add a boolean to use this as a warning or an error thing.. -void xml_Winding( char *msg, vec3_t p[], int numpoints, qboolean die ); -void xml_Point( char *msg, vec3_t pt ); - -extern qboolean bNetworkBroadcast; -void Broadcast_Setup( const char *dest ); -void Broadcast_Shutdown(); - -#define SYS_VRB 0 // verbose support (on/off) -#define SYS_STD 1 // standard print level -#define SYS_WRN 2 // warnings -#define SYS_ERR 3 // error -#define SYS_NOXML 4 // don't send that down the XML stream - -extern qboolean verbose; -void Sys_Printf( const char *text, ... ); -void Sys_FPrintf( int flag, const char *text, ... ); -void Error( const char *error, ... ); - -#if GDEF_DEBUG -#define DBG_XML 1 -#endif - -#ifdef DBG_XML -void DumpXML(); -#endif - -#endif diff --git a/tools/heretic2/common/inout.h b/tools/heretic2/common/inout.h new file mode 120000 index 00000000..b5989d57 --- /dev/null +++ b/tools/heretic2/common/inout.h @@ -0,0 +1 @@ +../../shared/common/inout.h \ No newline at end of file diff --git a/tools/heretic2/common/md4.c b/tools/heretic2/common/md4.c deleted file mode 100644 index f5034220..00000000 --- a/tools/heretic2/common/md4.c +++ /dev/null @@ -1,219 +0,0 @@ -/* - mdfour.c - - An implementation of MD4 designed for use in the samba SMB - authentication protocol - - Copyright (C) 1997-1998 Andrew Tridgell - - This program 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. - - This program 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 this program; if not, write to: - - Free Software Foundation, Inc. - 59 Temple Place - Suite 330 - Boston, MA 02111-1307, USA - - $Id: mdfour.c 7689 2007-11-12 14:28:40Z divverent $ - */ - -#include /* XoXus: needed for memset call */ -#include "md4.h" - -/* NOTE: This code makes no attempt to be fast! - - It assumes that a int is at least 32 bits long - */ - -static struct mdfour *m; - -#define F( X,Y,Z ) ( ( (X)&( Y ) ) | ( ( ~( X ) ) & ( Z ) ) ) -#define G( X,Y,Z ) ( ( (X)&( Y ) ) | ( (X)&( Z ) ) | ( (Y)&( Z ) ) ) -#define H( X,Y,Z ) ( ( X ) ^ ( Y ) ^ ( Z ) ) -#ifdef LARGE_INT32 -#define lshift( x,s ) ( ( ( ( x ) << ( s ) ) & 0xFFFFFFFF ) | ( ( ( x ) >> ( 32 - ( s ) ) ) & 0xFFFFFFFF ) ) -#else -#define lshift( x,s ) ( ( ( x ) << ( s ) ) | ( ( x ) >> ( 32 - ( s ) ) ) ) -#endif - -#define ROUND1( a,b,c,d,k,s ) a = lshift( a + F( b,c,d ) + X[k], s ) -#define ROUND2( a,b,c,d,k,s ) a = lshift( a + G( b,c,d ) + X[k] + 0x5A827999,s ) -#define ROUND3( a,b,c,d,k,s ) a = lshift( a + H( b,c,d ) + X[k] + 0x6ED9EBA1,s ) - -/* this applies md4 to 64 byte chunks */ -static void mdfour64( uint32 *M ){ - int j; - uint32 AA, BB, CC, DD; - uint32 X[16]; - uint32 A,B,C,D; - - for ( j = 0; j < 16; j++ ) - X[j] = M[j]; - - A = m->A; B = m->B; C = m->C; D = m->D; - AA = A; BB = B; CC = C; DD = D; - - ROUND1( A,B,C,D, 0, 3 ); ROUND1( D,A,B,C, 1, 7 ); - ROUND1( C,D,A,B, 2, 11 ); ROUND1( B,C,D,A, 3, 19 ); - ROUND1( A,B,C,D, 4, 3 ); ROUND1( D,A,B,C, 5, 7 ); - ROUND1( C,D,A,B, 6, 11 ); ROUND1( B,C,D,A, 7, 19 ); - ROUND1( A,B,C,D, 8, 3 ); ROUND1( D,A,B,C, 9, 7 ); - ROUND1( C,D,A,B, 10, 11 ); ROUND1( B,C,D,A, 11, 19 ); - ROUND1( A,B,C,D, 12, 3 ); ROUND1( D,A,B,C, 13, 7 ); - ROUND1( C,D,A,B, 14, 11 ); ROUND1( B,C,D,A, 15, 19 ); - - ROUND2( A,B,C,D, 0, 3 ); ROUND2( D,A,B,C, 4, 5 ); - ROUND2( C,D,A,B, 8, 9 ); ROUND2( B,C,D,A, 12, 13 ); - ROUND2( A,B,C,D, 1, 3 ); ROUND2( D,A,B,C, 5, 5 ); - ROUND2( C,D,A,B, 9, 9 ); ROUND2( B,C,D,A, 13, 13 ); - ROUND2( A,B,C,D, 2, 3 ); ROUND2( D,A,B,C, 6, 5 ); - ROUND2( C,D,A,B, 10, 9 ); ROUND2( B,C,D,A, 14, 13 ); - ROUND2( A,B,C,D, 3, 3 ); ROUND2( D,A,B,C, 7, 5 ); - ROUND2( C,D,A,B, 11, 9 ); ROUND2( B,C,D,A, 15, 13 ); - - ROUND3( A,B,C,D, 0, 3 ); ROUND3( D,A,B,C, 8, 9 ); - ROUND3( C,D,A,B, 4, 11 ); ROUND3( B,C,D,A, 12, 15 ); - ROUND3( A,B,C,D, 2, 3 ); ROUND3( D,A,B,C, 10, 9 ); - ROUND3( C,D,A,B, 6, 11 ); ROUND3( B,C,D,A, 14, 15 ); - ROUND3( A,B,C,D, 1, 3 ); ROUND3( D,A,B,C, 9, 9 ); - ROUND3( C,D,A,B, 5, 11 ); ROUND3( B,C,D,A, 13, 15 ); - ROUND3( A,B,C,D, 3, 3 ); ROUND3( D,A,B,C, 11, 9 ); - ROUND3( C,D,A,B, 7, 11 ); ROUND3( B,C,D,A, 15, 15 ); - - A += AA; B += BB; C += CC; D += DD; - -#ifdef LARGE_INT32 - A &= 0xFFFFFFFF; B &= 0xFFFFFFFF; - C &= 0xFFFFFFFF; D &= 0xFFFFFFFF; -#endif - - for ( j = 0; j < 16; j++ ) - X[j] = 0; - - m->A = A; m->B = B; m->C = C; m->D = D; -} - -static void copy64( uint32 *M, unsigned char *in ){ - int i; - - for ( i = 0; i < 16; i++ ) - M[i] = ( in[i * 4 + 3] << 24 ) | ( in[i * 4 + 2] << 16 ) | - ( in[i * 4 + 1] << 8 ) | ( in[i * 4 + 0] << 0 ); -} - -static void copy4( unsigned char *out,uint32 x ){ - out[0] = x & 0xFF; - out[1] = ( x >> 8 ) & 0xFF; - out[2] = ( x >> 16 ) & 0xFF; - out[3] = ( x >> 24 ) & 0xFF; -} - -void mdfour_begin( struct mdfour *md ){ - md->A = 0x67452301; - md->B = 0xefcdab89; - md->C = 0x98badcfe; - md->D = 0x10325476; - md->totalN = 0; -} - - -static void mdfour_tail( unsigned char *in, int n ){ - unsigned char buf[128]; - uint32 M[16]; - uint32 b; - - m->totalN += n; - - b = m->totalN * 8; - - memset( buf, 0, 128 ); - if ( n ) { - memcpy( buf, in, n ); - } - buf[n] = 0x80; - - if ( n <= 55 ) { - copy4( buf + 56, b ); - copy64( M, buf ); - mdfour64( M ); - } - else { - copy4( buf + 120, b ); - copy64( M, buf ); - mdfour64( M ); - copy64( M, buf + 64 ); - mdfour64( M ); - } -} - -void mdfour_update( struct mdfour *md, unsigned char *in, int n ){ - uint32 M[16]; - -// start of edit by Forest 'LordHavoc' Hale -// commented out to prevent crashing when length is 0 -// if (n == 0) mdfour_tail(in, n); -// end of edit by Forest 'LordHavoc' Hale - - m = md; - - while ( n >= 64 ) { - copy64( M, in ); - mdfour64( M ); - in += 64; - n -= 64; - m->totalN += 64; - } - - mdfour_tail( in, n ); -} - - -void mdfour_result( struct mdfour *md, unsigned char *out ){ - m = md; - - copy4( out, m->A ); - copy4( out + 4, m->B ); - copy4( out + 8, m->C ); - copy4( out + 12, m->D ); -} - - -void mdfour( unsigned char *out, unsigned char *in, int n ){ - struct mdfour md; - mdfour_begin( &md ); - mdfour_update( &md, in, n ); - mdfour_result( &md, out ); -} - -/////////////////////////////////////////////////////////////// -// MD4-based checksum utility functions -// -// Copyright (C) 2000 Jeff Teunissen -// -// Author: Jeff Teunissen -// Date: 01 Jan 2000 - -unsigned Com_BlockChecksum( void *buffer, int length ){ - int digest[4]; - unsigned val; - - mdfour( (unsigned char *) digest, (unsigned char *) buffer, length ); - - val = digest[0] ^ digest[1] ^ digest[2] ^ digest[3]; - - return val; -} - -void Com_BlockFullChecksum( void *buffer, int len, unsigned char *outbuf ){ - mdfour( outbuf, (unsigned char *) buffer, len ); -} diff --git a/tools/heretic2/common/md4.c b/tools/heretic2/common/md4.c new file mode 120000 index 00000000..37d5bc4e --- /dev/null +++ b/tools/heretic2/common/md4.c @@ -0,0 +1 @@ +../../shared/common/md4.c \ No newline at end of file diff --git a/tools/heretic2/common/md4.h b/tools/heretic2/common/md4.h deleted file mode 100644 index 6f64c289..00000000 --- a/tools/heretic2/common/md4.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - mdfour.h - - an implementation of MD4 designed for use in the SMB authentication - protocol - - Copyright (C) Andrew Tridgell 1997-1998 - - This program 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. - - This program 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 this program; if not, write to: - - Free Software Foundation, Inc. - 59 Temple Place - Suite 330 - Boston, MA 02111-1307, USA - */ - -#ifndef _MDFOUR_H -#define _MDFOUR_H - -#ifndef int32 -#define int32 int -#endif - -#if SIZEOF_INT > 4 -#define LARGE_INT32 -#endif - -#ifndef uint32 -#define uint32 unsigned int32 -#endif - -struct mdfour { - uint32 A, B, C, D; - uint32 totalN; -}; - -void mdfour_begin( struct mdfour *md ); // old: MD4Init -void mdfour_update( struct mdfour *md, unsigned char *in, int n ); //old: MD4Update -void mdfour_result( struct mdfour *md, unsigned char *out ); // old: MD4Final -void mdfour( unsigned char *out, unsigned char *in, int n ); - -unsigned Com_BlockChecksum( void *buffer, int length ); -void Com_BlockFullChecksum( void *buffer, int len, unsigned char *outbuf ); - -#endif // _MDFOUR_H diff --git a/tools/heretic2/common/md4.h b/tools/heretic2/common/md4.h new file mode 120000 index 00000000..12c45cbf --- /dev/null +++ b/tools/heretic2/common/md4.h @@ -0,0 +1 @@ +../../shared/common/md4.h \ No newline at end of file diff --git a/tools/quake2/common/inout.h b/tools/quake2/common/inout.h deleted file mode 100644 index 934189f2..00000000 --- a/tools/quake2/common/inout.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - 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 - */ - -#ifndef __INOUT__ -#define __INOUT__ - -#include "globaldefs.h" -// inout is the only stuff relying on xml, include the headers there -#include "libxml/tree.h" -#include "mathlib.h" - -// some useful xml routines -xmlNodePtr xml_NodeForVec( vec3_t v ); -void xml_SendNode( xmlNodePtr node ); -// print a message in q3map output and send the corresponding select information down the xml stream -// bError: do we end with an error on this one or do we go ahead? -void xml_Select( char *msg, int entitynum, int brushnum, qboolean bError ); -// end q3map with an error message and send a point information in the xml stream -// note: we might want to add a boolean to use this as a warning or an error thing.. -void xml_Winding( char *msg, vec3_t p[], int numpoints, qboolean die ); -void xml_Point( char *msg, vec3_t pt ); - -extern qboolean bNetworkBroadcast; -void Broadcast_Setup( const char *dest ); -void Broadcast_Shutdown(); - -#define SYS_VRB 0 // verbose support (on/off) -#define SYS_STD 1 // standard print level -#define SYS_WRN 2 // warnings -#define SYS_ERR 3 // error -#define SYS_NOXML 4 // don't send that down the XML stream - -extern qboolean verbose; -void Sys_Printf( const char *text, ... ); -void Sys_FPrintf( int flag, const char *text, ... ); -void Error( const char *error, ... ); - -#if GDEF_DEBUG -#define DBG_XML 1 -#endif - -#ifdef DBG_XML -void DumpXML(); -#endif - -#endif diff --git a/tools/quake2/common/inout.h b/tools/quake2/common/inout.h new file mode 120000 index 00000000..b5989d57 --- /dev/null +++ b/tools/quake2/common/inout.h @@ -0,0 +1 @@ +../../shared/common/inout.h \ No newline at end of file diff --git a/tools/quake2/common/l3dslib.c b/tools/quake2/common/l3dslib.c deleted file mode 100644 index d4a096ad..00000000 --- a/tools/quake2/common/l3dslib.c +++ /dev/null @@ -1,311 +0,0 @@ -/* - 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 - */ -// -// l3dslib.c: library for loading triangles from an Alias triangle file -// - -#include -#include "cmdlib.h" -#include "inout.h" -#include "mathlib.h" -#include "trilib.h" -#include "l3dslib.h" - -#define MAIN3DS 0x4D4D -#define EDIT3DS 0x3D3D // this is the start of the editor config -#define EDIT_OBJECT 0x4000 -#define OBJ_TRIMESH 0x4100 -#define TRI_VERTEXL 0x4110 -#define TRI_FACEL1 0x4120 - -#define MAXVERTS 2000 - -typedef struct { - int v[4]; -} tri; - -float fverts[MAXVERTS][3]; -tri tris[MAXTRIANGLES]; - -int bytesread, level, numtris, totaltris; -int vertsfound, trisfound; - -triangle_t *ptri; - - -// Alias stores triangles as 3 explicit vertices in .tri files, so even though we -// start out with a vertex pool and vertex indices for triangles, we have to convert -// to raw, explicit triangles -void StoreAliasTriangles( void ){ - int i, j, k; - - if ( ( totaltris + numtris ) > MAXTRIANGLES ) { - Error( "Error: Too many triangles" ); - } - - for ( i = 0; i < numtris ; i++ ) - { - for ( j = 0 ; j < 3 ; j++ ) - { - for ( k = 0 ; k < 3 ; k++ ) - { - ptri[i + totaltris].verts[j][k] = fverts[tris[i].v[j]][k]; - } - } - } - - totaltris += numtris; - numtris = 0; - vertsfound = 0; - trisfound = 0; -} - - -int ParseVertexL( FILE *input ){ - int i, j, startbytesread, numverts; - unsigned short tshort; - - if ( vertsfound ) { - Error( "Error: Multiple vertex chunks" ); - } - - vertsfound = 1; - startbytesread = bytesread; - - if ( feof( input ) ) { - Error( "Error: unexpected end of file" ); - } - - fread( &tshort, sizeof( tshort ), 1, input ); - bytesread += sizeof( tshort ); - numverts = (int)tshort; - - if ( numverts > MAXVERTS ) { - Error( "Error: Too many vertices" ); - } - - for ( i = 0 ; i < numverts ; i++ ) - { - for ( j = 0 ; j < 3 ; j++ ) - { - if ( feof( input ) ) { - Error( "Error: unexpected end of file" ); - } - - fread( &fverts[i][j], sizeof( float ), 1, input ); - bytesread += sizeof( float ); - } - } - - if ( vertsfound && trisfound ) { - StoreAliasTriangles(); - } - - return bytesread - startbytesread; -} - - -int ParseFaceL1( FILE *input ){ - - int i, j, startbytesread; - unsigned short tshort; - - if ( trisfound ) { - Error( "Error: Multiple face chunks" ); - } - - trisfound = 1; - startbytesread = bytesread; - - if ( feof( input ) ) { - Error( "Error: unexpected end of file" ); - } - - fread( &tshort, sizeof( tshort ), 1, input ); - bytesread += sizeof( tshort ); - numtris = (int)tshort; - - if ( numtris > MAXTRIANGLES ) { - Error( "Error: Too many triangles" ); - } - - for ( i = 0 ; i < numtris ; i++ ) - { - for ( j = 0 ; j < 4 ; j++ ) - { - if ( feof( input ) ) { - Error( "Error: unexpected end of file" ); - } - - fread( &tshort, sizeof( tshort ), 1, input ); - bytesread += sizeof( tshort ); - tris[i].v[j] = (int)tshort; - } - } - - if ( vertsfound && trisfound ) { - StoreAliasTriangles(); - } - - return bytesread - startbytesread; -} - - -int ParseChunk( FILE *input ){ -#define BLOCK_SIZE 4096 - char temp[BLOCK_SIZE]; - unsigned short type; - int i, length, w, t, retval; - - level++; - retval = 0; - -// chunk type - if ( feof( input ) ) { - Error( "Error: unexpected end of file" ); - } - - fread( &type, sizeof( type ), 1, input ); - bytesread += sizeof( type ); - -// chunk length - if ( feof( input ) ) { - Error( "Error: unexpected end of file" ); - } - - fread( &length, sizeof( length ), 1, input ); - bytesread += sizeof( length ); - w = length - 6; - -// process chunk if we care about it, otherwise skip it - switch ( type ) - { - case TRI_VERTEXL: - w -= ParseVertexL( input ); - goto ParseSubchunk; - - case TRI_FACEL1: - w -= ParseFaceL1( input ); - goto ParseSubchunk; - - case EDIT_OBJECT: - // read the name - i = 0; - - do - { - if ( feof( input ) ) { - Error( "Error: unexpected end of file" ); - } - - fread( &temp[i], 1, 1, input ); - i++; - w--; - bytesread++; - } while ( temp[i - 1] ); - - case MAIN3DS: - case OBJ_TRIMESH: - case EDIT3DS: - // parse through subchunks -ParseSubchunk: - while ( w > 0 ) - { - w -= ParseChunk( input ); - } - - retval = length; - goto Done; - - default: - // skip other chunks - while ( w > 0 ) - { - t = w; - - if ( t > BLOCK_SIZE ) { - t = BLOCK_SIZE; - } - - if ( feof( input ) ) { - Error( "Error: unexpected end of file" ); - } - - fread( &temp, t, 1, input ); - bytesread += t; - - w -= t; - } - - retval = length; - goto Done; - } - -Done: - level--; - return retval; -} - - -void Load3DSTriangleList( char *filename, triangle_t **pptri, int *numtriangles ){ - FILE *input; - short int tshort; - - bytesread = 0; - level = 0; - numtris = 0; - totaltris = 0; - vertsfound = 0; - trisfound = 0; - - if ( ( input = fopen( filename, "rb" ) ) == 0 ) { - fprintf( stderr,"reader: could not open file '%s'\n", filename ); - exit( 0 ); - } - - fread( &tshort, sizeof( tshort ), 1, input ); - -// should only be MAIN3DS, but some files seem to start with EDIT3DS, with -// no MAIN3DS - if ( ( tshort != MAIN3DS ) && ( tshort != EDIT3DS ) ) { - fprintf( stderr,"File is not a 3DS file.\n" ); - exit( 0 ); - } - -// back to top of file so we can parse the first chunk descriptor - fseek( input, 0, SEEK_SET ); - - ptri = malloc( MAXTRIANGLES * sizeof( triangle_t ) ); - - *pptri = ptri; - -// parse through looking for the relevant chunk tree (MAIN3DS | EDIT3DS | EDIT_OBJECT | -// OBJ_TRIMESH | {TRI_VERTEXL, TRI_FACEL1}) and skipping other chunks - ParseChunk( input ); - - if ( vertsfound || trisfound ) { - Error( "Incomplete triangle set" ); - } - - *numtriangles = totaltris; - - fclose( input ); -} diff --git a/tools/quake2/common/l3dslib.c b/tools/quake2/common/l3dslib.c new file mode 120000 index 00000000..84b2d472 --- /dev/null +++ b/tools/quake2/common/l3dslib.c @@ -0,0 +1 @@ +../../shared/common/l3dslib.c \ No newline at end of file diff --git a/tools/quake2/common/l3dslib.h b/tools/quake2/common/l3dslib.h deleted file mode 100644 index 41cb344e..00000000 --- a/tools/quake2/common/l3dslib.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - 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 - */ -// -// l3dslib.h: header file for loading triangles from a 3DS triangle file -// -void Load3DSTriangleList( char *filename, triangle_t **pptri, int *numtriangles ); diff --git a/tools/quake2/common/l3dslib.h b/tools/quake2/common/l3dslib.h new file mode 120000 index 00000000..e6bb7a5b --- /dev/null +++ b/tools/quake2/common/l3dslib.h @@ -0,0 +1 @@ +../../shared/common/l3dslib.h \ No newline at end of file diff --git a/tools/quake2/common/md4.c b/tools/quake2/common/md4.c deleted file mode 100644 index f5034220..00000000 --- a/tools/quake2/common/md4.c +++ /dev/null @@ -1,219 +0,0 @@ -/* - mdfour.c - - An implementation of MD4 designed for use in the samba SMB - authentication protocol - - Copyright (C) 1997-1998 Andrew Tridgell - - This program 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. - - This program 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 this program; if not, write to: - - Free Software Foundation, Inc. - 59 Temple Place - Suite 330 - Boston, MA 02111-1307, USA - - $Id: mdfour.c 7689 2007-11-12 14:28:40Z divverent $ - */ - -#include /* XoXus: needed for memset call */ -#include "md4.h" - -/* NOTE: This code makes no attempt to be fast! - - It assumes that a int is at least 32 bits long - */ - -static struct mdfour *m; - -#define F( X,Y,Z ) ( ( (X)&( Y ) ) | ( ( ~( X ) ) & ( Z ) ) ) -#define G( X,Y,Z ) ( ( (X)&( Y ) ) | ( (X)&( Z ) ) | ( (Y)&( Z ) ) ) -#define H( X,Y,Z ) ( ( X ) ^ ( Y ) ^ ( Z ) ) -#ifdef LARGE_INT32 -#define lshift( x,s ) ( ( ( ( x ) << ( s ) ) & 0xFFFFFFFF ) | ( ( ( x ) >> ( 32 - ( s ) ) ) & 0xFFFFFFFF ) ) -#else -#define lshift( x,s ) ( ( ( x ) << ( s ) ) | ( ( x ) >> ( 32 - ( s ) ) ) ) -#endif - -#define ROUND1( a,b,c,d,k,s ) a = lshift( a + F( b,c,d ) + X[k], s ) -#define ROUND2( a,b,c,d,k,s ) a = lshift( a + G( b,c,d ) + X[k] + 0x5A827999,s ) -#define ROUND3( a,b,c,d,k,s ) a = lshift( a + H( b,c,d ) + X[k] + 0x6ED9EBA1,s ) - -/* this applies md4 to 64 byte chunks */ -static void mdfour64( uint32 *M ){ - int j; - uint32 AA, BB, CC, DD; - uint32 X[16]; - uint32 A,B,C,D; - - for ( j = 0; j < 16; j++ ) - X[j] = M[j]; - - A = m->A; B = m->B; C = m->C; D = m->D; - AA = A; BB = B; CC = C; DD = D; - - ROUND1( A,B,C,D, 0, 3 ); ROUND1( D,A,B,C, 1, 7 ); - ROUND1( C,D,A,B, 2, 11 ); ROUND1( B,C,D,A, 3, 19 ); - ROUND1( A,B,C,D, 4, 3 ); ROUND1( D,A,B,C, 5, 7 ); - ROUND1( C,D,A,B, 6, 11 ); ROUND1( B,C,D,A, 7, 19 ); - ROUND1( A,B,C,D, 8, 3 ); ROUND1( D,A,B,C, 9, 7 ); - ROUND1( C,D,A,B, 10, 11 ); ROUND1( B,C,D,A, 11, 19 ); - ROUND1( A,B,C,D, 12, 3 ); ROUND1( D,A,B,C, 13, 7 ); - ROUND1( C,D,A,B, 14, 11 ); ROUND1( B,C,D,A, 15, 19 ); - - ROUND2( A,B,C,D, 0, 3 ); ROUND2( D,A,B,C, 4, 5 ); - ROUND2( C,D,A,B, 8, 9 ); ROUND2( B,C,D,A, 12, 13 ); - ROUND2( A,B,C,D, 1, 3 ); ROUND2( D,A,B,C, 5, 5 ); - ROUND2( C,D,A,B, 9, 9 ); ROUND2( B,C,D,A, 13, 13 ); - ROUND2( A,B,C,D, 2, 3 ); ROUND2( D,A,B,C, 6, 5 ); - ROUND2( C,D,A,B, 10, 9 ); ROUND2( B,C,D,A, 14, 13 ); - ROUND2( A,B,C,D, 3, 3 ); ROUND2( D,A,B,C, 7, 5 ); - ROUND2( C,D,A,B, 11, 9 ); ROUND2( B,C,D,A, 15, 13 ); - - ROUND3( A,B,C,D, 0, 3 ); ROUND3( D,A,B,C, 8, 9 ); - ROUND3( C,D,A,B, 4, 11 ); ROUND3( B,C,D,A, 12, 15 ); - ROUND3( A,B,C,D, 2, 3 ); ROUND3( D,A,B,C, 10, 9 ); - ROUND3( C,D,A,B, 6, 11 ); ROUND3( B,C,D,A, 14, 15 ); - ROUND3( A,B,C,D, 1, 3 ); ROUND3( D,A,B,C, 9, 9 ); - ROUND3( C,D,A,B, 5, 11 ); ROUND3( B,C,D,A, 13, 15 ); - ROUND3( A,B,C,D, 3, 3 ); ROUND3( D,A,B,C, 11, 9 ); - ROUND3( C,D,A,B, 7, 11 ); ROUND3( B,C,D,A, 15, 15 ); - - A += AA; B += BB; C += CC; D += DD; - -#ifdef LARGE_INT32 - A &= 0xFFFFFFFF; B &= 0xFFFFFFFF; - C &= 0xFFFFFFFF; D &= 0xFFFFFFFF; -#endif - - for ( j = 0; j < 16; j++ ) - X[j] = 0; - - m->A = A; m->B = B; m->C = C; m->D = D; -} - -static void copy64( uint32 *M, unsigned char *in ){ - int i; - - for ( i = 0; i < 16; i++ ) - M[i] = ( in[i * 4 + 3] << 24 ) | ( in[i * 4 + 2] << 16 ) | - ( in[i * 4 + 1] << 8 ) | ( in[i * 4 + 0] << 0 ); -} - -static void copy4( unsigned char *out,uint32 x ){ - out[0] = x & 0xFF; - out[1] = ( x >> 8 ) & 0xFF; - out[2] = ( x >> 16 ) & 0xFF; - out[3] = ( x >> 24 ) & 0xFF; -} - -void mdfour_begin( struct mdfour *md ){ - md->A = 0x67452301; - md->B = 0xefcdab89; - md->C = 0x98badcfe; - md->D = 0x10325476; - md->totalN = 0; -} - - -static void mdfour_tail( unsigned char *in, int n ){ - unsigned char buf[128]; - uint32 M[16]; - uint32 b; - - m->totalN += n; - - b = m->totalN * 8; - - memset( buf, 0, 128 ); - if ( n ) { - memcpy( buf, in, n ); - } - buf[n] = 0x80; - - if ( n <= 55 ) { - copy4( buf + 56, b ); - copy64( M, buf ); - mdfour64( M ); - } - else { - copy4( buf + 120, b ); - copy64( M, buf ); - mdfour64( M ); - copy64( M, buf + 64 ); - mdfour64( M ); - } -} - -void mdfour_update( struct mdfour *md, unsigned char *in, int n ){ - uint32 M[16]; - -// start of edit by Forest 'LordHavoc' Hale -// commented out to prevent crashing when length is 0 -// if (n == 0) mdfour_tail(in, n); -// end of edit by Forest 'LordHavoc' Hale - - m = md; - - while ( n >= 64 ) { - copy64( M, in ); - mdfour64( M ); - in += 64; - n -= 64; - m->totalN += 64; - } - - mdfour_tail( in, n ); -} - - -void mdfour_result( struct mdfour *md, unsigned char *out ){ - m = md; - - copy4( out, m->A ); - copy4( out + 4, m->B ); - copy4( out + 8, m->C ); - copy4( out + 12, m->D ); -} - - -void mdfour( unsigned char *out, unsigned char *in, int n ){ - struct mdfour md; - mdfour_begin( &md ); - mdfour_update( &md, in, n ); - mdfour_result( &md, out ); -} - -/////////////////////////////////////////////////////////////// -// MD4-based checksum utility functions -// -// Copyright (C) 2000 Jeff Teunissen -// -// Author: Jeff Teunissen -// Date: 01 Jan 2000 - -unsigned Com_BlockChecksum( void *buffer, int length ){ - int digest[4]; - unsigned val; - - mdfour( (unsigned char *) digest, (unsigned char *) buffer, length ); - - val = digest[0] ^ digest[1] ^ digest[2] ^ digest[3]; - - return val; -} - -void Com_BlockFullChecksum( void *buffer, int len, unsigned char *outbuf ){ - mdfour( outbuf, (unsigned char *) buffer, len ); -} diff --git a/tools/quake2/common/md4.c b/tools/quake2/common/md4.c new file mode 120000 index 00000000..37d5bc4e --- /dev/null +++ b/tools/quake2/common/md4.c @@ -0,0 +1 @@ +../../shared/common/md4.c \ No newline at end of file diff --git a/tools/quake2/common/md4.h b/tools/quake2/common/md4.h deleted file mode 100644 index 6f64c289..00000000 --- a/tools/quake2/common/md4.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - mdfour.h - - an implementation of MD4 designed for use in the SMB authentication - protocol - - Copyright (C) Andrew Tridgell 1997-1998 - - This program 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. - - This program 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 this program; if not, write to: - - Free Software Foundation, Inc. - 59 Temple Place - Suite 330 - Boston, MA 02111-1307, USA - */ - -#ifndef _MDFOUR_H -#define _MDFOUR_H - -#ifndef int32 -#define int32 int -#endif - -#if SIZEOF_INT > 4 -#define LARGE_INT32 -#endif - -#ifndef uint32 -#define uint32 unsigned int32 -#endif - -struct mdfour { - uint32 A, B, C, D; - uint32 totalN; -}; - -void mdfour_begin( struct mdfour *md ); // old: MD4Init -void mdfour_update( struct mdfour *md, unsigned char *in, int n ); //old: MD4Update -void mdfour_result( struct mdfour *md, unsigned char *out ); // old: MD4Final -void mdfour( unsigned char *out, unsigned char *in, int n ); - -unsigned Com_BlockChecksum( void *buffer, int length ); -void Com_BlockFullChecksum( void *buffer, int len, unsigned char *outbuf ); - -#endif // _MDFOUR_H diff --git a/tools/quake2/common/md4.h b/tools/quake2/common/md4.h new file mode 120000 index 00000000..12c45cbf --- /dev/null +++ b/tools/quake2/common/md4.h @@ -0,0 +1 @@ +../../shared/common/md4.h \ No newline at end of file diff --git a/tools/quake2/common/q2_threads.h b/tools/quake2/common/q2_threads.h deleted file mode 100644 index decd226a..00000000 --- a/tools/quake2/common/q2_threads.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - 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 - */ -#ifndef _THREADS_H - -#define _THREADS_H - -extern int numthreads; - -void ThreadSetDefault( void ); -int GetThreadWork( void ); -void RunThreadsOnIndividual( int workcnt, qboolean showpacifier, void ( *func )( int ) ); -void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ); -void ThreadLock( void ); -void ThreadUnlock( void ); - -#endif // _THREADS_H diff --git a/tools/quake2/common/q2_threads.h b/tools/quake2/common/q2_threads.h new file mode 120000 index 00000000..443a8d97 --- /dev/null +++ b/tools/quake2/common/q2_threads.h @@ -0,0 +1 @@ +../../shared/common/qthreads.h \ No newline at end of file diff --git a/tools/quake3/common/cmdlib.h b/tools/quake3/common/cmdlib.h index ecdcf6e1..96abfaaf 100644 --- a/tools/quake3/common/cmdlib.h +++ b/tools/quake3/common/cmdlib.h @@ -95,7 +95,6 @@ void ExpandWildcards( int *argc, char ***argv ); double I_FloatTime( void ); -void Error( const char *error, ... ) GDEF_ATTRIBUTE_NORETURN; int CheckParm( const char *check ); FILE *SafeOpenWrite( const char *filename ); diff --git a/tools/quake3/common/inout.h b/tools/quake3/common/inout.h deleted file mode 100644 index a4d7f38b..00000000 --- a/tools/quake3/common/inout.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - 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 - */ - -#ifndef __INOUT__ -#define __INOUT__ - -#include "globaldefs.h" -// inout is the only stuff relying on xml, include the headers there -#include "libxml/tree.h" -#include "mathlib.h" - -// some useful xml routines -xmlNodePtr xml_NodeForVec( vec3_t v ); -void xml_SendNode( xmlNodePtr node ); -// print a message in q3map output and send the corresponding select information down the xml stream -// bError: do we end with an error on this one or do we go ahead? -void xml_Select( char *msg, int entitynum, int brushnum, qboolean bError ); -// end q3map with an error message and send a point information in the xml stream -// note: we might want to add a boolean to use this as a warning or an error thing.. -void xml_Winding( char *msg, vec3_t p[], int numpoints, qboolean die ); -void xml_Point( char *msg, vec3_t pt ); - -extern qboolean bNetworkBroadcast; -void Broadcast_Setup( const char *dest ); -void Broadcast_Shutdown(); - -#define SYS_VRB 0 // verbose support (on/off) -#define SYS_STD 1 // standard print level -#define SYS_WRN 2 // warnings -#define SYS_ERR 3 // error -#define SYS_NOXML 4 // don't send that down the XML stream - -extern qboolean verbose; -extern qboolean werror; -void Sys_Printf( const char *text, ... ); -void Sys_FPrintf( int flag, const char *text, ... ); - -#if GDEF_DEBUG -#define DBG_XML 1 -#endif - -#ifdef DBG_XML -void DumpXML(); -#endif - -#endif diff --git a/tools/quake3/common/inout.h b/tools/quake3/common/inout.h new file mode 120000 index 00000000..b5989d57 --- /dev/null +++ b/tools/quake3/common/inout.h @@ -0,0 +1 @@ +../../shared/common/inout.h \ No newline at end of file diff --git a/tools/quake3/common/l3dslib.c b/tools/quake3/common/l3dslib.c deleted file mode 100644 index 5e340b9d..00000000 --- a/tools/quake3/common/l3dslib.c +++ /dev/null @@ -1,312 +0,0 @@ -/* - 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 - */ - -// -// l3dslib.c: library for loading triangles from an Alias triangle file -// - -#include -#include "cmdlib.h" -#include "mathlib.h" -#include "trilib.h" -#include "l3dslib.h" - -#define MAIN3DS 0x4D4D -#define EDIT3DS 0x3D3D // this is the start of the editor config -#define EDIT_OBJECT 0x4000 -#define OBJ_TRIMESH 0x4100 -#define TRI_VERTEXL 0x4110 -#define TRI_FACEL1 0x4120 - -#define MAXVERTS 2000 -#define MAXTRIANGLES 750 - -typedef struct { - int v[4]; -} tri; - -float fverts[MAXVERTS][3]; -tri tris[MAXTRIANGLES]; - -int bytesread, level, numtris, totaltris; -int vertsfound, trisfound; - -triangle_t *ptri; - - -// Alias stores triangles as 3 explicit vertices in .tri files, so even though we -// start out with a vertex pool and vertex indices for triangles, we have to convert -// to raw, explicit triangles -void StoreAliasTriangles( void ){ - int i, j, k; - - if ( ( totaltris + numtris ) > MAXTRIANGLES ) { - Error( "Error: Too many triangles" ); - } - - for ( i = 0; i < numtris ; i++ ) - { - for ( j = 0 ; j < 3 ; j++ ) - { - for ( k = 0 ; k < 3 ; k++ ) - { - ptri[i + totaltris].verts[j][k] = fverts[tris[i].v[j]][k]; - } - } - } - - totaltris += numtris; - numtris = 0; - vertsfound = 0; - trisfound = 0; -} - - -int ParseVertexL( FILE *input ){ - int i, j, startbytesread, numverts; - unsigned short tshort; - - if ( vertsfound ) { - Error( "Error: Multiple vertex chunks" ); - } - - vertsfound = 1; - startbytesread = bytesread; - - if ( feof( input ) ) { - Error( "Error: unexpected end of file" ); - } - - fread( &tshort, sizeof( tshort ), 1, input ); - bytesread += sizeof( tshort ); - numverts = (int)tshort; - - if ( numverts > MAXVERTS ) { - Error( "Error: Too many vertices" ); - } - - for ( i = 0 ; i < numverts ; i++ ) - { - for ( j = 0 ; j < 3 ; j++ ) - { - if ( feof( input ) ) { - Error( "Error: unexpected end of file" ); - } - - fread( &fverts[i][j], sizeof( float ), 1, input ); - bytesread += sizeof( float ); - } - } - - if ( vertsfound && trisfound ) { - StoreAliasTriangles(); - } - - return bytesread - startbytesread; -} - - -int ParseFaceL1( FILE *input ){ - - int i, j, startbytesread; - unsigned short tshort; - - if ( trisfound ) { - Error( "Error: Multiple face chunks" ); - } - - trisfound = 1; - startbytesread = bytesread; - - if ( feof( input ) ) { - Error( "Error: unexpected end of file" ); - } - - fread( &tshort, sizeof( tshort ), 1, input ); - bytesread += sizeof( tshort ); - numtris = (int)tshort; - - if ( numtris > MAXTRIANGLES ) { - Error( "Error: Too many triangles" ); - } - - for ( i = 0 ; i < numtris ; i++ ) - { - for ( j = 0 ; j < 4 ; j++ ) - { - if ( feof( input ) ) { - Error( "Error: unexpected end of file" ); - } - - fread( &tshort, sizeof( tshort ), 1, input ); - bytesread += sizeof( tshort ); - tris[i].v[j] = (int)tshort; - } - } - - if ( vertsfound && trisfound ) { - StoreAliasTriangles(); - } - - return bytesread - startbytesread; -} - - -int ParseChunk( FILE *input ){ -#define BLOCK_SIZE 4096 - char temp[BLOCK_SIZE]; - unsigned short type; - int i, length, w, t, retval; - - level++; - retval = 0; - -// chunk type - if ( feof( input ) ) { - Error( "Error: unexpected end of file" ); - } - - fread( &type, sizeof( type ), 1, input ); - bytesread += sizeof( type ); - -// chunk length - if ( feof( input ) ) { - Error( "Error: unexpected end of file" ); - } - - fread( &length, sizeof( length ), 1, input ); - bytesread += sizeof( length ); - w = length - 6; - -// process chunk if we care about it, otherwise skip it - switch ( type ) - { - case TRI_VERTEXL: - w -= ParseVertexL( input ); - goto ParseSubchunk; - - case TRI_FACEL1: - w -= ParseFaceL1( input ); - goto ParseSubchunk; - - case EDIT_OBJECT: - // read the name - i = 0; - - do - { - if ( feof( input ) ) { - Error( "Error: unexpected end of file" ); - } - - fread( &temp[i], 1, 1, input ); - i++; - w--; - bytesread++; - } while ( temp[i - 1] ); - - case MAIN3DS: - case OBJ_TRIMESH: - case EDIT3DS: - // parse through subchunks -ParseSubchunk: - while ( w > 0 ) - { - w -= ParseChunk( input ); - } - - retval = length; - goto Done; - - default: - // skip other chunks - while ( w > 0 ) - { - t = w; - - if ( t > BLOCK_SIZE ) { - t = BLOCK_SIZE; - } - - if ( feof( input ) ) { - Error( "Error: unexpected end of file" ); - } - - fread( &temp, t, 1, input ); - bytesread += t; - - w -= t; - } - - retval = length; - goto Done; - } - -Done: - level--; - return retval; -} - - -void Load3DSTriangleList( char *filename, triangle_t **pptri, int *numtriangles ){ - FILE *input; - short int tshort; - - bytesread = 0; - level = 0; - numtris = 0; - totaltris = 0; - vertsfound = 0; - trisfound = 0; - - if ( ( input = fopen( filename, "rb" ) ) == 0 ) { - fprintf( stderr,"reader: could not open file '%s'\n", filename ); - exit( 0 ); - } - - fread( &tshort, sizeof( tshort ), 1, input ); - -// should only be MAIN3DS, but some files seem to start with EDIT3DS, with -// no MAIN3DS - if ( ( tshort != MAIN3DS ) && ( tshort != EDIT3DS ) ) { - fprintf( stderr,"File is not a 3DS file.\n" ); - exit( 0 ); - } - -// back to top of file so we can parse the first chunk descriptor - fseek( input, 0, SEEK_SET ); - - ptri = safe_malloc( MAXTRIANGLES * sizeof( triangle_t ) ); - - *pptri = ptri; - -// parse through looking for the relevant chunk tree (MAIN3DS | EDIT3DS | EDIT_OBJECT | -// OBJ_TRIMESH | {TRI_VERTEXL, TRI_FACEL1}) and skipping other chunks - ParseChunk( input ); - - if ( vertsfound || trisfound ) { - Error( "Incomplete triangle set" ); - } - - *numtriangles = totaltris; - - fclose( input ); -} diff --git a/tools/quake3/common/l3dslib.c b/tools/quake3/common/l3dslib.c new file mode 120000 index 00000000..84b2d472 --- /dev/null +++ b/tools/quake3/common/l3dslib.c @@ -0,0 +1 @@ +../../shared/common/l3dslib.c \ No newline at end of file diff --git a/tools/quake3/common/l3dslib.h b/tools/quake3/common/l3dslib.h deleted file mode 100644 index 98ed5028..00000000 --- a/tools/quake3/common/l3dslib.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - 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 - */ - -// -// l3dslib.h: header file for loading triangles from a 3DS triangle file -// -void Load3DSTriangleList( char *filename, triangle_t **pptri, int *numtriangles ); diff --git a/tools/quake3/common/l3dslib.h b/tools/quake3/common/l3dslib.h new file mode 120000 index 00000000..e6bb7a5b --- /dev/null +++ b/tools/quake3/common/l3dslib.h @@ -0,0 +1 @@ +../../shared/common/l3dslib.h \ No newline at end of file diff --git a/tools/quake3/common/md4.c b/tools/quake3/common/md4.c deleted file mode 100644 index f5034220..00000000 --- a/tools/quake3/common/md4.c +++ /dev/null @@ -1,219 +0,0 @@ -/* - mdfour.c - - An implementation of MD4 designed for use in the samba SMB - authentication protocol - - Copyright (C) 1997-1998 Andrew Tridgell - - This program 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. - - This program 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 this program; if not, write to: - - Free Software Foundation, Inc. - 59 Temple Place - Suite 330 - Boston, MA 02111-1307, USA - - $Id: mdfour.c 7689 2007-11-12 14:28:40Z divverent $ - */ - -#include /* XoXus: needed for memset call */ -#include "md4.h" - -/* NOTE: This code makes no attempt to be fast! - - It assumes that a int is at least 32 bits long - */ - -static struct mdfour *m; - -#define F( X,Y,Z ) ( ( (X)&( Y ) ) | ( ( ~( X ) ) & ( Z ) ) ) -#define G( X,Y,Z ) ( ( (X)&( Y ) ) | ( (X)&( Z ) ) | ( (Y)&( Z ) ) ) -#define H( X,Y,Z ) ( ( X ) ^ ( Y ) ^ ( Z ) ) -#ifdef LARGE_INT32 -#define lshift( x,s ) ( ( ( ( x ) << ( s ) ) & 0xFFFFFFFF ) | ( ( ( x ) >> ( 32 - ( s ) ) ) & 0xFFFFFFFF ) ) -#else -#define lshift( x,s ) ( ( ( x ) << ( s ) ) | ( ( x ) >> ( 32 - ( s ) ) ) ) -#endif - -#define ROUND1( a,b,c,d,k,s ) a = lshift( a + F( b,c,d ) + X[k], s ) -#define ROUND2( a,b,c,d,k,s ) a = lshift( a + G( b,c,d ) + X[k] + 0x5A827999,s ) -#define ROUND3( a,b,c,d,k,s ) a = lshift( a + H( b,c,d ) + X[k] + 0x6ED9EBA1,s ) - -/* this applies md4 to 64 byte chunks */ -static void mdfour64( uint32 *M ){ - int j; - uint32 AA, BB, CC, DD; - uint32 X[16]; - uint32 A,B,C,D; - - for ( j = 0; j < 16; j++ ) - X[j] = M[j]; - - A = m->A; B = m->B; C = m->C; D = m->D; - AA = A; BB = B; CC = C; DD = D; - - ROUND1( A,B,C,D, 0, 3 ); ROUND1( D,A,B,C, 1, 7 ); - ROUND1( C,D,A,B, 2, 11 ); ROUND1( B,C,D,A, 3, 19 ); - ROUND1( A,B,C,D, 4, 3 ); ROUND1( D,A,B,C, 5, 7 ); - ROUND1( C,D,A,B, 6, 11 ); ROUND1( B,C,D,A, 7, 19 ); - ROUND1( A,B,C,D, 8, 3 ); ROUND1( D,A,B,C, 9, 7 ); - ROUND1( C,D,A,B, 10, 11 ); ROUND1( B,C,D,A, 11, 19 ); - ROUND1( A,B,C,D, 12, 3 ); ROUND1( D,A,B,C, 13, 7 ); - ROUND1( C,D,A,B, 14, 11 ); ROUND1( B,C,D,A, 15, 19 ); - - ROUND2( A,B,C,D, 0, 3 ); ROUND2( D,A,B,C, 4, 5 ); - ROUND2( C,D,A,B, 8, 9 ); ROUND2( B,C,D,A, 12, 13 ); - ROUND2( A,B,C,D, 1, 3 ); ROUND2( D,A,B,C, 5, 5 ); - ROUND2( C,D,A,B, 9, 9 ); ROUND2( B,C,D,A, 13, 13 ); - ROUND2( A,B,C,D, 2, 3 ); ROUND2( D,A,B,C, 6, 5 ); - ROUND2( C,D,A,B, 10, 9 ); ROUND2( B,C,D,A, 14, 13 ); - ROUND2( A,B,C,D, 3, 3 ); ROUND2( D,A,B,C, 7, 5 ); - ROUND2( C,D,A,B, 11, 9 ); ROUND2( B,C,D,A, 15, 13 ); - - ROUND3( A,B,C,D, 0, 3 ); ROUND3( D,A,B,C, 8, 9 ); - ROUND3( C,D,A,B, 4, 11 ); ROUND3( B,C,D,A, 12, 15 ); - ROUND3( A,B,C,D, 2, 3 ); ROUND3( D,A,B,C, 10, 9 ); - ROUND3( C,D,A,B, 6, 11 ); ROUND3( B,C,D,A, 14, 15 ); - ROUND3( A,B,C,D, 1, 3 ); ROUND3( D,A,B,C, 9, 9 ); - ROUND3( C,D,A,B, 5, 11 ); ROUND3( B,C,D,A, 13, 15 ); - ROUND3( A,B,C,D, 3, 3 ); ROUND3( D,A,B,C, 11, 9 ); - ROUND3( C,D,A,B, 7, 11 ); ROUND3( B,C,D,A, 15, 15 ); - - A += AA; B += BB; C += CC; D += DD; - -#ifdef LARGE_INT32 - A &= 0xFFFFFFFF; B &= 0xFFFFFFFF; - C &= 0xFFFFFFFF; D &= 0xFFFFFFFF; -#endif - - for ( j = 0; j < 16; j++ ) - X[j] = 0; - - m->A = A; m->B = B; m->C = C; m->D = D; -} - -static void copy64( uint32 *M, unsigned char *in ){ - int i; - - for ( i = 0; i < 16; i++ ) - M[i] = ( in[i * 4 + 3] << 24 ) | ( in[i * 4 + 2] << 16 ) | - ( in[i * 4 + 1] << 8 ) | ( in[i * 4 + 0] << 0 ); -} - -static void copy4( unsigned char *out,uint32 x ){ - out[0] = x & 0xFF; - out[1] = ( x >> 8 ) & 0xFF; - out[2] = ( x >> 16 ) & 0xFF; - out[3] = ( x >> 24 ) & 0xFF; -} - -void mdfour_begin( struct mdfour *md ){ - md->A = 0x67452301; - md->B = 0xefcdab89; - md->C = 0x98badcfe; - md->D = 0x10325476; - md->totalN = 0; -} - - -static void mdfour_tail( unsigned char *in, int n ){ - unsigned char buf[128]; - uint32 M[16]; - uint32 b; - - m->totalN += n; - - b = m->totalN * 8; - - memset( buf, 0, 128 ); - if ( n ) { - memcpy( buf, in, n ); - } - buf[n] = 0x80; - - if ( n <= 55 ) { - copy4( buf + 56, b ); - copy64( M, buf ); - mdfour64( M ); - } - else { - copy4( buf + 120, b ); - copy64( M, buf ); - mdfour64( M ); - copy64( M, buf + 64 ); - mdfour64( M ); - } -} - -void mdfour_update( struct mdfour *md, unsigned char *in, int n ){ - uint32 M[16]; - -// start of edit by Forest 'LordHavoc' Hale -// commented out to prevent crashing when length is 0 -// if (n == 0) mdfour_tail(in, n); -// end of edit by Forest 'LordHavoc' Hale - - m = md; - - while ( n >= 64 ) { - copy64( M, in ); - mdfour64( M ); - in += 64; - n -= 64; - m->totalN += 64; - } - - mdfour_tail( in, n ); -} - - -void mdfour_result( struct mdfour *md, unsigned char *out ){ - m = md; - - copy4( out, m->A ); - copy4( out + 4, m->B ); - copy4( out + 8, m->C ); - copy4( out + 12, m->D ); -} - - -void mdfour( unsigned char *out, unsigned char *in, int n ){ - struct mdfour md; - mdfour_begin( &md ); - mdfour_update( &md, in, n ); - mdfour_result( &md, out ); -} - -/////////////////////////////////////////////////////////////// -// MD4-based checksum utility functions -// -// Copyright (C) 2000 Jeff Teunissen -// -// Author: Jeff Teunissen -// Date: 01 Jan 2000 - -unsigned Com_BlockChecksum( void *buffer, int length ){ - int digest[4]; - unsigned val; - - mdfour( (unsigned char *) digest, (unsigned char *) buffer, length ); - - val = digest[0] ^ digest[1] ^ digest[2] ^ digest[3]; - - return val; -} - -void Com_BlockFullChecksum( void *buffer, int len, unsigned char *outbuf ){ - mdfour( outbuf, (unsigned char *) buffer, len ); -} diff --git a/tools/quake3/common/md4.c b/tools/quake3/common/md4.c new file mode 120000 index 00000000..37d5bc4e --- /dev/null +++ b/tools/quake3/common/md4.c @@ -0,0 +1 @@ +../../shared/common/md4.c \ No newline at end of file diff --git a/tools/quake3/common/md4.h b/tools/quake3/common/md4.h deleted file mode 100644 index 6f64c289..00000000 --- a/tools/quake3/common/md4.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - mdfour.h - - an implementation of MD4 designed for use in the SMB authentication - protocol - - Copyright (C) Andrew Tridgell 1997-1998 - - This program 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. - - This program 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 this program; if not, write to: - - Free Software Foundation, Inc. - 59 Temple Place - Suite 330 - Boston, MA 02111-1307, USA - */ - -#ifndef _MDFOUR_H -#define _MDFOUR_H - -#ifndef int32 -#define int32 int -#endif - -#if SIZEOF_INT > 4 -#define LARGE_INT32 -#endif - -#ifndef uint32 -#define uint32 unsigned int32 -#endif - -struct mdfour { - uint32 A, B, C, D; - uint32 totalN; -}; - -void mdfour_begin( struct mdfour *md ); // old: MD4Init -void mdfour_update( struct mdfour *md, unsigned char *in, int n ); //old: MD4Update -void mdfour_result( struct mdfour *md, unsigned char *out ); // old: MD4Final -void mdfour( unsigned char *out, unsigned char *in, int n ); - -unsigned Com_BlockChecksum( void *buffer, int length ); -void Com_BlockFullChecksum( void *buffer, int len, unsigned char *outbuf ); - -#endif // _MDFOUR_H diff --git a/tools/quake3/common/md4.h b/tools/quake3/common/md4.h new file mode 120000 index 00000000..12c45cbf --- /dev/null +++ b/tools/quake3/common/md4.h @@ -0,0 +1 @@ +../../shared/common/md4.h \ No newline at end of file diff --git a/tools/quake3/common/qthreads.h b/tools/quake3/common/qthreads.h deleted file mode 100644 index 823cb63a..00000000 --- a/tools/quake3/common/qthreads.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - 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 - */ - - -extern int numthreads; - -void ThreadSetDefault( void ); -int GetThreadWork( void ); -void RunThreadsOnIndividual( int workcnt, qboolean showpacifier, void ( *func )( int ) ); -void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ); -void ThreadLock( void ); -void ThreadUnlock( void ); diff --git a/tools/quake3/common/qthreads.h b/tools/quake3/common/qthreads.h new file mode 120000 index 00000000..443a8d97 --- /dev/null +++ b/tools/quake3/common/qthreads.h @@ -0,0 +1 @@ +../../shared/common/qthreads.h \ No newline at end of file diff --git a/tools/shared/common/inout.h b/tools/shared/common/inout.h new file mode 100644 index 00000000..cdb7aa18 --- /dev/null +++ b/tools/shared/common/inout.h @@ -0,0 +1,65 @@ +/* + 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 + */ + +#ifndef __INOUT__ +#define __INOUT__ + +#include "globaldefs.h" +// inout is the only stuff relying on xml, include the headers there +#include "libxml/tree.h" +#include "mathlib.h" + +// some useful xml routines +xmlNodePtr xml_NodeForVec( vec3_t v ); +void xml_SendNode( xmlNodePtr node ); +// print a message in q3map output and send the corresponding select information down the xml stream +// bError: do we end with an error on this one or do we go ahead? +void xml_Select( char *msg, int entitynum, int brushnum, qboolean bError ); +// end q3map with an error message and send a point information in the xml stream +// note: we might want to add a boolean to use this as a warning or an error thing.. +void xml_Winding( char *msg, vec3_t p[], int numpoints, qboolean die ); +void xml_Point( char *msg, vec3_t pt ); + +extern qboolean bNetworkBroadcast; +void Broadcast_Setup( const char *dest ); +void Broadcast_Shutdown(); + +#define SYS_VRB 0 // verbose support (on/off) +#define SYS_STD 1 // standard print level +#define SYS_WRN 2 // warnings +#define SYS_ERR 3 // error +#define SYS_NOXML 4 // don't send that down the XML stream + +extern qboolean verbose; +extern qboolean werror; +void Sys_Printf( const char *text, ... ); +void Sys_FPrintf( int flag, const char *text, ... ); +void Error( const char *error, ... ) GDEF_ATTRIBUTE_NORETURN; + +#if GDEF_DEBUG +#define DBG_XML 1 +#endif + +#ifdef DBG_XML +void DumpXML(); +#endif + +#endif diff --git a/tools/shared/common/l3dslib.c b/tools/shared/common/l3dslib.c new file mode 100644 index 00000000..5e340b9d --- /dev/null +++ b/tools/shared/common/l3dslib.c @@ -0,0 +1,312 @@ +/* + 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 + */ + +// +// l3dslib.c: library for loading triangles from an Alias triangle file +// + +#include +#include "cmdlib.h" +#include "mathlib.h" +#include "trilib.h" +#include "l3dslib.h" + +#define MAIN3DS 0x4D4D +#define EDIT3DS 0x3D3D // this is the start of the editor config +#define EDIT_OBJECT 0x4000 +#define OBJ_TRIMESH 0x4100 +#define TRI_VERTEXL 0x4110 +#define TRI_FACEL1 0x4120 + +#define MAXVERTS 2000 +#define MAXTRIANGLES 750 + +typedef struct { + int v[4]; +} tri; + +float fverts[MAXVERTS][3]; +tri tris[MAXTRIANGLES]; + +int bytesread, level, numtris, totaltris; +int vertsfound, trisfound; + +triangle_t *ptri; + + +// Alias stores triangles as 3 explicit vertices in .tri files, so even though we +// start out with a vertex pool and vertex indices for triangles, we have to convert +// to raw, explicit triangles +void StoreAliasTriangles( void ){ + int i, j, k; + + if ( ( totaltris + numtris ) > MAXTRIANGLES ) { + Error( "Error: Too many triangles" ); + } + + for ( i = 0; i < numtris ; i++ ) + { + for ( j = 0 ; j < 3 ; j++ ) + { + for ( k = 0 ; k < 3 ; k++ ) + { + ptri[i + totaltris].verts[j][k] = fverts[tris[i].v[j]][k]; + } + } + } + + totaltris += numtris; + numtris = 0; + vertsfound = 0; + trisfound = 0; +} + + +int ParseVertexL( FILE *input ){ + int i, j, startbytesread, numverts; + unsigned short tshort; + + if ( vertsfound ) { + Error( "Error: Multiple vertex chunks" ); + } + + vertsfound = 1; + startbytesread = bytesread; + + if ( feof( input ) ) { + Error( "Error: unexpected end of file" ); + } + + fread( &tshort, sizeof( tshort ), 1, input ); + bytesread += sizeof( tshort ); + numverts = (int)tshort; + + if ( numverts > MAXVERTS ) { + Error( "Error: Too many vertices" ); + } + + for ( i = 0 ; i < numverts ; i++ ) + { + for ( j = 0 ; j < 3 ; j++ ) + { + if ( feof( input ) ) { + Error( "Error: unexpected end of file" ); + } + + fread( &fverts[i][j], sizeof( float ), 1, input ); + bytesread += sizeof( float ); + } + } + + if ( vertsfound && trisfound ) { + StoreAliasTriangles(); + } + + return bytesread - startbytesread; +} + + +int ParseFaceL1( FILE *input ){ + + int i, j, startbytesread; + unsigned short tshort; + + if ( trisfound ) { + Error( "Error: Multiple face chunks" ); + } + + trisfound = 1; + startbytesread = bytesread; + + if ( feof( input ) ) { + Error( "Error: unexpected end of file" ); + } + + fread( &tshort, sizeof( tshort ), 1, input ); + bytesread += sizeof( tshort ); + numtris = (int)tshort; + + if ( numtris > MAXTRIANGLES ) { + Error( "Error: Too many triangles" ); + } + + for ( i = 0 ; i < numtris ; i++ ) + { + for ( j = 0 ; j < 4 ; j++ ) + { + if ( feof( input ) ) { + Error( "Error: unexpected end of file" ); + } + + fread( &tshort, sizeof( tshort ), 1, input ); + bytesread += sizeof( tshort ); + tris[i].v[j] = (int)tshort; + } + } + + if ( vertsfound && trisfound ) { + StoreAliasTriangles(); + } + + return bytesread - startbytesread; +} + + +int ParseChunk( FILE *input ){ +#define BLOCK_SIZE 4096 + char temp[BLOCK_SIZE]; + unsigned short type; + int i, length, w, t, retval; + + level++; + retval = 0; + +// chunk type + if ( feof( input ) ) { + Error( "Error: unexpected end of file" ); + } + + fread( &type, sizeof( type ), 1, input ); + bytesread += sizeof( type ); + +// chunk length + if ( feof( input ) ) { + Error( "Error: unexpected end of file" ); + } + + fread( &length, sizeof( length ), 1, input ); + bytesread += sizeof( length ); + w = length - 6; + +// process chunk if we care about it, otherwise skip it + switch ( type ) + { + case TRI_VERTEXL: + w -= ParseVertexL( input ); + goto ParseSubchunk; + + case TRI_FACEL1: + w -= ParseFaceL1( input ); + goto ParseSubchunk; + + case EDIT_OBJECT: + // read the name + i = 0; + + do + { + if ( feof( input ) ) { + Error( "Error: unexpected end of file" ); + } + + fread( &temp[i], 1, 1, input ); + i++; + w--; + bytesread++; + } while ( temp[i - 1] ); + + case MAIN3DS: + case OBJ_TRIMESH: + case EDIT3DS: + // parse through subchunks +ParseSubchunk: + while ( w > 0 ) + { + w -= ParseChunk( input ); + } + + retval = length; + goto Done; + + default: + // skip other chunks + while ( w > 0 ) + { + t = w; + + if ( t > BLOCK_SIZE ) { + t = BLOCK_SIZE; + } + + if ( feof( input ) ) { + Error( "Error: unexpected end of file" ); + } + + fread( &temp, t, 1, input ); + bytesread += t; + + w -= t; + } + + retval = length; + goto Done; + } + +Done: + level--; + return retval; +} + + +void Load3DSTriangleList( char *filename, triangle_t **pptri, int *numtriangles ){ + FILE *input; + short int tshort; + + bytesread = 0; + level = 0; + numtris = 0; + totaltris = 0; + vertsfound = 0; + trisfound = 0; + + if ( ( input = fopen( filename, "rb" ) ) == 0 ) { + fprintf( stderr,"reader: could not open file '%s'\n", filename ); + exit( 0 ); + } + + fread( &tshort, sizeof( tshort ), 1, input ); + +// should only be MAIN3DS, but some files seem to start with EDIT3DS, with +// no MAIN3DS + if ( ( tshort != MAIN3DS ) && ( tshort != EDIT3DS ) ) { + fprintf( stderr,"File is not a 3DS file.\n" ); + exit( 0 ); + } + +// back to top of file so we can parse the first chunk descriptor + fseek( input, 0, SEEK_SET ); + + ptri = safe_malloc( MAXTRIANGLES * sizeof( triangle_t ) ); + + *pptri = ptri; + +// parse through looking for the relevant chunk tree (MAIN3DS | EDIT3DS | EDIT_OBJECT | +// OBJ_TRIMESH | {TRI_VERTEXL, TRI_FACEL1}) and skipping other chunks + ParseChunk( input ); + + if ( vertsfound || trisfound ) { + Error( "Incomplete triangle set" ); + } + + *numtriangles = totaltris; + + fclose( input ); +} diff --git a/tools/shared/common/l3dslib.h b/tools/shared/common/l3dslib.h new file mode 100644 index 00000000..98ed5028 --- /dev/null +++ b/tools/shared/common/l3dslib.h @@ -0,0 +1,25 @@ +/* + 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 + */ + +// +// l3dslib.h: header file for loading triangles from a 3DS triangle file +// +void Load3DSTriangleList( char *filename, triangle_t **pptri, int *numtriangles ); diff --git a/tools/shared/common/md4.c b/tools/shared/common/md4.c new file mode 100644 index 00000000..f5034220 --- /dev/null +++ b/tools/shared/common/md4.c @@ -0,0 +1,219 @@ +/* + mdfour.c + + An implementation of MD4 designed for use in the samba SMB + authentication protocol + + Copyright (C) 1997-1998 Andrew Tridgell + + This program 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. + + This program 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 this program; if not, write to: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + + $Id: mdfour.c 7689 2007-11-12 14:28:40Z divverent $ + */ + +#include /* XoXus: needed for memset call */ +#include "md4.h" + +/* NOTE: This code makes no attempt to be fast! + + It assumes that a int is at least 32 bits long + */ + +static struct mdfour *m; + +#define F( X,Y,Z ) ( ( (X)&( Y ) ) | ( ( ~( X ) ) & ( Z ) ) ) +#define G( X,Y,Z ) ( ( (X)&( Y ) ) | ( (X)&( Z ) ) | ( (Y)&( Z ) ) ) +#define H( X,Y,Z ) ( ( X ) ^ ( Y ) ^ ( Z ) ) +#ifdef LARGE_INT32 +#define lshift( x,s ) ( ( ( ( x ) << ( s ) ) & 0xFFFFFFFF ) | ( ( ( x ) >> ( 32 - ( s ) ) ) & 0xFFFFFFFF ) ) +#else +#define lshift( x,s ) ( ( ( x ) << ( s ) ) | ( ( x ) >> ( 32 - ( s ) ) ) ) +#endif + +#define ROUND1( a,b,c,d,k,s ) a = lshift( a + F( b,c,d ) + X[k], s ) +#define ROUND2( a,b,c,d,k,s ) a = lshift( a + G( b,c,d ) + X[k] + 0x5A827999,s ) +#define ROUND3( a,b,c,d,k,s ) a = lshift( a + H( b,c,d ) + X[k] + 0x6ED9EBA1,s ) + +/* this applies md4 to 64 byte chunks */ +static void mdfour64( uint32 *M ){ + int j; + uint32 AA, BB, CC, DD; + uint32 X[16]; + uint32 A,B,C,D; + + for ( j = 0; j < 16; j++ ) + X[j] = M[j]; + + A = m->A; B = m->B; C = m->C; D = m->D; + AA = A; BB = B; CC = C; DD = D; + + ROUND1( A,B,C,D, 0, 3 ); ROUND1( D,A,B,C, 1, 7 ); + ROUND1( C,D,A,B, 2, 11 ); ROUND1( B,C,D,A, 3, 19 ); + ROUND1( A,B,C,D, 4, 3 ); ROUND1( D,A,B,C, 5, 7 ); + ROUND1( C,D,A,B, 6, 11 ); ROUND1( B,C,D,A, 7, 19 ); + ROUND1( A,B,C,D, 8, 3 ); ROUND1( D,A,B,C, 9, 7 ); + ROUND1( C,D,A,B, 10, 11 ); ROUND1( B,C,D,A, 11, 19 ); + ROUND1( A,B,C,D, 12, 3 ); ROUND1( D,A,B,C, 13, 7 ); + ROUND1( C,D,A,B, 14, 11 ); ROUND1( B,C,D,A, 15, 19 ); + + ROUND2( A,B,C,D, 0, 3 ); ROUND2( D,A,B,C, 4, 5 ); + ROUND2( C,D,A,B, 8, 9 ); ROUND2( B,C,D,A, 12, 13 ); + ROUND2( A,B,C,D, 1, 3 ); ROUND2( D,A,B,C, 5, 5 ); + ROUND2( C,D,A,B, 9, 9 ); ROUND2( B,C,D,A, 13, 13 ); + ROUND2( A,B,C,D, 2, 3 ); ROUND2( D,A,B,C, 6, 5 ); + ROUND2( C,D,A,B, 10, 9 ); ROUND2( B,C,D,A, 14, 13 ); + ROUND2( A,B,C,D, 3, 3 ); ROUND2( D,A,B,C, 7, 5 ); + ROUND2( C,D,A,B, 11, 9 ); ROUND2( B,C,D,A, 15, 13 ); + + ROUND3( A,B,C,D, 0, 3 ); ROUND3( D,A,B,C, 8, 9 ); + ROUND3( C,D,A,B, 4, 11 ); ROUND3( B,C,D,A, 12, 15 ); + ROUND3( A,B,C,D, 2, 3 ); ROUND3( D,A,B,C, 10, 9 ); + ROUND3( C,D,A,B, 6, 11 ); ROUND3( B,C,D,A, 14, 15 ); + ROUND3( A,B,C,D, 1, 3 ); ROUND3( D,A,B,C, 9, 9 ); + ROUND3( C,D,A,B, 5, 11 ); ROUND3( B,C,D,A, 13, 15 ); + ROUND3( A,B,C,D, 3, 3 ); ROUND3( D,A,B,C, 11, 9 ); + ROUND3( C,D,A,B, 7, 11 ); ROUND3( B,C,D,A, 15, 15 ); + + A += AA; B += BB; C += CC; D += DD; + +#ifdef LARGE_INT32 + A &= 0xFFFFFFFF; B &= 0xFFFFFFFF; + C &= 0xFFFFFFFF; D &= 0xFFFFFFFF; +#endif + + for ( j = 0; j < 16; j++ ) + X[j] = 0; + + m->A = A; m->B = B; m->C = C; m->D = D; +} + +static void copy64( uint32 *M, unsigned char *in ){ + int i; + + for ( i = 0; i < 16; i++ ) + M[i] = ( in[i * 4 + 3] << 24 ) | ( in[i * 4 + 2] << 16 ) | + ( in[i * 4 + 1] << 8 ) | ( in[i * 4 + 0] << 0 ); +} + +static void copy4( unsigned char *out,uint32 x ){ + out[0] = x & 0xFF; + out[1] = ( x >> 8 ) & 0xFF; + out[2] = ( x >> 16 ) & 0xFF; + out[3] = ( x >> 24 ) & 0xFF; +} + +void mdfour_begin( struct mdfour *md ){ + md->A = 0x67452301; + md->B = 0xefcdab89; + md->C = 0x98badcfe; + md->D = 0x10325476; + md->totalN = 0; +} + + +static void mdfour_tail( unsigned char *in, int n ){ + unsigned char buf[128]; + uint32 M[16]; + uint32 b; + + m->totalN += n; + + b = m->totalN * 8; + + memset( buf, 0, 128 ); + if ( n ) { + memcpy( buf, in, n ); + } + buf[n] = 0x80; + + if ( n <= 55 ) { + copy4( buf + 56, b ); + copy64( M, buf ); + mdfour64( M ); + } + else { + copy4( buf + 120, b ); + copy64( M, buf ); + mdfour64( M ); + copy64( M, buf + 64 ); + mdfour64( M ); + } +} + +void mdfour_update( struct mdfour *md, unsigned char *in, int n ){ + uint32 M[16]; + +// start of edit by Forest 'LordHavoc' Hale +// commented out to prevent crashing when length is 0 +// if (n == 0) mdfour_tail(in, n); +// end of edit by Forest 'LordHavoc' Hale + + m = md; + + while ( n >= 64 ) { + copy64( M, in ); + mdfour64( M ); + in += 64; + n -= 64; + m->totalN += 64; + } + + mdfour_tail( in, n ); +} + + +void mdfour_result( struct mdfour *md, unsigned char *out ){ + m = md; + + copy4( out, m->A ); + copy4( out + 4, m->B ); + copy4( out + 8, m->C ); + copy4( out + 12, m->D ); +} + + +void mdfour( unsigned char *out, unsigned char *in, int n ){ + struct mdfour md; + mdfour_begin( &md ); + mdfour_update( &md, in, n ); + mdfour_result( &md, out ); +} + +/////////////////////////////////////////////////////////////// +// MD4-based checksum utility functions +// +// Copyright (C) 2000 Jeff Teunissen +// +// Author: Jeff Teunissen +// Date: 01 Jan 2000 + +unsigned Com_BlockChecksum( void *buffer, int length ){ + int digest[4]; + unsigned val; + + mdfour( (unsigned char *) digest, (unsigned char *) buffer, length ); + + val = digest[0] ^ digest[1] ^ digest[2] ^ digest[3]; + + return val; +} + +void Com_BlockFullChecksum( void *buffer, int len, unsigned char *outbuf ){ + mdfour( outbuf, (unsigned char *) buffer, len ); +} diff --git a/tools/shared/common/md4.h b/tools/shared/common/md4.h new file mode 100644 index 00000000..6f64c289 --- /dev/null +++ b/tools/shared/common/md4.h @@ -0,0 +1,56 @@ +/* + mdfour.h + + an implementation of MD4 designed for use in the SMB authentication + protocol + + Copyright (C) Andrew Tridgell 1997-1998 + + This program 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. + + This program 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 this program; if not, write to: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + */ + +#ifndef _MDFOUR_H +#define _MDFOUR_H + +#ifndef int32 +#define int32 int +#endif + +#if SIZEOF_INT > 4 +#define LARGE_INT32 +#endif + +#ifndef uint32 +#define uint32 unsigned int32 +#endif + +struct mdfour { + uint32 A, B, C, D; + uint32 totalN; +}; + +void mdfour_begin( struct mdfour *md ); // old: MD4Init +void mdfour_update( struct mdfour *md, unsigned char *in, int n ); //old: MD4Update +void mdfour_result( struct mdfour *md, unsigned char *out ); // old: MD4Final +void mdfour( unsigned char *out, unsigned char *in, int n ); + +unsigned Com_BlockChecksum( void *buffer, int length ); +void Com_BlockFullChecksum( void *buffer, int len, unsigned char *outbuf ); + +#endif // _MDFOUR_H diff --git a/tools/shared/common/qthreads.h b/tools/shared/common/qthreads.h new file mode 100644 index 00000000..decd226a --- /dev/null +++ b/tools/shared/common/qthreads.h @@ -0,0 +1,34 @@ +/* + 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 + */ +#ifndef _THREADS_H + +#define _THREADS_H + +extern int numthreads; + +void ThreadSetDefault( void ); +int GetThreadWork( void ); +void RunThreadsOnIndividual( int workcnt, qboolean showpacifier, void ( *func )( int ) ); +void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ); +void ThreadLock( void ); +void ThreadUnlock( void ); + +#endif // _THREADS_H -- 2.39.2