Raised This Month: $51 Target: $400
 12% 

DHooks (Dynamic Hooks - Dev Preview)


Post New Thread Reply   
 
Thread Tools Display Modes
freakav
Senior Member
Join Date: Jul 2016
Old 10-20-2016 , 18:34   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #511

A .smx file download pls .. im bad in compile and scripting
freakav is offline
splewis
Veteran Member
Join Date: Feb 2014
Location: United States
Old 10-20-2016 , 20:46   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #512

Quote:
Originally Posted by freakav View Post
A .smx file download pls .. im bad in compile and scripting
This isn't a sourcemod plugin, there's no smx file to give you. The "builds" page linked on the first post has links to the compiled extension for all platforms, though.
__________________
splewis is offline
Blunderstab
Junior Member
Join Date: Nov 2015
Old 11-05-2016 , 15:02   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #513

I'm having a server crash with my feeble attempts to learn how to use DHooks. I'm trying to hook the act of hitting a building with a wrench in TF2. I found the following:
Code:
CBaseObject::OnWrenchHit(CTFPlayer*, CTFWrench*, Vector)
My gamedata looks like this:
Code:
"Games"
{
    "tf"
    {
        "Offsets"
        {
            "OnWrenchHit"
            {
                "windows"    "356"
                "linux"    "358"
                "mac"    "358"
            }
        }
    }
}
And my actual code looks like this:
Code:
public OnPluginStart()
{
    AddNormalSoundHook(Hook_EntitySound);
    
    new Handle:temp = LoadGameConfigFile("tf2.blunderatts");
    
    if(temp == INVALID_HANDLE)
    {
        SetFailState("Why you no has gamedata?");
    }
    
    new offset;
    
    offset = GameConfGetOffset(temp, "OnWrenchHit");
    hOnWrenchHit = DHookCreate(offset, HookType_Entity, ReturnType_Void, ThisPointer_CBaseEntity, OnWrenchHit);
    DHookAddParam(hOnWrenchHit, HookParamType_CBaseEntity);
    DHookAddParam(hOnWrenchHit, HookParamType_CBaseEntity);
    DHookAddParam(hOnWrenchHit, HookParamType_Int);
    
    CloseHandle(temp);
}

public OnEntityCreated(entity, const String:classname[])
{
    if (StrEqual(classname, "obj_dispenser")
        || StrEqual(classname, "obj_sentrygun")
        || StrEqual(classname, "obj_teleporter"))
    {
        SDKHook(entity, SDKHook_SpawnPost, OnSpawnPost);
    }
}

public void OnSpawnPost(entity)
{
    DHookEntity(hOnWrenchHit, false, entity);
}

public MRESReturn OnWrenchHit(pThis, Handle:hParams)
{
    PrintToChatAll("Hit with wrench.");
    //PrintToChatAll("DHooksHacks = Building %d, Player %d", pThis, DHookGetParam(hParams, 1));
}
The moment an active building is struck with a wrench, the server crashes without even reaching the PrintToChatAll. I tested removing Teleporters from the list, and then the server wouldn't crash when hitting a Teleporter, even when having another building active. I've tried a few different Return Types and have put in the Handle:hReturn when necessary, but no dice. Given the specificness of the crash, it sounds like I'm on the right track. But I'm completely new to DHooks, so I just need a shove in the right direction.

Thanks in advance!
Blunderstab is offline
Pelipoika
Veteran Member
Join Date: May 2012
Location: Inside
Old 11-05-2016 , 16:01   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #514

Quote:
Originally Posted by Blunderstab View Post
I'm having a server crash with my feeble attempts to learn how to use DHooks. I'm trying to hook the act of hitting a building with a wrench in TF2. I found the following:
Code:
CBaseObject::OnWrenchHit(CTFPlayer*, CTFWrench*, Vector)
My gamedata looks like this:
Code:
"Games"
{
    "tf"
    {
        "Offsets"
        {
            "OnWrenchHit"
            {
                "windows"    "356"
                "linux"    "358"
                "mac"    "358"
            }
        }
    }
}
And my actual code looks like this:
Code:
public OnPluginStart()
{
    AddNormalSoundHook(Hook_EntitySound);
    
    new Handle:temp = LoadGameConfigFile("tf2.blunderatts");
    
    if(temp == INVALID_HANDLE)
    {
        SetFailState("Why you no has gamedata?");
    }
    
    new offset;
    
    offset = GameConfGetOffset(temp, "OnWrenchHit");
    hOnWrenchHit = DHookCreate(offset, HookType_Entity, ReturnType_Void, ThisPointer_CBaseEntity, OnWrenchHit);
    DHookAddParam(hOnWrenchHit, HookParamType_CBaseEntity);
    DHookAddParam(hOnWrenchHit, HookParamType_CBaseEntity);
    DHookAddParam(hOnWrenchHit, HookParamType_Int);
    
    CloseHandle(temp);
}

