I'm trying to prevent the execution of:
PHP Code:
void __cdecl Bot_RunAll()
using DHooks with Experimental Detours.
I successfully create the detour and simply return MRES_Supercede. Code below:
Spoiler
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <dhooks>
#define DHOOK_POST true
#define DHOOK_PRE false
public void OnPluginStart()
{
static const char config_name[] = "bots.games";
Handle gameconf = LoadGameConfigFile(config_name);
if (!gameconf)
{
SetFailState("Missing gamedata file: %s", config_name);
}
Handle hRunAll = DHookCreateFromConfOrFail(gameconf, "Bot_RunAll");
if (!DHookEnableDetour(hRunAll, DHOOK_PRE, Detour_Bot_RunAll))
{
LogError("Failed to detour Bot_RunAll");
}
}
Handle DHookCreateFromConfOrFail(Handle gameconf, const char[] key)
{
Handle result = DHookCreateFromConf(gameconf, key);
if (!result)
{
CloseHandle(gameconf);
SetFailState("Failed to create DHook for %s", key);
}
return result;
}
public MRESReturn Detour_Bot_RunAll()
{
PrintToServer("This prints fine!")
return MRES_Supercede;
}
My gamedata:
Spoiler
PHP Code:
"Games"
{
"nmrih"
{
"Addresses"
{
"Bot_RunAll"
{
"signature" "Bot_RunAll"
}
}
"Signatures"
{
"Bot_RunAll"
{
"library" "server"
"windows" "\x55\x8B\xEC\x51\x8B\x0D\x2A\x2A\x2A\x2A\x83\xB9\x0C\x10\x00\x00\x00\x0F\x95\xC0\x88\x45\xFF\x84\xC0\x74\x2A\x6A\x04\x6A\x00\x68\x2A\x2A\x2A\x2A\x6A\x00\x68\x2A\x2A\x2A\x2A\xFF"
}
}
"Functions"
{
"Bot_RunAll"
{
"address" "Bot_RunAll"
"callconv" "cdecl"
"return" "void"
"arguments"
{
}
}
}
}
}
My detour executes but so does the original function, why?
From dhooks.inc:
PHP Code:
enum MRESReturn
{
MRES_Supercede // skip real function; use my return value
};
I've detoured plenty of functions in the past but never superseded them till now.
Am I doing something wrong?