From 9ab1589d3252032e9db3b74be8bd131f96714f18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Mu=C3=B1oz?= Date: Sun, 26 Nov 2023 01:21:04 -0300 Subject: [PATCH] Use CSEntity member to hold last inflictor from TakeDamage (#896) --- regamedll/dlls/basemonster.cpp | 10 ++----- regamedll/dlls/cbase.cpp | 4 +++ regamedll/dlls/cbase.h | 3 ++ regamedll/dlls/player.cpp | 8 ++++-- regamedll/dlls/player.h | 2 ++ regamedll/public/regamedll/API/CSEntity.h | 35 ++++++++++++++++++++--- 6 files changed, 48 insertions(+), 14 deletions(-) diff --git a/regamedll/dlls/basemonster.cpp b/regamedll/dlls/basemonster.cpp index a134d99c..bfa9a1e1 100644 --- a/regamedll/dlls/basemonster.cpp +++ b/regamedll/dlls/basemonster.cpp @@ -451,17 +451,13 @@ BOOL CBaseMonster::TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, f if (pev->health <= 0.0f) { - g_pevLastInflictor = pevInflictor; - if (bitsDamageType & DMG_ALWAYSGIB) - Killed(pevAttacker, GIB_ALWAYS); - + KilledInflicted(pevInflictor, pevAttacker, GIB_ALWAYS); else if (bitsDamageType & DMG_NEVERGIB) - Killed(pevAttacker, GIB_NEVER); + KilledInflicted(pevInflictor, pevAttacker, GIB_NEVER); else - Killed(pevAttacker, GIB_NORMAL); + KilledInflicted(pevInflictor, pevAttacker, GIB_NORMAL); - g_pevLastInflictor = nullptr; return FALSE; } if ((pev->flags & FL_MONSTER) && !FNullEnt(pevAttacker)) diff --git a/regamedll/dlls/cbase.cpp b/regamedll/dlls/cbase.cpp index 9e14bf43..a779c69c 100644 --- a/regamedll/dlls/cbase.cpp +++ b/regamedll/dlls/cbase.cpp @@ -697,7 +697,11 @@ BOOL CBaseEntity::TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, fl pev->health -= flDamage; if (pev->health <= 0) { +#ifdef REGAMEDLL_FIXES + KilledInflicted(pevInflictor, pevAttacker, GIB_NORMAL); +#else Killed(pevAttacker, GIB_NORMAL); +#endif return FALSE; } diff --git a/regamedll/dlls/cbase.h b/regamedll/dlls/cbase.h index 986933f5..e6830142 100644 --- a/regamedll/dlls/cbase.h +++ b/regamedll/dlls/cbase.h @@ -246,6 +246,9 @@ public: void ResetDmgPenetrationLevel(); int GetDmgPenetrationLevel() const; + void KilledInflicted(entvars_t *pevInflictor, entvars_t *pevAttacker, int iGib); + entvars_t *GetLastInflictor(); + #ifdef REGAMEDLL_API CCSEntity *m_pEntity; CCSEntity *CSEntity() const; diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index 5e7eed2f..030c4c04 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -82,7 +82,9 @@ const char *CDeadHEV::m_szPoses[] = "deadtable" }; +#ifndef REGAMEDLL_API entvars_t *g_pevLastInflictor; +#endif LINK_ENTITY_TO_CLASS(player, CBasePlayer, CCSPlayer) @@ -2130,7 +2132,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Killed)(entvars_t *pevAttacker, int iGib) if (IsBot() && IsBlind()) // dystopm: shouldn't be !IsBot() ? wasBlind = true; - TheCareerTasks->HandleEnemyKill(wasBlind, GetKillerWeaponName(g_pevLastInflictor, pevAttacker), m_bHeadshotKilled, killerHasShield, pAttacker, this); // last 2 param swapped to match function definition + TheCareerTasks->HandleEnemyKill(wasBlind, GetKillerWeaponName(GetLastInflictor(), pevAttacker), m_bHeadshotKilled, killerHasShield, pAttacker, this); // last 2 param swapped to match function definition } } #endif @@ -2161,7 +2163,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Killed)(entvars_t *pevAttacker, int iGib) { if (TheCareerTasks) { - TheCareerTasks->HandleEnemyKill(wasBlind, GetKillerWeaponName(g_pevLastInflictor, pevAttacker), m_bHeadshotKilled, killerHasShield, this, pPlayer); + TheCareerTasks->HandleEnemyKill(wasBlind, GetKillerWeaponName(GetLastInflictor(), pevAttacker), m_bHeadshotKilled, killerHasShield, this, pPlayer); } } } @@ -2171,7 +2173,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Killed)(entvars_t *pevAttacker, int iGib) if (!m_bKilledByBomb) { - g_pGameRules->PlayerKilled(this, pevAttacker, g_pevLastInflictor); + g_pGameRules->PlayerKilled(this, pevAttacker, GetLastInflictor()); } MESSAGE_BEGIN(MSG_ONE, gmsgNVGToggle, nullptr, pev); diff --git a/regamedll/dlls/player.h b/regamedll/dlls/player.h index d3b8e623..ce201dea 100644 --- a/regamedll/dlls/player.h +++ b/regamedll/dlls/player.h @@ -975,7 +975,9 @@ inline CBasePlayer *UTIL_PlayerByIndexSafe(int playerIndex) return pPlayer; } +#ifndef REGAMEDLL_API extern entvars_t *g_pevLastInflictor; +#endif extern CBaseEntity *g_pLastSpawn; extern CBaseEntity *g_pLastCTSpawn; extern CBaseEntity *g_pLastTerroristSpawn; diff --git a/regamedll/public/regamedll/API/CSEntity.h b/regamedll/public/regamedll/API/CSEntity.h index e2c1922c..4c4f1fce 100644 --- a/regamedll/public/regamedll/API/CSEntity.h +++ b/regamedll/public/regamedll/API/CSEntity.h @@ -46,12 +46,13 @@ public: public: CBaseEntity *m_pContainingEntity; unsigned char m_ucDmgPenetrationLevel; // penetration level of the damage caused by the inflictor + entvars_t *m_pevLastInflictor; private: #if defined(_MSC_VER) #pragma region reserve_data_Region #endif - char CCSEntity_Reserve[0x3FFF]; + char CCSEntity_Reserve[0x3FF7]; virtual void func_reserve1() {}; virtual void func_reserve2() {}; @@ -91,26 +92,52 @@ private: inline void CBaseEntity::SetDmgPenetrationLevel(int iPenetrationLevel) { #ifdef REGAMEDLL_API - m_pEntity->m_ucDmgPenetrationLevel = iPenetrationLevel; + CSEntity()->m_ucDmgPenetrationLevel = iPenetrationLevel; #endif } inline void CBaseEntity::ResetDmgPenetrationLevel() { #ifdef REGAMEDLL_API - m_pEntity->m_ucDmgPenetrationLevel = 0; + CSEntity()->m_ucDmgPenetrationLevel = 0; #endif } inline int CBaseEntity::GetDmgPenetrationLevel() const { #ifdef REGAMEDLL_API - return m_pEntity->m_ucDmgPenetrationLevel; + return CSEntity()->m_ucDmgPenetrationLevel; #else return 0; #endif } +inline void CBaseEntity::KilledInflicted(entvars_t* pevInflictor, entvars_t *pevAttacker, int iGib) +{ +#ifdef REGAMEDLL_API + CSEntity()->m_pevLastInflictor = pevInflictor; +#else + g_pevLastInflictor = pevInflictor; +#endif + + Killed(pevAttacker, iGib); + +#ifdef REGAMEDLL_API + CSEntity()->m_pevLastInflictor = nullptr; +#else + g_pevLastInflictor = nullptr; +#endif +} + +inline entvars_t* CBaseEntity::GetLastInflictor() +{ +#ifdef REGAMEDLL_API + return CSEntity()->m_pevLastInflictor; +#else + return g_pevLastInflictor; +#endif +} + class CCSDelay: public CCSEntity { public: