core/smn_keyvalues.cpp
author Scott Ehlert <ds@alliedmods.net>
Sat Apr 21 17:03:28 2007 +0000 (2007-04-21)
changeset 702 ff520b71249c
parent 682 a70055d6d3b3
child 703 cddbff919185
permissions -rw-r--r--
Wow, how did I forget this - exported IMemoryUtils interface
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     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
    11  *
    12  * Version: $Id$
    13  */
    14 
    15 #include "sourcemod.h"
    16 #include "sourcemm_api.h"
    17 #include "sm_stringutil.h"
    18 #include "HandleSys.h"
    19 #include <KeyValues.h>
    20 
    21 HandleType_t g_KeyValueType;
    22 
    23 struct KeyValueStack 
    24 {
    25 	KeyValues *pBase;
    26 	CStack<KeyValues *> pCurRoot;
    27 };
    28 
    29 class KeyValuekNatives : 
    30 	public SMGlobalClass,
    31 	public IHandleTypeDispatch
    32 {
    33 public:
    34 	void OnSourceModAllInitialized()
    35 	{
    36 		g_KeyValueType = g_HandleSys.CreateType("KeyValues", this, 0, NULL, NULL, g_pCoreIdent, NULL);
    37 	}
    38 	void OnSourceModShutdown()
    39 	{
    40 		g_HandleSys.RemoveType(g_KeyValueType, g_pCoreIdent);
    41 		g_KeyValueType = 0;
    42 	}
    43 	void OnHandleDestroy(HandleType_t type, void *object)
    44 	{
    45 		KeyValueStack *pStk = reinterpret_cast<KeyValueStack *>(object);
    46 		pStk->pBase->deleteThis();
    47 		delete pStk;
    48 	}
    49 };
    50 
    51 KeyValues *SourceModBase::ReadKeyValuesHandle(Handle_t hndl, HandleError *err, bool root)
    52 {
    53 	HandleError herr;
    54 	HandleSecurity sec;
    55 	KeyValueStack *pStk;
    56 
    57 	sec.pOwner = NULL;
    58 	sec.pIdentity = g_pCoreIdent;
    59 
    60 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
    61 		!= HandleError_None)
    62 	{
    63 		if (err)
    64 		{
    65 			*err = herr;
    66 		}
    67 		return NULL;
    68 	}
    69 
    70 	if (err)
    71 	{
    72 		*err = HandleError_None;
    73 	}
    74 
    75 	return (root) ? pStk->pBase : pStk->pCurRoot.front();
    76 }
    77 
    78 static cell_t smn_KvSetString(IPluginContext *pCtx, const cell_t *params)
    79 {
    80 	Handle_t hndl = static_cast<Handle_t>(params[1]);
    81 	HandleError herr;
    82 	HandleSecurity sec;
    83 	KeyValueStack *pStk;
    84 
    85 	sec.pOwner = NULL;
    86 	sec.pIdentity = g_pCoreIdent;
    87 
    88 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
    89 		!= HandleError_None)
    90 	{
    91 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
    92 	}
    93 
    94 	char *key, *value;
    95 	pCtx->LocalToString(params[2], &key);
    96 	pCtx->LocalToString(params[3], &value);
    97 
    98 	pStk->pCurRoot.front()->SetString(key, value);
    99 
   100 	return 1;
   101 }
   102 
   103 static cell_t smn_KvSetNum(IPluginContext *pCtx, const cell_t *params)
   104 {
   105 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   106 	HandleError herr;
   107 	HandleSecurity sec;
   108 	KeyValueStack *pStk;
   109 
   110 	sec.pOwner = NULL;
   111 	sec.pIdentity = g_pCoreIdent;
   112 
   113 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   114 		!= HandleError_None)
   115 	{
   116 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   117 	}
   118 
   119 	char *key;
   120 	pCtx->LocalToString(params[2], &key);
   121 
   122 	pStk->pCurRoot.front()->SetInt(key, params[3]);
   123 
   124 	return 1;
   125 }
   126 
   127 static cell_t smn_KvSetUint64(IPluginContext *pCtx, const cell_t *params)
   128 {
   129 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   130 	HandleError herr;
   131 	HandleSecurity sec;
   132 	KeyValueStack *pStk;
   133 
   134 	sec.pOwner = NULL;
   135 	sec.pIdentity = g_pCoreIdent;
   136 
   137 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   138 		!= HandleError_None)
   139 	{
   140 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   141 	}
   142 
   143 	char *key;
   144 	cell_t *addr;
   145 	uint64 value;
   146 	pCtx->LocalToString(params[2], &key);
   147 	pCtx->LocalToPhysAddr(params[3], &addr);
   148 
   149 	value = static_cast<uint64>(*addr);
   150 	pStk->pCurRoot.front()->SetUint64(key, value);
   151 
   152 	return 1;
   153 }
   154 
   155 static cell_t smn_KvSetFloat(IPluginContext *pCtx, const cell_t *params)
   156 {
   157 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   158 	HandleError herr;
   159 	HandleSecurity sec;
   160 	KeyValueStack *pStk;
   161 
   162 	sec.pOwner = NULL;
   163 	sec.pIdentity = g_pCoreIdent;
   164 
   165 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   166 		!= HandleError_None)
   167 	{
   168 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   169 	}
   170 
   171 	char *key;
   172 	pCtx->LocalToString(params[2], &key);
   173 
   174 	pStk->pCurRoot.front()->SetFloat(key, sp_ctof(params[3]));
   175 
   176 	return 1;
   177 }
   178 
   179 static cell_t smn_KvSetColor(IPluginContext *pCtx, const cell_t *params)
   180 {
   181 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   182 	HandleError herr;
   183 	HandleSecurity sec;
   184 	KeyValueStack *pStk;
   185 
   186 	sec.pOwner = NULL;
   187 	sec.pIdentity = g_pCoreIdent;
   188 
   189 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   190 		!= HandleError_None)
   191 	{
   192 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   193 	}
   194 
   195 	char *key;
   196 	pCtx->LocalToString(params[2], &key);
   197 
   198 	Color color(params[3], params[4], params[5], params[6]);
   199 	pStk->pCurRoot.front()->SetColor(key, color);
   200 
   201 	return 1;
   202 }
   203 
   204 static cell_t smn_KvGetString(IPluginContext *pCtx, const cell_t *params)
   205 {
   206 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   207 	HandleError herr;
   208 	HandleSecurity sec;
   209 	KeyValueStack *pStk;
   210 
   211 	sec.pOwner = NULL;
   212 	sec.pIdentity = g_pCoreIdent;
   213 
   214 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   215 		!= HandleError_None)
   216 	{
   217 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   218 	}
   219 
   220 	const char *value;
   221 	char *key, *defvalue;
   222 	pCtx->LocalToString(params[2], &key);
   223 	pCtx->LocalToString(params[5], &defvalue);
   224 
   225 	value = pStk->pCurRoot.front()->GetString(key, defvalue);
   226 	pCtx->StringToLocalUTF8(params[3], params[4], value, NULL);
   227 
   228 	return 1;
   229 }
   230 
   231 static cell_t smn_KvGetNum(IPluginContext *pCtx, const cell_t *params)
   232 {
   233 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   234 	HandleError herr;
   235 	HandleSecurity sec;
   236 	KeyValueStack *pStk;
   237 
   238 	sec.pOwner = NULL;
   239 	sec.pIdentity = g_pCoreIdent;
   240 
   241 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   242 		!= HandleError_None)
   243 	{
   244 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   245 	}
   246 
   247 	int value;
   248 	char *key;
   249 	pCtx->LocalToString(params[2], &key);
   250 
   251 	value = pStk->pCurRoot.front()->GetInt(key, params[3]);
   252 
   253 	return value;
   254 }
   255 
   256 static cell_t smn_KvGetFloat(IPluginContext *pCtx, const cell_t *params)
   257 {
   258 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   259 	HandleError herr;
   260 	HandleSecurity sec;
   261 	KeyValueStack *pStk;
   262 
   263 	sec.pOwner = NULL;
   264 	sec.pIdentity = g_pCoreIdent;
   265 
   266 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   267 		!= HandleError_None)
   268 	{
   269 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   270 	}
   271 
   272 	float value;
   273 	char *key;
   274 	pCtx->LocalToString(params[2], &key);
   275 
   276 	value = pStk->pCurRoot.front()->GetFloat(key, sp_ctof(params[3]));
   277 
   278 	return sp_ftoc(value);
   279 }
   280 
   281 static cell_t smn_KvGetColor(IPluginContext *pCtx, const cell_t *params)
   282 {
   283 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   284 	HandleError herr;
   285 	HandleSecurity sec;
   286 	KeyValueStack *pStk;
   287 
   288 	sec.pOwner = NULL;
   289 	sec.pIdentity = g_pCoreIdent;
   290 
   291 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   292 		!= HandleError_None)
   293 	{
   294 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   295 	}
   296 
   297 	Color color;
   298 	char *key;
   299 	cell_t *r, *g, *b, *a;
   300 	pCtx->LocalToString(params[2], &key);
   301 	pCtx->LocalToPhysAddr(params[3], &r);
   302 	pCtx->LocalToPhysAddr(params[4], &g);
   303 	pCtx->LocalToPhysAddr(params[5], &b);
   304 	pCtx->LocalToPhysAddr(params[6], &a);
   305 
   306 	color = pStk->pCurRoot.front()->GetColor(key);
   307 	*r = color.r();
   308 	*g = color.g();
   309 	*b = color.b();
   310 	*a = color.a();
   311 
   312 	return 1;
   313 }
   314 
   315 static cell_t smn_KvGetUint64(IPluginContext *pCtx, const cell_t *params)
   316 {
   317 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   318 	HandleError herr;
   319 	HandleSecurity sec;
   320 	KeyValueStack *pStk;
   321 
   322 	sec.pOwner = NULL;
   323 	sec.pIdentity = g_pCoreIdent;
   324 
   325 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   326 		!= HandleError_None)
   327 	{
   328 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   329 	}
   330 
   331 	char *key;
   332 	cell_t *addr, *defvalue;
   333 	uint64 value;
   334 	pCtx->LocalToString(params[2], &key);
   335 	pCtx->LocalToPhysAddr(params[3], &addr);
   336 	pCtx->LocalToPhysAddr(params[4], &defvalue);
   337 
   338 	value = pStk->pCurRoot.front()->GetUint64(key, static_cast<uint64>(*defvalue));
   339 	*reinterpret_cast<uint64 *>(addr) = value;
   340 
   341 	return 1;
   342 }
   343 
   344 static cell_t smn_CreateKeyValues(IPluginContext *pCtx, const cell_t *params)
   345 {
   346 	KeyValueStack *pStk;
   347 	char *name, *firstkey, *firstvalue;
   348 	bool is_empty;
   349 
   350 	pCtx->LocalToString(params[1], &name);
   351 	pCtx->LocalToString(params[2], &firstkey);
   352 	pCtx->LocalToString(params[3], &firstvalue);
   353 
   354 	is_empty = (firstkey[0] == '\0');
   355 	pStk = new KeyValueStack;
   356 	pStk->pBase = new KeyValues(name, is_empty ? NULL : firstkey, (is_empty||(firstvalue[0]=='\0')) ? NULL : firstvalue);
   357 	pStk->pCurRoot.push(pStk->pBase);
   358 
   359 	return g_HandleSys.CreateHandle(g_KeyValueType, pStk, pCtx->GetIdentity(), g_pCoreIdent, NULL);
   360 }
   361 
   362 static cell_t smn_KvJumpToKey(IPluginContext *pCtx, const cell_t *params)
   363 {
   364 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   365 	HandleError herr;
   366 	HandleSecurity sec;
   367 	char *name;	
   368 	KeyValueStack *pStk;
   369 
   370 	sec.pOwner = NULL;
   371 	sec.pIdentity = g_pCoreIdent;
   372 
   373 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   374 		!= HandleError_None)
   375 	{
   376 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   377 	}
   378 
   379 	pCtx->LocalToString(params[2], &name);
   380 
   381 	KeyValues *pSubKey = pStk->pBase->FindKey(name, (params[3]) ? true : false);
   382 	if (!pSubKey)
   383 	{
   384 		return 0;
   385 	}
   386 	pStk->pCurRoot.push(pSubKey);
   387 
   388 	return 1;
   389 }
   390 
   391 static cell_t smn_KvJumpFirstSubKey(IPluginContext *pCtx, const cell_t *params)
   392 {
   393 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   394 	HandleError herr;
   395 	HandleSecurity sec;
   396 	KeyValueStack *pStk;
   397 
   398 	sec.pOwner = NULL;
   399 	sec.pIdentity = g_pCoreIdent;
   400 
   401 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   402 		!= HandleError_None)
   403 	{
   404 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   405 	}
   406 
   407 	KeyValues *pSubKey = pStk->pCurRoot.front();
   408 	KeyValues *pFirstSubKey = pSubKey->GetFirstSubKey();
   409 	if (!pFirstSubKey)
   410 	{
   411 		return 0;
   412 	}
   413 	pStk->pCurRoot.push(pFirstSubKey);
   414 
   415 	return 1;
   416 }
   417 
   418 static cell_t smn_KvJumpNextSubKey(IPluginContext *pCtx, const cell_t *params)
   419 {
   420 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   421 	HandleError herr;
   422 	HandleSecurity sec;
   423 	KeyValueStack *pStk;
   424 
   425 	sec.pOwner = NULL;
   426 	sec.pIdentity = g_pCoreIdent;
   427 
   428 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   429 		!= HandleError_None)
   430 	{
   431 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   432 	}
   433 
   434 	KeyValues *pSubKey = pStk->pCurRoot.front();
   435 	KeyValues *pNextKey = pSubKey->GetNextKey();
   436 	if (!pNextKey)
   437 	{
   438 		return 0;
   439 	}
   440 	pStk->pCurRoot.push(pNextKey);
   441 
   442 	return 1;	
   443 }
   444 
   445 static cell_t smn_KvGoBack(IPluginContext *pCtx, const cell_t *params)
   446 {
   447 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   448 	HandleError herr;
   449 	HandleSecurity sec;
   450 	KeyValueStack *pStk;
   451 
   452 	sec.pOwner = NULL;
   453 	sec.pIdentity = g_pCoreIdent;
   454 
   455 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   456 		!= HandleError_None)
   457 	{
   458 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   459 	}
   460 
   461 	if (pStk->pCurRoot.size() == 1)
   462 	{
   463 		return 0;
   464 	}
   465 	pStk->pCurRoot.pop();
   466 
   467 	return 1;
   468 }
   469 
   470 static cell_t smn_KvRewind(IPluginContext *pCtx, const cell_t *params)
   471 {
   472 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   473 	HandleError herr;
   474 	HandleSecurity sec;
   475 	KeyValueStack *pStk;
   476 
   477 	sec.pOwner = NULL;
   478 	sec.pIdentity = g_pCoreIdent;
   479 
   480 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   481 		!= HandleError_None)
   482 	{
   483 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   484 	}
   485 
   486 	while (pStk->pCurRoot.size() > 1)
   487 	{
   488 		pStk->pCurRoot.pop();
   489 	}
   490 
   491 	return 1;
   492 }
   493 
   494 static cell_t smn_KvGetSectionName(IPluginContext *pCtx, const cell_t *params)
   495 {
   496 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   497 	HandleError herr;
   498 	HandleSecurity sec;
   499 	KeyValueStack *pStk;
   500 
   501 	sec.pOwner = NULL;
   502 	sec.pIdentity = g_pCoreIdent;
   503 
   504 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   505 		!= HandleError_None)
   506 	{
   507 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   508 	}
   509 
   510 	KeyValues *pSection = pStk->pCurRoot.front();
   511 	const char *name = pSection->GetName();
   512 	if (!name)
   513 	{
   514 		return 0;
   515 	}
   516 	pCtx->StringToLocalUTF8(params[2], params[3], name, NULL);
   517 
   518 	return 1;
   519 }
   520 
   521 static cell_t smn_KvSetSectionName(IPluginContext *pCtx, const cell_t *params)
   522 {
   523 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   524 	HandleError herr;
   525 	HandleSecurity sec;
   526 	char *name;
   527 	KeyValueStack *pStk;
   528 
   529 	sec.pOwner = NULL;
   530 	sec.pIdentity = g_pCoreIdent;
   531 
   532 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   533 		!= HandleError_None)
   534 	{
   535 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   536 	}
   537 
   538 	pCtx->LocalToString(params[2], &name);
   539 
   540 	KeyValues *pSection = pStk->pCurRoot.front();
   541 	pSection->SetName(name);
   542 
   543 	return 1;
   544 }
   545 
   546 static cell_t smn_KvGetDataType(IPluginContext *pCtx, const cell_t *params)
   547 {
   548 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   549 	HandleError herr;
   550 	HandleSecurity sec;
   551 	char *name;
   552 	KeyValueStack *pStk;
   553 
   554 	sec.pOwner = NULL;
   555 	sec.pIdentity = g_pCoreIdent;
   556 
   557 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   558 		!= HandleError_None)
   559 	{
   560 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   561 	}
   562 
   563 	pCtx->LocalToString(params[2], &name);
   564 
   565 	return pStk->pCurRoot.front()->GetDataType(name);
   566 }
   567 
   568 static cell_t smn_KeyValuesToFile(IPluginContext *pCtx, const cell_t *params)
   569 {
   570 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   571 	HandleError herr;
   572 	HandleSecurity sec;
   573 	char *path;
   574 	KeyValueStack *pStk;
   575 
   576 	sec.pOwner = NULL;
   577 	sec.pIdentity = g_pCoreIdent;
   578 
   579 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   580 		!= HandleError_None)
   581 	{
   582 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   583 	}
   584 
   585 	pCtx->LocalToString(params[2], &path);
   586 
   587 	char realpath[PLATFORM_MAX_PATH];
   588 	g_SourceMod.BuildPath(Path_Game, realpath, sizeof(realpath), "%s", path);
   589 
   590 	return pStk->pCurRoot.front()->SaveToFile(basefilesystem, realpath);
   591 }
   592 
   593 static cell_t smn_FileToKeyValues(IPluginContext *pCtx, const cell_t *params)
   594 {
   595 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   596 	HandleError herr;
   597 	HandleSecurity sec;
   598 	char *path;
   599 	KeyValueStack *pStk;
   600 
   601 	sec.pOwner = NULL;
   602 	sec.pIdentity = g_pCoreIdent;
   603 
   604 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   605 		!= HandleError_None)
   606 	{
   607 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   608 	}
   609 
   610 	pCtx->LocalToString(params[2], &path);
   611 
   612 	char realpath[PLATFORM_MAX_PATH];
   613 	g_SourceMod.BuildPath(Path_Game, realpath, sizeof(realpath), "%s", path);
   614 
   615 	return pStk->pCurRoot.front()->LoadFromFile(basefilesystem, realpath);
   616 }
   617 
   618 static cell_t smn_KvSetEscapeSequences(IPluginContext *pCtx, const cell_t *params)
   619 {
   620 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   621 	HandleError herr;
   622 	HandleSecurity sec;
   623 	KeyValueStack *pStk;
   624 
   625 	sec.pOwner = NULL;
   626 	sec.pIdentity = g_pCoreIdent;
   627 
   628 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   629 		!= HandleError_None)
   630 	{
   631 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   632 	}
   633 
   634 	pStk->pCurRoot.front()->UsesEscapeSequences(params[2] ? true : false);
   635 
   636 	return 1;
   637 }
   638 
   639 static KeyValuekNatives s_KeyValuekNatives;
   640 
   641 REGISTER_NATIVES(keyvaluenatives)
   642 {
   643 	{"KvSetString",				smn_KvSetString},
   644 	{"KvSetNum",				smn_KvSetNum},
   645 	{"KvSetUint64",				smn_KvSetUint64},
   646 	{"KvSetFloat",				smn_KvSetFloat},
   647 	{"KvSetColor",				smn_KvSetColor},
   648 	{"KvGetString",				smn_KvGetString},
   649 	{"KvGetNum",				smn_KvGetNum},
   650 	{"KvGetFloat",				smn_KvGetFloat},
   651 	{"KvGetColor",				smn_KvGetColor},
   652 	{"KvGetUint64",				smn_KvGetUint64},
   653 	{"CreateKeyValues",			smn_CreateKeyValues},
   654 	{"KvJumpToKey",				smn_KvJumpToKey},
   655 	{"KvJumpFirstSubKey",		smn_KvJumpFirstSubKey},
   656 	{"KvJumpNextSubKey",		smn_KvJumpNextSubKey},
   657 	{"KvGoBack",				smn_KvGoBack},
   658 	{"KvRewind",				smn_KvRewind},
   659 	{"KvGetSectionName",		smn_KvGetSectionName},
   660 	{"KvSetSectionName",		smn_KvSetSectionName},
   661 	{"KvGetDataType",			smn_KvGetDataType},
   662 	{"KeyValuesToFile",			smn_KeyValuesToFile},
   663 	{"FileToKeyValues",			smn_FileToKeyValues},
   664 	{"KvSetEscapeSequences",	smn_KvSetEscapeSequences},
   665 	{NULL,						NULL}
   666 };