From 0513f93f9d7e6e1daaebe0a0dab321a8f9367602 Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Wed, 7 May 2014 12:58:16 -0400 Subject: [PATCH] Add PrepSDKCall_SetAddress and Address support to PrepSDKCall_SetFromConf (bug 5261, r=asherkin). --- extensions/sdktools/vcaller.cpp | 40 ++++++++++++++++++++++++++++----- plugins/include/sdktools.inc | 9 ++++++++ 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/extensions/sdktools/vcaller.cpp b/extensions/sdktools/vcaller.cpp index 962e45b8..9cf6af65 100644 --- a/extensions/sdktools/vcaller.cpp +++ b/extensions/sdktools/vcaller.cpp @@ -155,6 +155,21 @@ static cell_t PrepSDKCall_SetSignature(IPluginContext *pContext, const cell_t *p return (s_call_addr != NULL) ? 1 : 0; } +static cell_t PrepSDKCall_SetAddress(IPluginContext *pContext, const cell_t *params) +{ + s_call_addr = reinterpret_cast(params[1]); + + return (s_call_addr != NULL) ? 1 : 0; +} + +// Must match same enum in sdktools.inc +enum SDKFuncConfSource +{ + SDKConf_Virtual, + SDKConf_Signature, + SDKConf_Address +}; + static cell_t PrepSDKCall_SetFromConf(IPluginContext *pContext, const cell_t *params) { IGameConfig *conf; @@ -173,12 +188,26 @@ static cell_t PrepSDKCall_SetFromConf(IPluginContext *pContext, const cell_t *pa char *key; pContext->LocalToString(params[3], &key); - if (params[2] == 0) + switch (params[2]) { - return conf->GetOffset(key, &s_vtbl_index) ? 1 : 0; - } else if (params[2] == 1) { - bool result = conf->GetMemSig(key, &s_call_addr) ? 1 : 0; - return (result && s_call_addr != NULL) ? 1 : 0; + case SDKConf_Virtual: + if (conf->GetOffset(key, &s_vtbl_index)) + { + return 1; + } + break; + case SDKConf_Signature: + if (conf->GetMemSig(key, &s_call_addr) && s_call_addr) + { + return 1; + } + break; + case SDKConf_Address: + if (conf->GetAddress(key, &s_call_addr) && s_call_addr) + { + return 1; + } + break; } return 0; @@ -477,6 +506,7 @@ sp_nativeinfo_t g_CallNatives[] = {"StartPrepSDKCall", StartPrepSDKCall}, {"PrepSDKCall_SetVirtual", PrepSDKCall_SetVirtual}, {"PrepSDKCall_SetSignature", PrepSDKCall_SetSignature}, + {"PrepSDKCall_SetAddress", PrepSDKCall_SetAddress}, {"PrepSDKCall_SetFromConf", PrepSDKCall_SetFromConf}, {"PrepSDKCall_SetReturnInfo", PrepSDKCall_SetReturnInfo}, {"PrepSDKCall_AddParameter", PrepSDKCall_AddParameter}, diff --git a/plugins/include/sdktools.inc b/plugins/include/sdktools.inc index 1f6337b9..cb9cf78b 100644 --- a/plugins/include/sdktools.inc +++ b/plugins/include/sdktools.inc @@ -72,6 +72,7 @@ enum SDKFuncConfSource { SDKConf_Virtual = 0, /**< Read a virtual index from the Offsets section */ SDKConf_Signature = 1, /**< Read a signature from the Signatures section */ + SDKConf_Address = 2, /**< Read an address from the Addresses section */ }; enum SDKType @@ -130,6 +131,14 @@ native PrepSDKCall_SetVirtual(vtblidx); */ native bool:PrepSDKCall_SetSignature(SDKLibrary:lib, const String:signature[], bytes); +/** + * Uses the given function address for the SDK call. + * + * @param addr Address of function to use. + * @return True on success, false on failure. + */ +native bool:PrepSDKCall_SetAddress(Address:addr); + /** * Finds an address or virtual function index in a GameConfig file and sets it as * the calling information for the SDK call.