core/smn_keyvalues.cpp
author Borja Ferrer <faluco@alliedmods.net>
Fri Sep 28 20:13:42 2007 +0000 (2007-09-28)
changeset 1499 e55ac4555a2b
parent 1401 e3b761515c0a
child 1707 05af94444cc8
child 1715 f9ecab642e25
permissions -rw-r--r--
synced linux build
faluco@654
     1
/**
faluco@654
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
dvander@1231
     4
 * SourceMod
dvander@1231
     5
 * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
ds@1330
     6
 * =============================================================================
faluco@654
     7
 *
ds@1330
     8
 * This program is free software; you can redistribute it and/or modify it under
ds@1330
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330
    10
 * Free Software Foundation.
dvander@1231
    11
 * 
ds@1330
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1330
    15
 * details.
dvander@1231
    16
 *
ds@1330
    17
 * You should have received a copy of the GNU General Public License along with
ds@1330
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
dvander@1231
    19
 *
ds@1330
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1330
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1330
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1330
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330
    27
 * or <http://www.sourcemod.net/license.php>.
faluco@654
    28
 *
faluco@654
    29
 * Version: $Id$
faluco@654
    30
 */
faluco@654
    31
faluco@654
    32
#include "sourcemod.h"
faluco@654
    33
#include "sourcemm_api.h"
faluco@654
    34
#include "sm_stringutil.h"
faluco@654
    35
#include "HandleSys.h"
faluco@654
    36
#include <KeyValues.h>
faluco@654
    37
faluco@654
    38
HandleType_t g_KeyValueType;
faluco@654
    39
faluco@654
    40
struct KeyValueStack 
faluco@654
    41
{
faluco@654
    42
	KeyValues *pBase;
faluco@654
    43
	CStack<KeyValues *> pCurRoot;
faluco@654
    44
};
faluco@654
    45
faluco@703
    46
class KeyValueNatives : 
faluco@654
    47
	public SMGlobalClass,
faluco@654
    48
	public IHandleTypeDispatch
faluco@654
    49
{
faluco@654
    50
public:
faluco@654
    51
	void OnSourceModAllInitialized()
faluco@654
    52
	{
faluco@654
    53
		g_KeyValueType = g_HandleSys.CreateType("KeyValues", this, 0, NULL, NULL, g_pCoreIdent, NULL);
faluco@654
    54
	}
faluco@654
    55
	void OnSourceModShutdown()
faluco@654
    56
	{
faluco@654
    57
		g_HandleSys.RemoveType(g_KeyValueType, g_pCoreIdent);
faluco@654
    58
		g_KeyValueType = 0;
faluco@654
    59
	}
faluco@654
    60
	void OnHandleDestroy(HandleType_t type, void *object)
faluco@654
    61
	{
faluco@654
    62
		KeyValueStack *pStk = reinterpret_cast<KeyValueStack *>(object);
faluco@654
    63
		pStk->pBase->deleteThis();
faluco@654
    64
		delete pStk;
faluco@654
    65
	}
faluco@654
    66
};
faluco@654
    67
faluco@682
    68
KeyValues *SourceModBase::ReadKeyValuesHandle(Handle_t hndl, HandleError *err, bool root)
faluco@682
    69
{
faluco@682
    70
	HandleError herr;
faluco@682
    71
	HandleSecurity sec;
faluco@682
    72
	KeyValueStack *pStk;
faluco@682
    73
faluco@682
    74
	sec.pOwner = NULL;
faluco@682
    75
	sec.pIdentity = g_pCoreIdent;
faluco@682
    76
faluco@682
    77
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
faluco@682
    78
		!= HandleError_None)
faluco@682
    79
	{
faluco@682
    80
		if (err)
faluco@682
    81
		{
faluco@682
    82
			*err = herr;
faluco@682
    83
		}
faluco@682
    84
		return NULL;
faluco@682
    85
	}
faluco@682
    86
faluco@682
    87
	if (err)
faluco@682
    88
	{
faluco@682
    89
		*err = HandleError_None;
faluco@682
    90
	}
faluco@682
    91
faluco@682
    92
	return (root) ? pStk->pBase : pStk->pCurRoot.front();
faluco@682
    93
}
faluco@682
    94
faluco@654
    95
static cell_t smn_KvSetString(IPluginContext *pCtx, const cell_t *params)
faluco@654
    96
{
faluco@654
    97
	Handle_t hndl = static_cast<Handle_t>(params[1]);
faluco@654
    98
	HandleError herr;
faluco@654
    99
	HandleSecurity sec;
faluco@654
   100
	KeyValueStack *pStk;
faluco@654
   101
faluco@654
   102
	sec.pOwner = NULL;
faluco@654
   103
	sec.pIdentity = g_pCoreIdent;
faluco@654
   104
faluco@654
   105
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
faluco@654
   106
		!= HandleError_None)
faluco@654
   107
	{
faluco@654
   108
		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
faluco@654
   109
	}
faluco@654
   110
faluco@654
   111
	char *key, *value;
dvander@1000
   112
	pCtx->LocalToStringNULL(params[2], &key);
faluco@654
   113
	pCtx->LocalToString(params[3], &value);
faluco@654
   114
faluco@654
   115
	pStk->pCurRoot.front()->SetString(key, value);
faluco@654
   116
faluco@654
   117
	return 1;
faluco@654
   118
}
faluco@654
   119
faluco@654
   120
static cell_t smn_KvSetNum(IPluginContext *pCtx, const cell_t *params)
faluco@654
   121
{
faluco@654
   122
	Handle_t hndl = static_cast<Handle_t>(params[1]);
faluco@654
   123
	HandleError herr;
faluco@654
   124
	HandleSecurity sec;
faluco@654
   125
	KeyValueStack *pStk;
faluco@654
   126
faluco@654
   127
	sec.pOwner = NULL;
faluco@654
   128
	sec.pIdentity = g_pCoreIdent;
faluco@654
   129
faluco@654
   130
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
faluco@654
   131
		!= HandleError_None)
