From fa9e6ce35f3a8a2b8b8bc273fff2c996a8c1d67a Mon Sep 17 00:00:00 2001 From: Jesse Date: Mon, 25 Nov 2024 15:47:31 +0100 Subject: [PATCH] Add further fixes to the airdop (#2) * Fix airspace congested spam by disposing of the Server airdrop manager as well * Add patch to dispose of flares correctly * Spacing fixes --- .../Patches/FixAirdropCrashPatch.cs | 31 +++++++++-------- .../Patches/FixAirdropFlareDisposePatch.cs | 33 +++++++++++++++++++ project/SPT.Custom/SPTCustomPlugin.cs | 7 ++-- 3 files changed, 55 insertions(+), 16 deletions(-) create mode 100644 project/SPT.Custom/Patches/FixAirdropFlareDisposePatch.cs diff --git a/project/SPT.Custom/Patches/FixAirdropCrashPatch.cs b/project/SPT.Custom/Patches/FixAirdropCrashPatch.cs index 73fafad..f103d61 100644 --- a/project/SPT.Custom/Patches/FixAirdropCrashPatch.cs +++ b/project/SPT.Custom/Patches/FixAirdropCrashPatch.cs @@ -8,19 +8,19 @@ 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)); - } + /// + /// 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() + [PatchPrefix] + public static void Prefix() { if (!Singleton.Instantiated) { @@ -48,8 +48,13 @@ namespace SPT.Custom.Patches // Without this check can cause black screen when backing out of raid prior to airdrop manager being init if (gameWorld.SynchronizableObjectLogicProcessor.AirdropManager is not null) { + if (gameWorld.SynchronizableObjectLogicProcessor is SynchronizableObjectLogicProcessorClass synchronizableObjectLogicProcessorClass) + { + synchronizableObjectLogicProcessorClass.ServerAirdropManager.Dispose(); + } + gameWorld.SynchronizableObjectLogicProcessor.Dispose(); } } - } + } } diff --git a/project/SPT.Custom/Patches/FixAirdropFlareDisposePatch.cs b/project/SPT.Custom/Patches/FixAirdropFlareDisposePatch.cs new file mode 100644 index 0000000..bf64dba --- /dev/null +++ b/project/SPT.Custom/Patches/FixAirdropFlareDisposePatch.cs @@ -0,0 +1,33 @@ +using SPT.Reflection.Patching; +using System.Collections.Generic; +using System.Reflection; +using UnityEngine; + +namespace SPT.Custom.Patches +{ + /// + /// This patch prevents the weird pink smoke / flares that are still in the sky the next raid if a player has just extracted + /// while the airplane is dropping a crate + /// + public class FixAirdropFlareDisposePatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return typeof(GClass2408).GetMethod(nameof(GClass2408.Dispose)); + } + + [PatchPrefix] + public static void Prefix(Dictionary ___dictionary_0) + { + if (___dictionary_0 == null) + { + return; + } + + foreach (KeyValuePair keyValuePair in ___dictionary_0) + { + Object.Destroy(keyValuePair.Key); + } + } + } +} diff --git a/project/SPT.Custom/SPTCustomPlugin.cs b/project/SPT.Custom/SPTCustomPlugin.cs index 3a19ade..cdbe860 100644 --- a/project/SPT.Custom/SPTCustomPlugin.cs +++ b/project/SPT.Custom/SPTCustomPlugin.cs @@ -38,14 +38,15 @@ namespace SPT.Custom new BotDifficultyPatch().Enable(); new VersionLabelPatch().Enable(); new FixScavWarNullErrorWithMarkOfUnknownPatch().Enable(); - new MergeScavPmcQuestsOnInventoryLoadPatch().Enable(); + new MergeScavPmcQuestsOnInventoryLoadPatch().Enable(); new CopyPmcQuestsToPlayerScavPatch().Enable(); new FixBossesHavingNoFollowersOnMediumAiAmount().Enable(); new FixAirdropCrashPatch().Enable(); - //new AllowAirdropsInPvEPatch().Enable(); + new FixAirdropFlareDisposePatch().Enable(); + //new AllowAirdropsInPvEPatch().Enable(); new MemoryCollectionPatch().Enable(); - HookObject.AddOrGetComponent(); + HookObject.AddOrGetComponent(); } catch (Exception ex) {