Raised This Month: $52 Target: $400
 13% 

DHooks (Dynamic Hooks - Dev Preview)


Post New Thread Reply   
 
Thread Tools Display Modes
Ryan.
Member
Join Date: Jan 2018
Old 12-17-2018 , 19:33   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #641

Quote:
Originally Posted by asherkin View Post
Make sure that you’re using clang for your build rather than gcc, and that you’re using the right SDK.
Thanks man, I'll give clang a try.
__________________
Ryan. is offline
Naydef
Senior Member
Join Date: Dec 2015
Location: Doom Town, Nevada
Old 01-11-2019 , 14:12   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #642

Hello everyone,
Dhooks with detours is great extension for saving me time when i want to hook functions, but i have a great problem when i try to post hook a function

Description:
I'm hooking non-virtual member function and when I use a pre hook, it works fine and prints the message in the test plugin, but the return value is invalid(expected, because original function is not called). When I try to use post hook, when i try to build a building, it crashes the server. I firstly used detours6 version, then after the crash i updated to detours7, but crashes still occurs.

Test plugin:
PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <tf2>
#include <tf2_stocks>
#include <dhooks>

#pragma newdecls required

#define PLUGIN_NAME     "Build on buildings plugin"
#define PLUGIN_AUTHOR   "Naydef"
#define PLUGIN_VERSION  "1.0"

public Plugin myinfo =
{
    
name PLUGIN_NAME,
    
author PLUGIN_AUTHOR,
    
version PLUGIN_VERSION,
};

Handle hDetourIsPlacementPosValid;

public 
void OnPluginStart()
{
    
Handle gamedatafile=LoadGameConfigFile("buildonbuildings_defs.games");
    if(
gamedatafile==null)
    {
        
SetFailState("Cannot find file buildonbuildings_defs.games!");
    }
    
hDetourIsPlacementPosValid=DHookCreateDetour(Address_NullCallConv_THISCALLReturnType_BoolThisPointer_CBaseEntity);
    if(
hDetourIsPlacementPosValid==null)
    {
        
SetFailState("Failed to create CBaseObject::IsPlacementPosValid detour!");
    }
    
// Load the address of the function from PTaH's signature gamedata file.
    
if(!DHookSetFromConf(hDetourIsPlacementPosValidgamedatafileSDKConf_Signature"CBaseObject::IsPlacementPosValid"))
    {
        
SetFailState("Failed to load CBaseObject::IsPlacementPosValid signature from gamedata");
    }
    
delete gamedatafile;
    
    
// Add a post hook on the function.
    //if(!DHookEnableDetour(hDetourIsPlacementPosValid, false, Detour_IsPlacementPosValid)) // Not crashing
          
if(!DHookEnableDetour(hDetourIsPlacementPosValidtrueDetour_IsPlacementPosValid)) // Crashing
    
{
        
SetFailState("Failed to detour CBaseObject::IsPlacementPosValid!");
    }
}

