Raised This Month: $ Target: $400
 0% 

DHooks (Dynamic Hooks - Dev Preview)


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 08-11-2018 , 00:55   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #11

Code below can replace L4D_OnFirstSurvivorLeftSafeArea forward from Downtown.

PHP Code:
#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>
#include <sdktools>
#include <dhooks>

#define GAMEDATA            "left4downtown.l4d2"

ConVar cvar_switch;

public 
void OnPluginStart()
{
    
cvar_switch    =    CreateConVar"cvar_on""0""Set to one to disable detour");

    
Handle hGamedata LoadGameConfigFile(GAMEDATA);
    if( 
hGamedata == null 
        
SetFailState("Failed to load \"%s.txt\" gamedata."GAMEDATA);
    
    
Handle hDetour DHookCreateDetour(Address_NullCallConv_THISCALLReturnType_BoolThisPointer_Ignore);
    if( !
hDetour )
        
SetFailState("Failed to setup detour for hDetour");
    
    
// Load the address of the function from gamedata file.
    
if (!DHookSetFromConf(hDetourhGamedataSDKConf_Signature"OnFirstSurvivorLeftSafeArea"))
        
SetFailState("Failed to find \"CDirector::OnFirstSurvivorLeftSafeArea\" signature.");

    
// Add all parameters.
    
DHookAddParam(hDetourHookParamType_CBaseEntity);


    
// Add a pre hook on the function.
    
if (!DHookEnableDetour(hDetourfalseDetour_OnFirstSurvivorLeftSafeArea))
        
SetFailState("Failed to detour OnFirstSurvivorLeftSafeArea.");
}

public 
MRESReturn Detour_OnFirstSurvivorLeftSafeArea(Handle hReturnHandle hParam)
{
    
int client DHookGetParam(hParam1);
    
PrintToChatAll("Detour_OnFirstSurvivorLeftSafeArea_pre called on %d Name: %N!"clientclient);
    
PrintToChatAll("%i"DHookGetReturn(hReturn));
    
    if(!
cvar_switch.BoolValue)
    {
        
DHookSetReturn(hReturnfalse);
        return 
MRES_Supercede;
    }
    return 
MRES_Ignored;

__________________

Last edited by Spirit_12; 08-13-2018 at 13:33. Reason: Cleaned code
Spirit_12 is offline
 



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 12:58.


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