void luasrc_setmodulepaths(lua_State *L) { lua_getglobal(L, LUA_LOADLIBNAME); char gamePath[ 256 ]; engine->GetGameDir( gamePath, 256 ); //Andrew; set package.cpath. lua_getfield(L, -1, "cpath"); char lookupCPath[MAX_PATH]; Q_snprintf( lookupCPath, sizeof( lookupCPath ), "%s\\%s;%s", gamePath, #ifdef _WIN32 LUA_PATH_MODULES "\\?.dll", #elif _LINUX LUA_PATH_MODULES "\\?.so", #endif luaL_checkstring(L, -1) ); Q_strlower( lookupCPath ); Q_FixSlashes( lookupCPath ); lua_pop(L, 1); /* pop result */ lua_pushstring(L, lookupCPath); lua_setfield(L, -2, "cpath"); //Andrew; set package.path. lua_getfield(L, -1, "path"); char lookupPath[MAX_PATH]; Q_snprintf( lookupPath, sizeof( lookupPath ), "%s\\%s;%s", gamePath, LUA_PATH_MODULES "\\?.lua", luaL_checkstring(L, -1) ); Q_strlower( lookupPath ); Q_FixSlashes( lookupPath ); lua_pop(L, 1); /* pop result */ lua_pushstring(L, lookupPath); lua_setfield(L, -2, "path"); lua_pop(L, 1); /* pop result */ }
int CASW_Mission_Chooser_Source_Local::GetNumMissionsCompleted(const char *szSaveName) { Msg("GetNumMissionsCompleted %s\n", szSaveName); // check the save file exists char stripped[MAX_PATH]; V_StripExtension( szSaveName, stripped, MAX_PATH ); Msg(" stripped = %s\n", stripped); char tempfile[MAX_PATH]; Q_snprintf( tempfile, sizeof( tempfile ), "save/%s.campaignsave", stripped ); Msg(" tempfile = %s\n", tempfile); Q_strlower( tempfile ); Msg(" tempfile lowered = %s\n", tempfile); if (!g_pFullFileSystem->FileExists(tempfile)) { Msg(" this save doesn't exist! returning -1 missions\n"); return -1; } KeyValues *pSaveKeyValues = new KeyValues( szSaveName ); if (pSaveKeyValues->LoadFromFile(g_pFullFileSystem, tempfile)) { int iMissions = pSaveKeyValues->GetInt("NumMissionsComplete"); pSaveKeyValues->deleteThis(); Msg(" loaded keyvalues from file and it thinks num missions is %d\n", iMissions); return iMissions; } Msg(" Couldn't load save keyvalues from file, returning -1\n"); if (pSaveKeyValues->LoadFromFile(g_pFullFileSystem, tempfile, "MOD")) Msg(" but it loaded if we use the MOD path\n"); else if (pSaveKeyValues->LoadFromFile(g_pFullFileSystem, tempfile, "GAME")) Msg(" but it loaded if we use the GAME path\n"); pSaveKeyValues->deleteThis(); return -1; }
void GenerateUniquePlayerId(CSteamAPIContext *pSteamAPIContext) { CSHA1 sha1; // Add the steam name char szSteamId[256] = "\0"; CSteamID steamid = pSteamAPIContext->SteamUser()->GetSteamID(); V_sprintf_safe(szSteamId, "%u%u%u%u", steamid.GetEUniverse(), steamid.GetEAccountType(), steamid.GetAccountID(), steamid.GetUnAccountInstance()); sha1.Update((unsigned char *)szSteamId, strlen(szSteamId)); // Add some random numbers char randomNumbers[256] = "\0"; Q_snprintf(randomNumbers, sizeof(randomNumbers), "%i%i%i%i%i%i", RandomInt(0, 1000), RandomInt(0, 1000), RandomInt(0, 1000), RandomInt(0, 1000), RandomInt(0, 1000), RandomInt(0, 1000)); sha1.Update((unsigned char *)randomNumbers, strlen(randomNumbers)); // Generate the hash sha1.Final(); // Compile SHA1 Report char szReport[1024] = "\0"; sha1.ReportHash(szReport); // Remove the spaces and make it lowercase char playerId[1024] = "\0"; Q_StrSubst(szReport, " ", "", playerId, sizeof(playerId)); Q_strlower(playerId); DevMsg("Generated unique player ID: %s\n", playerId); ae_uniqueplayerid.SetValue(playerId); }
//----------------------------------------------------------------------------- // Purpose: Called when object is being created //----------------------------------------------------------------------------- void CTempEntTester::Spawn( void ) { // Not a physical thing... AddEffects( EF_NODRAW ); m_pCurrent = CBaseTempEntity::GetList(); while ( m_pCurrent ) { char name[ 128 ]; Q_strncpy( name, m_pCurrent->GetName() ,sizeof(name)); Q_strlower( name ); if ( strstr( name, m_szClass ) ) { break; } m_pCurrent = m_pCurrent->GetNext(); } if ( !m_pCurrent ) { DevMsg("Couldn't find temp entity '%s'\n", m_szClass ); UTIL_Remove( this ); return; } // Think right away SetNextThink( gpGlobals->curtime ); }
void CEP2GameStats::Event_LoadGame( void ) { BaseClass::Event_LoadGame(); Ep2LevelStats_t *map = m_pCurrentMap; if ( !map ) return; ++map->m_IntCounters[ Ep2LevelStats_t::COUNTER_LOADS ]; StatsLog( " %I64uth load on this map\n", map->m_IntCounters[ Ep2LevelStats_t::COUNTER_LOADS ] ); char const *pchSaveFile = engine->GetMostRecentlyLoadedFileName(); if ( !pchSaveFile || !pchSaveFile[ 0 ] ) return; char name[ 512 ]; Q_snprintf( name, sizeof( name ), "SAVE/%s", pchSaveFile ); Q_DefaultExtension( name, IsX360() ? ".360.sav" : ".sav", sizeof( name ) ); Q_FixSlashes( name ); Q_strlower( name ); Ep2LevelStats_t::SaveGameInfo_t *pSaveGameInfo = &map->m_SaveGameInfo; if ( pSaveGameInfo->m_nCurrentSaveFileTime == 0 || pSaveGameInfo->m_sCurrentSaveFile != name ) { unsigned int uFileTime = filesystem->GetFileTime( name, "GAME" ); // Latch off previous StatsLog( "Relatching save game file due to time or filename change (%s : %u)\n", name, uFileTime ); pSaveGameInfo->Latch( name, uFileTime ); } }
int UTIL_GetMapKeyCount( const char *pszCustomKey ) { if ( !pszCustomKey ) return 0; char szFilename[ _MAX_PATH ]; if ( !UTIL_GetMapLoadCountFileName( MAP_KEY_FILE, szFilename, _MAX_PATH ) ) return 0; int iCount = 0; KeyValues *kvMapLoadFile = new KeyValues( MAP_KEY_FILE ); if ( kvMapLoadFile ) { kvMapLoadFile->LoadFromFile( g_pFullFileSystem, szFilename, "MOD" ); char mapname[MAX_MAP_NAME]; Q_FileBase( engine->GetLevelName(), mapname, sizeof( mapname) ); Q_strlower( mapname ); KeyValues *pMapKey = kvMapLoadFile->FindKey( mapname ); if ( pMapKey ) { iCount = pMapKey->GetInt( pszCustomKey ); } kvMapLoadFile->deleteThis(); } return iCount; }
void SetSteamAppUser( KeyValues *pSteamInfo, const char *steamInstallPath, CSteamEnvVars &steamEnvVars ) { // Always inherit the Steam user if it's already set, since it probably means we (or the // the app that launched us) were launched from Steam. char appUser[MAX_PATH]; if ( steamEnvVars.m_SteamAppUser.GetValue( appUser, sizeof( appUser ) ) ) return; const char *pTempAppUser = NULL; if ( pSteamInfo && (pTempAppUser = pSteamInfo->GetString( "SteamAppUser", NULL )) != NULL ) { Q_strncpy( appUser, pTempAppUser, sizeof( appUser ) ); } else { // They don't have SteamInfo.txt, or it's missing SteamAppUser. Try to figure out the user // by looking in <steam install path>\config\SteamAppData.vdf. char fullFilename[MAX_PATH]; Q_strncpy( fullFilename, steamInstallPath, sizeof( fullFilename ) ); Q_AppendSlash( fullFilename, sizeof( fullFilename ) ); Q_strncat( fullFilename, "config\\SteamAppData.vdf", sizeof( fullFilename ), COPY_ALL_CHARACTERS ); KeyValues *pSteamAppData = ReadKeyValuesFile( fullFilename ); if ( !pSteamAppData || (pTempAppUser = pSteamAppData->GetString( "AutoLoginUser", NULL )) == NULL ) { Error( "Can't find steam app user info." ); } Q_strncpy( appUser, pTempAppUser, sizeof( appUser ) ); pSteamAppData->deleteThis(); } Q_strlower( appUser ); steamEnvVars.m_SteamAppUser.SetValue( "%s", appUser ); }
// Precache all wave files referenced in wave or rndwave keys virtual void LevelInitPreEntity() { char mapname[ 256 ]; #if !defined( CLIENT_DLL ) StartLog(); Q_snprintf( mapname, sizeof( mapname ), "maps/%s", STRING( gpGlobals->mapname ) ); #else Q_strncpy( mapname, engine->GetLevelName(), sizeof( mapname ) ); #endif Q_FixSlashes( mapname ); Q_strlower( mapname ); // Load in any map specific overrides char scriptfile[ 512 ]; Q_StripExtension( mapname, scriptfile, sizeof( scriptfile ) ); Q_strncat( scriptfile, "_level_sounds.txt", sizeof( scriptfile ), COPY_ALL_CHARACTERS ); if ( filesystem->FileExists( scriptfile, "GAME" ) ) { soundemitterbase->AddSoundOverrides( scriptfile ); } #if !defined( CLIENT_DLL ) for ( int i=soundemitterbase->First(); i != soundemitterbase->InvalidIndex(); i=soundemitterbase->Next( i ) ) { CSoundParametersInternal *pParams = soundemitterbase->InternalGetParametersForSound( i ); if ( pParams->ShouldPreload() ) { InternalPrecacheWaves( i ); } } #endif }
bool CBaseGameStats::SaveToFileNOW( bool bForceSyncWrite /* = false */ ) { if ( !StatsTrackingIsFullyEnabled() ) return false; // this code path is only for old format stats. Products that use new format take a different path. if ( !gamestats->UseOldFormat() ) return false; CUtlBuffer buf; buf.PutShort( GAMESTATS_FILE_VERSION ); buf.Put( s_szPseudoUniqueID, 16 ); if( ShouldTrackStandardStats() ) m_BasicStats.SaveToBuffer( buf ); else buf.PutInt( GAMESTATS_STANDARD_NOT_SAVED ); gamestats->AppendCustomDataToSaveBuffer( buf ); char fullpath[ 512 ] = { 0 }; if ( filesystem->FileExists( GetStatSaveFileName(), GAMESTATS_PATHID ) ) { filesystem->RelativePathToFullPath( GetStatSaveFileName(), GAMESTATS_PATHID, fullpath, sizeof( fullpath ) ); } else { // filename is local to game dir for Steam, so we need to prepend game dir for regular file save char gamePath[256]; engine->GetGameDir( gamePath, 256 ); Q_StripTrailingSlash( gamePath ); Q_snprintf( fullpath, sizeof( fullpath ), "%s/%s", gamePath, GetStatSaveFileName() ); Q_strlower( fullpath ); Q_FixSlashes( fullpath ); } // StatsLog( "SaveToFileNOW '%s'\n", fullpath ); if( CBGSDriver.m_bShuttingDown || bForceSyncWrite ) //write synchronously { filesystem->WriteFile( fullpath, GAMESTATS_PATHID, buf ); StatsLog( "Shut down wrote to '%s'\n", fullpath ); } else { // Allocate memory for async system to use (and free afterward!!!) size_t nBufferSize = buf.TellPut(); void *pMem = malloc(nBufferSize); CUtlBuffer statsBuffer( pMem, nBufferSize ); statsBuffer.Put( buf.Base(), nBufferSize ); // Write data async filesystem->AsyncWrite( fullpath, statsBuffer.Base(), statsBuffer.TellPut(), true, false ); } return true; }
static int CC_asw_teleport_autocomplete( char const *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] ) { if ( !g_pGameRules ) { return 0; } char const *cmdname = "asw_teleport"; char *substring = (char *)partial; if ( Q_strstr( partial, cmdname ) ) { substring = (char *)partial + strlen( cmdname ) + 1; } int checklen = Q_strlen( substring ); CUtlSymbolTable entries( 0, 0, true ); CUtlVector< CUtlSymbol > symbols; CBaseEntity *pos = NULL; while ( ( pos = gEntList.NextEnt( pos ) ) != NULL ) { // Check target name against partial string if ( pos->GetEntityName() == NULL_STRING ) continue; if ( Q_strnicmp( STRING( pos->GetEntityName() ), substring, checklen ) ) continue; CUtlSymbol sym = entries.AddString( STRING( pos->GetEntityName() ) ); int idx = symbols.Find( sym ); if ( idx == symbols.InvalidIndex() ) { symbols.AddToTail( sym ); } // Too many if ( symbols.Count() >= COMMAND_COMPLETION_MAXITEMS ) break; } // Now fill in the results for ( int i = 0; i < symbols.Count(); i++ ) { char const *name = entries.String( symbols[ i ] ); char buf[ 512 ]; Q_strncpy( buf, name, sizeof( buf ) ); Q_strlower( buf ); Q_snprintf( commands[ i ], COMMAND_COMPLETION_ITEM_LENGTH, "%s %s", cmdname, buf ); } return symbols.Count(); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void ReloadParticleEffectsInList( IFileList *pFilesToReload ) { MEM_ALLOC_CREDIT(); CUtlVector<CUtlString> files; GetParticleManifest( files ); // CAB 2/17/11 Reload all the particles regardless (Fixes filename change exploits). bool bReloadAll = true; //int nCount = files.Count(); //for ( int i = 0; i < nCount; ++i ) //{ // // Skip the precache marker // const char *pFile = files[i]; // if ( pFile[0] == '!' ) // { // pFile++; // } // char szDX80Filename[MAX_PATH]; // V_strncpy( szDX80Filename, pFile, sizeof( szDX80Filename ) ); // V_StripExtension( pFile, szDX80Filename, sizeof( szDX80Filename ) ); // V_strncat( szDX80Filename, "_dx80.", sizeof( szDX80Filename ) ); // V_strncat( szDX80Filename, V_GetFileExtension( pFile ), sizeof( szDX80Filename ) ); // if ( pFilesToReload->IsFileInList( pFile ) || pFilesToReload->IsFileInList( szDX80Filename ) ) // { // Msg( "Reloading all particle files due to pure settings.\n" ); // bReloadAll = true; // break; // } //} // Then check to see if we need to reload the map's particles const char *pszMapName = NULL; #ifdef CLIENT_DLL pszMapName = engine->GetLevelName(); #else pszMapName = STRING( gpGlobals->mapname ); #endif if ( pszMapName && pszMapName[0] ) { char mapname[MAX_MAP_NAME]; Q_FileBase( pszMapName, mapname, sizeof( mapname ) ); Q_strlower( mapname ); ParseParticleEffectsMap( mapname, true, pFilesToReload ); } if ( bReloadAll ) { ParseParticleEffects( true, true ); } g_pParticleSystemMgr->DecommitTempMemory(); }
//----------------------------------------------------------------------------- // Purpose: Playback sound file that contains phonemes // Input : *actor - // *parameters - //----------------------------------------------------------------------------- void C_SceneEntity::DispatchStartSpeak( CChoreoScene *scene, C_BaseFlex *actor, CChoreoEvent *event, soundlevel_t iSoundlevel ) { // Emit sound if ( IsClientOnly() && actor ) { CSingleUserRecipientFilter filter( C_BasePlayer::GetLocalPlayer() ); float time_in_past = m_flCurrentTime - event->GetStartTime() ; float soundtime = gpGlobals->curtime - time_in_past; EmitSound_t es; es.m_nChannel = CHAN_VOICE; es.m_flVolume = 1; es.m_SoundLevel = iSoundlevel; es.m_flSoundTime = soundtime; // No CC since we do it manually // FIXME: This will change es.m_bEmitCloseCaption = false; es.m_pSoundName = event->GetParameters(); EmitSound( filter, actor->entindex(), es ); actor->AddSceneEvent( scene, event, NULL, IsClientOnly() ); // Close captioning only on master token no matter what... if ( event->GetCloseCaptionType() == CChoreoEvent::CC_MASTER ) { char tok[ CChoreoEvent::MAX_CCTOKEN_STRING ]; bool validtoken = event->GetPlaybackCloseCaptionToken( tok, sizeof( tok ) ); if ( validtoken ) { CRC32_t tokenCRC; CRC32_Init( &tokenCRC ); char lowercase[ 256 ]; Q_strncpy( lowercase, tok, sizeof( lowercase ) ); Q_strlower( lowercase ); CRC32_ProcessBuffer( &tokenCRC, lowercase, Q_strlen( lowercase ) ); CRC32_Final( &tokenCRC ); float endtime = event->GetLastSlaveEndTime(); float durationShort = event->GetDuration(); float durationLong = endtime - event->GetStartTime(); float duration = MAX( durationShort, durationLong ); CHudCloseCaption *hudCloseCaption = GET_HUDELEMENT( CHudCloseCaption ); if ( hudCloseCaption ) { hudCloseCaption->ProcessCaption( lowercase, duration ); } } } } }
void UTIL_IncrementMapKey( const char *pszCustomKey ) { if ( !pszCustomKey ) return; char szFilename[ _MAX_PATH ]; if ( !UTIL_GetMapLoadCountFileName( MAP_KEY_FILE, szFilename, _MAX_PATH ) ) return; int iCount = 1; KeyValues *kvMapLoadFile = new KeyValues( MAP_KEY_FILE ); if ( kvMapLoadFile ) { kvMapLoadFile->LoadFromFile( g_pFullFileSystem, szFilename, "MOD" ); char mapname[MAX_MAP_NAME]; Q_FileBase( engine->GetLevelName(), mapname, sizeof( mapname) ); Q_strlower( mapname ); // Increment existing, or add a new one KeyValues *pMapKey = kvMapLoadFile->FindKey( mapname ); if ( pMapKey ) { iCount = pMapKey->GetInt( pszCustomKey, 0 ) + 1; pMapKey->SetInt( pszCustomKey, iCount ); } else { KeyValues *pNewKey = new KeyValues( mapname ); if ( pNewKey ) { pNewKey->SetString( pszCustomKey, "1" ); kvMapLoadFile->AddSubKey( pNewKey ); } } // Write it out // force create this directory incase it doesn't exist filesystem->CreateDirHierarchy( MAP_KEY_FILE_DIR, "MOD"); CUtlBuffer buf( 0, 0, CUtlBuffer::TEXT_BUFFER ); kvMapLoadFile->RecursiveSaveToFile( buf, 0 ); g_pFullFileSystem->WriteFile( szFilename, "MOD", buf ); kvMapLoadFile->deleteThis(); } if ( IsX360() ) { #ifdef _X360 xboxsystem->FinishContainerWrites(); #endif } }
//----------------------------------------------------------------------------- // Purpose: Constructor //----------------------------------------------------------------------------- CMaterialSubRect::CMaterialSubRect( const char *pMaterialName, const char *pTextureGroupName, KeyValues *pVMTKeyValues, KeyValues *pPatchKeyValues, bool bAssumeCreateFromFile ) { m_QueueFriendlyVersion.SetRealTimeVersion( this ); // Name with extension stripped off. int len = Q_strlen( pMaterialName ); char* pTemp = ( char* )_alloca( len + 1 ); Q_strncpy( pTemp, pMaterialName, len + 1 ); Q_strlower( pTemp ); pTemp[ len - 4 ] = '\0'; m_symName = pTemp; #ifdef _DEBUG m_pDebugName = new char[Q_strlen( pTemp ) + 1]; Q_strncpy( m_pDebugName, pTemp, Q_strlen( pTemp ) + 1 ); #endif m_pMaterialPage = NULL; m_iEnumID = 0; m_symTextureGroupName = pTextureGroupName; m_vecOffset.Init(); m_vecScale.Init(); m_vecSize.Init(); m_nRefCount = 0; m_fLocal = 0; m_aMaterialVars.Purge(); if ( pTemp[0] == '/' && pTemp[1] == '/' && pTemp[2] != '/' ) { m_fLocal |= MATERIALSUBRECT_USES_UNC_FILENAME; } if ( !bAssumeCreateFromFile ) { m_pVMTKeyValues = pVMTKeyValues; if (m_pVMTKeyValues) { m_fLocal |= MATERIALSUBRECT_IS_MANUALLY_CREATED; } // Precache immediately. We need the material page immediately. Precache(); } else { m_pVMTKeyValues = NULL; PrecacheVars( pVMTKeyValues, pPatchKeyValues ); Precache(); } Assert( m_pMaterialPage ); // Increment the material page usage counter. m_pMaterialPage->IncrementReferenceCount(); }
//----------------------------------------------------------------------------- // Purpose: Entity classnames need to be in lower case. Use this whenever // you're spawning a weapon. //----------------------------------------------------------------------------- const char *WeaponIdToClassname( int iWeapon ) { const char *pszWeaponAlias = WeaponIdToAlias( iWeapon ); if ( pszWeaponAlias == NULL ) return NULL; static char szEntName[256]; Q_strcpy( szEntName, pszWeaponAlias ); Q_strlower( szEntName ); return szEntName; }
//----------------------------------------------------------------------------- // Generate patched material name //----------------------------------------------------------------------------- static void GeneratePatchedMaterialName( const char *pMaterialName, char *pBuffer, int nMaxLen ) { int nLen = Q_snprintf( pBuffer, nMaxLen, "maps/%s/%s_wvt_patch", mapbase, pMaterialName ); Assert( nLen < TEXTURE_NAME_LENGTH - 1 ); if ( nLen >= TEXTURE_NAME_LENGTH - 1 ) { Error( "Generated worldvertextransition patch name : %s too long! (max = %d)\n", pBuffer, TEXTURE_NAME_LENGTH ); } BackSlashToForwardSlash( pBuffer ); Q_strlower( pBuffer ); }
const char *findFileInDirCaseInsensitive(const char *file) { #ifdef __ANDROID__ return file; // Most files are in sdcard, case-sensitive internal storage is for very specific cases. #endif const char *dirSep = strrchr(file,'/'); if( !dirSep ) { dirSep=strrchr(file,'\\'); if( !dirSep ) { return NULL; } } char *dirName = static_cast<char *>( alloca( ( dirSep - file ) +1 ) ); if( !dirName ) return NULL; strncpy( dirName , file, dirSep - file ); dirName[ dirSep - file ] = '\0'; struct dirent **namelist; int n; strncpy( fileName, dirSep + 1, MAX_PATH ); n = scandir( dirName , &namelist, CheckName, alphasort ); if( n > 0 ) { while( n > 1 ) { free( namelist[n] ); // free the malloc'd strings n--; } Q_snprintf( fileName, sizeof( fileName ), "%s/%s", dirName, namelist[0]->d_name ); free( namelist[0] ); return fileName; } else { Q_strncpy( fileName, file, sizeof(fileName) ); Q_strlower( fileName ); return fileName; } }
//----------------------------------------------------------------------------- // Purpose: // Input : *classname - // *module - // line - // Output : static int //----------------------------------------------------------------------------- static int ClassFileLineHash( const char *classname, const char *module, int line ) { CRC32_t retval; CRC32_Init( &retval ); char tempbuffer[ 512 ]; // ACK, have to go lower case due to issues with .dsp having different cases of drive // letters, etc.!!! Q_strncpy( tempbuffer, classname, sizeof( tempbuffer ) ); Q_strlower( tempbuffer ); CRC32_ProcessBuffer( &retval, (void *)tempbuffer, Q_strlen( tempbuffer ) ); Q_strncpy( tempbuffer, module, sizeof( tempbuffer ) ); Q_strlower( tempbuffer ); CRC32_ProcessBuffer( &retval, (void *)tempbuffer, Q_strlen( tempbuffer ) ); CRC32_ProcessBuffer( &retval, (void *)&line, sizeof( int ) ); CRC32_Final( &retval ); return (int)retval; }
const char *findFileInDirCaseInsensitive(const char *file) { const char *dirSep = strrchr(file,'/'); if( !dirSep ) { dirSep=strrchr(file,'\\'); if( !dirSep ) { return NULL; } } char *dirName = static_cast<char *>( alloca( ( dirSep - file ) +1 ) ); if( !dirName ) return NULL; strncpy( dirName , file, dirSep - file ); dirName[ dirSep - file ] = '\0'; struct dirent **namelist; int n; strncpy( fileName, dirSep + 1, MAX_PATH ); n = scandir( dirName , &namelist, CheckName, alphasort ); if( n > 0 ) { while( n > 1 ) { free( namelist[n] ); // free the malloc'd strings n--; } Q_snprintf( fileName, sizeof( fileName ), "%s/%s", dirName, namelist[0]->d_name ); free( namelist[0] ); return fileName; } else { Q_strncpy( fileName, file, sizeof(fileName) ); Q_strlower( fileName ); return fileName; } }
void CEP2GameStats::Event_SaveGame( void ) { BaseClass::Event_SaveGame(); Ep2LevelStats_t *map = m_pCurrentMap; if ( !map ) return; ++map->m_IntCounters[ Ep2LevelStats_t::COUNTER_SAVES ]; StatsLog( " %I64uth save on this map\n", map->m_IntCounters[ Ep2LevelStats_t::COUNTER_SAVES ] ); char const *pchSaveFile = engine->GetSaveFileName(); if ( !pchSaveFile || !pchSaveFile[ 0 ] ) return; char name[ 512 ]; Q_strncpy( name, pchSaveFile, sizeof( name ) ); Q_strlower( name ); Q_FixSlashes( name ); unsigned int uFileTime = filesystem->GetFileTime( name, "GAME" ); // Latch off previous map->m_SaveGameInfo.Latch( name, uFileTime ); Ep2LevelStats_t::SaveGameInfoRecord2_t *rec = map->m_SaveGameInfo.m_pCurrentRecord; CBasePlayer *pPlayer = UTIL_GetLocalPlayer(); if ( pPlayer ) { Vector pos = pPlayer->GetAbsOrigin(); rec->m_nSavePos[ 0 ] = (short)pos.x; rec->m_nSavePos[ 1 ] = (short)pos.y; rec->m_nSavePos[ 2 ] = (short)pos.z; rec->m_nSaveHealth = clamp( pPlayer->GetHealth(), 0, 100 ); rec->m_SaveType = Q_stristr( pchSaveFile, "autosave" ) ? Ep2LevelStats_t::SaveGameInfoRecord2_t::TYPE_AUTOSAVE : Ep2LevelStats_t::SaveGameInfoRecord2_t::TYPE_USERSAVE; StatsLog( "save pos %i %i %i w/ health %d\n", rec->m_nSavePos[ 0 ], rec->m_nSavePos[ 1 ], rec->m_nSavePos[ 2 ], rec->m_nSaveHealth ); } }
// Assumed to be set up by calling code bool AsyncCaption_t::LoadFromFile( const char *pRelativePath ) { char pRelativePathFixed[MAX_PATH]; Q_strncpy( pRelativePathFixed, pRelativePath, sizeof(pRelativePathFixed) ); Q_FixSlashes( pRelativePathFixed ); Q_strlower( pRelativePathFixed ); pRelativePath = pRelativePathFixed; if ( Q_IsAbsolutePath( pRelativePath ) ) { Warning( "AsyncCaption_t::LoadFromFile: Fullpath encountered! %s\n", pRelativePath ); } FileHandle_t fh = g_pFullFileSystem->Open( pRelativePath, "rb", "GAME" ); if ( FILESYSTEM_INVALID_HANDLE == fh ) return false; MEM_ALLOC_CREDIT(); CUtlBuffer dirbuffer; // Read the header g_pFullFileSystem->Read( &m_Header, sizeof( m_Header ), fh ); if ( m_Header.magic != COMPILED_CAPTION_FILEID ) Error( "Invalid file id for %s\n", pRelativePath ); if ( m_Header.version != COMPILED_CAPTION_VERSION ) Error( "Invalid file version for %s\n", pRelativePath ); if ( m_Header.directorysize < 0 || m_Header.directorysize > 64 * 1024 ) Error( "Invalid directory size %d for %s\n", m_Header.directorysize, pRelativePath ); //if ( m_Header.blocksize != MAX_BLOCK_SIZE ) // Error( "Invalid block size %d, expecting %d for %s\n", m_Header.blocksize, MAX_BLOCK_SIZE, pchFullPath ); int directoryBytes = m_Header.directorysize * sizeof( CaptionLookup_t ); m_CaptionDirectory.EnsureCapacity( m_Header.directorysize ); dirbuffer.EnsureCapacity( directoryBytes ); g_pFullFileSystem->Read( dirbuffer.Base(), directoryBytes, fh ); g_pFullFileSystem->Close( fh ); m_CaptionDirectory.CopyArray( (const CaptionLookup_t *)dirbuffer.PeekGet(), m_Header.directorysize ); m_CaptionDirectory.RedoSort( true ); m_DataBaseFile = pRelativePath; return true; }
//----------------------------------------------------------------------------- // Generate patched material name //----------------------------------------------------------------------------- inline void GeneratePatchedName( const char *pMaterialName, const PatchInfo_t &info, bool bMaterialName, char *pBuffer, int nMaxLen ) { const char *pSeparator = bMaterialName ? "_" : ""; int nLen = Q_snprintf( pBuffer, nMaxLen, "maps/%s/%s%s%d_%d_%d", info.m_pMapName, pMaterialName, pSeparator, info.m_pOrigin[0], info.m_pOrigin[1], info.m_pOrigin[2] ); if ( bMaterialName ) { Assert( nLen < TEXTURE_NAME_LENGTH - 1 ); if ( nLen >= TEXTURE_NAME_LENGTH - 1 ) { Error( "Generated env_cubemap patch name : %s too long!\n", pBuffer ); } } BackSlashToForwardSlash( pBuffer ); Q_strlower( pBuffer ); }
unsigned short UTIL_GetAchievementEventMask( void ) { CRC32_t mapCRC; CRC32_Init( &mapCRC ); char lowercase[ 256 ]; #ifdef CLIENT_DLL Q_FileBase( engine->GetLevelName(), lowercase, sizeof( lowercase ) ); #else Q_strncpy( lowercase, STRING( gpGlobals->mapname ), sizeof( lowercase ) ); #endif Q_strlower( lowercase ); CRC32_ProcessBuffer( &mapCRC, lowercase, Q_strlen( lowercase ) ); CRC32_Final( &mapCRC ); return ( mapCRC & 0xFFFF ); }
//----------------------------------------------------------------------------- // Purpose: // Input : &vecOrigin - // &vecAngles - // *single_te - // Output : CBaseEntity //----------------------------------------------------------------------------- CBaseEntity *CTempEntTester::Create( const Vector &vecOrigin, const QAngle &vecAngles, const char *lifetime, const char *single_te ) { float life; char classname[ 128 ]; if ( lifetime && lifetime[0] ) { life = atoi( lifetime ); life = MAX( 1.0, life ); life = MIN( 1000.0, life ); life += gpGlobals->curtime; } else { Msg( "Usage: te <lifetime> <entname>\n" ); return NULL; } if ( single_te && single_te[0] ) { Q_strncpy( classname, single_te ,sizeof(classname)); Q_strlower( classname ); } else { Msg( "Usage: te <lifetime> <entname>\n" ); return NULL; } CTempEntTester *p = ( CTempEntTester * )CBaseEntity::CreateNoSpawn( "te_tester", vecOrigin, vecAngles ); if ( !p ) { return NULL; } Q_strncpy( p->m_szClass, classname ,sizeof(p->m_szClass)); p->m_fLifeTime = life; p->Spawn(); return p; }
void FileSystem_SetupStandardDirectories( const char *pFilename, const char *pGameInfoPath ) { // Set qdir. if ( !pFilename ) { pFilename = "."; } Q_MakeAbsolutePath( qdir, sizeof( qdir ), pFilename, NULL ); Q_StripFilename( qdir ); Q_strlower( qdir ); if ( qdir[0] != 0 ) { Q_AppendSlash( qdir, sizeof( qdir ) ); } // Set gamedir. Q_MakeAbsolutePath( gamedir, sizeof( gamedir ), pGameInfoPath ); Q_AppendSlash( gamedir, sizeof( gamedir ) ); }
int UTIL_GetMapKeyCount( const char *pszCustomKey ) { if ( !pszCustomKey ) return 0; char szFilename[ _MAX_PATH ]; if ( !UTIL_GetMapLoadCountFileName( MAP_KEY_FILE, szFilename, _MAX_PATH ) ) return 0; int iCount = 0; KeyValues *kvMapLoadFile = new KeyValues( MAP_KEY_FILE ); if ( kvMapLoadFile ) { // create an empty file if none exists if ( !g_pFullFileSystem->FileExists( szFilename, "MOD" ) ) { // force create this directory incase it doesn't exist filesystem->CreateDirHierarchy( MAP_KEY_FILE_DIR, "MOD"); CUtlBuffer buf( 0, 0, CUtlBuffer::TEXT_BUFFER ); g_pFullFileSystem->WriteFile( szFilename, "MOD", buf ); } kvMapLoadFile->LoadFromFile( g_pFullFileSystem, szFilename, "MOD" ); char mapname[MAX_MAP_NAME]; Q_FileBase( engine->GetLevelName(), mapname, sizeof( mapname) ); Q_strlower( mapname ); KeyValues *pMapKey = kvMapLoadFile->FindKey( mapname ); if ( pMapKey ) { iCount = pMapKey->GetInt( pszCustomKey ); } kvMapLoadFile->deleteThis(); } return iCount; }
//----------------------------------------------------------------------------- // Purpose: Fills buffer with list of maps from this mod //----------------------------------------------------------------------------- void CServerRemoteAccess::GetMapList(CUtlBuffer &value) { // search the directory structure. char mapwild[MAX_QPATH]; char friendly_com_gamedir[ MAX_OSPATH ]; strcpy(mapwild, "maps/*.bsp"); Q_strncpy( friendly_com_gamedir, com_gamedir, sizeof(friendly_com_gamedir) ); Q_strlower( friendly_com_gamedir ); char const *findfn = Sys_FindFirst( mapwild, NULL, 0 ); while ( findfn ) { char curDir[MAX_PATH]; _snprintf(curDir, MAX_PATH, "maps/%s", findfn); g_pFileSystem->GetLocalPath(curDir, curDir, MAX_PATH); // limit maps displayed to ones for the mod only if (strstr(curDir, friendly_com_gamedir)) { // clean up the map name char mapName[MAX_PATH]; strcpy(mapName, findfn); char *extension = strstr(mapName, ".bsp"); if (extension) { *extension = 0; } // write into buffer value.PutString(mapName); value.PutString("\n"); } findfn = Sys_FindNext( NULL, 0 ); } Sys_FindClose(); value.PutChar(0); }
void CBaseScripted::InitScriptedEntity( void ) { #if defined ( LUA_SDK ) #if 0 #ifndef CLIENT_DLL // Let the instance reinitialize itself for the client. if ( m_nTableReference != LUA_NOREF ) return; #endif #endif SetThink( &CBaseScripted::Think ); #ifdef CLIENT_DLL SetNextClientThink( gpGlobals->curtime ); #endif SetNextThink( gpGlobals->curtime ); SetTouch( &CBaseScripted::Touch ); char className[ 255 ]; #if defined ( CLIENT_DLL ) if ( strlen( GetScriptedClassname() ) > 0 ) Q_strncpy( className, GetScriptedClassname(), sizeof( className ) ); else Q_strncpy( className, GetClassname(), sizeof( className ) ); #else Q_strncpy( m_iScriptedClassname.GetForModify(), GetClassname(), sizeof( className ) ); Q_strncpy( className, GetClassname(), sizeof( className ) ); #endif Q_strlower( className ); SetClassname( className ); if ( m_nTableReference == LUA_NOREF ) { LoadScriptedEntity(); m_nTableReference = luaL_ref( L, LUA_REGISTRYINDEX ); } else { lua_getglobal( L, "table" ); if ( lua_istable( L, -1 ) ) { lua_getfield( L, -1, "merge" ); if ( lua_isfunction( L, -1 ) ) { lua_remove( L, -2 ); lua_getref( L, m_nTableReference ); LoadScriptedEntity(); luasrc_pcall( L, 2, 0, 0 ); } else { lua_pop( L, 2 ); } } else { lua_pop( L, 1 ); } } BEGIN_LUA_CALL_ENTITY_METHOD( "Initialize" ); END_LUA_CALL_ENTITY_METHOD( 0, 0 ); #endif }
void WritePHXFile( const char *pName, const phyfile_t &file ) { if ( file.header.size != sizeof(file.header) || file.collide.solidCount <= 0 ) return; CUtlBuffer out; char outName[1024]; Q_snprintf( outName, sizeof(outName), "%s", pName ); Q_SetExtension( outName, ".phx", sizeof(outName) ); simplifyparams_t params; params.Defaults(); params.tolerance = (file.collide.solidCount > 1) ? 4.0f : 2.0f; // single solids constraint to AABB for placement help params.addAABBToSimplifiedHull = (file.collide.solidCount == 1) ? true : false; params.mergeConvexElements = true; params.mergeConvexTolerance = 0.025f; Q_FixSlashes(outName); Q_strlower(outName); char *pSearch = Q_strstr( outName,"models\\" ); if ( pSearch ) { char keyname[1024]; pSearch += strlen("models\\"); Q_StripExtension( pSearch, keyname, sizeof(keyname) ); OverrideDefaultsForModel( keyname, params ); } out.Put( &file.header, sizeof(file.header) ); int outSize = 0; bool bStoreSolidNames = file.collide.solidCount > 1 ? true : false; bStoreSolidNames = bStoreSolidNames || HasMultipleBones(outName); vcollide_t *pNewCollide = ConvertVCollideToPHX( &file.collide, params, &outSize, false, bStoreSolidNames); g_TotalOut += file.fileSize; for ( int i = 0; i < pNewCollide->solidCount; i++ ) { int collideSize = physcollision->CollideSize( pNewCollide->solids[i] ); out.PutInt( collideSize ); char *pMem = new char[collideSize]; physcollision->CollideWrite( pMem, pNewCollide->solids[i] ); out.Put( pMem, collideSize ); delete[] pMem; } if (!g_bQuiet) { Msg("%s Compressed %d (%d text) to %d (%d text)\n", outName, file.fileSize, file.collide.descSize, out.TellPut(), pNewCollide->descSize ); } out.Put( pNewCollide->pKeyValues, pNewCollide->descSize ); g_TotalCompress += out.TellPut(); #if 0 //Msg("OLD:\n-----------------------------------\n%s\n", file.collide.pKeyValues ); CPackedPhysicsDescription *pPacked = physcollision->CreatePackedDesc( pNewCollide->pKeyValues, pNewCollide->descSize ); Msg("NEW:\n-----------------------------------\n" ); for ( int i = 0; i < pPacked->m_solidCount; i++ ) { solid_t solid; pPacked->GetSolid( &solid, i ); Msg("index %d\n", solid.index ); Msg("name %s\n", solid.name ); Msg("mass %.2f\n", solid.params.mass ); Msg("surfaceprop %s\n", solid.surfaceprop); Msg("damping %.2f\n", solid.params.damping ); Msg("rotdamping %.2f\n", solid.params.rotdamping ); Msg("drag %.2f\n", solid.params.dragCoefficient ); Msg("inertia %.2f\n", solid.params.inertia ); Msg("volume %.2f\n", solid.params.volume ); } #endif DestroyPHX( pNewCollide ); if ( !g_pFullFileSystem->WriteFile( outName, NULL, out ) ) Warning("Can't write file: %s\n", outName ); }
//========================================================= //========================================================= CSingleplayRules::CSingleplayRules( void ) { RefreshSkillData( true ); const char *cfgfile = defaultcfgfile.GetString(); if (cfgfile && cfgfile[0]) { char szCommand[256]; Log("Executing default gamemode config file %s\n", cfgfile); Q_snprintf(szCommand, sizeof(szCommand), "exec %s\n", cfgfile); engine->ServerCommand(szCommand); } char mapcfg[256]; Q_snprintf(mapcfg, sizeof(mapcfg), "cfg/%s.cfg", STRING(gpGlobals->mapname)); Q_FixSlashes(mapcfg); Q_strlower(mapcfg); if (mapcfg) { char szCommandMap[256]; Log("Executing map config file %s\n", mapcfg); Q_snprintf(szCommandMap, sizeof(szCommandMap), "exec %s\n", mapcfg); engine->ServerCommand(szCommandMap); } char mapname[256]; #if !defined( CLIENT_DLL ) Q_snprintf(mapname, sizeof(mapname), "maps/%s", STRING(gpGlobals->mapname)); #else Q_strncpy(mapname, engine->GetLevelName(), sizeof(mapname)); #endif Q_FixSlashes(mapname); Q_strlower(mapname); if (V_stristr(mapname, "cf")) { SetGamemode(FIREFIGHT_PRIMARY_COMBINEFIREFIGHT); Log("Automatically setting the gamemode to COMBINE FIREFIGHT due to mapname.\n"); } else if (V_stristr(mapname, "xi")) { SetGamemode(FIREFIGHT_PRIMARY_XENINVASION); Log("Automatically setting the gamemode to XEN INVASION due to mapname.\n"); } else if (V_stristr(mapname, "aa")) { SetGamemode(FIREFIGHT_PRIMARY_ANTLIONASSAULT); Log("Automatically setting the gamemode to ANTLION ASSAULT due to mapname.\n"); } else if (V_stristr(mapname, "zs")) { SetGamemode(FIREFIGHT_PRIMARY_ZOMBIESURVIVAL); Log("Automatically setting the gamemode to ZOMBIE SURVIVAL due to mapname.\n"); } else if (V_stristr(mapname, "fr")) { SetGamemode(FIREFIGHT_PRIMARY_FIREFIGHTRUMBLE); Log("Automatically setting the gamemode to FIREFIGHT RUMBLE due to mapname.\n"); } if (GetGamemode() == FIREFIGHT_PRIMARY_DEFAULT) { if (bHasRandomized) { bHasRandomized = false; iRandomGamemode = 0; } Log("No gamemode defined! Randomizing gamemodes.\n"); SetGamemodeRandom(FIREFIGHT_PRIMARY_COMBINEFIREFIGHT, FIREFIGHT_PRIMARY_FIREFIGHTRUMBLE, true); bHasRandomized = true; } if (bHasRandomized) { if (iRandomGamemode == FIREFIGHT_PRIMARY_COMBINEFIREFIGHT) { // listen server const char *cfgfilecf = combinefirefightcfgfile.GetString(); if (cfgfilecf && cfgfilecf[0]) { char szCommand[256]; Log("Executing COMBINE FIREFIGHT gamemode config file %s\n", cfgfilecf); Q_snprintf(szCommand, sizeof(szCommand), "exec %s\n", cfgfilecf); engine->ServerCommand(szCommand); } } else if (iRandomGamemode == FIREFIGHT_PRIMARY_XENINVASION) { // listen server const char *cfgfilexi = xeninvasioncfgfile.GetString(); if (cfgfilexi && cfgfilexi[0]) { char szCommand[256]; Log("Executing XEN INVASION gamemode config file %s\n", cfgfilexi); Q_snprintf(szCommand, sizeof(szCommand), "exec %s\n", cfgfilexi); engine->ServerCommand(szCommand); } } else if (iRandomGamemode == FIREFIGHT_PRIMARY_ANTLIONASSAULT) { // listen server const char *cfgfileaa = antlionassaultcfgfile.GetString(); if (cfgfileaa && cfgfileaa[0]) { char szCommand[256]; Log("Executing ANTLION ASSAULT gamemode config file %s\n", cfgfileaa); Q_snprintf(szCommand, sizeof(szCommand), "exec %s\n", cfgfileaa); engine->ServerCommand(szCommand); } } else if (iRandomGamemode == FIREFIGHT_PRIMARY_ZOMBIESURVIVAL) { // listen server const char *cfgfilezs = zombiesurvivalcfgfile.GetString(); if (cfgfilezs && cfgfilezs[0]) { char szCommand[256]; Log("Executing ZOMBIE SURVIVAL gamemode config file %s\n", cfgfilezs); Q_snprintf(szCommand, sizeof(szCommand), "exec %s\n", cfgfilezs); engine->ServerCommand(szCommand); } } else if (iRandomGamemode == FIREFIGHT_PRIMARY_FIREFIGHTRUMBLE) { // listen server const char *cfgfilefr = firefightrumblecfgfile.GetString(); if (cfgfilefr && cfgfilefr[0]) { char szCommand[256]; Log("Executing FIREFIGHT RUMBLE gamemode config file %s\n", cfgfilefr); Q_snprintf(szCommand, sizeof(szCommand), "exec %s\n", cfgfilefr); engine->ServerCommand(szCommand); } } } else { if (GetGamemode() == FIREFIGHT_PRIMARY_COMBINEFIREFIGHT) { // listen server const char *cfgfilecf = combinefirefightcfgfile.GetString(); if (cfgfilecf && cfgfilecf[0]) { char szCommand[256]; Log("Executing COMBINE FIREFIGHT gamemode config file %s\n", cfgfilecf); Q_snprintf(szCommand, sizeof(szCommand), "exec %s\n", cfgfilecf); engine->ServerCommand(szCommand); } } else if (GetGamemode() == FIREFIGHT_PRIMARY_XENINVASION) { // listen server const char *cfgfilexi = xeninvasioncfgfile.GetString(); if (cfgfilexi && cfgfilexi[0]) { char szCommand[256]; Log("Executing XEN INVASION gamemode config file %s\n", cfgfilexi); Q_snprintf(szCommand, sizeof(szCommand), "exec %s\n", cfgfilexi); engine->ServerCommand(szCommand); } } else if (GetGamemode() == FIREFIGHT_PRIMARY_ANTLIONASSAULT) { // listen server const char *cfgfileaa = antlionassaultcfgfile.GetString(); if (cfgfileaa && cfgfileaa[0]) { char szCommand[256]; Log("Executing ANTLION ASSAULT gamemode config file %s\n", cfgfileaa); Q_snprintf(szCommand, sizeof(szCommand), "exec %s\n", cfgfileaa); engine->ServerCommand(szCommand); } } else if (GetGamemode() == FIREFIGHT_PRIMARY_ZOMBIESURVIVAL) { // listen server const char *cfgfilezs = zombiesurvivalcfgfile.GetString(); if (cfgfilezs && cfgfilezs[0]) { char szCommand[256]; Log("Executing ZOMBIE SURVIVAL gamemode config file %s\n", cfgfilezs); Q_snprintf(szCommand, sizeof(szCommand), "exec %s\n", cfgfilezs); engine->ServerCommand(szCommand); } } else if (GetGamemode() == FIREFIGHT_PRIMARY_FIREFIGHTRUMBLE) { // listen server const char *cfgfilefr = firefightrumblecfgfile.GetString(); if (cfgfilefr && cfgfilefr[0]) { char szCommand[256]; Log("Executing FIREFIGHT RUMBLE gamemode config file %s\n", cfgfilefr); Q_snprintf(szCommand, sizeof(szCommand), "exec %s\n", cfgfilefr); engine->ServerCommand(szCommand); } } } }