added game config file natives
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40709
This commit is contained in:
@@ -761,6 +761,10 @@
|
||||
RelativePath="..\smn_functions.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\smn_gameconfigs.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\smn_halflife.cpp"
|
||||
>
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
* vim: set ts=4 :
|
||||
* ===============================================================
|
||||
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
|
||||
* ===============================================================
|
||||
*
|
||||
* This file is not open source and may not be copied without explicit
|
||||
* written permission of AlliedModders LLC. This file may not be redistributed
|
||||
* in whole or significant part.
|
||||
* For information, see LICENSE.txt or http://www.sourcemod.net/license.php
|
||||
*
|
||||
* Version: $Id$
|
||||
*/
|
||||
|
||||
#include "sourcemod.h"
|
||||
#include "HandleSys.h"
|
||||
#include "GameConfigs.h"
|
||||
|
||||
HandleType_t g_GameConfigsType;
|
||||
|
||||
class GameConfigsNatives :
|
||||
public IHandleTypeDispatch,
|
||||
public SourceModBase
|
||||
{
|
||||
public:
|
||||
void OnSourceModAllInitialized()
|
||||
{
|
||||
g_GameConfigsType = g_HandleSys.CreateType("GameConfigs", this, 0, NULL, NULL, g_pCoreIdent, NULL);
|
||||
}
|
||||
void OnSourceModShutdown()
|
||||
{
|
||||
g_HandleSys.RemoveType(g_GameConfigsType, g_pCoreIdent);
|
||||
g_GameConfigsType = 0;
|
||||
}
|
||||
void OnHandleDestroy(HandleType_t type, void *object)
|
||||
{
|
||||
g_GameConfigs.CloseGameConfigFile(reinterpret_cast<IGameConfig *>(object));
|
||||
}
|
||||
};
|
||||
|
||||
static cell_t smn_LoadGameConfigFile(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
IGameConfig *gc;
|
||||
char *filename;
|
||||
char error[128];
|
||||
|
||||
pCtx->LocalToString(params[1], &filename);
|
||||
if (!g_GameConfigs.LoadGameConfigFile(filename, &gc, error, sizeof(error)))
|
||||
{
|
||||
return pCtx->ThrowNativeError("Unable to open %s: %s", filename, error);
|
||||
}
|
||||
|
||||
return g_HandleSys.CreateHandle(g_GameConfigsType, gc, pCtx->GetIdentity(), g_pCoreIdent, NULL);
|
||||
}
|
||||
|
||||
static cell_t smn_GameConfGetOffset(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
||||
HandleError herr;
|
||||
HandleSecurity sec;
|
||||
IGameConfig *gc;
|
||||
|
||||
sec.pOwner = NULL;
|
||||
sec.pIdentity = g_pCoreIdent;
|
||||
|
||||
if ((herr=g_HandleSys.ReadHandle(hndl, g_GameConfigsType, &sec, (void **)&gc))
|
||||
!= HandleError_None)
|
||||
{
|
||||
return pCtx->ThrowNativeError("Invalid game config handle %x (error %d)", hndl, herr);
|
||||
}
|
||||
|
||||
char *key;
|
||||
int val;
|
||||
pCtx->LocalToString(params[2], &key);
|
||||
|
||||
if (!gc->GetOffset(key, &val))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static cell_t smn_GameConfGetKeyValue(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
||||
HandleError herr;
|
||||
HandleSecurity sec;
|
||||
IGameConfig *gc;
|
||||
|
||||
sec.pOwner = NULL;
|
||||
sec.pIdentity = g_pCoreIdent;
|
||||
|
||||
if ((herr=g_HandleSys.ReadHandle(hndl, g_GameConfigsType, &sec, (void **)&gc))
|
||||
!= HandleError_None)
|
||||
{
|
||||
return pCtx->ThrowNativeError("Invalid game config handle %x (error %d)", hndl, herr);
|
||||
}
|
||||
|
||||
char *key;
|
||||
const char *val;
|
||||
pCtx->LocalToString(params[2], &key);
|
||||
|
||||
if ((val=gc->GetKeyValue(key)) == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
pCtx->StringToLocalUTF8(params[3], params[4], val, NULL);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static GameConfigsNatives s_GameConfigsNatives;
|
||||
|
||||
REGISTER_NATIVES(gameconfignatives)
|
||||
{
|
||||
{"LoadGameConfigFile", smn_LoadGameConfigFile},
|
||||
{"GameConfGetOffset", smn_GameConfGetOffset},
|
||||
{"GameConfGetKeyValue", smn_GameConfGetKeyValue},
|
||||
{NULL, NULL}
|
||||
};
|
||||
@@ -26,7 +26,7 @@ struct KeyValueStack
|
||||
CStack<KeyValues *> pCurRoot;
|
||||
};
|
||||
|
||||
class KeyValuekNatives :
|
||||
class KeyValueNatives :
|
||||
public SMGlobalClass,
|
||||
public IHandleTypeDispatch
|
||||
{
|
||||
@@ -636,7 +636,7 @@ static cell_t smn_KvSetEscapeSequences(IPluginContext *pCtx, const cell_t *param
|
||||
return 1;
|
||||
}
|
||||
|
||||
static KeyValuekNatives s_KeyValuekNatives;
|
||||
static KeyValueNatives s_KeyValueNatives;
|
||||
|
||||
REGISTER_NATIVES(keyvaluenatives)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user