From 29080d7649edfa23889ec1a55a6f6b6dd0f5bb7a Mon Sep 17 00:00:00 2001 From: SanyaSho Date: Thu, 4 Aug 2022 00:33:45 +0300 Subject: [PATCH] game: apply https://developer.valvesoftware.com/wiki/Weapon_Respawn_Fix patch --- game/shared/hl2mp/weapon_hl2mpbase.cpp | 31 ++++++++++++++++++++++++-- game/shared/hl2mp/weapon_hl2mpbase.h | 5 +++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/game/shared/hl2mp/weapon_hl2mpbase.cpp b/game/shared/hl2mp/weapon_hl2mpbase.cpp index 15995a5b..7499efae 100644 --- a/game/shared/hl2mp/weapon_hl2mpbase.cpp +++ b/game/shared/hl2mp/weapon_hl2mpbase.cpp @@ -261,14 +261,41 @@ void CWeaponHL2MPBase::FallInit( void ) } SetPickupTouch(); - - SetThink( &CBaseCombatWeapon::FallThink ); + + SetThink( &CWeaponHL2MPBase::FallThink ); SetNextThink( gpGlobals->curtime + 0.1f ); #endif } +#ifdef GAME_DLL +void CWeaponHL2MPBase::FallThink( void ) +{ + // Prevent the common HL2DM weapon respawn bug from happening + // When a weapon is spawned, the following chain of events occurs: + // - Spawn() is called (duh), which then calls FallInit() + // - FallInit() is called, and prepares the weapon's 'Think' function (CBaseCombatWeapon::FallThink()) + // - FallThink() is called, and performs several checks before deciding whether the weapon should Materialize() + // - Materialize() is called (the HL2DM version above), which sets the weapon's respawn location. + // The problem occurs when a weapon isn't placed properly by a level designer. + // If the weapon is unable to move from its location (e.g. if its bounding box is halfway inside a wall), Materialize() never gets called. + // Since Materialize() never gets called, the weapon's respawn location is never set, so if a person picks it up, it respawns forever at + // 0 0 0 on the map (infinite loop of fall, wait, respawn, not nice at all for performance and bandwidth!) + + if( hasSpawnFlags( SF_NORESPAWN ) == false ) + { + if( GetOriginalSpawnOrigin() == vec3_origin ) + { + m_vOriginalSpawnOrigin = GetAbsOrigin(); + m_vOriginalSpawnAngles = GetAbsAngles(); + } + } + + return BaseClass::FallThink(); +} +#endif + const CHL2MPSWeaponInfo &CWeaponHL2MPBase::GetHL2MPWpnData() const { const FileWeaponInfo_t *pWeaponInfo = &GetWpnData(); diff --git a/game/shared/hl2mp/weapon_hl2mpbase.h b/game/shared/hl2mp/weapon_hl2mpbase.h index 0f21044b..8a664d23 100644 --- a/game/shared/hl2mp/weapon_hl2mpbase.h +++ b/game/shared/hl2mp/weapon_hl2mpbase.h @@ -40,11 +40,12 @@ public: #ifdef GAME_DLL DECLARE_DATADESC(); - + void SendReloadSoundEvent( void ); void Materialize( void ); - virtual int ObjectCaps( void ); + virtual int ObjectCaps( void ); + virtual void FallThink( void ); #endif // All predicted weapons need to implement and return true