Raised This Month: $319 Target: $400
 79%   Almost there!

CollisionHook


Post New Thread Reply   
 
Thread Tools Display Modes
HarryPotter
Veteran Member
Join Date: Sep 2017
Location: TW
Old 09-11-2021 , 07:56   Re: CollisionHook
Reply With Quote #131

l4d1 windows server crash, hope someone can help

sm1.10 + DHooks 2.2.0-detours17
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <dhooks>

Handle g_CHPassEntity;

public 
Plugin myinfo =
{
    
name "CollisionHook Dhooks",
    
author "$atanic $pirit, BHaType",
    
description "Hook on entity collision",
    
version "1.0",
    
url ""
}

public 
OnPluginStart()
{
    
GameData hData = new GameData("CollisionHook");

    
Handle hDetour DHookCreateFromConf(hData"PassEntityFilter");
    if( !
hDetour 
        
SetFailState("Failed to find \"PassEntityFilter\" offset.");
        
    if( !
DHookEnableDetour(hDetourtruedetour) ) 
        
SetFailState("Failed to detour \"PassEntityFilter\".");
    
delete hData;
    
    
g_CHPassEntity CreateGlobalForward("CH_PassFilter"ET_EventParam_CellParam_Cell Param_CellByRef);
}


public 
MRESReturn detour(Handle hReturnHandle hParams)
{
    if(!
DHookIsNullParam(hParams1) && !DHookIsNullParam(hParams2))
    {
        
int iEntity1    DHookGetParam(hParams1);
        
int iEntity2    DHookGetParam(hParams2);
        
int funcresult    DHookGetReturn(hReturn);
        
        if(
g_CHPassEntity)
        {
            
Action result Plugin_Continue;
            
            
/* Start function call */
            
Call_StartForward(g_CHPassEntity);

            
/* Push parameters one at a time */
            
Call_PushCell(iEntity1);
            
Call_PushCell(iEntity2);
            
Call_PushCellRef(funcresult);

            
/* Finish the call, get the result */
            
Call_Finish(result);
            
            if (
result == Plugin_Handled)
            {
                
DHookSetReturn(hReturnfuncresult);
                return 
MRES_Supercede;
            }
        }
    }
    
    
//PrintToChatAll("Entity 1 %i Entity 2 %i", iEntity1, iEntity2);
    
return MRES_Ignored;

Code:
"Games"
{
    "left4dead"
    {
        "Functions"
        {
            "PassEntityFilter"
            {
                "signature"            "PassEntityFilter"
                "callconv"            "cdecl"
                "return"            "int"
                "this"                "ignore"
                "arguments"
                {
                    "a1"
                    {
                        "type"    "cbaseentity"
                    }
                    "a2"
                    {
                        "type"    "cbaseentity"
                    }
                }
            }
        }
        "Signatures"
        {
            "PassEntityFilter"
            {
                "library" "server"
                "windows"        "\x2A\x2A\x2A\x2A\x2A\x2A\x2A\x75\x2A\xB0\x2A\x5F\xC3\x56"
                "linux"        "@_Z22PassServerEntityFilterPK13IHandleEntityS1_"
            }
        }
    }
}
Attached Files
File Type: txt CollisionHook.txt (973 Bytes, 18 views)
File Type: sp Get Plugin or Get Source (l4d_collision_hook_test.sp - 16 views - 1.8 KB)
__________________

Last edited by HarryPotter; 09-11-2021 at 07:57.
HarryPotter is offline
Psyk0tik
AlliedModders Donor
Join Date: May 2012
Location: Homeless
Old 09-11-2021 , 16:29   Re: CollisionHook
Reply With Quote #132

Quote:
Originally Posted by HarryPotter View Post
l4d1 windows server crash, hope someone can help

sm1.10 + DHooks 2.2.0-detours17
Your setup is wrong. You need to understand that not every entity handle pointer passed to the two params will be a CBaseEntity pointer. You'll have to figure out a way to check if they are static props or not. When one of the params is a static prop, you'll want to return early to avoid crashes. You'll also want to change the param types from "cbaseentity" to "int" so DHooks doesn't convert them to entity indexes, which is also why you're getting crashes.

This is the code in the SDK:
PHP Code:
bool PassServerEntityFilter( const IHandleEntity *pTouch, const IHandleEntity *pPass 
{
    if ( !
pPass )
        return 
true;

    if ( 
pTouch == pPass )
        return 
false;

    const 
CBaseEntity *pEntTouch EntityFromEntityHandlepTouch );
    const 
CBaseEntity *pEntPass EntityFromEntityHandlepPass );
    if ( !
pEntTouch || !pEntPass )
        return 
true;

    
// don't clip against own missiles
    
if ( pEntTouch->GetOwnerEntity() == pEntPass )
        return 
false;
    
    
// don't clip against owner
    
if ( pEntPass->GetOwnerEntity() == pEntTouch )
        return 
false;    


    return 
true;

You'll want to check for something like this in your detour:
PHP Code:
if ( IsStaticProppEntTouch ) || IsStaticProppEntPass ) )
    return 
true
__________________
AFK like JFK
--
Donate to Motivate
--
Get updated L4D/L4D2 gamedata signatures here.
--
PM me if you need help with finding signatures and/or offsets in the following games: L4D1&2/CSGO/TF2/NMRIH/INS/DODS/CSS/HL2DM

