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

feat(extra-natives/five): implement [GET/SET]_GLOBAL_PASSENGER_MASS_MULTIPLIER #2796

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions code/components/extra-natives-five/src/VehicleExtraNatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ static void writeVehicleMemory(fx::ScriptContext& context, std::string_view nn)
}
}

static float* PassengerMassPtr;

static int StreamRenderGfxPtrOffset;
static int HandlingDataPtrOffset;
static int DrawHandlerPtrOffset;
Expand Down Expand Up @@ -753,6 +755,11 @@ static HookFunction initFunction([]()
VehicleRollBiasOffset = VehiclePitchBiasOffset - 4;
}

{
auto location = hook::get_pattern<char>("F3 0F 59 3D ? ? ? ? F3 0F 58 3D ? ? ? ? 48 85 C9", 4);
PassengerMassPtr = hook::get_address<float*>(location);
}

{
std::initializer_list<PatternPair> list = {
{ "44 38 ? ? ? ? 02 74 ? F3 0F 10 1D", 13 },
Expand Down Expand Up @@ -1518,6 +1525,22 @@ static HookFunction initFunction([]()
ResetFlyThroughWindscreenParams();
});

fx::ScriptEngine::RegisterNativeHandler("SET_GLOBAL_PASSENGER_MASS_MULTIPLIER", [](fx::ScriptContext& context)
{
float weight = context.GetArgument<float>(0);

if (weight < 0.0)
{
weight = 0.0;
}
*PassengerMassPtr = weight;
});

fx::ScriptEngine::RegisterNativeHandler("GET_GLOBAL_PASSENGER_MASS_MULTIPLIER", [](fx::ScriptContext& context)
{
context.SetResult<float>(*PassengerMassPtr);
});

static struct : jitasm::Frontend
{
static bool ShouldSkipRepairFunc(fwEntity* VehPointer)
Expand Down Expand Up @@ -1595,6 +1618,8 @@ static HookFunction initFunction([]()

g_isFuelConsumptionOn = false;
g_globalFuelConsumptionMultiplier = 1.f;

*PassengerMassPtr = 0.05f;
});

fx::ScriptEngine::RegisterNativeHandler("SET_VEHICLE_AUTO_REPAIR_DISABLED", [](fx::ScriptContext& context)
Expand Down
15 changes: 15 additions & 0 deletions ext/native-decls/GetGlobalPassengerMassMultiplier.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
ns: CFX
apiset: client
game: gta5
---
## GET_GLOBAL_PASSENGER_MASS_MULTIPLIER

```c
float GET_GLOBAL_PASSENGER_MASS_MULTIPLIER();
```

A getter for [SET_GLOBAL_PASSENGER_MASS_MULTIPLIER](#_0x1c47f6ac).

## Return value
Returns the mass of each passenger (not counting the driver) as a percentage of vehicle mass. Default value is 0.05
13 changes: 13 additions & 0 deletions ext/native-decls/SetGlobalPassengerMassMultiplier.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
ns: CFX
apiset: client
game: gta5
---
## SET_GLOBAL_PASSENGER_MASS_MULTIPLIER

```c
void SET_GLOBAL_PASSENGER_MASS_MULTIPLIER(float massMul);
```
## Parameters
* **massMul**: Weight of each passenger (not counting the driver) as a percentage of vehicle mass. Is applied to all vehicles. Default value is 0.05
Loading