Remove optional callback parameter from DHookCreateFromConf

Encourage passing the callback when hooking instead of when setting the hook up.
This commit is contained in:
Peace-Maker 2018-04-21 09:43:53 +02:00
parent 556290e088
commit c6266bfcf3
2 changed files with 5 additions and 14 deletions

View File

@ -28,7 +28,7 @@ bool GetHandleIfValidOrError(HandleType_t type, void **object, IPluginContext *p
return true; return true;
} }
IPluginFunction *GetCallback(IPluginContext *pContext, HookSetup * setup, const cell_t *params, unsigned int callback_index) IPluginFunction *GetCallback(IPluginContext *pContext, HookSetup * setup, const cell_t *params, cell_t callback_index)
{ {
IPluginFunction *ret = NULL; IPluginFunction *ret = NULL;
@ -77,7 +77,7 @@ cell_t Native_CreateDetour(IPluginContext *pContext, const cell_t *params)
return hndl; return hndl;
} }
// native Handle:DHookCreateFromConf(Handle:gameconf, const String:function[], DHookCallback:callback=INVALID_FUNCTION); // native Handle:DHookCreateFromConf(Handle:gameconf, const String:function[]);
cell_t Native_DHookCreateFromConf(IPluginContext *pContext, const cell_t *params) cell_t Native_DHookCreateFromConf(IPluginContext *pContext, const cell_t *params)
{ {
IGameConfig *conf; IGameConfig *conf;
@ -96,14 +96,6 @@ cell_t Native_DHookCreateFromConf(IPluginContext *pContext, const cell_t *params
return pContext->ThrowNativeError("Function signature \"%s\" was not found.", function); return pContext->ThrowNativeError("Function signature \"%s\" was not found.", function);
} }
IPluginFunction *callback = nullptr;
if (params[3] != -1)
{
callback = pContext->GetFunctionById(params[3]);
if (!callback)
return pContext->ThrowNativeError("Failed to find callback function.");
}
HookSetup *setup = nullptr; HookSetup *setup = nullptr;
// This is a virtual hook. // This is a virtual hook.
if (sig->offset.length() > 0) if (sig->offset.length() > 0)
@ -114,7 +106,7 @@ cell_t Native_DHookCreateFromConf(IPluginContext *pContext, const cell_t *params
return BAD_HANDLE; return BAD_HANDLE;
} }
setup = new HookSetup(sig->retType, PASSFLAG_BYVAL, sig->hookType, sig->thisType, offset, callback); setup = new HookSetup(sig->retType, PASSFLAG_BYVAL, sig->hookType, sig->thisType, offset, nullptr);
} }
// This is a detour. // This is a detour.
else else
@ -211,7 +203,6 @@ cell_t Native_SetFromConf(IPluginContext *pContext, const cell_t *params)
return 1; return 1;
} }
//native bool:DHookAddParam(Handle:setup, HookParamType:type); OLD
//native bool:DHookAddParam(Handle:setup, HookParamType:type, size=-1, DHookPassFlag:flag=DHookPass_ByVal, DHookRegister custom_register=DHookRegister_Default); //native bool:DHookAddParam(Handle:setup, HookParamType:type, size=-1, DHookPassFlag:flag=DHookPass_ByVal, DHookRegister custom_register=DHookRegister_Default);
cell_t Native_AddParam(IPluginContext *pContext, const cell_t *params) cell_t Native_AddParam(IPluginContext *pContext, const cell_t *params)
{ {

View File

@ -242,12 +242,11 @@ native Handle DHookCreateDetour(Address funcaddr, CallingConvention callConv, Re
* *
* @param gameconf GameConfig handle * @param gameconf GameConfig handle
* @param name Name of the function in the gamedata to load. * @param name Name of the function in the gamedata to load.
* @param callback Callback function (only required for virtual hooks - ignored for detours).
* *
* @return Setup handle for the detour or INVALID_HANDLE if offset/signature/address wasn't found. * @return Setup handle for the detour or INVALID_HANDLE if offset/signature/address wasn't found.
* @error Failed to create detour setup handle, invalid gamedata handle, invalid callback function or failed to find function in gamedata. * @error Failed to create detour setup handle, invalid gamedata handle, invalid callback function or failed to find function in gamedata.
*/ */
native Handle DHookCreateFromConf(Handle gameconf, const char[] name, DHookCallback callback=INVALID_FUNCTION); native Handle DHookCreateFromConf(Handle gameconf, const char[] name);
/** /**
* Load details for a vhook or detour from a gamedata file. * Load details for a vhook or detour from a gamedata file.
@ -572,6 +571,7 @@ public __ext_dhooks_SetNTVOptional()
MarkNativeAsOptional("DHookRemoveEntityListener"); MarkNativeAsOptional("DHookRemoveEntityListener");
MarkNativeAsOptional("DHookCreate"); MarkNativeAsOptional("DHookCreate");
MarkNativeAsOptional("DHookCreateDetour"); MarkNativeAsOptional("DHookCreateDetour");
MarkNativeAsOptional("DHookCreateFromConf");
MarkNativeAsOptional("DHookSetFromConf"); MarkNativeAsOptional("DHookSetFromConf");
MarkNativeAsOptional("DHookEnableDetour"); MarkNativeAsOptional("DHookEnableDetour");
MarkNativeAsOptional("DHookDisableDetour"); MarkNativeAsOptional("DHookDisableDetour");