void CViewAngleAnimation::SaveAsAnimFile( const char *pKeyFrameFileName ) { // save all of our keyframes into the file KeyValues *pData = new KeyValues( pKeyFrameFileName ); pData->SetInt( "flags", m_iFlags ); KeyValues *pKey = new KeyValues( "keyframe" ); int i; int c = m_KeyFrames.Count(); char buf[64]; for ( i=0;i<c;i++ ) { pKey = pData->CreateNewKey(); Q_snprintf( buf, sizeof(buf), "%f %f %f", m_KeyFrames[i]->m_vecAngles[0], m_KeyFrames[i]->m_vecAngles[1], m_KeyFrames[i]->m_vecAngles[2] ); pKey->SetString( "angles", buf ); pKey->SetFloat( "time", m_KeyFrames[i]->m_flTime ); pKey->SetInt( "flags", m_KeyFrames[i]->m_iFlags ); } pData->SaveToFile( filesystem, pKeyFrameFileName, NULL ); pData->deleteThis(); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void MountExtraContent() { memset(g_AppStatus, 0, sizeof(g_AppStatus)); KeyValues *pMountList = new KeyValues( "MountList" ); if( !pMountList->LoadFromFile( filesystem, "mountlist.txt" ) ) { // Create default pMountList->SetString( "dota", "0" ); pMountList->SetString( "left4dead", "0" ); pMountList->SetString( "left4dead2", "0" ); pMountList->SetString( "portal2", "0" ); pMountList->SetString( "csgo", "0" ); pMountList->SetString( "dearesther", "0" ); pMountList->SaveToFile( filesystem, "mountlist.txt", "MOD" ); } if( TryMountVPKGame( "DOTA", "../../common/dota 2 beta/dota", APP_DOTA, "dota", pMountList ) ) PostProcessDota2( "models" ); TryMountVPKGame( "Portal 2", "../../common/portal 2/portal2", APP_PORTAL2, "portal2", pMountList ); TryMountVPKGame( "Left 4 Dead 2", "../../common/left 4 dead 2/left4dead2", APP_L4D2, "left4dead2", pMountList ); TryMountVPKGame( "Left 4 Dead", "../../common/left 4 dead/left4dead", APP_L4D1, "left4dead", pMountList ); TryMountVPKGame( "Counter-Strike Global Offensive", "../../common/Counter-Strike Global Offensive/csgo", APP_CSGO, "csgo", pMountList ); TryMountVPKGame( "Dear Esther", "../../common/dear esther/dearesther", APP_DEARESTHER, "dearesther", pMountList ); if( pMountList ) { pMountList->deleteThis(); pMountList = NULL; } }
void CEditorRoot::SaveLayout() { KeyValues *pKV = new KeyValues( "config" ); pKV->SetInt( "preview_visible", (pPreview && pPreview->IsVisible()) ); if ( pPreview ) pPreview->GetBounds( px, py, psx, psy ); pKV->SetInt( "p_x", px ); pKV->SetInt( "p_y", py ); pKV->SetInt( "p_sx", psx ); pKV->SetInt( "p_sy", psy ); pKV->SetInt( "draw_datatypes", m_bDraw_Datatypes ? 1 : 0 ); pKV->SetInt( "draw_shadows", m_bDraw_Shadows ? 1 : 0 ); pKV->SetInt( "draw_all_limits", m_bDraw_AllLimits ? 1 : 0 ); pKV->SetInt( "compile_preview", m_bAutoCompile ? 1 : 0 ); pKV->SetInt( "enable_nodeview_tooltips", m_bDoTooltips ? 1 : 0 ); pKV->SetInt( "compile_always_full", m_bAutoFullcompile ? 1 : 0 ); pKV->SetInt( "compile_auto_publish_to_materials", m_bAutoShaderPublish ? 1 : 0 ); pKV->SetInt( "precache_auto_reload", m_bAutoPrecacheUpdate ? 1 : 0 ); pKV->SetInt( "warn_unsaved_changes", m_bWarnOnClose ? 1 : 0 ); pKV->SetInt( "cedit_x", cedit_x ); pKV->SetInt( "cedit_y", cedit_y ); pKV->SetInt( "cedit_sx", cedit_sx ); pKV->SetInt( "cedit_sy", cedit_sy ); pKV->SaveToFile( filesystem, VarArgs( "%s/shadereditorui/editor_config.txt", engine->GetGameDirectory()), "MOD" ); pKV->deleteThis(); //DeallocPingPongRTs(); }
void CButtonPanel::OnCommand( const char *command) { if (!Q_strcmp(command, "opennews")) { CloseAll(); m_pNews->SetNormalImage("news"); m_iLatestNews = time(NULL); KeyValues *manifest = new KeyValues( "latest_news" ); manifest->SetInt("time", (long)m_iLatestNews); manifest->SaveToFile( filesystem, "latest_news.txt", "MOD" ); NewsFrame()->ShowPanel(true); return; } if (!Q_strcmp(command, "openleaderboard")) { CloseAll(); Leaderboard()->ShowPanel(true); return; } BaseClass::OnCommand(command); }
//Called every time a new time is achieved void CTimer::SaveTime() { const char *szMapName = gpGlobals->mapname.ToCStr(); KeyValues *timesKV = new KeyValues(szMapName); int count = localTimes.Count(); for (int i = 0; i < count; i++) { Time t = localTimes[i]; char timeName[512]; Q_snprintf(timeName, 512, "%i", t.ticks); KeyValues *pSubkey = new KeyValues(timeName); pSubkey->SetFloat("rate", t.tickrate); pSubkey->SetInt("date", t.date); timesKV->AddSubKey(pSubkey); } char file[MAX_PATH]; Q_strcpy(file, c_mapDir); Q_strcat(file, szMapName, MAX_PATH); Q_strncat(file, c_timesExt, MAX_PATH); if (timesKV->SaveToFile(filesystem, file, "MOD", true)) { Log("Successfully saved new time!\n"); IGameEvent *savedEvent = gameeventmanager->CreateEvent("runtime_saved"); if (savedEvent) gameeventmanager->FireEvent(savedEvent); } timesKV->deleteThis(); }
//----------------------------------------------------------------------------- // Purpose: saves control settings to file //----------------------------------------------------------------------------- bool BuildGroup::SaveControlSettings( void ) { bool bSuccess = false; if ( m_pResourceName ) { KeyValues *rDat = new KeyValues( m_pResourceName ); // get the data from our controls GetSettings( rDat ); char fullpath[ 512 ]; g_pFullFileSystem->RelativePathToFullPath( m_pResourceName, m_pResourcePathID, fullpath, sizeof( fullpath ) ); // save the data out to a file bSuccess = rDat->SaveToFile( g_pFullFileSystem, fullpath, NULL ); if (!bSuccess) { MessageBox *dlg = new MessageBox("BuildMode - Error saving file", "Error: Could not save changes. File is most likely read only."); dlg->DoModal(); } rDat->deleteThis(); } return bSuccess; }
//----------------------------------------------------------------------------- // Purpose: saves all the current settings to the user config file //----------------------------------------------------------------------------- void CSystem::SaveUserConfigFile() { if (m_pUserConfigData) { m_pUserConfigData->SaveToFile((IBaseFileSystem*)filesystem(), m_szFileName, m_szPathID); } }
//----------------------------------------------------------------------------- // Purpose: saves all the current settings to the user config file //----------------------------------------------------------------------------- void CSystem::SaveUserConfigFile() { if (m_pUserConfigData) { m_pUserConfigData->SaveToFile(g_pFullFileSystem, m_szFileName, m_szPathID); } }
bool CRoomTemplate::SaveRoomTemplate() { if (!m_pLevelTheme) return false; char szThemeDirName[MAX_PATH]; Q_snprintf(szThemeDirName, sizeof(szThemeDirName), "tilegen/roomtemplates/%s", m_pLevelTheme->m_szName); g_pFullFileSystem->CreateDirHierarchy( szThemeDirName, "GAME" ); char szFullFileName[MAX_PATH]; Q_snprintf( szFullFileName, sizeof(szFullFileName), "tilegen/roomtemplates/%s/%s.roomtemplate", m_pLevelTheme->m_szName, m_FullName ); KeyValues *pRoomTemplateKeyValues = new KeyValues( m_FullName ); pRoomTemplateKeyValues->SetInt( "TilesX", m_nTilesX ); pRoomTemplateKeyValues->SetInt( "TilesY", m_nTilesY ); pRoomTemplateKeyValues->SetInt( "SpawnWeight", m_nSpawnWeight ); pRoomTemplateKeyValues->SetString( "RoomTemplateDescription", m_Description ); pRoomTemplateKeyValues->SetString( "Soundscape", m_Soundscape ); pRoomTemplateKeyValues->SetInt( "TileType", m_nTileType ); // exits int iExits = m_Exits.Count(); for (int i=0; i<iExits; i++) { KeyValues *pkvSubSection = new KeyValues("EXIT"); pkvSubSection->SetInt("XPos", m_Exits[i]->m_iXPos); pkvSubSection->SetInt("YPos", m_Exits[i]->m_iYPos); pkvSubSection->SetInt("ExitDirection", (int) m_Exits[i]->m_ExitDirection); pkvSubSection->SetInt("ZChange", m_Exits[i]->m_iZChange); pkvSubSection->SetString("ExitTag", m_Exits[i]->m_szExitTag); pkvSubSection->SetBool("ChokeGrow", m_Exits[i]->m_bChokepointGrowSource); pRoomTemplateKeyValues->AddSubKey(pkvSubSection); } // tags KeyValues *pkvSubSection = new KeyValues("Tags"); for ( int i=0; i<GetNumTags(); i++ ) { pkvSubSection->AddSubKey( new KeyValues( "tag", NULL, GetTag( i ) ) ); } pRoomTemplateKeyValues->AddSubKey(pkvSubSection); if (!pRoomTemplateKeyValues->SaveToFile(g_pFullFileSystem, szFullFileName, "GAME")) { Msg("Error: Failed to save room template %s\n", szFullFileName); return false; } return true; }
void CTileGenDialog::GenerateRoomThumbnails( bool bAddToPerforce ) { // save out a keyvalues file with position/size of each room KeyValues *pKV = new KeyValues( "RoomThumbnails" ); char filename[MAX_PATH]; for ( int i=0;i<m_pMapLayout->m_PlacedRooms.Count();i++ ) { CRoom *pRoom = m_pMapLayout->m_PlacedRooms[i]; if ( !pRoom ) continue; KeyValues *pkvEntry = new KeyValues( "Thumbnail" ); Q_snprintf( filename, sizeof( filename ), "tilegen/roomtemplates/%s/%s.tga", pRoom->m_pRoomTemplate->m_pLevelTheme->m_szName, pRoom->m_pRoomTemplate->GetFullName() ); pkvEntry->SetString( "Filename", filename ); int half_map_size = MAP_LAYOUT_TILES_WIDE * 0.5f; // shift back so the middle of our grid is the origin float xPos = (pRoom->m_iPosX - half_map_size) * ASW_TILE_SIZE; float yPos = (pRoom->m_iPosY - half_map_size) * ASW_TILE_SIZE; pkvEntry->SetFloat( "RoomX", xPos ); pkvEntry->SetFloat( "RoomY", yPos + pRoom->m_pRoomTemplate->GetTilesY() * ASW_TILE_SIZE ); pkvEntry->SetFloat( "RoomWide", pRoom->m_pRoomTemplate->GetTilesX() * ASW_TILE_SIZE ); pkvEntry->SetFloat( "RoomTall", pRoom->m_pRoomTemplate->GetTilesY() * ASW_TILE_SIZE ); pkvEntry->SetFloat( "OutputWide", pRoom->m_pRoomTemplate->GetTilesX() * RoomTemplatePanelTileSize() ); pkvEntry->SetFloat( "OutputTall", pRoom->m_pRoomTemplate->GetTilesY() * RoomTemplatePanelTileSize() ); pKV->AddSubKey( pkvEntry ); } if ( !pKV->SaveToFile( g_pFullFileSystem, THUMBNAILS_FILE, "GAME" ) ) { Msg( "Error: Couldn't save %s\n", THUMBNAILS_FILE ); pKV->deleteThis(); return; } pKV->deleteThis(); m_pMapLayout->SaveMapLayout( "maps/output.layout" ); if ( engine ) { char buffer[256]; Q_snprintf(buffer, sizeof(buffer), "asw_random_weapons 0; asw_building_room_thumbnails 1; asw_add_room_thumbnails_to_perforce %d; asw_build_map %s", bAddToPerforce ? 1 : 0, "output.layout" ); engine->ClientCmd_Unrestricted( buffer ); } }
void CASWJukeboxPlaylist::ExportPlayistKV( void ) { KeyValues *pPlaylistKV = new KeyValues("playlist"); for( int i=0; i<m_CombatMusicPlaylist.Count(); ++i ) { KeyValues *pTrackKV = new KeyValues("Track"); pTrackKV->SetString( "TrackName", m_CombatMusicPlaylist[i].m_szFilename ); pTrackKV->SetString( "HexName", m_CombatMusicPlaylist[i].m_szHexname ); pTrackKV->SetString( "Album", m_CombatMusicPlaylist[i].m_szAlbum ); pTrackKV->SetString( "Artist", m_CombatMusicPlaylist[i].m_szArtist); pTrackKV->SetString( "Genre", m_CombatMusicPlaylist[i].m_szGenre ); pPlaylistKV->AddSubKey( pTrackKV ); } pPlaylistKV->SaveToFile( filesystem, sz_PlaylistFilename ); pPlaylistKV->deleteThis(); }
//-------------------------------------------------------------------------------------------------------------- void DownloadCache::PersistToCache( const RequestContext *rc ) { if ( !m_cache || !rc || !rc->data || !rc->nBytesTotal || !rc->nBytesCurrent ) return; char cachePath[_MAX_PATH]; GenerateCacheFilename( rc, cachePath ); FileHandle_t fp = g_pFileSystem->Open( cachePath, "wb" ); if ( fp ) { g_pFileSystem->Write( rc->data, rc->nBytesCurrent, fp ); g_pFileSystem->Close( fp ); m_cache->SaveToFile( g_pFileSystem, CacheFilename, NULL ); } }
/* 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(); }
void CTilegenKVEditorPage::OnCommand( const char *command ) { if ( !Q_stricmp( command, "Save" ) ) { KeyValues *pKV = GetKeyValues(); char fullFilePathBuffer [512]; Q_snprintf(fullFilePathBuffer, sizeof(fullFilePathBuffer),"C:\\Program Files\\Steam\\steamapps\\sourcemods\\alienswarmdirectormod\\%s", m_szFilename); Msg("Saving to [%s]", fullFilePathBuffer); //if ( pKV != NULL && !pKV->SaveToFile( g_pFullFileSystem, m_szFilename, "GAME" ) ) if ( pKV != NULL && !pKV->SaveToFile( g_pFullFileSystem, fullFilePathBuffer ) ) { if ( p4 ) { char fullPath[MAX_PATH]; g_pFullFileSystem->RelativePathToFullPath( m_szFilename, "GAME", fullPath, MAX_PATH ); if ( p4->IsFileInPerforce( fullPath ) ) { MessageBox *pMessage = new MessageBox( "Check Out?", "File is not writeable. Would you like to check it out from Perforce?", this ); pMessage->SetCancelButtonVisible( true ); pMessage->SetOKButtonText( "#MessageBox_Yes" ); pMessage->SetCancelButtonText( "#MessageBox_No" ); pMessage->SetCommand( new KeyValues( "CheckOutFromP4", "file", fullPath ) ); pMessage->DoModal(); return; } } else { VGUIMessageBox( this, "Save Error", "Failed to save %s. Make sure file is checked out from Perforce.", m_szFilename ); } } UpdateList(); return; } else if ( !Q_stricmp( command, "New" ) ) { SaveNew(); return; } BaseClass::OnCommand( command ); }
bool CLevelTheme::SaveTheme(const char *pszThemeName) { char szFullFileName[MAX_PATH]; Q_snprintf(szFullFileName, sizeof(szFullFileName), "tilegen/themes/%s.theme", pszThemeName); KeyValues *pThemeKeyValues = new KeyValues( pszThemeName ); pThemeKeyValues->SetString("ThemeName", m_szName); pThemeKeyValues->SetString("ThemeDescription", m_szDescription); pThemeKeyValues->SetBool( "VMFTweak", m_bRequiresVMFTweak ); pThemeKeyValues->SetBool( "SkipErrorCheck", m_bSkipErrorCheck ); char buffer[128]; Q_snprintf( buffer, sizeof( buffer ), "%f %f %f", m_vecAmbientLight.x, m_vecAmbientLight.y, m_vecAmbientLight.z ); pThemeKeyValues->SetString( "AmbientLight", buffer ); if (!pThemeKeyValues->SaveToFile(g_pFullFileSystem, szFullFileName, "GAME")) { Msg("Error: Failed to save theme %s\n", szFullFileName); return false; } // TODO: check the room templates folder for this theme exists return true; }
void CTilegenKVEditorPage::OnCheckOutFromP4( KeyValues *pKV ) { const char *pPath = pKV->GetString( "file", NULL ); if ( pPath != NULL ) { if ( p4->OpenFileForEdit( pPath ) ) { KeyValues *pKV = GetKeyValues(); if ( !pKV->SaveToFile( g_pFullFileSystem, m_szFilename, "GAME" ) ) { VGUIMessageBox( this, "Save Error!", "Checked out '%s' from Perforce, but failed to save file.", pPath ); } } else { VGUIMessageBox( this, "P4 Error!", "Failed to check out '%s' from Perforce.", pPath ); } } UpdateList(); }
void CTilegenLayoutSystemPage::OnFileSelected( const char *pFullPath ) { if ( g_pFullFileSystem->FileExists( pFullPath ) ) { VGUIMessageBox( this, "Save Error", "A layout system already exists with filename %s.", pFullPath ); return; } // create new keys KeyValues *pNewKeys = new KeyValues( "Mission" ); // save them at the full path if ( !pNewKeys->SaveToFile( g_pFullFileSystem, pFullPath ) ) { VGUIMessageBox( this, "Save Error", "Failed to save new file %s.", pFullPath ); return; } m_pEditor->SetMissionData( pNewKeys ); m_pReloadMissionButton->SetVisible( true ); m_pSaveButton->SetVisible( true ); m_pGenerateButton->SetVisible( true ); bool bConverted = g_pFullFileSystem->FullPathToRelativePath( pFullPath, m_szFilename, MAX_PATH ); if ( !bConverted ) { Warning( "Failed to convert this to a relative path: %s\n", pFullPath ); return; } m_pFilenameLabel->SetText( m_szFilename + Q_strlen( "tilegen/" ) ); m_pNewMissionDatabase->AddFile( pNewKeys, m_szFilename ); UpdateList(); if ( p4 ) { MessageBox *pMessage = new MessageBox( "Add to P4?", "Would you like to add this mission to perforce?", this ); pMessage->SetCancelButtonVisible( true ); pMessage->SetOKButtonText( "#MessageBox_Yes" ); pMessage->SetCancelButtonText( "#MessageBox_No" ); pMessage->SetCommand( new KeyValues( "AddToP4", "file", pFullPath ) ); pMessage->DoModal(); } }
static void WriteToProgramCache( CGLMShaderPair *pair ) { KeyValues *pProgramCache = new KeyValues( "programcache" ); pProgramCache->LoadFromFile( g_pFullFileSystem, PROGRAM_CACHE_FILE, "MOD" ); if ( !pProgramCache ) { Warning( "Could not write to program cache file!\n" ); return; } // extract values of interest which represent a pair of shaders char vprogramName[128]; int vprogramStaticIndex = -1; int vprogramDynamicIndex = -1; pair->m_vertexProg->GetLabelIndexCombo( vprogramName, sizeof(vprogramName), &vprogramStaticIndex, &vprogramDynamicIndex ); char pprogramName[128]; int pprogramStaticIndex = -1; int pprogramDynamicIndex = -1; pair->m_fragmentProg->GetLabelIndexCombo( pprogramName, sizeof(pprogramName), &pprogramStaticIndex, &pprogramDynamicIndex ); // make up a key - this thing is really a list of tuples, so need not be keyed by anything particular KeyValues *pProgramKey = pProgramCache->CreateNewKey(); Assert( pProgramKey ); pProgramKey->SetString ( "vs", vprogramName ); pProgramKey->SetString ( "ps", pprogramName ); pProgramKey->SetInt ( "vs_static", vprogramStaticIndex ); pProgramKey->SetInt ( "ps_static", pprogramStaticIndex ); pProgramKey->SetInt ( "vs_dynamic", vprogramDynamicIndex ); pProgramKey->SetInt ( "ps_dynamic", pprogramDynamicIndex ); pProgramCache->SaveToFile( g_pFullFileSystem, PROGRAM_CACHE_FILE, "MOD" ); pProgramCache->deleteThis(); }
//----------------------------------------------------------------------------- // Purpose: debug helper, spits out a human readable keyvalues version of the various configs //----------------------------------------------------------------------------- void OutputKeyValuesVersion( CVCProjConvert & proj ) { KeyValues *kv = new KeyValues( "project" ); for ( int projIndex = 0; projIndex < proj.GetNumConfigurations(); projIndex++ ) { CVCProjConvert::CConfiguration & config = proj.GetConfiguration(projIndex); KeyValues *configKv = kv->FindKey( config.GetName().String(), true ); int fileCount = 0; for( int fileIndex = 0; fileIndex < config.GetNumFileNames(); fileIndex++ ) { if ( config.GetFileType(fileIndex) == CVCProjConvert::CConfiguration::FILE_SOURCE ) { char num[20]; Q_snprintf( num, sizeof(num), "%i", fileCount ); fileCount++; configKv->SetString( num, config.GetFileName(fileIndex) ); } } } kv->SaveToFile( g_pFileSystem, "files.vdf" ); kv->deleteThis(); }
void CTilegenKVEditorPage::OnCommand( const char *command ) { if ( !Q_stricmp( command, "Save" ) ) { KeyValues *pKV = GetKeyValues(); if ( pKV != NULL && !pKV->SaveToFile( g_pFullFileSystem, m_szFilename, "MOD" ) ) { if ( p4 ) { char fullPath[MAX_PATH]; g_pFullFileSystem->RelativePathToFullPath( m_szFilename, "MOD", fullPath, MAX_PATH ); if ( p4->IsFileInPerforce( fullPath ) ) { MessageBox *pMessage = new MessageBox( "Check Out?", "File is not writeable. Would you like to check it out from Perforce?", this ); pMessage->SetCancelButtonVisible( true ); pMessage->SetOKButtonText( "#MessageBox_Yes" ); pMessage->SetCancelButtonText( "#MessageBox_No" ); pMessage->SetCommand( new KeyValues( "CheckOutFromP4", "file", fullPath ) ); pMessage->DoModal(); return; } } else { VGUIMessageBox( this, "Save Error", "Failed to save %s. Make sure file is checked out from Perforce.", m_szFilename ); } } UpdateList(); return; } else if ( !Q_stricmp( command, "New" ) ) { SaveNew(); return; } BaseClass::OnCommand( command ); }
// saves current save data to a keyvalues file bool CASW_Campaign_Save::SaveGameToFile(const char *szFileName) { // make sure the path and extension are correct char szFullFileName[256]; char tempbuffer[256]; if (szFileName==NULL) { if (m_CurrentSaveFileName == NULL_STRING) { Msg("Error: Couldn't save game to file as we have no name already and you didn't supply one.\n"); return false; } Q_snprintf(szFullFileName, sizeof(szFullFileName), "%s", STRING(m_CurrentSaveFileName)); } else { Q_snprintf(tempbuffer, sizeof(tempbuffer), "%s", szFileName); Q_SetExtension( tempbuffer, ".campaignsave", sizeof(tempbuffer) ); const char *pszNoPathName = Q_UnqualifiedFileName(tempbuffer); Q_snprintf(szFullFileName, sizeof(szFullFileName), "save/%s", pszNoPathName); } // before saving, check if this is actually a completed campaign if (ASWGameRules()) { int iLeft = ASWGameRules()->CampaignMissionsLeft(); if (iLeft <= 0) { Msg("Deleting completed campaign %s", szFullFileName); filesystem->RemoveFile( szFullFileName, "GAME" ); // notify the local mission source that a save has been deleted if (missionchooser && missionchooser->LocalMissionSource()) { const char *pszNoPathName = Q_UnqualifiedFileName(szFullFileName); missionchooser->LocalMissionSource()->NotifySaveDeleted(pszNoPathName); } return true; } } // we don't want completed campaigns lingering on disk KeyValues *pSaveKeyValues = new KeyValues( "CAMPAIGNSAVE" ); pSaveKeyValues->SetInt("Version", m_iVersion); pSaveKeyValues->SetInt("SkillLevel", m_iLowestSkillLevelPlayed); pSaveKeyValues->SetString("CampaignName", m_CampaignName.Get()); pSaveKeyValues->SetInt("CurrentPosition", m_iCurrentPosition); pSaveKeyValues->SetInt("NumMissionsComplete", m_iNumMissionsComplete); pSaveKeyValues->SetInt("InitialNumMissionsComplete", m_iInitialNumMissionsComplete); pSaveKeyValues->SetInt("Multiplayer", m_bMultiplayerGame ? 1 : 0); pSaveKeyValues->SetInt( "NumDeaths", m_iNumDeaths ); pSaveKeyValues->SetBool( "FixedSkillPoints", m_bFixedSkillPoints ); // update date int year, month, dayOfWeek, day, hour, minute, second; missionchooser->GetCurrentTimeAndDate(&year, &month, &dayOfWeek, &day, &hour, &minute, &second); //year = month = dayOfWeek = day = hour = minute = second = 0; Q_snprintf(m_DateTime.GetForModify(), 255, "%02d/%02d/%d %02d:%02d", month, day, year, hour, minute); pSaveKeyValues->SetString("DateTime", m_DateTime.Get()); // write out each mission's status KeyValues *pSubSection; for (int i=0; i<ASW_MAX_MISSIONS_PER_CAMPAIGN; i++) { pSubSection = new KeyValues("MISSION"); pSubSection->SetInt("MissionID", i); pSubSection->SetInt("MissionComplete", m_MissionComplete[i]); pSubSection->SetInt("NumRetries", m_NumRetries[i]); pSaveKeyValues->AddSubKey(pSubSection); } // write out each marine's stats for (int MarineID=0; MarineID<ASW_NUM_MARINE_PROFILES; MarineID++) { pSubSection = new KeyValues("MARINE"); pSubSection->SetInt("MarineID", MarineID); pSubSection->SetInt("SkillSlot0", m_iMarineSkill[MarineID][ASW_SKILL_SLOT_0]); pSubSection->SetInt("SkillSlot1", m_iMarineSkill[MarineID][ASW_SKILL_SLOT_1]); pSubSection->SetInt("SkillSlot2", m_iMarineSkill[MarineID][ASW_SKILL_SLOT_2]); pSubSection->SetInt("SkillSlot3", m_iMarineSkill[MarineID][ASW_SKILL_SLOT_3]); pSubSection->SetInt("SkillSlot4", m_iMarineSkill[MarineID][ASW_SKILL_SLOT_4]); pSubSection->SetInt("SkillSlotSpare", m_iMarineSkill[MarineID][ASW_SKILL_SLOT_SPARE]); pSubSection->SetInt("UndoSkillSlot0", m_iPreviousMarineSkill[MarineID][ASW_SKILL_SLOT_0]); pSubSection->SetInt("UndoSkillSlot1", m_iPreviousMarineSkill[MarineID][ASW_SKILL_SLOT_1]); pSubSection->SetInt("UndoSkillSlot2", m_iPreviousMarineSkill[MarineID][ASW_SKILL_SLOT_2]); pSubSection->SetInt("UndoSkillSlot3", m_iPreviousMarineSkill[MarineID][ASW_SKILL_SLOT_3]); pSubSection->SetInt("UndoSkillSlot4", m_iPreviousMarineSkill[MarineID][ASW_SKILL_SLOT_4]); pSubSection->SetInt("UndoSkillSlotSpare", m_iPreviousMarineSkill[MarineID][ASW_SKILL_SLOT_SPARE]); pSubSection->SetInt("ParasitesKilled", m_iParasitesKilled[MarineID]); pSubSection->SetString("MissionsCompleted", STRING(m_MissionsCompleteNames[MarineID])); pSubSection->SetString("Medals", STRING(m_Medals[MarineID])); int iWound = IsMarineWounded(MarineID) ? 1 : 0; pSubSection->SetInt("Wounded", iWound); int iDead = IsMarineAlive(MarineID) ? 0 : 1; pSubSection->SetInt("Dead", iDead); pSaveKeyValues->AddSubKey(pSubSection); } // check for any new players to add to our list for ( int i = 1; i <= gpGlobals->maxClients; i++ ) { CASW_Player* pPlayer = dynamic_cast<CASW_Player*>(UTIL_PlayerByIndex(i)); if ( pPlayer ) { // first check his network ID const char *pszNetworkID = pPlayer->GetASWNetworkID(); // check if it's in our list bool bFound = false; for (int k=0;k<m_PlayerIDs.Count();k++) { const char *p = STRING(m_PlayerIDs[k]); if (!Q_strcmp(p, pszNetworkID)) bFound = true; } if (!bFound) { // add it to the list string_t stringID = AllocPooledString(pszNetworkID); m_PlayerIDs.AddToTail(stringID); } // then check player name const char *pszPlayerName = pPlayer->GetPlayerName(); bFound = false; for (int k=0;k<m_PlayerNames.Count();k++) { const char *p = STRING(m_PlayerNames[k]); if (!Q_strcmp(p, pszPlayerName)) bFound = true; } if (!bFound) { // add it to the list string_t stringName = AllocPooledString(pszPlayerName); m_PlayerNames.AddToTail(stringName); } } } pSaveKeyValues->SetInt("NumPlayers", m_PlayerNames.Count()); // write out player names for (int i=0; i<m_PlayerNames.Count(); i++) { pSubSection = new KeyValues("PLAYER"); pSubSection->SetString("PlayerName", STRING(m_PlayerNames[i])); pSaveKeyValues->AddSubKey(pSubSection); } // write out player IDs for (int i=0; i<m_PlayerIDs.Count(); i++) { pSubSection = new KeyValues("DATA"); pSubSection->SetString("DataBlock", STRING(m_PlayerIDs[i])); pSaveKeyValues->AddSubKey(pSubSection); } // write out last commanders section pSubSection = new KeyValues("COMM"); for (int i=0;i<ASW_NUM_MARINE_PROFILES;i++) { char buffer[16]; Q_snprintf(buffer, sizeof(buffer), "Comm%d", i); pSubSection->SetString(buffer, STRING(m_LastCommanders[i])); Q_snprintf(buffer, sizeof(buffer), "Slot%d", i); pSubSection->SetInt( buffer, m_LastMarineResourceSlot[i] ); //Ch1ckensCoop: Record which marine was primary for reservations. Q_snprintf(buffer, sizeof(buffer), "Primary%d", i); pSubSection->SetBool( buffer, m_LastPrimaryMarines[i] ); } pSaveKeyValues->AddSubKey(pSubSection); if (pSaveKeyValues->SaveToFile(filesystem, szFullFileName)) { if (missionchooser && missionchooser->LocalMissionSource()) { const char *pszNoPathName = Q_UnqualifiedFileName(szFullFileName); missionchooser->LocalMissionSource()->OnSaveUpdated(pszNoPathName); } return true; } return false; }
void CGECreateServer::OnCommand( const char *command ) { if ( !Q_stricmp(command, "play") ) { CUtlVector<char*> commands; // Pull the values from our controls and apply them to commands and save off the choices for ( KeyValues *kv = m_kvCmdMap->GetFirstTrueSubKey(); kv; kv = kv->GetNextTrueSubKey() ) { KeyValues *kv_value = m_kvCmdValues->FindKey( kv->GetName(), true ); char *cmd = new char[128]; try { if ( !Q_stricmp(kv->GetString("type"), "CHOICE") ) { ComboBox *panel = dynamic_cast<ComboBox*>( FindChildByName(kv->GetName()) ); const char *cmd_value = panel->GetActiveItemUserData()->GetName(); kv_value->SetStringValue( cmd_value ); if ( !Q_stricmp(cmd_value, RANDOM_VALUE) ) { int idx = GERandom<int>( panel->GetItemCount()-1 ) + 1; idx = panel->GetItemIDFromRow( idx ); cmd_value = panel->GetItemUserData( idx )->GetName(); } Q_snprintf( cmd, 128, "%s \"%s\"", kv->GetString("cmd"), cmd_value ); commands.AddToTail( cmd ); } else if ( !Q_stricmp(kv->GetString("type"), "TEXT") ) { char cmd_value[64]; TextEntry *panel = dynamic_cast<TextEntry*>( FindChildByName(kv->GetName()) ); panel->GetText( cmd_value, 64 ); // We don't allow blank values... use default instead if ( !cmd_value[0] ) Q_strncpy( cmd_value, kv->GetString("default",""), 64 ); kv_value->SetStringValue( cmd_value ); Q_snprintf( cmd, 128, "%s \"%s\"", kv->GetString("cmd"), cmd_value ); commands.AddToTail( cmd ); } else if ( !Q_stricmp(kv->GetString("type"), "BOOL") ) { CheckButton *panel = dynamic_cast<CheckButton*>( FindChildByName(kv->GetName()) ); if ( panel->IsSelected() ) { kv_value->SetStringValue( "1" ); Q_snprintf( cmd, 128, "%s \"%s\"", kv->GetString("cmd"), kv->GetString("on_val","1") ); } else { kv_value->SetStringValue( "0" ); Q_snprintf( cmd, 128, "%s \"%s\"", kv->GetString("cmd"), kv->GetString("off_val","0") ); } commands.AddToTail( cmd ); } else { delete [] cmd; } } catch (...) { delete [] cmd; } } // Apply the commands for ( int i=0; i < commands.Count(); i++ ) engine->ClientCmd_Unrestricted( commands[i] ); // Save our last used settings to our custom file m_kvCmdValues->SaveToFile( filesystem, COMMAND_MAP_VAL, "MOD" ); // Cleanup commands.PurgeAndDeleteElements(); } SetVisible( false ); }
bool CASW_Mission_Chooser_Source_Local::ASW_Campaign_CreateNewSaveGame(char *szFileName, int iFileNameMaxLen, const char *szCampaignName, bool bMultiplayerGame, const char *szStartingMission) // szFileName arg is the desired filename or NULL for an autogenerated one. Function sets szFileName with the filename used. { if (!szFileName) return false; char stripped[MAX_PATH]; V_StripExtension( szCampaignName, stripped, MAX_PATH ); char szStartingMissionStripped[64]; if ( szStartingMission ) { V_StripExtension( szStartingMission, szStartingMissionStripped, sizeof( szStartingMissionStripped ) ); } else { szStartingMissionStripped[0] = 0; } // check the campaign file exists char campbuffer[MAX_PATH]; Q_snprintf(campbuffer, sizeof(campbuffer), "resource/campaigns/%s.txt", stripped); if (!g_pFullFileSystem->FileExists(campbuffer)) { Msg("No such campaign: %s\n", campbuffer); return false; } // Get the current time and date as a string char szDateTime[256]; int year, month, dayOfWeek, day, hour, minute, second; ASW_System_GetCurrentTimeAndDate(&year, &month, &dayOfWeek, &day, &hour, &minute, &second); Q_snprintf(szDateTime, sizeof(szDateTime), "%02d/%02d/%02d %02d:%02d", month, day, year, hour, minute); if (szFileName[0] == '\0') { // autogenerate a filename based on the current time and date Q_snprintf(szFileName, iFileNameMaxLen, "%s_save_%02d_%02d_%02d_%02d_%02d_%02d", stripped, year, month, day, hour, minute, second); } // make sure the path and extension are correct Q_SetExtension( szFileName, ".campaignsave", iFileNameMaxLen ); char tempbuffer[256]; Q_snprintf(tempbuffer, sizeof(tempbuffer), "%s", szFileName); const char *pszNoPathName = Q_UnqualifiedFileName(tempbuffer); Msg("Unqualified = %s\n", pszNoPathName); char szFullFileName[256]; Q_snprintf(szFullFileName, sizeof(szFullFileName), "save/%s", pszNoPathName); Msg("Creating new save with filename: %s\n", szFullFileName); KeyValues *pSaveKeyValues = new KeyValues( pszNoPathName ); int nMissionsComplete = 0; if ( szStartingMission && szStartingMission[0] ) { KeyValues *pCampaignDetails = GetCampaignDetails( stripped ); if ( pCampaignDetails ) { int nMissionSections = 0; for ( KeyValues *pMission = pCampaignDetails->GetFirstSubKey(); pMission; pMission = pMission->GetNextKey() ) { if ( !Q_stricmp( pMission->GetName(), "MISSION" ) ) { if ( !Q_stricmp( pMission->GetString( "MapName", "" ), szStartingMissionStripped ) ) { nMissionsComplete = nMissionSections - 1; // skip first dummy mission break; } nMissionSections++; } } } } pSaveKeyValues->SetInt("Version", ASW_CURRENT_SAVE_VERSION); pSaveKeyValues->SetString("CampaignName", stripped); pSaveKeyValues->SetInt("CurrentPosition", nMissionsComplete + 1); // position squad on the first uncompleted mission pSaveKeyValues->SetInt("NumMissionsComplete", nMissionsComplete); pSaveKeyValues->SetInt("InitialNumMissionsComplete", nMissionsComplete); pSaveKeyValues->SetInt("Multiplayer", bMultiplayerGame ? 1 : 0); pSaveKeyValues->SetString("DateTime", szDateTime); pSaveKeyValues->SetInt("NumPlayers", 0); // write out each mission's status KeyValues *pSubSection; for (int i=0; i<ASW_MAX_MISSIONS_PER_CAMPAIGN; i++) { pSubSection = new KeyValues("MISSION"); pSubSection->SetInt("MissionID", i); bool bComplete = ( i != 0 ) && ( i <= nMissionsComplete ); pSubSection->SetInt("MissionComplete", bComplete ? 1 : 0 ); pSaveKeyValues->AddSubKey(pSubSection); } const int nInitialSkillPoints = 0; // write out each marine's stats for (int i=0; i<ASW_NUM_MARINE_PROFILES; i++) { pSubSection = new KeyValues("MARINE"); pSubSection->SetInt("MarineID", i); pSubSection->SetInt("SkillSlot0", 0); pSubSection->SetInt("SkillSlot1", 0); pSubSection->SetInt("SkillSlot2", 0); pSubSection->SetInt("SkillSlot3", 0); pSubSection->SetInt("SkillSlot4", 0); pSubSection->SetInt("SkillSlotSpare", nInitialSkillPoints + nMissionsComplete * ASW_SKILL_POINTS_PER_MISSION ); pSubSection->SetInt("UndoSkillSlot0", 0); pSubSection->SetInt("UndoSkillSlot1", 0); pSubSection->SetInt("UndoSkillSlot2", 0); pSubSection->SetInt("UndoSkillSlot3", 0); pSubSection->SetInt("UndoSkillSlot4", 0); pSubSection->SetInt("UndoSkillSlotSpare", nInitialSkillPoints + nMissionsComplete * ASW_SKILL_POINTS_PER_MISSION ); pSubSection->SetString("MissionsCompleted", ""); pSubSection->SetString("Medals", ""); pSubSection->SetInt("Wounded", 0); pSubSection->SetInt("Dead", 0); pSubSection->SetInt("ParasitesKilled", 0); pSaveKeyValues->AddSubKey(pSubSection); } // players section is empty at first // Create the save sub-directory if (!g_pFullFileSystem->IsDirectory( "save", "MOD" )) { g_pFullFileSystem->CreateDirHierarchy( "save", "MOD" ); } // save it if (pSaveKeyValues->SaveToFile(g_pFullFileSystem, szFullFileName)) { // make sure our save summary list adds this to it, if needed Msg("New save created: %s\n", szFullFileName); NotifyNewSave(pszNoPathName); return true; } Msg("Save to file failed. Filename=%s\n", szFullFileName); return false; }
static void saveZonFile(const char* szMapName) { KeyValues* zoneKV = new KeyValues(szMapName); CBaseEntity* pEnt = gEntList.FindEntityByClassname(NULL, "trigger_momentum_*"); while (pEnt) { KeyValues* subKey = NULL; if (pEnt->ClassMatches("trigger_momentum_timer_start")) { CTriggerTimerStart* pTrigger = dynamic_cast<CTriggerTimerStart*>(pEnt); subKey = new KeyValues("start"); if (pTrigger) { subKey->SetFloat("leavespeed", pTrigger->GetMaxLeaveSpeed()); subKey->SetBool("limitingspeed", pTrigger->IsLimitingSpeed()); } } else if (pEnt->ClassMatches("trigger_momentum_timer_stop")) { subKey = new KeyValues("end"); } else if (pEnt->ClassMatches("trigger_momentum_timer_checkpoint")) { CTriggerCheckpoint* pTrigger = dynamic_cast<CTriggerCheckpoint*>(pEnt); if (pTrigger) { subKey = new KeyValues("checkpoint"); subKey->SetInt("number", pTrigger->GetCheckpointNumber()); } } else if (pEnt->ClassMatches("trigger_momentum_onehop")) { CTriggerOnehop* pTrigger = dynamic_cast<CTriggerOnehop*>(pEnt); if (pTrigger) { subKey = new KeyValues("onehop"); //subKey->SetInt("destination", pTrigger->GetDestinationIndex()); subKey->SetBool("stop", pTrigger->ShouldStopPlayer()); subKey->SetBool("resetang", pTrigger->ShouldResetAngles()); subKey->SetFloat("hold", pTrigger->GetHoldTeleportTime()); subKey->SetString("destinationname", pTrigger->m_target.ToCStr()); } } else if (pEnt->ClassMatches("trigger_momentum_resetonehop")) { subKey = new KeyValues("resetonehop"); } else if (pEnt->ClassMatches("trigger_momentum_teleport_checkpoint")) { CTriggerTeleportCheckpoint* pTrigger = dynamic_cast<CTriggerTeleportCheckpoint*>(pEnt); if (pTrigger) { subKey = new KeyValues("checkpoint_teleport"); //subKey->SetInt("destination", pTrigger->GetDestinationCheckpointNumber()); subKey->SetBool("stop", pTrigger->ShouldStopPlayer()); subKey->SetBool("resetang", pTrigger->ShouldResetAngles()); subKey->SetString("destinationname", pTrigger->m_target.ToCStr()); } } else if (pEnt->ClassMatches("trigger_momentum_multihop")) { CTriggerMultihop* pTrigger = dynamic_cast<CTriggerMultihop*>(pEnt); if (pTrigger) { subKey = new KeyValues("multihop"); //subKey->SetInt("destination", pTrigger->GetDestinationIndex()); subKey->SetBool("stop", pTrigger->ShouldStopPlayer()); subKey->SetFloat("hold", pTrigger->GetHoldTeleportTime()); subKey->SetBool("resetang", pTrigger->ShouldResetAngles()); subKey->SetString("destinationname", pTrigger->m_target.ToCStr()); } } else if (pEnt->ClassMatches("trigger_momentum_timer_stage")) { CTriggerStage *pTrigger = dynamic_cast<CTriggerStage*>(pEnt); if (pTrigger) { subKey = new KeyValues("stage"); subKey->SetInt("number", pTrigger->GetStageNumber()); } } if (subKey) { subKey->SetFloat("xPos", pEnt->GetAbsOrigin().x); subKey->SetFloat("yPos", pEnt->GetAbsOrigin().y); subKey->SetFloat("zPos", pEnt->GetAbsOrigin().z); subKey->SetFloat("xRot", pEnt->GetAbsAngles().x); subKey->SetFloat("yRot", pEnt->GetAbsAngles().y); subKey->SetFloat("zRot", pEnt->GetAbsAngles().z); subKey->SetFloat("xScaleMins", pEnt->WorldAlignMins().x); subKey->SetFloat("yScaleMins", pEnt->WorldAlignMins().y); subKey->SetFloat("zScaleMins", pEnt->WorldAlignMins().z); subKey->SetFloat("xScaleMaxs", pEnt->WorldAlignMaxs().x); subKey->SetFloat("yScaleMaxs", pEnt->WorldAlignMaxs().y); subKey->SetFloat("zScaleMaxs", pEnt->WorldAlignMaxs().z); zoneKV->AddSubKey(subKey); } pEnt = gEntList.FindEntityByClassname(pEnt, "trigger_momentum_*"); } if (zoneKV->GetFirstSubKey())//not empty { char zoneFilePath[MAX_PATH]; Q_strcpy(zoneFilePath, "maps/"); Q_strcat(zoneFilePath, szMapName, MAX_PATH); Q_strncat(zoneFilePath, ".zon", MAX_PATH); zoneKV->SaveToFile(filesystem, zoneFilePath, "MOD"); zoneKV->deleteThis(); } }
//-------------------------------------------------------------------------------------------------------------- void DownloadCache::PersistToDisk( const RequestContext *rc ) { if ( !m_cache ) return; if ( rc && rc->data && rc->nBytesTotal ) { char gamePath[MAX_PATH]; if ( rc->bIsBZ2 ) { Q_StripExtension( rc->gamePath, gamePath, sizeof( gamePath ) ); } else { Q_strncpy( gamePath, rc->gamePath, sizeof( gamePath ) ); } if ( !g_pFileSystem->FileExists( gamePath ) ) { // Create the subdirs char * tmpDir = CloneString( gamePath ); COM_CreatePath( tmpDir ); delete[] tmpDir; bool success = false; if ( rc->bIsBZ2 ) { success = DecompressBZipToDisk( gamePath, rc->gamePath, reinterpret_cast< char * >(rc->data), rc->nBytesTotal ); } else { FileHandle_t fp = g_pFileSystem->Open( gamePath, "wb" ); if ( fp ) { g_pFileSystem->Write( rc->data, rc->nBytesTotal, fp ); g_pFileSystem->Close( fp ); success = true; } } if ( success ) { // write succeeded. remove any old data from the cache. char cachePath[_MAX_PATH]; GetCacheFilename( rc, cachePath ); if ( cachePath[0] ) { g_pFileSystem->RemoveFile( cachePath, NULL ); } BuildKeyNames( rc->gamePath ); KeyValues *kv = m_cache->FindKey( m_cachefileKey, false ); if ( kv ) { m_cache->RemoveSubKey( kv ); } kv = m_cache->FindKey( m_timestampKey, false ); if ( kv ) { m_cache->RemoveSubKey( kv ); } } } } m_cache->SaveToFile( g_pFileSystem, CacheFilename, NULL ); }