Add support to define function signatures in gamedata

A "Functions" section is parsed in gamedata files that allow you to define the signature of functions including metadata like the calling convention and specifying the register an argument is passed in.
A new native DHookCreateFromConf can be used to setup a hook or detour from one of that function sections in the "Functions" section.
This commit is contained in:
Peace-Maker
2018-01-25 17:18:30 +01:00
parent e2d71bae03
commit aa3018a27d
10 changed files with 792 additions and 7 deletions
+5 -2
View File
@@ -33,14 +33,17 @@ public void OnPluginStart()
PrintToServer("CFlashbangProjectile::Detonate detoured!");
hFlashbangDeafen = DHookCreateDetour(Address_Null, CallConv_THISCALL, ReturnType_Void, ThisPointer_CBaseEntity);
hFlashbangDeafen = DHookCreateFromConf(temp, "Deafen");
if (!hFlashbangDeafen)
SetFailState("Failed to setup detour for Deafen");
/*hFlashbangDeafen = DHookCreateDetour(Address_Null, CallConv_THISCALL, ReturnType_Void, ThisPointer_CBaseEntity);
if (!hFlashbangDeafen)
SetFailState("Failed to setup detour for Deafen");
if (!DHookSetFromConf(hFlashbangDeafen, temp, SDKConf_Signature, "Deafen"))
SetFailState("Failed to load Deafen signature from gamedata");
DHookAddParam(hFlashbangDeafen, HookParamType_Float, .custom_register=DHookRegister_XMM1);
DHookAddParam(hFlashbangDeafen, HookParamType_Float, .custom_register=DHookRegister_XMM1);*/
if (!DHookEnableDetour(hFlashbangDeafen, false, Detour_OnDeafen))
SetFailState("Failed to detour Deafen.");
+14 -2
View File
@@ -219,7 +219,7 @@ native bool DHookRemoveEntityListener(ListenType type, ListenCB callback);
* @param callback Callback function
*
* @return Returns setup handle for the hook.
* @error Failed to create hook setup handle.
* @error Failed to create hook setup handle or invalid callback function.
*/
native Handle DHookCreate(int offset, HookType hooktype, ReturnType returntype, ThisPointerType thistype, DHookCallback callback);
@@ -237,6 +237,18 @@ native Handle DHookCreate(int offset, HookType hooktype, ReturnType returntype,
*/
native Handle DHookCreateDetour(Address funcaddr, CallingConvention callConv, ReturnType returntype, ThisPointerType thisType);
/**
* Setup a detour or hook for a function as described in a "Functions" section in gamedata.
*
* @param gameconf GameConfig handle
* @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.
* @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);
/**
* Load details for a vhook or detour from a gamedata file.
*
@@ -246,7 +258,7 @@ native Handle DHookCreateDetour(Address funcaddr, CallingConvention callConv, Re
* @param name Name of the property to find.
*
* @return True on success, false if nothing was found.
* @error Invalid setup handle.
* @error Invalid setup or gamedata handle.
*/
native bool DHookSetFromConf(Handle setup, Handle gameconf, SDKFuncConfSource source, const char[] name);