faluco@654
   132
	{
faluco@654
   133
		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
faluco@654
   134
	}
faluco@654
   135
faluco@654
   136
	char *key;
dvander@1000
   137
	pCtx->LocalToStringNULL(params[2], &key);
faluco@654
   138
faluco@654
   139
	pStk->pCurRoot.front()->SetInt(key, params[3]);
faluco@654
   140
faluco@654
   141
	return 1;
faluco@654
   142
}
faluco@654
   143
dvander@816
   144
static cell_t smn_KvSetUInt64(IPluginContext *pCtx, const cell_t *params)
faluco@654
   145
{
faluco@654
   146
	Handle_t hndl = static_cast<Handle_t>(params[1]);
faluco@654
   147
	HandleError herr;
faluco@654
   148
	HandleSecurity sec;
faluco@654
   149
	KeyValueStack *pStk;
faluco@654
   150
faluco@654
   151
	sec.pOwner = NULL;
faluco@654
   152
	sec.pIdentity = g_pCoreIdent;
faluco@654
   153
faluco@654
   154
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
faluco@654
   155
		!= HandleError_None)
faluco@654
   156
	{
faluco@654
   157
		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
faluco@654
   158
	}
faluco@654
   159
faluco@654
   160
	char *key;
faluco@654
   161
	cell_t *addr;
faluco@654
   162
	uint64 value;
dvander@1000
   163
	pCtx->LocalToStringNULL(params[2], &key);
faluco@654
   164
	pCtx->LocalToPhysAddr(params[3], &addr);
faluco@654
   165
faluco@654
   166
	value = static_cast<uint64>(*addr);
faluco@654
   167
	pStk->pCurRoot.front()->SetUint64(key, value);
faluco@654
   168
faluco@654
   169
	return 1;
faluco@654
   170
}
faluco@654
   171
faluco@654
   172
static cell_t smn_KvSetFloat(IPluginContext *pCtx, const cell_t *params)
faluco@654
   173
{
faluco@654
   174
	Handle_t hndl = static_cast<Handle_t>(params[1]);
faluco@654
   175
	HandleError herr;
faluco@654
   176
	HandleSecurity sec;
faluco@654
   177
	KeyValueStack *pStk;
faluco@654
   178
faluco@654
   179
	sec.pOwner = NULL;
faluco@654
   180
	sec.pIdentity = g_pCoreIdent;
faluco@654
   181
faluco@654
   182
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
faluco@654
   183
		!= HandleError_None)
faluco@654
   184
	{
faluco@654
   185
		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
faluco@654
   186
	}
faluco@654
   187
faluco@654
   188
	char *key;
dvander@1000
   189
	pCtx->LocalToStringNULL(params[2], &key);
faluco@654
   190
faluco@654
   191
	pStk->pCurRoot.front()->SetFloat(key, sp_ctof(params[3]));
faluco@654
   192
faluco@654
   193
	return 1;
faluco@654
   194
}
faluco@654
   195
faluco@654
   196
static cell_t smn_KvSetColor(IPluginContext *pCtx, const cell_t *params)
faluco@654
   197
{
faluco@654
   198
	Handle_t hndl = static_cast<Handle_t>(params[1]);
faluco@654
   199
	HandleError herr;
faluco@654
   200
	HandleSecurity sec;
faluco@654
   201
	KeyValueStack *pStk;
faluco@654
   202
faluco@654
   203
	sec.pOwner = NULL;
faluco@654
   204
	sec.pIdentity = g_pCoreIdent;
faluco@654
   205
faluco@654
   206
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
faluco@654
   207
		!= HandleError_None)
faluco@654
   208
	{
faluco@654
   209
		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
faluco@654
   210
	}
faluco@654
   211
faluco@654
   212
	char *key;
dvander@1000
   213
	pCtx->LocalToStringNULL(params[2], &key);
faluco@654
   214
faluco@654
   215
	Color color(params[3], params[4], params[5], params[6]);
faluco@654
   216
	pStk->pCurRoot.front()->SetColor(key, color);
faluco@654
   217
faluco@654
   218
	return 1;
faluco@654
   219
}
faluco@654
   220
faluco@654
   221
static cell_t smn_KvGetString(IPluginContext *pCtx, const cell_t *params)
faluco@654
   222
{
faluco@654
   223
	Handle_t hndl = static_cast<Handle_t>(params[1]);
faluco@654
   224
	HandleError herr;
faluco@654
   225
	HandleSecurity sec;
faluco@654
   226
	KeyValueStack *pStk;
faluco@654
   227
faluco@654
   228
	sec.pOwner = NULL;
faluco@654
   229
	sec.pIdentity = g_pCoreIdent;
faluco@654
   230
faluco@654
   231
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
faluco@654
   232
		!= HandleError_None)
faluco@654
   233
	{
faluco@654
   234
		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
faluco@654
   235
	}
faluco@654
   236
faluco@654
   237
	const char *value;
faluco@654
   238
	char *key, *defvalue;
dvander@1000
   239
	pCtx->LocalToStringNULL(params[2], &key);
faluco@654
   240
	pCtx->LocalToString(params[5], &defvalue);
faluco@654
   241
faluco@654
   242
	value = pStk->pCurRoot.front()->GetString(key, defvalue);
faluco@654
   243
	pCtx->StringToLocalUTF8(params[3], params[4], value, NULL);
faluco@654
   244
faluco@654
   245
	return 1;
faluco@654
   246
}
faluco@654
   247
faluco@654
   248
static cell_t smn_KvGetNum(IPluginContext *pCtx, const cell_t *params)
faluco@654
   249
{
faluco@654
   250
	Handle_t hndl = static_cast<Handle_t>(params[1]);
faluco@654
   251
	HandleError herr;
faluco@654
   252
	HandleSecurity sec;
faluco@654
   253
	KeyValueStack *pStk;
faluco@654
   254
faluco@654
   255
	sec.pOwner = NULL;
faluco@654
   256
	sec.pIdentity = g_pCoreIdent;
faluco@654
   257
faluco@654
   258
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
faluco@654
   259
		!= HandleError_None)