public 
MRESReturn Detour_IsPlacementPosValid(int pThisHandle hReturnHandle hParams)
{
    if(
pThis==-1)
    {
        return 
MRES_Ignored;
    }
    
/*
    if(DHookGetReturn(hReturn))
    {
        return MRES_Ignored;
    }
    */
    //bool result=false;
    
    
PrintToChatAll("Placement pos valid for: %i is %i"pThisDHookGetReturn(hReturn));
    
//DHookSetReturn(hReturn, result);
    //return MRES_ChangedOverride;
    
return MRES_Ignored;

The gamedata:
PHP Code:
"Games"
{
    
"#default"
    
{
        
"Signatures"
        
{
            
"CBaseObject::IsPlacementPosValid"
            
{
                
"library"        "server"
                "windows"        "\x53\x8b\xdc\x83\xec\x08\x83\xe4\xf0\x83\xc4\x04\x55\x8b\x6b\x04\x89\x6c\x24\x04\x8b\xec\x81\xec\x48\x01\x00\x00\x56\x57\x8b\xf9\x8b\x07\x8b\x80\x18"
                "linux"            "_ZN11CBaseObject19IsPlacementPosValidEv"
            
}
        }
    }

Info:
DHooks with detours(detours6, upgraded to detours7)
Sourcemod 1.8.0.6028
Windows platform
Accelerator crash report from detours6 - https://crash.limetech.org/jag75n4rfrem
Accelerator crash report from detours7 - https://crash.limetech.org/rb6m2np5yorp

The crash looks to me like a NULL pointer problem

Edit:
The functions is actually a virtual function, but i doubt this will create cause the crash.
__________________
My plugins:
Admin Stealth REDUX(v1.6.1)

Non-Sourcemod related projects:
8086eD x86 Emulator

Steam:
naydef

Last edited by Naydef; 01-11-2019 at 14:24.
Naydef is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 01-11-2019 , 16:27   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #643

That's an outstanding issue with parameter addresses getting reused in the functions on Windows, so post-hooks don't have access to the initial input anymore. The same holds for the this-pointer, except that there is special handling to save it and restore it for a post-hook. It is only saved from a pre-hook though and thus requires one. To work around that for now, you can add an empty pre hook on the function and you'll have access to the this-pointer in the post hook as well. This doesn't work for parameters.
__________________
Peace-Maker is offline
Naydef
Senior Member
Join Date: Dec 2015
Location: Doom Town, Nevada
Old 01-12-2019 , 07:11   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #644

Quote:
Originally Posted by Peace-Maker View Post
That's an outstanding issue with parameter addresses getting reused in the functions on Windows, so post-hooks don't have access to the initial input anymore. The same holds for the this-pointer, except that there is special handling to save it and restore it for a post-hook. It is only saved from a pre-hook though and thus requires one. To work around that for now, you can add an empty pre hook on the function and you'll have access to the this-pointer in the post hook as well. This doesn't work for parameters.
Thank you, now the post hook works correctly, but next time it'd be better this info is mentioned somewhere.
__________________
My plugins:
Admin Stealth REDUX(v1.6.1)

Non-Sourcemod related projects:
8086eD x86 Emulator

Steam:
naydef
Naydef is offline
SZOKOZ
Member
Join Date: Jan 2014
Old 02-20-2019 , 14:02   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #645

I have a scenario where I try to retrieve an object from a parameter and try to call a function of that object. Problem is I think the address is getting truncated because I'm retrieving it as an int.
Code:
StartPrepSDKCall(SDKCall_Raw);
PrepSDKCall_SetFromConf(hGameData, SDKConf_Signature, "GetEntityIndex");
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
g_hGetEntityIndex = EndPrepSDKCall();

...

any GameTraceObj = DHookGetParamObjectPtrVar(hParams, 1, 0, ObjectValueType_Int);
SDKCall(g_hGetEntityIndex, GameTraceObj);//Will crash here.
Any future support for retrieving addresses or I'm I making a mistake somewhere.
__________________
May still be available for SM scripting. Just look at my Steam profile regarding my availability.
My Steam
SZOKOZ is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 02-20-2019 , 14:31   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #646

Quote:
Originally Posted by SZOKOZ View Post
Problem is I think the address is getting truncated because I'm retrieving it as an int.
That is not the problem, your address is int-sized.
__________________
asherkin is offline
ichiballs
Member
Join Date: Oct 2016
Old 02-24-2019 , 21:52   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #647

When i put any version of dhooks.ext.so in my extension folder, the server crashes once I connect and then join a team. If i stay on "Choose team" screen, the server works normally but immediately after i choose a team, the server goes down. Any ideas?
ichiballs is offline
SZOKOZ
Member
Join Date: Jan 2014
Old 02-25-2019 , 19:45   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #648

Quote:
Originally Posted by ichiballs View Post
When i put any version of dhooks.ext.so in my extension folder, the server crashes once I connect and then join a team. If i stay on "Choose team" screen, the server works normally but immediately after i choose a team, the server goes down. Any ideas?
Sounds like a plugin using dhooks causing the problem. You know the deal, remove all your plugins and add them back one by one to see the plugin causing the problem.
__________________
May still be available for SM scripting. Just look at my Steam profile regarding my availability.
My Steam
SZOKOZ is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 03-15-2019 , 02:44   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #649

Experiencing a bug with DHooks (both latest original and dynhooks versions downloaded from the links in the initial and Peace-Maker's posts) specifically on SM 1.10.
I'd assume there's a regression in SM, but I'm not familiar with neither SM nor DHooks code.

A minimal test case for TF2 is attached; the expected outcome is that the second argument of CTFPlayer::TakeHealth is set to 6 (allowing overheal whenever healed). On 1.9, the plugin works correctly.

(I've since worked around the issue by detouring the function directly in this case.)
Attached Files
File Type: txt tf2.kit_overheal.txt (132 Bytes, 43 views)
File Type: sp Get Plugin or Get Source (dhooks_takehealth_overheal_test.sp - 43 views - 1.5 KB)
__________________
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)

Last edited by nosoop; 03-15-2019 at 02:46.
nosoop is online now
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 03-15-2019 , 06:33   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #650

Quote:
Originally Posted by nosoop View Post
Experiencing a bug with DHooks (both latest original and dynhooks versions downloaded from the links in the initial and Peace-Maker's posts) specifically on SM 1.10.
I'd assume there's a regression in SM, but I'm not familiar with neither SM nor DHooks code.
You need a copy of DHooks compiled against the SM 1.10 SDK.
__________________
asherkin 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 22:49.


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