core/smn_keyvalues.cpp
branchsourcemod-1.1.0
changeset 1715 f9ecab642e25
parent 1401 e3b761515c0a
     1.1 --- a/core/smn_keyvalues.cpp	Sun Nov 11 20:59:20 2007 +0000
     1.2 +++ b/core/smn_keyvalues.cpp	Fri Nov 23 05:10:33 2007 +0000
     1.3 @@ -406,6 +406,33 @@
     1.4  	return 1;
     1.5  }
     1.6  
     1.7 +static cell_t smn_KvJumpToKeySymbol(IPluginContext *pCtx, const cell_t *params)
     1.8 +{
     1.9 +	Handle_t hndl = static_cast<Handle_t>(params[1]);
    1.10 +	HandleError herr;
    1.11 +	HandleSecurity sec;
    1.12 +	KeyValueStack *pStk;
    1.13 +
    1.14 +	sec.pOwner = NULL;
    1.15 +	sec.pIdentity = g_pCoreIdent;
    1.16 +
    1.17 +	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
    1.18 +		!= HandleError_None)
    1.19 +	{
    1.20 +		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
    1.21 +	}
    1.22 +
    1.23 +	KeyValues *pSubKey = pStk->pCurRoot.front();
    1.24 +	pSubKey = pSubKey->FindKey(params[2]);
    1.25 +	if (!pSubKey)
    1.26 +	{
    1.27 +		return 0;
    1.28 +	}
    1.29 +	pStk->pCurRoot.push(pSubKey);
    1.30 +
    1.31 +	return 1;
    1.32 +}
    1.33 +
    1.34  static cell_t smn_KvGotoFirstSubKey(IPluginContext *pCtx, const cell_t *params)
    1.35  {
    1.36  	Handle_t hndl = static_cast<Handle_t>(params[1]);
    1.37 @@ -921,6 +948,36 @@
    1.38  	return 1;
    1.39  }
    1.40  
    1.41 +static cell_t smn_KvGetSectionSymbol(IPluginContext *pCtx, const cell_t *params)
    1.42 +{
    1.43 +	Handle_t hndl = static_cast<Handle_t>(params[1]);
    1.44 +	HandleError herr;
    1.45 +	HandleSecurity sec;
    1.46 +	KeyValueStack *pStk;
    1.47 +	cell_t *val;
    1.48 +
    1.49 +	sec.pOwner = NULL;
    1.50 +	sec.pIdentity = g_pCoreIdent;
    1.51 +
    1.52 +	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
    1.53 +		!= HandleError_None)
    1.54 +	{
    1.55 +		return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
    1.56 +	}
    1.57 +
    1.58 +	KeyValues *pSection = pStk->pCurRoot.front();
    1.59 +
    1.60 +	pCtx->LocalToPhysAddr(params[2], &val);
    1.61 +	*val = pSection->GetNameSymbol();
    1.62 +
    1.63 +	if (!*val)
    1.64 +	{
    1.65 +		return 0;
    1.66 +	}
    1.67 +
    1.68 +	return 1;
    1.69 +}
    1.70 +
    1.71  static KeyValueNatives s_KeyValueNatives;
    1.72  
    1.73  REGISTER_NATIVES(keyvaluenatives)
    1.74 @@ -937,6 +994,7 @@
    1.75  	{"KvGetUInt64",				smn_KvGetUInt64},
    1.76  	{"CreateKeyValues",			smn_CreateKeyValues},
    1.77  	{"KvJumpToKey",				smn_KvJumpToKey},
    1.78 +	{"KvJumpToKeySymbol",		smn_KvJumpToKeySymbol},
    1.79  	{"KvGotoNextKey",			smn_KvGotoNextKey},
    1.80  	{"KvJumpFirstSubKey",		smn_KvGotoFirstSubKey},		/* BACKWARDS COMPAT SHIM */
    1.81  	{"KvGotoFirstSubKey",		smn_KvGotoFirstSubKey},
    1.82 @@ -956,5 +1014,6 @@
    1.83  	{"KvCopySubkeys",			smn_CopySubkeys},
    1.84  	{"KvFindKeyById",			smn_FindKeyById},
    1.85  	{"KvGetNameSymbol",			smn_GetNameSymbol},
    1.86 +	{"KvGetSectionSymbol",		smn_KvGetSectionSymbol},
    1.87  	{NULL,						NULL}
    1.88  };