Hopefully you folks can help me here. I was just trying to recreate a function from Downtown to plugin using Dhooks Detours.
Here is the function from disassembly.
PHP Code:
; _DWORD __cdecl CDirector::OnFirstSurvivorLeftSafeArea(CDirector *this, CTerrorPlayer *)
This is the code that I copied from your test example.
PHP Code:
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <dhooks>
#define GAMEDATA "left4downtown.l4d2"
public void OnPluginStart()
{
Handle hGamedata = LoadGameConfigFile(GAMEDATA);
if( hGamedata == null )
SetFailState("Failed to load \"%s.txt\" gamedata.", GAMEDATA);
Handle hDetour = DHookCreateDetour(Address_Null, CallConv_THISCALL, ReturnType_Edict, ThisPointer_Address);
if( !hDetour )
SetFailState("Failed to setup detour for hDetour");
// Load the address of the function from gamedata file.
if (!DHookSetFromConf(hDetour, hGamedata, SDKConf_Signature, "OnFirstSurvivorLeftSafeArea"))
SetFailState("Failed to find \"CDirector::OnFirstSurvivorLeftSafeArea\" signature.");
// Add all parameters.
DHookAddParam(hDetour, HookParamType_Edict);
// Add a pre hook on the function.
if (!DHookEnableDetour(hDetour, false, Detour_OnFirstSurvivorLeftSafeArea))
SetFailState("Failed to detour OnFirstSurvivorLeftSafeArea.");
// And a post hook.
if (!DHookEnableDetour(hDetour, true, Detour_OnFirstSurvivorLeftSafeArea_Post))
SetFailState("Failed to detour OnFirstSurvivorLeftSafeArea post.");
}
public MRESReturn Detour_OnFirstSurvivorLeftSafeArea(Handle hReturn)
{
PrintToChatAll("Detour_OnFirstSurvivorLeftSafeArea_pre called!");
DHookSetReturn(hReturn, 1);
return MRES_Override;
}
public MRESReturn Detour_OnFirstSurvivorLeftSafeArea_Post(Handle hReturn)
{
PrintToChatAll("Detour_OnFirstSurvivorLeftSafeArea_Post called!");
PrintToChatAll("Return value : %i", DHookGetReturn(hReturn));
return MRES_Ignored;
}
The code yields the following errors.
PHP Code:
L 08/10/2018 - 22:12:34: [SM] Exception reported: Invalid Handle 2bed200 (error 4)
L 08/10/2018 - 22:12:34: [SM] Blaming: leftsaferoom.smx
L 08/10/2018 - 22:12:34: [SM] Call stack trace:
L 08/10/2018 - 22:12:34: [SM] [0] DHookSetReturn
L 08/10/2018 - 22:12:34: [SM] [1] Line 56, C:\Users\mypc\Desktop\scripting-l4d2\leftsaferoom.sp::Detour_OnFirstSurvivorLeftSafeArea
L 08/10/2018 - 22:12:34: [SM] Exception reported: Invalid Handle 2bed200 (error 4)
L 08/10/2018 - 22:12:34: [SM] Blaming: leftsaferoom.smx
L 08/10/2018 - 22:12:34: [SM] Call stack trace:
L 08/10/2018 - 22:12:34: [SM] [0] DHookGetReturn
L 08/10/2018 - 22:12:34: [SM] [1] Line 63, C:\Users\mypc\Desktop\scripting-l4d2\leftsaferoom.sp::Detour_OnFirstSurvivorLeftSafeArea_Post
I'm assuming that either my return type is wrong or my add parameter needs a switch. Either that or function has no return value and if that's the case then how do I stop its execution.
__________________