I'm trying to get the address to a function from its caller function, to set up a detour for it. It looks like this:
CNMRiH_GameRules::CleanAndResetMap(void) + E4 == call
CEventQueue::Clear(void)
Both are non-virtual so I'm using
DHooks with Experimental Dynamic Detours. I set up my gamedata to look like this:
PHP Code:
"Games"
{
"nmrih"
{
"Addresses"
{
"CEventQueue::Clear"
{
"windows"
{
"signature" "CNMRiH_GameRules::CleanAndResetMap" //Tells it to use this signature which is in the signatures block
"read" "228" //Tells it to read 228 bytes and get the pointer for what is here
}
//"linux"{}
}
}
"Signatures"
{
/* Used solely to get the offset for CEventQueue::Clear */
"CNMRiH_GameRules::CleanAndResetMap"
{
"library" "server"
"windows" "\x55\x8B\xEC\xA1****\x83\xEC\x24\x83\x78\x30\x00\x56\x57"
"linux" "@_ZN16CNMRiH_GameRules16CleanAndResetMapEv"
}
}
}
}
And this is my script:
PHP Code:
#include <sdktools>
#include <dhooks>
#define DHOOK_PRE false
#define DHOOK_POST true
Handle hClear;
public void OnPluginStart()
{
Handle hGameData = LoadGameConfigFile("EQC.games");
if(!hGameData)
SetFailState("Couldn't find EQC.games gamedata.");
// Setup detour on CEventQueue::Clear
hClear = DHookCreateDetour(Address_Null, CallConv_THISCALL, ReturnType_Void, ThisPointer_Address);
if (!hClear)
SetFailState("Failed to set up detour for CEventQueue::Clear");
// Load the address of the function from EQC's address gamedata file.
if (!DHookSetFromConf(hClear, hGameData, SDKConf_Address, "CEventQueue::Clear"))
SetFailState("Failed to load CEventQueue::Clear address from gamedata");
// Add a pre hook on the function.
if (!DHookEnableDetour(hClear, DHOOK_PRE, Detour_OnEventQueueClear))
SetFailState("Failed to detour CEventQueue::Clear");
PrintToServer("CEventQueue::Clear detoured!");
}
public MRESReturn Detour_OnEventQueueClear(Address pThis, Handle hReturn, Handle hParams)
{
PrintToServer("CEventQueue::Clear called");
//Do stuff
return MRES_Ignored;
}
However, it seems to crash the server the moment I start it.
https://crash.limetech.org/sselqyxocfdi
https://crash.limetech.org/zltfxqe7oabw
Am I doing something wrong here? The signature is confirmed valid
Thanks