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 ); } }
CChoreoScene *C_SceneEntity::LoadScene( const char *filename ) { char loadfile[ 512 ]; Q_strncpy( loadfile, filename, sizeof( loadfile ) ); Q_SetExtension( loadfile, ".vcd", sizeof( loadfile ) ); Q_FixSlashes( loadfile ); char *pBuffer = NULL; size_t bufsize = scenefilecache->GetSceneBufferSize( loadfile ); if ( bufsize <= 0 ) return NULL; pBuffer = new char[ bufsize ]; if ( !scenefilecache->GetSceneData( filename, (byte *)pBuffer, bufsize ) ) { delete[] pBuffer; return NULL; } CChoreoScene *pScene; if ( IsBufferBinaryVCD( pBuffer, bufsize ) ) { pScene = new CChoreoScene( this ); CUtlBuffer buf( pBuffer, bufsize, CUtlBuffer::READ_ONLY ); if ( !pScene->RestoreFromBinaryBuffer( buf, loadfile, &g_ChoreoStringPool ) ) { Warning( "Unable to restore binary scene '%s'\n", loadfile ); delete pScene; pScene = NULL; } else { pScene->SetPrintFunc( Scene_Printf ); pScene->SetEventCallbackInterface( this ); } } else { g_TokenProcessor.SetBuffer( pBuffer ); pScene = ChoreoLoadScene( loadfile, this, &g_TokenProcessor, Scene_Printf ); } delete[] pBuffer; return pScene; }
bool CmdLib_HasBasePath( const char *pFileName_, int &pathLength ) { char *pFileName = ( char * )_alloca( strlen( pFileName_ ) + 1 ); strcpy( pFileName, pFileName_ ); Q_FixSlashes( pFileName ); pathLength = 0; int i; for( i = 0; i < g_NumBasePaths; i++ ) { // see if we can rip the base off of the filename. if( Q_strncasecmp( g_pBasePaths[i], pFileName, strlen( g_pBasePaths[i] ) ) == 0 ) { pathLength = strlen( g_pBasePaths[i] ); return true; } } return false; }
/* CUtlVector< SimpleTexture* > hList_Textures; CUtlVector< SimpleCombo* > hList_Combos; CUtlVector< SimpleEnvConstant* > hList_EConstants; */ void df_SaveDump_File( const char *canvasname, const BasicShaderCfg_t &shader ) { KeyValues *pKV = new KeyValues( canvasname ); char _path[MAX_PATH]; Q_snprintf( _path, MAX_PATH, "%s/%s.dump", ::GetDumpDirectory(), canvasname ); Q_FixSlashes( _path ); pKV->SetString( "vs_name", shader.ProcVSName ); pKV->SetString( "ps_name", shader.ProcPSName ); pKV->SetString( "shader_filename", shader.Filename ); pKV->SetString( GetDumpVersion_KeyName(), GetDumpVersion_Current() ); pKV->SetInt( "i_sm", shader.iShaderModel ); pKV->SetInt( "i_cull", shader.iCullmode ); pKV->SetInt( "i_ablend", shader.iAlphablendmode ); pKV->SetFloat( "fl_atestref", shader.flAlphaTestRef ); pKV->SetInt( "i_dtest", shader.iDepthtestmode ); pKV->SetInt( "i_dwrite", shader.iDepthwritemode ); pKV->SetInt( "i_srgbw", shader.bsRGBWrite ? 1 : 0 ); pKV->SetInt( "i_vfmt_flags", shader.iVFMT_flags ); pKV->SetInt( "i_vfmt_texcoords", shader.iVFMT_numTexcoords ); pKV->SetInt( "i_vfmt_udata", shader.iVFMT_numUserData ); for ( int i = 0; i < 3; i++ ) { char tmp[48]; Q_snprintf( tmp, sizeof(tmp), "i_vfmt_texcoordDim_%i", i ); pKV->SetInt( tmp, shader.iVFMT_texDim[i] ); } pKV->SetInt( "i_vlit", shader.bVertexLighting ); pKV->SetInt( "i_vrefract", shader.bRefractionSupport ); KeyValues *pKVIdentVS = __AllocKV_Identifiers( shader.pVS_Identifiers ); pKVIdentVS->SetName( "identifiers_VS" ); pKV->AddSubKey( pKVIdentVS ); KeyValues *pKVIdentPS = __AllocKV_Identifiers( shader.pPS_Identifiers ); pKVIdentPS->SetName( "identifiers_PS" ); pKV->AddSubKey( pKVIdentPS ); pKV->SaveToFile( g_pFullFileSystem, _path, "MOD" ); pKV->deleteThis(); }
KeyValues *CCompiledKeyValuesReader::Instance( char const *kvfilename ) { char sz[ 512 ]; Q_strncpy( sz, kvfilename, sizeof( sz ) ); Q_FixSlashes( sz ); FileInfo_t search; search.hFile = g_pFullFileSystem->FindOrAddFileName( sz ); int idx = m_Dict.Find( search ); if ( idx == m_Dict.InvalidIndex() ) { return NULL; } const FileInfo_t& info = m_Dict[ idx ]; return CreateFromData( info ); }
IFaceposerModels::CFacePoserModel::CFacePoserModel( char const *modelfile, StudioModel *model ) { m_pModel = model; m_szActorName[ 0 ] = 0; m_szShortName[ 0 ] = 0; strcpy( m_szModelFileName, modelfile ); Q_FixSlashes( m_szModelFileName ); CStudioHdr *hdr = model->GetStudioHdr(); if ( hdr ) { Q_StripExtension( hdr->pszName(), m_szShortName, sizeof( m_szShortName ) ); } m_bVisibileIn3DView = false; m_bFirstBitmapLoad = true; LoadBitmaps(); }
//----------------------------------------------------------------------------- // Purpose: // Output : const char //----------------------------------------------------------------------------- const char *CExpression::GetBitmapFilename( int modelindex ) { static char filename[ 256 ] = { 0 }; char const *classname = "error"; CExpClass *cl = GetExpressionClass(); if ( cl ) { classname = cl->GetBaseName(); } char modelName[512], modelNameTemp[512]; Q_strncpy( modelNameTemp, models->GetModelName( modelindex ), sizeof( modelNameTemp ) ); char const *in = modelNameTemp; char *out = modelName; while ( *in ) { if ( isalnum( *in ) || *in == '_' || *in == '\\' || *in == '/' || *in == '.' || *in == ':' ) { *out++ = *in; } in++; } *out = 0; sprintf( filename, "expressions/%s/%s/%s.bmp", modelName, classname, GetBitmapCheckSum() ); Q_FixSlashes( filename ); strlwr( filename ); CreatePath( filename ); return filename; }
bool CCompiledKeyValuesReader::LookupKeyValuesRootKeyName( char const *kvfilename, char *outbuf, size_t bufsize ) { char sz[ 512 ]; Q_strncpy( sz, kvfilename, sizeof( sz ) ); Q_FixSlashes( sz ); FileInfo_t search; search.hFile = g_pFullFileSystem->FindOrAddFileName( sz ); int idx = m_Dict.Find( search ); if ( idx == m_Dict.InvalidIndex() ) { return false; } const FileInfo_t& info = m_Dict[ idx ]; Q_strncpy( outbuf, m_StringTable.Lookup( m_Data[ info.nFirstIndex ].key ), bufsize ); return true; }
int main(int argc, char* argv[]) { if ( argc < 2 ) { printf("Usage: test_binaries <FILENAME>\n" ); } else { char fileName[2048], dir[2048]; if ( !Q_ExtractFilePath( argv[1], dir, sizeof( dir ) ) ) { strcpy( dir, "" ); } else { Q_FixSlashes( dir, '/' ); int len = strlen(dir); if ( len && dir[len-1] !='/' ) { strcat( dir, "/" ); } } WIN32_FIND_DATA findData; HANDLE hFind = FindFirstFile( argv[1], &findData ); if ( hFind == INVALID_HANDLE_VALUE ) { printf("Can't find %s\n", argv[1] ); } else { do { sprintf( fileName, "%s%s", dir, findData.cFileName ); TestFile( fileName ); } while ( FindNextFile( hFind, &findData ) ); FindClose( hFind ); } } return 0; }
//----------------------------------------------------------------------------- // Adds the platform folder to the search path. //----------------------------------------------------------------------------- void FileSystem_AddSearchPath_Platform( IFileSystem *pFileSystem, const char *szGameInfoPath ) { char platform[MAX_PATH]; if ( pFileSystem->IsSteam() ) { // Steam doesn't support relative paths Q_strncpy( platform, "platform", MAX_PATH ); } else { if ( !Sys_GetExecutableName( platform, sizeof( platform ) ) ) { // fall back to old method if we can't get the executable name Q_strncpy( platform, szGameInfoPath, MAX_PATH ); Q_StripTrailingSlash( platform ); Q_strncat( platform, "/../platform", MAX_PATH, MAX_PATH ); } else { Q_StripFilename( platform ); Q_StripTrailingSlash( platform ); Q_FixSlashes( platform ); // remove bin folder if necessary int nLen = Q_strlen( platform ); if ( ( nLen > 4 ) && platform[ nLen - 4 ] == CORRECT_PATH_SEPARATOR && !Q_stricmp( "bin", platform + ( nLen - 3 ) ) ) { Q_StripLastDir( platform, sizeof( platform ) ); Q_StripTrailingSlash( platform ); } // go into platform folder Q_strncat( platform, "/platform", MAX_PATH, MAX_PATH ); } } pFileSystem->AddSearchPath( platform, "PLATFORM" ); }
bool IsUsingPerPlayerExpressions() { bool bPerPlayerExpressions = false; if ( CommandLine()->CheckParm( "-perplayerexpressions" ) ) { bPerPlayerExpressions = true; } else { // Returns the search path, each path is separated by ;s. Returns the length of the string returned char pSearchPath[2048]; if ( g_pFullFileSystem->GetSearchPath( "GAME", false, pSearchPath, sizeof(pSearchPath) ) ) { Q_FixSlashes( pSearchPath ); if ( Q_stristr( pSearchPath, "\\tf" ) ) { bPerPlayerExpressions = true; } } } return bPerPlayerExpressions; }
void RemoveFromWhiteList( char const *path ) { vprint( 2, "-\t'%s'\n", path ); char dir[ 512 ]; Q_strncpy( dir, path, sizeof( dir ) ); // Get the base filename from the path _strlwr( dir ); Q_FixSlashes( dir ); CUtlVector< FileEntry > files; char *lastslash = strrchr( dir, '\\' ); if ( lastslash == 0 ) { BuildFileListWildcard( 1, files, "", dir, 0 ); } else { char *wild = lastslash + 1; *lastslash = 0; BuildFileListWildcard( 1, files, dir, wild, 0 ); } int c = files.Count(); for ( int i = 0; i < c; ++i ) { UnusedContent::CUtlSymbol sym = files[ i ].sym; int idx = g_WhiteList.Find( sym ); if ( idx != g_WhiteList.InvalidIndex() ) { g_WhiteList.RemoveAt( idx ); ++wl_removed; } } }
CRoomTemplate* CLevelTheme::FindRoom( const char *szRoomTemplate ) { // strip off .vmf if it's there static char buffer[ 256 ]; Q_snprintf( buffer, sizeof( buffer ), "%s", szRoomTemplate ); int len = Q_strlen( buffer ); if ( len >= 4 && !Q_stricmp( buffer - 4, ".vmf" ) ) { buffer[ len - 4 ] = 0; } Q_FixSlashes( buffer ); for ( int i = 0; i < m_RoomTemplates.Count(); i++ ) { CRoomTemplate *pTemplate = m_RoomTemplates[i]; if ( !pTemplate ) continue; if ( !Q_stricmp( pTemplate->GetFullName(), buffer ) ) return pTemplate; } return NULL; }
const char *IFaceposerModels::CFacePoserModel::GetBitmapFilename( int sequence ) { char *in, *out; static char filename[ 256 ]; filename[ 0 ] = 0; char modelName[512], modelNameTemp[512]; Q_strncpy( modelNameTemp, GetShortModelName(), sizeof( modelNameTemp ) ); in = modelNameTemp; out = modelName; while ( *in ) { if ( isalnum( *in ) || *in == '_' || *in == '\\' || *in == '/' || *in == '.' || *in == ':' ) { *out++ = *in; } in++; } *out = 0; Q_snprintf( filename, sizeof( filename ), "expressions/%s/animation/%s.bmp", modelName, GetBitmapChecksum( sequence ) ); Q_FixSlashes( filename ); strlwr( filename ); CreatePath( filename ); return filename; }
//----------------------------------------------------------------------------- // Exports a Maya file to a DMX file //----------------------------------------------------------------------------- bool CMayaDmeMakefileUtils::PerformCompilationStep( CDmeMayaMakefile *pMakeFile, CompilationStep_t step ) { if ( step != BEFORE_COMPILATION ) return BaseClass::PerformCompilationStep( pMakeFile, step ); MString currentFile = MFileIO::currentFile(); int nCount = pMakeFile->GetSourceCount(); for ( int i = 0; i < nCount; ++i ) { CDmeSourceMayaFile *pMayaSource = CastElement< CDmeSourceMayaFile >( pMakeFile->GetSource(i) ); if ( !pMayaSource ) continue; char pSourcePath[MAX_PATH]; pMakeFile->GetSourceFullPath( pMayaSource, pSourcePath, sizeof(pSourcePath) ); // Maya wants forward slashes Q_FixSlashes( pSourcePath, '/' ); if ( Q_stricmp( currentFile.asChar(), pSourcePath ) ) continue; // It's already open MString command = "saveChanges(\"\")"; g_pMayaVGui->SetModalMode( true ); int nResult; MStatus status = MGlobal::executeCommand( command, nResult ); g_pMayaVGui->SetModalMode( false ); if ( status != MStatus::kSuccess || ( nResult == 0 ) ) return false; break; } return BaseClass::PerformCompilationStep( pMakeFile, step ); }
FSReturnCode_t FileSystem_LoadSearchPaths( CFSSearchPathsInit &initInfo ) { if ( !initInfo.m_pFileSystem || !initInfo.m_pDirectoryName ) return SetupFileSystemError( false, FS_INVALID_PARAMETERS, "FileSystem_LoadSearchPaths: Invalid parameters specified." ); KeyValues *pMainFile, *pFileSystemInfo, *pSearchPaths; FSReturnCode_t retVal = LoadGameInfoFile( initInfo.m_pDirectoryName, pMainFile, pFileSystemInfo, pSearchPaths ); if ( retVal != FS_OK ) return retVal; // All paths except those marked with |gameinfo_path| are relative to the base dir. char baseDir[MAX_PATH]; if ( !FileSystem_GetBaseDir( baseDir, sizeof( baseDir ) ) ) return SetupFileSystemError( false, FS_INVALID_PARAMETERS, "FileSystem_GetBaseDir failed." ); initInfo.m_ModPath[0] = 0; #define GAMEINFOPATH_TOKEN "|gameinfo_path|" #define BASESOURCEPATHS_TOKEN "|all_source_engine_paths|" bool bLowViolence = IsLowViolenceBuild(); bool bFirstGamePath = true; for ( KeyValues *pCur=pSearchPaths->GetFirstValue(); pCur; pCur=pCur->GetNextValue() ) { const char *pPathID = pCur->GetName(); const char *pLocation = pCur->GetString(); if ( Q_stristr( pLocation, GAMEINFOPATH_TOKEN ) == pLocation ) { pLocation += strlen( GAMEINFOPATH_TOKEN ); FileSystem_AddLoadedSearchPath( initInfo, pPathID, &bFirstGamePath, initInfo.m_pDirectoryName, pLocation, bLowViolence ); } else if ( Q_stristr( pLocation, BASESOURCEPATHS_TOKEN ) == pLocation ) { // This is a special identifier that tells it to add the specified path for all source engine versions equal to or prior to this version. // So in Orange Box, if they specified: // |all_source_engine_paths|hl2 // it would add the ep2\hl2 folder and the base (ep1-era) hl2 folder. // // We need a special identifier in the gameinfo.txt here because the base hl2 folder exists in different places. // In the case of a game or a Steam-launched dedicated server, all the necessary prior engine content is mapped in with the Steam depots, // so we can just use the path as-is. // In the case of an hldsupdatetool dedicated server, the base hl2 folder is "..\..\hl2" (since we're up in the 'orangebox' folder). pLocation += strlen( BASESOURCEPATHS_TOKEN ); // Add the Orange-box path (which also will include whatever the depots mapped in as well if we're // running a Steam-launched app). FileSystem_AddLoadedSearchPath( initInfo, pPathID, &bFirstGamePath, baseDir, pLocation, bLowViolence ); if ( FileSystem_IsHldsUpdateToolDedicatedServer() ) { // If we're using the hldsupdatetool dedicated server, then go up a directory to get the ep1-era files too. char ep1EraPath[MAX_PATH]; V_snprintf( ep1EraPath, sizeof( ep1EraPath ), "..%c%s", CORRECT_PATH_SEPARATOR, pLocation ); FileSystem_AddLoadedSearchPath( initInfo, pPathID, &bFirstGamePath, baseDir, ep1EraPath, bLowViolence ); } } else { FileSystem_AddLoadedSearchPath( initInfo, pPathID, &bFirstGamePath, baseDir, pLocation, bLowViolence ); } } pMainFile->deleteThis(); // // Set up search paths for add-ons // if ( IsPC() ) { #ifdef ENGINE_DLL FileSystem_UpdateAddonSearchPaths( initInfo.m_pFileSystem ); #endif } // these specialized tool paths are not used on 360 and cause a costly constant perf tax, so inhibited if ( IsPC() ) { // Create a content search path based on the game search path const char *pGameRoot = getenv( GAMEROOT_TOKEN ); const char *pContentRoot = getenv( CONTENTROOT_TOKEN ); if ( pGameRoot && pContentRoot ) { int nLen = initInfo.m_pFileSystem->GetSearchPath( "GAME", false, NULL, 0 ); char *pSearchPath = (char*)stackalloc( nLen * sizeof(char) ); initInfo.m_pFileSystem->GetSearchPath( "GAME", false, pSearchPath, nLen ); char *pPath = pSearchPath; while( pPath ) { char *pSemiColon = strchr( pPath, ';' ); if ( pSemiColon ) { *pSemiColon = 0; } Q_StripTrailingSlash( pPath ); Q_FixSlashes( pPath ); const char *pCurPath = pPath; pPath = pSemiColon ? pSemiColon + 1 : NULL; char pRelativePath[MAX_PATH]; char pContentPath[MAX_PATH]; if ( !Q_MakeRelativePath( pCurPath, pGameRoot, pRelativePath, sizeof(pRelativePath) ) ) continue; Q_ComposeFileName( pContentRoot, pRelativePath, pContentPath, sizeof(pContentPath) ); initInfo.m_pFileSystem->AddSearchPath( pContentPath, "CONTENT" ); } // Add the "platform" directory as a game searchable path char pPlatformPath[MAX_PATH]; Q_ComposeFileName( pGameRoot, "platform", pPlatformPath, sizeof(pPlatformPath) ); initInfo.m_pFileSystem->AddSearchPath( pPlatformPath, "GAME", PATH_ADD_TO_TAIL ); initInfo.m_pFileSystem->AddSearchPath( pContentRoot, "CONTENTROOT" ); initInfo.m_pFileSystem->AddSearchPath( pGameRoot, "GAMEROOT" ); } else { // Come up with some reasonable default int nLen = initInfo.m_pFileSystem->GetSearchPath( "MOD", false, NULL, 0 ); char *pSearchPath = (char*)stackalloc( nLen * sizeof(char) ); initInfo.m_pFileSystem->GetSearchPath( "MOD", false, pSearchPath, nLen ); char *pSemiColon = strchr( pSearchPath, ';' ); if ( pSemiColon ) { *pSemiColon = 0; } char pGameRootPath[MAX_PATH]; Q_strncpy( pGameRootPath, pSearchPath, sizeof(pGameRootPath) ); Q_StripTrailingSlash( pGameRootPath ); Q_StripFilename( pGameRootPath ); char pContentRootPath[MAX_PATH]; Q_strncpy( pContentRootPath, pGameRootPath, sizeof(pContentRootPath) ); char *pGame = Q_stristr( pContentRootPath, "game" ); if ( pGame ) { Q_strcpy( pGame, "content" ); } initInfo.m_pFileSystem->AddSearchPath( pContentRootPath, "CONTENTROOT" ); initInfo.m_pFileSystem->AddSearchPath( pGameRootPath, "GAMEROOT" ); } // Also, mark specific path IDs as "by request only". That way, we won't waste time searching in them // when people forget to specify a search path. initInfo.m_pFileSystem->MarkPathIDByRequestOnly( "contentroot", true ); initInfo.m_pFileSystem->MarkPathIDByRequestOnly( "gameroot", true ); initInfo.m_pFileSystem->MarkPathIDByRequestOnly( "content", true ); } // Also, mark specific path IDs as "by request only". That way, we won't waste time searching in them // when people forget to specify a search path. initInfo.m_pFileSystem->MarkPathIDByRequestOnly( "executable_path", true ); initInfo.m_pFileSystem->MarkPathIDByRequestOnly( "gamebin", true ); initInfo.m_pFileSystem->MarkPathIDByRequestOnly( "mod", true ); // Add the write path last. if ( initInfo.m_ModPath[0] != 0 ) { initInfo.m_pFileSystem->AddSearchPath( initInfo.m_ModPath, "DEFAULT_WRITE_PATH", PATH_ADD_TO_TAIL ); } #ifdef _DEBUG initInfo.m_pFileSystem->PrintSearchPaths(); #endif #if defined( ENABLE_RUNTIME_STACK_TRANSLATION ) && !defined( _X360 ) //copy search paths to stack tools so it can grab pdb's from all over. But only on P4 or Steam Beta builds if( (CommandLine()->FindParm( "-steam" ) == 0) || //not steam (CommandLine()->FindParm( "-internalbuild" ) != 0) ) //steam beta is ok { char szSearchPaths[4096]; //int CBaseFileSystem::GetSearchPath( const char *pathID, bool bGetPackFiles, char *pPath, int nMaxLen ) int iLength1 = initInfo.m_pFileSystem->GetSearchPath( "EXECUTABLE_PATH", false, szSearchPaths, 4096 ); if( iLength1 == 1 ) iLength1 = 0; int iLength2 = initInfo.m_pFileSystem->GetSearchPath( "GAMEBIN", false, szSearchPaths + iLength1, 4096 - iLength1 ); if( (iLength2 > 1) && (iLength1 > 1) ) { szSearchPaths[iLength1 - 1] = ';'; //replace first null terminator } const char *szAdditionalPath = CommandLine()->ParmValue( "-AdditionalPDBSearchPath" ); if( szAdditionalPath && szAdditionalPath[0] ) { int iLength = iLength1; if( iLength2 > 1 ) iLength += iLength2; if( iLength != 0 ) { szSearchPaths[iLength - 1] = ';'; //replaces null terminator } V_strncpy( &szSearchPaths[iLength], szAdditionalPath, 4096 - iLength ); } //Append the perforce symbol server last. Documentation says that "srv*\\perforce\symbols" should work, but it doesn't. //"symsrv*symsrv.dll*\\perforce\symbols" which the docs say is the same statement, works. { V_strncat( szSearchPaths, ";symsrv*symsrv.dll*\\\\perforce\\symbols", 4096 ); } SetStackTranslationSymbolSearchPath( szSearchPaths ); //MessageBox( NULL, szSearchPaths, "Search Paths", 0 ); } #endif return FS_OK; }
//========================================================= //========================================================= 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); } } } }
void CASW_Location::LoadFromKeyValues( KeyValues *pKeys, CUniformRandomStream* pStream) { m_iXPos = pKeys->GetInt( "x" ); m_iYPos = pKeys->GetInt( "y" ); Q_strcpy( m_szMapName, "random" ); m_iMinDifficulty = pKeys->GetInt( "MinDifficulty", 1 ); m_iMaxDifficulty = pKeys->GetInt( "MaxDifficulty", 100 ); m_iCompanyIndex = pKeys->GetInt( "Company", 0 ); m_bIsMissionOptional = !!pKeys->GetInt( "Optional", 1 ); m_iLocationID = pKeys->GetInt( "ID", -1 ); m_pszCustomMission = TileGenCopyString( pKeys->GetString( "CustomMission" ) ); m_szStoryScene = TileGenCopyString( pKeys->GetString( "StoryScene" ) ) ? TileGenCopyString( pKeys->GetString( "StoryScene" ) ) : "spaceport_crashsite"; m_szImageName = TileGenCopyString( pKeys->GetString( "ImageName" ) ) ? TileGenCopyString( pKeys->GetString( "ImageName" ) ) : "swarm/MissionPics/PlantMissionpic.vmt"; if ( m_pszCustomMission ) { Q_FixSlashes( m_pszCustomMission ); } // pick a difficulty between the bounds m_iDifficulty = pStream->RandomInt( m_iMinDifficulty, m_iMaxDifficulty ); if ( m_pszCustomMission && m_pszCustomMission[0] ) { m_pMissionKV = m_pLocationGrid->GetMissionData( m_pszCustomMission ); } if ( m_pMissionKV ) { // Make a copy so we can modify it m_pMissionKV = m_pMissionKV->MakeCopy(); // Fill out mission settings from the mission grid data so it gets into the .layout file if ( GetMissionSettings() ) { GetMissionSettings()->SetInt( "Difficulty", m_iDifficulty ); const char *pMissionName = m_pszCustomMission; if ( Q_strnicmp( m_pszCustomMission, "tilegen/new_missions/", Q_strlen( "tilegen/new_missions/" ) ) == 0 ) { pMissionName += Q_strlen( "tilegen/new_missions/" ); } GetMissionSettings()->SetString( "Filename", m_pszCustomMission + Q_strlen( "tilegen/new_missions/" ) ); GetMissionSettings()->SetInt( "GridLocationID", m_iLocationID ); } } // if mission doesn't have a valid ID then find one if ( m_iLocationID == -1 ) { m_iLocationID = LocationGrid()->GetFreeLocationID(); } KeyValues *pRewards = pKeys->FindKey( "Rewards" ); if ( pRewards ) { for ( KeyValues *pRewardKey = pRewards->GetFirstSubKey(); pRewardKey; pRewardKey = pRewardKey->GetNextKey() ) { CASW_Reward *pReward = new CASW_Reward(); if ( pReward->LoadFromKeyValues( pRewardKey, m_iDifficulty ) ) { m_Rewards.AddToTail( pReward ); } else { delete pReward; } } } else { // TODO: Create some default rewards? } }
//----------------------------------------------------------------------------- // Purpose: extracts the list of defines and includes used for this config //----------------------------------------------------------------------------- bool CVCProjConvert::ExtractIncludes( IXMLDOMElement *pDoc, CConfiguration & config ) { config.ResetDefines(); config.ResetIncludes(); if (!pDoc) { return false; } #ifdef _WIN32 CComPtr<IXMLDOMNodeList> pTools; pDoc->getElementsByTagName( _bstr_t("Tool"), &pTools); if (pTools) { long len = 0; pTools->get_length(&len); for ( int i=0; i<len; i++ ) { CComPtr<IXMLDOMNode> pNode; pTools->get_item( i, &pNode ); if (pNode) { CComQIPtr<IXMLDOMElement> pElem( pNode ); CUtlSymbol toolName = GetXMLAttribValue( pElem, "Name" ); if ( toolName == "VCCLCompilerTool" ) { CUtlSymbol defines = GetXMLAttribValue( pElem, "PreprocessorDefinitions" ); char *str = (char *)_alloca( Q_strlen( defines.String() ) + 1 ); Assert( str ); Q_strcpy( str, defines.String() ); // now tokenize the string on the ";" char char *delim = strchr( str, ';' ); char *curpos = str; while ( delim ) { *delim = 0; delim++; if ( Q_stricmp( curpos, "WIN32" ) && Q_stricmp( curpos, "_WIN32" ) && Q_stricmp( curpos, "_WINDOWS") && Q_stricmp( curpos, "WINDOWS")) // don't add WIN32 defines { config.AddDefine( curpos ); } curpos = delim; delim = strchr( delim, ';' ); } if ( Q_stricmp( curpos, "WIN32" ) && Q_stricmp( curpos, "_WIN32" ) && Q_stricmp( curpos, "_WINDOWS") && Q_stricmp( curpos, "WINDOWS")) // don't add WIN32 defines { config.AddDefine( curpos ); } CUtlSymbol includes = GetXMLAttribValue( pElem, "AdditionalIncludeDirectories" ); char *str2 = (char *)_alloca( Q_strlen( includes.String() ) + 1 ); Assert( str2 ); Q_strcpy( str2, includes.String() ); // now tokenize the string on the ";" char delim = strchr( str2, ',' ); curpos = str2; while ( delim ) { *delim = 0; delim++; config.AddInclude( curpos ); curpos = delim; delim = strchr( delim, ',' ); } config.AddInclude( curpos ); } } } } #elif _LINUX DOMNodeList *nodes= pDoc->getElementsByTagName( _bstr_t("Tool")); if (nodes) { int len = nodes->getLength(); for ( int i=0; i<len; i++ ) { DOMNode *node = nodes->item(i); if (node) { CUtlSymbol toolName = GetXMLAttribValue( node, "Name" ); if ( toolName == "VCCLCompilerTool" ) { CUtlSymbol defines = GetXMLAttribValue( node, "PreprocessorDefinitions" ); char *str = (char *)_alloca( Q_strlen( defines.String() ) + 1 ); Assert( str ); Q_strcpy( str, defines.String() ); // now tokenize the string on the ";" char char *delim = strchr( str, ';' ); char *curpos = str; while ( delim ) { *delim = 0; delim++; if ( Q_stricmp( curpos, "WIN32" ) && Q_stricmp( curpos, "_WIN32" ) && Q_stricmp( curpos, "_WINDOWS") && Q_stricmp( curpos, "WINDOWS")) // don't add WIN32 defines { config.AddDefine( curpos ); } curpos = delim; delim = strchr( delim, ';' ); } if ( Q_stricmp( curpos, "WIN32" ) && Q_stricmp( curpos, "_WIN32" ) && Q_stricmp( curpos, "_WINDOWS") && Q_stricmp( curpos, "WINDOWS")) // don't add WIN32 defines { config.AddDefine( curpos ); } CUtlSymbol includes = GetXMLAttribValue( node, "AdditionalIncludeDirectories" ); char *str2 = (char *)_alloca( Q_strlen( includes.String() ) + 1 ); Assert( str2 ); Q_strcpy( str2, includes.String() ); // now tokenize the string on the ";" char char token = ','; delim = strchr( str2, token ); if ( !delim ) { token = ';'; delim = strchr( str2, token ); } curpos = str2; while ( delim ) { *delim = 0; delim++; Q_FixSlashes( curpos ); Q_strlower( curpos ); char fullPath[ MAX_PATH ]; Q_snprintf( fullPath, sizeof(fullPath), "%s/%s", m_BaseDir.String(), curpos ); Q_StripTrailingSlash( fullPath ); config.AddInclude( fullPath ); curpos = delim; delim = strchr( delim, token ); } Q_FixSlashes( curpos ); Q_strlower( curpos ); char fullPath[ MAX_PATH ]; Q_snprintf( fullPath, sizeof(fullPath), "%s/%s", m_BaseDir.String(), curpos ); Q_StripTrailingSlash( fullPath ); config.AddInclude( fullPath ); } } } } #endif return true; }
//----------------------------------------------------------------------------- // Purpose: Get list of files from current path that match pattern //----------------------------------------------------------------------------- int CScriptLib::GetFileList( const char* pDirPath, const char* pPattern, CUtlVector< fileList_t > &fileList ) { char sourcePath[MAX_PATH]; char fullPath[MAX_PATH]; bool bFindDirs; fileList.Purge(); strcpy( sourcePath, pDirPath ); int len = (int)strlen( sourcePath ); if ( !len ) { strcpy( sourcePath, ".\\" ); } else if ( sourcePath[len-1] != '\\' ) { sourcePath[len] = '\\'; sourcePath[len+1] = '\0'; } strcpy( fullPath, sourcePath ); if ( pPattern[0] == '\\' && pPattern[1] == '\0' ) { // find directories only bFindDirs = true; strcat( fullPath, "*" ); } else { // find files, use provided pattern bFindDirs = false; strcat( fullPath, pPattern ); } #ifdef WIN32 struct _finddata_t findData; intptr_t h = _findfirst( fullPath, &findData ); if ( h == -1 ) { return 0; } do { // dos attribute complexities i.e. _A_NORMAL is 0 if ( bFindDirs ) { // skip non dirs if ( !( findData.attrib & _A_SUBDIR ) ) continue; } else { // skip dirs if ( findData.attrib & _A_SUBDIR ) continue; } if ( !stricmp( findData.name, "." ) ) continue; if ( !stricmp( findData.name, ".." ) ) continue; char fileName[MAX_PATH]; strcpy( fileName, sourcePath ); strcat( fileName, findData.name ); int j = fileList.AddToTail(); fileList[j].fileName.Set( fileName ); fileList[j].timeWrite = findData.time_write; } while ( !_findnext( h, &findData ) ); _findclose( h ); #elif defined(POSIX) FIND_DATA findData; Q_FixSlashes( fullPath ); void *h = FindFirstFile( fullPath, &findData ); if ( (int)h == -1 ) { return 0; } do { // dos attribute complexities i.e. _A_NORMAL is 0 if ( bFindDirs ) { // skip non dirs if ( !( findData.dwFileAttributes & S_IFDIR ) ) continue; } else { // skip dirs if ( findData.dwFileAttributes & S_IFDIR ) continue; } if ( !stricmp( findData.cFileName, "." ) ) continue; if ( !stricmp( findData.cFileName, ".." ) ) continue; char fileName[MAX_PATH]; strcpy( fileName, sourcePath ); strcat( fileName, findData.cFileName ); int j = fileList.AddToTail(); fileList[j].fileName.Set( fileName ); struct stat statbuf; if ( stat( fileName, &statbuf ) ) #ifdef OSX fileList[j].timeWrite = statbuf.st_mtimespec.tv_sec; #else fileList[j].timeWrite = statbuf.st_mtime; #endif else fileList[j].timeWrite = 0; }
//----------------------------------------------------------------------------- // Purpose: walks the file elements in the vcproj and inserts them into configs //----------------------------------------------------------------------------- bool CVCProjConvert::ExtractFiles( IXMLDOMDocument *pDoc ) { if (!pDoc) { return false; } Assert( m_Configurations.Count() ); // some configs must be loaded first #ifdef _WIN32 CComPtr<IXMLDOMNodeList> pFiles; pDoc->getElementsByTagName( _bstr_t("File"), &pFiles); if (pFiles) { long len = 0; pFiles->get_length(&len); for ( int i=0; i<len; i++ ) { CComPtr<IXMLDOMNode> pNode; pFiles->get_item( i, &pNode); if (pNode) { CComQIPtr<IXMLDOMElement> pElem( pNode ); CUtlSymbol fileName = GetXMLAttribValue(pElem,"RelativePath"); if ( fileName.IsValid() ) { CConfiguration::FileType_e type = GetFileType( fileName.String() ); CConfiguration::CFileEntry fileEntry( fileName.String(), type ); for ( int i = 0; i < m_Configurations.Count(); i++ ) // add the file to all configs { CConfiguration & config = m_Configurations[i]; config.InsertFile( fileEntry ); } IterateFileConfigurations( pElem, fileName ); // now remove the excluded ones } } }//for } #elif _LINUX DOMNodeList *nodes = pDoc->getElementsByTagName( _bstr_t("File") ); if (nodes) { int len = nodes->getLength(); for ( int i=0; i<len; i++ ) { DOMNode *node = nodes->item(i); if (node) { CUtlSymbol fileName = GetXMLAttribValue(node,"RelativePath"); if ( fileName.IsValid() ) { char fixedFileName[ MAX_PATH ]; Q_strncpy( fixedFileName, fileName.String(), sizeof(fixedFileName) ); if ( fixedFileName[0] == '.' && fixedFileName[1] == '\\' ) { Q_memmove( fixedFileName, fixedFileName+2, sizeof(fixedFileName)-2 ); } Q_FixSlashes( fixedFileName ); FindFileCaseInsensitive( fixedFileName, sizeof(fixedFileName) ); CConfiguration::FileType_e type = GetFileType( fileName.String() ); CConfiguration::CFileEntry fileEntry( fixedFileName, type ); for ( int i = 0; i < m_Configurations.Count(); i++ ) // add the file to all configs { CConfiguration & config = m_Configurations[i]; config.InsertFile( fileEntry ); } IterateFileConfigurations( node, fixedFileName ); // now remove the excluded ones } } }//for } #endif return true; }
void CModelBrowser::GetModelName( char *pModelName, int length ) { m_pPicker->GetSelectedMDLName( pModelName, length ); Q_FixSlashes( pModelName, '/' ); }
int SEditModelRender::MaterialPicker( char ***szMat ) { int mx, my; #ifdef SOURCE_2006 vgui::input()->GetCursorPos( mx, my ); #else vgui::input()->GetCursorPosition( mx, my ); #endif Vector ray; const CViewSetup *pViewSetup = view->GetPlayerViewSetup(); float ratio =engine->GetScreenAspectRatio( #ifdef SWARM_DLL pViewSetup->width, pViewSetup->height #endif ); ratio = ( 1.0f / ratio ) * (4.0f/3.0f); float flFov = ScaleFOVByWidthRatio( pViewSetup->fov, ratio ); ScreenToWorld( mx, my, flFov, pViewSetup->origin, pViewSetup->angles, ray ); Vector start = pViewSetup->origin; Vector end = start + ray * MAX_TRACE_LENGTH; trace_t tr; C_BaseEntity *pIgnore = input->CAM_IsThirdPerson() ? NULL : C_BasePlayer::GetLocalPlayer(); UTIL_TraceLine( start, end, MASK_SOLID, pIgnore, COLLISION_GROUP_NONE, &tr ); if ( !tr.DidHit() ) return 0; int numMaterials = 0; IMaterial **MatList = NULL; studiohdr_t *pSHdr = NULL; if ( tr.DidHitWorld() ) { if ( tr.hitbox == 0 ) { Vector dummy; IMaterial *pMat = engine->TraceLineMaterialAndLighting( start, end, dummy, dummy ); if ( pMat ) { numMaterials = 1; MatList = new IMaterial*[1]; MatList[0] = pMat; } } else { ICollideable *prop = staticpropmgr->GetStaticPropByIndex( tr.hitbox - 1 ); if ( prop ) { IClientRenderable *pRenderProp = prop->GetIClientUnknown()->GetClientRenderable(); if ( pRenderProp ) { const model_t *pModel = pRenderProp->GetModel(); if ( pModel ) pSHdr = modelinfo->GetStudiomodel( pModel ); } } } } else if ( tr.m_pEnt ) { const model_t *pModel = tr.m_pEnt->GetModel(); if ( pModel ) pSHdr = modelinfo->GetStudiomodel( pModel ); } if ( pSHdr ) { Assert( !numMaterials && !MatList ); numMaterials = pSHdr->numtextures; const int numPaths = pSHdr->numcdtextures; if ( numMaterials ) { CUtlVector< IMaterial* >hValidMaterials; for ( int i = 0; i < numMaterials; i++ ) { mstudiotexture_t *pStudioTex = pSHdr->pTexture( i ); const char *matName = pStudioTex->pszName(); for ( int p = 0; p < numPaths; p++ ) { char tmpPath[MAX_PATH]; Q_snprintf( tmpPath, MAX_PATH, "%s%s\0", pSHdr->pCdtexture( p ), matName ); Q_FixSlashes( tmpPath ); IMaterial *pTempMat = materials->FindMaterial( tmpPath, TEXTURE_GROUP_MODEL ); if ( !IsErrorMaterial( pTempMat ) ) { hValidMaterials.AddToTail( pTempMat ); break; } } } numMaterials = hValidMaterials.Count(); if ( numMaterials ) { MatList = new IMaterial*[ numMaterials ]; for ( int i = 0; i < numMaterials; i++ ) MatList[i] = hValidMaterials[i]; } hValidMaterials.Purge(); } } *szMat = new char*[ numMaterials ]; int iTotalLength = 0; for ( int i = 0; i < numMaterials; i++ ) iTotalLength += Q_strlen( MatList[i]->GetName() ) + 1; **szMat = new char[ iTotalLength ]; int curpos = 0; for ( int i = 0; i < numMaterials; i++ ) { const char *pszName = MatList[i]->GetName(); int curLength = Q_strlen( pszName ) + 1; (*szMat)[ i ] = **szMat + curpos; Q_strcpy( (*szMat)[ i ], pszName ); curpos += curLength; } if ( MatList ) delete [] MatList; return numMaterials; }
bool CEngineSprite::Init( const char *pName ) { m_VideoMaterial = NULL; for ( int i = 0; i < kRenderModeCount; ++i ) { m_material[ i ] = NULL; } m_width = m_height = m_numFrames = 1; Assert( g_pVideo != NULL ); if ( g_pVideo != NULL && g_pVideo->LocateVideoSystemForPlayingFile( pName ) != VideoSystem::NONE ) { m_VideoMaterial = g_pVideo->CreateVideoMaterial( pName, pName, "GAME", VideoPlaybackFlags::DEFAULT_MATERIAL_OPTIONS, VideoSystem::DETERMINE_FROM_FILE_EXTENSION, false ); if ( m_VideoMaterial == NULL ) return false; IMaterial *pMaterial = m_VideoMaterial->GetMaterial(); m_VideoMaterial->GetVideoImageSize( &m_width, &m_height ); m_numFrames = m_VideoMaterial->GetFrameCount(); for ( int i = 0; i < kRenderModeCount; ++i ) { m_material[i] = pMaterial; pMaterial->IncrementReferenceCount(); } } else { char pTemp[MAX_PATH]; char pMaterialName[MAX_PATH]; char pMaterialPath[MAX_PATH]; Q_StripExtension( pName, pTemp, sizeof(pTemp) ); Q_strlower( pTemp ); Q_FixSlashes( pTemp, '/' ); // Check to see if this is a UNC-specified material name bool bIsUNC = pTemp[0] == '/' && pTemp[1] == '/' && pTemp[2] != '/'; if ( !bIsUNC ) { Q_strncpy( pMaterialName, "materials/", sizeof(pMaterialName) ); Q_strncat( pMaterialName, pTemp, sizeof(pMaterialName), COPY_ALL_CHARACTERS ); } else { Q_strncpy( pMaterialName, pTemp, sizeof(pMaterialName) ); } Q_strncpy( pMaterialPath, pMaterialName, sizeof(pMaterialPath) ); Q_SetExtension( pMaterialPath, ".vmt", sizeof(pMaterialPath) ); KeyValues *kv = new KeyValues( "vmt" ); if ( !kv->LoadFromFile( g_pFullFileSystem, pMaterialPath, "GAME" ) ) { Warning( "Unable to load sprite material %s!\n", pMaterialPath ); return false; } for ( int i = 0; i < kRenderModeCount; ++i ) { if ( i == kRenderNone || i == kRenderEnvironmental ) { m_material[i] = NULL; continue; } Q_snprintf( pMaterialPath, sizeof(pMaterialPath), "%s_rendermode_%d", pMaterialName, i ); KeyValues *pMaterialKV = kv->MakeCopy(); pMaterialKV->SetInt( "$spriteRenderMode", i ); m_material[i] = g_pMaterialSystem->FindProceduralMaterial( pMaterialPath, TEXTURE_GROUP_CLIENT_EFFECTS, pMaterialKV ); m_material[ i ]->IncrementReferenceCount(); } kv->deleteThis(); m_width = m_material[0]->GetMappingWidth(); m_height = m_material[0]->GetMappingHeight(); m_numFrames = m_material[0]->GetNumAnimationFrames(); } for ( int i = 0; i < kRenderModeCount; ++i ) { if ( i == kRenderNone || i == kRenderEnvironmental ) continue; if ( !m_material[i] ) return false; } IMaterialVar *orientationVar = m_material[0]->FindVarFast( "$spriteorientation", &spriteOrientationCache ); m_orientation = orientationVar ? orientationVar->GetIntValue() : C_SpriteRenderer::SPR_VP_PARALLEL_UPRIGHT; IMaterialVar *originVar = m_material[0]->FindVarFast( "$spriteorigin", &spriteOriginCache ); Vector origin, originVarValue; if( !originVar || ( originVar->GetType() != MATERIAL_VAR_TYPE_VECTOR ) ) { origin[0] = -m_width * 0.5f; origin[1] = m_height * 0.5f; } else { originVar->GetVecValue( &originVarValue[0], 3 ); origin[0] = -m_width * originVarValue[0]; origin[1] = m_height * originVarValue[1]; } up = origin[1]; down = origin[1] - m_height; left = origin[0]; right = m_width + origin[0]; return true; }
void BuildFileList_R( int depth, CUtlVector< FileEntry >& files, CUtlVector< FileEntry > * otherfiles, char const *dir, char const *wild, int skipchars ) { WIN32_FIND_DATA wfd; char directory[ 256 ]; char filename[ 256 ]; HANDLE ff; bool canrecurse = true; if ( !Q_stricmp( wild, "..." ) ) { canrecurse = true; sprintf( directory, "%s%s%s", dir[0] == '\\' ? dir + 1 : dir, dir[0] != 0 ? "\\" : "", "*.*" ); } else { sprintf( directory, "%s%s%s", dir, dir[0] != 0 ? "\\" : "", wild ); } int dirlen = Q_strlen( dir ); if ( ( ff = FindFirstFile( directory, &wfd ) ) == INVALID_HANDLE_VALUE ) return; do { if ( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { bool useOtherFiles = false; if ( wfd.cFileName[ 0 ] == '.' ) continue; if ( depth == 0 && !ShouldCheckDir( wfd.cFileName ) && otherfiles ) { if ( !ShouldIgnoreDir( wfd.cFileName ) ) { useOtherFiles = true; } } if ( !canrecurse ) continue; // Recurse down directory if ( dir[0] ) { sprintf( filename, "%s\\%s", dir, wfd.cFileName ); } else { sprintf( filename, "%s", wfd.cFileName ); } BuildFileList_R( depth + 1, useOtherFiles ? *otherfiles: files, NULL, filename, wild, skipchars ); } else { if (!stricmp(wfd.cFileName, "vssver.scc")) continue; char filename[ MAX_PATH ]; if ( dirlen <= skipchars ) { Q_snprintf( filename, sizeof( filename ), "%s", wfd.cFileName ); } else { Q_snprintf( filename, sizeof( filename ), "%s\\%s", &dir[ skipchars ], wfd.cFileName ); } _strlwr( filename ); Q_FixSlashes( filename ); UnusedContent::CUtlSymbol sym = g_Analysis.symbols.AddString( filename ); FileEntry entry; entry.sym = sym; int size = g_pFileSystem->Size( filename ); entry.size = size >= 0 ? (unsigned int)size : 0; files.AddToTail( entry ); if ( !( files.Count() % 3000 ) ) { vprint( 0, "...found %i files\n", files.Count() ); } } } while ( FindNextFile( ff, &wfd ) ); }
//----------------------------------------------------------------------------- // Purpose: // Input : argc - // argv[] - // Output : int //----------------------------------------------------------------------------- int main( int argc, char* argv[] ) { SpewOutputFunc( SpewFunc ); SpewActivate( "unusedcontent", 2 ); CommandLine()->CreateCmdLine( argc, argv ); int i=1; for ( i ; i<argc ; i++) { if ( argv[ i ][ 0 ] == '-' ) { switch( argv[ i ][ 1 ] ) { case 'l': uselogfile = true; break; case 'v': verbose = true; break; case 'r': showreferencedfiles = true; break; case 'd': spewdeletions = true; break; case 'i': immediatedelete = true; break; case 'w': printwhitelist = true; break; case 'm': showmapfileusage = true; break; case 'g': // Just skip -game Assert( !Q_stricmp( argv[ i ], "-game" ) ); ++i; break; case 'f': // grab reslists folder { ++i; Q_strncpy( g_szReslistDir, argv[ i ], sizeof( g_szReslistDir ) ); Q_strlower( g_szReslistDir ); Q_FixSlashes( g_szReslistDir ); Q_AppendSlash( g_szReslistDir, sizeof( g_szReslistDir ) ); } break; default: printusage(); break; } } } if ( argc < 3 || ( i != argc ) ) { PrintHeader(); printusage(); return 0; } CheckLogFile(); PrintHeader(); vprint( 0, " Using reslist dir '%s'\n", g_szReslistDir ); vprint( 0, " Looking for extraneous content...\n" ); char resfile[ 256 ]; strcpy( resfile, argv[ i - 1 ] ); vprint( 0, " Comparing results of resfile (%s) with files under current directory...\n", resfile ); char workingdir[ 256 ]; workingdir[0] = 0; Q_getwd( workingdir, sizeof( workingdir ) ); // If they didn't specify -game on the command line, use VPROJECT. CmdLib_InitFileSystem( workingdir ); filesystem = (IFileSystem *)(CmdLib_GetFileSystemFactory()( FILESYSTEM_INTERFACE_VERSION, NULL )); if ( !filesystem ) { AssertMsg( 0, "Failed to create/get IFileSystem" ); return 1; } g_pFullFileSystem->RemoveAllSearchPaths(); g_pFullFileSystem->AddSearchPath(gamedir, "GAME"); Q_strlower( gamedir ); Q_FixSlashes( gamedir ); // //ProcessMaterialsDirectory( vmtdir ); // find out the mod dir name Q_strncpy( modname, gamedir, sizeof(modname) ); modname[ strlen(modname) - 1] = 0; if ( strrchr( modname, '\\' ) ) { Q_strncpy( modname, strrchr( modname, '\\' ) + 1, sizeof(modname) ); } else { Q_strncpy( modname, "", sizeof(modname) ); } vprint( 1, "Mod Name:%s\n", modname); BuildCheckdirList(); BuildWhiteList(); vprint( 0, "Building aggregate file list from resfile output\n" ); CUtlRBTree< ReferencedFile, int > referencedfiles( 0, 0, RefFileLessFunc ); CUtlVector< UnusedContent::CUtlSymbol > resfiles; BuildReferencedFileList( resfiles, referencedfiles, resfile ); vprint( 0, "found %i files\n\n", referencedfiles.Count() ); vprint( 0, "Building list of all game content files\n" ); CUtlVector< FileEntry > contentfiles; CUtlVector< FileEntry > otherfiles; BuildFileList( 0, contentfiles, &otherfiles, "", 0 ); vprint( 0, "found %i files in content tree\n\n", contentfiles.Count() ); Correlate( referencedfiles, contentfiles, modname ); // now output the files not referenced in the whitelist or general reslists filesystem->RemoveFile( CFmtStr( "%sunreferenced_files.lst", g_szReslistDir ), "GAME" ); int c = otherfiles.Count(); for ( i = 0; i < c; ++i ) { FileEntry & entry = otherfiles[ i ]; char const *name = g_Analysis.symbols.String( entry.sym ); logprint( CFmtStr( "%sunreferenced_files.lst", g_szReslistDir ), "\"%s\\%s\"\n", modname, name ); } // also include the files from deletions.bat, as we don't actually run that now c = contentfiles.Count(); for ( i = 0; i < c; ++i ) { FileEntry & entry = contentfiles[ i ]; if ( entry.referenced != REFERENCED_NO ) continue; char const *fn = g_Analysis.symbols.String( entry.sym ); logprint( CFmtStr( "%sunreferenced_files.lst", g_szReslistDir ), "\"%s\\%s\"\n", modname, fn ); } FileSystem_Term(); return 0; }
bool BuildReferencedFileList( CUtlVector< UnusedContent::CUtlSymbol >& resfiles, CUtlRBTree< ReferencedFile, int >& files, const char *resfile ) { // Load the reslist file FileHandle_t resfilehandle; resfilehandle = g_pFileSystem->Open( resfile, "rb" ); if ( FILESYSTEM_INVALID_HANDLE != resfilehandle ) { // Read in and parse mapcycle.txt int length = g_pFileSystem->Size(resfilehandle); if ( length > 0 ) { char *pStart = (char *)new char[ length + 1 ]; if ( pStart && ( length == g_pFileSystem->Read(pStart, length, resfilehandle) ) ) { pStart[ length ] = 0; char *pFileList = pStart; while ( 1 ) { char szResList[ 256 ]; pFileList = COM_Parse( pFileList ); if ( strlen( com_token ) <= 0 ) break; Q_snprintf(szResList, sizeof( szResList ), "%s%s.lst", g_szReslistDir, com_token ); _strlwr( szResList ); Q_FixSlashes( szResList ); if ( !g_pFileSystem->FileExists( szResList ) ) { vprint( 0, "Couldn't find %s\n", szResList ); continue; } UnusedContent::CUtlSymbol sym = g_Analysis.symbols.AddString( szResList ); resfiles.AddToTail( sym ); } } delete[] pStart; } g_pFileSystem->Close(resfilehandle); } else { Error( "Unable to open reslist file %s\n", resfile ); exit( -1 ); } if ( g_pFileSystem->FileExists( CFmtStr( "%sall.lst", g_szReslistDir ) ) ) { UnusedContent::CUtlSymbol sym = g_Analysis.symbols.AddString( CFmtStr( "%sall.lst", g_szReslistDir ) ); resfiles.AddToTail( sym ); } if ( g_pFileSystem->FileExists( CFmtStr( "%sengine.lst", g_szReslistDir ) ) ) { UnusedContent::CUtlSymbol sym = g_Analysis.symbols.AddString( CFmtStr( "%sengine.lst", g_szReslistDir ) ); resfiles.AddToTail( sym ); } // Do we have any resfiles? if ( resfiles.Count() <= 0 ) { vprint( 0, "%s didn't have any actual .lst files in the reslists folder, have you run the engine with %s\n", resfile, "-makereslists -usereslistfile maplist.txt" ); return false; } vprint( 0, "Parsed %i reslist files\n", resfiles.Count() ); // Now load in each res file int c = resfiles.Count(); for ( int i = 0; i < c; ++i ) { UnusedContent::CUtlSymbol& filename = resfiles[ i ]; char fn[ 256 ]; Q_strncpy( fn, g_Analysis.symbols.String( filename ), sizeof( fn ) ); ParseFilesFromResList( filename, files, fn ); } return true; }
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 ); }
//----------------------------------------------------------------------------- // Purpose: Searches for GameStartup*.mp3 files in the sound/ui folder and plays one //----------------------------------------------------------------------------- void CGameUI::PlayGameStartupSound() { #if defined( LEFT4DEAD ) // L4D not using this path, L4D UI now handling with background menu movies return; #endif if ( IsX360() ) return; if ( CommandLine()->FindParm( "-nostartupsound" ) ) return; FileFindHandle_t fh; CUtlVector<char *> fileNames; char path[ 512 ]; Q_snprintf( path, sizeof( path ), "sound/ui/gamestartup*.mp3" ); Q_FixSlashes( path ); char const *fn = g_pFullFileSystem->FindFirstEx( path, "MOD", &fh ); if ( fn ) { do { char ext[ 10 ]; Q_ExtractFileExtension( fn, ext, sizeof( ext ) ); if ( !Q_stricmp( ext, "mp3" ) ) { char temp[ 512 ]; Q_snprintf( temp, sizeof( temp ), "ui/%s", fn ); char *found = new char[ strlen( temp ) + 1 ]; Q_strncpy( found, temp, strlen( temp ) + 1 ); Q_FixSlashes( found ); fileNames.AddToTail( found ); } fn = g_pFullFileSystem->FindNext( fh ); } while ( fn ); g_pFullFileSystem->FindClose( fh ); } // did we find any? if ( fileNames.Count() > 0 ) { SYSTEMTIME SystemTime; GetSystemTime( &SystemTime ); int index = SystemTime.wMilliseconds % fileNames.Count(); if ( fileNames.IsValidIndex( index ) && fileNames[index] ) { char found[ 512 ]; // escape chars "*#" make it stream, and be affected by snd_musicvolume Q_snprintf( found, sizeof( found ), "play *#%s", fileNames[index] ); engine->ClientCmd_Unrestricted( found ); } fileNames.PurgeAndDeleteElements(); } }
void ParseFilesFromResList( UnusedContent::CUtlSymbol & resfilesymbol, CUtlRBTree< ReferencedFile, int >& files, char const *resfile ) { int addedStrings = 0; int resourcesConsidered = 0; int offset = Q_strlen( gamedir ); char basedir[MAX_PATH]; Q_strncpy( basedir, gamedir, sizeof( basedir ) ); if ( !Q_StripLastDir( basedir, sizeof( basedir ) ) ) Error( "Can't get basedir from %s.", gamedir ); FileHandle_t resfilehandle; resfilehandle = g_pFileSystem->Open( resfile, "rb" ); if ( FILESYSTEM_INVALID_HANDLE != resfilehandle ) { // Read in the entire file int length = g_pFileSystem->Size(resfilehandle); if ( length > 0 ) { char *pStart = (char *)new char[ length + 1 ]; if ( pStart && ( length == g_pFileSystem->Read(pStart, length, resfilehandle) ) ) { pStart[ length ] = 0; char *pFileList = pStart; char token[512]; while ( 1 ) { pFileList = ParseFile( pFileList, token, NULL ); if ( !pFileList ) break; if ( strlen( token ) > 0 ) { char szFileName[ 256 ]; Q_snprintf( szFileName, sizeof( szFileName ), "%s%s", basedir, token ); _strlwr( szFileName ); Q_FixSlashes( szFileName ); while ( szFileName[ strlen( szFileName ) - 1 ] == '\n' || szFileName[ strlen( szFileName ) - 1 ] == '\r' ) { szFileName[ strlen( szFileName ) - 1 ] = 0; } if ( Q_strnicmp( szFileName, gamedir, offset ) ) continue; char *pFile = szFileName + offset; ++resourcesConsidered; ReferencedFile rf; rf.sym = g_Analysis.symbols.AddString( pFile ); int idx = files.Find( rf ); if ( idx == files.InvalidIndex() ) { ++addedStrings; rf.maplist.AddToTail( resfilesymbol ); files.Insert( rf ); } else { // ReferencedFile & slot = files[ idx ]; if ( slot.maplist.Find( resfilesymbol ) == slot.maplist.InvalidIndex() ) { slot.maplist.AddToTail( resfilesymbol ); } } } } } delete[] pStart; } g_pFileSystem->Close(resfilehandle); } int filesFound = addedStrings; vprint( 1, "Found %i new resources (%i total) in %s\n", filesFound, resourcesConsidered, resfile ); }