1.1 --- a/core/smn_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,139 +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 "sourcemod.h"
1.36 -#include "HandleSys.h"
1.37 -#include "GameConfigs.h"
1.38 -
1.39 -HandleType_t g_GameConfigsType;
1.40 -
1.41 -class GameConfigsNatives :
1.42 - public IHandleTypeDispatch,
1.43 - public SourceModBase
1.44 -{
1.45 -public:
1.46 - void OnSourceModAllInitialized()
1.47 - {
1.48 - g_GameConfigsType = g_HandleSys.CreateType("GameConfigs", this, 0, NULL, NULL, g_pCoreIdent, NULL);
1.49 - }
1.50 - void OnSourceModShutdown()
1.51 - {
1.52 - g_HandleSys.RemoveType(g_GameConfigsType, g_pCoreIdent);
1.53 - g_GameConfigsType = 0;
1.54 - }
1.55 - void OnHandleDestroy(HandleType_t type, void *object)
1.56 - {
1.57 - g_GameConfigs.CloseGameConfigFile(reinterpret_cast<IGameConfig *>(object));
1.58 - }
1.59 -};
1.60 -
1.61 -static cell_t smn_LoadGameConfigFile(IPluginContext *pCtx, const cell_t *params)
1.62 -{
1.63 - IGameConfig *gc;
1.64 - char *filename;
1.65 - char error[128];
1.66 -
1.67 - pCtx->LocalToString(params[1], &filename);
1.68 - if (!g_GameConfigs.LoadGameConfigFile(filename, &gc, error, sizeof(error)))
1.69 - {
1.70 - return pCtx->ThrowNativeError("Unable to open %s: %s", filename, error);
1.71 - }
1.72 -
1.73 - return g_HandleSys.CreateHandle(g_GameConfigsType, gc, pCtx->GetIdentity(), g_pCoreIdent, NULL);
1.74 -}
1.75 -
1.76 -static cell_t smn_GameConfGetOffset(IPluginContext *pCtx, const cell_t *params)
1.77 -{
1.78 - Handle_t hndl = static_cast<Handle_t>(params[1]);
1.79 - HandleError herr;
1.80 - HandleSecurity sec;
1.81 - IGameConfig *gc;
1.82 -
1.83 - sec.pOwner = NULL;
1.84 - sec.pIdentity = g_pCoreIdent;
1.85 -
1.86 - if ((herr=g_HandleSys.ReadHandle(hndl, g_GameConfigsType, &sec, (void **)&gc))
1.87 - != HandleError_None)
1.88 - {
1.89 - return pCtx->ThrowNativeError("Invalid game config handle %x (error %d)", hndl, herr);
1.90 - }
1.91 -
1.92 - char *key;
1.93 - int val;
1.94 - pCtx->LocalToString(params[2], &key);
1.95 -
1.96 - if (!gc->GetOffset(key, &val))
1.97 - {
1.98 - return -1;
1.99 - }
1.100 -
1.101 - return val;
1.102 -}
1.103 -
1.104 -static cell_t smn_GameConfGetKeyValue(IPluginContext *pCtx, const cell_t *params)
1.105 -{
1.106 - Handle_t hndl = static_cast<Handle_t>(params[1]);
1.107 - HandleError herr;
1.108 - HandleSecurity sec;
1.109 - IGameConfig *gc;
1.110 -
1.111 - sec.pOwner = NULL;
1.112 - sec.pIdentity = g_pCoreIdent;
1.113 -
1.114 - if ((herr=g_HandleSys.ReadHandle(hndl, g_GameConfigsType, &sec, (void **)&gc))
1.115 - != HandleError_None)
1.116 - {
1.117 - return pCtx->ThrowNativeError("Invalid game config handle %x (error %d)", hndl, herr);
1.118 - }
1.119 -
1.120 - char *key;
1.121 - const char *val;
1.122 - pCtx->LocalToString(params[2], &key);
1.123 -
1.124 - if ((val=gc->GetKeyValue(key)) == NULL)
1.125 - {
1.126 - return 0;
1.127 - }
1.128 -
1.129 - pCtx->StringToLocalUTF8(params[3], params[4], val, NULL);
1.130 -
1.131 - return 1;
1.132 -}
1.133 -
1.134 -static GameConfigsNatives s_GameConfigsNatives;
1.135 -
1.136 -REGISTER_NATIVES(gameconfignatives)
1.137 -{
1.138 - {"LoadGameConfigFile", smn_LoadGameConfigFile},
1.139 - {"GameConfGetOffset", smn_GameConfGetOffset},
1.140 - {"GameConfGetKeyValue", smn_GameConfGetKeyValue},
1.141 - {NULL, NULL}
1.142 -};