From 0688b2ef65fde3b7c9ea460d1fb5f6c784d895e3 Mon Sep 17 00:00:00 2001 From: pierow Date: Wed, 7 Feb 2024 00:48:35 -0500 Subject: [PATCH] fix pistol firing when closing game menu or tabbing in --- main/config.cfg | 1 + main/source/cl_dll/hl/hl_weapons.cpp | 8 +++--- main/source/cl_dll/input.cpp | 34 +++---------------------- main/source/dlls/player.h | 3 +++ main/source/dlls/weapons.cpp | 7 ++--- main/source/dlls/weapons.h | 4 +-- main/source/mod/AvHBasePlayerWeapon.cpp | 8 +++--- main/source/mod/AvHBasePlayerWeapon.h | 4 ++- main/source/mod/AvHGamerules.cpp | 18 ++++++------- main/source/mod/AvHGrenade.cpp | 2 +- main/source/mod/AvHMarineWeapons.h | 6 ++--- main/source/mod/AvHPistol.cpp | 13 +++++++--- main/source/mod/AvHPlayer.h | 4 --- 13 files changed, 49 insertions(+), 63 deletions(-) diff --git a/main/config.cfg b/main/config.cfg index 230b71a4..5bdeeb84 100644 --- a/main/config.cfg +++ b/main/config.cfg @@ -185,6 +185,7 @@ cl_bob "0.006" cl_bobcycle "0.85" cl_bobup "0.5" cl_weaponswap "2" +cl_pistoltrigger "1" +mlook exec userconfig.cfg diff --git a/main/source/cl_dll/hl/hl_weapons.cpp b/main/source/cl_dll/hl/hl_weapons.cpp index ed50f9c5..63fbccd2 100644 --- a/main/source/cl_dll/hl/hl_weapons.cpp +++ b/main/source/cl_dll/hl/hl_weapons.cpp @@ -525,7 +525,9 @@ void CBasePlayerWeapon::ItemPostFrame( void ) } } - if ((m_pPlayer->pev->button & IN_ATTACK || this->m_bAttackQueued) && (!(m_pPlayer->pev->button & IN_ATTACK2) || gHUD.GetHUDUser3() == AVH_USER3_ALIEN_PLAYER3)) + bool pistolAttackUp = ((CVAR_GET_FLOAT("cl_pistoltrigger") != 0) && m_pPlayer->m_afButtonLast & IN_ATTACK && m_pPlayer->m_afButtonReleased & IN_ATTACK && ii.iId == AVH_WEAPON_PISTOL); + + if ((m_pPlayer->pev->button & IN_ATTACK || this->m_bAttackQueued || pistolAttackUp) && (!(m_pPlayer->pev->button & IN_ATTACK2) || gHUD.GetHUDUser3() == AVH_USER3_ALIEN_PLAYER3)) { if (GetCanUseWeapon()) { @@ -574,12 +576,12 @@ void CBasePlayerWeapon::ItemPostFrame( void ) //#ifdef AVH_CLIENT //if((m_iClip == 0) && ? //#endif - PrimaryAttack(); + PrimaryAttack(pistolAttackUp); //return; } else { - QueueAttack(); + QueueAttack(pistolAttackUp); } } } diff --git a/main/source/cl_dll/input.cpp b/main/source/cl_dll/input.cpp index a3fa00dd..9df85169 100644 --- a/main/source/cl_dll/input.cpp +++ b/main/source/cl_dll/input.cpp @@ -826,32 +826,6 @@ void IN_AttackUpForced(void) KeyUpForced( &in_attack ); } -void IN_AttackHandlerDown(void) -{ - if (gHUD.GetCurrentWeaponID() == AVH_WEAPON_PISTOL && cl_pistoltrigger && cl_pistoltrigger->value) - { - IN_AttackDown(); - IN_AttackUp(); - } - else - { - IN_AttackDown(); - } -} - -void IN_AttackHandlerUp(void) -{ - if (gHUD.GetCurrentWeaponID() == AVH_WEAPON_PISTOL && cl_pistoltrigger && cl_pistoltrigger->value) - { - IN_AttackDown(); - IN_AttackUp(); - } - else - { - IN_AttackUp(); - } -} - // Special handling void IN_Cancel(void) { @@ -1565,8 +1539,6 @@ void NsPreset(void) char execText[1024]; //char localizedText[1024]; - inGameAdditional = gViewPort ? " See console for details." : ""; - switch (presetChoice) { case 1: @@ -1650,8 +1622,8 @@ void InitInput (void) gEngfuncs.pfnAddCommand ("-moveright", IN_MoverightUp); gEngfuncs.pfnAddCommand ("+speed", IN_SpeedDown); gEngfuncs.pfnAddCommand ("-speed", IN_SpeedUp); - gEngfuncs.pfnAddCommand ("+attack", IN_AttackHandlerDown); - gEngfuncs.pfnAddCommand ("-attack", IN_AttackHandlerUp); + gEngfuncs.pfnAddCommand ("+attack", IN_AttackDown); + gEngfuncs.pfnAddCommand ("-attack", IN_AttackUp); //gEngfuncs.pfnAddCommand ("+movement", IN_Attack2Down); //gEngfuncs.pfnAddCommand ("-movement", IN_Attack2Up); gEngfuncs.pfnAddCommand ("+use", IN_UseDown); @@ -1735,7 +1707,7 @@ void InitInput (void) cl_chatbeep = gEngfuncs.pfnRegisterVariable ("cl_chatbeep", "1", FCVAR_ARCHIVE); cl_mutemenu = gEngfuncs.pfnRegisterVariable ("cl_mutemenu", "3", FCVAR_ARCHIVE); cl_weaponcfgs = gEngfuncs.pfnRegisterVariable ("cl_weaponcfgs", "1", FCVAR_ARCHIVE); - cl_pistoltrigger = gEngfuncs.pfnRegisterVariable ("cl_pistoltrigger", "1", FCVAR_ARCHIVE); + cl_pistoltrigger = gEngfuncs.pfnRegisterVariable ("cl_pistoltrigger", "1", FCVAR_ARCHIVE | FCVAR_USERINFO); // Initialize third person camera controls. CAM_Init(); diff --git a/main/source/dlls/player.h b/main/source/dlls/player.h index 5b6255f9..12f086f2 100644 --- a/main/source/dlls/player.h +++ b/main/source/dlls/player.h @@ -361,6 +361,9 @@ public: // Added by mmcguire. virtual bool GetCanUseWeapon() const { return true; } + // Networked user options + int m_iAutoWeaponSwap; + int m_iPistolTrigger; }; #define AUTOAIM_2DEGREES 0.0348994967025 diff --git a/main/source/dlls/weapons.cpp b/main/source/dlls/weapons.cpp index 2db96011..7c451943 100644 --- a/main/source/dlls/weapons.cpp +++ b/main/source/dlls/weapons.cpp @@ -951,6 +951,7 @@ void CBasePlayerWeapon::ItemPostFrame( void ) { // Block attacks during +movement except for lerk. bool theAttackPressed = (m_pPlayer->pev->button & IN_ATTACK) && (!(m_pPlayer->pev->button & IN_ATTACK2) || m_pPlayer->pev->iuser3 == AVH_USER3_ALIEN_PLAYER3); + bool pistolAttackUp = (m_pPlayer->m_iPistolTrigger && m_pPlayer->m_afButtonLast & IN_ATTACK && m_pPlayer->m_afButtonReleased & IN_ATTACK && m_iId == AVH_WEAPON_PISTOL); bool theWeaponPrimes = (this->GetWeaponPrimeTime() > 0.0f); bool theWeaponIsPriming = this->GetIsWeaponPriming(); @@ -989,7 +990,7 @@ void CBasePlayerWeapon::ItemPostFrame( void ) else */ - if ( (theAttackPressed || m_bAttackQueued) && m_pPlayer->GetCanUseWeapon()) + if ( (theAttackPressed || m_bAttackQueued || pistolAttackUp) && m_pPlayer->GetCanUseWeapon()) { if ((m_fInSpecialReload == 1 || m_fInSpecialReload == 2) && m_iClip != 0) { @@ -1004,11 +1005,11 @@ void CBasePlayerWeapon::ItemPostFrame( void ) } m_pPlayer->TabulateAmmo(); - PrimaryAttack(); + PrimaryAttack(pistolAttackUp); } else { - QueueAttack(); + QueueAttack(pistolAttackUp); } } else if (m_pPlayer->pev->button & IN_ATTACK2) diff --git a/main/source/dlls/weapons.h b/main/source/dlls/weapons.h index 0ec91968..895e3314 100644 --- a/main/source/dlls/weapons.h +++ b/main/source/dlls/weapons.h @@ -353,8 +353,8 @@ public: virtual void ItemPostFrame( void ); // called each frame by the player PostThink // called by CBasePlayerWeapons ItemPostFrame() - virtual void PrimaryAttack( void ) { return; } // do "+ATTACK" - virtual void QueueAttack(void) { return; } // queue an attack + virtual void PrimaryAttack( bool fireOnAttackUp = false ) { return; } // do "+ATTACK" + virtual void QueueAttack( bool fireOnAttackUp = false ) { return; } // queue an attack virtual void SecondaryAttack( void ) { return; } // do "+ATTACK2" virtual void Reload( void ) { return; } // do "+RELOAD" virtual void WeaponIdle( void ) { return; } // called when no buttons pressed diff --git a/main/source/mod/AvHBasePlayerWeapon.cpp b/main/source/mod/AvHBasePlayerWeapon.cpp index eb740b0b..1d508297 100644 --- a/main/source/mod/AvHBasePlayerWeapon.cpp +++ b/main/source/mod/AvHBasePlayerWeapon.cpp @@ -180,6 +180,8 @@ AvHBasePlayerWeapon::AvHBasePlayerWeapon() this->mIsPersistent = false; this->mLifetime = -1; #endif + + this->mFireOnAttackUp = false; } void AvHBasePlayerWeapon::PrintWeaponToClient(CBaseEntity *theAvHPlayer) { char msg[1024]; @@ -779,7 +781,7 @@ bool AvHBasePlayerWeapon::ProcessValidAttack(void) { if((this->m_flNextPrimaryAttack <= 0) && !this->m_fInSpecialReload) { - if(!this->GetMustPressTriggerForEachShot() || (!this->mAttackButtonDownLastFrame)) + if(!this->GetMustPressTriggerForEachShot() || !this->mAttackButtonDownLastFrame || this->mFireOnAttackUp) { //ALERT(at_console, "trueattack1 primammo:%d primatype:%d secammo:%d secatype:%d\n", this->m_pPlayer->m_rgAmmo[this->m_iPrimaryAmmoType], this->m_iPrimaryAmmoType, this->m_pPlayer->m_rgAmmo[this->m_iSecondaryAmmoType], this->m_iSecondaryAmmoType); theAttackIsValid = true; @@ -1025,11 +1027,11 @@ void AvHBasePlayerWeapon::SetNextAttack(void) } -void AvHBasePlayerWeapon::PrimaryAttack(void) +void AvHBasePlayerWeapon::PrimaryAttack(bool fireOnAttackUp) { if (this->ProcessValidAttack()) { - + if (!this->mAttackButtonDownLastFrame) { this->PlaybackEvent(this->mStartEvent); diff --git a/main/source/mod/AvHBasePlayerWeapon.h b/main/source/mod/AvHBasePlayerWeapon.h index 1c19ab05..6ee75921 100644 --- a/main/source/mod/AvHBasePlayerWeapon.h +++ b/main/source/mod/AvHBasePlayerWeapon.h @@ -177,7 +177,7 @@ public: virtual void Precache(); - virtual void PrimaryAttack(); + virtual void PrimaryAttack(bool fireOnAttackUp = false); virtual void Reload(); @@ -261,6 +261,8 @@ protected: // sounds CStringList mFireSounds; + + bool mFireOnAttackUp; }; #endif diff --git a/main/source/mod/AvHGamerules.cpp b/main/source/mod/AvHGamerules.cpp index 56c5ae32..4a4c35ff 100644 --- a/main/source/mod/AvHGamerules.cpp +++ b/main/source/mod/AvHGamerules.cpp @@ -643,9 +643,7 @@ BOOL AvHGamerules::CanHavePlayerItem(CBasePlayer *pPlayer, CBasePlayerItem *pWea int playerAutoSwapWeapon = 1; bool newWeaponCanFire = true; - AvHPlayer* thePlayer = dynamic_cast(pPlayer); - if(thePlayer) - playerAutoSwapWeapon = thePlayer->GetAutoWeapSwapValue(); + playerAutoSwapWeapon = pPlayer->m_iAutoWeaponSwap; AvHBasePlayerWeapon* theNewWeapon = dynamic_cast(pWeapon); if (theNewWeapon) @@ -866,13 +864,15 @@ void AvHGamerules::ClientUserInfoChanged(CBasePlayer *pPlayer, char *infobuffer) // NOTE: Not currently calling down to parent CHalfLifeTeamplay const char* theAutoWeapSwapValue = g_engfuncs.pfnInfoKeyValue(infobuffer, "cl_weaponswap"); + if (theAutoWeapSwapValue) + { + pPlayer->m_iAutoWeaponSwap = atoi(theAutoWeapSwapValue); + } - if (theAutoWeapSwapValue) { - - AvHPlayer* thePlayer = dynamic_cast(pPlayer); - if (thePlayer) { - thePlayer->SetAutoWeapSwapValue(atoi(theAutoWeapSwapValue)); - } + const char* thePistolTriggerValue = g_engfuncs.pfnInfoKeyValue(infobuffer, "cl_pistoltrigger"); + if (thePistolTriggerValue) + { + pPlayer->m_iPistolTrigger = atoi(thePistolTriggerValue); } } diff --git a/main/source/mod/AvHGrenade.cpp b/main/source/mod/AvHGrenade.cpp index 179a99dc..71197cd6 100644 --- a/main/source/mod/AvHGrenade.cpp +++ b/main/source/mod/AvHGrenade.cpp @@ -238,7 +238,7 @@ BOOL AvHGrenade::IsUseable(void) } -void AvHGrenade::PrimaryAttack(void) +void AvHGrenade::PrimaryAttack(bool fireOnAttackUp) { if (this->ProcessValidAttack()) diff --git a/main/source/mod/AvHMarineWeapons.h b/main/source/mod/AvHMarineWeapons.h index 970fec8a..e2b98e3b 100644 --- a/main/source/mod/AvHMarineWeapons.h +++ b/main/source/mod/AvHMarineWeapons.h @@ -233,9 +233,9 @@ public: virtual void Precache(void); - virtual void PrimaryAttack(); + virtual void PrimaryAttack(bool fireOnAttackUp = false); - virtual void QueueAttack(void); + virtual void QueueAttack(bool fireOnAttackUp); virtual void Spawn(); @@ -624,7 +624,7 @@ public: virtual void WeaponIdle(); - virtual void PrimaryAttack(void); + virtual void PrimaryAttack(bool fireOnAttackUp = false); protected: diff --git a/main/source/mod/AvHPistol.cpp b/main/source/mod/AvHPistol.cpp index 35997802..ef230a2c 100644 --- a/main/source/mod/AvHPistol.cpp +++ b/main/source/mod/AvHPistol.cpp @@ -174,17 +174,24 @@ void AvHPistol::Precache() this->mEvent = PRECACHE_EVENT(1, kHGEventName); } -void AvHPistol::PrimaryAttack() +void AvHPistol::PrimaryAttack(bool fireOnAttackUp) { this->m_bAttackQueued = false; + this->mFireOnAttackUp = fireOnAttackUp; + if (fireOnAttackUp) + { + this->m_iPlayEmptySound = true; + } AvHMarineWeapon::PrimaryAttack(); + this->mFireOnAttackUp = false; } -void AvHPistol::QueueAttack(void) +void AvHPistol::QueueAttack(bool fireOnAttackUp) { - if (!this->mAttackButtonDownLastFrame) + if (!this->mAttackButtonDownLastFrame || fireOnAttackUp) { this->m_bAttackQueued = true; + this->mAttackButtonDownLastFrame = false; } } diff --git a/main/source/mod/AvHPlayer.h b/main/source/mod/AvHPlayer.h index 1cb61cc6..21dfed3e 100644 --- a/main/source/mod/AvHPlayer.h +++ b/main/source/mod/AvHPlayer.h @@ -477,9 +477,6 @@ public: void SetUsedKilled(bool bKilled ) { mUsedKilled = bKilled; } void ClearOrders() { mClientOrders.clear(); } - int GetAutoWeapSwapValue() { return mAutoWeapSwapValue; } - void SetAutoWeapSwapValue(int autoSwap) { mAutoWeapSwapValue = autoSwap; } - // : 0000953 bool JoinTeamCooledDown(float inCoolDownTime); // @@ -865,7 +862,6 @@ private: bool mUsedKilled; - int mAutoWeapSwapValue; //TODO: remove this system from AvHPlayer and create an // explicit balance forwarding class registered to each