faluco@654
   260
	{
faluco@654
   261
		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
faluco@654
   262
	}
faluco@654
   263
faluco@654
   264
	int value;
faluco@654
   265
	char *key;
dvander@1000
   266
	pCtx->LocalToStringNULL(params[2], &key);
faluco@654
   267
faluco@654
   268
	value = pStk->pCurRoot.front()->GetInt(key, params[3]);
faluco@654
   269
faluco@654
   270
	return value;
faluco@654
   271
}
faluco@654
   272
faluco@654
   273
static cell_t smn_KvGetFloat(IPluginContext *pCtx, const cell_t *params)
faluco@654
   274
{
faluco@654
   275
	Handle_t hndl = static_cast<Handle_t>(params[1]);
faluco@654
   276
	HandleError herr;
faluco@654
   277
	HandleSecurity sec;
faluco@654
   278
	KeyValueStack *pStk;
faluco@654
   279
faluco@654
   280
	sec.pOwner = NULL;
faluco@654
   281
	sec.pIdentity = g_pCoreIdent;
faluco@654
   282
faluco@654
   283
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
faluco@654
   284
		!= HandleError_None)
faluco@654
   285
	{
faluco@654
   286
		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
faluco@654
   287
	}
faluco@654
   288
faluco@654
   289
	float value;
faluco@654
   290
	char *key;
dvander@1000
   291
	pCtx->LocalToStringNULL(params[2], &key);
faluco@654
   292
faluco@654
   293
	value = pStk->pCurRoot.front()->GetFloat(key, sp_ctof(params[3]));
faluco@654
   294
faluco@654
   295
	return sp_ftoc(value);
faluco@654
   296
}
faluco@654
   297
faluco@654
   298
static cell_t smn_KvGetColor(IPluginContext *pCtx, const cell_t *params)
faluco@654
   299
{
faluco@654
   300
	Handle_t hndl = static_cast<Handle_t>(params[1]);
faluco@654
   301
	HandleError herr;
faluco@654
   302
	HandleSecurity sec;
faluco@654
   303
	KeyValueStack *pStk;
faluco@654
   304
faluco@654
   305
	sec.pOwner = NULL;
faluco@654
   306
	sec.pIdentity = g_pCoreIdent;
faluco@654
   307
faluco@654
   308
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
faluco@654
   309
		!= HandleError_None)
faluco@654
   310
	{
faluco@654
   311
		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
faluco@654
   312
	}
faluco@654
   313
faluco@654
   314
	Color color;
faluco@654
   315
	char *key;
faluco@654
   316
	cell_t *r, *g, *b, *a;
dvander@1000
   317
	pCtx->LocalToStringNULL(params[2], &key);
faluco@654
   318
	pCtx->LocalToPhysAddr(params[3], &r);
faluco@654
   319
	pCtx->LocalToPhysAddr(params[4], &g);
faluco@654
   320
	pCtx->LocalToPhysAddr(params[5], &b);
faluco@654
   321
	pCtx->LocalToPhysAddr(params[6], &a);
faluco@654
   322
faluco@654
   323
	color = pStk->pCurRoot.front()->GetColor(key);
faluco@654
   324
	*r = color.r();
faluco@654
   325
	*g = color.g();
faluco@654
   326
	*b = color.b();
faluco@654
   327
	*a = color.a();
faluco@654
   328
faluco@654
   329
	return 1;
faluco@654
   330
}
faluco@654
   331
dvander@816
   332
static cell_t smn_KvGetUInt64(IPluginContext *pCtx, const cell_t *params)
faluco@654
   333
{
faluco@654
   334
	Handle_t hndl = static_cast<Handle_t>(params[1]);
faluco@654
   335
	HandleError herr;
faluco@654
   336
	HandleSecurity sec;
faluco@654
   337
	KeyValueStack *pStk;
faluco@654
   338
faluco@654
   339
	sec.pOwner = NULL;
faluco@654
   340
	sec.pIdentity = g_pCoreIdent;
faluco@654
   341
faluco@654
   342
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
faluco@654
   343
		!= HandleError_None)
faluco@654
   344
	{
faluco@654
   345
		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
faluco@654
   346
	}
faluco@654
   347
faluco@654
   348
	char *key;
faluco@654
   349
	cell_t *addr, *defvalue;
faluco@654
   350
	uint64 value;
dvander@1000
   351
	pCtx->LocalToStringNULL(params[2], &key);
faluco@654
   352
	pCtx->LocalToPhysAddr(params[3], &addr);
faluco@654
   353
	pCtx->LocalToPhysAddr(params[4], &defvalue);
faluco@654
   354
faluco@654
   355
	value = pStk->pCurRoot.front()->GetUint64(key, static_cast<uint64>(*defvalue));
faluco@654
   356
	*reinterpret_cast<uint64 *>(addr) = value;
faluco@654
   357
faluco@654
   358
	return 1;
faluco@654
   359
}
faluco@654
   360
faluco@654
   361
static cell_t smn_CreateKeyValues(IPluginContext *pCtx, const cell_t *params)
faluco@654
   362
{
faluco@654
   363
	KeyValueStack *pStk;
faluco@654
   364
	char *name, *firstkey, *firstvalue;
faluco@654
   365
	bool is_empty;
faluco@654
   366
faluco@654
   367
	pCtx->LocalToString(params[1], &name);
faluco@654
   368
	pCtx->LocalToString(params[2], &firstkey);
faluco@654
   369
	pCtx->LocalToString(params[3], &firstvalue);
faluco@654
   370
faluco@654
   371
	is_empty = (firstkey[0] == '\0');
faluco@654
   372
	pStk = new KeyValueStack;
faluco@654
   373
	pStk->pBase = new KeyValues(name, is_empty ? NULL : firstkey, (is_empty||(firstvalue[0]=='\0')) ? NULL : firstvalue);
faluco@654
   374
	pStk->pCurRoot.push(pStk->pBase);
faluco@654
   375
faluco@654
   376
	return g_HandleSys.CreateHandle(g_KeyValueType, pStk, pCtx->GetIdentity(), g_pCoreIdent, NULL);
faluco@654
   377
}
faluco@654
   378
