From c08375cb21031e6c443f156e3473ce45d0aa717f Mon Sep 17 00:00:00 2001 From: treacherousfiend Date: Mon, 24 Feb 2025 02:04:05 -0700 Subject: [PATCH 1/2] Fix medigun prediction errors All of the code which determines how much ubercharge you get on a specific tick was server only, causing the medigun to constantly cause prediction errors unless you are in a situation where you are getting the default ubercharge per tick (stock medigun, damaged patient, no critheals). This fixes that by making all possible server code to also be on the client. The only exception to this is an unused weapon attribute which would modify ubercharge rate as long as you weren't in a respawn room. The functions it calls are server only, and would require changes to how respawn room entities are handled on the client to fix. --- src/game/shared/tf/tf_weapon_medigun.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/game/shared/tf/tf_weapon_medigun.cpp b/src/game/shared/tf/tf_weapon_medigun.cpp index ed55d29ef31..9b8f9e696fe 100644 --- a/src/game/shared/tf/tf_weapon_medigun.cpp +++ b/src/game/shared/tf/tf_weapon_medigun.cpp @@ -1252,7 +1252,6 @@ bool CWeaponMedigun::FindAndHealTargets( void ) if ( pTFPlayer && weapon_medigun_charge_rate.GetFloat() ) { -#ifdef GAME_DLL int iBoostMax = floor( pTFPlayer->m_Shared.GetMaxBuffedHealth() * 0.95); float flChargeModifier = 1.f; @@ -1309,7 +1308,7 @@ bool CWeaponMedigun::FindAndHealTargets( void ) CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( pOwner, flChargeAmount, mult_medigun_uberchargerate ); - +#ifdef GAME_DLL // Apply any bonus our target gives us. if ( pTarget ) { @@ -1322,6 +1321,7 @@ bool CWeaponMedigun::FindAndHealTargets( void ) CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( pTarget, flChargeAmount, mult_uberchargerate_for_healer ); } } +#endif if ( TFGameRules() ) { if ( TFGameRules()->IsQuickBuildTime() ) @@ -1333,7 +1333,6 @@ bool CWeaponMedigun::FindAndHealTargets( void ) flChargeAmount *= 3.f; } } -#endif float flNewLevel = MIN( m_flChargeLevel + flChargeAmount, 1.0 ); From 436a84ec5cacfd194e37e33cfbf1c90141b6053d Mon Sep 17 00:00:00 2001 From: treacherousfiend Date: Fri, 2 May 2025 20:45:00 -0600 Subject: [PATCH 2/2] Fix Ubercharge drain prediction errors Shoutouts to @JustYourOrdinaryNormie for making me aware that my PR didn't fix ubercharge drain prediction errors! Fixes prediction errors caused by Ubercharge draining by adding client only `DrainCharge` functioncalls to the medi-gun's `ItemPostFrame` and newly added `ItemBusyFrame` functions. Additionally, moved the Vaccinator charge removal outside of a server only #ifdef to fix prediction errors from using charges with the Vaccinator. --- src/game/shared/tf/tf_weapon_medigun.cpp | 18 +++++++++++++++++- src/game/shared/tf/tf_weapon_medigun.h | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/game/shared/tf/tf_weapon_medigun.cpp b/src/game/shared/tf/tf_weapon_medigun.cpp index 9b8f9e696fe..1719f6952b7 100644 --- a/src/game/shared/tf/tf_weapon_medigun.cpp +++ b/src/game/shared/tf/tf_weapon_medigun.cpp @@ -1610,9 +1610,25 @@ void CWeaponMedigun::ItemPostFrame( void ) m_bReloadDown = false; } +#ifdef CLIENT_DLL + DrainCharge(); +#endif + WeaponIdle(); } +//----------------------------------------------------------------------------- +// Purpose: Drain Ubercharge on client during weapon draw to fix prediction errors +//----------------------------------------------------------------------------- +void CWeaponMedigun::ItemBusyFrame( void ) +{ +#ifdef CLIENT_DLL + DrainCharge(); +#endif + + BaseClass::ItemBusyFrame(); +} + //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- @@ -1963,11 +1979,11 @@ void CWeaponMedigun::SecondaryAttack( void ) { // Remove charge immediately and just give target and yourself the conditions m_bChargeRelease = false; + SetChargeLevel( m_flChargeLevel - flChunkSize ); #ifdef GAME_DLL float flResistDuration = weapon_vaccinator_resist_duration.GetFloat(); CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( pOwner, flResistDuration, add_uber_time ); pOwner->m_Shared.AddCond( g_MedigunResistConditions[GetResistType()].uberCond, flResistDuration, pOwner ); - m_flChargeLevel -= flChunkSize; if ( pTFPlayerPatient ) { pTFPlayerPatient->m_Shared.AddCond( g_MedigunResistConditions[GetResistType()].uberCond, flResistDuration, pOwner ); diff --git a/src/game/shared/tf/tf_weapon_medigun.h b/src/game/shared/tf/tf_weapon_medigun.h index 5b4fae8194f..681b8b9a335 100644 --- a/src/game/shared/tf/tf_weapon_medigun.h +++ b/src/game/shared/tf/tf_weapon_medigun.h @@ -73,6 +73,7 @@ class CWeaponMedigun : public CTFWeaponBaseGun virtual void UpdateOnRemove( void ); virtual void ItemHolsterFrame( void ); virtual void ItemPostFrame( void ); + virtual void ItemBusyFrame( void ); virtual bool Lower( void ); virtual void PrimaryAttack( void ); virtual void SecondaryAttack( void );