//----------------------------------------------------------------------------- // Purpose: Read the information we use out of the configs // Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- bool ParseConfigs( void ) { if ( !g_ConfigManager.IsLoaded() ) return false; // Find the games block of the keyvalues KeyValues *gameBlock = g_ConfigManager.GetGameBlock(); if ( gameBlock == NULL ) { Assert( 0 ); return false; } // Iterate through all subkeys for ( KeyValues *pGame=gameBlock->GetFirstTrueSubKey(); pGame; pGame=pGame->GetNextTrueSubKey() ) { const char *pName = pGame->GetName(); const char *pDir = pGame->GetString( TOKEN_GAME_DIRECTORY ); CGameConfig *newConfig = new CGameConfig( pName, pDir ); g_Configs.AddToTail( newConfig ); } return true; }
static cell_t smn_KvGotoFirstSubKey(IPluginContext *pCtx, const cell_t *params) { Handle_t hndl = static_cast<Handle_t>(params[1]); HandleError herr; HandleSecurity sec; KeyValueStack *pStk; sec.pOwner = NULL; sec.pIdentity = g_pCoreIdent; if ((herr=handlesys->ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk)) != HandleError_None) { return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr); } KeyValues *pSubKey = pStk->pCurRoot.front(); KeyValues *pFirstSubKey; if (params[2]) { pFirstSubKey = pSubKey->GetFirstTrueSubKey(); } else { pFirstSubKey = pSubKey->GetFirstSubKey(); } if (!pFirstSubKey) { return 0; } pStk->pCurRoot.push(pFirstSubKey); return 1; }
//----------------------------------------------------------------------------- // Purpose: Updates the internal data of the keyvalue buffer with the edited info // Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- bool UpdateConfigs( void ) { if ( !g_ConfigManager.IsLoaded() ) return false; // Find the games block of the keyvalues KeyValues *gameBlock = g_ConfigManager.GetGameBlock(); if ( gameBlock == NULL ) { Assert( 0 ); return false; } int i = 0; // Stomp parsed data onto the contained keyvalues for ( KeyValues *pGame=gameBlock->GetFirstTrueSubKey(); pGame != NULL; pGame=pGame->GetNextTrueSubKey(), i++ ) { pGame->SetName( g_Configs[i]->m_Name.Base() ); pGame->SetString( TOKEN_GAME_DIRECTORY, g_Configs[i]->m_ModDir.Base() ); } return true; }
//----------------------------------------------------------------------------- // Purpose: Remove a configuration from the data block //----------------------------------------------------------------------------- bool RemoveConfig( int configID ) { if ( !g_ConfigManager.IsLoaded() ) return false; // Find the games block of the keyvalues KeyValues *gameBlock = g_ConfigManager.GetGameBlock(); if ( gameBlock == NULL ) { Assert( 0 ); return false; } int i = 0; // Iterate through all subkeys for ( KeyValues *pGame=gameBlock->GetFirstTrueSubKey(); pGame; pGame=pGame->GetNextTrueSubKey(), i++ ) { if ( i == configID ) { KeyValues *pOldGame = pGame; pGame = pGame->GetNextTrueSubKey(); gameBlock->RemoveSubKey( pOldGame ); pOldGame->deleteThis(); if ( pGame == NULL ) return true; } } return false; }
//============================================================================= void CustomCampaigns::Activate() { BaseClass::Activate(); // // Show reminder to download legacy data (if necessary) // if ( GetLegacyData::CheckAndSeeIfShouldShow() ) { CBaseModPanel::GetSingleton().OpenWindow( WT_GETLEGACYDATA, this, false ); } m_ActiveControl = m_GplCustomCampaigns; m_GplCustomCampaigns->RemoveAllPanelItems(); // Build a list of campaigns KeyValues *pAllMissions = g_pMatchExtSwarm->GetAllMissions(); if ( !pAllMissions ) return; char const *szGameMode = m_pDataSettings->GetString( "game/mode", "campaign" ); for ( KeyValues *pMission = pAllMissions->GetFirstTrueSubKey(); pMission; pMission = pMission->GetNextTrueSubKey() ) { // Skip builtin missions if ( pMission->GetInt( "builtin" ) ) continue; m_hasAddonCampaign = true; // Check this campaign has chapters for this mode KeyValues *pFirstChapter = pMission->FindKey( CFmtStr( "modes/%s/1", szGameMode ) ); if ( !pFirstChapter ) { m_SomeAddonNoSupport = true; continue; } CustomCampaignListItem* panelItem = m_GplCustomCampaigns->AddPanelItem<CustomCampaignListItem>( "CustomCampaignListItem" ); panelItem->SetParent( m_GplCustomCampaigns ); panelItem->SetCustomCampaignName( pMission->GetString( "displaytitle" ) ); panelItem->SetCampaignContext( pMission->GetString( "name" ) ); } }
//========================================================= //========================================================= void C_GameInstructor::ReadLessonsFromFile( const char *pchFileName ) { // Static init function CScriptedIconLesson::PreReadLessonsFromFile(); MEM_ALLOC_CREDIT(); KeyValues *pLessonKeys = new KeyValues("instructor_lessons"); KeyValues::AutoDelete autoDelete(pLessonKeys); pLessonKeys->LoadFromFile(g_pFullFileSystem, pchFileName, NULL); for ( m_pScriptKeys = pLessonKeys->GetFirstTrueSubKey(); m_pScriptKeys; m_pScriptKeys = m_pScriptKeys->GetNextTrueSubKey() ) { if ( Q_stricmp(m_pScriptKeys->GetName(), "GroupConVarToggle") == 0 ) { // Add convar group toggler to the list int nLessonGroupConVarToggle = m_LessonGroupConVarToggles.AddToTail( LessonGroupConVarToggle_t( m_pScriptKeys->GetString( "convar" ) ) ); LessonGroupConVarToggle_t *pLessonGroupConVarToggle = &(m_LessonGroupConVarToggles[nLessonGroupConVarToggle]); Q_strcpy( pLessonGroupConVarToggle->szLessonGroupName, m_pScriptKeys->GetString("group") ); continue; } // Ensure that lessons aren't added twice if ( GetLesson_Internal(m_pScriptKeys->GetName()) ) { DevWarning("Lesson \"%s\" defined twice!\n", m_pScriptKeys->GetName()); continue; } CScriptedIconLesson *pNewLesson = new CScriptedIconLesson(m_pScriptKeys->GetName(), false, false); GetGameInstructor().DefineLesson(pNewLesson); } m_pScriptKeys = NULL; }
void ReadCheatCommandsFromFile( char *pchFileName ) { KeyValues *pCheatCodeKeys = new KeyValues( "cheat_codes" ); pCheatCodeKeys->LoadFromFile( g_pFullFileSystem, pchFileName, NULL ); KeyValues *pKey = NULL; for ( pKey = pCheatCodeKeys->GetFirstTrueSubKey(); pKey; pKey = pKey->GetNextTrueSubKey() ) { int iCheat = s_CheatCodeCommands.AddToTail(); CheatCodeData_t *pNewCheatCode = &(s_CheatCodeCommands[ iCheat ]); Q_strncpy( pNewCheatCode->szName, pKey->GetName(), CHEAT_NAME_MAX_LEN ); // Get the name pNewCheatCode->bDevOnly = ( pKey->GetInt( "dev", 0 ) != 0 ); // Get developer only flag pNewCheatCode->iCodeLength = 0; // Start at zero code elements Q_strncpy( pNewCheatCode->szCommand, pKey->GetString( "command", "echo \"Cheat code has no command!\"" ), CHEAT_COMMAND_MAX_LEN ); KeyValues *pSubKey = NULL; for ( pSubKey = pKey->GetFirstSubKey(); pSubKey; pSubKey = pSubKey->GetNextKey() ) { const char *pchType = pSubKey->GetName(); if ( Q_strcmp( pchType, "code" ) == 0 ) { AssertMsg( ( pNewCheatCode->iCodeLength < CHEAT_NAME_MAX_LEN ), "Cheat code elements exceeded max!" ); pNewCheatCode->pButtonCodes[ pNewCheatCode->iCodeLength ] = g_pInputSystem->StringToButtonCode( pSubKey->GetString() ); ++pNewCheatCode->iCodeLength; } } if ( pNewCheatCode->iCodeLength < CHEAT_NAME_MAX_LEN ) { // If it's activation is a subsequence of another cheat, the longer cheat can't be activated! DevWarning( "Cheat code \"%s\" has less than %i code elements!", pKey->GetName(), CHEAT_NAME_MAX_LEN ); } } }
void CGECreateServer::PopulateControls( void ) { // Only populate on first load if ( !m_bFirstLoad ) return; // Populate the map list ComboBox *maplist = dynamic_cast<ComboBox*>( FindChildByName("MapList") ); if ( maplist ) { // Clear the list first maplist->DeleteAllItems(); FileFindHandle_t findHandle; // note: FileFINDHandle char file[32]; maplist->AddItem( "#SERVER_RANDOM_MAP", new KeyValues(RANDOM_VALUE) ); const char *pFilename = filesystem->FindFirstEx( "maps\\*.bsp", "MOD", &findHandle ); while ( pFilename ) { if ( stricmp(pFilename, "ge_transition.bsp") ) //They don't need to pick our dinky crash avoidance map. { // Add the map to the list Q_FileBase(pFilename, file, 32); maplist->AddItem(file, new KeyValues(file)); } pFilename = filesystem->FindNext( findHandle ); } filesystem->FindClose( findHandle ); maplist->SetNumberOfEditLines( 10 ); maplist->SetEditable( false ); maplist->GetMenu()->ForceCalculateWidth(); maplist->ActivateItemByRow( 0 ); } // Populate the weapon list ComboBox *weaponlist = dynamic_cast<ComboBox*>( FindChildByName("WeaponList") ); if ( weaponlist ) { weaponlist->DeleteAllItems(); // TAKEN DIRECTLY FROM ge_loadoutmanager.cpp // Parsing individually allows us to overwrite the default sets with custom ones // Multiple custom sets can be defined as needed (can even make sets per gameplay) if ( !GELoadoutParser.HasBeenParsed() ) { GELoadoutParser.InitParser("scripts/loadouts/weapon_sets_default.X"); GELoadoutParser.SetHasBeenParsed( false ); GELoadoutParser.InitParser("scripts/loadouts/weapon_sets_custom*.X"); } // Random loadout weaponlist->AddItem( "#SERVER_RANDOM_SET", new KeyValues("random_loadout") ); FOR_EACH_DICT( m_WeaponSets, idx ) { if (Q_strstr(m_WeaponSets.GetElementName(idx), "_mhide")) continue; int id = weaponlist->AddItem( m_WeaponSets.GetElementName(idx), NULL ); weaponlist->GetMenu()->SetItemEnabled( id, false ); for ( int k=m_WeaponSets[idx]->First(); k != m_WeaponSets[idx]->InvalidIndex(); k = m_WeaponSets[idx]->Next(k) ) weaponlist->AddItem( m_WeaponSets[idx]->Element(k), new KeyValues(m_WeaponSets[idx]->GetElementName(k)) ); } weaponlist->SetEditable( false ); weaponlist->SetNumberOfEditLines( 15 ); weaponlist->GetMenu()->ForceCalculateWidth(); weaponlist->ActivateItemByRow( 0 ); } // Populate the scenario list ComboBox *scenariolist = dynamic_cast<ComboBox*>( FindChildByName("ScenarioList") ); if ( scenariolist ) { // Clear the list first scenariolist->DeleteAllItems(); FileFindHandle_t findHandle; // note: FileFINDHandle char file[32]; scenariolist->AddItem( "#SERVER_RANDOM_SCENARIO", new KeyValues(RANDOM_VALUE) ); const char *pFilename = filesystem->FindFirstEx( PYDIR, "MOD", &findHandle ); while ( pFilename ) { // Add the scenario to the list if not __init__ if ( !Q_stristr( pFilename, "__init__") ) { Q_FileBase( pFilename, file, 32 ); scenariolist->AddItem( file, new KeyValues(file) ); } pFilename = filesystem->FindNext( findHandle ); } filesystem->FindClose( findHandle ); scenariolist->SetEditable( false ); scenariolist->SetNumberOfEditLines( 10 ); scenariolist->GetMenu()->ForceCalculateWidth(); scenariolist->ActivateItemByRow( 0 ); } // Populate the bot difficulty list ComboBox *botdifflist = dynamic_cast<ComboBox*>( FindChildByName("BotLevel") ); if ( botdifflist && botdifflist->GetItemCount() == 0 ) { // Hard coded items (sorry!) botdifflist->AddItem( "#BOT_LEVEL_EASY", new KeyValues("1") ); botdifflist->AddItem( "#BOT_LEVEL_MED", new KeyValues("3") ); botdifflist->AddItem( "#BOT_LEVEL_HARD", new KeyValues("6") ); botdifflist->AddItem( "#BOT_LEVEL_UBER", new KeyValues("9") ); // Admin botdifflist->SetEditable( false ); botdifflist->SetNumberOfEditLines( 4 ); botdifflist->GetMenu()->ForceCalculateWidth(); botdifflist->ActivateItemByRow( 0 ); } // Populate the turbo mode list ComboBox *turbolist = dynamic_cast<ComboBox*>( FindChildByName("TurboMode") ); if ( turbolist && turbolist->GetItemCount() == 0 ) { // Hard coded items (sorry!) turbolist->AddItem( "#TURBO_MODE_NORM", new KeyValues("1.000000") ); turbolist->AddItem( "#TURBO_MODE_FAST", new KeyValues("1.500000") ); turbolist->AddItem( "#TURBO_MODE_LIGHT", new KeyValues("1.850000") ); // Admin turbolist->SetEditable( false ); turbolist->SetNumberOfEditLines( 3 ); turbolist->GetMenu()->ForceCalculateWidth(); turbolist->ActivateItemByRow( 0 ); } // Load the default/saved values from our command map for ( KeyValues *kv = m_kvCmdMap->GetFirstTrueSubKey(); kv; kv = kv->GetNextTrueSubKey() ) { // Get our value (or default) const char *value = (m_kvCmdValues->FindKey( kv->GetName() )) ? m_kvCmdValues->GetString( kv->GetName() ) : NULL; if ( !value ) value = kv->GetString( "default", "" ); if ( !Q_stricmp(kv->GetString("type"), "CHOICE") ) { ComboBox *panel = dynamic_cast<ComboBox*>( FindChildByName(kv->GetName()) ); if ( !panel ) continue; // Search through all our items to find a matching value for ( int i=0; i < panel->GetItemCount(); i++ ) { int id = panel->GetItemIDFromRow( i ); KeyValues* userdata = panel->GetItemUserData( id ); if ( userdata && !Q_stricmp(value, userdata->GetName()) ) { panel->ActivateItem( id ); break; } } } else if ( !Q_stricmp(kv->GetString("type"), "TEXT") ) { TextEntry *panel = dynamic_cast<TextEntry*>( FindChildByName(kv->GetName()) ); if ( !panel ) continue; panel->SetText( value ); } else if ( !Q_stricmp(kv->GetString("type"), "BOOL") ) { CheckButton *panel = dynamic_cast<CheckButton*>( FindChildByName(kv->GetName()) ); if ( !panel ) continue; if ( !Q_stricmp(value, "1") ) panel->SetSelected( true ); else panel->SetSelected( false ); } } m_bFirstLoad = 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 ); }
//============================================================================= void InGameChapterSelect::ApplySchemeSettings(vgui::IScheme *pScheme) { BaseClass::ApplySchemeSettings(pScheme); SetPaintBackgroundEnabled( true ); // Determine current game settings KeyValues *pGameSettings = g_pMatchFramework->GetMatchNetworkMsgController()->GetActiveServerGameDetails( NULL ); KeyValues::AutoDelete autodelete_pGameSettings( pGameSettings ); char const *szGameMode = pGameSettings->GetString( "game/mode", "campaign" ); if ( !GameModeIsSingleChapter( szGameMode ) ) pGameSettings->SetInt( "game/chapter", 1 ); // Get mission and campaign info KeyValues *pInfoMission = NULL; KeyValues *pInfoChapter = g_pMatchExtSwarm->GetMapInfo( pGameSettings, &pInfoMission ); // Check if this is a custom mission? if ( pInfoMission && !pInfoMission->GetBool( "builtin" ) ) pInfoChapter = pInfoMission = NULL; // trigger to use another builtin mission if ( !pInfoMission || !pInfoChapter ) { KeyValues *pAllMissions = g_pMatchExtSwarm->GetAllMissions(); for ( pInfoMission = pAllMissions ? pAllMissions->GetFirstTrueSubKey() : NULL; pInfoMission; pInfoMission = pInfoMission->GetNextTrueSubKey() ) { if ( !pInfoMission->GetBool( "builtin" ) ) continue; pInfoChapter = pInfoMission->FindKey( CFmtStr( "modes/%s/1", szGameMode ) ); if ( pInfoChapter ) break; } } Assert( pInfoMission && pInfoChapter ); // set the dropdowns DropDownMenu *pMissionDropDown = dynamic_cast< DropDownMenu* >( FindChildByName( "DrpMission" ) ); DropDownMenu *pChapterDropDown = dynamic_cast< DropDownMenu* >( FindChildByName( "DrpChapter" ) ); if( pMissionDropDown && pChapterDropDown ) //missions change what the available campaigns are, we should listen on that flyout as well { pMissionDropDown->SetFlyout( CFmtStr( "FlmMission%s", szGameMode ) ); if ( pInfoMission && pInfoChapter ) { pMissionDropDown->SetCurrentSelection( CFmtStr( "cmd_campaign_%s", pInfoMission->GetString( "name" ) ) ); Q_strncpy( m_chCampaign, pInfoMission->GetString( "name" ), ARRAYSIZE( m_chCampaign ) ); // Set this after setting the mission dropdown, as that will default the chapter to the first in the campaign pChapterDropDown->SetCurrentSelection( CFmtStr( "#L4D360UI_Chapter_%d", pInfoChapter->GetInt( "chapter" ) ) ); m_nChapter = pInfoChapter->GetInt( "chapter" ); } FlyoutMenu *flyout = pMissionDropDown->GetCurrentFlyout(); if( flyout ) { flyout->CloseMenu( NULL ); } flyout = pChapterDropDown->GetCurrentFlyout(); if( flyout ) { flyout->CloseMenu( NULL ); } if ( m_ActiveControl ) { m_ActiveControl->NavigateFrom( ); } pMissionDropDown->NavigateTo(); m_ActiveControl = pMissionDropDown; // Chapters are directly selectable only in some game modes pChapterDropDown->SetEnabled( GameModeIsSingleChapter( szGameMode ) ); } SetPaintBackgroundEnabled( true ); SetupAsDialogStyle(); }
void CWeapons::LoadWeapons(const char *szWeaponListName, WeaponsData_t *pDefault) { if ((szWeaponListName != NULL) && (szWeaponListName[0] != 0)) { KeyValues *kv = new KeyValues("Weapons"); char szFilename[1024]; CBotGlobals::BuildFileName(szFilename, "weapons", BOT_CONFIG_FOLDER, "ini", false); if (kv) { if (kv->LoadFromFile(filesystem, szFilename, NULL)) { kv = kv->FindKey(szWeaponListName); if (kv) { kv = kv->GetFirstSubKey(); if (0) kv = kv->GetFirstTrueSubKey(); while (kv != NULL) { WeaponsData_t newWeapon; memset(&newWeapon, 0, sizeof(WeaponsData_t)); const char *szKeyName = kv->GetName(); char lowered[64]; strncpy(lowered, szKeyName, 63); lowered[63] = 0; __strlow(lowered); newWeapon.szWeaponName = CStrings::GetString(lowered); newWeapon.iId = kv->GetInt("id"); newWeapon.iSlot = kv->GetInt("slot"); newWeapon.minPrimDist = kv->GetFloat("minPrimDist"); newWeapon.maxPrimDist = kv->GetFloat("maxPrimDist"); newWeapon.m_fProjSpeed = kv->GetFloat("m_fProjSpeed"); newWeapon.m_iAmmoIndex = kv->GetInt("m_iAmmoIndex"); newWeapon.m_iPreference = kv->GetInt("m_iPreference"); KeyValues *flags = kv->FindKey("flags"); if (flags) { int i = 0; while (szWeaponFlags[i][0] != '\0') { if (flags->FindKey(szWeaponFlags[i]) && (flags->GetInt(szWeaponFlags[i]) == 1)) newWeapon.m_iFlags |= (1 << i); i++; } } AddWeapon(new CWeapon(&newWeapon)); kv = kv->GetNextTrueSubKey(); } } } kv->deleteThis(); } } if (pDefault != NULL) { // No weapons from INI file then add default if (m_theWeapons.size() == 0) { while (pDefault->szWeaponName[0] != '\0') { AddWeapon(new CWeapon(pDefault)); pDefault++; } } } }