faluco@654
   379
static cell_t smn_KvJumpToKey(IPluginContext *pCtx, const cell_t *params)
faluco@654
   380
{
faluco@654
   381
	Handle_t hndl = static_cast<Handle_t>(params[1]);
faluco@654
   382
	HandleError herr;
faluco@654
   383
	HandleSecurity sec;
faluco@654
   384
	char *name;	
faluco@654
   385
	KeyValueStack *pStk;
faluco@654
   386
faluco@654
   387
	sec.pOwner = NULL;
faluco@654
   388
	sec.pIdentity = g_pCoreIdent;
faluco@654
   389
faluco@654
   390
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
faluco@654
   391
		!= HandleError_None)
faluco@654
   392
	{
faluco@654
   393
		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
faluco@654
   394
	}
faluco@654
   395
faluco@654
   396
	pCtx->LocalToString(params[2], &name);
faluco@654
   397
dvander@726
   398
	KeyValues *pSubKey = pStk->pCurRoot.front();
dvander@726
   399
	pSubKey = pSubKey->FindKey(name, (params[3]) ? true : false);
faluco@654
   400
	if (!pSubKey)
faluco@654
   401
	{
faluco@654
   402
		return 0;
faluco@654
   403
	}
faluco@654
   404
	pStk->pCurRoot.push(pSubKey);
faluco@654
   405
faluco@654
   406
	return 1;
faluco@654
   407
}
faluco@654
   408
dvander@753
   409
static cell_t smn_KvGotoFirstSubKey(IPluginContext *pCtx, const cell_t *params)
faluco@654
   410
{
faluco@654
   411
	Handle_t hndl = static_cast<Handle_t>(params[1]);
faluco@654
   412
	HandleError herr;
faluco@654
   413
	HandleSecurity sec;
faluco@654
   414
	KeyValueStack *pStk;
faluco@654
   415
faluco@654
   416
	sec.pOwner = NULL;
faluco@654
   417
	sec.pIdentity = g_pCoreIdent;
faluco@654
   418
faluco@654
   419
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
faluco@654
   420
		!= HandleError_None)
faluco@654
   421
	{
faluco@654
   422
		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
faluco@654
   423
	}
faluco@654
   424
faluco@654
   425
	KeyValues *pSubKey = pStk->pCurRoot.front();
dvander@753
   426
	KeyValues *pFirstSubKey;
dvander@753
   427
	if (params[2])
dvander@753
   428
	{
dvander@753
   429
		pFirstSubKey = pSubKey->GetFirstTrueSubKey();
dvander@753
   430
	} else {
dvander@753
   431
		pFirstSubKey = pSubKey->GetFirstSubKey();
dvander@753
   432
	}
dvander@753
   433
faluco@654
   434
	if (!pFirstSubKey)
faluco@654
   435
	{
faluco@654
   436
		return 0;
faluco@654
   437
	}
faluco@654
   438
	pStk->pCurRoot.push(pFirstSubKey);
faluco@654
   439
faluco@654
   440
	return 1;
faluco@654
   441
}
faluco@654
   442
dvander@753
   443
static cell_t smn_KvGotoNextKey(IPluginContext *pCtx, const cell_t *params)
dvander@753
   444
{
dvander@753
   445
	Handle_t hndl = static_cast<Handle_t>(params[1]);
dvander@753
   446
	HandleError herr;
dvander@753
   447
	HandleSecurity sec;
dvander@753
   448
	KeyValueStack *pStk;
dvander@753
   449
dvander@753
   450
	sec.pOwner = NULL;
dvander@753
   451
	sec.pIdentity = g_pCoreIdent;
dvander@753
   452
dvander@753
   453
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
dvander@753
   454
		!= HandleError_None)
dvander@753
   455
	{
dvander@753
   456
		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
dvander@753
   457
	}
dvander@753
   458
dvander@753
   459
	KeyValues *pSubKey = pStk->pCurRoot.front();
dvander@753
   460
	if (params[2])
dvander@753
   461
	{
dvander@1002
   462
		pSubKey = pSubKey->GetNextTrueSubKey();
dvander@753
   463
	} else {
dvander@1002
   464
		pSubKey = pSubKey->GetNextKey();
dvander@753
   465
	}
dvander@753
   466
	if (!pSubKey)
dvander@753
   467
	{
dvander@753
   468
		return 0;
dvander@753
   469
	}
dvander@753
   470
	pStk->pCurRoot.pop();
dvander@753
   471
	pStk->pCurRoot.push(pSubKey);
dvander@753
   472
dvander@753
   473
	return 1;	
dvander@753
   474
}
dvander@753
   475
faluco@654
   476
static cell_t smn_KvJumpNextSubKey(IPluginContext *pCtx, const cell_t *params)
faluco@654
   477
{
faluco@654
   478
	Handle_t hndl = static_cast<Handle_t>(params[1]);
faluco@654
   479
	HandleError herr;
faluco@654
   480
	HandleSecurity sec;
faluco@654
   481
	KeyValueStack *pStk;
faluco@654
   482
faluco@654
   483
	sec.pOwner = NULL;
faluco@654
   484
	sec.pIdentity = g_pCoreIdent;
faluco@654
   485
faluco@654
   486
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
faluco@654
   487
		!= HandleError_None)
faluco@654
   488
	{
faluco@654
   489
		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
faluco@654
   490
	}
faluco@654
   491
faluco@654
   492
	KeyValues *pSubKey = pStk->pCurRoot.front();
