/* ================= SV_LoadGame_f ================= */ void SV_LoadGame_f( void ) { char filename[MAX_QPATH], mapname[MAX_QPATH]; byte *buffer; int size; Q_strncpyz( filename, Cmd_Argv( 1 ), sizeof( filename ) ); if ( !filename[0] ) { Com_Printf( "You must specify a savegame to load\n" ); return; } if ( Q_strncmp( filename, "save/", 5 ) && Q_strncmp( filename, "save\\", 5 ) ) { Q_strncpyz( filename, va( "save/%s", filename ), sizeof( filename ) ); } if ( !strstr( filename, ".svg" ) ) { Q_strcat( filename, sizeof( filename ), ".svg" ); } size = FS_ReadFile( filename, NULL ); if ( size < 0 ) { Com_Printf( "Can't find savegame %s\n", filename ); return; } buffer = Hunk_AllocateTempMemory( size ); FS_ReadFile( filename, (void **)&buffer ); // read the mapname, if it is the same as the current map, then do a fast load Com_sprintf( mapname, sizeof( mapname ), buffer + sizeof( int ) ); if ( com_sv_running->integer && ( com_frameTime != sv.serverId ) ) { // check mapname if ( !Q_stricmp( mapname, sv_mapname->string ) ) { // same if ( Q_stricmp( filename, "save/current.svg" ) != 0 ) { // copy it to the current savegame file FS_WriteFile( "save/current.svg", buffer, size ); } Hunk_FreeTempMemory( buffer ); Cvar_Set( "savegame_loading", "2" ); // 2 means it's a restart, so stop rendering until we are loaded SV_MapRestart_f(); // savegame will be loaded after restart return; } } Hunk_FreeTempMemory( buffer ); // otherwise, do a slow load if ( Cvar_VariableIntegerValue( "sv_cheats" ) ) { Cbuf_ExecuteText( EXEC_APPEND, va( "spdevmap %s", filename ) ); } else { // no cheats Cbuf_ExecuteText( EXEC_APPEND, va( "spmap %s", filename ) ); } }
static void SV_ChangeMap( qbool cheats ) { const char* map = Cmd_Argv(1); if ( !map ) { return; } // make sure the level exists before trying to change // so that a typo at the server console won't end the game const char* mapfile = va( "maps/%s.bsp", map ); if ( FS_ReadFile( mapfile, NULL ) == -1 ) { Com_Printf( "Can't find map %s\n", mapfile ); return; } // force latched values to get set Cvar_Get( "g_gametype", "0", CVAR_SERVERINFO | CVAR_LATCH ); // save the map name here cause on a map restart we reload the q3config.cfg // and thus nuke the arguments of the map command char mapname[MAX_QPATH]; Q_strncpyz( mapname, map, sizeof(mapname) ); // start up the map SV_SpawnServer( mapname ); Cvar_Set( "sv_cheats", cheats ? "1" : "0" ); }
/* =============== Cmd_Exec_f =============== */ void Cmd_Exec_f( void ) { qboolean quiet; union { char *c; void *v; } f; char filename[MAX_QPATH]; quiet = !Q_stricmp(Cmd_Argv(0), "execq"); if (Cmd_Argc () != 2) { Com_Printf ("exec%s <filename> : execute a script file%s\n", quiet ? "q" : "", quiet ? " without notification" : ""); return; } Q_strncpyz( filename, Cmd_Argv(1), sizeof( filename ) ); COM_DefaultExtension( filename, sizeof( filename ), ".cfg" ); FS_ReadFile( filename, &f.v); if (!f.c) { Com_Printf ("couldn't exec %s\n", filename); return; } if (!quiet) Com_Printf ("execing %s\n", filename); Cbuf_InsertText (f.c); FS_FreeFile (f.v); }
/* * Class: xreal_Engine * Method: readFile * Signature: (Ljava/lang/String;)[B */ jbyteArray JNICALL Java_xreal_Engine_readFile(JNIEnv *env, jclass cls, jstring jfileName) { char *fileName; jbyteArray array; int length; byte *buf; fileName = (char *)((*env)->GetStringUTFChars(env, jfileName, 0)); length = FS_ReadFile(fileName, (void **)&buf); if(!buf) { return NULL; } //Com_Printf("Java_xreal_Engine_readFile: file '%s' has length = %i\n", filename, length); array = (*env)->NewByteArray(env, length); (*env)->SetByteArrayRegion(env, array, 0, length, buf); (*env)->ReleaseStringUTFChars(env, jfileName, fileName); FS_FreeFile(buf); return array; }
/* =============== Cmd_Exec_f =============== */ void Cmd_Exec_f( void ) { char *f; int len; char filename[MAX_QPATH]; if (Cmd_Argc () != 2) { Com_Printf ("exec <filename> : execute a script file\n"); return; } Q_strncpyz( filename, Cmd_Argv(1), sizeof( filename ) ); COM_DefaultExtension( filename, sizeof( filename ), ".cfg" ); len = FS_ReadFile( filename, (void **)&f); if (!f) { Com_Printf ("couldn't exec %s\n",Cmd_Argv(1)); return; } #ifndef FINAL_BUILD Com_Printf ("execing %s\n",Cmd_Argv(1)); #endif Cbuf_InsertText (f); FS_FreeFile (f); }
// Request a download from the server static void CLQ2_Download_f() { if ( Cmd_Argc() != 2 ) { common->Printf( "Usage: download <filename>\n" ); return; } char filename[ MAX_OSPATH ]; String::Sprintf( filename, sizeof ( filename ), "%s", Cmd_Argv( 1 ) ); if ( strstr( filename, ".." ) ) { common->Printf( "Refusing to download a path with ..\n" ); return; } if ( FS_ReadFile( filename, NULL ) != -1 ) {// it exists, no need to download common->Printf( "File already exists.\n" ); return; } String::Cpy( clc.downloadName, filename ); common->Printf( "Downloading %s\n", clc.downloadName ); // download to a temp name, and only rename // to the real name when done, so if interrupted // a runt file wont be left String::StripExtension( clc.downloadName, clc.downloadTempName ); String::Cat( clc.downloadTempName, sizeof ( clc.downloadTempName ), ".tmp" ); CL_AddReliableCommand( va( "download %s", clc.downloadName ) ); clc.downloadNumber++; }
//========================================================= // don't call this directly, it should only be called from SV_Map_f() or SV_MapTransition_f() // static void SV_Map_( ForceReload_e eForceReload ) { char *map; char expanded[MAX_QPATH]; map = Cmd_Argv(1); if ( !*map ) { return; } // make sure the level exists before trying to change, so that // a typo at the server console won't end the game if (strchr (map, '\\') ) { Com_Printf ("Can't have mapnames with a \\\n"); return; } Com_sprintf (expanded, sizeof(expanded), "maps/%s.bsp", map); if ( FS_ReadFile (expanded, NULL) == -1 ) { Com_Printf ("Can't find map %s\n", expanded); return; } if (map[0]!='_') { SG_WipeSavegame("auto"); } SP_Unload(SP_REGISTER_CLIENT); //clear the previous map srings SV_SpawnServer( map, eForceReload, qtrue ); // start up the map }
/* ============== S_LoadSound The filename may be different than sfx->name in the case of a forced fallback of a player specific sound ============== */ bool S_LoadSound( sfx_t *sfx ) { byte *data; short *samples; wavinfo_t info; int size; // player specific sounds are never directly loaded if ( sfx->soundName[0] == '*') return false; // load it in size = FS_ReadFile( sfx->soundName, (void **)&data ); if ( !data ) return false; info = GetWavinfo( sfx->soundName, data, size ); if ( info.channels != 1 ) { Com_Printf ("%s is a stereo wav file\n", sfx->soundName); FS_FreeFile (data); return false; } if ( info.width == 1 ) Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is a 8 bit wav file\n", sfx->soundName); if ( info.rate != 22050 ) Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is not a 22kHz wav file\n", sfx->soundName); samples = reinterpret_cast<short*>(Hunk_AllocateTempMemory(info.samples * sizeof(short) * 2)); sfx->lastTimeUsed = Com_Milliseconds()+1; // each of these compression schemes works just fine // but the 16bit quality is much nicer and with a local // install assured we can rely upon the sound memory // manager to do the right thing for us and page // sound in as needed if( sfx->soundCompressed == true) { sfx->soundCompressionMethod = 1; sfx->soundData = NULL; sfx->soundLength = ResampleSfxRaw( samples, info.rate, info.width, info.samples, (data + info.dataofs) ); S_AdpcmEncodeSound(sfx, samples); } else { sfx->soundCompressionMethod = 0; sfx->soundLength = info.samples; sfx->soundData = NULL; ResampleSfx( sfx, info.rate, info.width, data + info.dataofs, false ); } Hunk_FreeTempMemory(samples); FS_FreeFile( data ); return true; }
/* ================= S_FindCodecForFile Select an appropriate codec for a file based on its extension ================= */ static snd_codec_t *S_FindCodecForFile(const char *filename) { char *ext = S_FileExtension(filename); snd_codec_t *codec = codecs; if(!ext) { // No extension - auto-detect while(codec) { char fn[MAX_QPATH]; Q_strncpyz(fn, filename, sizeof(fn) - 4); COM_DefaultExtension(fn, sizeof(fn), codec->ext); // Check it exists if(FS_ReadFile(fn, NULL) != -1) return codec; // Nope. Next! codec = codec->next; } // Nothin' return NULL; } while(codec) { if(!Q_stricmp(ext, codec->ext)) return codec; codec = codec->next; } return NULL; }
/* ================ FS_InitFilesystem Called only at inital startup, not when the filesystem is resetting due to a game change ================ */ void FS_InitFilesystem( void ) { // allow command line parms to override our defaults // we don't have to specially handle this, because normal command // line variable sets happen before the filesystem // has been initialized // // UPDATE: BTO (VV) // we have to specially handle this, because normal command // line variable sets don't happen until after the filesystem // has already been initialized Com_StartupVariable( "fs_cdpath" ); Com_StartupVariable( "fs_basepath" ); Com_StartupVariable( "fs_game" ); Com_StartupVariable( "fs_copyfiles" ); Com_StartupVariable( "fs_restrict" ); // try to start up normally FS_Startup( BASEGAME ); initialized = qtrue; // see if we are going to allow add-ons FS_SetRestrictions(); // if we can't find default.cfg, assume that the paths are // busted and error out now, rather than getting an unreadable // graphics screen when the font fails to load if ( FS_ReadFile( "default.cfg", NULL ) <= 0 ) { Com_Error( ERR_FATAL, "Couldn't load default.cfg" ); } }
/* ================ FS_InitFilesystem Called only at inital startup, not when the filesystem is resetting due to a game change ================ */ void FS_InitFilesystem( void ) { // allow command line parms to override our defaults // we have to specially handle this, because normal command // line variable sets don't happen until after the filesystem // has already been initialized Com_StartupVariable( "fs_cdpath" ); Com_StartupVariable( "fs_basepath" ); Com_StartupVariable( "fs_homepath" ); Com_StartupVariable( "fs_game" ); Com_StartupVariable( "fs_copyfiles" ); Com_StartupVariable( "fs_dirbeforepak" ); if(!FS_FilenameCompare(Cvar_VariableString("fs_game"), BASEGAME)) Cvar_Set("fs_game", ""); // try to start up normally FS_Startup( BASEGAME ); initialized = qtrue; // if we can't find default.cfg, assume that the paths are // busted and error out now, rather than getting an unreadable // graphics screen when the font fails to load if ( FS_ReadFile( "mpdefault.cfg", NULL ) <= 0 ) { Com_Error( ERR_FATAL, "Couldn't load mpdefault.cfg" ); // bk001208 - SafeMode see below, FIXME? } Q_strncpyz(lastValidBase, fs_basepath->string, sizeof(lastValidBase)); Q_strncpyz(lastValidGame, fs_gamedirvar->string, sizeof(lastValidGame)); // bk001208 - SafeMode see below, FIXME? }
/* =============== Cmd_Exec_f =============== */ void Cmd_Exec_f( void ) { union { char *c; void *v; } f; int len; char filename[MAX_QPATH]; if (Cmd_Argc () != 2) { Com_Printf ("exec <filename> : execute a script file\n"); return; } Q_strncpyz( filename, Cmd_Argv(1), sizeof( filename ) ); COM_DefaultExtension( filename, sizeof( filename ), ".cfg" ); len = FS_ReadFile( filename, &f.v); if (!f.c) { Com_Printf ("couldn't exec %s\n",Cmd_Argv(1)); return; } Com_Printf ("execing %s\n",Cmd_Argv(1)); Cbuf_InsertText (f.c); FS_FreeFile (f.v); }
static qboolean DoFileFindReplace( LPCSTR psMenuFile, LPCSTR psFind, LPCSTR psReplace ) { char *buffer; OutputDebugString(va("Loading: \"%s\"\n",psMenuFile)); int iLen = FS_ReadFile( psMenuFile,(void **) &buffer); if (iLen<1) { OutputDebugString("Failed!\n"); assert(0); return qfalse; } // find/rep... // string str(buffer); str += "\r\n"; // safety for *(char+1) stuff FS_FreeFile( buffer ); // let go of the buffer // originally this kept looping for replacements, but now it only does one (since the find/replace args are repeated // and this is called again if there are >1 replacements of the same strings to be made... // // int iReplacedCount = 0; char *pFound; int iSearchPos = 0; while ( (pFound = strstr(str.c_str()+iSearchPos,psFind)) != NULL) { // special check, the next char must be whitespace or carriage return etc, or we're not on a whole-word position... // int iFoundLoc = pFound - str.c_str(); char cAfterFind = pFound[strlen(psFind)]; if (cAfterFind > 32) { // ... then this string was part of a larger one, so ignore it... // iSearchPos = iFoundLoc+1; continue; } str.replace(iFoundLoc, strlen(psFind), psReplace); // iSearchPos = iFoundLoc+1; // iReplacedCount++; break; } // assert(iReplacedCount); // if (iReplacedCount>1) // { // int z=1; // } FS_WriteFile( psMenuFile, str.c_str(), strlen(str.c_str())); OutputDebugString("Ok\n"); return qtrue; }
/** * @brief Restart the server on a different map */ static void SV_Map_f(void) { char *cmd; char *map; char mapname[MAX_QPATH]; qboolean cheat; char expanded[MAX_QPATH]; map = Cmd_Argv(1); if (!map || !map[0]) { Com_Printf("Usage: \n map <map name>\n devmap <map name>\n"); return; } // make sure the level exists before trying to change, so that // a typo at the server console won't end the game Com_sprintf(expanded, sizeof(expanded), "maps/%s.bsp", map); if (FS_ReadFile(expanded, NULL) == -1) { Com_Printf("Can't find map %s\n", expanded); return; } Cvar_Set("gamestate", va("%i", GS_INITIALIZE)); // reset gamestate on map/devmap Cvar_Set("g_currentRound", "0"); // reset the current round Cvar_Set("g_nextTimeLimit", "0"); // reset the next time limit cmd = Cmd_Argv(0); if (!Q_stricmp(cmd, "devmap")) { cheat = qtrue; } else { cheat = qfalse; } // save the map name here cause on a map restart we reload the etconfig.cfg // and thus nuke the arguments of the map command Q_strncpyz(mapname, map, sizeof(mapname)); // start up the map SV_SpawnServer(mapname); // set the cheat value // if the level was started with "map <mapname>", then // cheats will not be allowed. // If started with "devmap <mapname>" // then cheats will be allowed if (cheat) { Cvar_Set("sv_cheats", "1"); } else { Cvar_Set("sv_cheats", "0"); } }
// can't unload TTFs, so we'll need to make sure we don't keep reloading them, sadly void* TTF_Load(Asset &asset) { TTFFont_t *fnt = new TTFFont_t(); if (ctx == nullptr) { ctx = glfonsCreate(512, 512, FONS_ZERO_TOPLEFT); } int found = fonsGetFontByName(ctx, asset.name); if (found != FONS_INVALID) { fnt->valid = true; fnt->hnd = found; found++; return fnt; } unsigned char *font; auto sz = FS_ReadFile(asset.path, (void **)&font); if (sz == -1) { Con_Errorf(ERR_GAME, "couldn't load file %s", asset.path); return nullptr; } int hnd = fonsAddFontMem(ctx, asset.name, font, sz, 1); if (hnd < 0) { return nullptr; } fnt->valid = true; fnt->hnd = hnd; return (void*)fnt; }
// note this function has to return 'int', as otherwise only the bottom byte will get cleared int ExecIsFSHookFunc(const char* execFilename, const char* dummyMatch) { // dummyMatch isn't used by us // check if the file exists in our FS_* path if (FS_ReadFile(execFilename, NULL) >= 0) { return false; } return true; }
/************************************************************************************************ * JK2SP_Register : Load given string package file. Register it. * * Inputs: * Package File name * Registration flag * * Return: * success/fail * ************************************************************************************************/ qboolean JK2SP_Register(const char *inPackage, unsigned char Registration) { char *buffer; char Package[MAX_QPATH]; int size; cStringPackageSingle *new_sp; std::map<std::string, cStringPackageSingle *>::iterator i; assert(JK2SP_ListByName.size() == JK2SP_ListByID.size()); Q_strncpyz(Package, inPackage, MAX_QPATH); Q_strupr(Package); i = JK2SP_ListByName.find(Package); if (i != JK2SP_ListByName.end()) { new_sp = (*i).second; } else { size = FS_ReadFile(va("strip/%s.sp", Package), (void **)&buffer); if (size == -1) { if ( Registration & SP_REGISTER_REQUIRED ) { Com_Error(ERR_FATAL, "Could not open string package '%s'", Package); } return qfalse; } // Create the new string package new_sp = new cStringPackageSingle(Package); new_sp->Load(buffer, size ); FS_FreeFile(buffer); if (Registration & SP_REGISTER_CLIENT) { Com_DPrintf(S_COLOR_YELLOW "JK2SP_Register: Registered client string package '%s' with ID %02x\n", Package, (int)new_sp->GetID()); } else { Com_DPrintf(S_COLOR_YELLOW "JK2SP_Register: Registered string package '%s' with ID %02x\n", Package, (int)new_sp->GetID()); } // Insert into the name vs package map JK2SP_ListByName[Package] = new_sp; // Insert into the id vs package map JK2SP_ListByID[new_sp->GetID()] = new_sp; } // Or in the new registration data new_sp->Register(Registration); // return new_sp; return qtrue; }
PRIVATE size_t ovc_read( void *ptr, size_t size, size_t nmemb, void *dataSource ) { if( ! size || ! nmemb ) { return 0; } return FS_ReadFile( ptr, size, nmemb, fh ); }
void R_LoadPIC( const char* fileName, byte** pic, int* width, int* height, int mode ) { idList<byte> buffer; if ( FS_ReadFile( fileName, buffer ) <= 0 ) { *pic = NULL; return; } R_LoadPICMem( buffer.Ptr(), pic, width, height, mode ); }
/* ================== R_ScreenShotTGA_f screenshot screenshot [silent] screenshot [levelshot] screenshot [filename] Doesn't print the pacifier message if there is a second arg ================== */ void R_ScreenShotTGA_f (void) { #ifndef _XBOX char checkname[MAX_OSPATH]; int len; static int lastNumber = -1; qboolean silent; if ( !strcmp( Cmd_Argv(1), "levelshot" ) ) { R_LevelShot(); return; } if ( !strcmp( Cmd_Argv(1), "silent" ) ) { silent = qtrue; } else { silent = qfalse; } if ( Cmd_Argc() == 2 && !silent ) { // explicit filename Com_sprintf( checkname, MAX_OSPATH, "screenshots/%s.tga", Cmd_Argv( 1 ) ); } else { // scan for a free filename // if we have saved a previous screenshot, don't scan // again, because recording demo avis can involve // thousands of shots if ( lastNumber == -1 ) { // scan for a free number for ( lastNumber = 0 ; lastNumber <= 9999 ; lastNumber++ ) { R_ScreenshotFilename( lastNumber, checkname, ".tga" ); len = FS_ReadFile( checkname, NULL ); if ( len <= 0 ) { break; // file doesn't exist } } } else { R_ScreenshotFilename( lastNumber, checkname, ".tga" ); } if ( lastNumber == 10000 ) { VID_Printf (PRINT_ALL, "ScreenShot: Couldn't create a file\n"); return; } lastNumber++; } R_TakeScreenshot( 0, 0, glConfig.vidWidth, glConfig.vidHeight, checkname ); if ( !silent ) { VID_Printf (PRINT_ALL, "Wrote %s\n", checkname); } #endif }
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* Util_LoadFileToBuffer(char* path, uint32_t* size) { FSFile file; FS_InitFile(&file); FS_OpenFile(&file, path); uint32_t mSize = FS_GetLength(&file); void* buffer = NNS_FndAllocFromExpHeapEx(mHeapHandle, mSize, 16); FS_ReadFile(&file, buffer, (int)mSize); FS_CloseFile(&file); if(size != NULL) *size = mSize; return buffer; }
const char* PHandler_OpenTempFile(char* name, char* fullfilepath, int fplen){ // Load a plugin, safe for use void *buf; int len; int wlen; char* file; char tmpfile[MAX_QPATH]; char filepath[MAX_QPATH]; Com_sprintf(filepath, sizeof(filepath),"plugins/%s" DLL_EXT, name); len = FS_ReadFile(filepath, &buf); if(len < 100) len = FS_SV_ReadFile( filepath, &buf ); if(len < 100) { Com_Printf("No such file found: %s. Can not load this plugin.\n", filepath); return NULL; } if(PHandler_VerifyPlugin(buf, len) == qfalse) { Com_Printf("%s is not a plugin file or is corrupt or contains disallowed functions.\n", filepath); FS_FreeFile(buf); return NULL; } Com_sprintf(tmpfile, sizeof(tmpfile), "plugin.%s.tmp", name); /* If there is already such a file remove it now */ file = FS_SV_GetFilepath( tmpfile, fullfilepath, fplen ); if(file) { FS_RemoveOSPath(file); file = FS_SV_GetFilepath( tmpfile, fullfilepath, fplen ); if(file) { FS_RemoveOSPath(file); } } wlen = FS_SV_HomeWriteFile( tmpfile, buf, len); if(wlen != len) { Com_PrintError("fs_homepath is readonly. Can not load this plugin.\n"); FS_FreeFile(buf); return NULL; } //Additional test if a file is there and creation of full filepath FS_FreeFile(buf); return FS_SV_GetFilepath( tmpfile, fullfilepath, fplen ); }
/* ================== SV_Map_f Restart the server on a different map ================== */ static void SV_Map_f( void ) { char *cmd; char *map; qboolean killBots, cheat; char expanded[MAX_QPATH]; char mapname[MAX_QPATH]; int i; map = Cmd_Argv(1); if ( !map ) { return; } // make sure the level exists before trying to change, so that // a typo at the server console won't end the game Com_sprintf (expanded, sizeof(expanded), "maps/%s.bsp", map); if ( FS_ReadFile (expanded, NULL) == -1 ) { Com_Printf ("Can't find map %s\n", expanded); return; } cmd = Cmd_Argv(0); if ( !Q_stricmp( cmd, "devmap" ) ) { cheat = qtrue; killBots = qtrue; } else { cheat = qfalse; killBots = qfalse; } // save the map name here cause on a map restart we reload the autogen.cfg // and thus nuke the arguments of the map command Q_strncpyz(mapname, map, sizeof(mapname)); // start up the map SV_SpawnServer( mapname, killBots ); // set the cheat value // if the level was started with "map <levelname>", then // cheats will not be allowed. If started with "devmap <levelname>" // then cheats will be allowed if ( cheat ) { Cvar_Set( "sv_cheats", "1" ); } else { Cvar_Set( "sv_cheats", "0" ); } // This forces the local master server IP address cache // to be updated on sending the next heartbeat for( i = 0; i < MAX_MASTER_SERVERS; i++ ) sv_master[ i ]->modified = qtrue; }
/** * \brief OGG read Callback. Reads data from a stream. * \param[in] ptr Storage location for data. * \param[in] size Item size in bytes. * \param[in] nmemb Maximum number of items to be read. * \param[in] datasource Music track data structure. * \return * \note */ PRIVATE size_t ovc_read( void *ptr, size_t size, size_t nmemb, void *datasource ) { musicTrack_t *track = (musicTrack_t *)datasource; if( ! size || ! nmemb ) { return 0; } return FS_ReadFile( ptr, size, nmemb, track->hFile ); }
/* ================== SV_Map_f Restart the server on a different map ================== */ static void SV_Map_f( void ) { char *cmd; char *map; const char *layouts; char mapname[ MAX_QPATH ]; qboolean cheat; char expanded[ MAX_QPATH ]; char layout[ MAX_CVAR_VALUE_STRING ]; map = Cmd_Argv( 1 ); if ( !map ) { return; } // make sure the level exists before trying to change, so that // a typo at the server console won't end the game Com_sprintf( expanded, sizeof( expanded ), "maps/%s.bsp", map ); if ( FS_ReadFile( expanded, NULL ) == -1 ) { Com_Printf(_( "Can't find map %s\n"), expanded ); return; } // layout(s) - note that ArgsFrom adds quoting which we don't want here // Also, if empty, don't override layouts = Cmd_UnquoteString( Cmd_ArgsFrom( 2 ) ); if ( *layouts ) { Cvar_Set( "g_layouts", layouts ); } cheat = !Q_stricmp( Cmd_Argv( 0 ), "devmap" ); // save the map name here cause on a map restart we reload the q3config.cfg // and thus nuke the arguments of the map command Q_strncpyz( mapname, map, sizeof( mapname ) ); // start up the map SV_SpawnServer( mapname ); // set the cheat value // if the level was started with "map <levelname>", then // cheats will not be allowed. If started with "devmap <levelname>" // then cheats will be allowed Cvar_Set( "sv_cheats", cheat ? "1" : "0" ); }
void AS_ParseSets( void ) { union { char *c; void *v; } as_file; char *text_p, *token; FS_ReadFile( SOUNDSET_FILE, &as_file.v ); if ( !as_file.c ) { Com_Printf( S_COLOR_RED "ERROR: Couldn't load ambient sound sets from \"%s\"\n", SOUNDSET_FILE ); return; } text_p = as_file.c; do { token = AS_Parse( &text_p ); if ( !token || !token[0] ) { break; } if ( !strcmp( "type", token ) ) { token = AS_Parse( &text_p ); if( Q_stricmp( token, "ambientset" ) ) { Com_Printf( S_COLOR_RED "AS_ParseHeader: Set type \"%s\" is not a valid set type!\n", token ); FS_FreeFile( as_file.v ); return; } continue; } if ( !strcmp( "amsdir", token ) ) { //token = AS_Parse( &text_p ); AS_SkipRestOfLine( &text_p ); continue; } if ( !strcmp( "outdir", token ) ) { //token = AS_Parse( &text_p ); AS_SkipRestOfLine( &text_p ); continue; } if ( !strcmp( "basedir", token ) ) { //token = AS_Parse( &text_p ); AS_SkipRestOfLine( &text_p ); continue; } //generalSet localSet bmodelSet } while ( token ); FS_FreeFile( as_file.v ); }
bool wavPlayer::update() { if(!playing || paused) return false; if(fileCursor >= loop.end) seek(loop.begin); if(buffercursor >= audiobuffer_size) buffercursor = 0; //Find out how many new samples should we push to the buffer. int curtimer = TIMER3_DATA; int newData = curtimer - prevtimer; if(newData < 0) newData += 65536; if(newData > audiobuffer_size - buffercursor) newData = audiobuffer_size - buffercursor; int readBegin = fileCursor; int readEnd = fileCursor + newData; if(readEnd >= loop.end) readEnd = loop.end; newData = (readEnd-readBegin); prevtimer = (prevtimer+newData)%65536; int pos = buffercursor*bitdepth; int len = newData*bitdepth; FS_ReadFile(&fileLeft, audiobufferLeft+pos, len); FS_ReadFile(&fileRight, audiobufferRight+pos, len); fileCursor += newData; buffercursor += newData; return true; }
void CL_Record_f(void) { char name[MAX_OSPATH]; char *s; if (Cmd_Argc() > 2) { Com_FuncPrinf("record <demoname>\n"); return; } if (clc.demorecording) { Com_FuncPrinf("Already recording.\n"); return; } if (cls.state != CA_ACTIVE) { Com_FuncPrinf("You must be in a level to record.\n"); return; } if (Cmd_Argc() == 2) { s = Cmd_Argv(1); Q_strncpyz(demoName, s, sizeof(demoName)); Com_sprintf(name, sizeof(name), "demos/%s.%s%d", demoName, DEMOEXT, PROTOCOL_VERSION); } else { int number, len; // scan for a free demo name for (number = 0; number <= 9999; number++) { CL_DemoFilename(number, demoName); Com_sprintf(name, sizeof(name), "demos/%s.%s%d", demoName, DEMOEXT, PROTOCOL_VERSION); len = FS_ReadFile(name, NULL); if (len <= 0) { break; // file doesn't exist } } } CL_Record(name); }
//========================================================= // don't call this directly, it should only be called from SV_Map_f() or SV_MapTransition_f() // static bool SV_Map_( ForceReload_e eForceReload ) { char *map; char expanded[MAX_QPATH]; map = Cmd_Argv(1); if ( !*map ) { Com_Printf ("no map specified\n"); return false; } // make sure the level exists before trying to change, so that // a typo at the server console won't end the game if (strchr (map, '\\') ) { Com_Printf ("Can't have mapnames with a \\\n"); return false; } #ifndef _XBOX // Could check for maps/%s/brushes.mle or something... Com_sprintf (expanded, sizeof(expanded), "maps/%s.bsp", map); #ifndef _DEBUG Com_Printf("SV_Map_ CHECK HERE: %s\n", expanded); #endif if ( FS_ReadFile (expanded, NULL) == -1 ) { Com_Printf ("Can't find map %s\n", expanded); extern cvar_t *com_buildScript; if (com_buildScript && com_buildScript->integer) {//yes, it's happened, someone deleted a map during my build... Com_Error( ERR_FATAL, "Can't find map %s\n", expanded ); } return false; } #endif if (map[0]!='_') { SG_WipeSavegame("auto"); } #ifndef _DEBUG Com_Printf("SV_SpawnServer call: %s\n", map); #endif SV_SpawnServer( map, eForceReload, qtrue ); // start up the map return true; }