X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=common.c;h=3dfcf6d51577d324702fcf62083d03de5cf9edee;hp=daa7fbde44efd30ae09aa0758be96ca831178f03;hb=9f0345dcadf3d619bb98991ee2dd051787654bf5;hpb=c4ee1bbcc6b2f917465f07269ad09942bbf40849 diff --git a/common.c b/common.c index daa7fbde..3dfcf6d5 100644 --- a/common.c +++ b/common.c @@ -29,14 +29,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" -#define NUM_SAFE_ARGVS 7 - -static char *largv[MAX_NUM_ARGVS + NUM_SAFE_ARGVS + 1]; -static char *argvdummy = " "; - -static char *safeargvs[NUM_SAFE_ARGVS] = - {"-stdvid", "-nolan", "-nosound", "-nocdaudio", "-nojoy", "-nomouse", "-window"}; - cvar_t registered = {0, "registered","0"}; cvar_t cmdline = {0, "cmdline","0"}; @@ -44,15 +36,12 @@ mempool_t *pak_mempool; qboolean com_modified; // set true if using non-id files -//qboolean proghack; - -//int static_registered = 1; // only for startup check, then set - qboolean msg_suppress_1 = 0; void COM_InitFilesystem (void); char com_token[1024]; +char com_basedir[MAX_OSPATH]; int com_argc; char **com_argv; @@ -62,6 +51,7 @@ char com_cmdline[CMDLINE_LENGTH]; int gamemode; char *gamename; +char *gamedirname; /* @@ -95,126 +85,6 @@ The file "parms.txt" will be read out of the game directory and appended to the ============================================================================ */ -/* -void Q_memset (void *dest, int fill, int count) -{ - int i; - - if ( (((long)dest | count) & 3) == 0) - { - count >>= 2; - fill = fill | (fill<<8) | (fill<<16) | (fill<<24); - for (i=0 ; i>=2; - for (i=0 ; i= '0' && c <= '9') - val = (val<<4) + c - '0'; - else if (c >= 'a' && c <= 'f') - val = (val<<4) + c - 'a' + 10; - else if (c >= 'A' && c <= 'F') - val = (val<<4) + c - 'A' + 10; - else - return val*sign; - } - } - -// -// check for character -// - if (str[0] == '\'') - { - return sign * str[1]; - } - -// -// assume decimal -// - while (1) - { - c = *str++; - if (c <'0' || c > '9') - return val*sign; - val = val*10 + c - '0'; - } - - return 0; -} - - -float Q_atof (char *str) -{ - double val; - int sign; - int c; - int decimal, total; - - if (*str == '-') - { - sign = -1; - str++; - } - else - sign = 1; - - val = 0; - -// -// check for hex -// - if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X') ) - { - str += 2; - while (1) - { - c = *str++; - if (c >= '0' && c <= '9') - val = (val*16) + c - '0'; - else if (c >= 'a' && c <= 'f') - val = (val*16) + c - 'a' + 10; - else if (c >= 'A' && c <= 'F') - val = (val*16) + c - 'A' + 10; - else - return val*sign; - } - } - -// -// check for character -// - if (str[0] == '\'') - { - return sign * str[1]; - } - -// -// assume decimal -// - decimal = -1; - total = 0; - while (1) - { - c = *str++; - if (c == '.') - { - decimal = total; - continue; - } - if (c <'0' || c > '9') - break; - val = val*10 + c - '0'; - total++; - } - - if (decimal == -1) - return val*sign; - while (total > decimal) - { - val /= 10; - total--; - } - - return val*sign; -} -*/ /* ============================================================================ @@ -479,11 +212,6 @@ void MSG_WriteChar (sizebuf_t *sb, int c) { qbyte *buf; -//#ifdef PARANOID -// if (c < -128 || c > 127) -// Sys_Error ("MSG_WriteChar: range error"); -//#endif - buf = SZ_GetSpace (sb, 1); buf[0] = c; } @@ -492,11 +220,6 @@ void MSG_WriteByte (sizebuf_t *sb, int c) { qbyte *buf; -//#ifdef PARANOID -// if (c < 0 || c > 255) -// Sys_Error ("MSG_WriteByte: range error"); -//#endif - buf = SZ_GetSpace (sb, 1); buf[0] = c; } @@ -505,11 +228,6 @@ void MSG_WriteShort (sizebuf_t *sb, int c) { qbyte *buf; -//#ifdef PARANOID -// if (c < ((short)0x8000) || c > (short)0x7fff) -// Sys_Error ("MSG_WriteShort: range error"); -//#endif - buf = SZ_GetSpace (sb, 2); buf[0] = c&0xff; buf[1] = c>>8; @@ -558,27 +276,6 @@ void MSG_WriteDPCoord (sizebuf_t *sb, float f) MSG_WriteShort (sb, (int)(f - 0.5f)); } -// used by client -void MSG_WriteCoord (sizebuf_t *sb, float f) -{ - if (dpprotocol == DPPROTOCOL_VERSION2) - { - if (f >= 0) - MSG_WriteShort (sb, (int)(f + 0.5f)); - else - MSG_WriteShort (sb, (int)(f - 0.5f)); - } - else if (dpprotocol == DPPROTOCOL_VERSION1) - MSG_WriteFloat(sb, f); - else - { - if (f >= 0) - MSG_WriteShort (sb, (int)(f*8.0f + 0.5f)); - else - MSG_WriteShort (sb, (int)(f*8.0f - 0.5f)); - } -} - void MSG_WritePreciseAngle (sizebuf_t *sb, float f) { if (f >= 0) @@ -608,45 +305,6 @@ void MSG_BeginReading (void) msg_badread = false; } -/* -// returns -1 and sets msg_badread if no more characters are available -int MSG_ReadChar (void) -{ - int c; - - // LordHavoc: minor optimization - if (msg_readcount >= net_message.cursize) -// if (msg_readcount+1 > net_message.cursize) - { - msg_badread = true; - return -1; - } - - c = (signed char)net_message.data[msg_readcount]; - msg_readcount++; - - return c; -} - -int MSG_ReadByte (void) -{ - int c; - - // LordHavoc: minor optimization - if (msg_readcount >= net_message.cursize) -// if (msg_readcount+1 > net_message.cursize) - { - msg_badread = true; - return -1; - } - - c = (unsigned char)net_message.data[msg_readcount]; - msg_readcount++; - - return c; -} -*/ - int MSG_ReadShort (void) { int c; @@ -734,7 +392,7 @@ float MSG_ReadDPCoord (void) // used by client float MSG_ReadCoord (void) { - if (dpprotocol == DPPROTOCOL_VERSION2) + if (dpprotocol == DPPROTOCOL_VERSION2 || dpprotocol == DPPROTOCOL_VERSION3) return (signed short) MSG_ReadShort(); else if (dpprotocol == DPPROTOCOL_VERSION1) return MSG_ReadFloat(); @@ -742,23 +400,6 @@ float MSG_ReadCoord (void) return MSG_ReadShort() * (1.0f/8.0f); } -/* -float MSG_ReadCoord (void) -{ - return MSG_ReadShort() * (1.0f/8.0f); -} - -float MSG_ReadAngle (void) -{ - return MSG_ReadChar() * (360.0f/256.0f); -} - -float MSG_ReadPreciseAngle (void) -{ - return MSG_ReadShort() * (360.0f/65536); -} -*/ - //=========================================================================== @@ -793,13 +434,13 @@ void *SZ_GetSpace (sizebuf_t *buf, int length) if (buf->cursize + length > buf->maxsize) { if (!buf->allowoverflow) - Host_Error ("SZ_GetSpace: overflow without allowoverflow set"); + Host_Error ("SZ_GetSpace: overflow without allowoverflow set\n"); if (length > buf->maxsize) - Host_Error ("SZ_GetSpace: %i is > full buffer size", length); + Host_Error ("SZ_GetSpace: %i is > full buffer size\n", length); buf->overflowed = true; - Con_Printf ("SZ_GetSpace: overflow"); + Con_Printf ("SZ_GetSpace: overflow\n"); SZ_Clear (buf); } @@ -817,7 +458,7 @@ void SZ_Write (sizebuf_t *buf, void *data, int length) void SZ_Print (sizebuf_t *buf, char *data) { int len; - + len = strlen(data)+1; // byte * cast to keep VC++ happy @@ -827,6 +468,55 @@ void SZ_Print (sizebuf_t *buf, char *data) memcpy ((qbyte *)SZ_GetSpace(buf, len-1)-1,data,len); // write over trailing 0 } +static char *hexchar = "0123456789ABCDEF"; +void SZ_HexDumpToConsole(sizebuf_t *buf) +{ + int i; + char text[1024]; + char *cur, *flushpointer; + cur = text; + flushpointer = text + 512; + for (i = 0;i < buf->cursize;i++) + { + if ((i & 15) == 0) + { + *cur++ = hexchar[(i >> 12) & 15]; + *cur++ = hexchar[(i >> 8) & 15]; + *cur++ = hexchar[(i >> 4) & 15]; + *cur++ = hexchar[(i >> 0) & 15]; + *cur++ = ':'; + *cur++ = ' '; + } + else if ((i & 15) == 15) + *cur++ = '\n'; + else + *cur++ = ' '; + if (i & 1) + { + *cur++ = hexchar[(buf->data[i] >> 4) & 15] | 0x80; + *cur++ = hexchar[(buf->data[i] >> 0) & 15] | 0x80; + } + else + { + *cur++ = hexchar[(buf->data[i] >> 4) & 15]; + *cur++ = hexchar[(buf->data[i] >> 0) & 15]; + } + if (cur >= flushpointer) + { + *cur++ = 0; + Con_Printf("%s", text); + cur = text; + } + } + if ((i & 15) != 0) + *cur++ = '\n'; + if (cur > text) + { + *cur++ = 0; + Con_Printf("%s", text); + } +} + //============================================================================ @@ -862,13 +552,15 @@ void COM_StripExtension (char *in, char *out) while (*in) { if (*in == '.') - last = in; - if ((*in == '/') || (*in == '\\') || (*in == ':')) + last = out; + else if (*in == '/' || *in == '\\' || *in == ':') last = NULL; *out++ = *in++; } if (last) *last = 0; + else + *out = 0; } /* @@ -977,7 +669,7 @@ skipwhite: return NULL; // end of file; data++; } - + // skip // comments if (c=='/' && data[1] == '/') { @@ -1066,26 +758,16 @@ void COM_CheckRegistered (void) { Cvar_Set ("cmdline", com_cmdline); -// static_registered = 0; - if (!Sys_FileTime("gfx/pop.lmp")) { if (com_modified) Con_Printf ("Playing shareware version, with modification.\nwarning: most mods require full quake data.\n"); else Con_Printf ("Playing shareware version.\n"); -//#if WINDED -// Sys_Error ("This dedicated server requires a full registered copy of Quake"); -//#endif -// Con_Printf ("Playing shareware version.\n"); -// if (com_modified) -// Sys_Error ("You must have the registered version to use modified games"); return; } -// Cvar_Set ("cmdline", com_cmdline); Cvar_Set ("registered", "1"); -// static_registered = 1; Con_Printf ("Playing registered version.\n"); } @@ -1098,95 +780,76 @@ void COM_Path_f (void); COM_InitArgv ================ */ -void COM_InitArgv (int argc, char **argv) +void COM_InitArgv (void) { - qboolean safe; - int i, j, n; - -// reconstitute the command line for the cmdline externally visible cvar + int i, j, n; + // reconstitute the command line for the cmdline externally visible cvar n = 0; - - for (j=0 ; (jnext; -// } for ( ; search ; search = search->next) { @@ -1557,13 +1206,6 @@ int COM_FindFile (char *filename, QFile **file, qboolean quiet, qboolean zip) } else { - // check a file in the directory tree -// if (!static_registered) -// { // if not a registered version, don't ever go beyond base -// if ( strchr (filename, '/') || strchr (filename,'\\')) -// continue; -// } - sprintf (netpath, "%s/%s",search->filename, filename); findtime = Sys_FileTime (netpath); @@ -1584,7 +1226,7 @@ int COM_FindFile (char *filename, QFile **file, qboolean quiet, qboolean zip) #endif cachetime = Sys_FileTime (cachepath); - + if (cachetime < findtime) COM_CopyFile (netpath, cachepath); strcpy (netpath, cachepath); @@ -1685,10 +1327,8 @@ pack_t *COM_LoadPackFile (char *packfile) dpackfile_t *info; if (Sys_FileOpenRead (packfile, &packhandle) == -1) - { - //Con_Printf ("Couldn't open %s\n", packfile); return NULL; - } + Sys_FileRead (packhandle, (void *)&header, sizeof(header)); if (memcmp(header.id, "PACK", 4)) Sys_Error ("%s is not a packfile", packfile); @@ -1741,10 +1381,10 @@ then loads and adds pak1.pak pak2.pak ... */ void COM_AddGameDirectory (char *dir) { - int i; - searchpath_t *search; - pack_t *pak; - char pakfile[MAX_OSPATH]; + stringlist_t *list, *current; + searchpath_t *search; + pack_t *pak; + char pakfile[MAX_OSPATH]; strcpy (com_gamedir, dir); @@ -1756,25 +1396,26 @@ void COM_AddGameDirectory (char *dir) search->next = com_searchpaths; com_searchpaths = search; -// -// add any pak files in the format pak0.pak pak1.pak, ... -// - for (i=0 ; ; i++) + // add any paks in the directory + list = listdirectory(dir); + for (current = list;current;current = current->next) { - sprintf (pakfile, "%s/pak%i.pak", dir, i); - pak = COM_LoadPackFile (pakfile); - if (!pak) - break; - search = Mem_Alloc(pak_mempool, sizeof(searchpath_t)); - search->pack = pak; - search->next = com_searchpaths; - com_searchpaths = search; + if (matchpattern(current->text, "*.pak")) + { + sprintf (pakfile, "%s/%s", dir, current->text); + pak = COM_LoadPackFile (pakfile); + if (pak) + { + search = Mem_Alloc(pak_mempool, sizeof(searchpath_t)); + search->pack = pak; + search->next = com_searchpaths; + com_searchpaths = search; + } + else + Con_Printf("unable to load pak \"%s\"\n", pakfile); + } } - -// -// add the contents of the parms.txt file to the end of the command line -// - + freedirectory(list); } /* @@ -1784,90 +1425,40 @@ COM_InitFilesystem */ void COM_InitFilesystem (void) { - int i, j; - char basedir[MAX_OSPATH]; - searchpath_t *search; + int i; + searchpath_t *search; -// -// -basedir -// Overrides the system supplied base directory (under GAMENAME) -// + strcpy(com_basedir, "."); + + // -basedir + // Overrides the system supplied base directory (under GAMENAME) i = COM_CheckParm ("-basedir"); if (i && i < com_argc-1) - strcpy (basedir, com_argv[i+1]); - else - strcpy (basedir, host_parms.basedir); + strcpy (com_basedir, com_argv[i+1]); - j = strlen (basedir); - - if (j > 0) - { - if ((basedir[j-1] == '\\') || (basedir[j-1] == '/')) - basedir[j-1] = 0; - } - -#if CACHEENABLE -// -// -cachedir -// Overrides the system supplied cache directory (NULL or /qcache) -// -cachedir - will disable caching. -// - i = COM_CheckParm ("-cachedir"); - if (i && i < com_argc-1) - { - if (com_argv[i+1][0] == '-') - com_cachedir[0] = 0; - else - strcpy (com_cachedir, com_argv[i+1]); - } - else if (host_parms.cachedir) - strcpy (com_cachedir, host_parms.cachedir); - else - com_cachedir[0] = 0; -#endif + i = strlen (com_basedir); + if (i > 0 && (com_basedir[i-1] == '\\' || com_basedir[i-1] == '/')) + com_basedir[i-1] = 0; // start up with GAMENAME by default (id1) - COM_AddGameDirectory (va("%s/"GAMENAME, basedir) ); - - switch(gamemode) + COM_AddGameDirectory (va("%s/"GAMENAME, com_basedir)); + if (gamedirname[0]) { - case GAME_NORMAL: - break; - case GAME_HIPNOTIC: - COM_AddGameDirectory (va("%s/hipnotic", basedir) ); - break; - case GAME_ROGUE: - COM_AddGameDirectory (va("%s/rogue", basedir) ); - break; - case GAME_NEHAHRA: - COM_AddGameDirectory (va("%s/nehahra", basedir) ); - break; - case GAME_FIENDARENA: - COM_AddGameDirectory (va("%s/fiendarena", basedir) ); - break; - case GAME_ZYMOTIC: - COM_AddGameDirectory (va("%s/zymotic", basedir) ); - break; - default: - Sys_Error("COM_InitFilesystem: unknown gamemode %i\n", gamemode); - break; + com_modified = true; + COM_AddGameDirectory (va("%s/%s", com_basedir, gamedirname)); } -// -// -game -// Adds basedir/gamedir as an override game -// + // -game + // Adds basedir/gamedir as an override game i = COM_CheckParm ("-game"); if (i && i < com_argc-1) { com_modified = true; - COM_AddGameDirectory (va("%s/%s", basedir, com_argv[i+1])); + COM_AddGameDirectory (va("%s/%s", com_basedir, com_argv[i+1])); } -// -// -path [] ... -// Fully specifies the exact search path, overriding the generated one -// + // -path [] ... + // Fully specifies the exact search path, overriding the generated one i = COM_CheckParm ("-path"); if (i) { @@ -1891,9 +1482,6 @@ void COM_InitFilesystem (void) com_searchpaths = search; } } - -// if (COM_CheckParm ("-proghack")) -// proghack = true; } int COM_FileExists(char *filename) @@ -1950,3 +1538,12 @@ void COM_ToUpperString(char *in, char *out) *out++ = *in++; } } + +int COM_StringBeginsWith(const char *s, const char *match) +{ + for (;*s && *match;s++, match++) + if (*s != *match) + return false; + return true; +} +