/* <845bc> ../engine/r_studio.c:5809 */ int R_GetStudioBounds(const char *filename, float *mins, float *maxs) { int iret = 0; qboolean usingReadBuffer = 0; for (int i = 0; i < 3; i++) mins[0] = maxs[0] = vec3_origin[i]; if (!Q_strstr(filename, "models") || !Q_strstr(filename, ".mdl")) return 0; FileHandle_t fp = FS_Open(filename, "rb"); if (!fp) return 0; int length; char *pBuffer = (char *)FS_GetReadBuffer(fp, &length); if (pBuffer) usingReadBuffer = 1; else pBuffer = (char*) COM_LoadFile(filename, 5, 0); if (pBuffer) { if (LittleLong(*(unsigned int *)pBuffer) == 'TSDI') iret = R_StudioComputeBounds((unsigned char*)pBuffer, mins, maxs); #ifndef REHLDS_FIXES //wrong release memory code else COM_FreeFile(pBuffer); #endif } if (usingReadBuffer) FS_ReleaseReadBuffer(fp, pBuffer); else COM_FreeFile(pBuffer); FS_Close(fp); return iret; }
bool GetModelNameFromSourceFile( char const *filename, char *modelname, int maxlen ) { modelname[0]=0; int filelength; char *buffer = (char *)COM_LoadFile( filename, &filelength ); if ( !buffer ) { vprint( 0, "Couldn't load %s\n", filename ); return false; } bool valid = false; // Parse tokens char *current = buffer; while ( current ) { current = CC_ParseToken( current ); if ( strlen( com_token ) <= 0 ) break; if ( stricmp( com_token, "$modelname" ) ) continue; current = CC_ParseToken( current ); strcpy( modelname, com_token ); _strlwr( modelname ); Q_FixSlashes( modelname ); Q_DefaultExtension( modelname, ".mdl", maxlen ); valid = true; break; } COM_FreeFile( (unsigned char *)buffer ); if ( !valid ) { vprint( 0, ".qc file %s missing $modelname directive!!!\n", filename ); } return valid; }
bool CServerRemoteAccess::LookupValue(const char *variable, CUtlBuffer &value) { const char* strval = LookupStringValue(variable); if (strval) { value.PutString(strval); value.PutChar(0); return true; } if (!Q_stricmp(variable, "stats")) { char stats[512]; GetStatsString(stats, sizeof(stats)); value.PutString(stats); value.PutChar(0); return true; } if (!Q_stricmp(variable, "banlist")) { GetUserBanList(value); return true; } if (!Q_stricmp(variable, "playerlist")) { GetPlayerList(value); return true; } if (!Q_stricmp(variable, "maplist")) { GetMapList(value); return true; } if (!Q_stricmp(variable, "uptime")) { value.PutInt(int(Sys_FloatTime() - Host_GetStartTime())); value.PutChar(0); return true; } if (!Q_stricmp(variable, "ipaddress")) { value.PutString(NET_AdrToString(net_local_adr)); value.PutChar(0); return true; } if (!Q_stricmp(variable, "mapcycle")) { int len; void* mapcyclelist = COM_LoadFileForMe(mapcyclefile.string, &len); if (mapcyclelist && len) { value.PutString((char*)mapcyclelist); value.PutChar(0); COM_FreeFile(mapcyclelist); } return true; } value.PutChar(0); return false; }
void CCodeProcessor::ProcessModule( bool forcequiet, int depth, int& maxdepth, int& numheaders, int& skippedfiles, const char *srcroot, const char *baseroot, const char *root, const char *module ) { char filename[ 256 ]; if ( depth > maxdepth ) { maxdepth = depth; } int filelength; char *buffer = NULL; // Always skip these particular modules/headers if ( SkipFile( module ) ) { CODE_MODULE module; module.skipped = true; m_Modules.Insert( filename, module ); skippedfiles++; return; } if ( !LoadFile( &buffer, filename, module, forcequiet, depth, filelength, numheaders, skippedfiles, srcroot, root, baseroot ) ) { CODE_MODULE module; module.skipped = true; m_Modules.Insert( filename, module ); skippedfiles++; return; } assert( buffer ); m_nBytesProcessed += filelength; CODE_MODULE m; m.skipped = false; m_Modules.Insert( filename, m ); if ( !forcequiet ) { strcpy( m_szCurrentCPP, filename ); } AddHeader( depth, filename, m_szCurrentCPP ); bool onclient = !strnicmp( m_szBaseEntityClass, "C_", 2 ) ? true : false; // Parse tokens looking for #include directives or class starts char *current = buffer; current = CC_ParseToken( current ); while ( 1 ) { // No more tokens if ( !current ) break; if ( !stricmp( com_token, "#include" ) ) { current = CC_ParseToken( current ); if ( strlen( com_token ) > 0 && com_token[ 0 ] != '<' ) { //vprint( "#include %s\n", com_token ); m_nHeadersProcessed++; numheaders++; ProcessModule( true, depth + 1, maxdepth, numheaders, skippedfiles, srcroot, baseroot, root, com_token ); } } else if ( !stricmp( com_token, "class" ) || !stricmp( com_token, "struct" ) ) { current = CC_ParseToken( current ); if ( strlen( com_token ) > 0 ) { //vprint( depth, "class %s\n", com_token ); CClass *cl = AddClass( com_token ); // Now see if there's a base class current = CC_ParseToken( current ); if ( !stricmp( com_token, ":" ) ) { // Parse out public and then classname an current = CC_ParseToken( current ); if ( !stricmp( com_token, "public" ) ) { current = CC_ParseToken( current ); if ( strlen( com_token ) > 0 ) { cl->SetBaseClass( com_token ); do { current = CC_ParseToken( current ); } while ( strlen( com_token ) && stricmp( com_token, "{" ) ); if ( !stricmp( com_token, "{" ) ) { current = cl->ParseClassDeclaration( current ); } } } } else if ( !stricmp( com_token, "{" ) ) { current = cl->ParseClassDeclaration( current ); } } } else if ( !strnicmp( com_token, "PREDICTABLE_CLASS", strlen( "PREDICTABLE_CLASS" ) ) ) { char prefix[ 32 ]; prefix[ 0 ] = 0; int type = 0; int bases = 1; int usebase = 0; if ( !stricmp( com_token, "PREDICTABLE_CLASS_ALIASED" ) ) { type = 2; bases = 2; if ( onclient ) { strcpy( prefix, "C_" ); } else { strcpy( prefix, "C" ); usebase = 1; } } else if ( !stricmp( com_token, "PREDICTABLE_CLASS_SHARED" ) ) { type = 1; bases = 1; } else if ( !stricmp( com_token, "PREDICTABLE_CLASS" ) ) { type = 0; bases = 1; if ( onclient ) { strcpy( prefix, "C_" ); } else { strcpy( prefix, "C" ); } } else if ( !stricmp( com_token, "PREDICTABLE_CLASS_ALIASED_PREFIXED" ) ) { // Nothing } else { vprint( 0, "PREDICTABLE_CLASS of unknown type!!! %s\n", com_token ); } // parse the ( current = CC_ParseToken( current ); if ( !strcmp( com_token, "(" ) ) { // Now the classname current = CC_ParseToken( current ); if ( strlen( com_token ) > 0 ) { //vprint( depth, "class %s\n", com_token ); CClass *cl = AddClass( com_token ); // Now see if there's a base class current = CC_ParseToken( current ); if ( !stricmp( com_token, "," ) ) { // Parse out public and then classname an current = CC_ParseToken( current ); if ( strlen( com_token ) > 0 ) { char basename[ 256 ]; sprintf( basename, "%s%s", prefix, com_token ); bool valid = true; if ( bases == 2 ) { valid = false; current = CC_ParseToken( current ); if ( !stricmp( com_token, "," ) ) { current = CC_ParseToken( current ); if ( strlen( com_token ) > 0 ) { valid = true; if ( usebase == 1 ) { sprintf( basename, "%s%s", prefix, com_token ); } } } } if ( valid ) { cl->SetBaseClass( basename ); strcpy( cl->m_szTypedefBaseClass, basename ); } do { current = CC_ParseToken( current ); } while ( strlen( com_token ) && stricmp( com_token, ")" ) ); if ( !stricmp( com_token, ")" ) ) { current = cl->ParseClassDeclaration( current ); } } } else if ( !stricmp( com_token, ")" ) ) { current = cl->ParseClassDeclaration( current ); } } } } else if ( !strcmp( com_token, "TYPEDESCRIPTION" ) || !strcmp( com_token, "typedescription_t" ) ) { current = ParseTypeDescription( current, false ); } else if ( !strcmp( com_token, "BEGIN_DATADESC" ) || !strcmp( com_token, "BEGIN_DATADESC_NO_BASE" ) || !strcmp( com_token, "BEGIN_SIMPLE_DATADESC" ) ) { current = ParseTypeDescription( current, true ); } else if ( !strcmp( com_token, "BEGIN_PREDICTION_DATA" ) || !strcmp( com_token, "BEGIN_EMBEDDED_PREDDESC" ) ) { current = ParsePredictionTypeDescription( current ); } else if ( !strcmp( com_token, "BEGIN_RECV_TABLE" ) || !strcmp( com_token, "BEGIN_RECV_TABLE_NOBASE" ) || !strcmp( com_token, "IMPLEMENT_CLIENTCLASS_DT" ) || !strcmp( com_token, "IMPLEMENT_CLIENTCLASS_DT_NOBASE" ) ) { current = ParseReceiveTable( current ); } else if ( !strcmp( com_token, "IMPLEMENT_PREDICTABLE_NODATA" ) ) { current = CC_ParseToken( current ); if ( !strcmp( com_token, "(" ) ) { current = CC_ParseToken( current ); CClass *cl = FindClass( com_token ); if ( cl ) { if ( cl->m_bHasPredictionData ) { if ( !forcequiet ) { vprint( 0, "Class %s declared predictable and implemented with IMPLEMENT_PREDICTABLE_NODATA in typedescription\n", cl->m_szName ); } cl->m_bHasPredictionData = false; } } current = CC_ParseToken( current ); } } current = CC_ParseToken( current ); } COM_FreeFile( (unsigned char *)buffer ); if ( !forcequiet && !GetQuiet() ) { vprint( 0, " %s: headers (%i game / %i total)", (char *)&filename[ m_nOffset ], numheaders - skippedfiles, numheaders ); if ( maxdepth > 1 ) { vprint( 0, ", depth %i", maxdepth ); } vprint( 0, "\n" ); } m_nLinesOfCode += linesprocessed; linesprocessed = 0; }
void CCodeProcessor::ProcessModule( bool forcequiet, int depth, int& maxdepth, int& numheaders, int& skippedfiles, const char *baseroot, const char *root, const char *module ) { char filename[ 256 ]; bool checkroot = false; if ( depth > maxdepth ) { maxdepth = depth; } // Load the base module sprintf( filename, "%s\\%s", root, module ); strlwr( filename ); bool firstheader = true; retry: // Check module list for ( int i = 0; i < m_nModuleCount; i++ ) { if ( !stricmp( m_Modules[ i ].name, filename ) ) { if ( forcequiet ) { m_nHeadersProcessed++; numheaders++; if ( m_Modules[ i ].skipped ) { skippedfiles++; } } AddHeader( depth, filename, m_szCurrentCPP ); return; } } int filelength; char *buffer = (char *)COM_LoadFile( filename, &filelength ); if ( !buffer ) { if ( !checkroot ) { checkroot = true; // Load the base module sprintf( filename, "%s\\%s", baseroot, module ); goto retry; } m_Modules[ m_nModuleCount ].skipped = true; strcpy( m_Modules[ m_nModuleCount++ ].name, filename ); skippedfiles++; return; } m_nBytesProcessed += filelength; m_Modules[ m_nModuleCount ].skipped = false; strcpy( m_Modules[ m_nModuleCount++ ].name, filename ); bool readonly = false; bool madechanges = false; CreateBackup( filename, readonly ); if ( !forcequiet ) { strcpy( m_szCurrentCPP, filename ); vprint( 0, "- %s\n", (char *)&filename[ m_nOffset ] ); } // Parse tokens looking for #include directives or class starts char *current = buffer; char *startofline; current = CC_ParseToken( current ); while ( current ) { // No more tokens if ( strlen( com_token ) <= 0 ) break; if ( !stricmp( com_token, "#include" ) ) { startofline = current - strlen( "#include" ); current = CC_ParseToken( current ); if ( strlen( com_token ) > 0) { vprint( 1, "#include %s", com_token ); m_nHeadersProcessed++; numheaders++; AddHeader( depth, filename, m_szCurrentCPP ); bool dobuild = true; if ( firstheader ) { if ( !stricmp( com_token, "cbase.h" ) ) { dobuild = false; } if ( !TryBuild( baseroot, filename, (unsigned char *)buffer, filelength ) ) { // build is broken, stop assert( 0 ); } } firstheader = false; if ( dobuild ) { // Try removing the header and compiling char saveinfo[2]; memcpy( saveinfo, startofline, 2 ); startofline[ 0 ] = '/'; startofline[ 1 ] = '/'; if ( TryBuild( baseroot, filename, (unsigned char *)buffer, filelength ) ) { vprint( 0, ", unnecessary\n" ); madechanges = true; } else { // Restore line memcpy( startofline, saveinfo, 2 ); vprint( 0, "\n" ); } } else { vprint( 0, "\n" ); } } } current = CC_ParseToken( current ); } // Save out last set of changes { FILE *fp; fp = fopen( filename, "wb" ); if ( fp ) { fwrite( buffer, filelength, 1, fp ); fclose( fp ); } } COM_FreeFile( (unsigned char *)buffer ); if ( !madechanges ) { RestoreBackup( filename, readonly ); } if ( !forcequiet && !GetQuiet() ) { vprint( 0, " %s: headers (%i)", (char *)&filename[ m_nOffset ], numheaders ); if ( maxdepth > 1 ) { vprint( 0, ", depth %i", maxdepth ); } vprint( 0, "\n" ); } m_nLinesOfCode += linesprocessed; linesprocessed = 0; }
void SystemWrapper::FreeFile(unsigned char *fileHandle) { COM_FreeFile(fileHandle); }
void Master_Init() { int i, SkipSection, tempport; static int HaveConfigured = 0; char * filep; const char * curfilep; netadr_t tempadr; if(HaveConfigured != 0 || gfNoMasterServer != 0) { return; } HaveConfigured = 1; if(COM_CheckParmCase("-nomaster") != 0 || global_svs.allocated_client_slots <= 1) { Con_Printf("%s: Master server comm disabled.\n", __FUNCTION__); gfNoMasterServer = 0; return; //and don't check again, ever. } MasterHeartbeatTimeout = 15; i = COM_CheckParmCase("-comm"); if(i != 0 && i+1 < global_com_argc) { filep = COM_LoadFileForMe(global_com_argv[i+1], NULL); } else { filep = COM_LoadFileForMe("valvecomm.lst", NULL); if(filep == NULL) { filep = COM_LoadFileForMe("woncomm.lst", NULL); } } if(filep == NULL) { Con_Printf("%s: Couldn't load comm file. Disabling masters--fix it.\n", __FUNCTION__); return; } curfilep = filep; i = 0; while(1) { curfilep = COM_Parse(curfilep); if(global_com_token[0] == '\0') { break; } SkipSection = 1; if(Q_strcasecmp("master", global_com_token) == 0) { SkipSection = 0; } curfilep = COM_Parse(curfilep); if(Q_strcmp("{", global_com_token) != 0) { break; } while(1) { curfilep = COM_Parse(curfilep); if(global_com_token[0] == '\0' || Q_strcmp("}", global_com_token) == 0) { break; } if(SkipSection == 0 && NET_StringToAdr(global_com_token, &tempadr) == 0) { break; } //We just (maybe) parsed the server name, if you missed it. Now for the port. curfilep = COM_Parse(curfilep); if(Q_strcmp(":", global_com_token) != 0) { break; } curfilep = COM_Parse(curfilep); if(global_com_token[0] == '\0') { break; } if(SkipSection == 0) { tempport = Q_atoi(global_com_token); if(tempport < 1 || tempport > 65535) { tempport = 27010; } tempadr.port = tempport; Con_Printf("%s: Adding master server %s.\n", __FUNCTION__, NET_AdrToString(tempadr)); //all that work to avoid needless string copying, all gone :) Master_AddServer(&tempadr); i++; } } } COM_FreeFile(filep); if(i == 0) { Con_Printf("%s: Didn't parse any masters. Disabling master comm.\n", __FUNCTION__); gfNoMasterServer = 0; } }