Thread: CollisionHook
View Single Post
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 11-24-2019 , 17:00   Re: CollisionHook
Reply With Quote #103

This is my understanding from what I read of Peace-Maker's reply. You are to store the entity data in pre hook phase as opposed to using DHookGetParam in post hook.

I don't have a windows server running, so this is an untested version, but it should work.

PHP Code:
#include <sourcemod>
#include <sdktools>
#include <dhooks>

// Global Variables to store parameters.
int g_iEntityOne;
int g_iEntityTwo;

public 
OnPluginStart()
{
    
// Setup gamedata file
    
GameData hData = new GameData("l4dcollisionhook");

    
Handle hDetour DHookCreateFromConf(hData"PassEntityFilter");
    if( !
hDetour 
        
SetFailState("Failed to find \"PassEntityFilter\" offset.");
    
delete hData;

    
// Setup pre hook to grab parameters
    
if( !DHookEnableDetour(hDetourfalsedetour_pre) ) 
        
SetFailState("Failed to detour \"PassEntityFilter\". pre");
    
    
// Setup post hook
    
if( !DHookEnableDetour(hDetourtruedetour_post) ) 
        
SetFailState("Failed to detour \"PassEntityFilter\". post");
}

public 
MRESReturn detour_pre(Handle hReturnHandle hParams)
{
    
// Store prehook parameters into global variables
    
g_iEntityOne    =    DHookGetParam(hParams1);
    
g_iEntityTwo    =    DHookGetParam(hParams2);
    
    
PrintToServer("Entity 1 %i Entity 2 %i"DHookGetParam(hParams1), DHookGetParam(hParams2));
    return 
MRES_Ignored;


public 
MRESReturn detour_post(Handle hReturnHandle hParams)
{
    
PrintToServer("Entity 1 %i Entity 2 %i"g_iEntityOneg_iEntityTwo);
    return 
MRES_Ignored;

__________________
Spirit_12 is offline