From 42f45bdaec7c110424eec4a5e6664d14dcd0e6e1 Mon Sep 17 00:00:00 2001 From: Sam V Date: Wed, 20 Jul 2022 17:28:02 +0200 Subject: [PATCH] Fix weapon deploy animations caused by lastinv command not working properly Resolves #154 --- dlls/weapons.cpp | 2 +- dlls/weapons.h | 3 +++ dlls/weapons_shared.cpp | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/dlls/weapons.cpp b/dlls/weapons.cpp index 428259280..d203433b3 100644 --- a/dlls/weapons.cpp +++ b/dlls/weapons.cpp @@ -735,7 +735,7 @@ bool CBasePlayerWeapon::UpdateClientData(CBasePlayer* pPlayer) void CBasePlayerWeapon::SendWeaponAnim(int iAnim, int body) { - const bool skiplocal = UseDecrement() != false; + const bool skiplocal = !m_ForceSendAnimations && UseDecrement() != false; m_pPlayer->pev->weaponanim = iAnim; diff --git a/dlls/weapons.h b/dlls/weapons.h index add901130..8fa66e579 100644 --- a/dlls/weapons.h +++ b/dlls/weapons.h @@ -358,6 +358,9 @@ class CBasePlayerWeapon : public CBasePlayerItem // hle time creep vars float m_flPrevPrimaryAttack; float m_flLastFireTime; + + //Hack so deploy animations work when weapon prediction is enabled. + bool m_ForceSendAnimations = false; }; diff --git a/dlls/weapons_shared.cpp b/dlls/weapons_shared.cpp index 7a0d3da8b..5cd84863d 100644 --- a/dlls/weapons_shared.cpp +++ b/dlls/weapons_shared.cpp @@ -223,6 +223,20 @@ void CBasePlayer::SelectLastItem() CBasePlayerItem* pTemp = m_pActiveItem; m_pActiveItem = m_pLastItem; m_pLastItem = pTemp; + + auto weapon = static_cast(m_pActiveItem->GetWeaponPtr()); + + if (weapon) + { + weapon->m_ForceSendAnimations = true; + } + m_pActiveItem->Deploy(); + + if (weapon) + { + weapon->m_ForceSendAnimations = false; + } + m_pActiveItem->UpdateItemInfo(); }