I am having issues with the experimental detours branch.
Game is No More Room in Hell and I'm returning MRES_Supercede on a void function.
PHP Code:
void __cdecl Bot_RunAll( void )
The detour fires, but so does the real function.
Could this be a bug, or am I doing something wrong?
My code:
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");
}
PrintToServer("Bot_RunAll detoured!");
}
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("Detouring..")
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"
{
}
}
}
}
}
Output:
Code:
Bot_RunAll detoured!
Detouring..
Bot kicked by server. (caused by the real function)
For some context, Bot_RunAll() is called by GameStartFrame(), and kicks any bots it finds. My code tries to stop that.