fixed inheritance not being used in the base menu style when removing clients from the watch list
3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is not open source and may not be copied without explicit
8 * written permission of AlliedModders LLC. This file may not be redistributed
9 * in whole or significant part.
10 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
17 #include "GameConfigs.h"
18 #include "TextParsers.h"
19 #include "sm_stringutil.h"
20 #include "sourcemod.h"
21 #include "sourcemm_api.h"
22 #include "HalfLife2.h"
26 GameConfigManager g_GameConfigs;
27 IGameConfig *g_pGameConf = NULL;
31 #define PSTATE_GAMES 1
32 #define PSTATE_GAMEDEFS 2
33 #define PSTATE_GAMEDEFS_OFFSETS 3
34 #define PSTATE_GAMEDEFS_OFFSETS_OFFSET 4
35 #define PSTATE_GAMEDEFS_KEYS 5
37 #if defined PLATFORM_WINDOWS
38 #define PLATFORM_NAME "windows"
39 #elif defined PLATFORM_LINUX
40 #define PLATFORM_NAME "linux"
43 CGameConfig::CGameConfig(const char *file)
45 m_pFile = sm_strdup(file);
46 m_pOffsets = sm_trie_create();
47 m_pProps = sm_trie_create();
48 m_pKeys = sm_trie_create();
49 m_pStrings = new BaseStringTable(512);
53 CGameConfig::~CGameConfig()
55 sm_trie_destroy(m_pOffsets);
56 sm_trie_destroy(m_pProps);
57 sm_trie_destroy(m_pKeys);
62 SMCParseResult CGameConfig::ReadSMC_NewSection(const char *name, bool opt_quotes)
67 return SMCParse_Continue;
73 if (strcmp(name, "Games") == 0)
75 m_ParseState = PSTATE_GAMES;
83 if ((strcmp(name, "*") == 0)
84 || (strcmp(name, g_mod) == 0))
86 m_ParseState = PSTATE_GAMEDEFS;
87 strncopy(m_mod, name, sizeof(m_mod));
95 if (strcmp(name, "Offsets") == 0)
97 m_ParseState = PSTATE_GAMEDEFS_OFFSETS;
98 } else if (strcmp(name, "Keys") == 0) {
99 m_ParseState = PSTATE_GAMEDEFS_KEYS;
105 case PSTATE_GAMEDEFS_OFFSETS:
109 strncopy(m_offset, name, sizeof(m_offset));
110 m_ParseState = PSTATE_GAMEDEFS_OFFSETS_OFFSET;
113 /* No sub-sections allowed:
114 case PSTATE_GAMEDEFS_OFFSETS_OFFSET:
115 case PSTATE_GAMEDEFS_KEYS:
119 /* If we don't know what we got, start ignoring */
125 return SMCParse_Continue;
128 SMCParseResult CGameConfig::ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes)
132 return SMCParse_Continue;
135 if (m_ParseState == PSTATE_GAMEDEFS_OFFSETS_OFFSET)
137 if (strcmp(key, "class") == 0)
139 strncopy(m_class, value, sizeof(m_class));
140 } else if (strcmp(key, "prop") == 0) {
141 strncopy(m_prop, value, sizeof(m_prop));
142 } else if (strcmp(key, PLATFORM_NAME) == 0) {
143 int val = atoi(value);
144 sm_trie_insert(m_pOffsets, m_offset, (void *)val);
146 } else if (m_ParseState == PSTATE_GAMEDEFS_KEYS) {
147 int id = m_pStrings->AddString(value);
148 sm_trie_insert(m_pKeys, key, (void *)id);
151 return SMCParse_Continue;
154 SMCParseResult CGameConfig::ReadSMC_LeavingSection()
159 return SMCParse_Continue;
162 switch (m_ParseState)
166 m_ParseState = PSTATE_NONE;
169 case PSTATE_GAMEDEFS:
171 m_ParseState = PSTATE_GAMES;
174 case PSTATE_GAMEDEFS_KEYS:
175 case PSTATE_GAMEDEFS_OFFSETS:
177 m_ParseState = PSTATE_GAMEDEFS;
180 case PSTATE_GAMEDEFS_OFFSETS_OFFSET:
182 /* Parse the offset... */
183 if (m_class[0] != '\0'
184 && m_prop[0] != '\0')
186 SendProp *pProp = g_HL2.FindInSendTable(m_class, m_prop);
189 int val = pProp->GetOffset();
190 sm_trie_insert(m_pOffsets, m_offset, (void *)val);
191 sm_trie_insert(m_pProps, m_offset, pProp);
193 /* Check if it's a non-default game and no offsets exist */
194 if ((strcmp(m_mod, "*") != 0)
195 && (!sm_trie_retrieve(m_pOffsets, m_offset, NULL)))
197 g_Logger.LogError("[SM] Unable to find property %s.%s (file \"%s\") (mod \"%s\")",
205 m_ParseState = PSTATE_GAMEDEFS_OFFSETS;
210 return SMCParse_Continue;
213 bool CGameConfig::Reparse(char *error, size_t maxlength)
217 char path[PLATFORM_MAX_PATH];
218 g_SourceMod.BuildPath(Path_SM, path, sizeof(path), "configs/gamedata/%s.txt", m_pFile);
220 /* Initialize parse states */
222 m_ParseState = PSTATE_NONE;
223 /* Reset cached data */
225 sm_trie_clear(m_pOffsets);
226 sm_trie_clear(m_pProps);
227 sm_trie_clear(m_pKeys);
229 if ((err=g_TextParser.ParseFile_SMC(path, this, NULL, NULL))
232 if (error && (err != SMCParse_Custom))
234 const char *str = g_TextParser.GetSMCErrorString(err);
235 snprintf(error, maxlength, "%s", str);
243 bool CGameConfig::GetOffset(const char *key, int *value)
247 if (!sm_trie_retrieve(m_pOffsets, key, &obj))
257 const char *CGameConfig::GetKeyValue(const char *key)
260 if (!sm_trie_retrieve(m_pKeys, key, &obj))
264 return m_pStrings->GetString((int)obj);
267 SendProp *CGameConfig::GetSendProp(const char *key)
271 if (!sm_trie_retrieve(m_pProps, key, (void **)&pProp))
279 void CGameConfig::IncRefCount()
284 unsigned int CGameConfig::DecRefCount()
290 GameConfigManager::GameConfigManager()
292 m_pLookup = sm_trie_create();
295 GameConfigManager::~GameConfigManager()
297 sm_trie_destroy(m_pLookup);
300 void GameConfigManager::OnSourceModStartup(bool late)
302 LoadGameConfigFile("core.games", &g_pGameConf, NULL, 0);
304 strncopy(g_mod, g_SourceMod.GetGameFolderName(), sizeof(g_mod));
307 void GameConfigManager::OnSourceModAllInitialized()
309 /* NOW initialize the game file */
310 CGameConfig *pGameConf = (CGameConfig *)g_pGameConf;
313 if (!pGameConf->Reparse(error, sizeof(error)))
318 g_ShareSys.AddInterface(NULL, this);
321 void GameConfigManager::OnSourceModAllShutdown()
323 CloseGameConfigFile(g_pGameConf);
326 bool GameConfigManager::LoadGameConfigFile(const char *file, IGameConfig **_pConfig, char *error, size_t maxlength)
328 CGameConfig *pConfig;
330 if (sm_trie_retrieve(m_pLookup, file, (void **)&pConfig))
332 pConfig->IncRefCount();
337 pConfig = new CGameConfig(file);
339 /* :HACKHACK: Don't parse the main config file */
341 if (_pConfig != &g_pGameConf)
343 retval = pConfig->Reparse(error, maxlength);
346 m_cfgs.push_back(pConfig);
347 sm_trie_insert(m_pLookup, file, pConfig);
349 pConfig->IncRefCount();
356 void GameConfigManager::CloseGameConfigFile(IGameConfig *cfg)
358 CGameConfig *pConfig = (CGameConfig *)cfg;
360 if (pConfig->DecRefCount() == 0)