From f6c21f15c0dcb1058cad6ea69dad316d226fac27 Mon Sep 17 00:00:00 2001 From: "ALLEN-PC\\acj30" Date: Sun, 26 Jan 2025 12:04:15 -0600 Subject: [PATCH] Make dual wielded pistols capable of being fired with IN_ATTACK2 (both mouse buttons) --- sp/src/game/server/hl2/weapon_pistol.cpp | 2 + .../shared/hl2/basehlcombatweapon_shared.cpp | 37 +++++++++++++++++++ .../shared/hl2/basehlcombatweapon_shared.h | 2 + 3 files changed, 41 insertions(+) diff --git a/sp/src/game/server/hl2/weapon_pistol.cpp b/sp/src/game/server/hl2/weapon_pistol.cpp index ce575c082b7..d206554eda5 100644 --- a/sp/src/game/server/hl2/weapon_pistol.cpp +++ b/sp/src/game/server/hl2/weapon_pistol.cpp @@ -667,6 +667,8 @@ class CWeaponPulsePistol : public CWeaponPistol virtual bool Reload( void ) { return false; } // The pulse pistol does not reload + bool DualWieldOverridesSecondary() const { return false; } + virtual int GetMaxClip2( void ) const { int iBase = BaseClass::GetMaxClip2(); diff --git a/sp/src/game/shared/hl2/basehlcombatweapon_shared.cpp b/sp/src/game/shared/hl2/basehlcombatweapon_shared.cpp index eb62441d8d1..fc4592b1dc2 100644 --- a/sp/src/game/shared/hl2/basehlcombatweapon_shared.cpp +++ b/sp/src/game/shared/hl2/basehlcombatweapon_shared.cpp @@ -8,6 +8,7 @@ #include "basehlcombatweapon_shared.h" #if defined(EZ2) && defined(GAME_DLL) #include "npcevent.h" +#include "in_buttons.h" #endif #include "hl2_player_shared.h" @@ -261,6 +262,42 @@ void CBaseHLCombatWeapon::WeaponIdle( void ) } #ifdef EZ2 +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void CBaseHLCombatWeapon::ItemPostFrame( void ) +{ +#ifdef GAME_DLL + // When dual wielding, secondary attack is synonymous with primary attack + if (IsDualWielding() && DualWieldOverridesSecondary()) + { + CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); + if ( pOwner != NULL ) + { + if (pOwner->m_nButtons & IN_ATTACK2) + { + pOwner->m_nButtons |= IN_ATTACK; + pOwner->m_nButtons &= ~IN_ATTACK2; + } + + if (pOwner->m_afButtonPressed & IN_ATTACK2) + { + pOwner->m_afButtonPressed |= IN_ATTACK; + pOwner->m_afButtonPressed &= ~IN_ATTACK2; + } + + if (pOwner->m_afButtonReleased & IN_ATTACK2) + { + pOwner->m_afButtonReleased |= IN_ATTACK; + pOwner->m_afButtonReleased &= ~IN_ATTACK2; + } + } + } +#endif + + BaseClass::ItemPostFrame(); +} + //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- diff --git a/sp/src/game/shared/hl2/basehlcombatweapon_shared.h b/sp/src/game/shared/hl2/basehlcombatweapon_shared.h index 8468bba83b2..8464bc9ef15 100644 --- a/sp/src/game/shared/hl2/basehlcombatweapon_shared.h +++ b/sp/src/game/shared/hl2/basehlcombatweapon_shared.h @@ -57,12 +57,14 @@ class CBaseHLCombatWeapon : public CBaseCombatWeapon // // Dual wielding // + virtual void ItemPostFrame( void ); virtual const char *GetViewModel( int viewmodelindex = 0 ) const; virtual CHudTexture const *GetSpriteActive( void ) const; virtual CHudTexture const *GetSpriteInactive( void ) const; virtual bool CanDualWield() const { return false; } + virtual bool DualWieldOverridesSecondary() const { return true; } bool IsDualWielding() const { return m_hLeftHandGun != NULL; } CBaseAnimating *GetLeftHandGun() const { return m_hLeftHandGun; }