diff --git a/Server/mods/deathmatch/logic/packets/CBulletsyncPacket.cpp b/Server/mods/deathmatch/logic/packets/CBulletsyncPacket.cpp index 43d41199b19..b224c1c5215 100644 --- a/Server/mods/deathmatch/logic/packets/CBulletsyncPacket.cpp +++ b/Server/mods/deathmatch/logic/packets/CBulletsyncPacket.cpp @@ -15,6 +15,8 @@ #include "CWeaponStatManager.h" #include "CElementIDs.h" #include "CElement.h" +#include "CWeaponNames.h" +#include CBulletsyncPacket::CBulletsyncPacket(CPlayer* player) : m_weapon(WEAPONTYPE_UNARMED) @@ -68,13 +70,13 @@ bool CBulletsyncPacket::ValidateTrajectory() const noexcept const float dz = m_end.fZ - m_start.fZ; const float movementSq = (dx * dx) + (dy * dy) + (dz * dz); - + if (IsNaN(movementSq)) return false; - + if (movementSq < MIN_DISTANCE_SQ) return false; - + if (movementSq > MAX_DISTANCE_SQ) return false; @@ -104,13 +106,13 @@ bool CBulletsyncPacket::ReadWeaponAndPositions(NetBitStreamInterface& stream) if (!stream.Read(reinterpret_cast(&m_end), sizeof(CVector))) return false; - + if (!IsValidVector(m_start)) return false; - + if (!IsValidVector(m_end)) return false; - + if (!ValidateVectorBounds(m_start)) return false; @@ -158,7 +160,7 @@ bool CBulletsyncPacket::ReadOptionalDamage(NetBitStreamInterface& stream) ResetDamageData(); return false; } - + // Validate that target element exists if (m_damaged != INVALID_ELEMENT_ID) { @@ -171,8 +173,8 @@ bool CBulletsyncPacket::ReadOptionalDamage(NetBitStreamInterface& stream) // Check element type is valid for damage auto elementType = pElement->GetType(); - if (elementType != CElement::PLAYER && - elementType != CElement::PED && + if (elementType != CElement::PLAYER && + elementType != CElement::PED && elementType != CElement::VEHICLE) { ResetDamageData(); @@ -187,14 +189,14 @@ bool CBulletsyncPacket::Read(NetBitStreamInterface& stream) { if (!m_pSourceElement) return false; - + CPlayer* pPlayer = static_cast(m_pSourceElement); if (pPlayer) { // Check if player is spawned and alive if (!pPlayer->IsSpawned() || pPlayer->IsDead()) return false; - + // Check player position is reasonable relative to bullet start const CVector& playerPos = pPlayer->GetPosition(); const float maxShootDistance = 50.0f; // Max distance from player to bullet start @@ -204,7 +206,7 @@ bool CBulletsyncPacket::Read(NetBitStreamInterface& stream) if (!ReadWeaponAndPositions(stream)) return false; - + // Now validate player position relative to shot origin if (pPlayer) { @@ -212,18 +214,18 @@ bool CBulletsyncPacket::Read(NetBitStreamInterface& stream) float dx = m_start.fX - playerPos.fX; float dy = m_start.fY - playerPos.fY; float dz = m_start.fZ - playerPos.fZ; - float distSq = dx*dx + dy*dy + dz*dz; + float distSq = dx * dx + dy * dy + dz * dz; const float maxShootDistanceSq = 50.0f * 50.0f; if (distSq > maxShootDistanceSq) return false; // Check if player has this weapon - if (!pPlayer->HasWeaponType(static_cast(m_weapon))) + if (!pPlayer->HasWeaponType(static_cast(m_weapon))) return false; - + // Check if weapon has ammo - if (pPlayer->GetWeaponAmmoInClip(static_cast(m_weapon)) == 0) + if (pPlayer->GetWeaponTotalAmmo(static_cast(m_weapon)) <= 0) return false; } @@ -232,7 +234,7 @@ bool CBulletsyncPacket::Read(NetBitStreamInterface& stream) if (!ReadOptionalDamage(stream)) return false; - + return true; } @@ -244,21 +246,21 @@ bool CBulletsyncPacket::Write(NetBitStreamInterface& stream) const const auto* pPlayer = static_cast(m_pSourceElement); if (!pPlayer) return false; - + const ElementID id = pPlayer->GetID(); if (id == INVALID_ELEMENT_ID) return false; - + if (id == 0) return false; if (!IsValidVector(m_start)) return false; - + if (!IsValidVector(m_end)) return false; - + if (!ValidateVectorBounds(m_start)) return false; @@ -289,4 +291,4 @@ bool CBulletsyncPacket::Write(NetBitStreamInterface& stream) const } return true; -} \ No newline at end of file +}