Thread: CollisionHook
View Single Post
HarryPotter
Veteran Member
Join Date: Sep 2017
Location: Taiwan, Asia
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, 110 views)
File Type: sp Get Plugin or Get Source (l4d_collision_hook_test.sp - 96 views - 1.8 KB)
__________________

Last edited by HarryPotter; 09-11-2021 at 07:57.
HarryPotter is offline