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_Null, CallConv_THISCALL, ReturnType_Bool, ThisPointer_Ignore);
if( !hDetour )
SetFailState("Failed to setup detour for hDetour");
// Load the address of the function from gamedata file.
if (!DHookSetFromConf(hDetour, hGamedata, SDKConf_Signature, "OnFirstSurvivorLeftSafeArea"))
SetFailState("Failed to find \"CDirector::OnFirstSurvivorLeftSafeArea\" signature.");
// Add all parameters.
DHookAddParam(hDetour, HookParamType_CBaseEntity);
// Add a pre hook on the function.
if (!DHookEnableDetour(hDetour, false, Detour_OnFirstSurvivorLeftSafeArea))
SetFailState("Failed to detour OnFirstSurvivorLeftSafeArea.");
}
public MRESReturn Detour_OnFirstSurvivorLeftSafeArea(Handle hReturn, Handle hParam)
{
int client = DHookGetParam(hParam, 1);
PrintToChatAll("Detour_OnFirstSurvivorLeftSafeArea_pre called on %d Name: %N!", client, client);
PrintToChatAll("%i", DHookGetReturn(hReturn));
if(!cvar_switch.BoolValue)
{
DHookSetReturn(hReturn, false);
return MRES_Supercede;
}
return MRES_Ignored;
}
__________________