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

Setting a detour


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ShadowMarioBR
Member
Join Date: Feb 2018
Old 02-08-2019 , 22:47   Setting a detour
Reply With Quote #1

I've tried setting a detour but it doesn't seem to be working correctly... Could someone help me (I'm on Windows)?

The gamedata:
Code:
"CTFFlameEntity::OnCollideWithTeammate"
{
    "library""server"
    "linux""@_ZN14CTFFlameEntity21OnCollideWithTeammateEP9CTFPlayer"
    "windows"	"\x55\x8B\xEC\x56\x8B\x75\x08\x57\x8B\xF9\x8B\xCE\x6A\x02"
}
The code:
Spoiler
ShadowMarioBR is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 02-11-2019 , 09:45   Re: Setting a detour
Reply With Quote #2

What's not working correctly? Without looking at the function you're trying to detour itself, it looks like you're using the wrong calling convention for a member function. Try thiscall.
__________________
Peace-Maker is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 02-11-2019 , 11:55   Re: Setting a detour
Reply With Quote #3

CTFFlameEntity::OnCollideWithTeammate function description:
Code:
prototype: void CTFFlameEntity::OnCollideWithTeammate(CTFPlayer *other);
Calling convention:
windows: void __thiscall CTFFlameEntity::OnCollideWithTeammate(CTFPlayer *other);
linux: void __cdecl CTFFlameEntity::OnCollideWithTeammate(CTFPlayer *other);
I suggest to replace hook build by Function gamedata section.
Code:
"Games"
{
    "#default"
    {
        "Signatures"
        {
            "CTFFlameEntity::OnCollideWithTeammate"
            {
                "library"  "server"
                "linux"  "@_ZN14CTFFlameEntity21OnCollideWithTeammateEP9CTFPlayer"
                "windows"  "\x55\x8B\xEC\x56\x8B\x75\x08\x57\x8B\xF9\x8B\xCE\x6A\x02"
            }
        }
        "Functions"
        {
            "CTFFlameEntity::OnCollideWithTeammate"
            {
                "signature"  "CTFFlameEntity::OnCollideWithTeammate"
                "windows"
                {
                    "callconv"  "stdcall"
                }
                "linux"
                {
                    "callconv"  "cdecl"
                }
                "return"  "void"
                "this"  "ignore"
                "arguments"
                {
                    "this"
                    {
                        "type"  "cbaseentity"
                        "windows"
                        {
                            "register"  "ecx"
                        }
                    }
                    "other"
                    {
                        "type"  "cbaseentity"
                    }
                }
            }
        }
    }
}
Code:
public void OnPluginStart()
{
    Handle config = LoadGameConfigFile("tf2.deathmatch");
    if(config == INVALID_HANDLE)
    {
        SetFailState("Could not find 'gamedata/tf2.deathmatch.txt'.");
    }
    
    onTeammate = DHookCreateFromConf(config, "CTFFlameEntity::OnCollideWithTeammate");
    
    if(!onTeammate)
    {
        SetFailState("Failed to create CWeaponMedigun::OnCollideWithTeammate detour!");
    }
    
    if(!DHookEnableDetour(onTeammate, false, Detour_FlameCollideWithTeammate))
    {
        SetFailState("Failed to detour CTFFlameEntity::OnCollideWithTeammate!");
    }

    delete config;
}

public MRESReturn Detour_FlameCollideWithTeammate(Handle hParams)
{
    PrintToChatAll("test");
}

Last edited by Kailo; 02-11-2019 at 11:57.
Kailo is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 02-11-2019 , 21:35   Re: Setting a detour
Reply With Quote #4

@Kailo: As a convenience you don't have to add that logic yourself and can just set the calling convention to "thiscall" on Linux as well. Internally dhooks will do exactly what you did, but allows you to use the normal natives to interact with the this pointer. Check the paragraph about "Detouring member functions" in the release post.
__________________
Peace-Maker is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 02-12-2019 , 02:39   Re: Setting a detour
Reply With Quote #5

@Peace-Maker, thank you, i found "Detouring member functions" section.

So, @ShadowMarioBR, config will be:
Code:
"Games"
{
    "#default"
    {
        "Signatures"
        {
            "CTFFlameEntity::OnCollideWithTeammate"
            {
                "library"  "server"
                "linux"  "@_ZN14CTFFlameEntity21OnCollideWithTeammateEP9CTFPlayer"
                "windows"  "\x55\x8B\xEC\x56\x8B\x75\x08\x57\x8B\xF9\x8B\xCE\x6A\x02"
            }
        }
        "Functions"
        {
            "CTFFlameEntity::OnCollideWithTeammate"
            {
                "signature"  "CTFFlameEntity::OnCollideWithTeammate"
                "callconv"  "thiscall"
                "return"  "void"
                "this"  "entity"
                "arguments"
                {
                    "other"
                    {
                        "type"  "cbaseentity"
                    }
                }
            }
        }
    }
}
Kailo 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 15:01.


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