From a4b03ed09e2b0f4e049794ef3411d50574e36eca Mon Sep 17 00:00:00 2001 From: Ricky Merc Date: Wed, 6 Mar 2024 16:05:28 -0500 Subject: [PATCH] tweak(extra-natives/five): Changed requested stuff for GET_VEHICLE_GEAR_RATIO and SET_VEHICLE_GEAR_RATIO --- .../src/VehicleExtraNatives.cpp | 27 ++++++++++--------- ext/native-decls/GetVehicleGearRatio.md | 17 +++++++----- ext/native-decls/SetVehicleGearRatio.md | 7 ++--- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/code/components/extra-natives-five/src/VehicleExtraNatives.cpp b/code/components/extra-natives-five/src/VehicleExtraNatives.cpp index 99a1823606..1e26b3b517 100644 --- a/code/components/extra-natives-five/src/VehicleExtraNatives.cpp +++ b/code/components/extra-natives-five/src/VehicleExtraNatives.cpp @@ -518,6 +518,8 @@ static HookFunction initFunction([]() CurrentGearOffset = *(uint32_t*)(location + 18); NextGearOffset = *(uint32_t*)(location + 11); + + VehicleGearRatioOffset = CurrentGearOffset + (xbr::IsGameBuildOrGreater<3095>() ? 12 : 8); } { @@ -635,18 +637,7 @@ static HookFunction initFunction([]() VehiclePitchBiasOffset = *hook::get_pattern("0F 2F F7 44 0F 28 C0 F3 44 0F 58 83", 12); VehicleRollBiasOffset = VehiclePitchBiasOffset - 4; } - if (xbr::IsGameBuildOrGreater<3095>()) - { - auto location = hook::get_pattern("48 8D 8F ? ? ? ? 4C 8B C3 F3 0F 11 7C 24"); - - VehicleGearRatioOffset = *(int*)(location + 3) + 8 + 1 * sizeof(float); - } - else - { - auto location = hook::get_pattern("48 8D 8F ? ? ? ? 4C 8B C3 F3 0F 11 7C 24"); - VehicleGearRatioOffset = *(int*)(location + 3) + 8; - } { std::initializer_list list = { { "44 38 ? ? ? ? 02 74 ? F3 0F 10 1D", 13 }, @@ -883,7 +874,14 @@ static HookFunction initFunction([]() unsigned char gear = context.GetArgument(1); if (fwEntity* vehicle = getAndCheckVehicle(context, "GET_VEHICLE_GEAR_RATIO")) { - context.SetResult(*(float*)((char*)vehicle + VehicleGearRatioOffset + gear * sizeof(float))); + if (gear <= 10) + { + context.SetResult(*(float*)((char*)vehicle + VehicleGearRatioOffset + gear * sizeof(float))); + } + else + { + context.SetResult(0.0f); + } } }); @@ -892,7 +890,10 @@ static HookFunction initFunction([]() unsigned char gear = context.GetArgument(1); if (fwEntity* vehicle = getAndCheckVehicle(context, "SET_VEHICLE_GEAR_RATIO")) { - *(float*)((char*)vehicle + VehicleGearRatioOffset + gear * sizeof(float)) = context.GetArgument(2); + if (gear <= 10) + { + *(float*)((char*)vehicle + VehicleGearRatioOffset + gear * sizeof(float)) = context.GetArgument(2); + } } }); diff --git a/ext/native-decls/GetVehicleGearRatio.md b/ext/native-decls/GetVehicleGearRatio.md index dace0e358a..4c75e92dd0 100644 --- a/ext/native-decls/GetVehicleGearRatio.md +++ b/ext/native-decls/GetVehicleGearRatio.md @@ -1,12 +1,14 @@ --- ns: CFX apiset: client +game: gta5 --- ## GET_VEHICLE_GEAR_RATIO ```c float GET_VEHICLE_GEAR_RATIO(Vehicle vehicle, int gear); ``` + Gets vehicles gear ratio on choosen gear. ## Parameters @@ -14,25 +16,26 @@ Gets vehicles gear ratio on choosen gear. * **gear**: The vehicles gear you want to get. ## Examples + ```lua -local Vehicle = GetVehiclePedIsIn(PlayerPedId(-1)) +local vehicle = GetVehiclePedIsIn(PlayerPedId(-1)) local currentGear = GetVehicleCurrentGear(Vehicle) -print(GetVehicleGearRatio(Vehicle, currentGear)) -- will print current vehicle gear to console +print(GetVehicleGearRatio(vehicle, currentGear)) -- will print current vehicle gear to console ``` ```js -const Vehicle = GetVehiclePedIsIn(PlayerPedId(-1)); +const vehicle = GetVehiclePedIsIn(PlayerPedId(-1)); const currentGear = GetVehicleCurrentGear(Vehicle); -console.log(GetVehicleGearRatio(Vehicle, currentGear)); // will print current vehicle gear to console +console.log(GetVehicleGearRatio(vehicle, currentGear)); // will print current vehicle gear to console ``` ```cs using static CitizenFX.Core.API; -Vehicle veh = Game.PlayerPed.CurrentVehicle; -int currentGear = GetVehicleCurrentGear(veh.Handle); +Vehicle vehicle = Game.PlayerPed.CurrentVehicle; +int currentGear = GetVehicleCurrentGear(vehicle.Handle); -Debug.WriteLine($"{GetVehicleGearRatio(veh.Handle, currentGear)}"); +Debug.WriteLine($"{GetVehicleGearRatio(vehicle.Handle, currentGear)}"); ``` \ No newline at end of file diff --git a/ext/native-decls/SetVehicleGearRatio.md b/ext/native-decls/SetVehicleGearRatio.md index fcb4c2d709..95d793cfe4 100644 --- a/ext/native-decls/SetVehicleGearRatio.md +++ b/ext/native-decls/SetVehicleGearRatio.md @@ -1,19 +1,23 @@ --- ns: CFX apiset: client +game: gta5 --- ## SET_VEHICLE_GEAR_RATIO ```c void SET_VEHICLE_GEAR_RATIO(Vehicle vehicle, int gear, float ratio); ``` + Sets the vehicles gear ratio on choosen gear, reverse gear needs to be a negative float and forward moving gear needs to be a positive float. Refer to the examples if confused. + ## Parameters * **vehicle**: The vehicle handle. * **gear**: The vehicles gear you want to change. * **ratio**: The gear ratio you want to use. ## Examples + ```lua local function Set8SpeedVehicleGears(Vehicle) SetVehicleGearRatio(Vehicle, 0, -3.32) -- reverse gear at -3.21:1 @@ -25,7 +29,6 @@ local function Set8SpeedVehicleGears(Vehicle) SetVehicleGearRatio(Vehicle, 6, 1.0) -- 6th gear at 1.0:1 SetVehicleGearRatio(Vehicle, 7, 0.84) -- 7th gear at 0.84:1 SetVehicleGearRatio(Vehicle, 8, 0.67) -- 8th gear at 0.67:1 - return end ``` @@ -40,7 +43,6 @@ function Set8SpeedVehicleGears(Vehicle) { SetVehicleGearRatio(Vehicle, 6, 1.0); // 6th gear at 1.0:1 SetVehicleGearRatio(Vehicle, 7, 0.84); // 7th gear at 0.84:1 SetVehicleGearRatio(Vehicle, 8, 0.67); // 8th gear at 0.67:1 - return; } ``` @@ -58,6 +60,5 @@ public static void Set8SpeedVehicleGears(int Vehicle) SetVehicleGearRatio(Vehicle, 6, 1.0); // 6th gear at 1.0:1 SetVehicleGearRatio(Vehicle, 7, 0.84); // 7th gear at 0.84:1 SetVehicleGearRatio(Vehicle, 8, 0.67); // 8th gear at 0.67:1 - return; } ``` \ No newline at end of file