View Single Post
Author Message
Addie
Junior Member
Join Date: Nov 2018
Old 11-09-2018 , 03:24   Crash on DHook detouring (dhooks.ext.dll + 0xc3e0)
Reply With Quote #1

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_NullCallConv_THISCALLReturnType_VoidThisPointer_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(hClearhGameDataSDKConf_Address"CEventQueue::Clear"))
        
SetFailState("Failed to load CEventQueue::Clear address from gamedata");
    
    
// Add a pre hook on the function.
    
if (!DHookEnableDetour(hClearDHOOK_PREDetour_OnEventQueueClear))
        
SetFailState("Failed to detour CEventQueue::Clear");
    
    
PrintToServer("CEventQueue::Clear detoured!");
}

public 
MRESReturn Detour_OnEventQueueClear(Address pThisHandle hReturnHandle 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

Last edited by Addie; 11-09-2018 at 22:14.
Addie is offline