Skip to content

Commit

Permalink
tweak(extra-natives/five): Changed requested stuff for GET_VEHICLE_GE…
Browse files Browse the repository at this point in the history
…AR_RATIO and SET_VEHICLE_GEAR_RATIO
  • Loading branch information
RickyB505 committed Mar 12, 2024
1 parent a511410 commit a4b03ed
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
27 changes: 14 additions & 13 deletions code/components/extra-natives-five/src/VehicleExtraNatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,8 @@ static HookFunction initFunction([]()

CurrentGearOffset = *(uint32_t*)(location + 18);
NextGearOffset = *(uint32_t*)(location + 11);

VehicleGearRatioOffset = CurrentGearOffset + (xbr::IsGameBuildOrGreater<3095>() ? 12 : 8);
}

{
Expand Down Expand Up @@ -635,18 +637,7 @@ static HookFunction initFunction([]()
VehiclePitchBiasOffset = *hook::get_pattern<uint32_t>("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<char>("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<char>("48 8D 8F ? ? ? ? 4C 8B C3 F3 0F 11 7C 24");

VehicleGearRatioOffset = *(int*)(location + 3) + 8;
}
{
std::initializer_list<PatternPair> list = {
{ "44 38 ? ? ? ? 02 74 ? F3 0F 10 1D", 13 },
Expand Down Expand Up @@ -883,7 +874,14 @@ static HookFunction initFunction([]()
unsigned char gear = context.GetArgument<int>(1);
if (fwEntity* vehicle = getAndCheckVehicle(context, "GET_VEHICLE_GEAR_RATIO"))
{
context.SetResult<float>(*(float*)((char*)vehicle + VehicleGearRatioOffset + gear * sizeof(float)));
if (gear <= 10)
{
context.SetResult<float>(*(float*)((char*)vehicle + VehicleGearRatioOffset + gear * sizeof(float)));
}
else
{
context.SetResult<float>(0.0f);
}
}
});

Expand All @@ -892,7 +890,10 @@ static HookFunction initFunction([]()
unsigned char gear = context.GetArgument<int>(1);
if (fwEntity* vehicle = getAndCheckVehicle(context, "SET_VEHICLE_GEAR_RATIO"))
{
*(float*)((char*)vehicle + VehicleGearRatioOffset + gear * sizeof(float)) = context.GetArgument<float>(2);
if (gear <= 10)
{
*(float*)((char*)vehicle + VehicleGearRatioOffset + gear * sizeof(float)) = context.GetArgument<float>(2);
}
}
});

Expand Down
17 changes: 10 additions & 7 deletions ext/native-decls/GetVehicleGearRatio.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
---
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
* **vehicle**: The vehicle handle.
* **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)}");
```
7 changes: 4 additions & 3 deletions ext/native-decls/SetVehicleGearRatio.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
```

Expand All @@ -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;
}
```

Expand All @@ -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;
}
```

0 comments on commit a4b03ed

Please sign in to comment.