From 689dd82d41d232bb6e9bd465a62ff957871c4aad Mon Sep 17 00:00:00 2001 From: dystopm Date: Sun, 3 Dec 2023 21:50:16 -0300 Subject: [PATCH 1/2] Add member m_iGibDamageThreshold to control GIB damage threshold --- regamedll/dlls/player.cpp | 2 +- regamedll/dlls/player.h | 1 + regamedll/public/regamedll/API/CSPlayer.h | 15 ++++++++++++++- regamedll/public/regamedll/regamedll_const.h | 1 + 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index 3fdad71bc..176ff36a5 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -2455,7 +2455,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Killed)(entvars_t *pevAttacker, int iGib) HintMessage("#Hint_cannot_play_because_tk", TRUE, TRUE); } - if ((pev->health < -9000 && iGib != GIB_NEVER) || iGib == GIB_ALWAYS) + if (ShouldGibPlayer(iGib)) { #ifndef REGAMEDLL_FIXES diff --git a/regamedll/dlls/player.h b/regamedll/dlls/player.h index bd3bf33ed..5e90890d5 100644 --- a/regamedll/dlls/player.h +++ b/regamedll/dlls/player.h @@ -641,6 +641,7 @@ class CBasePlayer: public CBaseMonster { bool ShouldToShowAccount(CBasePlayer *pReceiver) const; bool ShouldToShowHealthInfo(CBasePlayer *pReceiver) const; const char *GetKillerWeaponName(entvars_t *pevInflictor, entvars_t *pevKiller) const; + bool ShouldGibPlayer(int iGib); CBasePlayerItem *GetItemByName(const char *itemName); CBasePlayerItem *GetItemById(WeaponIdType weaponID); diff --git a/regamedll/public/regamedll/API/CSPlayer.h b/regamedll/public/regamedll/API/CSPlayer.h index 476b20013..72349040b 100644 --- a/regamedll/public/regamedll/API/CSPlayer.h +++ b/regamedll/public/regamedll/API/CSPlayer.h @@ -56,7 +56,8 @@ class CCSPlayer: public CCSMonster { m_flLongJumpHeight(0), m_flLongJumpForce(0), m_flDuckSpeedMultiplier(0), - m_iUserID(-1) + m_iUserID(-1), + m_iGibDamageThreshold(GIB_PLAYER_THRESHOLD) { m_szModel[0] = '\0'; @@ -172,6 +173,8 @@ class CCSPlayer: public CCSMonster { void RecordDamage(CBasePlayer *pAttacker, float flDamage, float flFlashDurationTime = -1); int m_iNumKilledByUnanswered[MAX_CLIENTS]; // [0-31] how many unanswered kills this player has been dealt by each other player bool m_bPlayerDominated[MAX_CLIENTS]; // [0-31] array of state per other player whether player is dominating other players + + int m_iGibDamageThreshold; // negative health to reach to gib player }; // Inlines @@ -210,3 +213,13 @@ inline void CCSPlayer::SetPlayerDominated(CBasePlayer *pPlayer, bool bDominated) assert(iPlayerIndex >= 0 && iPlayerIndex < MAX_CLIENTS); m_bPlayerDominated[iPlayerIndex - 1] = bDominated; } + +inline bool CBasePlayer::ShouldGibPlayer(int iGib) +{ +#ifdef REGAMEDLL_API + int threshold = CSPlayer()->m_iGibDamageThreshold; +#else + int threshold = GIB_PLAYER_THRESHOLD; +#endif + return ((pev->health < threshold && iGib != GIB_NEVER) || iGib == GIB_ALWAYS); +} diff --git a/regamedll/public/regamedll/regamedll_const.h b/regamedll/public/regamedll/regamedll_const.h index ddbe62af4..4599c58f2 100644 --- a/regamedll/public/regamedll/regamedll_const.h +++ b/regamedll/public/regamedll/regamedll_const.h @@ -106,3 +106,4 @@ #define GIB_NEVER 1 // Never gib, no matter how much death damage is done ( freezing, etc ) #define GIB_ALWAYS 2 // Always gib ( Houndeye Shock, Barnacle Bite ) #define GIB_HEALTH_VALUE -30 +#define GIB_PLAYER_THRESHOLD -9000 From b998d987b6accea67f2b7a150247819c03522f22 Mon Sep 17 00:00:00 2001 From: s1lentq Date: Tue, 12 Dec 2023 19:23:46 +0700 Subject: [PATCH 2/2] Refactoring API functions --- regamedll/dlls/player.h | 21 +++++++++++++++++++-- regamedll/public/regamedll/API/CSPlayer.h | 19 +++++++++++++------ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/regamedll/dlls/player.h b/regamedll/dlls/player.h index 0a35faa28..a3f0411f1 100644 --- a/regamedll/dlls/player.h +++ b/regamedll/dlls/player.h @@ -448,7 +448,7 @@ class CBasePlayer: public CBaseMonster { edict_t *EntSelectSpawnPoint_OrigFunc(); void PlayerDeathThink_OrigFunc(); void Observer_Think_OrigFunc(); - + CCSPlayer *CSPlayer() const; #endif // REGAMEDLL_API @@ -955,7 +955,24 @@ inline bool CBasePlayer::HasTimePassedSinceDeath(float duration) const inline CCSPlayer *CBasePlayer::CSPlayer() const { return reinterpret_cast(this->m_pEntity); } -#endif +#else // !REGAMEDLL_API + +// Determine whether player can be gibbed or not +inline bool CBasePlayer::ShouldGibPlayer(int iGib) +{ + // Always gib the player regardless of incoming damage + if (iGib == GIB_ALWAYS) + return true; + + // Gib the player if health is below the gib damage threshold + if (pev->health < GIB_PLAYER_THRESHOLD && iGib != GIB_NEVER) + return true; + + // do not gib the player + return false; +} + +#endif // !REGAMEDLL_API #ifdef REGAMEDLL_FIXES diff --git a/regamedll/public/regamedll/API/CSPlayer.h b/regamedll/public/regamedll/API/CSPlayer.h index 72349040b..6261e567f 100644 --- a/regamedll/public/regamedll/API/CSPlayer.h +++ b/regamedll/public/regamedll/API/CSPlayer.h @@ -214,12 +214,19 @@ inline void CCSPlayer::SetPlayerDominated(CBasePlayer *pPlayer, bool bDominated) m_bPlayerDominated[iPlayerIndex - 1] = bDominated; } +#ifdef REGAMEDLL_API +// Determine whether player can be gibbed or not inline bool CBasePlayer::ShouldGibPlayer(int iGib) { -#ifdef REGAMEDLL_API - int threshold = CSPlayer()->m_iGibDamageThreshold; -#else - int threshold = GIB_PLAYER_THRESHOLD; -#endif - return ((pev->health < threshold && iGib != GIB_NEVER) || iGib == GIB_ALWAYS); + // Always gib the player regardless of incoming damage + if (iGib == GIB_ALWAYS) + return true; + + // Gib the player if health is below the gib damage threshold + if (pev->health < CSPlayer()->m_iGibDamageThreshold && iGib != GIB_NEVER) + return true; + + // do not gib the player + return false; } +#endif