faluco@654
   493
	KeyValues *pNextKey = pSubKey->GetNextKey();
faluco@654
   494
	if (!pNextKey)
faluco@654
   495
	{
faluco@654
   496
		return 0;
faluco@654
   497
	}
faluco@654
   498
	pStk->pCurRoot.push(pNextKey);
faluco@654
   499
faluco@654
   500
	return 1;	
faluco@654
   501
}
faluco@654
   502
faluco@654
   503
static cell_t smn_KvGoBack(IPluginContext *pCtx, const cell_t *params)
faluco@654
   504
{
faluco@654
   505
	Handle_t hndl = static_cast<Handle_t>(params[1]);
faluco@654
   506
	HandleError herr;
faluco@654
   507
	HandleSecurity sec;
faluco@654
   508
	KeyValueStack *pStk;
faluco@654
   509
faluco@654
   510
	sec.pOwner = NULL;
faluco@654
   511
	sec.pIdentity = g_pCoreIdent;
faluco@654
   512
faluco@654
   513
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
faluco@654
   514
		!= HandleError_None)
faluco@654
   515
	{
faluco@654
   516
		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
faluco@654
   517
	}
faluco@654
   518
faluco@654
   519
	if (pStk->pCurRoot.size() == 1)
faluco@654
   520
	{
faluco@654
   521
		return 0;
faluco@654
   522
	}
faluco@654
   523
	pStk->pCurRoot.pop();
faluco@654
   524
faluco@654
   525
	return 1;
faluco@654
   526
}
faluco@654
   527
faluco@654
   528
static cell_t smn_KvRewind(IPluginContext *pCtx, const cell_t *params)
faluco@654
   529
{
faluco@654
   530
	Handle_t hndl = static_cast<Handle_t>(params[1]);
faluco@654
   531
	HandleError herr;
faluco@654
   532
	HandleSecurity sec;
faluco@654
   533
	KeyValueStack *pStk;
faluco@654
   534
faluco@654
   535
	sec.pOwner = NULL;
faluco@654
   536
	sec.pIdentity = g_pCoreIdent;
faluco@654
   537
faluco@654
   538
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
faluco@654
   539
		!= HandleError_None)
faluco@654
   540
	{
faluco@654
   541
		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
faluco@654
   542
	}
faluco@654
   543
faluco@654
   544
	while (pStk->pCurRoot.size() > 1)
faluco@654
   545
	{
faluco@654
   546
		pStk->pCurRoot.pop();
faluco@654
   547
	}
faluco@654
   548
faluco@654
   549
	return 1;
faluco@654
   550
}
faluco@654
   551
faluco@654
   552
static cell_t smn_KvGetSectionName(IPluginContext *pCtx, const cell_t *params)
faluco@654
   553
{
faluco@654
   554
	Handle_t hndl = static_cast<Handle_t>(params[1]);
faluco@654
   555
	HandleError herr;
faluco@654
   556
	HandleSecurity sec;
faluco@654
   557
	KeyValueStack *pStk;
faluco@654
   558
faluco@654
   559
	sec.pOwner = NULL;
faluco@654
   560
	sec.pIdentity = g_pCoreIdent;
faluco@654
   561
faluco@654
   562
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
faluco@654
   563
		!= HandleError_None)
faluco@654
   564
	{
faluco@654
   565
		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
faluco@654
   566
	}
faluco@654
   567
faluco@654
   568
	KeyValues *pSection = pStk->pCurRoot.front();
faluco@654
   569
	const char *name = pSection->GetName();
faluco@654
   570
	if (!name)
faluco@654
   571
	{
faluco@654
   572
		return 0;
faluco@654
   573
	}
faluco@654
   574
	pCtx->StringToLocalUTF8(params[2], params[3], name, NULL);
faluco@654
   575
faluco@654
   576
	return 1;
faluco@654
   577
}
faluco@654
   578
faluco@654
   579
static cell_t smn_KvSetSectionName(IPluginContext *pCtx, const cell_t *params)
faluco@654
   580
{
faluco@654
   581
	Handle_t hndl = static_cast<Handle_t>(params[1]);
faluco@654
   582
	HandleError herr;
faluco@654
   583
	HandleSecurity sec;
faluco@654
   584
	char *name;
faluco@654
   585
	KeyValueStack *pStk;
faluco@654
   586
faluco@654
   587
	sec.pOwner = NULL;
faluco@654
   588
	sec.pIdentity = g_pCoreIdent;
faluco@654
   589
faluco@654
   590
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
faluco@654
   591
		!= HandleError_None)
faluco@654
   592
	{
faluco@654
   593
		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
faluco@654
   594
	}
faluco@654
   595
faluco@654
   596
	pCtx->LocalToString(params[2], &name);
faluco@654
   597
faluco@654
   598
	KeyValues *pSection = pStk->pCurRoot.front();
faluco@654
   599
	pSection->SetName(name);
faluco@654
   600
faluco@654
   601
	return 1;
faluco@654
   602
}
faluco@654
   603
faluco@654
   604
static cell_t smn_KvGetDataType(IPluginContext *pCtx, const cell_t *params)
faluco@654
   605
{
faluco@654
   606
	Handle_t hndl = static_cast<Handle_t>(params[1]);
faluco@654
   607
	HandleError herr;
faluco@654
   608
	HandleSecurity sec;
faluco@654
   609
	char *name;
faluco@654
   610
	KeyValueStack *pStk;
faluco@654
   611
faluco@654
   612
	sec.pOwner = NULL;
faluco@654
   613
	sec.pIdentity = g_pCoreIdent;
faluco@654
   614
faluco@654
   615
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
faluco@654
   616
		!= HandleError_None)
faluco@654
   617
	{
faluco@654
   618
		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
faluco@654
   619
	}
faluco@654
   620
faluco@654
   621
	pCtx->LocalToString(params[2], &name);
faluco@654
   622
faluco@654
   623
	return pStk->pCurRoot.front()->GetDataType(name);
