From 62a5960474f5b3e634a382709534342560e81cbb Mon Sep 17 00:00:00 2001 From: Disquse Date: Thu, 15 Feb 2024 17:20:00 +0300 Subject: [PATCH 1/2] fix(extra-natives/five): reset "can stand on vehicles" flag and map --- .../extra-natives-five/src/VehicleExtraNatives.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/code/components/extra-natives-five/src/VehicleExtraNatives.cpp b/code/components/extra-natives-five/src/VehicleExtraNatives.cpp index c6bbd411cb..581cd16894 100644 --- a/code/components/extra-natives-five/src/VehicleExtraNatives.cpp +++ b/code/components/extra-natives-five/src/VehicleExtraNatives.cpp @@ -1375,10 +1375,15 @@ static HookFunction initFunction([]() OnKillNetworkDone.Connect([]() { - g_skipRepairVehicles.clear(); ResetFlyThroughWindscreenParams(); + *g_trainsForceDoorsOpen = true; + + g_skipRepairVehicles.clear(); + g_canPedStandOnVehicles.clear(); + g_overrideUseDefaultDriveByClipset = false; + g_overrideCanPedStandOnVehicle = false; }); fx::ScriptEngine::RegisterNativeHandler("SET_VEHICLE_AUTO_REPAIR_DISABLED", [](fx::ScriptContext& context) From 16a085ecfc3690be370a62be798de0ff672176bf Mon Sep 17 00:00:00 2001 From: Disquse Date: Thu, 15 Feb 2024 17:20:37 +0300 Subject: [PATCH 2/2] tweak(extra-natives/five): use `getAndCheckVehicle` to avoid code duplication Some natives weren't checking if the entity was valid (not nullptr). --- .../src/VehicleExtraNatives.cpp | 37 +++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/code/components/extra-natives-five/src/VehicleExtraNatives.cpp b/code/components/extra-natives-five/src/VehicleExtraNatives.cpp index 581cd16894..66c9e554be 100644 --- a/code/components/extra-natives-five/src/VehicleExtraNatives.cpp +++ b/code/components/extra-natives-five/src/VehicleExtraNatives.cpp @@ -1388,27 +1388,24 @@ static HookFunction initFunction([]() fx::ScriptEngine::RegisterNativeHandler("SET_VEHICLE_AUTO_REPAIR_DISABLED", [](fx::ScriptContext& context) { - auto vehHandle = context.GetArgument(0); - auto shouldDisable = context.GetArgument(1); - - fwEntity* entity = rage::fwScriptGuid::GetBaseFromGuid(vehHandle); - - if (shouldDisable) + if (fwEntity* entity = getAndCheckVehicle(context, "SET_VEHICLE_AUTO_REPAIR_DISABLED")) { - g_skipRepairVehicles.insert(entity); - } - else - { - g_skipRepairVehicles.erase(entity); + auto shouldDisable = context.GetArgument(1); + + if (shouldDisable) + { + g_skipRepairVehicles.insert(entity); + } + else + { + g_skipRepairVehicles.erase(entity); + } } }); fx::ScriptEngine::RegisterNativeHandler("ADD_VEHICLE_DELETION_TRACE", [](fx::ScriptContext& context) { - auto vehHandle = context.GetArgument(0); - fwEntity* entity = rage::fwScriptGuid::GetBaseFromGuid(vehHandle); - - if (entity->IsOfType()) + if (fwEntity* entity = getAndCheckVehicle(context, "ADD_VEHICLE_DELETION_TRACE")) { g_deletionTraces.insert(entity); g_deletionTraces2.insert(entity); @@ -1417,10 +1414,7 @@ static HookFunction initFunction([]() fx::ScriptEngine::RegisterNativeHandler("OVERRIDE_VEHICLE_PEDS_CAN_STAND_ON_TOP_FLAG", [](fx::ScriptContext& context) { - auto vehHandle = context.GetArgument(0); - fwEntity* entity = rage::fwScriptGuid::GetBaseFromGuid(vehHandle); - - if (entity->IsOfType()) + if (fwEntity* entity = getAndCheckVehicle(context, "OVERRIDE_VEHICLE_PEDS_CAN_STAND_ON_TOP_FLAG")) { bool can = context.GetArgument(1); SetCanPedStandOnVehicle(entity, can ? 1 : -1); @@ -1429,10 +1423,7 @@ static HookFunction initFunction([]() fx::ScriptEngine::RegisterNativeHandler("RESET_VEHICLE_PEDS_CAN_STAND_ON_TOP_FLAG", [](fx::ScriptContext& context) { - auto vehHandle = context.GetArgument(0); - fwEntity* entity = rage::fwScriptGuid::GetBaseFromGuid(vehHandle); - - if (entity->IsOfType()) + if (fwEntity* entity = getAndCheckVehicle(context, "RESET_VEHICLE_PEDS_CAN_STAND_ON_TOP_FLAG")) { SetCanPedStandOnVehicle(entity, 0); }