From 5a58e038549f85b88cbbaf0492391cc2ebeed680 Mon Sep 17 00:00:00 2001 From: Archangel Date: Mon, 18 Nov 2024 20:50:55 +0000 Subject: [PATCH] Add FixAirdropCrashPatch (!175) This fixes the current issue of having an airdrop in the game causing a CTD after an extract. There's still two caveats to this that I'm looking into: - On the very next raid, the sky will still have the chaff from the flares in the sky, however these will have pink textures and take a few seconds to dissipate. - On the very next raid, calling in an airplane with a red flare will cause the notification manager to spam messages about the airspace being currently in use even at the start of the raid. Reviewed-on: https://dev.sp-tarkov.com/SPT/Modules/pulls/175 Co-authored-by: Archangel Co-committed-by: Archangel --- .../Patches/FixAirdropCrashPatch.cs | 42 +++++++++++++++++++ project/SPT.Custom/SPTCustomPlugin.cs | 3 +- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 project/SPT.Custom/Patches/FixAirdropCrashPatch.cs diff --git a/project/SPT.Custom/Patches/FixAirdropCrashPatch.cs b/project/SPT.Custom/Patches/FixAirdropCrashPatch.cs new file mode 100644 index 0000000..e07e8c1 --- /dev/null +++ b/project/SPT.Custom/Patches/FixAirdropCrashPatch.cs @@ -0,0 +1,42 @@ +using EFT.SynchronizableObjects; +using EFT; +using HarmonyLib; +using SPT.Reflection.Patching; +using System.Collections.Generic; +using System.Reflection; +using Comfort.Common; + +namespace SPT.Custom.Patches +{ + /// + /// This patch prevents the crashing that was caused by the airdrop since the mortar event, it fully unloads whatever synchronized objects + /// Are still loaded before unused resources are cleaned up (Which causes this crash) + /// + public class FixAirdropCrashPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return typeof(TarkovApplication).GetMethod(nameof(TarkovApplication.method_48)); + } + + [PatchPrefix] + public static void Prefix() + { + if (Singleton.Instantiated) + { + GameWorld gameWorld = Singleton.Instance; + + List synchronizableObjectList = Traverse.Create(gameWorld.SynchronizableObjectLogicProcessor).Field>("list_0").Value; + + foreach (SynchronizableObject obj in synchronizableObjectList) + { + obj.Logic.ReturnToPool(); + obj.ReturnToPool(); + } + + gameWorld.SynchronizableObjectLogicProcessor.Dispose(); + + } + } + } +} diff --git a/project/SPT.Custom/SPTCustomPlugin.cs b/project/SPT.Custom/SPTCustomPlugin.cs index 7160a4d..22f3674 100644 --- a/project/SPT.Custom/SPTCustomPlugin.cs +++ b/project/SPT.Custom/SPTCustomPlugin.cs @@ -40,7 +40,8 @@ namespace SPT.Custom new MergeScavPmcQuestsOnInventoryLoadPatch().Enable(); new CopyPmcQuestsToPlayerScavPatch().Enable(); new FixBossesHavingNoFollowersOnMediumAiAmount().Enable(); - //new AllowAirdropsInPvEPatch().Enable(); + new FixAirdropCrashPatch().Enable(); + //new AllowAirdropsInPvEPatch().Enable(); HookObject.AddOrGetComponent(); }