faluco@654
   624
}
faluco@654
   625
faluco@654
   626
static cell_t smn_KeyValuesToFile(IPluginContext *pCtx, const cell_t *params)
faluco@654
   627
{
faluco@654
   628
	Handle_t hndl = static_cast<Handle_t>(params[1]);
faluco@654
   629
	HandleError herr;
faluco@654
   630
	HandleSecurity sec;
faluco@654
   631
	char *path;
faluco@654
   632
	KeyValueStack *pStk;
faluco@654
   633
faluco@654
   634
	sec.pOwner = NULL;
faluco@654
   635
	sec.pIdentity = g_pCoreIdent;
faluco@654
   636
faluco@654
   637
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
faluco@654
   638
		!= HandleError_None)
faluco@654
   639
	{
faluco@654
   640
		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
faluco@654
   641
	}
faluco@654
   642
faluco@654
   643
	pCtx->LocalToString(params[2], &path);
faluco@654
   644
faluco@654
   645
	char realpath[PLATFORM_MAX_PATH];
faluco@654
   646
	g_SourceMod.BuildPath(Path_Game, realpath, sizeof(realpath), "%s", path);
faluco@654
   647
faluco@654
   648
	return pStk->pCurRoot.front()->SaveToFile(basefilesystem, realpath);
faluco@654
   649
}
faluco@654
   650
faluco@654
   651
static cell_t smn_FileToKeyValues(IPluginContext *pCtx, const cell_t *params)
faluco@654
   652
{
faluco@654
   653
	Handle_t hndl = static_cast<Handle_t>(params[1]);
faluco@654
   654
	HandleError herr;
faluco@654
   655
	HandleSecurity sec;
faluco@654
   656
	char *path;
faluco@654
   657
	KeyValueStack *pStk;
faluco@654
   658
faluco@654
   659
	sec.pOwner = NULL;
faluco@654
   660
	sec.pIdentity = g_pCoreIdent;
faluco@654
   661
faluco@654
   662
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
faluco@654
   663
		!= HandleError_None)
faluco@654
   664
	{
faluco@654
   665
		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
faluco@654
   666
	}
faluco@654
   667
faluco@654
   668
	pCtx->LocalToString(params[2], &path);
faluco@654
   669
faluco@654
   670
	char realpath[PLATFORM_MAX_PATH];
faluco@654
   671
	g_SourceMod.BuildPath(Path_Game, realpath, sizeof(realpath), "%s", path);
faluco@654
   672
faluco@654
   673
	return pStk->pCurRoot.front()->LoadFromFile(basefilesystem, realpath);
faluco@654
   674
}
faluco@654
   675
faluco@654
   676
static cell_t smn_KvSetEscapeSequences(IPluginContext *pCtx, const cell_t *params)
faluco@654
   677
{
faluco@654
   678
	Handle_t hndl = static_cast<Handle_t>(params[1]);
faluco@654
   679
	HandleError herr;
faluco@654
   680
	HandleSecurity sec;
faluco@654
   681
	KeyValueStack *pStk;
faluco@654
   682
faluco@654
   683
	sec.pOwner = NULL;
faluco@654
   684
	sec.pIdentity = g_pCoreIdent;
faluco@654
   685
faluco@654
   686
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
faluco@654
   687
		!= HandleError_None)
faluco@654
   688
	{
faluco@654
   689
		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
faluco@654
   690
	}
faluco@654
   691
faluco@654
   692
	pStk->pCurRoot.front()->UsesEscapeSequences(params[2] ? true : false);
faluco@654
   693
faluco@654
   694
	return 1;
faluco@654
   695
}
faluco@654
   696
dvander@750
   697
static cell_t smn_KvNodesInStack(IPluginContext *pCtx, const cell_t *params)
dvander@750
   698
{
dvander@750
   699
	Handle_t hndl = static_cast<Handle_t>(params[1]);
dvander@750
   700
	HandleError herr;
dvander@750
   701
	HandleSecurity sec;
dvander@750
   702
	KeyValueStack *pStk;
dvander@750
   703
dvander@750
   704
	sec.pOwner = NULL;
dvander@750
   705
	sec.pIdentity = g_pCoreIdent;
dvander@750
   706
dvander@750
   707
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
dvander@750
   708
		!= HandleError_None)
dvander@750
   709
	{
dvander@750
   710
		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
dvander@750
   711
	}
dvander@750
   712
dvander@751
   713
	return pStk->pCurRoot.size() - 1;
dvander@750
   714
}
dvander@750
   715
dvander@743
   716
static cell_t smn_KvDeleteThis(IPluginContext *pContext, const cell_t *params)
dvander@743
   717
{
dvander@743
   718
	Handle_t hndl = static_cast<Handle_t>(params[1]);
dvander@743
   719
	HandleError herr;
dvander@743
   720
	HandleSecurity sec;
dvander@743
   721
	KeyValueStack *pStk;
dvander@743
   722
dvander@743
   723
	sec.pOwner = NULL;
dvander@743
   724
	sec.pIdentity = g_pCoreIdent;
dvander@743
   725
dvander@743
   726
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
dvander@743
   727
		!= HandleError_None)
dvander@743
   728
	{
dvander@743
   729
		return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
dvander@743
   730
	}
dvander@743
   731
dvander@743
   732
	if (pStk->pCurRoot.size() < 2)
dvander@743
   733
	{
dvander@743
   734
		return 0;
dvander@743
   735
	}
dvander@743
   736
dvander@743
   737
	KeyValues *pValues = pStk->pCurRoot.front();
dvander@743
   738
	pStk->pCurRoot.pop();
dvander@753
   739
	KeyValues *pRoot = pStk->pCurRoot.front();
dvander@743
   740
dvander@753
   741
	/* We have to manually verify this since Valve sucks
dvander@753
   742
	 * :TODO: make our own KeyValues.h file and make
dvander@753
   743
	 * the sub stuff private so we can do this ourselves!
dvander@753
   744
 	 */
