From 64a07ce1980ff9837ee7bbc65b51848355b071a0 Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Wed, 21 Nov 2007 06:49:40 +0000 Subject: [PATCH] added new native KvJumpToKeySymbol --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401713 --- core/smn_keyvalues.cpp | 29 +++++++++++++++++++++++++++++ plugins/include/keyvalues.inc | 9 +++++++++ 2 files changed, 38 insertions(+) diff --git a/core/smn_keyvalues.cpp b/core/smn_keyvalues.cpp index 3ffad068..ef18e36d 100644 --- a/core/smn_keyvalues.cpp +++ b/core/smn_keyvalues.cpp @@ -406,6 +406,34 @@ static cell_t smn_KvJumpToKey(IPluginContext *pCtx, const cell_t *params) return 1; } +static cell_t smn_KvJumpToKeySymbol(IPluginContext *pCtx, const cell_t *params) +{ + Handle_t hndl = static_cast(params[1]); + HandleError herr; + HandleSecurity sec; + char *name; + KeyValueStack *pStk; + + sec.pOwner = NULL; + sec.pIdentity = g_pCoreIdent; + + if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk)) + != HandleError_None) + { + return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr); + } + + KeyValues *pSubKey = pStk->pCurRoot.front(); + pSubKey = pSubKey->FindKey(params[2]); + if (!pSubKey) + { + return 0; + } + pStk->pCurRoot.push(pSubKey); + + return 1; +} + static cell_t smn_KvGotoFirstSubKey(IPluginContext *pCtx, const cell_t *params) { Handle_t hndl = static_cast(params[1]); @@ -937,6 +965,7 @@ REGISTER_NATIVES(keyvaluenatives) {"KvGetUInt64", smn_KvGetUInt64}, {"CreateKeyValues", smn_CreateKeyValues}, {"KvJumpToKey", smn_KvJumpToKey}, + {"KvJumpToKeySymbol", smn_KvJumpToKeySymbol}, {"KvGotoNextKey", smn_KvGotoNextKey}, {"KvJumpFirstSubKey", smn_KvGotoFirstSubKey}, /* BACKWARDS COMPAT SHIM */ {"KvGotoFirstSubKey", smn_KvGotoFirstSubKey}, diff --git a/plugins/include/keyvalues.inc b/plugins/include/keyvalues.inc index 715ddc44..bd8804c8 100644 --- a/plugins/include/keyvalues.inc +++ b/plugins/include/keyvalues.inc @@ -191,6 +191,15 @@ native KvGetUInt64(Handle:kv, const String:key[], value[2], defvalue[2]={0,0}); */ native bool:KvJumpToKey(Handle:kv, const String:key[], bool:create=false); +/** + * Sets the current position in the KeyValues tree to the given key. + * + * @param kv KeyValues Handle. + * @param id KeyValues id. + * @return True if the key exists, false if it does not. + */ +native bool:KvJumpToKeySymbol(Handle:kv, id); + /** * Sets the current position in the KeyValues tree to the first sub key. * This native adds to the internal traversal stack.