Raised This Month: $ Target: $400
 0% 

DHooks (Dynamic Hooks - Dev Preview)


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 08-10-2018 , 22:20   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #11

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 *thisCTerrorPlayer *) 
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_NullCallConv_THISCALLReturnType_EdictThisPointer_Address);
    if( !
hDetour )
        
SetFailState("Failed to setup detour for hDetour");
    
    
// Load the address of the function from gamedata file.
    
if (!DHookSetFromConf(hDetourhGamedataSDKConf_Signature"OnFirstSurvivorLeftSafeArea"))
        
SetFailState("Failed to find \"CDirector::OnFirstSurvivorLeftSafeArea\" signature.");

    
// Add all parameters.
    
DHookAddParam(hDetourHookParamType_Edict);


    
// Add a pre hook on the function.
    
if (!DHookEnableDetour(hDetourfalseDetour_OnFirstSurvivorLeftSafeArea))
        
SetFailState("Failed to detour OnFirstSurvivorLeftSafeArea.");
        
    
// And a post hook.
    
if (!DHookEnableDetour(hDetourtrueDetour_OnFirstSurvivorLeftSafeArea_Post))
        
SetFailState("Failed to detour OnFirstSurvivorLeftSafeArea post."); 
}

public 
MRESReturn Detour_OnFirstSurvivorLeftSafeArea(Handle hReturn)
{
    
PrintToChatAll("Detour_OnFirstSurvivorLeftSafeArea_pre called!");
    
DHookSetReturn(hReturn1);
    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: [SMException reportedInvalid Handle 2bed200 (error 4)
L 08/10/2018 22:12:34: [SMBlamingleftsaferoom.smx
L 08
/10/2018 22:12:34: [SMCall stack trace:
L 08/10/2018 22:12:34: [SM]   [0DHookSetReturn
L 08
/10/2018 22:12:34: [SM]   [1Line 56C:\Users\mypc\Desktop\scripting-l4d2\leftsaferoom.sp::Detour_OnFirstSurvivorLeftSafeArea
L 08
/10/2018 22:12:34: [SMException reportedInvalid Handle 2bed200 (error 4)
L 08/10/2018 22:12:34: [SMBlamingleftsaferoom.smx
L 08
/10/2018 22:12:34: [SMCall stack trace:
L 08/10/2018 22:12:34: [SM]   [0DHookGetReturn
L 08
/10/2018 22:12:34: [SM]   [1Line 63C:\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.
__________________
Spirit_12 is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:58.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode