Skip to content

Commit

Permalink
tweak(extra-natives/five): implement [GET/SET]_VEHICLE_XMAS_SNOW_FACTOR
Browse files Browse the repository at this point in the history
  • Loading branch information
ook3D committed Dec 14, 2024
1 parent 1baa5c8 commit 181a3c2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
24 changes: 24 additions & 0 deletions code/components/extra-natives-five/src/VehicleExtraNatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ static void writeVehicleMemory(fx::ScriptContext& context, std::string_view nn)
}

static float* PassengerMassPtr;
static float* SnowGripFactor;

static int StreamRenderGfxPtrOffset;
static int HandlingDataPtrOffset;
Expand Down Expand Up @@ -775,6 +776,12 @@ static HookFunction initFunction([]()
PassengerMassPtr = hook::get_address<float*>(location);
}

{
SnowGripFactor = (float*)hook::AllocateStubMemory(4);
static uint8_t* location = hook::get_pattern<uint8_t>("F3 0F 5C C8 48 3B C8", 4);
hook::put<int32_t>(location, (intptr_t)SnowGripFactor - (intptr_t)location - 4);
}

{
std::initializer_list<PatternPair> list = {
{ "44 38 ? ? ? ? 02 74 ? F3 0F 10 1D", 13 },
Expand Down Expand Up @@ -1581,6 +1588,22 @@ static HookFunction initFunction([]()
context.SetResult<float>(*PassengerMassPtr);
});

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

if (gripFactor < 0.0)
{
gripFactor = 0.0;
}
*SnowGripFactor = gripFactor;
});

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

static struct : jitasm::Frontend
{
static bool ShouldSkipRepairFunc(fwEntity* VehPointer)
Expand Down Expand Up @@ -1660,6 +1683,7 @@ static HookFunction initFunction([]()
g_globalFuelConsumptionMultiplier = 1.f;

*PassengerMassPtr = 0.05f;
*SnowGripFactor = 0.2f;
});

fx::ScriptEngine::RegisterNativeHandler("SET_VEHICLE_AUTO_REPAIR_DISABLED", [](fx::ScriptContext& context)
Expand Down
12 changes: 12 additions & 0 deletions ext/native-decls/GetVehicleXmasSnowFactor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
ns: CFX
apiset: client
game: gta5
---
## GET_VEHICLE_XMAS_SNOW_FACTOR
```c
float GET_VEHICLE_XMAS_SNOW_FACTOR();
```
A getter for [SET_VEHICLE_XMAS_SNOW_FACTOR](#_80cc4c9e).
## Return value
Returns the grip factor for the vehicles wheels during xmas weather. default value is 0.2.
11 changes: 11 additions & 0 deletions ext/native-decls/SetVehicleXmasSnowFactor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
ns: CFX
apiset: client
game: gta5
---
## SET_VEHICLE_XMAS_SNOW_FACTOR
```c
void SET_VEHICLE_XMAS_SNOW_FACTOR(float gripFactor);
```
## Parameters
* **gripFactor**: amount of grip strength vehicle wheels have when xmas weather is active, 1.0 being normal weather grip. 0.2 is the default.

0 comments on commit 181a3c2

Please sign in to comment.