core/GameConfigs.cpp
branchsourcemod-1.1.0
changeset 2283 03a67e41afbc
parent 1951 c7b4237fff50
child 2287 017a725c9d17
     1.1 --- a/core/GameConfigs.cpp	Fri Mar 28 06:21:34 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,664 +0,0 @@
     1.4 -/**
     1.5 - * vim: set ts=4 :
     1.6 - * =============================================================================
     1.7 - * SourceMod
     1.8 - * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
     1.9 - * =============================================================================
    1.10 - *
    1.11 - * This program is free software; you can redistribute it and/or modify it under
    1.12 - * the terms of the GNU General Public License, version 3.0, as published by the
    1.13 - * Free Software Foundation.
    1.14 - * 
    1.15 - * This program is distributed in the hope that it will be useful, but WITHOUT
    1.16 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.17 - * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.18 - * details.
    1.19 - *
    1.20 - * You should have received a copy of the GNU General Public License along with
    1.21 - * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.22 - *
    1.23 - * As a special exception, AlliedModders LLC gives you permission to link the
    1.24 - * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.25 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.26 - * by the Valve Corporation.  You must obey the GNU General Public License in
    1.27 - * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.28 - * this exception to all derivative works.  AlliedModders LLC defines further
    1.29 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.30 - * or <http://www.sourcemod.net/license.php>.
    1.31 - *
    1.32 - * Version: $Id$
    1.33 - */
    1.34 -
    1.35 -#include <string.h>
    1.36 -#include <stdlib.h>
    1.37 -#include "GameConfigs.h"
    1.38 -#include "sm_stringutil.h"
    1.39 -#include "sourcemod.h"
    1.40 -#include "sourcemm_api.h"
    1.41 -#include "HalfLife2.h"
    1.42 -#include "Logger.h"
    1.43 -#include "ShareSys.h"
    1.44 -#include "MemoryUtils.h"
    1.45 -#include "LibrarySys.h"
    1.46 -#include "HandleSys.h"
    1.47 -#include "sm_crc32.h"
    1.48 -
    1.49 -#if defined PLATFORM_LINUX
    1.50 -#include <dlfcn.h>
    1.51 -#endif
    1.52 -
    1.53 -GameConfigManager g_GameConfigs;
    1.54 -IGameConfig *g_pGameConf = NULL;
    1.55 -char g_Game[256];
    1.56 -char g_GameDesc[256] = {'!', '\0'};
    1.57 -
    1.58 -#define PSTATE_NONE						0
    1.59 -#define PSTATE_GAMES					1
    1.60 -#define PSTATE_GAMEDEFS					2
    1.61 -#define PSTATE_GAMEDEFS_OFFSETS			3
    1.62 -#define PSTATE_GAMEDEFS_OFFSETS_OFFSET	4
    1.63 -#define PSTATE_GAMEDEFS_KEYS			5
    1.64 -#define PSTATE_GAMEDEFS_SUPPORTED		6
    1.65 -#define PSTATE_GAMEDEFS_SIGNATURES		7
    1.66 -#define PSTATE_GAMEDEFS_SIGNATURES_SIG	8
    1.67 -#define PSTATE_GAMEDEFS_CRC				9
    1.68 -#define PSTATE_GAMEDEFS_CRC_BINARY		10
    1.69 -
    1.70 -#if defined PLATFORM_WINDOWS
    1.71 -#define PLATFORM_NAME				"windows"
    1.72 -#define PLATFORM_SERVER_BINARY		"server.dll"
    1.73 -#elif defined PLATFORM_LINUX
    1.74 -#define PLATFORM_NAME				"linux"
    1.75 -#define PLATFORM_SERVER_BINARY		"server_i486.so"
    1.76 -#endif
    1.77 -
    1.78 -struct TempSigInfo
    1.79 -{
    1.80 -	void Reset()
    1.81 -	{
    1.82 -		library[0] = '\0';
    1.83 -		sig[0] = '\0';
    1.84 -	}
    1.85 -	char sig[512];
    1.86 -	char library[64];
    1.87 -} s_TempSig;
    1.88 -unsigned int s_ServerBinCRC;
    1.89 -bool s_ServerBinCRC_Ok = false;
    1.90 -
    1.91 -CGameConfig::CGameConfig(const char *file)
    1.92 -{
    1.93 -	m_pFile = sm_strdup(file);
    1.94 -	m_pOffsets = sm_trie_create();
    1.95 -	m_pProps = sm_trie_create();
    1.96 -	m_pKeys = sm_trie_create();
    1.97 -	m_pSigs = sm_trie_create();
    1.98 -	m_pStrings = new BaseStringTable(512);
    1.99 -	m_RefCount = 0;
   1.100 -}
   1.101 -
   1.102 -CGameConfig::~CGameConfig()
   1.103 -{
   1.104 -	sm_trie_destroy(m_pOffsets);
   1.105 -	sm_trie_destroy(m_pProps);
   1.106 -	sm_trie_destroy(m_pKeys);
   1.107 -	sm_trie_destroy(m_pSigs);
   1.108 -	delete [] m_pFile;
   1.109 -	delete m_pStrings;
   1.110 -}
   1.111 -
   1.112 -SMCResult CGameConfig::ReadSMC_NewSection(const SMCStates *states, const char *name)
   1.113 -{
   1.114 -	if (m_IgnoreLevel)
   1.115 -	{
   1.116 -		m_IgnoreLevel++;
   1.117 -		return SMCResult_Continue;
   1.118 -	}
   1.119 -
   1.120 -	switch (m_ParseState)
   1.121 -	{
   1.122 -	case PSTATE_NONE:
   1.123 -		{
   1.124 -			if (strcmp(name, "Games") == 0)
   1.125 -			{
   1.126 -				m_ParseState = PSTATE_GAMES;
   1.127 -			} else {
   1.128 -				m_IgnoreLevel++;
   1.129 -			}
   1.130 -			break;
   1.131 -		}
   1.132 -	case PSTATE_GAMES:
   1.133 -		{
   1.134 -			if ((strcmp(name, "*") == 0)
   1.135 -				|| (strcmp(name, "#default") == 0)
   1.136 -				|| (strcasecmp(name, g_Game) == 0)
   1.137 -				|| (strcasecmp(name, g_GameDesc) == 0))
   1.138 -			{
   1.139 -				bShouldBeReadingDefault = true;
   1.140 -				m_ParseState = PSTATE_GAMEDEFS;
   1.141 -				strncopy(m_Game, name, sizeof(m_Game));
   1.142 -			} else {
   1.143 -				m_IgnoreLevel++;
   1.144 -			}
   1.145 -			break;
   1.146 -		}
   1.147 -	case PSTATE_GAMEDEFS:
   1.148 -		{
   1.149 -			if (strcmp(name, "Offsets") == 0)
   1.150 -			{
   1.151 -				m_ParseState = PSTATE_GAMEDEFS_OFFSETS;
   1.152 -			}
   1.153 -			else if (strcmp(name, "Keys") == 0)
   1.154 -			{
   1.155 -				m_ParseState = PSTATE_GAMEDEFS_KEYS;
   1.156 -			}
   1.157 -			else if ((strcmp(name, "#supported") == 0)
   1.158 -					 && (strcmp(m_Game, "#default") == 0))
   1.159 -			{
   1.160 -				m_ParseState = PSTATE_GAMEDEFS_SUPPORTED;
   1.161 -				/* Ignore this section unless we get a game. */
   1.162 -				bShouldBeReadingDefault = false;
   1.163 -			}
   1.164 -			else if (strcmp(name, "Signatures") == 0)
   1.165 -			{
   1.166 -				m_ParseState = PSTATE_GAMEDEFS_SIGNATURES;
   1.167 -			}
   1.168 -			else if (strcmp(name, "CRC") == 0)
   1.169 -			{
   1.170 -				m_ParseState = PSTATE_GAMEDEFS_CRC;
   1.171 -				bShouldBeReadingDefault = false;
   1.172 -			}
   1.173 -			else
   1.174 -			{
   1.175 -				m_IgnoreLevel++;
   1.176 -			}
   1.177 -			break;
   1.178 -		}
   1.179 -	case PSTATE_GAMEDEFS_OFFSETS:
   1.180 -		{
   1.181 -			m_Prop[0] = '\0';
   1.182 -			m_Class[0] = '\0';
   1.183 -			strncopy(m_offset, name, sizeof(m_offset));
   1.184 -			m_ParseState = PSTATE_GAMEDEFS_OFFSETS_OFFSET;
   1.185 -			break;
   1.186 -		}
   1.187 -	case PSTATE_GAMEDEFS_SIGNATURES:
   1.188 -		{
   1.189 -			strncopy(m_offset, name, sizeof(m_offset));
   1.190 -			s_TempSig.Reset();
   1.191 -			m_ParseState = PSTATE_GAMEDEFS_SIGNATURES_SIG;
   1.192 -			break;
   1.193 -		}
   1.194 -	case PSTATE_GAMEDEFS_CRC:
   1.195 -		{
   1.196 -			char error[255];
   1.197 -			error[0] = '\0';
   1.198 -			if (strcmp(name, "server") != 0)
   1.199 -			{
   1.200 -				UTIL_Format(error, sizeof(error), "Unrecognized library \"%s\"", name);
   1.201 -			} 
   1.202 -			else if (!s_ServerBinCRC_Ok)
   1.203 -			{
   1.204 -				FILE *fp;
   1.205 -				char path[PLATFORM_MAX_PATH];
   1.206 -
   1.207 -				g_SourceMod.BuildPath(Path_Game, path, sizeof(path), "bin/" PLATFORM_SERVER_BINARY);
   1.208 -				if ((fp = fopen(path, "rb")) == NULL)
   1.209 -				{
   1.210 -					UTIL_Format(error, sizeof(error), "Could not open binary: %s", path);
   1.211 -				} else {
   1.212 -					size_t size;
   1.213 -					void *buffer;
   1.214 -
   1.215 -					fseek(fp, 0, SEEK_END);
   1.216 -					size = ftell(fp);
   1.217 -					fseek(fp, 0, SEEK_SET);
   1.218 -
   1.219 -					buffer = malloc(size);
   1.220 -					fread(buffer, size, 1, fp);
   1.221 -					s_ServerBinCRC = UTIL_CRC32(buffer, size);
   1.222 -					free(buffer);
   1.223 -					s_ServerBinCRC_Ok = true;
   1.224 -				}
   1.225 -			}
   1.226 -			if (error[0] != '\0')
   1.227 -			{
   1.228 -				m_IgnoreLevel = 1;
   1.229 -				g_Logger.LogError("[SM] Error while parsing CRC section for \"%s\" (%s):", m_Game, m_pFile);
   1.230 -				g_Logger.LogError("[SM] %s", error);
   1.231 -			} else {
   1.232 -				m_ParseState = PSTATE_GAMEDEFS_CRC_BINARY;
   1.233 -			}
   1.234 -			break;
   1.235 -		}
   1.236 -	/* No sub-sections allowed:
   1.237 -	 case PSTATE_GAMEDEFS_OFFSETS_OFFSET:
   1.238 -	 case PSTATE_GAMEDEFS_KEYS:
   1.239 -	 case PSTATE_GAMEDEFS_SUPPORTED:
   1.240 -	 case PSTATE_GAMEDEFS_SIGNATURES_SIG:
   1.241 -	 case PSTATE_GAMEDEFS_CRC_BINARY:
   1.242 -	 */
   1.243 -	default:
   1.244 -		{
   1.245 -			/* If we don't know what we got, start ignoring */
   1.246 -			m_IgnoreLevel++;
   1.247 -			break;
   1.248 -		}
   1.249 -	}
   1.250 -
   1.251 -	return SMCResult_Continue;
   1.252 -}
   1.253 -
   1.254 -SMCResult CGameConfig::ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value)
   1.255 -{
   1.256 -	if (m_IgnoreLevel)
   1.257 -	{
   1.258 -		return SMCResult_Continue;
   1.259 -	}
   1.260 -
   1.261 -	if (m_ParseState == PSTATE_GAMEDEFS_OFFSETS_OFFSET)
   1.262 -	{
   1.263 -		if (strcmp(key, "class") == 0)
   1.264 -		{
   1.265 -			strncopy(m_Class, value, sizeof(m_Class));
   1.266 -		} else if (strcmp(key, "prop") == 0) {
   1.267 -			strncopy(m_Prop, value, sizeof(m_Prop));
   1.268 -		} else if (strcmp(key, PLATFORM_NAME) == 0) {
   1.269 -			int val = atoi(value);
   1.270 -			sm_trie_replace(m_pOffsets, m_offset, (void *)val);
   1.271 -		}
   1.272 -	} else if (m_ParseState == PSTATE_GAMEDEFS_KEYS) {
   1.273 -		int id = m_pStrings->AddString(value);
   1.274 -		sm_trie_replace(m_pKeys, key, (void *)id);
   1.275 -	} else if (m_ParseState == PSTATE_GAMEDEFS_SUPPORTED) {
   1.276 -		if (strcmp(key, "game") == 0
   1.277 -			&& (strcasecmp(value, g_Game) == 0 || strcasecmp(value, g_GameDesc) == 0))
   1.278 -		{
   1.279 -			bShouldBeReadingDefault = true;
   1.280 -		}
   1.281 -	} else if (m_ParseState == PSTATE_GAMEDEFS_SIGNATURES_SIG) {
   1.282 -		if (strcmp(key, PLATFORM_NAME) == 0)
   1.283 -		{
   1.284 -			strncopy(s_TempSig.sig, value, sizeof(s_TempSig.sig));
   1.285 -		} else if (strcmp(key, "library") == 0) {
   1.286 -			strncopy(s_TempSig.library, value, sizeof(s_TempSig.library));
   1.287 -		}
   1.288 -	} else if (m_ParseState == PSTATE_GAMEDEFS_CRC_BINARY) {
   1.289 -		if (strcmp(key, PLATFORM_NAME) == 0 
   1.290 -			&& s_ServerBinCRC_Ok
   1.291 -			&& !bShouldBeReadingDefault)
   1.292 -		{
   1.293 -			unsigned int crc = 0;
   1.294 -			sscanf(value, "%08X", &crc);
   1.295 -			if (s_ServerBinCRC == crc)
   1.296 -			{
   1.297 -				bShouldBeReadingDefault = true;
   1.298 -			}
   1.299 -		}
   1.300 -	}
   1.301 -
   1.302 -	return SMCResult_Continue;
   1.303 -}
   1.304 -
   1.305 -SMCResult CGameConfig::ReadSMC_LeavingSection(const SMCStates *states)
   1.306 -{
   1.307 -	if (m_IgnoreLevel)
   1.308 -	{
   1.309 -		m_IgnoreLevel--;
   1.310 -		return SMCResult_Continue;
   1.311 -	}
   1.312 -
   1.313 -	switch (m_ParseState)
   1.314 -	{
   1.315 -	case PSTATE_GAMES:
   1.316 -		{
   1.317 -			m_ParseState = PSTATE_NONE;
   1.318 -			break;
   1.319 -		}
   1.320 -	case PSTATE_GAMEDEFS:
   1.321 -		{
   1.322 -			m_ParseState = PSTATE_GAMES;
   1.323 -			break;
   1.324 -		}
   1.325 -	case PSTATE_GAMEDEFS_KEYS:
   1.326 -	case PSTATE_GAMEDEFS_OFFSETS:
   1.327 -		{
   1.328 -			m_ParseState = PSTATE_GAMEDEFS;
   1.329 -			break;
   1.330 -		}
   1.331 -	case PSTATE_GAMEDEFS_OFFSETS_OFFSET:
   1.332 -		{
   1.333 -			/* Parse the offset... */
   1.334 -			if (m_Class[0] != '\0'
   1.335 -				&& m_Prop[0] != '\0')
   1.336 -			{
   1.337 -				SendProp *pProp = g_HL2.FindInSendTable(m_Class, m_Prop);
   1.338 -				if (pProp)
   1.339 -				{
   1.340 -					int val = pProp->GetOffset();
   1.341 -					sm_trie_replace(m_pOffsets, m_offset, (void *)val);
   1.342 -					sm_trie_replace(m_pProps, m_offset, pProp);
   1.343 -				} else {
   1.344 -					/* Check if it's a non-default game and no offsets exist */
   1.345 -					if (((strcmp(m_Game, "*") != 0) && strcmp(m_Game, "#default") != 0)
   1.346 -						&& (!sm_trie_retrieve(m_pOffsets, m_offset, NULL)))
   1.347 -					{
   1.348 -						g_Logger.LogError("[SM] Unable to find property %s.%s (file \"%s\") (mod \"%s\")", 
   1.349 -							m_Class,
   1.350 -							m_Prop,
   1.351 -							m_pFile,
   1.352 -							m_Game);
   1.353 -					}
   1.354 -				}
   1.355 -			}
   1.356 -			m_ParseState = PSTATE_GAMEDEFS_OFFSETS;
   1.357 -			break;
   1.358 -		}
   1.359 -	case PSTATE_GAMEDEFS_CRC:
   1.360 -	case PSTATE_GAMEDEFS_SUPPORTED:
   1.361 -		{
   1.362 -			if (!bShouldBeReadingDefault)
   1.363 -			{
   1.364 -				/* If we shouldn't read the rest of this section, set the ignore level. */
   1.365 -				m_IgnoreLevel = 1;
   1.366 -				m_ParseState = PSTATE_GAMES;
   1.367 -			} else {
   1.368 -				m_ParseState = PSTATE_GAMEDEFS;
   1.369 -			}
   1.370 -			break;
   1.371 -		}
   1.372 -	case PSTATE_GAMEDEFS_CRC_BINARY:
   1.373 -		{
   1.374 -			m_ParseState = PSTATE_GAMEDEFS_CRC;
   1.375 -			break;
   1.376 -		}
   1.377 -	case PSTATE_GAMEDEFS_SIGNATURES:
   1.378 -		{
   1.379 -			m_ParseState = PSTATE_GAMEDEFS;
   1.380 -			break;
   1.381 -		}
   1.382 -	case PSTATE_GAMEDEFS_SIGNATURES_SIG:
   1.383 -		{
   1.384 -			if (s_TempSig.library[0] == '\0')
   1.385 -			{
   1.386 -				/* assume server */
   1.387 -				strncopy(s_TempSig.library, "server", sizeof(s_TempSig.library));
   1.388 -			}
   1.389 -			void *addrInBase = NULL;
   1.390 -			if (strcmp(s_TempSig.library, "server") == 0)
   1.391 -			{
   1.392 -				addrInBase = (void *)g_SMAPI->GetServerFactory(false);
   1.393 -			} else if (strcmp(s_TempSig.library, "engine") == 0) {
   1.394 -				addrInBase = (void *)g_SMAPI->GetEngineFactory(false);
   1.395 -			}
   1.396 -			void *final_addr = NULL;
   1.397 -			if (addrInBase == NULL)
   1.398 -			{
   1.399 -				g_Logger.LogError("[SM] Unrecognized library \"%s\" (gameconf \"%s\")", 
   1.400 -					s_TempSig.library, 
   1.401 -					m_pFile);
   1.402 -			} else {
   1.403 -#if defined PLATFORM_LINUX
   1.404 -				if (s_TempSig.sig[0] == '@')
   1.405 -				{
   1.406 -					Dl_info info;
   1.407 -					/* GNU only: returns 0 on error, inconsistent! >:[ */
   1.408 -					if (dladdr(addrInBase, &info) != 0)
   1.409 -					{
   1.410 -						void *handle = dlopen(info.dli_fname, RTLD_NOW);
   1.411 -						if (handle)
   1.412 -						{
   1.413 -							final_addr = dlsym(handle, &s_TempSig.sig[1]);
   1.414 -							dlclose(handle);
   1.415 -						} else {
   1.416 -							g_Logger.LogError("[SM] Unable to load library \"%s\" (gameconf \"%s\")",
   1.417 -								s_TempSig.library,
   1.418 -								m_pFile);
   1.419 -						}
   1.420 -					} else {
   1.421 -						g_Logger.LogError("[SM] Unable to find library \"%s\" in memory (gameconf \"%s\")",
   1.422 -							s_TempSig.library,
   1.423 -							m_pFile);
   1.424 -					}
   1.425 -				}
   1.426 -				if (final_addr)
   1.427 -				{
   1.428 -					goto skip_find;
   1.429 -				}
   1.430 -#endif
   1.431 -				/* First, preprocess the signature */
   1.432 -				char real_sig[255];
   1.433 -				size_t real_bytes;
   1.434 -				size_t length;
   1.435 -
   1.436 -				real_bytes = 0;
   1.437 -				length = strlen(s_TempSig.sig);
   1.438 -
   1.439 -				for (size_t i=0; i<length; i++)
   1.440 -				{
   1.441 -					if (real_bytes >= sizeof(real_sig))
   1.442 -					{
   1.443 -						break;
   1.444 -					}
   1.445 -					real_sig[real_bytes++] = s_TempSig.sig[i];
   1.446 -					if (s_TempSig.sig[i] == '\\'
   1.447 -						&& s_TempSig.sig[i+1] == 'x')
   1.448 -					{
   1.449 -						if (i + 3 >= length)
   1.450 -						{
   1.451 -							continue;
   1.452 -						}
   1.453 -						/* Get the hex part */
   1.454 -						char s_byte[3];
   1.455 -						int r_byte;
   1.456 -						s_byte[0] = s_TempSig.sig[i+2];
   1.457 -						s_byte[1] = s_TempSig.sig[i+3];
   1.458 -						s_byte[2] = '\0';
   1.459 -						/* Read it as an integer */
   1.460 -						sscanf(s_byte, "%x", &r_byte);
   1.461 -						/* Save the value */
   1.462 -						real_sig[real_bytes-1] = r_byte;
   1.463 -						/* Adjust index */
   1.464 -						i += 3;
   1.465 -					}
   1.466 -				}
   1.467 -
   1.468 -				if (real_bytes >= 1)
   1.469 -				{
   1.470 -					final_addr = g_MemUtils.FindPattern(addrInBase, real_sig, real_bytes);
   1.471 -				}
   1.472 -			}
   1.473 -
   1.474 -#if defined PLATFORM_LINUX
   1.475 -skip_find:
   1.476 -#endif
   1.477 -			sm_trie_replace(m_pSigs, m_offset, final_addr);
   1.478 -			m_ParseState = PSTATE_GAMEDEFS_SIGNATURES;
   1.479 -
   1.480 -			break;
   1.481 -		}
   1.482 -	}
   1.483 -
   1.484 -	return SMCResult_Continue;
   1.485 -}
   1.486 -
   1.487 -bool CGameConfig::Reparse(char *error, size_t maxlength)
   1.488 -{
   1.489 -	SMCError err;
   1.490 -
   1.491 -	char path[PLATFORM_MAX_PATH];
   1.492 -	g_SourceMod.BuildPath(Path_SM, path, sizeof(path), "gamedata/%s.txt", m_pFile);
   1.493 -	/* Backwards compatibility */
   1.494 -	if (!g_LibSys.PathExists(path))
   1.495 -	{
   1.496 -		g_SourceMod.BuildPath(Path_SM, path, sizeof(path), "configs/gamedata/%s.txt", m_pFile);
   1.497 -	}
   1.498 -
   1.499 -	/* Initialize parse states */
   1.500 -	m_IgnoreLevel = 0;
   1.501 -	bShouldBeReadingDefault = true;
   1.502 -	m_ParseState = PSTATE_NONE;
   1.503 -	/* Reset cached data */
   1.504 -	m_pStrings->Reset();
   1.505 -	sm_trie_clear(m_pOffsets);
   1.506 -	sm_trie_clear(m_pProps);
   1.507 -	sm_trie_clear(m_pKeys);
   1.508 -
   1.509 -	if ((err=textparsers->ParseFile_SMC(path, this, NULL))
   1.510 -		!= SMCError_Okay)
   1.511 -	{
   1.512 -		if (error && (err != SMCError_Custom))
   1.513 -		{
   1.514 -			const char *str = textparsers->GetSMCErrorString(err);
   1.515 -			snprintf(error, maxlength, "%s", str);
   1.516 -		}
   1.517 -		return false;
   1.518 -	}
   1.519 -
   1.520 -	return true;
   1.521 -}
   1.522 -
   1.523 -bool CGameConfig::GetOffset(const char *key, int *value)
   1.524 -{
   1.525 -	void *obj;
   1.526 -
   1.527 -	if (!sm_trie_retrieve(m_pOffsets, key, &obj))
   1.528 -	{
   1.529 -		return false;
   1.530 -	}
   1.531 -
   1.532 -	*value = (int)obj;
   1.533 -	
   1.534 -	return true;
   1.535 -}
   1.536 -
   1.537 -const char *CGameConfig::GetKeyValue(const char *key)
   1.538 -{
   1.539 -	void *obj;
   1.540 -	if (!sm_trie_retrieve(m_pKeys, key, &obj))
   1.541 -	{
   1.542 -		return NULL;
   1.543 -	}
   1.544 -	return m_pStrings->GetString((int)obj);
   1.545 -}
   1.546 -
   1.547 -SendProp *CGameConfig::GetSendProp(const char *key)
   1.548 -{
   1.549 -	SendProp *pProp;
   1.550 -
   1.551 -	if (!sm_trie_retrieve(m_pProps, key, (void **)&pProp))
   1.552 -	{
   1.553 -		return NULL;
   1.554 -	}
   1.555 -
   1.556 -	return pProp;
   1.557 -}
   1.558 -
   1.559 -bool CGameConfig::GetMemSig(const char *key, void **addr)
   1.560 -{
   1.561 -	return sm_trie_retrieve(m_pSigs, key, addr);
   1.562 -}
   1.563 -
   1.564 -void CGameConfig::IncRefCount()
   1.565 -{
   1.566 -	m_RefCount++;
   1.567 -}
   1.568 -
   1.569 -unsigned int CGameConfig::DecRefCount()
   1.570 -{
   1.571 -	m_RefCount--;
   1.572 -	return m_RefCount;
   1.573 -}
   1.574 -
   1.575 -GameConfigManager::GameConfigManager()
   1.576 -{
   1.577 -	m_pLookup = sm_trie_create();
   1.578 -}
   1.579 -
   1.580 -GameConfigManager::~GameConfigManager()
   1.581 -{
   1.582 -	sm_trie_destroy(m_pLookup);
   1.583 -}
   1.584 -
   1.585 -void GameConfigManager::OnSourceModStartup(bool late)
   1.586 -{
   1.587 -	LoadGameConfigFile("core.games", &g_pGameConf, NULL, 0);
   1.588 -
   1.589 -	strncopy(g_Game, g_SourceMod.GetGameFolderName(), sizeof(g_Game));
   1.590 -	strncopy(g_GameDesc + 1, SERVER_CALL(GetGameDescription)(), sizeof(g_GameDesc) - 1);
   1.591 -}
   1.592 -
   1.593 -void GameConfigManager::OnSourceModAllInitialized()
   1.594 -{
   1.595 -	/* NOW initialize the game file */
   1.596 -	CGameConfig *pGameConf = (CGameConfig *)g_pGameConf;
   1.597 -	
   1.598 -	char error[255];
   1.599 -	if (!pGameConf->Reparse(error, sizeof(error)))
   1.600 -	{
   1.601 -		/* :TODO: log */
   1.602 -	}
   1.603 -
   1.604 -	g_ShareSys.AddInterface(NULL, this);
   1.605 -}
   1.606 -
   1.607 -void GameConfigManager::OnSourceModAllShutdown()
   1.608 -{
   1.609 -	CloseGameConfigFile(g_pGameConf);
   1.610 -}
   1.611 -
   1.612 -bool GameConfigManager::LoadGameConfigFile(const char *file, IGameConfig **_pConfig, char *error, size_t maxlength)
   1.613 -{
   1.614 -	CGameConfig *pConfig;
   1.615 -
   1.616 -	if (sm_trie_retrieve(m_pLookup, file, (void **)&pConfig))
   1.617 -	{
   1.618 -		pConfig->IncRefCount();
   1.619 -		*_pConfig = pConfig;
   1.620 -		return true;
   1.621 -	}
   1.622 -
   1.623 -	pConfig = new CGameConfig(file);
   1.624 -
   1.625 -	/* :HACKHACK: Don't parse the main config file */
   1.626 -	bool retval = true;
   1.627 -	if (_pConfig != &g_pGameConf)
   1.628 -	{
   1.629 -		retval = pConfig->Reparse(error, maxlength);
   1.630 -	}
   1.631 -
   1.632 -	m_cfgs.push_back(pConfig);
   1.633 -	sm_trie_insert(m_pLookup, file, pConfig);
   1.634 -
   1.635 -	pConfig->IncRefCount();
   1.636 -
   1.637 -	*_pConfig = pConfig;
   1.638 -
   1.639 -	return retval;
   1.640 -}
   1.641 -
   1.642 -void GameConfigManager::CloseGameConfigFile(IGameConfig *cfg)
   1.643 -{
   1.644 -	CGameConfig *pConfig = (CGameConfig *)cfg;
   1.645 -
   1.646 -	if (pConfig->DecRefCount() == 0)
   1.647 -	{
   1.648 -		sm_trie_delete(m_pLookup, pConfig->m_pFile);
   1.649 -		delete pConfig;
   1.650 -	}
   1.651 -}
   1.652 -
   1.653 -extern HandleType_t g_GameConfigsType;
   1.654 -
   1.655 -IGameConfig *GameConfigManager::ReadHandle(Handle_t hndl, IdentityToken_t *ident, HandleError *err)
   1.656 -{
   1.657 -	HandleSecurity sec(ident, g_pCoreIdent);
   1.658 -	IGameConfig *conf = NULL;
   1.659 -	HandleError _err = g_HandleSys.ReadHandle(hndl, g_GameConfigsType, &sec, (void **)&conf);
   1.660 -
   1.661 -	if (err)
   1.662 -	{
   1.663 -		*err = _err;
   1.664 -	}
   1.665 -
   1.666 -	return conf;
   1.667 -}