Add PrepSDKCall_SetAddress and Address support to PrepSDKCall_SetFromConf (bug 5261, r=asherkin).

This commit is contained in:
Nicholas Hastings 2014-05-07 12:58:16 -04:00
parent b5decd8a50
commit 0513f93f9d
2 changed files with 44 additions and 5 deletions

View File

@ -155,6 +155,21 @@ static cell_t PrepSDKCall_SetSignature(IPluginContext *pContext, const cell_t *p
return (s_call_addr != NULL) ? 1 : 0; return (s_call_addr != NULL) ? 1 : 0;
} }
static cell_t PrepSDKCall_SetAddress(IPluginContext *pContext, const cell_t *params)
{
s_call_addr = reinterpret_cast<void *>(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) static cell_t PrepSDKCall_SetFromConf(IPluginContext *pContext, const cell_t *params)
{ {
IGameConfig *conf; IGameConfig *conf;
@ -173,12 +188,26 @@ static cell_t PrepSDKCall_SetFromConf(IPluginContext *pContext, const cell_t *pa
char *key; char *key;
pContext->LocalToString(params[3], &key); pContext->LocalToString(params[3], &key);
if (params[2] == 0) switch (params[2])
{ {
return conf->GetOffset(key, &s_vtbl_index) ? 1 : 0; case SDKConf_Virtual:
} else if (params[2] == 1) { if (conf->GetOffset(key, &s_vtbl_index))
bool result = conf->GetMemSig(key, &s_call_addr) ? 1 : 0; {
return (result && s_call_addr != NULL) ? 1 : 0; 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; return 0;
@ -477,6 +506,7 @@ sp_nativeinfo_t g_CallNatives[] =
{"StartPrepSDKCall", StartPrepSDKCall}, {"StartPrepSDKCall", StartPrepSDKCall},
{"PrepSDKCall_SetVirtual", PrepSDKCall_SetVirtual}, {"PrepSDKCall_SetVirtual", PrepSDKCall_SetVirtual},
{"PrepSDKCall_SetSignature", PrepSDKCall_SetSignature}, {"PrepSDKCall_SetSignature", PrepSDKCall_SetSignature},
{"PrepSDKCall_SetAddress", PrepSDKCall_SetAddress},
{"PrepSDKCall_SetFromConf", PrepSDKCall_SetFromConf}, {"PrepSDKCall_SetFromConf", PrepSDKCall_SetFromConf},
{"PrepSDKCall_SetReturnInfo", PrepSDKCall_SetReturnInfo}, {"PrepSDKCall_SetReturnInfo", PrepSDKCall_SetReturnInfo},
{"PrepSDKCall_AddParameter", PrepSDKCall_AddParameter}, {"PrepSDKCall_AddParameter", PrepSDKCall_AddParameter},

View File

@ -72,6 +72,7 @@ enum SDKFuncConfSource
{ {
SDKConf_Virtual = 0, /**< Read a virtual index from the Offsets section */ SDKConf_Virtual = 0, /**< Read a virtual index from the Offsets section */
SDKConf_Signature = 1, /**< Read a signature from the Signatures section */ SDKConf_Signature = 1, /**< Read a signature from the Signatures section */
SDKConf_Address = 2, /**< Read an address from the Addresses section */
}; };
enum SDKType enum SDKType
@ -130,6 +131,14 @@ native PrepSDKCall_SetVirtual(vtblidx);
*/ */
native bool:PrepSDKCall_SetSignature(SDKLibrary:lib, const String:signature[], bytes); 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 * Finds an address or virtual function index in a GameConfig file and sets it as
* the calling information for the SDK call. * the calling information for the SDK call.