Native GetVehicleCurrentGear() is reading from the wrong address in memory

FiveM Client (Production) | FXServer Version: FXServer-master SERVER v1.0.0.6497 win32

What should’ve happend:

This native should’ve read the vehicle current gear

What Actually Happens:

This native is reading the vehicle next gear, instead of the current.

Since in ordinary gameplay, those are always the same, it make it looks as if this native was working properly.

Category of bug:

Native, likely to happen in all FiveM Versions and GameBuilds.

Reproducible Steps:

  1. Set the vehicle current gear to 2
  2. Read the current gear from memory using an .asi plugin, like IKT Manual transmission
  3. you’ll see that while on the plugin, which is reading from the correct address in memory shows that you’re in second gear, if you try to get the current gear with GetVehicleCurrentGear() it will return either 1 or 0 (reverse, if you’re in reverse.)

Example script:

local setGear = GetHashKey('SET_VEHICLE_CURRENT_GEAR') & 0xFFFFFFFF
local function SetVehicleCurrentGear(veh, gear)
    Citizen.InvokeNative(setGear, veh, gear)
end

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        local player = PlayerPedId()
        if IsPedInAnyVehicle(player, false) then
            local vehicle = GetVehiclePedIsIn(player, false)
            if GetPedInVehicleSeat(vehicle, -1) == player then
                                    SetVehicleHighGear(vehicle,1)
                                    SetVehicleCurrentGear(vehicle,2)
            end
            print(GetVehicleCurrentGear(vehicle)) -- will output 1, which is the vehilcle next gear.
         end
      end

to further confirm that, you can call the native to set the nextgear to whatever, and you’ll see that the getvehiclecurrentgear will output the same as you set.

the aforementioned native is:

local nextGear = GetHashKey('SET_VEHICLE_NEXT_GEAR') & 0xFFFFFFFF
local function SetVehicleNextGear(veh, gear)
    Citizen.InvokeNative(nextGear, veh, gear)
end

IN Game screen shot showing the problem:

Took a peek at this and it turned out to be an unintentional variable swap, PR’d a fix :smile: