From 9fff4b2b1eabbf252bdbabc7a64574a1b4c2b4ed Mon Sep 17 00:00:00 2001 From: Eren Yaman <68560906+shadylua@users.noreply.github.com> Date: Sun, 7 Sep 2025 22:06:26 +0300 Subject: [PATCH 1/4] Update CBulletsyncPacket.cpp --- .../mods/deathmatch/logic/packets/CBulletsyncPacket.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Server/mods/deathmatch/logic/packets/CBulletsyncPacket.cpp b/Server/mods/deathmatch/logic/packets/CBulletsyncPacket.cpp index 43d41199b19..a05f928602d 100644 --- a/Server/mods/deathmatch/logic/packets/CBulletsyncPacket.cpp +++ b/Server/mods/deathmatch/logic/packets/CBulletsyncPacket.cpp @@ -15,6 +15,7 @@ #include "CWeaponStatManager.h" #include "CElementIDs.h" #include "CElement.h" +#include "CWeaponNames.h" CBulletsyncPacket::CBulletsyncPacket(CPlayer* player) : m_weapon(WEAPONTYPE_UNARMED) @@ -222,10 +223,14 @@ bool CBulletsyncPacket::Read(NetBitStreamInterface& stream) if (!pPlayer->HasWeaponType(static_cast(m_weapon))) return false; + // Check if weapon has ammo - if (pPlayer->GetWeaponAmmoInClip(static_cast(m_weapon)) == 0) + unsigned char ucSlot = CWeaponNames::GetSlotFromWeapon(static_cast(m_weapon)); + CWeapon* pWeapon = pPlayer->GetWeapon(ucSlot); + if (!pWeapon || pWeapon->usAmmo <= 0) return false; } + if (!stream.Read(m_order)) return false; @@ -289,4 +294,4 @@ bool CBulletsyncPacket::Write(NetBitStreamInterface& stream) const } return true; -} \ No newline at end of file +} From 837714e1f8776b376eddacc552ab45c0150f1307 Mon Sep 17 00:00:00 2001 From: Eren Yaman <68560906+shadylua@users.noreply.github.com> Date: Mon, 8 Sep 2025 09:26:59 +0300 Subject: [PATCH 2/4] Update CBulletsyncPacket.cpp --- Server/mods/deathmatch/logic/packets/CBulletsyncPacket.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Server/mods/deathmatch/logic/packets/CBulletsyncPacket.cpp b/Server/mods/deathmatch/logic/packets/CBulletsyncPacket.cpp index a05f928602d..d8fadb853b1 100644 --- a/Server/mods/deathmatch/logic/packets/CBulletsyncPacket.cpp +++ b/Server/mods/deathmatch/logic/packets/CBulletsyncPacket.cpp @@ -225,10 +225,9 @@ bool CBulletsyncPacket::Read(NetBitStreamInterface& stream) // Check if weapon has ammo - unsigned char ucSlot = CWeaponNames::GetSlotFromWeapon(static_cast(m_weapon)); - CWeapon* pWeapon = pPlayer->GetWeapon(ucSlot); - if (!pWeapon || pWeapon->usAmmo <= 0) - return false; + std::uint8_t weaponSlot = CWeaponNames::GetSlotFromWeapon(static_cast(m_weapon)); + if (pPlayer->GetWeaponTotalAmmo(static_cast(m_weapon)) <= 0) + return false; } From ce815b3dd5218715e118f1ea3500eba44fe266db Mon Sep 17 00:00:00 2001 From: Eren Yaman <68560906+shadylua@users.noreply.github.com> Date: Mon, 8 Sep 2025 14:50:15 +0300 Subject: [PATCH 3/4] Update CBulletsyncPacket.cpp --- .../logic/packets/CBulletsyncPacket.cpp | 96 +++++++++---------- 1 file changed, 47 insertions(+), 49 deletions(-) diff --git a/Server/mods/deathmatch/logic/packets/CBulletsyncPacket.cpp b/Server/mods/deathmatch/logic/packets/CBulletsyncPacket.cpp index d8fadb853b1..d314f031102 100644 --- a/Server/mods/deathmatch/logic/packets/CBulletsyncPacket.cpp +++ b/Server/mods/deathmatch/logic/packets/CBulletsyncPacket.cpp @@ -16,6 +16,7 @@ #include "CElementIDs.h" #include "CElement.h" #include "CWeaponNames.h" +#include CBulletsyncPacket::CBulletsyncPacket(CPlayer* player) : m_weapon(WEAPONTYPE_UNARMED) @@ -33,16 +34,16 @@ bool CBulletsyncPacket::IsValidVector(const CVector& vec) noexcept { if (!vec.IsValid()) return false; - + if (IsNaN(vec.fX)) return false; - + if (IsNaN(vec.fY)) return false; - + if (IsNaN(vec.fZ)) return false; - + return true; } @@ -67,18 +68,18 @@ bool CBulletsyncPacket::ValidateTrajectory() const noexcept const float dx = m_end.fX - m_start.fX; const float dy = m_end.fY - m_start.fY; 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; - + return true; } @@ -102,25 +103,25 @@ bool CBulletsyncPacket::ReadWeaponAndPositions(NetBitStreamInterface& stream) if (!stream.Read(reinterpret_cast(&m_start), sizeof(CVector))) return false; - + 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; - + if (!ValidateVectorBounds(m_end)) return false; - + if (!ValidateTrajectory()) return false; - + return true; } @@ -141,25 +142,25 @@ bool CBulletsyncPacket::ReadOptionalDamage(NetBitStreamInterface& stream) ResetDamageData(); return false; } - + if (m_damage < 0.0f || m_damage > MAX_DAMAGE) { ResetDamageData(); return false; } - + if (m_zone > MAX_BODY_ZONE) { ResetDamageData(); return false; } - + if (m_damaged == 0) { ResetDamageData(); return false; } - + // Validate that target element exists if (m_damaged != INVALID_ELEMENT_ID) { @@ -169,18 +170,18 @@ bool CBulletsyncPacket::ReadOptionalDamage(NetBitStreamInterface& stream) ResetDamageData(); return false; } - + // 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(); return false; } } - + return true; } @@ -195,17 +196,17 @@ bool CBulletsyncPacket::Read(NetBitStreamInterface& stream) // 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 - + // This check will be done after we read positions } - + if (!ReadWeaponAndPositions(stream)) return false; - + // Now validate player position relative to shot origin if (pPlayer) { @@ -213,30 +214,27 @@ 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 - std::uint8_t weaponSlot = CWeaponNames::GetSlotFromWeapon(static_cast(m_weapon)); - if (pPlayer->GetWeaponTotalAmmo(static_cast(m_weapon)) <= 0) - return false; + if (pPlayer->GetWeaponTotalAmmo(static_cast(m_weapon)) <= 0) + return false; } - - + if (!stream.Read(m_order)) return false; - + if (!ReadOptionalDamage(stream)) return false; - + return true; } @@ -248,27 +246,27 @@ 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; - + if (!ValidateVectorBounds(m_end)) return false; - + if (!ValidateTrajectory()) return false; @@ -284,7 +282,7 @@ bool CBulletsyncPacket::Write(NetBitStreamInterface& stream) const const bool hasDamage = (m_damage > EPSILON) && (m_damaged != INVALID_ELEMENT_ID); stream.WriteBit(hasDamage); - + if (hasDamage) { stream.Write(m_damage); From a3cc119357ad43c9efd3f211456afa63e6f1cc99 Mon Sep 17 00:00:00 2001 From: Dutchman101 <12105539+Dutchman101@users.noreply.github.com> Date: Mon, 8 Sep 2025 14:04:58 +0000 Subject: [PATCH 4/4] Restore original indentation --- .../logic/packets/CBulletsyncPacket.cpp | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/Server/mods/deathmatch/logic/packets/CBulletsyncPacket.cpp b/Server/mods/deathmatch/logic/packets/CBulletsyncPacket.cpp index d314f031102..b224c1c5215 100644 --- a/Server/mods/deathmatch/logic/packets/CBulletsyncPacket.cpp +++ b/Server/mods/deathmatch/logic/packets/CBulletsyncPacket.cpp @@ -34,16 +34,16 @@ bool CBulletsyncPacket::IsValidVector(const CVector& vec) noexcept { if (!vec.IsValid()) return false; - + if (IsNaN(vec.fX)) return false; - + if (IsNaN(vec.fY)) return false; - + if (IsNaN(vec.fZ)) return false; - + return true; } @@ -68,9 +68,9 @@ bool CBulletsyncPacket::ValidateTrajectory() const noexcept const float dx = m_end.fX - m_start.fX; const float dy = m_end.fY - m_start.fY; const float dz = m_end.fZ - m_start.fZ; - + const float movementSq = (dx * dx) + (dy * dy) + (dz * dz); - + if (IsNaN(movementSq)) return false; @@ -79,7 +79,7 @@ bool CBulletsyncPacket::ValidateTrajectory() const noexcept if (movementSq > MAX_DISTANCE_SQ) return false; - + return true; } @@ -103,25 +103,25 @@ bool CBulletsyncPacket::ReadWeaponAndPositions(NetBitStreamInterface& stream) if (!stream.Read(reinterpret_cast(&m_start), sizeof(CVector))) return false; - + 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; - + if (!ValidateVectorBounds(m_end)) return false; - + if (!ValidateTrajectory()) return false; - + return true; } @@ -142,19 +142,19 @@ bool CBulletsyncPacket::ReadOptionalDamage(NetBitStreamInterface& stream) ResetDamageData(); return false; } - + if (m_damage < 0.0f || m_damage > MAX_DAMAGE) { ResetDamageData(); return false; } - + if (m_zone > MAX_BODY_ZONE) { ResetDamageData(); return false; } - + if (m_damaged == 0) { ResetDamageData(); @@ -170,7 +170,7 @@ bool CBulletsyncPacket::ReadOptionalDamage(NetBitStreamInterface& stream) ResetDamageData(); return false; } - + // Check element type is valid for damage auto elementType = pElement->GetType(); if (elementType != CElement::PLAYER && @@ -181,7 +181,7 @@ bool CBulletsyncPacket::ReadOptionalDamage(NetBitStreamInterface& stream) return false; } } - + return true; } @@ -189,7 +189,7 @@ bool CBulletsyncPacket::Read(NetBitStreamInterface& stream) { if (!m_pSourceElement) return false; - + CPlayer* pPlayer = static_cast(m_pSourceElement); if (pPlayer) { @@ -200,10 +200,10 @@ bool CBulletsyncPacket::Read(NetBitStreamInterface& stream) // 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 - + // This check will be done after we read positions } - + if (!ReadWeaponAndPositions(stream)) return false; @@ -215,23 +215,23 @@ bool CBulletsyncPacket::Read(NetBitStreamInterface& stream) float dy = m_start.fY - playerPos.fY; float dz = m_start.fZ - playerPos.fZ; 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))) return false; - + // Check if weapon has ammo if (pPlayer->GetWeaponTotalAmmo(static_cast(m_weapon)) <= 0) return false; } - + if (!stream.Read(m_order)) return false; - + if (!ReadOptionalDamage(stream)) return false; @@ -248,7 +248,7 @@ bool CBulletsyncPacket::Write(NetBitStreamInterface& stream) const return false; const ElementID id = pPlayer->GetID(); - + if (id == INVALID_ELEMENT_ID) return false; @@ -263,10 +263,10 @@ bool CBulletsyncPacket::Write(NetBitStreamInterface& stream) const if (!ValidateVectorBounds(m_start)) return false; - + if (!ValidateVectorBounds(m_end)) return false; - + if (!ValidateTrajectory()) return false; @@ -282,7 +282,7 @@ bool CBulletsyncPacket::Write(NetBitStreamInterface& stream) const const bool hasDamage = (m_damage > EPSILON) && (m_damaged != INVALID_ELEMENT_ID); stream.WriteBit(hasDamage); - + if (hasDamage) { stream.Write(m_damage);