Skip to content

Commit

Permalink
m_bHasSecondaryAttack refactory
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
dystopm committed Jul 17, 2023
1 parent cf5bfb6 commit 231a97b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 35 deletions.
62 changes: 31 additions & 31 deletions regamedll/dlls/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}

Expand Down
15 changes: 11 additions & 4 deletions regamedll/public/regamedll/API/CSPlayerWeapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class CCSPlayerWeapon: public CCSPlayerItem
{
public:
CCSPlayerWeapon() :
m_bHasSecondaryAttack(false),
m_bBlockSecondaryAttack(false)
m_iStateSecondaryAttack(WEAPON_SECONDARY_ATTACK_NONE)
{
}

Expand All @@ -47,13 +46,21 @@ 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
inline CBasePlayerWeapon *CCSPlayerWeapon::BasePlayerWeapon() const
{
return reinterpret_cast<CBasePlayerWeapon *>(this->m_pContainingEntity);
}

0 comments on commit 231a97b

Please sign in to comment.