core/GameConfigs.cpp
author David Anderson <dvander@alliedmods.net>
Sun Aug 26 17:41:02 2007 +0000 (2007-08-26)
changeset 1369 bd9ccced1b1a
parent 1330 ab94316bb52b
child 1406 f5c07ec3c052
permissions -rw-r--r--
fixed amb834 - command callbacks could potentially occur on invalid clients in very rare cases
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or modify it under
     9  * the terms of the GNU General Public License, version 3.0, as published by the
    10  * Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful, but WITHOUT
    13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    15  * details.
    16  *
    17  * You should have received a copy of the GNU General Public License along with
    18  * this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to link the
    21  * code of this program (as well as its derivative works) to "Half-Life 2," the
    22  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    23  * by the Valve Corporation.  You must obey the GNU General Public License in
    24  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    25  * this exception to all derivative works.  AlliedModders LLC defines further
    26  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    27  * or <http://www.sourcemod.net/license.php>.
    28  *
    29  * Version: $Id$
    30  */
    31 
    32 #include <string.h>
    33 #include <stdlib.h>
    34 #include "GameConfigs.h"
    35 #include "TextParsers.h"
    36 #include "sm_stringutil.h"
    37 #include "sourcemod.h"
    38 #include "sourcemm_api.h"
    39 #include "HalfLife2.h"
    40 #include "Logger.h"
    41 #include "ShareSys.h"
    42 #include "MemoryUtils.h"
    43 #include "LibrarySys.h"
    44 #include "HandleSys.h"
    45 #include "sm_crc32.h"
    46 
    47 #if defined PLATFORM_LINUX
    48 #include <dlfcn.h>
    49 #endif
    50 
    51 GameConfigManager g_GameConfigs;
    52 IGameConfig *g_pGameConf = NULL;
    53 char g_Game[256];
    54 char g_GameDesc[256] = {'!', '\0'};
    55 
    56 #define PSTATE_NONE						0
    57 #define PSTATE_GAMES					1
    58 #define PSTATE_GAMEDEFS					2
    59 #define PSTATE_GAMEDEFS_OFFSETS			3
    60 #define PSTATE_GAMEDEFS_OFFSETS_OFFSET	4
    61 #define PSTATE_GAMEDEFS_KEYS			5
    62 #define PSTATE_GAMEDEFS_SUPPORTED		6
    63 #define PSTATE_GAMEDEFS_SIGNATURES		7
    64 #define PSTATE_GAMEDEFS_SIGNATURES_SIG	8
    65 #define PSTATE_GAMEDEFS_CRC				9
    66 #define PSTATE_GAMEDEFS_CRC_BINARY		10
    67 
    68 #if defined PLATFORM_WINDOWS
    69 #define PLATFORM_NAME				"windows"
    70 #define PLATFORM_SERVER_BINARY		"server.dll"
    71 #elif defined PLATFORM_LINUX
    72 #define PLATFORM_NAME				"linux"
    73 #define PLATFORM_SERVER_BINARY		"server_i486.so"
    74 #endif
    75 
    76 struct TempSigInfo
    77 {
    78 	void Reset()
    79 	{
    80 		library[0] = '\0';
    81 		sig[0] = '\0';
    82 	}
    83 	char sig[512];
    84 	char library[64];
    85 } s_TempSig;
    86 unsigned int s_ServerBinCRC;
    87 bool s_ServerBinCRC_Ok = false;
    88 
    89 CGameConfig::CGameConfig(const char *file)
    90 {
    91 	m_pFile = sm_strdup(file);
    92 	m_pOffsets = sm_trie_create();
    93 	m_pProps = sm_trie_create();
    94 	m_pKeys = sm_trie_create();
    95 	m_pSigs = sm_trie_create();
    96 	m_pStrings = new BaseStringTable(512);
    97 	m_RefCount = 0;
    98 }
    99 
   100 CGameConfig::~CGameConfig()
   101 {
   102 	sm_trie_destroy(m_pOffsets);
   103 	sm_trie_destroy(m_pProps);
   104 	sm_trie_destroy(m_pKeys);
   105 	sm_trie_destroy(m_pSigs);
   106 	delete [] m_pFile;
   107 	delete m_pStrings;
   108 }
   109 
   110 SMCParseResult CGameConfig::ReadSMC_NewSection(const char *name, bool opt_quotes)
   111 {
   112 	if (m_IgnoreLevel)
   113 	{
   114 		m_IgnoreLevel++;
   115 		return SMCParse_Continue;
   116 	}
   117 
   118 	switch (m_ParseState)
   119 	{
   120 	case PSTATE_NONE:
   121 		{
   122 			if (strcmp(name, "Games") == 0)
   123 			{
   124 				m_ParseState = PSTATE_GAMES;
   125 			} else {
   126 				m_IgnoreLevel++;
   127 			}
   128 			break;
   129 		}
   130 	case PSTATE_GAMES:
   131 		{
   132 			if ((strcmp(name, "*") == 0)
   133 				|| (strcmp(name, "#default") == 0)
   134 				|| (strcasecmp(name, g_Game) == 0)
   135 				|| (strcasecmp(name, g_GameDesc) == 0))
   136 			{
   137 				bShouldBeReadingDefault = true;
   138 				m_ParseState = PSTATE_GAMEDEFS;
   139 				strncopy(m_Game, name, sizeof(m_Game));
   140 			} else {
   141 				m_IgnoreLevel++;
   142 			}
   143 			break;
   144 		}
   145 	case PSTATE_GAMEDEFS:
   146 		{
   147 			if (strcmp(name, "Offsets") == 0)
   148 			{
   149 				m_ParseState = PSTATE_GAMEDEFS_OFFSETS;
   150 			}
   151 			else if (strcmp(name, "Keys") == 0)
   152 			{
   153 				m_ParseState = PSTATE_GAMEDEFS_KEYS;
   154 			}
   155 			else if ((strcmp(name, "#supported") == 0)
   156 					 && (strcmp(m_Game, "#default") == 0))
   157 			{
   158 				m_ParseState = PSTATE_GAMEDEFS_SUPPORTED;
   159 				/* Ignore this section unless we get a game. */
   160 				bShouldBeReadingDefault = false;
   161 			}
   162 			else if (strcmp(name, "Signatures") == 0)
   163 			{
   164 				m_ParseState = PSTATE_GAMEDEFS_SIGNATURES;
   165 			}
   166 			else if (strcmp(name, "CRC") == 0)
   167 			{
   168 				m_ParseState = PSTATE_GAMEDEFS_CRC;
   169 				bShouldBeReadingDefault = false;
   170 			}
   171 			else
   172 			{
   173 				m_IgnoreLevel++;
   174 			}
   175 			break;
   176 		}
   177 	case PSTATE_GAMEDEFS_OFFSETS:
   178 		{
   179 			m_Prop[0] = '\0';
   180 			m_Class[0] = '\0';
   181 			strncopy(m_offset, name, sizeof(m_offset));
   182 			m_ParseState = PSTATE_GAMEDEFS_OFFSETS_OFFSET;
   183 			break;
   184 		}
   185 	case PSTATE_GAMEDEFS_SIGNATURES:
   186 		{
   187 			strncopy(m_offset, name, sizeof(m_offset));
   188 			s_TempSig.Reset();
   189 			m_ParseState = PSTATE_GAMEDEFS_SIGNATURES_SIG;
   190 			break;
   191 		}
   192 	case PSTATE_GAMEDEFS_CRC:
   193 		{
   194 			char error[255];
   195 			error[0] = '\0';
   196 			if (strcmp(name, "server") != 0)
   197 			{
   198 				UTIL_Format(error, sizeof(error), "Unrecognized library \"%s\"", name);
   199 			} 
   200 			else if (!s_ServerBinCRC_Ok)
   201 			{
   202 				FILE *fp;
   203 				char path[PLATFORM_MAX_PATH];
   204 
   205 				g_SourceMod.BuildPath(Path_Game, path, sizeof(path), "bin/" PLATFORM_SERVER_BINARY);
   206 				if ((fp = fopen(path, "rb")) == NULL)
   207 				{
   208 					UTIL_Format(error, sizeof(error), "Could not open binary: %s", path);
   209 				} else {
   210 					size_t size;
   211 					void *buffer;
   212 
   213 					fseek(fp, 0, SEEK_END);
   214 					size = ftell(fp);
   215 					fseek(fp, 0, SEEK_SET);
   216 
   217 					buffer = malloc(size);
   218 					fread(buffer, size, 1, fp);
   219 					s_ServerBinCRC = UTIL_CRC32(buffer, size);
   220 					free(buffer);
   221 					s_ServerBinCRC_Ok = true;
   222 				}
   223 			}
   224 			if (error[0] != '\0')
   225 			{
   226 				m_IgnoreLevel = 1;
   227 				g_Logger.LogError("[SM] Error while parsing CRC section for \"%s\" (%s):", m_Game, m_pFile);
   228 				g_Logger.LogError("[SM] %s", error);
   229 			} else {
   230 				m_ParseState = PSTATE_GAMEDEFS_CRC_BINARY;
   231 			}
   232 			break;
   233 		}
   234 	/* No sub-sections allowed:
   235 	 case PSTATE_GAMEDEFS_OFFSETS_OFFSET:
   236 	 case PSTATE_GAMEDEFS_KEYS:
   237 	 case PSTATE_GAMEDEFS_SUPPORTED:
   238 	 case PSTATE_GAMEDEFS_SIGNATURES_SIG:
   239 	 case PSTATE_GAMEDEFS_CRC_BINARY:
   240 	 */
   241 	default:
   242 		{
   243 			/* If we don't know what we got, start ignoring */
   244 			m_IgnoreLevel++;
   245 			break;
   246 		}
   247 	}
   248 
   249 	return SMCParse_Continue;
   250 }
   251 
   252 SMCParseResult CGameConfig::ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes)
   253 {
   254 	if (m_IgnoreLevel)
   255 	{
   256 		return SMCParse_Continue;
   257 	}
   258 
   259 	if (m_ParseState == PSTATE_GAMEDEFS_OFFSETS_OFFSET)
   260 	{
   261 		if (strcmp(key, "class") == 0)
   262 		{
   263 			strncopy(m_Class, value, sizeof(m_Class));
   264 		} else if (strcmp(key, "prop") == 0) {
   265 			strncopy(m_Prop, value, sizeof(m_Prop));
   266 		} else if (strcmp(key, PLATFORM_NAME) == 0) {
   267 			int val = atoi(value);
   268 			sm_trie_replace(m_pOffsets, m_offset, (void *)val);
   269 		}
   270 	} else if (m_ParseState == PSTATE_GAMEDEFS_KEYS) {
   271 		int id = m_pStrings->AddString(value);
   272 		sm_trie_replace(m_pKeys, key, (void *)id);
   273 	} else if (m_ParseState == PSTATE_GAMEDEFS_SUPPORTED) {
   274 		if (strcmp(key, "game") == 0
   275 			&& (strcasecmp(value, g_Game) == 0 || strcasecmp(value, g_GameDesc) == 0))
   276 		{
   277 			bShouldBeReadingDefault = true;
   278 		}
   279 	} else if (m_ParseState == PSTATE_GAMEDEFS_SIGNATURES_SIG) {
   280 		if (strcmp(key, PLATFORM_NAME) == 0)
   281 		{
   282 			strncopy(s_TempSig.sig, value, sizeof(s_TempSig.sig));
   283 		} else if (strcmp(key, "library") == 0) {
   284 			strncopy(s_TempSig.library, value, sizeof(s_TempSig.library));
   285 		}
   286 	} else if (m_ParseState == PSTATE_GAMEDEFS_CRC_BINARY) {
   287 		if (strcmp(key, PLATFORM_NAME) == 0 
   288 			&& s_ServerBinCRC_Ok
   289 			&& !bShouldBeReadingDefault)
   290 		{
   291 			unsigned int crc = 0;
   292 			sscanf(value, "%08X", &crc);
   293 			if (s_ServerBinCRC == crc)
   294 			{
   295 				bShouldBeReadingDefault = true;
   296 			}
   297 		}
   298 	}
   299 
   300 	return SMCParse_Continue;
   301 }
   302 
   303 SMCParseResult CGameConfig::ReadSMC_LeavingSection()
   304 {
   305 	if (m_IgnoreLevel)
   306 	{
   307 		m_IgnoreLevel--;
   308 		return SMCParse_Continue;
   309 	}
   310 
   311 	switch (m_ParseState)
   312 	{
   313 	case PSTATE_GAMES:
   314 		{
   315 			m_ParseState = PSTATE_NONE;
   316 			break;
   317 		}
   318 	case PSTATE_GAMEDEFS:
   319 		{
   320 			m_ParseState = PSTATE_GAMES;
   321 			break;
   322 		}
   323 	case PSTATE_GAMEDEFS_KEYS:
   324 	case PSTATE_GAMEDEFS_OFFSETS:
   325 		{
   326 			m_ParseState = PSTATE_GAMEDEFS;
   327 			break;
   328 		}
   329 	case PSTATE_GAMEDEFS_OFFSETS_OFFSET:
   330 		{
   331 			/* Parse the offset... */
   332 			if (m_Class[0] != '\0'
   333 				&& m_Prop[0] != '\0')
   334 			{
   335 				SendProp *pProp = g_HL2.FindInSendTable(m_Class, m_Prop);
   336 				if (pProp)
   337 				{
   338 					int val = pProp->GetOffset();
   339 					sm_trie_replace(m_pOffsets, m_offset, (void *)val);
   340 					sm_trie_replace(m_pProps, m_offset, pProp);
   341 				} else {
   342 					/* Check if it's a non-default game and no offsets exist */
   343 					if (((strcmp(m_Game, "*") != 0) && strcmp(m_Game, "#default") != 0)
   344 						&& (!sm_trie_retrieve(m_pOffsets, m_offset, NULL)))
   345 					{
   346 						g_Logger.LogError("[SM] Unable to find property %s.%s (file \"%s\") (mod \"%s\")", 
   347 							m_Class,
   348 							m_Prop,
   349 							m_pFile,
   350 							m_Game);
   351 					}
   352 				}
   353 			}
   354 			m_ParseState = PSTATE_GAMEDEFS_OFFSETS;
   355 			break;
   356 		}
   357 	case PSTATE_GAMEDEFS_CRC:
   358 	case PSTATE_GAMEDEFS_SUPPORTED:
   359 		{
   360 			if (!bShouldBeReadingDefault)
   361 			{
   362 				/* If we shouldn't read the rest of this section, set the ignore level. */
   363 				m_IgnoreLevel = 1;
   364 				m_ParseState = PSTATE_GAMES;
   365 			} else {
   366 				m_ParseState = PSTATE_GAMEDEFS;
   367 			}
   368 			break;
   369 		}
   370 	case PSTATE_GAMEDEFS_CRC_BINARY:
   371 		{
   372 			m_ParseState = PSTATE_GAMEDEFS_CRC;
   373 			break;
   374 		}
   375 	case PSTATE_GAMEDEFS_SIGNATURES:
   376 		{
   377 			m_ParseState = PSTATE_GAMEDEFS;
   378 			break;
   379 		}
   380 	case PSTATE_GAMEDEFS_SIGNATURES_SIG:
   381 		{
   382 			if (s_TempSig.library[0] == '\0')
   383 			{
   384 				/* assume server */
   385 				strncopy(s_TempSig.library, "server", sizeof(s_TempSig.library));
   386 			}
   387 			void *addrInBase = NULL;
   388 			if (strcmp(s_TempSig.library, "server") == 0)
   389 			{
   390 				addrInBase = (void *)g_SMAPI->serverFactory(false);
   391 			} else if (strcmp(s_TempSig.library, "engine") == 0) {
   392 				addrInBase = (void *)g_SMAPI->engineFactory(false);
   393 			}
   394 			void *final_addr = NULL;
   395 			if (addrInBase == NULL)
   396 			{
   397 				g_Logger.LogError("[SM] Unrecognized library \"%s\" (gameconf \"%s\")", 
   398 					s_TempSig.library, 
   399 					m_pFile);
   400 			} else {
   401 #if defined PLATFORM_LINUX
   402 				if (s_TempSig.sig[0] == '@')
   403 				{
   404 					Dl_info info;
   405 					/* GNU only: returns 0 on error, inconsistent! >:[ */
   406 					if (dladdr(addrInBase, &info) != 0)
   407 					{
   408 						void *handle = dlopen(info.dli_fname, RTLD_NOW);
   409 						if (handle)
   410 						{
   411 							final_addr = dlsym(handle, &s_TempSig.sig[1]);
   412 							dlclose(handle);
   413 						} else {
   414 							g_Logger.LogError("[SM] Unable to load library \"%s\" (gameconf \"%s\")",
   415 								s_TempSig.library,
   416 								m_pFile);
   417 						}
   418 					} else {
   419 						g_Logger.LogError("[SM] Unable to find library \"%s\" in memory (gameconf \"%s\")",
   420 							s_TempSig.library,
   421 							m_pFile);
   422 					}
   423 				}
   424 				if (final_addr)
   425 				{
   426 					goto skip_find;
   427 				}
   428 #endif
   429 				/* First, preprocess the signature */
   430 				char real_sig[255];
   431 				size_t real_bytes;
   432 				size_t length;
   433 
   434 				real_bytes = 0;
   435 				length = strlen(s_TempSig.sig);
   436 
   437 				for (size_t i=0; i<length; i++)
   438 				{
   439 					if (real_bytes >= sizeof(real_sig))
   440 					{
   441 						break;
   442 					}
   443 					real_sig[real_bytes++] = s_TempSig.sig[i];
   444 					if (s_TempSig.sig[i] == '\\'
   445 						&& s_TempSig.sig[i+1] == 'x')
   446 					{
   447 						if (i + 3 >= length)
   448 						{
   449 							continue;
   450 						}
   451 						/* Get the hex part */
   452 						char s_byte[3];
   453 						int r_byte;
   454 						s_byte[0] = s_TempSig.sig[i+2];
   455 						s_byte[1] = s_TempSig.sig[i+3];
   456 						s_byte[2] = '\0';
   457 						/* Read it as an integer */
   458 						sscanf(s_byte, "%x", &r_byte);
   459 						/* Save the value */
   460 						real_sig[real_bytes-1] = r_byte;
   461 						/* Adjust index */
   462 						i += 3;
   463 					}
   464 				}
   465 
   466 				if (real_bytes >= 1)
   467 				{
   468 					final_addr = g_MemUtils.FindPattern(addrInBase, real_sig, real_bytes);
   469 				}
   470 			}
   471 
   472 #if defined PLATFORM_LINUX
   473 skip_find:
   474 #endif
   475 			sm_trie_replace(m_pSigs, m_offset, final_addr);
   476 			m_ParseState = PSTATE_GAMEDEFS_SIGNATURES;
   477 
   478 			break;
   479 		}
   480 	}
   481 
   482 	return SMCParse_Continue;
   483 }
   484 
   485 bool CGameConfig::Reparse(char *error, size_t maxlength)
   486 {
   487 	SMCParseError err;
   488 
   489 	char path[PLATFORM_MAX_PATH];
   490 	g_SourceMod.BuildPath(Path_SM, path, sizeof(path), "gamedata/%s.txt", m_pFile);
   491 	/* Backwards compatibility */
   492 	if (!g_LibSys.PathExists(path))
   493 	{
   494 		g_SourceMod.BuildPath(Path_SM, path, sizeof(path), "configs/gamedata/%s.txt", m_pFile);
   495 	}
   496 
   497 	/* Initialize parse states */
   498 	m_IgnoreLevel = 0;
   499 	bShouldBeReadingDefault = true;
   500 	m_ParseState = PSTATE_NONE;
   501 	/* Reset cached data */
   502 	m_pStrings->Reset();
   503 	sm_trie_clear(m_pOffsets);
   504 	sm_trie_clear(m_pProps);
   505 	sm_trie_clear(m_pKeys);
   506 
   507 	if ((err=g_TextParser.ParseFile_SMC(path, this, NULL, NULL))
   508 		!= SMCParse_Okay)
   509 	{
   510 		if (error && (err != SMCParse_Custom))
   511 		{
   512 			const char *str = g_TextParser.GetSMCErrorString(err);
   513 			snprintf(error, maxlength, "%s", str);
   514 		}
   515 		return false;
   516 	}
   517 
   518 	return true;
   519 }
   520 
   521 bool CGameConfig::GetOffset(const char *key, int *value)
   522 {
   523 	void *obj;
   524 
   525 	if (!sm_trie_retrieve(m_pOffsets, key, &obj))
   526 	{
   527 		return false;
   528 	}
   529 
   530 	*value = (int)obj;
   531 	
   532 	return true;
   533 }
   534 
   535 const char *CGameConfig::GetKeyValue(const char *key)
   536 {
   537 	void *obj;
   538 	if (!sm_trie_retrieve(m_pKeys, key, &obj))
   539 	{
   540 		return NULL;
   541 	}
   542 	return m_pStrings->GetString((int)obj);
   543 }
   544 
   545 SendProp *CGameConfig::GetSendProp(const char *key)
   546 {
   547 	SendProp *pProp;
   548 
   549 	if (!sm_trie_retrieve(m_pProps, key, (void **)&pProp))
   550 	{
   551 		return NULL;
   552 	}
   553 
   554 	return pProp;
   555 }
   556 
   557 bool CGameConfig::GetMemSig(const char *key, void **addr)
   558 {
   559 	return sm_trie_retrieve(m_pSigs, key, addr);
   560 }
   561 
   562 void CGameConfig::IncRefCount()
   563 {
   564 	m_RefCount++;
   565 }
   566 
   567 unsigned int CGameConfig::DecRefCount()
   568 {
   569 	m_RefCount--;
   570 	return m_RefCount;
   571 }
   572 
   573 GameConfigManager::GameConfigManager()
   574 {
   575 	m_pLookup = sm_trie_create();
   576 }
   577 
   578 GameConfigManager::~GameConfigManager()
   579 {
   580 	sm_trie_destroy(m_pLookup);
   581 }
   582 
   583 void GameConfigManager::OnSourceModStartup(bool late)
   584 {
   585 	LoadGameConfigFile("core.games", &g_pGameConf, NULL, 0);
   586 
   587 	strncopy(g_Game, g_SourceMod.GetGameFolderName(), sizeof(g_Game));
   588 	strncopy(g_GameDesc + 1, SERVER_CALL(GetGameDescription)(), sizeof(g_GameDesc) - 1);
   589 }
   590 
   591 void GameConfigManager::OnSourceModAllInitialized()
   592 {
   593 	/* NOW initialize the game file */
   594 	CGameConfig *pGameConf = (CGameConfig *)g_pGameConf;
   595 	
   596 	char error[255];
   597 	if (!pGameConf->Reparse(error, sizeof(error)))
   598 	{
   599 		/* :TODO: log */
   600 	}
   601 
   602 	g_ShareSys.AddInterface(NULL, this);
   603 }
   604 
   605 void GameConfigManager::OnSourceModAllShutdown()
   606 {
   607 	CloseGameConfigFile(g_pGameConf);
   608 }
   609 
   610 bool GameConfigManager::LoadGameConfigFile(const char *file, IGameConfig **_pConfig, char *error, size_t maxlength)
   611 {
   612 	CGameConfig *pConfig;
   613 
   614 	if (sm_trie_retrieve(m_pLookup, file, (void **)&pConfig))
   615 	{
   616 		pConfig->IncRefCount();
   617 		*_pConfig = pConfig;
   618 		return true;
   619 	}
   620 
   621 	pConfig = new CGameConfig(file);
   622 
   623 	/* :HACKHACK: Don't parse the main config file */
   624 	bool retval = true;
   625 	if (_pConfig != &g_pGameConf)
   626 	{
   627 		retval = pConfig->Reparse(error, maxlength);
   628 	}
   629 
   630 	m_cfgs.push_back(pConfig);
   631 	sm_trie_insert(m_pLookup, file, pConfig);
   632 
   633 	pConfig->IncRefCount();
   634 
   635 	*_pConfig = pConfig;
   636 
   637 	return retval;
   638 }
   639 
   640 void GameConfigManager::CloseGameConfigFile(IGameConfig *cfg)
   641 {
   642 	CGameConfig *pConfig = (CGameConfig *)cfg;
   643 
   644 	if (pConfig->DecRefCount() == 0)
   645 	{
   646 		sm_trie_delete(m_pLookup, pConfig->m_pFile);
   647 		delete pConfig;
   648 	}
   649 }
   650 
   651 extern HandleType_t g_GameConfigsType;
   652 
   653 IGameConfig *GameConfigManager::ReadHandle(Handle_t hndl, IdentityToken_t *ident, HandleError *err)
   654 {
   655 	HandleSecurity sec(ident, g_pCoreIdent);
   656 	IGameConfig *conf = NULL;
   657 	HandleError _err = g_HandleSys.ReadHandle(hndl, g_GameConfigsType, &sec, (void **)&conf);
   658 
   659 	if (err)
   660 	{
   661 		*err = _err;
   662 	}
   663 
   664 	return conf;
   665 }