Skip to content

Commit

Permalink
Merge pull request BSVino#43 from TomyLobo/fix-akimbo-quickreload
Browse files Browse the repository at this point in the history
Fix NPE in new akimbo Deploy/Holster code
  • Loading branch information
TomyLobo committed Apr 1, 2016
2 parents d4f5174 + 693eb2f commit 895615e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
36 changes: 23 additions & 13 deletions mp/src/game/shared/sdk/weapon_akimbobase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,27 @@ Activity CAkimboBase::GetIdleActivity(void)

bool CAkimboBase::Deploy()
{
// Transfer iClip1 of single pistol to m_iRightClip
SDKWeaponID eSingleId = AliasToWeaponID(GetSDKWpnData().m_szSingle);

CWeaponSDKBase *pSingle = GetPlayerOwner()->FindWeapon(eSingleId);
Assert(pSingle);
CWeaponSDKBase *pSingle = FindSingleWeapon();

m_iRightClip = pSingle->m_iClip1;
m_iClip1 = m_iLeftClip + m_iRightClip;
if (pSingle)
{
// Transfer iClip1 of single pistol to m_iRightClip
m_iRightClip = pSingle->m_iClip1;
m_iClip1 = m_iLeftClip + m_iRightClip;
}

return BaseClass::Deploy();
}

bool CAkimboBase::Holster(CBaseCombatWeapon *pSwitchingTo)
{
// Transfer m_iRightClip into iClip1 of single pistol
SDKWeaponID eSingleId = AliasToWeaponID(GetSDKWpnData().m_szSingle);

CWeaponSDKBase *pSingle = GetPlayerOwner()->FindWeapon(eSingleId);
Assert(pSingle);
CWeaponSDKBase *pSingle = FindSingleWeapon();

pSingle->m_iClip1 = m_iRightClip;
if (pSingle)
{
// Transfer m_iRightClip into iClip1 of single pistol
pSingle->m_iClip1 = m_iRightClip;
}

return BaseClass::Holster(pSwitchingTo);
}
Expand Down Expand Up @@ -261,3 +261,13 @@ const Vector CAkimboBase::GetShootPosition(CSDKPlayer* pShooter)

return vecPosition + vecRight * (m_bShootRight ? 4 : -4);
}

CWeaponSDKBase *CAkimboBase::FindSingleWeapon()
{
SDKWeaponID eSingleId = AliasToWeaponID(GetSDKWpnData().m_szSingle);

CWeaponSDKBase *pSingle = GetPlayerOwner()->FindWeapon(eSingleId);
Assert(pSingle);

return pSingle;
}
4 changes: 4 additions & 0 deletions mp/src/game/shared/sdk/weapon_akimbobase.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ class CAkimboBase : public CWeaponSDKBase
virtual int GetWeight(void) const;

const Vector GetShootPosition(CSDKPlayer* pShooter);

// Finds the single variant of this akimbo weapon
CWeaponSDKBase *FindSingleWeapon();

protected:
virtual bool NeedsReload( int iClipSize1, int iClipSize2 );
};
Expand Down

0 comments on commit 895615e

Please sign in to comment.