Skip to content

Commit 2399b9d

Browse files
committed
Test for remote weapon desync #2
1 parent 0d77bea commit 2399b9d

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

Client/mods/deathmatch/logic/CClientPed.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,6 +2093,8 @@ bool CClientPed::SetCurrentWeaponSlot ( eWeaponSlot weaponSlot )
20932093
// Don't allow doing gang driveby while unarmed
20942094
if ( IsDoingGangDriveby () )
20952095
SetDoingGangDriveby ( false );
2096+
m_CurrentWeaponSlot = weaponSlot;
2097+
return true;
20962098
}
20972099
else
20982100
{
@@ -2844,7 +2846,7 @@ void CClientPed::StreamedInPulse ( bool bDoStandardPulses )
28442846
m_RestoreWeaponList.pop_front();
28452847

28462848
// Give our Weapon back after deleting to reload the model
2847-
CWeapon * pWeapon = GiveWeapon ( item.eWeaponID, item.dwAmmo );
2849+
CWeapon * pWeapon = GiveWeapon ( item.eWeaponID, item.dwAmmo, item.bCurrentWeapon );
28482850

28492851
// Reset our states
28502852
pWeapon->SetAmmoInClip ( item.dwClipAmmo );
@@ -3496,11 +3498,7 @@ void CClientPed::UpdateKeysync ( bool bCleanup )
34963498
CWeapon* pSlotWeapon = GetWeapon ( eCurrentSlot );
34973499
if ( pSlotWeapon )
34983500
{
3499-
pPlayerWeapon = GiveWeapon ( pSlotWeapon->GetType (), pData->usWeaponAmmo );
3500-
if ( pPlayerWeapon )
3501-
{
3502-
pPlayerWeapon->SetAsCurrentWeapon ();
3503-
}
3501+
pPlayerWeapon = GiveWeapon ( pSlotWeapon->GetType (), pData->usWeaponAmmo, true );
35043502
}
35053503
}
35063504

Client/mods/deathmatch/logic/CNetAPI.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,10 +1520,9 @@ void CNetAPI::ReadVehiclePuresync ( CClientPlayer* pPlayer, CClientVehicle* pVeh
15201520

15211521
if ( pWeapon )
15221522
{
1523-
CWeapon* pPlayerWeapon = pPlayer->GiveWeapon ( static_cast < eWeaponType > ( ucCurrentWeapon ), usWeaponAmmo );
1523+
CWeapon* pPlayerWeapon = pPlayer->GiveWeapon ( static_cast < eWeaponType > ( ucCurrentWeapon ), usWeaponAmmo, true );
15241524
if ( pPlayerWeapon )
15251525
{
1526-
pPlayerWeapon->SetAsCurrentWeapon ();
15271526
pPlayerWeapon->SetAmmoTotal ( BitStream.Version () >= 0x44 ? ammo.data.usTotalAmmo : 9999 );
15281527
pPlayerWeapon->SetAmmoInClip ( usWeaponAmmo );
15291528
}

Client/mods/deathmatch/logic/rpc/CWeaponRPCs.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void CWeaponRPCs::GiveWeapon ( CClientEntity* pSource, NetBitStreamInterface& bi
3434
SWeaponAmmoSync ammo ( weaponType.data.ucWeaponType, true, false );
3535
if ( bitStream.Read ( &ammo ) )
3636
{
37-
bool bGiveWeapon = bitStream.ReadBit ();
37+
bool bSetAsCurrent = bitStream.ReadBit ();
3838
unsigned char ucWeaponID = weaponType.data.ucWeaponType;
3939
unsigned short usAmmo = ammo.data.usTotalAmmo;
4040

@@ -51,12 +51,9 @@ void CWeaponRPCs::GiveWeapon ( CClientEntity* pSource, NetBitStreamInterface& bi
5151
if ( usAmmo > 9999 ) usAmmo = 9999;
5252

5353
// Give the local player the weapon
54-
CWeapon* pPlayerWeapon = NULL;
5554
if ( ucWeaponID != 0 )
5655
{
57-
pPlayerWeapon = pPed->GiveWeapon ( static_cast < eWeaponType > ( ucWeaponID ), usAmmo );
58-
if ( pPlayerWeapon && bGiveWeapon )
59-
pPlayerWeapon->SetAsCurrentWeapon ();
56+
pPed->GiveWeapon ( static_cast < eWeaponType > ( ucWeaponID ), usAmmo, bSetAsCurrent );
6057

6158
// Store the ammo so it's not lost if a ped is streamed out
6259
if ( pPed->GetType () == CCLIENTPED )
@@ -76,7 +73,7 @@ void CWeaponRPCs::GiveWeapon ( CClientEntity* pSource, NetBitStreamInterface& bi
7673
{
7774
eWeaponType unarmedWeapon = oldWeapon->GetType();
7875
pPed->RemoveWeapon ( unarmedWeapon );
79-
if ( bGiveWeapon || pPed->GetCurrentWeaponSlot() == WEAPONSLOT_TYPE_UNARMED )
76+
if ( bSetAsCurrent || pPed->GetCurrentWeaponSlot() == WEAPONSLOT_TYPE_UNARMED )
8077
{
8178
oldWeapon = NULL;
8279
if ( unarmedWeapon == WEAPONTYPE_BRASSKNUCKLE )
@@ -107,7 +104,7 @@ void CWeaponRPCs::GiveWeapon ( CClientEntity* pSource, NetBitStreamInterface& bi
107104
{
108105
// Probably the ped is streamed out
109106
pPed->GiveWeapon ( WEAPONTYPE_UNARMED, 1 );
110-
if ( bGiveWeapon )
107+
if ( bSetAsCurrent )
111108
pPed->SetCurrentWeaponSlot ( WEAPONSLOT_TYPE_UNARMED );
112109
}
113110
}

0 commit comments

Comments
 (0)