1515#include " CWeaponStatManager.h"
1616#include " CElementIDs.h"
1717#include " CElement.h"
18+ #include " CWeaponNames.h"
19+ #include < cstdint>
1820
1921CBulletsyncPacket::CBulletsyncPacket (CPlayer* player)
2022 : m_weapon(WEAPONTYPE_UNARMED)
@@ -68,13 +70,13 @@ bool CBulletsyncPacket::ValidateTrajectory() const noexcept
6870 const float dz = m_end.fZ - m_start.fZ ;
6971
7072 const float movementSq = (dx * dx) + (dy * dy) + (dz * dz);
71-
73+
7274 if (IsNaN (movementSq))
7375 return false ;
74-
76+
7577 if (movementSq < MIN_DISTANCE_SQ)
7678 return false ;
77-
79+
7880 if (movementSq > MAX_DISTANCE_SQ)
7981 return false ;
8082
@@ -104,13 +106,13 @@ bool CBulletsyncPacket::ReadWeaponAndPositions(NetBitStreamInterface& stream)
104106
105107 if (!stream.Read (reinterpret_cast <char *>(&m_end), sizeof (CVector)))
106108 return false ;
107-
109+
108110 if (!IsValidVector (m_start))
109111 return false ;
110-
112+
111113 if (!IsValidVector (m_end))
112114 return false ;
113-
115+
114116 if (!ValidateVectorBounds (m_start))
115117 return false ;
116118
@@ -158,7 +160,7 @@ bool CBulletsyncPacket::ReadOptionalDamage(NetBitStreamInterface& stream)
158160 ResetDamageData ();
159161 return false ;
160162 }
161-
163+
162164 // Validate that target element exists
163165 if (m_damaged != INVALID_ELEMENT_ID)
164166 {
@@ -171,8 +173,8 @@ bool CBulletsyncPacket::ReadOptionalDamage(NetBitStreamInterface& stream)
171173
172174 // Check element type is valid for damage
173175 auto elementType = pElement->GetType ();
174- if (elementType != CElement::PLAYER &&
175- elementType != CElement::PED &&
176+ if (elementType != CElement::PLAYER &&
177+ elementType != CElement::PED &&
176178 elementType != CElement::VEHICLE)
177179 {
178180 ResetDamageData ();
@@ -187,14 +189,14 @@ bool CBulletsyncPacket::Read(NetBitStreamInterface& stream)
187189{
188190 if (!m_pSourceElement)
189191 return false ;
190-
192+
191193 CPlayer* pPlayer = static_cast <CPlayer*>(m_pSourceElement);
192194 if (pPlayer)
193195 {
194196 // Check if player is spawned and alive
195197 if (!pPlayer->IsSpawned () || pPlayer->IsDead ())
196198 return false ;
197-
199+
198200 // Check player position is reasonable relative to bullet start
199201 const CVector& playerPos = pPlayer->GetPosition ();
200202 const float maxShootDistance = 50 .0f ; // Max distance from player to bullet start
@@ -204,26 +206,26 @@ bool CBulletsyncPacket::Read(NetBitStreamInterface& stream)
204206
205207 if (!ReadWeaponAndPositions (stream))
206208 return false ;
207-
209+
208210 // Now validate player position relative to shot origin
209211 if (pPlayer)
210212 {
211213 const CVector& playerPos = pPlayer->GetPosition ();
212214 float dx = m_start.fX - playerPos.fX ;
213215 float dy = m_start.fY - playerPos.fY ;
214216 float dz = m_start.fZ - playerPos.fZ ;
215- float distSq = dx* dx + dy* dy + dz* dz;
217+ float distSq = dx * dx + dy * dy + dz * dz;
216218
217219 const float maxShootDistanceSq = 50 .0f * 50 .0f ;
218220 if (distSq > maxShootDistanceSq)
219221 return false ;
220222
221223 // Check if player has this weapon
222- if (!pPlayer->HasWeaponType (static_cast <unsigned char >(m_weapon)))
224+ if (!pPlayer->HasWeaponType (static_cast <std:: uint8_t >(m_weapon)))
223225 return false ;
224-
226+
225227 // Check if weapon has ammo
226- if (pPlayer->GetWeaponAmmoInClip (static_cast <unsigned char >(m_weapon)) = = 0 )
228+ if (pPlayer->GetWeaponTotalAmmo (static_cast <std:: uint8_t >(m_weapon)) < = 0 )
227229 return false ;
228230 }
229231
@@ -232,7 +234,7 @@ bool CBulletsyncPacket::Read(NetBitStreamInterface& stream)
232234
233235 if (!ReadOptionalDamage (stream))
234236 return false ;
235-
237+
236238 return true ;
237239}
238240
@@ -244,21 +246,21 @@ bool CBulletsyncPacket::Write(NetBitStreamInterface& stream) const
244246 const auto * pPlayer = static_cast <const CPlayer*>(m_pSourceElement);
245247 if (!pPlayer)
246248 return false ;
247-
249+
248250 const ElementID id = pPlayer->GetID ();
249251
250252 if (id == INVALID_ELEMENT_ID)
251253 return false ;
252-
254+
253255 if (id == 0 )
254256 return false ;
255257
256258 if (!IsValidVector (m_start))
257259 return false ;
258-
260+
259261 if (!IsValidVector (m_end))
260262 return false ;
261-
263+
262264 if (!ValidateVectorBounds (m_start))
263265 return false ;
264266
@@ -289,4 +291,4 @@ bool CBulletsyncPacket::Write(NetBitStreamInterface& stream) const
289291 }
290292
291293 return true ;
292- }
294+ }
0 commit comments