dvander@753
   745
	KeyValues *sub = pRoot->GetFirstSubKey();
dvander@753
   746
	while (sub)
dvander@753
   747
	{
dvander@753
   748
		if (sub == pValues)
dvander@753
   749
		{
dvander@753
   750
			KeyValues *pNext = pValues->GetNextKey();
dvander@753
   751
			pRoot->RemoveSubKey(pValues);
dvander@753
   752
			pValues->deleteThis();
dvander@753
   753
			if (pNext)
dvander@753
   754
			{
dvander@753
   755
				pStk->pCurRoot.push(pNext);
dvander@753
   756
				return 1;
dvander@753
   757
			} else {
dvander@753
   758
				return -1;
dvander@753
   759
			}
dvander@753
   760
		}
dvander@753
   761
		sub = sub->GetNextKey();
dvander@753
   762
	}
dvander@753
   763
dvander@753
   764
	/* Push this back on :( */
dvander@753
   765
	pStk->pCurRoot.push(pValues);
dvander@753
   766
dvander@753
   767
	return 0;
dvander@743
   768
}
dvander@743
   769
dvander@743
   770
static cell_t smn_KvDeleteKey(IPluginContext *pContext, const cell_t *params)
dvander@743
   771
{
dvander@743
   772
	Handle_t hndl = static_cast<Handle_t>(params[1]);
dvander@743
   773
	HandleError herr;
dvander@743
   774
	HandleSecurity sec;
dvander@743
   775
	KeyValueStack *pStk;
dvander@743
   776
dvander@743
   777
	sec.pOwner = NULL;
dvander@743
   778
	sec.pIdentity = g_pCoreIdent;
dvander@743
   779
dvander@743
   780
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
dvander@743
   781
		!= HandleError_None)
dvander@743
   782
	{
dvander@743
   783
		return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
dvander@743
   784
	}
dvander@743
   785
dvander@743
   786
	if (pStk->pCurRoot.size() < 2)
dvander@743
   787
	{
dvander@743
   788
		return 0;
dvander@743
   789
	}
dvander@743
   790
dvander@743
   791
	char *keyName;
dvander@743
   792
	pContext->LocalToString(params[2], &keyName);
dvander@743
   793
dvander@743
   794
	KeyValues *pRoot = pStk->pCurRoot.front();
dvander@743
   795
	KeyValues *pValues = pRoot->FindKey(keyName);
dvander@743
   796
	if (!pValues)
dvander@743
   797
	{
dvander@743
   798
		return 0;
dvander@743
   799
	}
dvander@743
   800
dvander@743
   801
	pRoot->RemoveSubKey(pValues);
dvander@743
   802
	pValues->deleteThis();
dvander@743
   803
dvander@743
   804
	return 1;
dvander@743
   805
}
dvander@743
   806
dvander@753
   807
static cell_t smn_KvSavePosition(IPluginContext *pContext, const cell_t *params)
dvander@753
   808
{
dvander@753
   809
	Handle_t hndl = static_cast<Handle_t>(params[1]);
dvander@753
   810
	HandleError herr;
dvander@753
   811
	HandleSecurity sec;
dvander@753
   812
	KeyValueStack *pStk;
dvander@753
   813
dvander@753
   814
	sec.pOwner = NULL;
dvander@753
   815
	sec.pIdentity = g_pCoreIdent;
dvander@753
   816
dvander@753
   817
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
dvander@753
   818
		!= HandleError_None)
dvander@753
   819
	{
dvander@753
   820
		return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
dvander@753
   821
	}
dvander@753
   822
dvander@753
   823
	if (pStk->pCurRoot.size() < 2)
dvander@753
   824
	{
dvander@753
   825
		return 0;
dvander@753
   826
	}
dvander@753
   827
dvander@753
   828
	KeyValues *pValues = pStk->pCurRoot.front();
dvander@753
   829
	pStk->pCurRoot.push(pValues);
dvander@753
   830
dvander@753
   831
	return 1;
dvander@753
   832
}
dvander@753
   833
faluco@1401
   834
static cell_t smn_CopySubkeys(IPluginContext *pContext, const cell_t *params)
faluco@1401
   835
{
faluco@1401
   836
	Handle_t hndl_copied = static_cast<Handle_t>(params[1]);
faluco@1401
   837
	Handle_t hndl_parent = static_cast<Handle_t>(params[2]);
faluco@1401
   838
	HandleError herr;
faluco@1401
   839
	HandleSecurity sec;
faluco@1401
   840
	KeyValueStack *pStk_copied, *pStk_parent;
faluco@1401
   841
faluco@1401
   842
	sec.pOwner = NULL;
faluco@1401
   843
	sec.pIdentity = g_pCoreIdent;
faluco@1401
   844
faluco@1401
   845
	if ((herr=g_HandleSys.ReadHandle(hndl_copied, g_KeyValueType, &sec, (void **)&pStk_copied))
faluco@1401
   846
		!= HandleError_None)
faluco@1401
   847
	{
faluco@1401
   848
		return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl_copied, herr);
faluco@1401
   849
	}
faluco@1401
   850
	if ((herr=g_HandleSys.ReadHandle(hndl_parent, g_KeyValueType, &sec, (void **)&pStk_parent))
faluco@1401
   851
		!= HandleError_None)
faluco@1401
   852
	{
faluco@1401
   853
		return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl_parent, herr);
faluco@1401
   854
	}
faluco@1401
   855
faluco@1401
   856
	pStk_copied->pCurRoot.front()->CopySubkeys(pStk_parent->pCurRoot.front());
faluco@1401
   857
faluco@1401
   858
	return 1;
faluco@1401
   859
}
faluco@1401
   860
faluco@1401
   861
