Veteran Member
Join Date: Sep 2017
Location: Taiwan, Asia
02-21-2022
, 07:37
Re: [L4D2] Remove bile effect if Vomit jar out of map (NAV)
#12
Quote:
Originally Posted by
BHaType
Added additional hook. Now it should properly detect invalid path
Code
PHP Code:
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <left4dhooks>
#include <dhooks>
#include <actions>
#include <sourcescramble>
MemoryPatch g_hBlockWavingAnimation ;
bool g_bShouldCheck , g_bValid ;
public void OnPluginStart ()
{
GameData data = new GameData ( "l4d2_infected_navigation_out_of_map" );
g_hBlockWavingAnimation = MemoryPatch . CreateFromConf ( data , "ChaseVictim::Update" );
DynamicDetour detour = DynamicDetour . FromConf ( data , "DirectChasePath::Update" );
if ( detour )
detour . Enable ( Hook_Post , OnChasePathUpdate );
delete data ;
}
public void OnActionCreated ( BehaviorAction action , int actor , const char [] name )
{
if ( strcmp ( name , "ChaseVictim" ) == 0 )
{
action . OnUpdate = OnUpdate ;
action . OnUpdatePost = OnUpdatePost ;
}
}
public Action OnUpdate ( BehaviorAction chaseVictim , float interval , ActionResult result )
{
BehaviorAction attack = chaseVictim . Parent ;
if ( attack == INVALID_ACTION )
return Plugin_Continue ;
int target = attack . Get ( 0x34 ) & 0xFFF ;
g_bShouldCheck = IsValidEntity ( target ) && ClassMatchesComplex ( target , "info_goal_infected_chase" );
return Plugin_Continue ;
}
public MRESReturn OnChasePathUpdate ( Address path , DHookParam params )
{
if ( ! g_bShouldCheck )
return MRES_Ignored ;
Address pValid = path + view_as < Address >( 0x480C );
g_bValid = LoadFromAddress ( pValid , NumberType_Int8 );
if ( ! g_bValid )
{
BlockWavingAnimation ( true );
StoreToAddress ( pValid , 1 , NumberType_Int8 );
int entity = params . Get ( 2 );
if ( entity != - 1 )
RemoveEntity ( entity );
}
return MRES_Ignored ;
}
public Action OnUpdatePost ( BehaviorAction chaseVictim , float interval , ActionResult result )
{
if ( g_bValid )
return Plugin_Continue ;
g_bValid = true ;
BlockWavingAnimation ( false );
result . type = DONE ;
return Plugin_Changed ;
}
bool ClassMatchesComplex ( int entity , const char [] name )
{
char classname [ 32 ];
GetEntityClassname ( entity , classname , sizeof classname );
return strcmp ( classname , name , false ) == 0 ;
}
void BlockWavingAnimation ( bool block )
{
if ( block )
g_hBlockWavingAnimation . Enable ();
else
g_hBlockWavingAnimation . Disable ();
}
stock int GetEntityHandle ( int entity )
{
return EntIndexToEntRef ( entity ) & ~( 1 << 31 );
}
GameData
PHP Code:
"Games"
{
"left4dead2"
{
"MemPatches"
{
"ChaseVictim::Update"
{
"signature" "ChaseVictim::Update"
"linux"
{
"offset" "3916"
"verify" "\x0F\x84\xA7\x02\x00\x00"
}
"windows"
{
"offset" "2427"
"verify" "\x0F\x84\x9C\x00\x00\x00"
}
"patch" "\x90\x90\x90\x90\x90\x90"
}
}
"Functions"
{
"DirectChasePath::Update"
{
"signature" "DirectChasePath::Update"
"callconv" "thiscall"
"return" "void"
"this" "address"
"arguments"
{
"bot"
{
"type" "int"
}
"victim"
{
"type" "cbaseentity"
}
"pathCost"
{
"type" "int"
}
"pPredictedSubjectPos"
{
"type" "vectorptr"
}
}
}
}
"Signatures"
{
"DirectChasePath::Update"
{
/* 55 8B EC 83 EC 0C 53 8B 5D 08 56 57 8B 7D 0C */
"linux" "@_ZN15DirectChasePath6UpdateEP8INextBotP11CBaseEntityRK9IPathCostP6Vector"
"windows" "\x55\x8B\xEC\x83\xEC\x0C\x53\x8B\x5D\x08\x56\x57\x8B\x7D\x0C"
}
"ChaseVictim::Update"
{
"linux" "@_ZN11ChaseVictim6UpdateEP8Infectedf"
"windows" "\x55\x8B\xEC\x83\xEC\x68\xA1\x2A\x2A\x2A\x2A\x53\x56\x33\xF6\x8B\xD9"
}
}
}
}
WORKS Pefect, Thanks
__________________