Raised This Month: $32 Target: $400
 8% 

DHooks (Dynamic Hooks - Dev Preview)


Post New Thread Reply   
 
Thread Tools Display Modes
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 #601

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
nosoop
Veteran Member
Join Date: Aug 2014
Old 08-10-2018 , 22:42   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #602

Quote:
Originally Posted by Spirit_12 View Post
Hopefully you folks can help me here. I was just trying to recreate a function from Downtown to plugin using Dhooks Detours.

[...]

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.
The one thing that stands out for me is that the value it's spitting out isn't a handle.

Looking through the code, you specified a ThisPointerType of ThisPointer_Address but didn't use a callback prototype that references it like so:

Code:
function MRESReturn (Address pThis, Handle hReturn, Handle hParams);
If you don't need the this pointer, you should instantiate using ThisPointer_Ignore instead, which will omit pushing the this to your callback. (The extension has no way to see what the callback takes as its arguments; you only get the compile-time check that it matches one of the ones specified as a DHookCallback.)
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)

Last edited by nosoop; 08-10-2018 at 22:48.
nosoop is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 08-10-2018 , 22:54   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #603

Quote:
Originally Posted by nosoop View Post
The one thing that stands out for me is that the value it's spitting out isn't a handle.

Looking through the code, you specified a ThisPointerType of ThisPointer_Address but didn't use a callback prototype that references it like so:

Code:
function MRESReturn (Address pThis, Handle hReturn, Handle hParams);
If you don't need the this pointer, you should instantiate using ThisPointer_Ignore instead, which will omit pushing the this to your callback. (The extension has no way to see what the callback takes as its arguments; you only get the compile-time check that it matches one of the ones specified as a DHookCallback.)
I hear you on the callback prototype. Going to fix that part. That actually did the trick. I'll post the final code after I'm done testing.
__________________

Last edited by Spirit_12; 08-10-2018 at 23:43.
Spirit_12 is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 08-11-2018 , 00:55   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #604

Code below can replace L4D_OnFirstSurvivorLeftSafeArea forward from Downtown.

PHP Code:
#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>
#include <sdktools>
#include <dhooks>

#define GAMEDATA            "left4downtown.l4d2"

ConVar cvar_switch;

public 
void OnPluginStart()
{
    
cvar_switch    =    CreateConVar"cvar_on""0""Set to one to disable detour");

    
Handle hGamedata LoadGameConfigFile(GAMEDATA);
    if( 
hGamedata == null 
        
SetFailState("Failed to load \"%s.txt\" gamedata."GAMEDATA);
    
    
Handle hDetour DHookCreateDetour(Address_NullCallConv_THISCALLReturnType_BoolThisPointer_Ignore);
    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_CBaseEntity);


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

public 
MRESReturn Detour_OnFirstSurvivorLeftSafeArea(Handle hReturnHandle hParam)
{
    
int client DHookGetParam(hParam1);
    
PrintToChatAll("Detour_OnFirstSurvivorLeftSafeArea_pre called on %d Name: %N!"clientclient);
    
PrintToChatAll("%i"DHookGetReturn(hReturn));
    
    if(!
cvar_switch.BoolValue)
    {
        
DHookSetReturn(hReturnfalse);
        return 
MRES_Supercede;
    }
    return 
MRES_Ignored;

__________________

Last edited by Spirit_12; 08-13-2018 at 13:33. Reason: Cleaned code
Spirit_12 is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 08-29-2018 , 19:48   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #605

Can anyone show me an example of how to use physical offsets of an address and detour that? I'm trying to get the userid from a function, but its neither a this pointer, parameter or a return, but instead its an offset in the function.

PHP Code:
mov     dword ptr [esp+4], offset aUserid "userid" 
How do I solve this? Seems like its pointer + the offset.
__________________
Spirit_12 is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 08-29-2018 , 22:26   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #606

That's setting a stack variable to point to a string with contents "userid". Are you sure that's what you're looking for?
What exactly is your end goal here?
hmmmmm is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 08-30-2018 , 00:23   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #607

Quote:
Originally Posted by hmmmmm View Post
That's setting a stack variable to point to a string with contents "userid". Are you sure that's what you're looking for?
What exactly is your end goal here?
End goal is to detour the function only if a certain condition is met. This function detects what was the reason for smoker's tongue to be broken. I just want to detour if a certain condition is met and not all the times.
__________________
Spirit_12 is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 08-30-2018 , 01:44   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #608

Quote:
Originally Posted by Spirit_12 View Post
This function detects what was the reason for smoker's tongue to be broken. I just want to detour if a certain condition is met and not all the times.
What you've posted seems to be the setup for an event to be fired (when the userid key / value gets added).

You may need to assembly patch the function (StoreToAddress-ing the bytes in the subroutine), if you cannot detour and check the same criteria to override beforehand. It's hard to say what you can do without actually seeing the function you're hooking.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop is offline
paulo_crash
AlliedModders Donor
Join Date: May 2016
Location: Brazil
Old 09-26-2018 , 23:33   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #609

I downloaded the following version for my CSGO Servers:
Quote:
dhooks-2.2.0-hg126-linux.tar.gz
But it is giving the following errors:
Quote:
Errors:
dhooks-test.smx: Error detected in plugin startup (see error logs)

L 09/27/2018 - 00:20:05: [SM] Exception reported: Failed to get CreateInterface
L 09/27/2018 - 00:20:05: [SM] Blaming: dhooks-test.smx
L 09/27/2018 - 00:20:05: [SM] Call stack trace:
L 09/27/2018 - 00:20:05: [SM] [0] SetFailState
L 09/27/2018 - 00:20:05: [SM] [1] Line 99, C:\Users\Gabriel\OneDrive\ZK Servidores\Plugins\Formatar\dhooks-test.sp::OnPluginStart
L 09/27/2018 - 00:20:05: [SM] Unable to load plugin "dhooks-test.smx": Error detected in plugin startup (see error logs)
What could it be, how can I correct it?
paulo_crash is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 09-27-2018 , 01:14   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #610

Quote:
Originally Posted by paulo_crash View Post
I downloaded the following version for my CSGO Servers:

But it is giving the following errors: [...]

What could it be, how can I correct it?
Quote:
Originally Posted by asherkin View Post
That is expected, it is a code sample of the DHooks API and does not contain up-to-date gamedata for every game. You should not be trying to load it.
From the previous page.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop is offline
Reply


Thread Tools
Display Modes

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 03:46.


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