public OnEntityCreated(entity, const String:classname[])
{
    if (StrEqual(classname, "obj_dispenser")
        || StrEqual(classname, "obj_sentrygun")
        || StrEqual(classname, "obj_teleporter"))
    {
        SDKHook(entity, SDKHook_SpawnPost, OnSpawnPost);
    }
}

public void OnSpawnPost(entity)
{
    DHookEntity(hOnWrenchHit, false, entity);
}

public MRESReturn OnWrenchHit(pThis, Handle:hParams)
{
    PrintToChatAll("Hit with wrench.");
    //PrintToChatAll("DHooksHacks = Building %d, Player %d", pThis, DHookGetParam(hParams, 1));
}
The moment an active building is struck with a wrench, the server crashes without even reaching the PrintToChatAll. I tested removing Teleporters from the list, and then the server wouldn't crash when hitting a Teleporter, even when having another building active. I've tried a few different Return Types and have put in the Handle:hReturn when necessary, but no dice. Given the specificness of the crash, it sounds like I'm on the right track. But I'm completely new to DHooks, so I just need a shove in the right direction.

Thanks in advance!
The last param is a vector not an int and the return type is a bool
__________________

Last edited by Pelipoika; 11-05-2016 at 16:10.
Pelipoika is offline
Blunderstab
Junior Member
Join Date: Nov 2015
Old 11-05-2016 , 16:33   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #515

Code:
    hOnWrenchHit = DHookCreate(offset, HookType_Entity, ReturnType_Bool, ThisPointer_CBaseEntity, OnWrenchHit);
    DHookAddParam(hOnWrenchHit, HookParamType_CBaseEntity);
    DHookAddParam(hOnWrenchHit, HookParamType_CBaseEntity);
    DHookAddParam(hOnWrenchHit, HookParamType_VectorPtr);
Code:
public MRESReturn OnWrenchHit(pThis, Handle:hReturn, Handle:hParams)
{
    PrintToChatAll("Hit with wrench.");
    //PrintToChatAll("DHooksHacks = Building %d, Player %d", pThis, DHookGetParam(hParams, 1));
}
Changed to these things, same result.

Last edited by Blunderstab; 11-05-2016 at 16:40.
Blunderstab is offline
Pelipoika
Veteran Member
Join Date: May 2012
Location: Inside
Old 11-05-2016 , 17:19   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #516

Quote:
Originally Posted by Blunderstab View Post
Code:
    hOnWrenchHit = DHookCreate(offset, HookType_Entity, ReturnType_Bool, ThisPointer_CBaseEntity, OnWrenchHit);
    DHookAddParam(hOnWrenchHit, HookParamType_CBaseEntity);
    DHookAddParam(hOnWrenchHit, HookParamType_CBaseEntity);
    DHookAddParam(hOnWrenchHit, HookParamType_VectorPtr);
Code:
public MRESReturn OnWrenchHit(pThis, Handle:hReturn, Handle:hParams)
{
    PrintToChatAll("Hit with wrench.");
    //PrintToChatAll("DHooksHacks = Building %d, Player %d", pThis, DHookGetParam(hParams, 1));
}
Changed to these things, same result.
Tried myself, can't get it to work without crashing either.
__________________
Pelipoika is offline
Dr!fter
The Salt Boss
Join Date: Mar 2007
Old 11-05-2016 , 22:05   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #517

Its not a vector ptr it is a vector.
Dr!fter is offline
Blunderstab
Junior Member
Join Date: Nov 2015
Old 11-06-2016 , 00:03   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #518

There's no HookParamType_Vector though. What do I use for vectors? (And for the record, not adding this parameter or having it be HookParamType_Float crashes the server as well.)

Last edited by Blunderstab; 11-06-2016 at 00:13.
Blunderstab is offline
Dr!fter
The Salt Boss
Join Date: Mar 2007
Old 11-06-2016 , 08:28   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #519

HookParamType_Object and set the size to 12 and pass by val
Dr!fter is offline
Blunderstab
Junior Member
Join Date: Nov 2015
Old 11-06-2016 , 15:48   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #520

That fixed it! Thanks a bunch. While I'm still learning this though, I'd really like to know why size is "12". I'd expect vectors to be "3" since they should be storing three numbers.
Blunderstab is offline
Reply



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 04:14.


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