Skip to content

Commit

Permalink
Use CSEntity member to hold last inflictor from TakeDamage (#896)
Browse files Browse the repository at this point in the history
  • Loading branch information
dystopm authored Nov 26, 2023
1 parent e3d70d2 commit 9ab1589
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 14 deletions.
10 changes: 3 additions & 7 deletions regamedll/dlls/basemonster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/cbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions regamedll/dlls/cbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ class CBaseEntity {
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;
Expand Down
8 changes: 5 additions & 3 deletions regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions regamedll/dlls/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
35 changes: 31 additions & 4 deletions regamedll/public/regamedll/API/CSEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ class CCSEntity
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() {};
Expand Down Expand Up @@ -91,26 +92,52 @@ class CCSEntity
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:
Expand Down

0 comments on commit 9ab1589

Please sign in to comment.