Skip to content

Commit

Permalink
fix: blockdamage not working (#311)
Browse files Browse the repository at this point in the history
* the great company VALVE

* call actual

* Cleanup

---------

Co-authored-by: Vauff <[email protected]>
  • Loading branch information
Kxnrl and Vauff authored Oct 14, 2024
1 parent eadb9f6 commit 5534568
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions cfg/cs2fixes/cs2fixes.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ cs2f_flashlight_attachment axis_of_intent // Which attachment to parent a flash
// Damage block settings
cs2f_block_molotov_self_dmg 0 // Whether to block self-damage from molotovs
cs2f_block_all_dmg 0 // Whether to block all damage to players
cs2f_fix_block_dmg 0 // Whether to fix block-damage on players
// Custom burn settings
cs2f_burn_particle "particles/cs2fixes/napalm_fire.vpcf" // The particle to use for burning players
Expand Down
2 changes: 1 addition & 1 deletion src/cs2_sdk/entity/ctakedamageinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct AttackerInfo_t
bool m_bNeedInit;
bool m_bIsPawn;
bool m_bIsWorld;
CBaseHandle m_hAttackerPawn;
CHandle<CCSPlayerPawn> m_hAttackerPawn;
uint16_t m_nAttackerPlayerSlot;
int m_iTeamChecked;
int m_nTeam;
Expand Down
21 changes: 21 additions & 0 deletions src/detours.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ DECLARE_DETOUR(TraceShape, Detour_TraceShape);

static bool g_bBlockMolotovSelfDmg = false;
static bool g_bBlockAllDamage = false;
static bool g_bFixBlockDamage = false;

FAKE_BOOL_CVAR(cs2f_block_molotov_self_dmg, "Whether to block self-damage from molotovs", g_bBlockMolotovSelfDmg, false, false)
FAKE_BOOL_CVAR(cs2f_block_all_dmg, "Whether to block all damage to players", g_bBlockAllDamage, false, false)
FAKE_BOOL_CVAR(cs2f_fix_block_dmg, "Whether to fix block-damage on players", g_bFixBlockDamage, false, false)

void FASTCALL Detour_CBaseEntity_TakeDamageOld(CBaseEntity *pThis, CTakeDamageInfo *inputInfo)
{
Expand Down Expand Up @@ -110,6 +112,25 @@ void FASTCALL Detour_CBaseEntity_TakeDamageOld(CBaseEntity *pThis, CTakeDamageIn
CBaseEntity *pInflictor = inputInfo->m_hInflictor.Get();
const char *pszInflictorClass = pInflictor ? pInflictor->GetClassname() : "";

// After Armory update, activator became attacker on block damage, which broke it..
if (g_bFixBlockDamage && inputInfo->m_AttackerInfo.m_bIsPawn && inputInfo->m_bitsDamageType ^ DMG_BULLET && inputInfo->m_hAttacker != pThis->GetHandle())
{
if (V_strcasecmp(pszInflictorClass, "func_movelinear") == 0
|| V_strcasecmp(pszInflictorClass, "func_mover") == 0
|| V_strcasecmp(pszInflictorClass, "func_door") == 0
|| V_strcasecmp(pszInflictorClass, "func_door_rotating") == 0
|| V_strcasecmp(pszInflictorClass, "func_rotating") == 0
|| V_strcasecmp(pszInflictorClass, "point_hurt") == 0)
{
inputInfo->m_AttackerInfo.m_bIsPawn = false;
inputInfo->m_AttackerInfo.m_bIsWorld = true;
inputInfo->m_hAttacker = inputInfo->m_hInflictor;

inputInfo->m_AttackerInfo.m_hAttackerPawn = CHandle<CCSPlayerPawn>(~0u);
inputInfo->m_AttackerInfo.m_nAttackerPlayerSlot = ~0;
}
}

// Prevent everything but nades from inflicting blast damage
if (inputInfo->m_bitsDamageType == DamageTypes_t::DMG_BLAST && V_strncmp(pszInflictorClass, "hegrenade", 9))
inputInfo->m_bitsDamageType = DamageTypes_t::DMG_GENERIC;
Expand Down

0 comments on commit 5534568

Please sign in to comment.