From 19c184aefc21f6a2987e722cf5776c2af2b16909 Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Wed, 21 Nov 2007 20:58:00 +0000 Subject: [PATCH] Added KvGetSectionSymbol --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401715 --- core/smn_keyvalues.cpp | 31 +++++++++++++++++++++++++++++++ plugins/include/keyvalues.inc | 10 ++++++++++ 2 files changed, 41 insertions(+) diff --git a/core/smn_keyvalues.cpp b/core/smn_keyvalues.cpp index f5ff470c..f87ee7e7 100644 --- a/core/smn_keyvalues.cpp +++ b/core/smn_keyvalues.cpp @@ -948,6 +948,36 @@ static cell_t smn_FindKeyById(IPluginContext *pContext, const cell_t *params) return 1; } +static cell_t smn_KvGetSectionSymbol(IPluginContext *pCtx, const cell_t *params) +{ + Handle_t hndl = static_cast(params[1]); + HandleError herr; + HandleSecurity sec; + KeyValueStack *pStk; + cell_t *val; + + 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 *pSection = pStk->pCurRoot.front(); + + pContext->LocalToPhysAddr(params[2], &val); + *val = pSection->GetNameSymbol(); + + if (!*val) + { + return 0; + } + + return 1; +} + static KeyValueNatives s_KeyValueNatives; REGISTER_NATIVES(keyvaluenatives) @@ -984,5 +1014,6 @@ REGISTER_NATIVES(keyvaluenatives) {"KvCopySubkeys", smn_CopySubkeys}, {"KvFindKeyById", smn_FindKeyById}, {"KvGetNameSymbol", smn_GetNameSymbol}, + {"KvGetSectionSymbol", smn_KvGetSectionSymbol}, {NULL, NULL} }; diff --git a/plugins/include/keyvalues.inc b/plugins/include/keyvalues.inc index bd8804c8..deb21e6c 100644 --- a/plugins/include/keyvalues.inc +++ b/plugins/include/keyvalues.inc @@ -394,3 +394,13 @@ native bool:KvFindKeyById(Handle:kv, id, String:name[], maxlength); * @error Invalid Handle. */ native bool:KvGetNameSymbol(Handle:kv, const String:key[], &id); + +/** + * Retrieves the current section id. + * + * @param kv KeyValues Handle. + * @param id Id of the current section. + * @return True on success, false on failure. + * @error Invalid Handle. + */ +native bool:KvGetSectionSymbol(Handle:kv, &id);