From 1c67801d797c80414af1f8c2a82edb20a049e751 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Thu, 18 Nov 2021 16:00:51 +0000 Subject: [PATCH] fix not being able to open map after dying --- QSB/DeathSync/Events/EndLoopEvent.cs | 3 +++ QSB/Patches/QSBPatchManager.cs | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/QSB/DeathSync/Events/EndLoopEvent.cs b/QSB/DeathSync/Events/EndLoopEvent.cs index 0208c4ea..17ed544d 100644 --- a/QSB/DeathSync/Events/EndLoopEvent.cs +++ b/QSB/DeathSync/Events/EndLoopEvent.cs @@ -1,6 +1,7 @@ using QSB.ClientServerStateSync; using QSB.Events; using QSB.Messaging; +using QSB.Patches; using QSB.Utility; namespace QSB.DeathSync.Events @@ -29,6 +30,8 @@ namespace QSB.DeathSync.Events switch (message.EnumValue) { case EndLoopReason.AllPlayersDead: + QSBPatchManager.DoUnpatchType(QSBPatchTypes.RespawnTime); + Locator.GetDeathManager().KillPlayer(DeathType.TimeLoop); if (QSBCore.IsHost) { diff --git a/QSB/Patches/QSBPatchManager.cs b/QSB/Patches/QSBPatchManager.cs index 0734fa55..00c64c64 100644 --- a/QSB/Patches/QSBPatchManager.cs +++ b/QSB/Patches/QSBPatchManager.cs @@ -37,6 +37,7 @@ namespace QSB.Patches public static event Action OnUnpatchType; private static List _patchList = new List(); + private static List _patchedTypes = new List(); public static Dictionary TypeToInstance = new Dictionary(); @@ -88,6 +89,12 @@ namespace QSB.Patches public static void DoPatchType(QSBPatchTypes type) { + if (_patchedTypes.Contains(type)) + { + DebugLog.ToConsole($"Warning - Tried to patch type {type}, when it has already been patched!", MessageType.Warning); + return; + } + OnPatchType?.SafeInvoke(type); //DebugLog.DebugWrite($"Patch block {Enum.GetName(typeof(QSBPatchTypes), type)}", MessageType.Info); foreach (var patch in _patchList.Where(x => x.Type == type)) @@ -96,6 +103,7 @@ namespace QSB.Patches try { patch.DoPatches(TypeToInstance[type]); + _patchedTypes.Add(type); } catch (Exception ex) { @@ -106,9 +114,16 @@ namespace QSB.Patches public static void DoUnpatchType(QSBPatchTypes type) { + if (!_patchedTypes.Contains(type)) + { + DebugLog.ToConsole($"Warning - Tried to unpatch type {type}, when it is either unpatched or was never patched.", MessageType.Warning); + return; + } + OnUnpatchType?.SafeInvoke(type); //DebugLog.DebugWrite($"Unpatch block {Enum.GetName(typeof(QSBPatchTypes), type)}", MessageType.Info); TypeToInstance[type].UnpatchSelf(); + _patchedTypes.Remove(type); } } }