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(); }