From 231a97be07be614225ebf65d5f25bd50c9d57f3f Mon Sep 17 00:00:00 2001 From: dystopm Date: Mon, 17 Jul 2023 12:21:28 -0400 Subject: [PATCH] m_bHasSecondaryAttack refactory - Member name changed to m_iStateSecondaryAttack - Member type changed to uint8_t which has same size of bool but allows more values than true or false (this wont break API compatibility) - Moved logic inside HasSecondaryAttack to correctly alter function return based on m_iStateSecondaryAttack, which can be (0) no value / null (1) set (2) block -Removed logic in CBasePlayerWeapon::Spawn that caches the return value of HasSecondaryAttack, as this can only be overridden when set, rather than always --- regamedll/dlls/weapons.cpp | 62 +++++++++---------- .../public/regamedll/API/CSPlayerWeapon.h | 15 +++-- 2 files changed, 42 insertions(+), 35 deletions(-) diff --git a/regamedll/dlls/weapons.cpp b/regamedll/dlls/weapons.cpp index ebdb45c9b..fd58896b1 100644 --- a/regamedll/dlls/weapons.cpp +++ b/regamedll/dlls/weapons.cpp @@ -814,44 +814,48 @@ BOOL CanAttack(float attack_time, float curtime, BOOL isPredicted) bool CBasePlayerWeapon::HasSecondaryAttack() { - if (m_pPlayer && m_pPlayer->HasShield()) +#ifdef REGAMEDLL_API + if (CSPlayerWeapon()->m_iStateSecondaryAttack != CCSPlayerWeapon::WEAPON_SECONDARY_ATTACK_NONE) { - return true; + switch (CSPlayerWeapon()->m_iStateSecondaryAttack) + { + case CCSPlayerWeapon::WEAPON_SECONDARY_ATTACK_SET: + return true; + case CCSPlayerWeapon::WEAPON_SECONDARY_ATTACK_BLOCK: + return false; + default: + break; + } } +#endif -#ifdef REGAMEDLL_API - if (CSPlayerWeapon()->m_bHasSecondaryAttack) + if (m_pPlayer && m_pPlayer->HasShield()) { return true; } - if (CSPlayerWeapon()->m_bBlockSecondaryAttack) - { - return false; - } -#endif switch (m_iId) { - case WEAPON_AK47: - case WEAPON_XM1014: - case WEAPON_MAC10: - case WEAPON_ELITE: - case WEAPON_FIVESEVEN: - case WEAPON_MP5N: + case WEAPON_AK47: + case WEAPON_XM1014: + case WEAPON_MAC10: + case WEAPON_ELITE: + case WEAPON_FIVESEVEN: + case WEAPON_MP5N: #ifdef BUILD_LATEST_FIXES - case WEAPON_UMP45: + case WEAPON_UMP45: #endif - case WEAPON_M249: - case WEAPON_M3: - case WEAPON_TMP: - case WEAPON_DEAGLE: - case WEAPON_P228: - case WEAPON_P90: - case WEAPON_C4: - case WEAPON_GALIL: - return false; - default: - break; + case WEAPON_M249: + case WEAPON_M3: + case WEAPON_TMP: + case WEAPON_DEAGLE: + case WEAPON_P228: + case WEAPON_P90: + case WEAPON_C4: + case WEAPON_GALIL: + return false; + default: + break; } return true; @@ -1199,10 +1203,6 @@ void CBasePlayerWeapon::Spawn() if (GetItemInfo(&info)) { CSPlayerItem()->SetItemInfo(&info); } - - bool secondaryAble = HasSecondaryAttack(); - CSPlayerWeapon()->m_bHasSecondaryAttack = secondaryAble; - CSPlayerWeapon()->m_bBlockSecondaryAttack = !secondaryAble; // this could be only one member *sigh* #endif } diff --git a/regamedll/public/regamedll/API/CSPlayerWeapon.h b/regamedll/public/regamedll/API/CSPlayerWeapon.h index c36c838cc..73719ede0 100644 --- a/regamedll/public/regamedll/API/CSPlayerWeapon.h +++ b/regamedll/public/regamedll/API/CSPlayerWeapon.h @@ -33,8 +33,7 @@ class CCSPlayerWeapon: public CCSPlayerItem { public: CCSPlayerWeapon() : - m_bHasSecondaryAttack(false), - m_bBlockSecondaryAttack(false) + m_iStateSecondaryAttack(WEAPON_SECONDARY_ATTACK_NONE) { } @@ -47,9 +46,16 @@ class CCSPlayerWeapon: public CCSPlayerItem CBasePlayerWeapon *BasePlayerWeapon() const; public: - bool m_bHasSecondaryAttack; + enum SecondaryAtkState : uint8_t + { + WEAPON_SECONDARY_ATTACK_NONE = 0, + WEAPON_SECONDARY_ATTACK_SET, + WEAPON_SECONDARY_ATTACK_BLOCK + }; + +public: + SecondaryAtkState m_iStateSecondaryAttack; float m_flBaseDamage; - bool m_bBlockSecondaryAttack; }; // Inlines @@ -57,3 +63,4 @@ inline CBasePlayerWeapon *CCSPlayerWeapon::BasePlayerWeapon() const { return reinterpret_cast(this->m_pContainingEntity); } +