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

Drive-by clipset fallback bypass native for FiveM #2380

Merged
merged 2 commits into from Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 23 additions & 1 deletion code/components/extra-natives-five/src/VehicleExtraNatives.cpp
Expand Up @@ -371,6 +371,20 @@ static void DeleteNetworkCloneWrap(void* objectMgr, void* netObject, int reason,
return g_origDeleteNetworkClone(objectMgr, netObject, reason, forceRemote1, forceRemote2);
}

static bool g_overrideUseDefaultDriveByClipset = false;

static bool (*g_origShouldUseDefaultDriveByClipset)(CPed*, char);

static bool ShouldUseDefaultDriveByClipset(CPed* ped, char flag)
{
if (g_overrideUseDefaultDriveByClipset)
{
return false;
}

return g_origShouldUseDefaultDriveByClipset(ped, flag);
}

static void ResetFlyThroughWindscreenParams()
{
for (auto& entry : g_flyThroughWindscreenParams)
Expand Down Expand Up @@ -1364,9 +1378,11 @@ static HookFunction initFunction([]()
g_skipRepairVehicles.clear();
ResetFlyThroughWindscreenParams();
*g_trainsForceDoorsOpen = true;
g_overrideUseDefaultDriveByClipset = false;
});

fx::ScriptEngine::RegisterNativeHandler("SET_VEHICLE_AUTO_REPAIR_DISABLED", [](fx::ScriptContext& context) {
fx::ScriptEngine::RegisterNativeHandler("SET_VEHICLE_AUTO_REPAIR_DISABLED", [](fx::ScriptContext& context)
{
auto vehHandle = context.GetArgument<int>(0);
auto shouldDisable = context.GetArgument<bool>(1);

Expand Down Expand Up @@ -1422,6 +1438,11 @@ static HookFunction initFunction([]()
g_overrideCanPedStandOnVehicle = context.GetArgument<bool>(0);
});

fx::ScriptEngine::RegisterNativeHandler("OVERRIDE_PEDS_USE_DEFAULT_DRIVE_BY_CLIPSET", [](fx::ScriptContext& context)
{
g_overrideUseDefaultDriveByClipset = context.GetArgument<bool>(0);
});

// vehicle xenon lights patches to support RGB colors
{
static struct : jitasm::Frontend
Expand Down Expand Up @@ -1591,6 +1612,7 @@ static HookFunction initFunction([]()
MH_Initialize();
MH_CreateHook(hook::get_pattern("E8 ? ? ? ? 8A 83 DA 00 00 00 24 0F 3C 02", -0x32), DeleteVehicleWrap, (void**)&g_origDeleteVehicle);
MH_CreateHook(hook::get_pattern("80 7A 4B 00 45 8A F9", -0x1D), DeleteNetworkCloneWrap, (void**)&g_origDeleteNetworkClone);
MH_CreateHook(hook::get_call(hook::get_pattern("E8 ? ? ? ? 84 C0 74 0F 8B 47 20")), ShouldUseDefaultDriveByClipset, (void**)&g_origShouldUseDefaultDriveByClipset);
MH_CreateHook(hook::get_call(hook::get_pattern("74 22 48 8B CA E8 ? ? ? ? 84 C0 74 16", 5)), CanPedStandOnVehicleWrap, (void**)&g_origCanPedStandOnVehicle);
MH_CreateHook(hook::get_call(hook::get_pattern("48 8B 4F 20 48 8D 54 24 ? E8", 0x9)), DashboardHandler, (void**)&g_origDashboardHandler);
MH_EnableHook(MH_ALL_HOOKS);
Expand Down
17 changes: 17 additions & 0 deletions ext/native-decls/OverridePedsUseDefaultDriveByClipset.md
@@ -0,0 +1,17 @@
---
ns: CFX
apiset: client
game: gta5
---
## OVERRIDE_PEDS_USE_DEFAULT_DRIVE_BY_CLIPSET

```c
void OVERRIDE_PEDS_USE_DEFAULT_DRIVE_BY_CLIPSET(BOOL flag);
```

Allows the bypassing of default game behavior that prevents the use of [SET_PED_DRIVE_BY_CLIPSET_OVERRIDE](#_0xED34AB6C5CB36520) in certain scenarios to avoid clipping issues (e.g., when there is more than one Ped in a vehicle).

Note: This flag and the overridden clipset are not replicated values and require synchronization through user scripts. Additionally, current game behavior also restricts applying this clipset locally when in first-person mode and will require a temporary workaround.

## Parameters
* **flag**: true to override, false to use default game behavior.