Skip to content

Commit 0d77bea

Browse files
committed
Test for remote weapon desync
1 parent d823fdc commit 0d77bea

File tree

3 files changed

+66
-7
lines changed

3 files changed

+66
-7
lines changed

Client/mods/deathmatch/logic/CClientPed.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,6 +2155,22 @@ CWeapon* CClientPed::GetWeapon ( void )
21552155
return NULL;
21562156
}
21572157

2158+
eWeaponType CClientPed::GetWeaponType(eWeaponSlot slot)
2159+
{
2160+
if ( slot >= WEAPONSLOT_MAX )
2161+
return WEAPONTYPE_UNARMED;
2162+
2163+
if ( m_pPlayerPed )
2164+
{
2165+
CWeapon* pWeapon = GetWeapon(slot);
2166+
if ( pWeapon )
2167+
{
2168+
return pWeapon->GetType();
2169+
}
2170+
return WEAPONTYPE_UNARMED;
2171+
}
2172+
return m_WeaponTypes[slot];
2173+
}
21582174

21592175
void CClientPed::RemoveWeapon ( eWeaponType weaponType )
21602176
{
@@ -2258,6 +2274,49 @@ bool CClientPed::HasWeapon ( eWeaponType weaponType )
22582274
return false;
22592275
}
22602276

2277+
2278+
//
2279+
// Check and attempt to fix weapons for remote players
2280+
//
2281+
void CClientPed::ValidateRemoteWeapons( void )
2282+
{
2283+
// Must be streamed in remote player
2284+
if( !m_pPlayerPed || IsLocalPlayer() || GetType() != CCLIENTPLAYER )
2285+
return;
2286+
2287+
// Check everything matches
2288+
bool bMismatch = false;
2289+
for ( uint i = 0; i < WEAPONSLOT_MAX; i++ )
2290+
{
2291+
eWeaponType slotWeaponType = GetWeaponType((eWeaponSlot)i);
2292+
if ( m_WeaponTypes[i] != slotWeaponType )
2293+
{
2294+
SString strPlayerName = ((CClientPlayer*)this)->GetNick();
2295+
AddReportLog(5430, SString( "Mismatch in slot %d Wanted type:%d Got type:%d (%s)", i, m_WeaponTypes[i], slotWeaponType, *strPlayerName ), 30);
2296+
bMismatch = true;
2297+
}
2298+
}
2299+
2300+
if ( !bMismatch )
2301+
{
2302+
// All fine. Save current slot
2303+
m_CurrentWeaponSlot = m_pPlayerPed->GetCurrentWeaponSlot();
2304+
return;
2305+
}
2306+
2307+
// Fix wrongness
2308+
for ( uint i = 0; i < WEAPONSLOT_MAX; i++ )
2309+
{
2310+
if ( m_WeaponTypes[i] != WEAPONTYPE_UNARMED )
2311+
{
2312+
bool bSetAsCurrent = (i == m_CurrentWeaponSlot);
2313+
GiveWeapon(m_WeaponTypes[i], m_usWeaponAmmo[i], bSetAsCurrent);
2314+
}
2315+
}
2316+
m_pPlayerPed->SetCurrentWeaponSlot(m_CurrentWeaponSlot);
2317+
}
2318+
2319+
22612320
eMovementState CClientPed::GetMovementState ( void )
22622321
{
22632322
// Do we have a player, and are we on foot? (streamed in)
@@ -2792,6 +2851,8 @@ void CClientPed::StreamedInPulse ( bool bDoStandardPulses )
27922851
if ( item.bCurrentWeapon )
27932852
pWeapon->SetAsCurrentWeapon ( );
27942853
}
2854+
2855+
ValidateRemoteWeapons();
27952856
}
27962857
}
27972858

Client/mods/deathmatch/logic/CClientPed.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,15 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
260260
bool SetCurrentWeaponSlot ( eWeaponSlot weaponSlot );
261261
eWeaponSlot GetCurrentWeaponSlot ( void );
262262
eWeaponType GetCurrentWeaponType ( void );
263+
eWeaponType GetWeaponType ( eWeaponSlot slot );
263264
CWeapon* GetWeapon ( void );
264265
CWeapon* GetWeapon ( eWeaponSlot weaponSlot );
265266
CWeapon* GetWeapon ( eWeaponType weaponType );
266267
bool HasWeapon ( eWeaponType weaponType );
267268
void RemoveWeapon ( eWeaponType weaponType );
268269
void RemoveAllWeapons ( void );
269270
bool IsCurrentWeaponUsingBulletSync ( void );
271+
void ValidateRemoteWeapons ( void );
270272

271273
std::map<eMovementState,std::string> m_MovementStateNames;
272274
eMovementState GetMovementState ( void );

Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,9 @@ int CLuaPedDefs::GetPedWeapon ( lua_State* luaVM )
289289
if ( ucSlot == 0xFF )
290290
ucSlot = pPed->GetCurrentWeaponSlot ();
291291

292-
CWeapon* pWeapon = pPed->GetWeapon ( (eWeaponSlot) ucSlot );
293-
if ( pWeapon )
294-
{
295-
unsigned char ucWeapon = pWeapon->GetType ();
296-
lua_pushnumber ( luaVM, ucWeapon );
297-
return 1;
298-
}
292+
unsigned char ucWeapon = pPed->GetWeaponType( (eWeaponSlot)ucSlot );
293+
lua_pushnumber ( luaVM, ucWeapon );
294+
return 1;
299295
}
300296
else
301297
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

0 commit comments

Comments
 (0)