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
15 #include "sourcemod.h"
16 #include "HandleSys.h"
17 #include "GameConfigs.h"
19 HandleType_t g_GameConfigsType;
21 class GameConfigsNatives :
22 public IHandleTypeDispatch,
26 void OnSourceModAllInitialized()
28 g_GameConfigsType = g_HandleSys.CreateType("GameConfigs", this, 0, NULL, NULL, g_pCoreIdent, NULL);
30 void OnSourceModShutdown()
32 g_HandleSys.RemoveType(g_GameConfigsType, g_pCoreIdent);
33 g_GameConfigsType = 0;
35 void OnHandleDestroy(HandleType_t type, void *object)
37 g_GameConfigs.CloseGameConfigFile(reinterpret_cast<IGameConfig *>(object));
41 static cell_t smn_LoadGameConfigFile(IPluginContext *pCtx, const cell_t *params)
47 pCtx->LocalToString(params[1], &filename);
48 if (!g_GameConfigs.LoadGameConfigFile(filename, &gc, error, sizeof(error)))
50 return pCtx->ThrowNativeError("Unable to open %s: %s", filename, error);
53 return g_HandleSys.CreateHandle(g_GameConfigsType, gc, pCtx->GetIdentity(), g_pCoreIdent, NULL);
56 static cell_t smn_GameConfGetOffset(IPluginContext *pCtx, const cell_t *params)
58 Handle_t hndl = static_cast<Handle_t>(params[1]);
64 sec.pIdentity = g_pCoreIdent;
66 if ((herr=g_HandleSys.ReadHandle(hndl, g_GameConfigsType, &sec, (void **)&gc))
69 return pCtx->ThrowNativeError("Invalid game config handle %x (error %d)", hndl, herr);
74 pCtx->LocalToString(params[2], &key);
76 if (!gc->GetOffset(key, &val))
84 static cell_t smn_GameConfGetKeyValue(IPluginContext *pCtx, const cell_t *params)
86 Handle_t hndl = static_cast<Handle_t>(params[1]);
92 sec.pIdentity = g_pCoreIdent;
94 if ((herr=g_HandleSys.ReadHandle(hndl, g_GameConfigsType, &sec, (void **)&gc))
97 return pCtx->ThrowNativeError("Invalid game config handle %x (error %d)", hndl, herr);
102 pCtx->LocalToString(params[2], &key);
104 if ((val=gc->GetKeyValue(key)) == NULL)
109 pCtx->StringToLocalUTF8(params[3], params[4], val, NULL);
114 static GameConfigsNatives s_GameConfigsNatives;
116 REGISTER_NATIVES(gameconfignatives)
118 {"LoadGameConfigFile", smn_LoadGameConfigFile},
119 {"GameConfGetOffset", smn_GameConfGetOffset},
120 {"GameConfGetKeyValue", smn_GameConfGetKeyValue},