void Sys_AddDefaultConfig(void) { FILE *fp; struct stat st; size_t len, r; fp = fopen(SYS_SITE_CFG, "r"); if (!fp) { return; } if (fstat(fileno(fp), &st) == 0) { len = st.st_size; if (len >= cmd_buffer.maxsize) { len = cmd_buffer.maxsize - 1; } r = fread(cmd_buffer.text, 1, len, fp); cmd_buffer.text[r] = 0; cmd_buffer.cursize = COM_Compress(cmd_buffer.text); } fclose(fp); if (cmd_buffer.cursize) { Com_Printf("Execing %s\n", SYS_SITE_CFG); Cbuf_Execute(&cmd_buffer); } }
/* =============== UI_LoadBotsFromFile =============== */ static void UI_LoadBotsFromFile( char *filename ) { int len; fileHandle_t f; char buf[MAX_BOTS_TEXT]; len = trap_FS_FOpenFile( filename, &f, FS_READ ); if( !f ) { trap_Print( va( S_COLOR_RED "file not found: %s\n", filename ) ); return; } if( len >= MAX_BOTS_TEXT ) { trap_Print( va( S_COLOR_RED "file too large: %s is %i, max allowed is %i", filename, len, MAX_BOTS_TEXT ) ); trap_FS_FCloseFile( f ); return; } trap_FS_Read( buf, len, f ); buf[len] = 0; trap_FS_FCloseFile( f ); COM_Compress( buf ); ui_numBots += UI_ParseInfos( buf, MAX_BOTS - ui_numBots, &ui_botInfos[ui_numBots] ); }
void CM_LoadShaderFiles( void ) { if( !shaderText ) { char **shaderFiles1; int numShaders1; char *buffers[MAX_SHADER_FILES]; int numShaders; int i; int sum = 0; // scan for shader files shaderFiles1 = FS_ListFiles( "shaders", ".shader", &numShaders1 ); if ( !shaderFiles1 || !numShaders1 ) { Com_Printf( S_COLOR_YELLOW "WARNING: no shader files found\n" ); return; } numShaders = numShaders1; if ( numShaders > MAX_SHADER_FILES ) { numShaders = MAX_SHADER_FILES; } // load and parse shader files for ( i = 0; i < numShaders1; i++ ) { char filename[MAX_QPATH]; Com_sprintf( filename, sizeof( filename ), "shaders/%s", shaderFiles1[i] ); Com_DPrintf( "...loading '%s'\n", filename ); FS_ReadFile( filename, (void **)&buffers[i] ); if ( !buffers[i] ) { Com_Error( ERR_FATAL, "Couldn't load %s", filename ); } sum += COM_Compress( buffers[i] ); } // build single large buffer shaderText = (char *)Z_Malloc( sum + numShaders * 2, TAG_SHADERTEXT, qtrue); // free in reverse order, so the temp files are all dumped for ( i = numShaders - 1; i >= 0 ; i-- ) { strcat( shaderText, "\n" ); strcat( shaderText, buffers[i] ); FS_FreeFile( buffers[i] ); } // free up memory FS_FreeFileList( shaderFiles1 ); } }
void UI_SaberLoadParms( void ) { int len, totallen, saberExtFNLen, fileCnt, i; char *buffer, *holdChar, *marker; char saberExtensionListBuf[2048]; // The list of file names read in //ui.Printf( "UI Parsing *.sab saber definitions\n" ); ui_saber_parms_parsed = qtrue; UI_CacheSaberGlowGraphics(); //set where to store the first one totallen = 0; marker = SaberParms; marker[0] = '\0'; //now load in the sabers fileCnt = ui.FS_GetFileList("ext_data/sabers", ".sab", saberExtensionListBuf, sizeof(saberExtensionListBuf) ); holdChar = saberExtensionListBuf; for ( i = 0; i < fileCnt; i++, holdChar += saberExtFNLen + 1 ) { saberExtFNLen = strlen( holdChar ); len = ui.FS_ReadFile( va( "ext_data/sabers/%s", holdChar), (void **) &buffer ); if ( len == -1 ) { ui.Printf( "UI_SaberLoadParms: error reading %s\n", holdChar ); } else { if ( totallen && *(marker-1) == '}' ) {//don't let it end on a } because that should be a stand-alone token strcat( marker, " " ); totallen++; marker++; } len = COM_Compress( buffer ); if ( totallen + len >= MAX_SABER_DATA_SIZE ) { Com_Error( ERR_FATAL, "UI_SaberLoadParms: ran out of space before reading %s\n(you must make the .npc files smaller)", holdChar ); } strcat( marker, buffer ); ui.FS_FreeFile( buffer ); totallen += len; marker += len; } } }
/* =============== UI_LoadBotsFromFile =============== */ static void UI_LoadBotsFromFile( char *filename ) { int len; fileHandle_t f; char buf[MAX_BOTS_TEXT]; char *stopMark; len = trap->FS_Open( filename, &f, FS_READ ); if ( !f ) { trap->Print( S_COLOR_RED "file not found: %s\n", filename ); return; } if ( len >= MAX_BOTS_TEXT ) { trap->Print( S_COLOR_RED "file too large: %s is %i, max allowed is %i", filename, len, MAX_BOTS_TEXT ); trap->FS_Close( f ); return; } trap->FS_Read( buf, len, f ); buf[len] = 0; stopMark = strstr(buf, "@STOPHERE"); //This bot is in place as a mark for modview's bot viewer. //If we hit it just stop and trace back to the beginning of the bot define and cut the string off. //This is only done in the UI and not the game so that "test" bots can be added manually and still //not show up in the menu. if (stopMark) { int startPoint = stopMark - buf; while (buf[startPoint] != '{') { startPoint--; } buf[startPoint] = 0; } trap->FS_Close( f ); COM_Compress(buf); ui_numBots += UI_ParseInfos( buf, MAX_BOTS - ui_numBots, &ui_botInfos[ui_numBots] ); }
/* =============== Cmd_ExecFile =============== */ static void Cmd_ExecFile( char *f ) { int i; COM_Compress (f); Cvar_Get( "arg_all", Cmd_ArgsFrom(2), CVAR_TEMP | CVAR_ROM | CVAR_USER_CREATED, "" ); Cvar_Set( "arg_all", Cmd_ArgsFrom(2) ); Cvar_Get( "arg_count", va( "%i", Cmd_Argc() - 2 ), CVAR_TEMP | CVAR_ROM | CVAR_USER_CREATED, "" ); Cvar_Set( "arg_count", va( "%i", Cmd_Argc() - 2 ) ); for (i = Cmd_Argc() - 2; i; i--) { Cvar_Get( va("arg_%i", i), Cmd_Argv( i + 1 ), CVAR_TEMP | CVAR_ROM | CVAR_USER_CREATED, "" ); Cvar_Set( va("arg_%i", i), Cmd_Argv( i + 1 ) ); } Cbuf_InsertText (f); }
/* ====================== UI_ParseAnimationFile ====================== */ static qbool UI_ParseAnimationFile( const char *filename, animation_t *animations ) { char *text_p, *prev; int len; int i; char *token; float fps; int skip; char text[20000]; fileHandle_t f; memset( animations, 0, sizeof( animation_t ) * MAX_ANIMATIONS ); // load the file len = trap_FS_FOpenFile( filename, &f, FS_READ ); if ( len <= 0 ) { return qfalse; } if ( len >= ( sizeof( text ) - 1 ) ) { Com_Printf( "File %s too long\n", filename ); trap_FS_FCloseFile( f ); return qfalse; } trap_FS_Read( text, len, f ); text[len] = 0; trap_FS_FCloseFile( f ); COM_Compress(text); // parse the text text_p = text; skip = 0; // quite the compiler warning // read optional parameters while ( 1 ) { prev = text_p; // so we can unget token = COM_Parse( &text_p ); if ( !token ) { break; } if ( !Q_stricmp( token, "footsteps" ) ) { token = COM_Parse( &text_p ); if ( !token ) { break; } continue; } else if ( !Q_stricmp( token, "headoffset" ) ) { for ( i = 0 ; i < 3 ; i++ ) { token = COM_Parse( &text_p ); if ( !token ) { break; } } continue; } else if ( !Q_stricmp( token, "sex" ) ) { token = COM_Parse( &text_p ); if ( !token ) { break; } continue; } // if it is a number, start parsing animations if ( token[0] >= '0' && token[0] <= '9' ) { text_p = prev; // unget the token break; } Com_Printf( "unknown token '%s' is %s\n", token, filename ); } // read information for each frame for ( i = 0 ; i < MAX_ANIMATIONS ; i++ ) { token = COM_Parse( &text_p ); if ( !token ) { break; } animations[i].firstFrame = atoi( token ); token = COM_Parse( &text_p ); if ( !token ) { break; } animations[i].numFrames = atoi( token ); token = COM_Parse( &text_p ); if ( !token ) { break; } animations[i].loopFrames = atoi( token ); token = COM_Parse( &text_p ); if ( !token ) { break; } fps = atof( token ); if ( fps == 0 ) { fps = 1; } animations[i].frameLerp = 1000 / fps; animations[i].initialLerp = 1000 / fps; } if ( i != MAX_ANIMATIONS ) { Com_Printf( "Error parsing animation file: %s", filename ); return qfalse; } return qtrue; }
//============================================================================ // // Parameter: - // Returns: - // Changes Globals: - //============================================================================ script_t *LoadScriptFile(const char *filename) { #ifdef BOTLIB fileHandle_t fp; char pathname[MAX_QPATH]; #else FILE *fp; #endif int length; void *buffer; script_t *script; #ifdef BOTLIB if (strlen(basefolder)) Com_sprintf(pathname, sizeof(pathname), "%s/%s", basefolder, filename); else Com_sprintf(pathname, sizeof(pathname), "%s", filename); length = botimport.FS_FOpenFile( pathname, &fp, FS_READ ); if (!fp) return NULL; #else fp = fopen(filename, "rb"); if (!fp) return NULL; length = FileLength(fp); #endif buffer = GetClearedMemory(sizeof(script_t) + length + 1); script = (script_t *) buffer; Com_Memset(script, 0, sizeof(script_t)); strcpy(script->filename, filename); script->buffer = (char *) buffer + sizeof(script_t); script->buffer[length] = 0; script->length = length; //pointer in script buffer script->script_p = script->buffer; //pointer in script buffer before reading token script->lastscript_p = script->buffer; //pointer to end of script buffer script->end_p = &script->buffer[length]; //set if there's a token available in script->token script->tokenavailable = 0; // script->line = 1; script->lastline = 1; // SetScriptPunctuations(script, NULL); // #ifdef BOTLIB botimport.FS_Read(script->buffer, length, fp); botimport.FS_FCloseFile(fp); #else if (fread(script->buffer, length, 1, fp) != 1) { FreeMemory(buffer); script = NULL; } //end if fclose(fp); #endif // script->length = COM_Compress(script->buffer); return script; } //end of the function LoadScriptFile
void CG_LoadLensFlareEntities(void) { char name[256]; fileHandle_t f; int len; char* p; #if LFDEBUG CG_LoadingString("LF: CG_LoadLensFlareEntities()"); #endif cgs.numLensFlareEntities = 0; memset(&cgs.lensFlareEntities, 0, sizeof(cgs.lensFlareEntities)); if (cgs.sunFlareEffect[0]) { lensFlareEntity_t* lfent; vec3_t angles; vec3_t sunDir; lfent = &cgs.sunFlare; lfent->lfeff = CG_FindLensFlareEffect(cgs.sunFlareEffect); if (!lfent->lfeff) { CG_Printf(S_COLOR_YELLOW "undefined sun flare effect '%s'\n", cgs.sunFlareEffect); } angles[YAW] = cgs.sunFlareYaw; angles[PITCH] = -cgs.sunFlarePitch; angles[ROLL] = 0; AngleVectors(angles, sunDir, NULL, NULL); VectorScale(sunDir, cgs.sunFlareDistance, lfent->origin); lfent->radius = 150; lfent->lightRadius = 100; lfent->angle = -1; CG_ComputeMaxVisAngle(lfent); CG_Printf("sun flare entity created\n"); } Com_sprintf(name, sizeof(name), "maps/%s.lfe", Info_ValueForKey(CG_ConfigString(CS_SERVERINFO), "mapname")); len = trap_FS_FOpenFile(name, &f, FS_READ); if (!f) { CG_Printf("'%s' not found\n", name); return; } if (len >= sizeof(lfbuf)) { CG_Printf(S_COLOR_YELLOW "file too large: '%s' > %d\n", name, sizeof(lfbuf)-1); return; } CG_Printf("reading '%s'...\n", name); #if LFDEBUG CG_LoadingString(va("%s", name)); #endif trap_FS_Read(lfbuf, len, f); lfbuf[len] = 0; trap_FS_FCloseFile(f); COM_Compress(lfbuf); p = lfbuf; // parse all lens flare entities while (cgs.numLensFlareEntities < MAX_LIGHTS_PER_MAP && p) { if (!CG_ParseLensFlareEntity(&p, &cgs.lensFlareEntities[cgs.numLensFlareEntities])) { break; } cgs.numLensFlareEntities++; } CG_Printf("%d lens flare entities loaded\n", cgs.numLensFlareEntities); #if LFDEBUG CG_LoadingString("LF: CG_LoadLensFlareEntities() ready"); #endif }
void UI_SaberLoadParms( void ) { int len, totallen, saberExtFNLen, fileCnt, i; char *holdChar, *marker; char saberExtensionListBuf[2048]; // The list of file names read in fileHandle_t f; char buffer[MAX_MENUFILE]; //[DynamicMemory_Sabers] #ifdef DYNAMICMEMORY_SABERS int maxLen; #endif //[/DynamicMemory_Sabers] //ui.Printf( "UI Parsing *.sab saber definitions\n" ); ui_saber_parms_parsed = qtrue; UI_CacheSaberGlowGraphics(); //[DynamicMemory_Sabers] moved down lower /* //set where to store the first one totallen = 0; marker = SaberParms; marker[0] = '\0'; */ //we werent initilizing saberExtFNLen, which is Bad //this is just a general bug fix, not for the purpose of [DynamicMemory_Sabers] saberExtFNLen = 0; ///[DynamicMemory_Sabers] //now load in the extra .npc extensions fileCnt = trap_FS_GetFileList("ext_data/sabers", ".sab", saberExtensionListBuf, sizeof(saberExtensionListBuf) ); holdChar = saberExtensionListBuf; //[DynamicMemory_Sabers] #ifdef DYNAMICMEMORY_SABERS maxLen = 0; saberExtFNLen = -1; for ( i = 0; i < fileCnt; i++, holdChar += saberExtFNLen + 1 ) { saberExtFNLen = strlen( holdChar ); len = trap_FS_FOpenFile( va( "ext_data/sabers/%s", holdChar), &f, FS_READ ); if(!f) continue; trap_FS_FCloseFile(f); maxLen += len; } //what do we do if totallen is zero? will never happen, but COULD happen in theory... //trap_TrueMalloc(&SaberParms, totallen+1); //+1 for null char, needed? maxLen++; //for ending null char UI_AllocMem(&SaberParms, maxLen); if(!SaberParms) //ERR_FATAL or any level isnt used with Com_Error Com_Error(ERR_FATAL, "Saber parsing: Out of memory!"); holdChar = saberExtensionListBuf; #endif //[/DynamicMemory_Sabers] //[DynamicMemory_Sabers] moved to here //set where to store the first one totallen = 0; marker = SaberParms; marker[0] = '\0'; saberExtFNLen = -1; ///[DynamicMemory_Sabers] for ( i = 0; i < fileCnt; i++, holdChar += saberExtFNLen + 1 ) { saberExtFNLen = strlen( holdChar ); len = trap_FS_FOpenFile( va( "ext_data/sabers/%s", holdChar), &f, FS_READ ); if (!f) { continue; } if ( len == -1 ) { Com_Printf( "UI_SaberLoadParms: error reading %s\n", holdChar ); } else { if (len > sizeof(buffer) ) { Com_Error( ERR_FATAL, "UI_SaberLoadParms: file %s too large to read (max=%d)", holdChar, sizeof(buffer) ); } trap_FS_Read( buffer, len, f ); trap_FS_FCloseFile( f ); buffer[len] = 0; if ( totallen && *(marker-1) == '}' ) {//don't let it end on a } because that should be a stand-alone token strcat( marker, " " ); totallen++; marker++; } len = COM_Compress( buffer ); //[DynamicMemory_Sabers] #ifndef DYNAMICMEMORY_SABERS if ( totallen + len >= MAX_SABER_DATA_SIZE ) { Com_Error( ERR_FATAL, "UI_SaberLoadParms: ran out of space before reading %s\n(you must make the .sab files smaller)", holdChar ); } #else if ( totallen + len >= maxLen ) { Com_Error( ERR_FATAL, "UI_SaberLoadParms: ran out of space before reading %s\n(This should never happen)", holdChar ); } #endif //[/DynamicMemory_Sabers] strcat( marker, buffer ); totallen += len; marker += len; } } }
/* * G_SetClan */ static void G_SetClan( edict_t *ent, const char *original_clan ) { const char *invalid_values[] = { "console", "spec", "bot", "coach", "tv", NULL }; char clan[MAX_CLANNAME_BYTES]; char colorless[MAX_CLANNAME_BYTES]; int i; int c_ascii; int maxchars; if( !ent->r.client ) return; // we allow NULL to be passed for clan name if( ent->r.svflags & SVF_FAKECLIENT ) original_clan = "BOT"; else if( !original_clan ) original_clan = ""; Q_strncpyz( clan, original_clan, sizeof( clan ) ); COM_Compress( clan ); c_ascii = G_SanitizeUserString( clan, sizeof( clan ) ); if( !c_ascii ) clan[0] = colorless[0] = '\0'; else Q_strncpyz( colorless, COM_RemoveColorTokens( clan ), sizeof( colorless ) ); if( !( ent->r.svflags & SVF_FAKECLIENT ) ) { for( i = 0; invalid_values[i] != NULL; i++ ) { if( !Q_strnicmp( colorless, invalid_values[i], strlen( invalid_values[i] ) ) ) { clan[0] = colorless[0] = '\0'; break; } } } // clan names can not contain spaces Q_chrreplace( clan, ' ', '_' ); // clan names can not start with an ampersand { char *t; int len; t = clan; while( *t == '&' ) t++; len = strlen( clan ) - (t - clan); if( clan != t ) memmove( clan, t, len + 1 ); } maxchars = MAX_CLANNAME_CHARS; // Limit the name to MAX_NAME_CHARS printable characters // (non-ascii utf-8 sequences are currently counted as 2 or more each, sorry) COM_SanitizeColorString( va( "%s", clan ), clan, sizeof( clan ), maxchars, COLOR_WHITE ); Q_strncpyz( ent->r.client->clanname, clan, sizeof( ent->r.client->clanname ) ); }
static qboolean Parse_File(const char *path, int depth) { char *raw, *data, *p, *cmd; int argc; menuFrameWork_t *menu = NULL; qerror_t ret; ret = FS_LoadFile(path, (void **)&raw); if (!raw) { if (ret != Q_ERR_NOENT || depth) { Com_WPrintf("Couldn't %s %s: %s\n", depth ? "include" : "load", path, Q_ErrorString(ret)); } return qfalse; } data = raw; COM_Compress(data); while (*data) { p = strchr(data, '\n'); if (p) { *p = 0; } Cmd_TokenizeString(data, qtrue); argc = Cmd_Argc(); if (argc) { cmd = Cmd_Argv(0); if (menu) { if (!strcmp(cmd, "end")) { if (menu->nitems) { List_Append(&ui_menus, &menu->entry); } else { Com_WPrintf("Menu entry without items\n"); menu->free(menu); } menu = NULL; } else if (!strcmp(cmd, "title")) { if (menu->title) { Z_Free(menu->title); } menu->title = UI_CopyString(Cmd_Argv(1)); } else if (!strcmp(cmd, "plaque")) { Parse_Plaque(menu); } else if (!strcmp(cmd, "banner")) { Parse_Banner(menu); } else if (!strcmp(cmd, "background")) { Parse_Background(menu); } else if (!strcmp(cmd, "style")) { Parse_Style(menu); } else if (!strcmp(cmd, "values")) { Parse_Spin(menu, MTYPE_SPINCONTROL); } else if (!strcmp(cmd, "strings")) { Parse_Spin(menu, MTYPE_STRINGS); } else if (!strcmp(cmd, "pairs")) { Parse_Pairs(menu); } else if (!strcmp(cmd, "range")) { Parse_Range(menu); } else if (!strcmp(cmd, "action")) { Parse_Action(menu); } else if (!strcmp(cmd, "bitmap")) { Parse_Bitmap(menu); } else if (!strcmp(cmd, "bind")) { Parse_Bind(menu); } else if (!strcmp(cmd, "savegame")) { Parse_Savegame(menu, MTYPE_SAVEGAME); } else if (!strcmp(cmd, "loadgame")) { Parse_Savegame(menu, MTYPE_LOADGAME); } else if (!strcmp(cmd, "toggle")) { Parse_Toggle(menu); } else if (!strcmp(cmd, "field")) { Parse_Field(menu); } else if (!strcmp(cmd, "blank")) { Parse_Blank(menu); } else { Com_WPrintf("Unknown keyword '%s'\n", cmd); } } else { if (!strcmp(cmd, "begin")) { char *s = Cmd_Argv(1); if (!*s) { Com_WPrintf("Expected menu name after '%s'\n", cmd); break; } menu = UI_FindMenu(s); if (menu) { if (menu->free) { menu->free(menu); } List_Remove(&menu->entry); } menu = UI_Mallocz(sizeof(*menu)); menu->name = UI_CopyString(s); menu->push = Menu_Push; menu->pop = Menu_Pop; menu->free = Menu_Free; menu->image = uis.backgroundHandle; menu->color.u32 = uis.color.background.u32; menu->transparent = uis.transparent; } else if (!strcmp(cmd, "include")) { char *s = Cmd_Argv(1); if (!*s) { Com_WPrintf("Expected file name after '%s'\n", cmd); break; } if (depth == 16) { Com_WPrintf("Includes too deeply nested\n"); } else { Parse_File(s, depth + 1); } } else if (!strcmp(cmd, "color")) { Parse_Color(); } else if (!strcmp(cmd, "background")) { char *s = Cmd_Argv(1); if (SCR_ParseColor(s, &uis.color.background)) { uis.backgroundHandle = 0; uis.transparent = uis.color.background.u8[3] != 255; } else { uis.backgroundHandle = R_RegisterPic(s); uis.transparent = R_GetPicSize(NULL, NULL, uis.backgroundHandle); } } else if (!strcmp(cmd, "font")) { uis.fontHandle = R_RegisterFont(Cmd_Argv(1)); } else if (!strcmp(cmd, "cursor")) { uis.cursorHandle = R_RegisterPic(Cmd_Argv(1)); R_GetPicSize(&uis.cursorWidth, &uis.cursorHeight, uis.cursorHandle); } else if (!strcmp(cmd, "weapon")) { Cmd_ArgvBuffer(1, uis.weaponModel, sizeof(uis.weaponModel)); } else { Com_WPrintf("Unknown keyword '%s'\n", cmd); break; } } } if (!p) { break; } data = p + 1; } FS_FreeFile(raw); if (menu) { Com_WPrintf("Menu entry without 'end' terminator\n"); menu->free(menu); } return qtrue; }
void UI_SaberLoadParms( void ) { int len, totallen, saberExtFNLen, fileCnt, i; char *holdChar, *marker; char saberExtensionListBuf[2048]; // The list of file names read in fileHandle_t f; char buffer[MAX_MENUFILE]; //ui.Printf( "UI Parsing *.sab saber definitions\n" ); ui_saber_parms_parsed = qtrue; UI_CacheSaberGlowGraphics(); //set where to store the first one totallen = 0; marker = SaberParms; marker[0] = '\0'; //now load in the extra .npc extensions fileCnt = trap->FS_GetFileList("ext_data/sabers", ".sab", saberExtensionListBuf, sizeof(saberExtensionListBuf) ); holdChar = saberExtensionListBuf; for ( i = 0; i < fileCnt; i++, holdChar += saberExtFNLen + 1 ) { saberExtFNLen = strlen( holdChar ); len = trap->FS_Open( va( "ext_data/sabers/%s", holdChar), &f, FS_READ ); if (!f) { continue; } if ( len == -1 ) { Com_Printf( "UI_SaberLoadParms: error reading %s\n", holdChar ); } else { if (len > sizeof(buffer) ) { Com_Error( ERR_FATAL, "UI_SaberLoadParms: file %s too large to read (max=%d)", holdChar, sizeof(buffer) ); } trap->FS_Read( buffer, len, f ); trap->FS_Close( f ); buffer[len] = 0; if ( totallen && *(marker-1) == '}' ) {//don't let it end on a } because that should be a stand-alone token strcat( marker, " " ); totallen++; marker++; } len = COM_Compress( buffer ); if ( totallen + len >= MAX_SABER_DATA_SIZE ) { Com_Error( ERR_FATAL, "UI_SaberLoadParms: ran out of space before reading %s\n(you must make the .sab files smaller)", holdChar ); } strcat( marker, buffer ); totallen += len; marker += len; } } }
/** * @brief Finds and loads all .shader files, combining them into * a single large text block that can be scanned for shader names */ int ScanAndLoadShaderFilesR1() { char **shaderFiles; char *buffers[MAX_SHADER_FILES]; char *p; int numShaderFiles, i; char *oldp, *token, *textEnd; char **hashMem; int shaderTextHashTableSizes[MAX_SHADERTEXT_HASH], hash; unsigned int size; char filename[MAX_QPATH]; long sum = 0, summand; Com_Memset(buffers, 0, MAX_SHADER_FILES); Com_Memset(shaderTextHashTableSizes, 0, MAX_SHADER_FILES); // scan for shader files shaderFiles = ri.FS_ListFiles("scripts", ".shader", &numShaderFiles); if (!shaderFiles || !numShaderFiles) { Ren_Print("----- ScanAndLoadShaderFilesR1 (no files)-----\n"); return 0; } Ren_Print("----- ScanAndLoadShaderFilesR1 (%i files)-----\n", numShaderFiles); if (numShaderFiles >= MAX_SHADER_FILES) { Ren_Drop("MAX_SHADER_FILES limit is reached!"); } // load and parse shader files for (i = 0; i < numShaderFiles; i++) { Com_sprintf(filename, sizeof(filename), "scripts/%s", shaderFiles[i]); COM_BeginParseSession(filename); Ren_Developer("...loading '%s'\n", filename); summand = ri.FS_ReadFile(filename, (void **)&buffers[i]); if (!buffers[i]) { Ren_Drop("Couldn't load %s", filename); // in this case shader file is cought/listed but the file can't be read - drop! } p = buffers[i]; while (1) { token = COM_ParseExt(&p, qtrue); if (!*token) { break; } // Step over the "table"/"guide" and the name if (!Q_stricmp(token, "table") || !Q_stricmp(token, "guide")) { token = COM_ParseExt2(&p, qtrue); if (!*token) { break; } } oldp = p; token = COM_ParseExt2(&p, qtrue); if (token[0] != '{' && token[1] != '\0') { Ren_Warning("WARNING: Bad shader file %s has incorrect syntax near token '%s' line %i\n", filename, token, COM_GetCurrentParseLine()); ri.FS_FreeFile(buffers[i]); buffers[i] = NULL; break; } SkipBracedSection(&oldp); p = oldp; } if (buffers[i]) { sum += summand; } } // build single large buffer s_shaderTextR1 = (char *)ri.Hunk_Alloc(sum + numShaderFiles * 2, h_low); s_shaderTextR1[0] = '\0'; textEnd = s_shaderTextR1; // free in reverse order, so the temp files are all dumped for (i = numShaderFiles - 1; i >= 0 ; i--) { if (!buffers[i]) { continue; } strcat(textEnd, buffers[i]); strcat(textEnd, "\n"); textEnd += strlen(textEnd); ri.FS_FreeFile(buffers[i]); } COM_Compress(s_shaderTextR1); // free up memory ri.FS_FreeFileList(shaderFiles); Com_Memset(shaderTextHashTableSizes, 0, sizeof(shaderTextHashTableSizes)); size = 0; p = s_shaderTextR1; // look for shader names while (1) { token = COM_ParseExt(&p, qtrue); if (token[0] == 0) { break; } // skip shader tables if (!Q_stricmp(token, "table")) { // skip table name (void) COM_ParseExt2(&p, qtrue); SkipBracedSection(&p); } // support shader templates else if (!Q_stricmp(token, "guide")) { // parse shader name token = COM_ParseExt2(&p, qtrue); //Ren_Print("...guided '%s'\n", token); hash = generateHashValue(token, MAX_SHADERTEXT_HASH); shaderTextHashTableSizes[hash]++; size++; // skip guide name token = COM_ParseExt2(&p, qtrue); // skip parameters token = COM_ParseExt2(&p, qtrue); if (Q_stricmp(token, "(")) { Ren_Warning("expected ( found '%s'\n", token); break; } while (1) { token = COM_ParseExt2(&p, qtrue); if (!token[0]) { break; } if (!Q_stricmp(token, ")")) { break; } } if (Q_stricmp(token, ")")) { Ren_Warning("expected ( found '%s'\n", token); break; } } else { hash = generateHashValue(token, MAX_SHADERTEXT_HASH); shaderTextHashTableSizes[hash]++; size++; SkipBracedSection(&p); } } //Ren_Print("Shader hash table size %i\n", size); size += MAX_SHADERTEXT_HASH; hashMem = (char **)ri.Hunk_Alloc(size * sizeof(char *), h_low); for (i = 0; i < MAX_SHADERTEXT_HASH; i++) { shaderTextHashTableR1[i] = hashMem; hashMem += shaderTextHashTableSizes[i] + 1; } Com_Memset(shaderTextHashTableSizes, 0, sizeof(shaderTextHashTableSizes)); p = s_shaderTextR1; // look for shader names while (1) { oldp = p; token = COM_ParseExt(&p, qtrue); if (token[0] == 0) { break; } // parse shader tables if (!Q_stricmp(token, "table")) { int depth; float values[FUNCTABLE_SIZE]; int numValues; shaderTable_t *tb; qboolean alreadyCreated; Com_Memset(&values, 0, sizeof(values)); Com_Memset(&table, 0, sizeof(table)); token = COM_ParseExt2(&p, qtrue); Q_strncpyz(table.name, token, sizeof(table.name)); // check if already created alreadyCreated = qfalse; hash = generateHashValue(table.name, MAX_SHADERTABLE_HASH); for (tb = shaderTableHashTable[hash]; tb; tb = tb->next) { if (Q_stricmp(tb->name, table.name) == 0) { // match found alreadyCreated = qtrue; break; } } depth = 0; numValues = 0; do { token = COM_ParseExt2(&p, qtrue); if (!Q_stricmp(token, "snap")) { table.snap = qtrue; } else if (!Q_stricmp(token, "clamp")) { table.clamp = qtrue; } else if (token[0] == '{') { depth++; } else if (token[0] == '}') { depth--; } else if (token[0] == ',') { continue; } else { if (numValues == FUNCTABLE_SIZE) { Ren_Warning("WARNING: FUNCTABLE_SIZE hit\n"); break; } values[numValues++] = atof(token); } } while (depth && p); if (!alreadyCreated) { Ren_Developer("...generating '%s'\n", table.name); GeneratePermanentShaderTable(values, numValues); } } // support shader templates else if (!Q_stricmp(token, "guide")) { // parse shader name oldp = p; token = COM_ParseExt2(&p, qtrue); //Ren_Print("...guided '%s'\n", token); hash = generateHashValue(token, MAX_SHADERTEXT_HASH); shaderTextHashTableR1[hash][shaderTextHashTableSizes[hash]++] = oldp; // skip guide name token = COM_ParseExt2(&p, qtrue); // skip parameters token = COM_ParseExt2(&p, qtrue); if (Q_stricmp(token, "(")) { Ren_Warning("expected ( found '%s'\n", token); break; } while (1) { token = COM_ParseExt2(&p, qtrue); if (!token[0]) { break; } if (!Q_stricmp(token, ")")) { break; } } if (Q_stricmp(token, ")")) { Ren_Warning("expected ( found '%s'\n", token); break; } } else { hash = generateHashValue(token, MAX_SHADERTEXT_HASH); shaderTextHashTableR1[hash][shaderTextHashTableSizes[hash]++] = oldp; SkipBracedSection(&p); } } return numShaderFiles; }
static qboolean UI_ParseAnimationFile( const char *filename, animation_t *animations ) { const char *text_p, *prev; int len, i, skip; char text[20000], *token; float fps; fileHandle_t f; memset( animations, 0, sizeof( animation_t ) * MAX_ANIMATIONS ); // load the file len = trap->FS_Open( filename, &f, FS_READ ); if ( len <= 0 ) { return qfalse; } if ( len >= ( sizeof( text ) - 1 ) ) { Com_Printf( "File %s too long\n", filename ); trap->FS_Close( f ); return qfalse; } trap->FS_Read( text, len, f ); text[len] = 0; trap->FS_Close( f ); COM_Compress(text); // parse the text text_p = text; skip = 0; // read optional parameters while ( 1 ) { prev = text_p; // so we can unget token = COM_Parse( &text_p ); if ( !token ) { break; } if ( !Q_stricmp( token, "footsteps" ) ) { token = COM_Parse( &text_p ); if ( !token ) { break; } continue; } else if ( !Q_stricmp( token, "headoffset" ) ) { for ( i = 0 ; i < 3 ; i++ ) { token = COM_Parse( &text_p ); if ( !token ) { break; } } continue; } // if it is a number, start parsing animations if ( token[0] >= '0' && token[0] <= '9' ) { text_p = prev; // unget the token break; } Com_Printf( "unknown token '%s' in %s\n", token, filename ); } // read information for each frame for ( i = 0 ; i < MAX_ANIMATIONS ; i++ ) { token = COM_Parse( &text_p ); if ( !token ) { break; } animations[i].firstFrame = atoi( token ); // leg only frames are adjusted to not count the upper body only frames if ( i == LEGS_WALKCR ) { skip = animations[LEGS_WALKCR].firstFrame - animations[TORSO_GESTURE].firstFrame; } if ( i >= LEGS_WALKCR ) { animations[i].firstFrame -= skip; } token = COM_Parse( &text_p ); if ( !token ) { break; } animations[i].numFrames = atoi( token ); token = COM_Parse( &text_p ); if ( !token ) { break; } animations[i].loopFrames = atoi( token ); token = COM_Parse( &text_p ); if ( !token ) { break; } fps = (float)atof( token ); if ( fps == 0 ) { fps = 1; } animations[i].frameLerp = (int)(1000 / fps); animations[i].initialLerp = (int)(1000 / fps); } if ( i != MAX_ANIMATIONS ) { Com_Printf( "Error parsing animation file: %s\n", filename ); return qfalse; } return qtrue; }
script_t *LoadScriptFile(const char *filename) { fileHandle_t h_up, h_patch; char pathname[MAX_QPATH], pathpatch[MAX_QPATH]; unsigned long inhash = 0; int inlength, outlength, plength; char *inbuffer, *outbuffer, *pbuffer; script_t *script; if (strlen(basefolder)) { Com_sprintf(pathname, sizeof(pathname), "%s/%s", basefolder, filename); Com_sprintf(pathpatch, sizeof(pathpatch), "%s/%s_patch", basefolder, filename); } else { Com_sprintf(pathname, sizeof(pathname), "%s", filename); Com_sprintf(pathpatch, sizeof(pathpatch), "%s_patch", filename); } inlength = botimport.FS_FOpenFileHash(pathname, &h_up, FS_READ, &inhash); if (!h_up) return NULL; plength = botimport.FS_FOpenFile(pathpatch, &h_patch, FS_READ); inbuffer = (char *)GetClearedMemory(inlength + 1); botimport.FS_Read(inbuffer, inlength, h_up); botimport.FS_FCloseFile(h_up); if (h_patch) { pbuffer = (char *)GetClearedMemory(plength + 1); botimport.FS_Read(pbuffer, plength, h_patch); botimport.FS_FCloseFile(h_patch); Com_Printf("patching menu file %s...\n", pathname); outlength = MV_MenuPatchFile(inbuffer, inhash, pbuffer, &outbuffer); if (outlength < 0) { if (outlength == ERROR_SYNTAX) { Com_Printf("patching failed: syntax error in patchfile\n"); } else if (outlength == ERROR_HASH) { Com_Printf("patching skipped: hash mismatch\n"); } outbuffer = inbuffer; outlength = inlength; } FreeMemory(pbuffer); // uncomment to dump patched file with _patched suffix; menu_patch /* char patchedName[MAX_QPATH]; fileHandle_t patchedFile; Com_sprintf(patchedName, sizeof(patchedName), "%s_patched", pathname); botimport.FS_FOpenFile(patchedName, &patchedFile, FS_WRITE); botimport.FS_Write(outbuffer, outlength, patchedFile); botimport.FS_FCloseFile(patchedFile); */ } else { outbuffer = inbuffer; outlength = inlength; } script = (script_t *)GetClearedMemory(sizeof(script_t) + outlength + 1); Com_Memset(script, 0, sizeof(script_t)); strcpy(script->filename, filename); script->buffer = (char *)script + sizeof(script_t); script->buffer[outlength] = 0; script->length = outlength; script->script_p = script->buffer; script->lastscript_p = script->buffer; script->end_p = &script->buffer[outlength]; script->tokenavailable = 0; script->line = 1; script->lastline = 1; SetScriptPunctuations(script, NULL); Com_Memcpy(script->buffer, outbuffer, outlength); FreeMemory(outbuffer); if (outbuffer != inbuffer) FreeMemory(inbuffer); script->length = COM_Compress(script->buffer); return script; } //end of the function LoadScriptFile