Last edited by Psyk0tik; 09-12-2021 at 02:42.
Psyk0tik is offline
Forgetest
Member
Join Date: Aug 2020
Old 09-15-2021 , 01:23   Re: CollisionHook
Reply With Quote #133

Quote:
Originally Posted by Psyk0tik View Post
Your setup is wrong. You need to understand that not every entity handle pointer passed to the two params will be a CBaseEntity pointer. You'll have to figure out a way to check if they are static props or not. When one of the params is a static prop, you'll want to return early to avoid crashes. You'll also want to change the param types from "cbaseentity" to "int" so DHooks doesn't convert them to entity indexes, which is also why you're getting crashes.
Thanks for your information, but nonetheless it's still crashing on Windows in my attempts.

Current setup (works on Linux L4D1):
Code:
"Games"
{
    "left4dead"
    {
        "Functions"
        {
            "PassEntityFilter"
            {
                "signature"			"PassEntityFilter"
                "callconv"			"cdecl"
                "return"			"bool"
                "this"				"ignore"
                "arguments"
                {
                    "a1"
                    {
                        "type"		"int"
                    }
                    "a2"
                    {
                        "type"		"int"
                    }
                }
            }
        }
        "Signatures"
        {
            "PassEntityFilter"
            {
                "library"		"server"
                "linux"			"@_Z22PassServerEntityFilterPK13IHandleEntityS1_"
                "windows"		"\x2A\x2A\x2A\x2A\x2A\x2A\x2A\x75\x2A\xB0\x2A\x5F\xC3\x56"
				/* ? ? ? ? ? ? ? 75 ? B0 ? 5F C3 56 */
            }
	}
    }
}
Tried a few possible setups before I gave up on this, which includes adding an argument whilist setting "a1" to be passed in "ebx".
Given it's always a crash regardless of what's in the detour callback (empty callback included), I started to dig out a few hints from crash logs, until I met with multiple ones labelled unique signature crash.

Plugin setup:
PHP Code:
public void OnPluginStart()
{
    
Handle hData LoadGameConfigFile("CollisionHook");
    
    
Handle hDetour DHookCreateFromConf(hData"PassEntityFilter");
    if (!
hDetour
        
SetFailState("Failed to find \"PassEntityFilter\" offset.");
        
    if (!
DHookEnableDetour(hDetourfalsePassEntityFilter)) // tried both pre and post hook
        
SetFailState("Failed to detour \"PassEntityFilter\".");

    
delete hData;
}

public 
MRESReturn PassEntityFilter(Handle hReturnHandle hParams)
{
    return 
MRES_Ignored;

Several crash IDs:
Code:
XCOI-K4MM-OETP
YKWD-K76T-OXYS
A2Y6-CIZK-VEW4

Last edited by Forgetest; 09-15-2021 at 01:23.
Forgetest is offline
cravenge
Veteran Member
Join Date: Nov 2015
Location: Middle of Nowhere
Old 09-15-2021 , 08:30   Re: CollisionHook
Reply With Quote #134

Maybe the fault lies within DHooks and how it replaces the first six bytes of the function during the detouring process.
__________________
cravenge is offline
Psyk0tik
AlliedModders Donor
Join Date: May 2012
Location: Homeless
Old 09-16-2021 , 21:50   Re: CollisionHook
Reply With Quote #135

Quote:
Originally Posted by Forgetest View Post
Thanks for your information, but nonetheless it's still crashing on Windows in my attempts.

Current setup (works on Linux L4D1):
...

Tried a few possible setups before I gave up on this, which includes adding an argument whilist setting "a1" to be passed in "ebx".
Given it's always a crash regardless of what's in the detour callback (empty callback included), I started to dig out a few hints from crash logs, until I met with multiple ones labelled unique signature crash.

Plugin setup:
...

Several crash IDs:
...
The function seems to be setup differently on Windows for both games. I can't say anything definite yet since I'm looking more into this, but so far, it seems that the function may not be "detour-able" on Windows because of its non-standard calling convention.

I haven't tested Linux but the following setup should work fine on both games without needing any extra params. You'll still need to convert the IHandleEntities though.
PHP Code:
"PassServerEntityFilter"
{
    
"signature"    "PassServerEntityFilter"
    "callconv"    "cdecl"
    "return"    "bool"
    "this"        "ignore"
    "arguments"
    
{
        
"entity1"
        
{
            
"type"        "int"
        
}
        
"entity2"
        
{
            
"type"        "int"
        
}
    }

Quote:
Originally Posted by cravenge View Post
Maybe the fault lies within DHooks and how it replaces the first six bytes of the function during the detouring process.
The first few bytes are just relocated since all DHooks does is replace them with a jump instruction to use its function instead. Those bytes only matter when DHooks accesses them (i.e. creating a detour to send a forward to all plugins detouring the function, restoring the original bytes when no plugin is detouring the function anymore, etc.).
__________________
AFK like JFK
--
Donate to Motivate
--
Get updated L4D/L4D2 gamedata signatures here.
--
PM me if you need help with finding signatures and/or offsets in the following games: L4D1&2/CSGO/TF2/NMRIH/INS/DODS/CSS/HL2DM
Psyk0tik 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 10:18.


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