Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] [Scripting] Vehicle:setLicensePlate() is not working properly #112

Closed
Deewarz opened this issue Jan 12, 2025 · 2 comments · Fixed by #114
Closed

[Bug] [Scripting] Vehicle:setLicensePlate() is not working properly #112

Deewarz opened this issue Jan 12, 2025 · 2 comments · Fixed by #114
Labels
bug Something isn't working

Comments

@Deewarz
Copy link
Contributor

Deewarz commented Jan 12, 2025

Description

If we try to update the license plate of a vehicle other than empty, nothing happens.

Reproduction

When in vehicle:

listenEvent("onChatCommand", function (player, message, command, args)
  if command == "plate" then
    local veh = player:getVehicle()

    if veh == nil then
      return
    end

    local licensePlate = args[1] or ""
    veh:setLicensePlate(licensePlate)
  end
end)

Possible reason

Could be related to the way we manage the string here:

void Vehicle::SetLicensePlate(std::string plate) {
auto vehData = _ent.get_mut<Shared::Modules::VehicleSync::UpdateData>();
::memcpy(vehData->licensePlate, plate.c_str(), std::min(sizeof(vehData->licensePlate), plate.length()));
MafiaMP::Shared::RPC::VehicleSetProps msg {};
msg.licensePlate = plate.c_str();
FW_SEND_SERVER_COMPONENT_GAME_RPC(Shared::RPC::VehicleSetProps, _ent, msg);
}

@Deewarz Deewarz added the bug Something isn't working label Jan 12, 2025
@zpl-zak
Copy link
Member

zpl-zak commented Jan 12, 2025

Could you check if we hit this condition on client-side and whether it carries any value at all?

if (licensePlate.HasValue()) {
const auto plate = licensePlate().C_String();
::memcpy(updateData->licensePlate, plate, strlen(plate) + 1);
}

Also check if msg validation passes or fails here:

if (licensePlate.HasValue() && licensePlate().GetLength() > 7) {
return false;
}

@Deewarz
Copy link
Contributor Author

Deewarz commented Jan 12, 2025

After analysis, the bug is related to this code:

if (::strcmp(vehicle->GetSPZText(), updateData->licensePlate) > 0) {
vehicle->SetSPZText(updateData->licensePlate, true);
}

The comparison should check if it is not equal to zero. (https://en.cppreference.com/w/cpp/string/byte/strcmp)

Fix incoming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants