core/smn_keyvalues.cpp
author David Anderson <dvander@alliedmods.net>
Wed May 02 21:00:13 2007 +0000 (2007-05-02)
changeset 726 95a1d238c482
parent 703 cddbff919185
child 743 a2804c2faba2
permissions -rw-r--r--
fixed a bug where KvJumpToKey did not obey the internal path stack
     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 KeyValueNatives : 
    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->pCurRoot.front();
   382 	pSubKey = pSubKey->FindKey(name, (params[3]) ? true : false);
   383 	if (!pSubKey)
   384 	{
   385 		return 0;
   386 	}
   387 	pStk->pCurRoot.push(pSubKey);
   388 
   389 	return 1;
   390 }
   391 
   392 static cell_t smn_KvJumpFirstSubKey(IPluginContext *pCtx, const cell_t *params)
   393 {
   394 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   395 	HandleError herr;
   396 	HandleSecurity sec;
   397 	KeyValueStack *pStk;
   398 
   399 	sec.pOwner = NULL;
   400 	sec.pIdentity = g_pCoreIdent;
   401 
   402 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   403 		!= HandleError_None)
   404 	{
   405 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   406 	}
   407 
   408 	KeyValues *pSubKey = pStk->pCurRoot.front();
   409 	KeyValues *pFirstSubKey = pSubKey->GetFirstSubKey();
   410 	if (!pFirstSubKey)
   411 	{
   412 		return 0;
   413 	}
   414 	pStk->pCurRoot.push(pFirstSubKey);
   415 
   416 	return 1;
   417 }
   418 
   419 static cell_t smn_KvJumpNextSubKey(IPluginContext *pCtx, const cell_t *params)
   420 {
   421 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   422 	HandleError herr;
   423 	HandleSecurity sec;
   424 	KeyValueStack *pStk;
   425 
   426 	sec.pOwner = NULL;
   427 	sec.pIdentity = g_pCoreIdent;
   428 
   429 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   430 		!= HandleError_None)
   431 	{
   432 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   433 	}
   434 
   435 	KeyValues *pSubKey = pStk->pCurRoot.front();
   436 	KeyValues *pNextKey = pSubKey->GetNextKey();
   437 	if (!pNextKey)
   438 	{
   439 		return 0;
   440 	}
   441 	pStk->pCurRoot.push(pNextKey);
   442 
   443 	return 1;	
   444 }
   445 
   446 static cell_t smn_KvGoBack(IPluginContext *pCtx, const cell_t *params)
   447 {
   448 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   449 	HandleError herr;
   450 	HandleSecurity sec;
   451 	KeyValueStack *pStk;
   452 
   453 	sec.pOwner = NULL;
   454 	sec.pIdentity = g_pCoreIdent;
   455 
   456 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   457 		!= HandleError_None)
   458 	{
   459 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   460 	}
   461 
   462 	if (pStk->pCurRoot.size() == 1)
   463 	{
   464 		return 0;
   465 	}
   466 	pStk->pCurRoot.pop();
   467 
   468 	return 1;
   469 }
   470 
   471 static cell_t smn_KvRewind(IPluginContext *pCtx, const cell_t *params)
   472 {
   473 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   474 	HandleError herr;
   475 	HandleSecurity sec;
   476 	KeyValueStack *pStk;
   477 
   478 	sec.pOwner = NULL;
   479 	sec.pIdentity = g_pCoreIdent;
   480 
   481 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   482 		!= HandleError_None)
   483 	{
   484 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   485 	}
   486 
   487 	while (pStk->pCurRoot.size() > 1)
   488 	{
   489 		pStk->pCurRoot.pop();
   490 	}
   491 
   492 	return 1;
   493 }
   494 
   495 static cell_t smn_KvGetSectionName(IPluginContext *pCtx, const cell_t *params)
   496 {
   497 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   498 	HandleError herr;
   499 	HandleSecurity sec;
   500 	KeyValueStack *pStk;
   501 
   502 	sec.pOwner = NULL;
   503 	sec.pIdentity = g_pCoreIdent;
   504 
   505 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   506 		!= HandleError_None)
   507 	{
   508 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   509 	}
   510 
   511 	KeyValues *pSection = pStk->pCurRoot.front();
   512 	const char *name = pSection->GetName();
   513 	if (!name)
   514 	{
   515 		return 0;
   516 	}
   517 	pCtx->StringToLocalUTF8(params[2], params[3], name, NULL);
   518 
   519 	return 1;
   520 }
   521 
   522 static cell_t smn_KvSetSectionName(IPluginContext *pCtx, const cell_t *params)
   523 {
   524 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   525 	HandleError herr;
   526 	HandleSecurity sec;
   527 	char *name;
   528 	KeyValueStack *pStk;
   529 
   530 	sec.pOwner = NULL;
   531 	sec.pIdentity = g_pCoreIdent;
   532 
   533 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   534 		!= HandleError_None)
   535 	{
   536 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   537 	}
   538 
   539 	pCtx->LocalToString(params[2], &name);
   540 
   541 	KeyValues *pSection = pStk->pCurRoot.front();
   542 	pSection->SetName(name);
   543 
   544 	return 1;
   545 }
   546 
   547 static cell_t smn_KvGetDataType(IPluginContext *pCtx, const cell_t *params)
   548 {
   549 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   550 	HandleError herr;
   551 	HandleSecurity sec;
   552 	char *name;
   553 	KeyValueStack *pStk;
   554 
   555 	sec.pOwner = NULL;
   556 	sec.pIdentity = g_pCoreIdent;
   557 
   558 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   559 		!= HandleError_None)
   560 	{
   561 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   562 	}
   563 
   564 	pCtx->LocalToString(params[2], &name);
   565 
   566 	return pStk->pCurRoot.front()->GetDataType(name);
   567 }
   568 
   569 static cell_t smn_KeyValuesToFile(IPluginContext *pCtx, const cell_t *params)
   570 {
   571 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   572 	HandleError herr;
   573 	HandleSecurity sec;
   574 	char *path;
   575 	KeyValueStack *pStk;
   576 
   577 	sec.pOwner = NULL;
   578 	sec.pIdentity = g_pCoreIdent;
   579 
   580 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   581 		!= HandleError_None)
   582 	{
   583 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   584 	}
   585 
   586 	pCtx->LocalToString(params[2], &path);
   587 
   588 	char realpath[PLATFORM_MAX_PATH];
   589 	g_SourceMod.BuildPath(Path_Game, realpath, sizeof(realpath), "%s", path);
   590 
   591 	return pStk->pCurRoot.front()->SaveToFile(basefilesystem, realpath);
   592 }
   593 
   594 static cell_t smn_FileToKeyValues(IPluginContext *pCtx, const cell_t *params)
   595 {
   596 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   597 	HandleError herr;
   598 	HandleSecurity sec;
   599 	char *path;
   600 	KeyValueStack *pStk;
   601 
   602 	sec.pOwner = NULL;
   603 	sec.pIdentity = g_pCoreIdent;
   604 
   605 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   606 		!= HandleError_None)
   607 	{
   608 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   609 	}
   610 
   611 	pCtx->LocalToString(params[2], &path);
   612 
   613 	char realpath[PLATFORM_MAX_PATH];
   614 	g_SourceMod.BuildPath(Path_Game, realpath, sizeof(realpath), "%s", path);
   615 
   616 	return pStk->pCurRoot.front()->LoadFromFile(basefilesystem, realpath);
   617 }
   618 
   619 static cell_t smn_KvSetEscapeSequences(IPluginContext *pCtx, const cell_t *params)
   620 {
   621 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   622 	HandleError herr;
   623 	HandleSecurity sec;
   624 	KeyValueStack *pStk;
   625 
   626 	sec.pOwner = NULL;
   627 	sec.pIdentity = g_pCoreIdent;
   628 
   629 	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
   630 		!= HandleError_None)
   631 	{
   632 		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
   633 	}
   634 
   635 	pStk->pCurRoot.front()->UsesEscapeSequences(params[2] ? true : false);
   636 
   637 	return 1;
   638 }
   639 
   640 static KeyValueNatives s_KeyValueNatives;
   641 
   642 REGISTER_NATIVES(keyvaluenatives)
   643 {
   644 	{"KvSetString",				smn_KvSetString},
   645 	{"KvSetNum",				smn_KvSetNum},
   646 	{"KvSetUint64",				smn_KvSetUint64},
   647 	{"KvSetFloat",				smn_KvSetFloat},
   648 	{"KvSetColor",				smn_KvSetColor},
   649 	{"KvGetString",				smn_KvGetString},
   650 	{"KvGetNum",				smn_KvGetNum},
   651 	{"KvGetFloat",				smn_KvGetFloat},
   652 	{"KvGetColor",				smn_KvGetColor},
   653 	{"KvGetUint64",				smn_KvGetUint64},
   654 	{"CreateKeyValues",			smn_CreateKeyValues},
   655 	{"KvJumpToKey",				smn_KvJumpToKey},
   656 	{"KvJumpFirstSubKey",		smn_KvJumpFirstSubKey},
   657 	{"KvJumpNextSubKey",		smn_KvJumpNextSubKey},
   658 	{"KvGoBack",				smn_KvGoBack},
   659 	{"KvRewind",				smn_KvRewind},
   660 	{"KvGetSectionName",		smn_KvGetSectionName},
   661 	{"KvSetSectionName",		smn_KvSetSectionName},
   662 	{"KvGetDataType",			smn_KvGetDataType},
   663 	{"KeyValuesToFile",			smn_KeyValuesToFile},
   664 	{"FileToKeyValues",			smn_FileToKeyValues},
   665 	{"KvSetEscapeSequences",	smn_KvSetEscapeSequences},
   666 	{NULL,						NULL}
   667 };