Skip to content

Commit

Permalink
Fix deflected projectiles being in spectator team (#12)
Browse files Browse the repository at this point in the history
* Fix deflected projectiles being in spectator team

* Bump version
  • Loading branch information
Mikusch committed May 3, 2024
1 parent 16e0e40 commit d5a61e4
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 7 deletions.
24 changes: 24 additions & 0 deletions addons/sourcemod/gamedata/friendlyfire.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@
"linux" "293"
"windows" "287"
}
"CBaseEntity::Deflected"
{
"library" "server"
"linux" "160"
"windows" "159"
}
"CBaseEntity::VPhysicsUpdate"
{
"library" "server"
Expand Down Expand Up @@ -247,6 +253,24 @@
"return" "void"
"this" "entity"
}
"CBaseEntity::Deflected"
{
"offset" "CBaseEntity::Deflected"
"hooktype" "entity"
"return" "void"
"this" "entity"
"arguments"
{
"pDeflectedBy"
{
"type" "cbaseentity"
}
"vecDir"
{
"type" "vectorptr"
}
}
}
"CBaseEntity::VPhysicsUpdate"
{
"offset" "CBaseEntity::VPhysicsUpdate"
Expand Down
2 changes: 1 addition & 1 deletion addons/sourcemod/scripting/friendlyfire.sp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <tf2_stocks>
#include <tf2utils>

#define PLUGIN_VERSION "1.2.5"
#define PLUGIN_VERSION "1.2.6"

#define TICK_NEVER_THINK -1.0
#define TF_CUSTOM_NONE 0
Expand Down
39 changes: 33 additions & 6 deletions addons/sourcemod/scripting/friendlyfire/dhooks.sp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ static DynamicHook g_dhook_CTFBaseRocket_Explode;
static DynamicHook g_dhook_CBasePlayer_Event_Killed;
static DynamicHook g_dhook_CTFWeaponBaseMelee_Smack;
static DynamicHook g_dhook_CTFWeaponBase_SecondaryAttack;
static DynamicHook g_dhook_CBaseEntity_Deflected;
static DynamicHook g_dhook_CBaseEntity_VPhysicsUpdate;

static ThinkFunction g_thinkFunction = ThinkFunction_None;
Expand All @@ -64,6 +65,7 @@ void DHooks_Initialize(GameData gamedata)
g_dhook_CBasePlayer_Event_Killed = DHooks_AddDynamicHook(gamedata, "CBasePlayer::Event_Killed");
g_dhook_CTFWeaponBaseMelee_Smack = DHooks_AddDynamicHook(gamedata, "CTFWeaponBaseMelee::Smack");
g_dhook_CTFWeaponBase_SecondaryAttack = DHooks_AddDynamicHook(gamedata, "CTFWeaponBase::SecondaryAttack");
g_dhook_CBaseEntity_Deflected = DHooks_AddDynamicHook(gamedata, "CBaseEntity::Deflected");
g_dhook_CBaseEntity_VPhysicsUpdate = DHooks_AddDynamicHook(gamedata, "CBaseEntity::VPhysicsUpdate");
}

Expand Down Expand Up @@ -102,6 +104,10 @@ void DHooks_HookEntity(int entity, const char[] classname)
// Fixes projectiles sometimes not colliding with teammates
DHooks_HookEntityInternal(g_dhook_CBaseProjectile_CanCollideWithTeammates, Hook_Post, entity, DHookCallback_CBaseProjectile_CanCollideWithTeammates_Post);

// Fixes reflected projectiles being in spectator team
DHooks_HookEntityInternal(g_dhook_CBaseEntity_Deflected, Hook_Pre, entity, DHookCallback_CBaseEntity_Deflected_Pre);
DHooks_HookEntityInternal(g_dhook_CBaseEntity_Deflected, Hook_Post, entity, DHookCallback_CBaseEntity_Deflected_Post);

if (IsEntityBaseGrenadeProjectile(entity))
{
// Fixes grenades rarely bouncing off friendly objects
Expand Down Expand Up @@ -286,9 +292,8 @@ static MRESReturn DHookCallback_CTFProjectile_Flare_Explode_Pre(int entity, DHoo
if (IsTruceActive())
return MRES_Ignored;

int other = params.Get(2);

Entity(other).ChangeToSpectator();
if (!params.IsNull(2))
Entity(params.Get(2)).ChangeToSpectator();

return MRES_Ignored;
}
Expand All @@ -298,9 +303,8 @@ static MRESReturn DHookCallback_CTFProjectile_Flare_Explode_Post(int entity, DHo
if (IsTruceActive())
return MRES_Ignored;

int other = params.Get(2);

Entity(other).ResetTeam();
if (!params.IsNull(2))
Entity(params.Get(2)).ResetTeam();

return MRES_Ignored;
}
Expand All @@ -316,6 +320,29 @@ static MRESReturn DHookCallback_CBaseProjectile_CanCollideWithTeammates_Post(int
return MRES_Supercede;
}

static MRESReturn DHookCallback_CBaseEntity_Deflected_Pre(int entity, DHookParam params)
{
if (IsTruceActive())
return MRES_Ignored;

// Make projectiles have the original team of the deflector
if (!params.IsNull(1))
Entity(params.Get(1)).ChangeToOriginalTeam();

return MRES_Ignored;
}

static MRESReturn DHookCallback_CBaseEntity_Deflected_Post(int entity, DHookParam params)
{
if (IsTruceActive())
return MRES_Ignored;

if (!params.IsNull(1))
Entity(params.Get(1)).ResetTeam();

return MRES_Ignored;
}

static MRESReturn DHookCallback_CTFSniperRifle_GetCustomDamageType_Post(int entity, DHookReturn ret)
{
if (IsTruceActive())
Expand Down

0 comments on commit d5a61e4

Please sign in to comment.