Thread: CollisionHook
View Single Post
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 02-15-2021 , 17:05   Re: CollisionHook
Reply With Quote #117

Quote:
Originally Posted by cravenge View Post
BHaType posted a newer way of recreating this extension for L4D2 in the form of a plugin. The only problem is you have to find the latest offset of the PassServerEntityFilter function in the binary to make it work post-TLS.
Just to add to what cravenge is talking about. I went ahead with BhaType's idea and created this plugin with a forward.

Just grab the right signature for your game and it should work fine. Windows is not tested at all, so you are on your own.

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;

GameData

PHP Code:
"Games"
{
    
"left4dead2"
    
{
        
"Functions"
        
{
            
"PassEntityFilter"
            
{
                
"signature"            "PassEntityFilter"
                "callconv"            "cdecl"
                "return"            "int"
                "this"                "ignore"
                "arguments"
                
{
                    
"a1"
                    
{
                        
"type"    "cbaseentity"
                    
}
                    
"a2"
                    
{
                        
"type"    "cbaseentity"
                    
}
                }
            }
        }
        
"Signatures"
        
{
            
"PassEntityFilter"
            
{
                
"library" "server"
                "windows"        "\x55\x8B\xEC\x57\x8B\x7D\x0C\x85\xFF\x75"
                "linux"        "@_Z22PassServerEntityFilterPK13IHandleEntityS1_"
            
}
        }
    }

Attached Files
File Type: txt CollisionHook.txt (573 Bytes, 110 views)
File Type: sp Get Plugin or Get Source (CollisionHook.sp - 139 views - 1.5 KB)
__________________
Spirit_12 is offline