Initial Import of beta structs extension.
3 * =============================================================================
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #include "sourcemod.h"
33 #include "sourcemm_api.h"
34 #include "sm_stringutil.h"
35 #include "HandleSys.h"
36 #include "HalfLife2.h"
37 #include <KeyValues.h>
38 #include "utlbuffer.h"
40 HandleType_t g_KeyValueType;
45 CStack<KeyValues *> pCurRoot;
48 class KeyValueNatives :
50 public IHandleTypeDispatch
53 void OnSourceModAllInitialized()
55 g_KeyValueType = g_HandleSys.CreateType("KeyValues", this, 0, NULL, NULL, g_pCoreIdent, NULL);
57 void OnSourceModShutdown()
59 g_HandleSys.RemoveType(g_KeyValueType, g_pCoreIdent);
62 void OnHandleDestroy(HandleType_t type, void *object)
64 KeyValueStack *pStk = reinterpret_cast<KeyValueStack *>(object);
65 pStk->pBase->deleteThis();
68 int CalcKVSizeR(KeyValues *pv)
73 pv->RecursiveSaveToFile(buf, 0);
74 size = buf.TellMaxPut();
80 bool GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize)
82 KeyValueStack *pStk = (KeyValueStack *)object;
83 unsigned int size = sizeof(KeyValueStack) + (pStk->pCurRoot.size() * sizeof(KeyValues *));
85 /* Check how much memory the actual thing takes up */
86 size += CalcKVSizeR(pStk->pBase);
94 KeyValues *SourceModBase::ReadKeyValuesHandle(Handle_t hndl, HandleError *err, bool root)
101 sec.pIdentity = g_pCoreIdent;
103 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
115 *err = HandleError_None;
118 return (root) ? pStk->pBase : pStk->pCurRoot.front();
121 static cell_t smn_KvSetString(IPluginContext *pCtx, const cell_t *params)
123 Handle_t hndl = static_cast<Handle_t>(params[1]);
129 sec.pIdentity = g_pCoreIdent;
131 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
134 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
138 pCtx->LocalToStringNULL(params[2], &key);
139 pCtx->LocalToString(params[3], &value);
141 pStk->pCurRoot.front()->SetString(key, value);
146 static cell_t smn_KvSetNum(IPluginContext *pCtx, const cell_t *params)
148 Handle_t hndl = static_cast<Handle_t>(params[1]);
154 sec.pIdentity = g_pCoreIdent;
156 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
159 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
163 pCtx->LocalToStringNULL(params[2], &key);
165 pStk->pCurRoot.front()->SetInt(key, params[3]);
170 static cell_t smn_KvSetUInt64(IPluginContext *pCtx, const cell_t *params)
172 Handle_t hndl = static_cast<Handle_t>(params[1]);
178 sec.pIdentity = g_pCoreIdent;
180 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
183 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
189 pCtx->LocalToStringNULL(params[2], &key);
190 pCtx->LocalToPhysAddr(params[3], &addr);
192 value = static_cast<uint64>(*addr);
193 pStk->pCurRoot.front()->SetUint64(key, value);
198 static cell_t smn_KvSetFloat(IPluginContext *pCtx, const cell_t *params)
200 Handle_t hndl = static_cast<Handle_t>(params[1]);
206 sec.pIdentity = g_pCoreIdent;
208 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
211 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
215 pCtx->LocalToStringNULL(params[2], &key);
217 pStk->pCurRoot.front()->SetFloat(key, sp_ctof(params[3]));
222 static cell_t smn_KvSetColor(IPluginContext *pCtx, const cell_t *params)
224 Handle_t hndl = static_cast<Handle_t>(params[1]);
230 sec.pIdentity = g_pCoreIdent;
232 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
235 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
239 pCtx->LocalToStringNULL(params[2], &key);
241 Color color(params[3], params[4], params[5], params[6]);
242 pStk->pCurRoot.front()->SetColor(key, color);
247 static cell_t smn_KvSetVector(IPluginContext *pCtx, const cell_t *params)
249 Handle_t hndl = static_cast<Handle_t>(params[1]);
255 sec.pIdentity = g_pCoreIdent;
257 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
260 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
266 pCtx->LocalToStringNULL(params[2], &key);
267 pCtx->LocalToPhysAddr(params[3], &vector);
269 UTIL_Format(buffer, sizeof(buffer), "%f %f %f", sp_ctof(vector[0]), sp_ctof(vector[1]), sp_ctof(vector[2]));
271 pStk->pCurRoot.front()->SetString(key, buffer);
276 static cell_t smn_KvGetString(IPluginContext *pCtx, const cell_t *params)
278 Handle_t hndl = static_cast<Handle_t>(params[1]);
284 sec.pIdentity = g_pCoreIdent;
286 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
289 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
293 char *key, *defvalue;
294 pCtx->LocalToStringNULL(params[2], &key);
295 pCtx->LocalToString(params[5], &defvalue);
297 value = pStk->pCurRoot.front()->GetString(key, defvalue);
298 pCtx->StringToLocalUTF8(params[3], params[4], value, NULL);
303 static cell_t smn_KvGetNum(IPluginContext *pCtx, const cell_t *params)
305 Handle_t hndl = static_cast<Handle_t>(params[1]);
311 sec.pIdentity = g_pCoreIdent;
313 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
316 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
321 pCtx->LocalToStringNULL(params[2], &key);
323 value = pStk->pCurRoot.front()->GetInt(key, params[3]);
328 static cell_t smn_KvGetFloat(IPluginContext *pCtx, const cell_t *params)
330 Handle_t hndl = static_cast<Handle_t>(params[1]);
336 sec.pIdentity = g_pCoreIdent;
338 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
341 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
346 pCtx->LocalToStringNULL(params[2], &key);
348 value = pStk->pCurRoot.front()->GetFloat(key, sp_ctof(params[3]));
350 return sp_ftoc(value);
353 static cell_t smn_KvGetColor(IPluginContext *pCtx, const cell_t *params)
355 Handle_t hndl = static_cast<Handle_t>(params[1]);
361 sec.pIdentity = g_pCoreIdent;
363 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
366 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
371 cell_t *r, *g, *b, *a;
372 pCtx->LocalToStringNULL(params[2], &key);
373 pCtx->LocalToPhysAddr(params[3], &r);
374 pCtx->LocalToPhysAddr(params[4], &g);
375 pCtx->LocalToPhysAddr(params[5], &b);
376 pCtx->LocalToPhysAddr(params[6], &a);
378 color = pStk->pCurRoot.front()->GetColor(key);
387 static cell_t smn_KvGetUInt64(IPluginContext *pCtx, const cell_t *params)
389 Handle_t hndl = static_cast<Handle_t>(params[1]);
395 sec.pIdentity = g_pCoreIdent;
397 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
400 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
404 cell_t *addr, *defvalue;
406 pCtx->LocalToStringNULL(params[2], &key);
407 pCtx->LocalToPhysAddr(params[3], &addr);
408 pCtx->LocalToPhysAddr(params[4], &defvalue);
410 value = pStk->pCurRoot.front()->GetUint64(key, static_cast<uint64>(*defvalue));
411 *reinterpret_cast<uint64 *>(addr) = value;
416 static cell_t smn_KvGetVector(IPluginContext *pCtx, const cell_t *params)
418 Handle_t hndl = static_cast<Handle_t>(params[1]);
424 sec.pIdentity = g_pCoreIdent;
426 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
429 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
434 cell_t *defvector, *outvector;
436 pCtx->LocalToStringNULL(params[2], &key);
437 pCtx->LocalToPhysAddr(params[3], &outvector);
438 pCtx->LocalToPhysAddr(params[4], &defvector);
440 UTIL_Format(buffer, sizeof(buffer), "%f %f %f", sp_ctof(defvector[0]), sp_ctof(defvector[1]), sp_ctof(defvector[2]));
442 value = pStk->pCurRoot.front()->GetString(key, buffer);
446 while (*value && components < 3)
448 while ((*value) && (*value == ' '))
465 for (; *value && isdigit(*value); ++value)
475 for (; *value && isdigit(*value); ++value)
477 out += (*value - '0') * factor;
482 out = (isnegative) ? -out : out;
483 outvector[components++] = sp_ftoc(out);
489 static cell_t smn_CreateKeyValues(IPluginContext *pCtx, const cell_t *params)
492 char *name, *firstkey, *firstvalue;
495 pCtx->LocalToString(params[1], &name);
496 pCtx->LocalToString(params[2], &firstkey);
497 pCtx->LocalToString(params[3], &firstvalue);
499 is_empty = (firstkey[0] == '\0');
500 pStk = new KeyValueStack;
501 pStk->pBase = new KeyValues(name, is_empty ? NULL : firstkey, (is_empty||(firstvalue[0]=='\0')) ? NULL : firstvalue);
502 pStk->pCurRoot.push(pStk->pBase);
504 return g_HandleSys.CreateHandle(g_KeyValueType, pStk, pCtx->GetIdentity(), g_pCoreIdent, NULL);
507 static cell_t smn_KvJumpToKey(IPluginContext *pCtx, const cell_t *params)
509 Handle_t hndl = static_cast<Handle_t>(params[1]);
516 sec.pIdentity = g_pCoreIdent;
518 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
521 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
524 pCtx->LocalToString(params[2], &name);
526 KeyValues *pSubKey = pStk->pCurRoot.front();
527 pSubKey = pSubKey->FindKey(name, (params[3]) ? true : false);
532 pStk->pCurRoot.push(pSubKey);
537 static cell_t smn_KvJumpToKeySymbol(IPluginContext *pCtx, const cell_t *params)
539 Handle_t hndl = static_cast<Handle_t>(params[1]);
545 sec.pIdentity = g_pCoreIdent;
547 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
550 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
553 KeyValues *pSubKey = pStk->pCurRoot.front();
554 pSubKey = pSubKey->FindKey(params[2]);
559 pStk->pCurRoot.push(pSubKey);
564 static cell_t smn_KvGotoFirstSubKey(IPluginContext *pCtx, const cell_t *params)
566 Handle_t hndl = static_cast<Handle_t>(params[1]);
572 sec.pIdentity = g_pCoreIdent;
574 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
577 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
580 KeyValues *pSubKey = pStk->pCurRoot.front();
581 KeyValues *pFirstSubKey;
584 pFirstSubKey = pSubKey->GetFirstTrueSubKey();
586 pFirstSubKey = pSubKey->GetFirstSubKey();
593 pStk->pCurRoot.push(pFirstSubKey);
598 static cell_t smn_KvGotoNextKey(IPluginContext *pCtx, const cell_t *params)
600 Handle_t hndl = static_cast<Handle_t>(params[1]);
606 sec.pIdentity = g_pCoreIdent;
608 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
611 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
614 KeyValues *pSubKey = pStk->pCurRoot.front();
617 pSubKey = pSubKey->GetNextTrueSubKey();
619 pSubKey = pSubKey->GetNextKey();
625 pStk->pCurRoot.pop();
626 pStk->pCurRoot.push(pSubKey);
631 static cell_t smn_KvGoBack(IPluginContext *pCtx, const cell_t *params)
633 Handle_t hndl = static_cast<Handle_t>(params[1]);
639 sec.pIdentity = g_pCoreIdent;
641 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
644 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
647 if (pStk->pCurRoot.size() == 1)
651 pStk->pCurRoot.pop();
656 static cell_t smn_KvRewind(IPluginContext *pCtx, const cell_t *params)
658 Handle_t hndl = static_cast<Handle_t>(params[1]);
664 sec.pIdentity = g_pCoreIdent;
666 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
669 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
672 while (pStk->pCurRoot.size() > 1)
674 pStk->pCurRoot.pop();
680 static cell_t smn_KvGetSectionName(IPluginContext *pCtx, const cell_t *params)
682 Handle_t hndl = static_cast<Handle_t>(params[1]);
688 sec.pIdentity = g_pCoreIdent;
690 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
693 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
696 KeyValues *pSection = pStk->pCurRoot.front();
697 const char *name = pSection->GetName();
702 pCtx->StringToLocalUTF8(params[2], params[3], name, NULL);
707 static cell_t smn_KvSetSectionName(IPluginContext *pCtx, const cell_t *params)
709 Handle_t hndl = static_cast<Handle_t>(params[1]);
716 sec.pIdentity = g_pCoreIdent;
718 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
721 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
724 pCtx->LocalToString(params[2], &name);
726 KeyValues *pSection = pStk->pCurRoot.front();
727 pSection->SetName(name);
732 static cell_t smn_KvGetDataType(IPluginContext *pCtx, const cell_t *params)
734 Handle_t hndl = static_cast<Handle_t>(params[1]);
741 sec.pIdentity = g_pCoreIdent;
743 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
746 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
749 pCtx->LocalToString(params[2], &name);
751 return pStk->pCurRoot.front()->GetDataType(name);
754 static cell_t smn_KeyValuesToFile(IPluginContext *pCtx, const cell_t *params)
756 Handle_t hndl = static_cast<Handle_t>(params[1]);
763 sec.pIdentity = g_pCoreIdent;
765 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
768 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
771 pCtx->LocalToString(params[2], &path);
773 char realpath[PLATFORM_MAX_PATH];
774 g_SourceMod.BuildPath(Path_Game, realpath, sizeof(realpath), "%s", path);
776 return pStk->pCurRoot.front()->SaveToFile(basefilesystem, realpath);
779 static cell_t smn_FileToKeyValues(IPluginContext *pCtx, const cell_t *params)
781 Handle_t hndl = static_cast<Handle_t>(params[1]);
789 sec.pIdentity = g_pCoreIdent;
791 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
794 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
797 pCtx->LocalToString(params[2], &path);
799 char realpath[PLATFORM_MAX_PATH];
800 g_SourceMod.BuildPath(Path_Game, realpath, sizeof(realpath), "%s", path);
802 kv = pStk->pCurRoot.front();
803 return g_HL2.KVLoadFromFile(kv, basefilesystem, realpath);
806 static cell_t smn_KvSetEscapeSequences(IPluginContext *pCtx, const cell_t *params)
808 Handle_t hndl = static_cast<Handle_t>(params[1]);
814 sec.pIdentity = g_pCoreIdent;
816 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
819 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
822 pStk->pCurRoot.front()->UsesEscapeSequences(params[2] ? true : false);
827 static cell_t smn_KvNodesInStack(IPluginContext *pCtx, const cell_t *params)
829 Handle_t hndl = static_cast<Handle_t>(params[1]);
835 sec.pIdentity = g_pCoreIdent;
837 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
840 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
843 return pStk->pCurRoot.size() - 1;
846 static cell_t smn_KvDeleteThis(IPluginContext *pContext, const cell_t *params)
848 Handle_t hndl = static_cast<Handle_t>(params[1]);
854 sec.pIdentity = g_pCoreIdent;
856 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
859 return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
862 if (pStk->pCurRoot.size() < 2)
867 KeyValues *pValues = pStk->pCurRoot.front();
868 pStk->pCurRoot.pop();
869 KeyValues *pRoot = pStk->pCurRoot.front();
871 /* We have to manually verify this since Valve sucks
872 * :TODO: make our own KeyValues.h file and make
873 * the sub stuff private so we can do this ourselves!
875 KeyValues *sub = pRoot->GetFirstSubKey();
880 KeyValues *pNext = pValues->GetNextKey();
881 pRoot->RemoveSubKey(pValues);
882 pValues->deleteThis();
885 pStk->pCurRoot.push(pNext);
891 sub = sub->GetNextKey();
894 /* Push this back on :( */
895 pStk->pCurRoot.push(pValues);
900 static cell_t smn_KvDeleteKey(IPluginContext *pContext, const cell_t *params)
902 Handle_t hndl = static_cast<Handle_t>(params[1]);
908 sec.pIdentity = g_pCoreIdent;
910 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
913 return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
916 if (pStk->pCurRoot.size() < 2)
922 pContext->LocalToString(params[2], &keyName);
924 KeyValues *pRoot = pStk->pCurRoot.front();
925 KeyValues *pValues = pRoot->FindKey(keyName);
931 pRoot->RemoveSubKey(pValues);
932 pValues->deleteThis();
937 static cell_t smn_KvSavePosition(IPluginContext *pContext, const cell_t *params)
939 Handle_t hndl = static_cast<Handle_t>(params[1]);
945 sec.pIdentity = g_pCoreIdent;
947 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
950 return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
953 if (pStk->pCurRoot.size() < 2)
958 KeyValues *pValues = pStk->pCurRoot.front();
959 pStk->pCurRoot.push(pValues);
964 static cell_t smn_CopySubkeys(IPluginContext *pContext, const cell_t *params)
966 Handle_t hndl_copied = static_cast<Handle_t>(params[1]);
967 Handle_t hndl_parent = static_cast<Handle_t>(params[2]);
970 KeyValueStack *pStk_copied, *pStk_parent;
973 sec.pIdentity = g_pCoreIdent;
975 if ((herr=g_HandleSys.ReadHandle(hndl_copied, g_KeyValueType, &sec, (void **)&pStk_copied))
978 return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl_copied, herr);
980 if ((herr=g_HandleSys.ReadHandle(hndl_parent, g_KeyValueType, &sec, (void **)&pStk_parent))
983 return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl_parent, herr);
986 pStk_copied->pCurRoot.front()->CopySubkeys(pStk_parent->pCurRoot.front());
991 static cell_t smn_GetNameSymbol(IPluginContext *pContext, const cell_t *params)
993 Handle_t hndl = static_cast<Handle_t>(params[1]);
1001 sec.pIdentity = g_pCoreIdent;
1003 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
1004 != HandleError_None)
1006 return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
1009 if (pStk->pCurRoot.size() < 2)
1014 pContext->LocalToString(params[2], &key);
1016 KeyValues *pKv = pStk->pCurRoot.front()->FindKey(key);
1021 pContext->LocalToPhysAddr(params[3], &val);
1022 *val = pKv->GetNameSymbol();
1027 static cell_t smn_FindKeyById(IPluginContext *pContext, const cell_t *params)
1029 Handle_t hndl = static_cast<Handle_t>(params[1]);
1032 KeyValueStack *pStk;
1035 sec.pIdentity = g_pCoreIdent;
1037 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
1038 != HandleError_None)
1040 return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
1043 KeyValues *pKv = pStk->pCurRoot.front()->FindKey(params[2]);
1049 pContext->StringToLocalUTF8(params[3], params[4], pKv->GetName(), NULL);
1054 static cell_t smn_KvGetSectionSymbol(IPluginContext *pCtx, const cell_t *params)
1056 Handle_t hndl = static_cast<Handle_t>(params[1]);
1059 KeyValueStack *pStk;
1063 sec.pIdentity = g_pCoreIdent;
1065 if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
1066 != HandleError_None)
1068 return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
1071 KeyValues *pSection = pStk->pCurRoot.front();
1073 pCtx->LocalToPhysAddr(params[2], &val);
1074 *val = pSection->GetNameSymbol();
1084 static KeyValueNatives s_KeyValueNatives;
1086 REGISTER_NATIVES(keyvaluenatives)
1088 {"KvSetString", smn_KvSetString},
1089 {"KvSetNum", smn_KvSetNum},
1090 {"KvSetUInt64", smn_KvSetUInt64},
1091 {"KvSetFloat", smn_KvSetFloat},
1092 {"KvSetColor", smn_KvSetColor},
1093 {"KvGetString", smn_KvGetString},
1094 {"KvGetNum", smn_KvGetNum},
1095 {"KvGetFloat", smn_KvGetFloat},
1096 {"KvGetColor", smn_KvGetColor},
1097 {"KvGetUInt64", smn_KvGetUInt64},
1098 {"CreateKeyValues", smn_CreateKeyValues},
1099 {"KvJumpToKey", smn_KvJumpToKey},
1100 {"KvJumpToKeySymbol", smn_KvJumpToKeySymbol},
1101 {"KvGotoNextKey", smn_KvGotoNextKey},
1102 {"KvGotoFirstSubKey", smn_KvGotoFirstSubKey},
1103 {"KvGoBack", smn_KvGoBack},
1104 {"KvRewind", smn_KvRewind},
1105 {"KvGetSectionName", smn_KvGetSectionName},
1106 {"KvSetSectionName", smn_KvSetSectionName},
1107 {"KvGetDataType", smn_KvGetDataType},
1108 {"KeyValuesToFile", smn_KeyValuesToFile},
1109 {"FileToKeyValues", smn_FileToKeyValues},
1110 {"KvSetEscapeSequences", smn_KvSetEscapeSequences},
1111 {"KvDeleteThis", smn_KvDeleteThis},
1112 {"KvDeleteKey", smn_KvDeleteKey},
1113 {"KvNodesInStack", smn_KvNodesInStack},
1114 {"KvSavePosition", smn_KvSavePosition},
1115 {"KvCopySubkeys", smn_CopySubkeys},
1116 {"KvFindKeyById", smn_FindKeyById},
1117 {"KvGetNameSymbol", smn_GetNameSymbol},
1118 {"KvGetSectionSymbol", smn_KvGetSectionSymbol},
1119 {"KvGetVector", smn_KvGetVector},
1120 {"KvSetVector", smn_KvSetVector},