From ee7489218d7434986b529c00b15002d9eec897db Mon Sep 17 00:00:00 2001 From: Deewarz Date: Sun, 12 Jan 2025 19:40:11 +0100 Subject: [PATCH] Fix set license plate --- code/client/src/core/modules/vehicle.cpp | 10 ++-- code/server/src/core/builtins/vehicle.cpp | 5 +- code/server/src/core/modules/vehicle.cpp | 12 ----- .../game_rpc/vehicle/vehicle_setprops.h | 2 +- code/shared/modules/vehicle_sync.hpp | 52 ++++++++++++++----- 5 files changed, 48 insertions(+), 33 deletions(-) diff --git a/code/client/src/core/modules/vehicle.cpp b/code/client/src/core/modules/vehicle.cpp index c795aa7..9f41555 100644 --- a/code/client/src/core/modules/vehicle.cpp +++ b/code/client/src/core/modules/vehicle.cpp @@ -99,9 +99,9 @@ namespace MafiaMP::Core::Modules { void Vehicle::Create(flecs::entity e, std::string modelName) { auto info = Core::gApplication->GetEntityFactory()->RequestVehicle(std::move(modelName)); - auto &trackingData = e.ensure(); - trackingData.info = info; - trackingData.car = nullptr; + auto &trackingData = e.ensure(); + trackingData.info = info; + trackingData.car = nullptr; auto &interp = e.ensure(); interp.interpolator.GetPosition()->SetCompensationFactor(1.5f); @@ -211,7 +211,7 @@ namespace MafiaMP::Core::Modules { vehicle->SetGear(updateData->gear); vehicle->SetHandbrake(updateData->handbrake, false); vehicle->SetHorn(updateData->hornOn); - if (::strcmp(vehicle->GetSPZText(), updateData->licensePlate) > 0) { + if (std::strcmp(vehicle->GetSPZText(), updateData->licensePlate) != 0) { vehicle->SetSPZText(updateData->licensePlate, true); } vehicle->SetPower(updateData->power); @@ -341,7 +341,7 @@ namespace MafiaMP::Core::Modules { if (licensePlate.HasValue()) { const auto plate = licensePlate().C_String(); - ::memcpy(updateData->licensePlate, plate, strlen(plate) + 1); + std::memcpy(updateData->licensePlate, plate, strlen(plate) + 1); } if (lockState.HasValue()) { diff --git a/code/server/src/core/builtins/vehicle.cpp b/code/server/src/core/builtins/vehicle.cpp index c7b17ae..91f7833 100644 --- a/code/server/src/core/builtins/vehicle.cpp +++ b/code/server/src/core/builtins/vehicle.cpp @@ -127,7 +127,10 @@ namespace MafiaMP::Scripting { void Vehicle::SetLicensePlate(std::string plate) { auto vehData = _ent.get_mut(); - ::memcpy(vehData->licensePlate, plate.c_str(), std::min(sizeof(vehData->licensePlate), plate.length())); + + size_t copyLength = std::min(Shared::Modules::VehicleSync::LICENSE_PLATE_MAX_LENGTH - 1, plate.length()); + std::memcpy(vehData->licensePlate, plate.c_str(), copyLength); + MafiaMP::Shared::RPC::VehicleSetProps msg {}; msg.licensePlate = plate.c_str(); FW_SEND_SERVER_COMPONENT_GAME_RPC(Shared::RPC::VehicleSetProps, _ent, msg); diff --git a/code/server/src/core/modules/vehicle.cpp b/code/server/src/core/modules/vehicle.cpp index 939fe61..84b16b4 100644 --- a/code/server/src/core/modules/vehicle.cpp +++ b/code/server/src/core/modules/vehicle.cpp @@ -50,18 +50,6 @@ namespace MafiaMP::Core::Modules { auto updateData = e.ensure(); - // generate a random license plate - { - constexpr char letters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - constexpr char numbers[] = "0123456789"; - for (int i = 0; i < 2; i++) { - updateData.licensePlate[i] = letters[::rand() % (sizeof(letters) - 1)]; - } - for (int i = 3; i < 6; i++) { - updateData.licensePlate[i] = numbers[::rand() % (sizeof(numbers) - 1)]; - } - } - e.add(); e.add(); diff --git a/code/shared/game_rpc/vehicle/vehicle_setprops.h b/code/shared/game_rpc/vehicle/vehicle_setprops.h index 25cb71f..6a44656 100644 --- a/code/shared/game_rpc/vehicle/vehicle_setprops.h +++ b/code/shared/game_rpc/vehicle/vehicle_setprops.h @@ -60,7 +60,7 @@ namespace MafiaMP::Shared::RPC { } bool Valid() const override { - if (licensePlate.HasValue() && licensePlate().GetLength() > 7) { + if (licensePlate.HasValue() && licensePlate().GetLength() > Modules::VehicleSync::LICENSE_PLATE_MAX_LENGTH) { return false; } diff --git a/code/shared/modules/vehicle_sync.hpp b/code/shared/modules/vehicle_sync.hpp index 1899da6..f809000 100644 --- a/code/shared/modules/vehicle_sync.hpp +++ b/code/shared/modules/vehicle_sync.hpp @@ -8,6 +8,8 @@ namespace MafiaMP::Shared::Modules { struct VehicleSync { + static constexpr uint32_t LICENSE_PLATE_MAX_LENGTH = 7; + enum class LockState { UNLOCKED, LOCKED, @@ -16,27 +18,49 @@ namespace MafiaMP::Shared::Modules { struct UpdateData { glm::vec3 angularVelocity {}; + bool beaconLightsOn = false; - float brake = 0.0f; + + float brake = 0.0f; + glm::vec4 colorPrimary {1.0f, 1.0f, 1.0f, 1.0f}; + glm::vec4 colorSecondary {1.0f, 1.0f, 1.0f, 1.0f}; - float dirt = 0.0f; - bool engineOn = false; - float fuel = 100.0f; // We use arbitrary value, the max depends of the vehicle. See C_Motor::GetFuelSettings. - int gear = 0; - float handbrake = 0.0f; - bool hornOn = false; - char licensePlate[7] = "AZ-000"; - LockState lockState = LockState::UNLOCKED; - float power = 0.0f; - bool radioOn = false; - int radioStationId = 0; + + float dirt = 0.0f; + + bool engineOn = false; + + float fuel = 100.0f; // We use arbitrary value, the max depends of the vehicle. See C_Motor::GetFuelSettings. + + int gear = 0; + + float handbrake = 0.0f; + + bool hornOn = false; + + char licensePlate[LICENSE_PLATE_MAX_LENGTH] = "AZ-000"; + + LockState lockState = LockState::UNLOCKED; + + float power = 0.0f; + + bool radioOn = false; + + int radioStationId = 0; + glm::vec4 rimColor {1.0f, 1.0f, 1.0f, 1.0f}; - float rust = 0.0f; + + float rust = 0.0f; + bool sirenOn = false; - float steer = 0.0f; + + float steer = 0.0f; + glm::vec4 tireColor {1.0f, 1.0f, 1.0f, 1.0f}; + glm::vec3 velocity {}; + glm::vec4 windowTint {0.0f, 0.0f, 0.0f, 20.0f / 255.0f}; };