static cell_t smn_GetNameSymbol(IPluginContext *pContext, const cell_t *params)
faluco@1401
   862
{
faluco@1401
   863
	Handle_t hndl = static_cast<Handle_t>(params[1]);
faluco@1401
   864
	HandleError herr;
faluco@1401
   865
	HandleSecurity sec;
faluco@1401
   866
	KeyValueStack *pStk;
faluco@1401
   867
	cell_t *val;
faluco@1401
   868
	char *key;
faluco@1401
   869
faluco@1401
   870
	sec.pOwner = NULL;
faluco@1401
   871
	sec.pIdentity = g_pCoreIdent;
faluco@1401
   872
faluco@1401
   873
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
faluco@1401
   874
		!= HandleError_None)
faluco@1401
   875
	{
faluco@1401
   876
		return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
faluco@1401
   877
	}
faluco@1401
   878
faluco@1401
   879
	if (pStk->pCurRoot.size() < 2)
faluco@1401
   880
	{
faluco@1401
   881
		return 0;
faluco@1401
   882
	}
faluco@1401
   883
faluco@1401
   884
	pContext->LocalToString(params[2], &key);
faluco@1401
   885
faluco@1401
   886
	KeyValues *pKv = pStk->pCurRoot.front()->FindKey(key);
faluco@1401
   887
	if (!pKv)
faluco@1401
   888
	{
faluco@1401
   889
		return 0;
faluco@1401
   890
	}
faluco@1401
   891
	pContext->LocalToPhysAddr(params[3], &val);
faluco@1401
   892
	*val = pKv->GetNameSymbol();
faluco@1401
   893
faluco@1401
   894
	return 1;
faluco@1401
   895
}
faluco@1401
   896
faluco@1401
   897
static cell_t smn_FindKeyById(IPluginContext *pContext, const cell_t *params)
faluco@1401
   898
{
faluco@1401
   899
	Handle_t hndl = static_cast<Handle_t>(params[1]);
faluco@1401
   900
	HandleError herr;
faluco@1401
   901
	HandleSecurity sec;
faluco@1401
   902
	KeyValueStack *pStk;
faluco@1401
   903
faluco@1401
   904
	sec.pOwner = NULL;
faluco@1401
   905
	sec.pIdentity = g_pCoreIdent;
faluco@1401
   906
faluco@1401
   907
	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
faluco@1401
   908
		!= HandleError_None)
faluco@1401
   909
	{
faluco@1401
   910
		return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
faluco@1401
   911
	}
faluco@1401
   912
faluco@1401
   913
	KeyValues *pKv = pStk->pCurRoot.front()->FindKey(params[2]);
faluco@1401
   914
	if (!pKv)
faluco@1401
   915
	{
faluco@1401
   916
		return 0;
faluco@1401
   917
	}
faluco@1401
   918
faluco@1401
   919
	pContext->StringToLocalUTF8(params[3], params[4], pKv->GetName(), NULL);
faluco@1401
   920
faluco@1401
   921
	return 1;
faluco@1401
   922
}
faluco@1401
   923
faluco@703
   924
static KeyValueNatives s_KeyValueNatives;
faluco@654
   925
faluco@654
   926
REGISTER_NATIVES(keyvaluenatives)
faluco@654
   927
{
faluco@654
   928
	{"KvSetString",				smn_KvSetString},
faluco@654
   929
	{"KvSetNum",				smn_KvSetNum},
dvander@816
   930
	{"KvSetUInt64",				smn_KvSetUInt64},
faluco@654
   931
	{"KvSetFloat",				smn_KvSetFloat},
faluco@654
   932
	{"KvSetColor",				smn_KvSetColor},
faluco@654
   933
	{"KvGetString",				smn_KvGetString},
faluco@654
   934
	{"KvGetNum",				smn_KvGetNum},
faluco@654
   935
	{"KvGetFloat",				smn_KvGetFloat},
faluco@654
   936
	{"KvGetColor",				smn_KvGetColor},
dvander@816
   937
	{"KvGetUInt64",				smn_KvGetUInt64},
faluco@654
   938
	{"CreateKeyValues",			smn_CreateKeyValues},
faluco@654
   939
	{"KvJumpToKey",				smn_KvJumpToKey},
dvander@753
   940
	{"KvGotoNextKey",			smn_KvGotoNextKey},
dvander@753
   941
	{"KvJumpFirstSubKey",		smn_KvGotoFirstSubKey},		/* BACKWARDS COMPAT SHIM */
dvander@753
   942
	{"KvGotoFirstSubKey",		smn_KvGotoFirstSubKey},
dvander@753
   943
	{"KvJumpNextSubKey",		smn_KvJumpNextSubKey},		/* BACKWARDS COMPAT SHIM */
faluco@654
   944
	{"KvGoBack",				smn_KvGoBack},
faluco@654
   945
	{"KvRewind",				smn_KvRewind},
faluco@654
   946
	{"KvGetSectionName",		smn_KvGetSectionName},
faluco@654
   947
	{"KvSetSectionName",		smn_KvSetSectionName},
faluco@654
   948
	{"KvGetDataType",			smn_KvGetDataType},
faluco@654
   949
	{"KeyValuesToFile",			smn_KeyValuesToFile},
faluco@654
   950
	{"FileToKeyValues",			smn_FileToKeyValues},
faluco@654
   951
	{"KvSetEscapeSequences",	smn_KvSetEscapeSequences},
dvander@743
   952
	{"KvDeleteThis",			smn_KvDeleteThis},
dvander@743
   953
	{"KvDeleteKey",				smn_KvDeleteKey},
dvander@750
   954
	{"KvNodesInStack",			smn_KvNodesInStack},
dvander@753
   955
	{"KvSavePosition",			smn_KvSavePosition},
faluco@1401
   956
	{"KvCopySubkeys",			smn_CopySubkeys},
faluco@1401
   957
	{"KvFindKeyById",			smn_FindKeyById},
faluco@1401
   958
	{"KvGetNameSymbol",			smn_GetNameSymbol},
faluco@654
   959
	{NULL,						NULL}
faluco@654
   960
};