From f7250c8288fb6208e1147b23af8ec633c43dcf34 Mon Sep 17 00:00:00 2001 From: A1mDev <33463136+A1mDev@users.noreply.github.com> Date: Sun, 19 Oct 2025 20:05:19 +0700 Subject: [PATCH] Added missing fields to the `CTakeDamageInfo` class, the actual size of the structure is 96 bytes. - Updated `CTakeDamageInfo` to include new class fields (`m_flRadius` and `m_iDamageVictimIndex`) for clarity and future compatibility. - Existing hooks remain fully compatible. - Crashes in SourceMod do not occur due to an incorrect stack, because the structure is always passed by reference or pointer. - Updating the structure is recommended for cases where manual access to all fields or other special use cases is required. --- game/shared/takedamageinfo.cpp | 28 ++++++++++++++--------- game/shared/takedamageinfo.h | 42 +++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 12 deletions(-) diff --git a/game/shared/takedamageinfo.cpp b/game/shared/takedamageinfo.cpp index ccead8c3b..595f1c619 100644 --- a/game/shared/takedamageinfo.cpp +++ b/game/shared/takedamageinfo.cpp @@ -16,18 +16,20 @@ ConVar phys_pushscale( "phys_pushscale", "1", FCVAR_REPLICATED ); BEGIN_SIMPLE_DATADESC( CTakeDamageInfo ) DEFINE_FIELD( m_vecDamageForce, FIELD_VECTOR ), - DEFINE_FIELD( m_vecDamagePosition, FIELD_POSITION_VECTOR), - DEFINE_FIELD( m_vecReportedPosition, FIELD_POSITION_VECTOR), - DEFINE_FIELD( m_hInflictor, FIELD_EHANDLE), - DEFINE_FIELD( m_hAttacker, FIELD_EHANDLE), - DEFINE_FIELD( m_hWeapon, FIELD_EHANDLE), - DEFINE_FIELD( m_flDamage, FIELD_FLOAT), - DEFINE_FIELD( m_flMaxDamage, FIELD_FLOAT), + DEFINE_FIELD( m_vecDamagePosition, FIELD_POSITION_VECTOR ), + DEFINE_FIELD( m_vecReportedPosition, FIELD_POSITION_VECTOR ), + DEFINE_FIELD( m_hInflictor, FIELD_EHANDLE ), + DEFINE_FIELD( m_hAttacker, FIELD_EHANDLE ), + DEFINE_FIELD( m_hWeapon, FIELD_EHANDLE ), + DEFINE_FIELD( m_flDamage, FIELD_FLOAT ), + DEFINE_FIELD( m_flMaxDamage, FIELD_FLOAT ), DEFINE_FIELD( m_flBaseDamage, FIELD_FLOAT ), - DEFINE_FIELD( m_bitsDamageType, FIELD_INTEGER), - DEFINE_FIELD( m_iDamageCustom, FIELD_INTEGER), - DEFINE_FIELD( m_iDamageStats, FIELD_INTEGER), - DEFINE_FIELD( m_iAmmoType, FIELD_INTEGER), + DEFINE_FIELD( m_bitsDamageType, FIELD_INTEGER ), + DEFINE_FIELD( m_iDamageCustom, FIELD_INTEGER ), + DEFINE_FIELD( m_iDamageStats, FIELD_INTEGER ), + DEFINE_FIELD( m_iAmmoType, FIELD_INTEGER ), + DEFINE_FIELD( m_flRadius, FIELD_FLOAT ), + DEFINE_FIELD( m_iDamageVictimIndex, FIELD_INTEGER ), END_DATADESC() void CTakeDamageInfo::Init( CBaseEntity *pInflictor, CBaseEntity *pAttacker, CBaseEntity *pWeapon, const Vector &damageForce, const Vector &damagePosition, const Vector &reportedPosition, float flDamage, int bitsDamageType, int iCustomDamage ) @@ -56,6 +58,10 @@ void CTakeDamageInfo::Init( CBaseEntity *pInflictor, CBaseEntity *pAttacker, CBa m_vecDamagePosition = damagePosition; m_vecReportedPosition = reportedPosition; m_iAmmoType = -1; + + m_vecDamageDirection = vec3_origin; + m_flRadius = 0.0; + m_iDamageVictimIndex = 0; } CTakeDamageInfo::CTakeDamageInfo() diff --git a/game/shared/takedamageinfo.h b/game/shared/takedamageinfo.h index a7e115353..12e9e0d9d 100644 --- a/game/shared/takedamageinfo.h +++ b/game/shared/takedamageinfo.h @@ -80,6 +80,15 @@ class CTakeDamageInfo void SetAmmoType( int iAmmoType ); const char * GetAmmoName() const; + Vector GetDamageDirection() const; + void SetDamageDirection( const Vector &damageDirection ); + + float GetRadius() const; + void SetRadius( float flRadius ); + + float GetVictimIndex() const; + void SetVictimIndex( int iVictimIndex ); + void Set( CBaseEntity *pInflictor, CBaseEntity *pAttacker, float flDamage, int bitsDamageType, int iKillType = 0 ); void Set( CBaseEntity *pInflictor, CBaseEntity *pAttacker, CBaseEntity *pWeapon, float flDamage, int bitsDamageType, int iKillType = 0 ); void Set( CBaseEntity *pInflictor, CBaseEntity *pAttacker, const Vector &damageForce, const Vector &damagePosition, float flDamage, int bitsDamageType, int iKillType = 0, Vector *reportedPosition = NULL ); @@ -102,7 +111,7 @@ class CTakeDamageInfo Vector m_vecDamageForce; Vector m_vecDamagePosition; Vector m_vecReportedPosition; // Position players are told damage is coming from - Vector m_vecUnknown; + Vector m_vecDamageDirection; // The type matches, but I'm not sure about the name; the name is taken from new games. EHANDLE m_hInflictor; EHANDLE m_hAttacker; EHANDLE m_hWeapon; @@ -113,6 +122,8 @@ class CTakeDamageInfo int m_iDamageCustom; int m_iDamageStats; int m_iAmmoType; // AmmoType of the weapon used to cause this damage, if any + int m_flRadius; + int m_iDamageVictimIndex; DECLARE_SIMPLE_DATADESC(); }; @@ -331,6 +342,35 @@ inline void CTakeDamageInfo::CopyDamageToBaseDamage() m_flBaseDamage = m_flDamage; } +inline Vector CTakeDamageInfo::GetDamageDirection() const +{ + return m_vecDamageDirection; +} + +inline void CTakeDamageInfo::SetDamageDirection( const Vector &damageDirection ) +{ + m_vecDamageDirection = damageDirection; +} + +inline float CTakeDamageInfo::GetRadius() const +{ + return m_flRadius; +} + +inline void CTakeDamageInfo::SetRadius( float flRadius ) +{ + m_flRadius = flRadius; +} + +inline float CTakeDamageInfo::GetVictimIndex() const +{ + return m_iDamageVictimIndex; +} + +inline void CTakeDamageInfo::SetVictimIndex( int iVictimIndex ) +{ + m_iDamageVictimIndex = iVictimIndex; +} // -------------------------------------------------------------------------------------------------- // // Inlines.