Skip to content

Commit

Permalink
Merge Train station natives (pr-2916)
Browse files Browse the repository at this point in the history
f74a2a7 - feat(extra-natives/five): train station natives
  • Loading branch information
prikolium-cfx committed Nov 12, 2024
2 parents 37215a5 + f74a2a7 commit 4e5ddb1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ static int VehicleDamageStructOffset;
static bool* g_trainsForceDoorsOpen;
static int TrainDoorCountOffset;
static int TrainDoorArrayPointerOffset;
static int TrainFlagOffset;
constexpr int TrainStopAtStationsFlag = 4;

static int VehicleRepairMethodVtableOffset;

Expand Down Expand Up @@ -588,6 +590,7 @@ static HookFunction initFunction([]()
WheelHealthOffset = *hook::get_pattern<uint32_t>("75 24 F3 0F 10 ? ? ? 00 00 F3 0F", 6);
LightMultiplierGetOffset = *hook::get_pattern<uint32_t>("00 00 48 8B CE F3 0F 59 ? ? ? 00 00 F3 41", 9);
VehicleRepairMethodVtableOffset = *hook::get_pattern<uint32_t>("C1 E8 19 A8 01 74 ? 48 8B 81", -14);
TrainFlagOffset = *hook::get_pattern<uint32_t>("80 8B ? ? ? ? ? 8B 05 ? ? ? ? FF C8", 2);
}

{
Expand Down Expand Up @@ -1466,6 +1469,10 @@ static HookFunction initFunction([]()
GetTrainDoor(train, doorIndex)->ratio = ratio;
}));

fx::ScriptEngine::RegisterNativeHandler("SET_TRAIN_STOP_AT_STATIONS", std::bind(writeVehicleMemoryBit<&TrainFlagOffset, TrainStopAtStationsFlag>, _1, "SET_TRAIN_STOP_AT_STATIONS"));

fx::ScriptEngine::RegisterNativeHandler("DOES_TRAIN_STOP_AT_STATIONS", std::bind(readVehicleMemoryBit<&TrainFlagOffset, TrainStopAtStationsFlag>, _1, "DOES_TRAIN_STOP_AT_STATIONS"));

fx::ScriptEngine::RegisterNativeHandler("GET_VEHICLE_WHEEL_X_OFFSET", makeWheelFunction([](fx::ScriptContext& context, fwEntity* vehicle, uintptr_t wheelAddr)
{
context.SetResult<float>(*reinterpret_cast<float*>(wheelAddr + WheelXOffsetOffset));
Expand Down
16 changes: 16 additions & 0 deletions ext/native-decls/DoesTrainStopAtStations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
ns: CFX
apiset: client
game: gta5
---
## DOES_TRAIN_STOP_AT_STATIONS

```c
BOOL DOES_TRAIN_STOP_AT_STATIONS(Vehicle train);
```
## Parameters
* **train**: The train handle
## Return value
True if the train stops at stations. False otherwise
16 changes: 16 additions & 0 deletions ext/native-decls/SetTrainStopAtStations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
ns: CFX
apiset: client
game: gta5
---
## SET_TRAIN_STOP_AT_STATIONS

```c
void SET_TRAIN_STOP_AT_STATIONS(Vehicle train, BOOL state);
```
Toggles a train's ability to stop at stations
## Parameters
* **train**: The train handle
* **state**: True to make the train stop at stations. False to make the train not stop at stations

0 comments on commit 4e5ddb1

Please sign in to comment.