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