From ae871fff33e123935a769e1ad0e375b2384c1ecc Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Tue, 9 Feb 2021 17:18:01 +0000 Subject: [PATCH] unpatching, stuff --- .../Patches/ConversationPatches.cs | 10 ++++++++++ QSB/DeathSync/Patches/DeathPatches.cs | 10 ++++++++++ QSB/ElevatorSync/Patches/ElevatorPatches.cs | 2 ++ QSB/FrequencySync/Patches/FrequencyPatches.cs | 6 ++++++ QSB/LogSync/Patches/LogPatches.cs | 2 ++ QSB/OrbSync/Patches/OrbPatches.cs | 6 ++++++ QSB/Patches/QSBPatch.cs | 1 + QSB/Patches/QSBPatchManager.cs | 12 ++++++++++++ QSB/Player/QSBPlayerManager.cs | 15 +++++++++++++-- QSB/QSBNetworkManager.cs | 6 ++++++ QSB/QuantumSync/Patches/ClientQuantumPatches.cs | 1 + QSB/QuantumSync/Patches/QuantumPatches.cs | 16 +++++++++++++--- .../Patches/QuantumVisibilityPatches.cs | 8 ++++++++ QSB/QuantumSync/Patches/ServerQuantumPatches.cs | 6 ++++++ QSB/TimeSync/Patches/WakeUpPatches.cs | 2 ++ QSB/TranslationSync/Patches/SpiralPatches.cs | 7 +++++++ QuantumUNET/Components/QNetworkManager.cs | 2 +- 17 files changed, 106 insertions(+), 6 deletions(-) diff --git a/QSB/ConversationSync/Patches/ConversationPatches.cs b/QSB/ConversationSync/Patches/ConversationPatches.cs index 25000aad..c658df47 100644 --- a/QSB/ConversationSync/Patches/ConversationPatches.cs +++ b/QSB/ConversationSync/Patches/ConversationPatches.cs @@ -102,5 +102,15 @@ namespace QSB.ConversationSync.Patches QSBCore.Helper.HarmonyHelper.AddPrefix("OnAnimatorIK", typeof(ConversationPatches), nameof(OnAnimatorIK)); QSBCore.Helper.HarmonyHelper.AddPrefix("OnZoneExit", typeof(ConversationPatches), nameof(OnZoneExit)); } + + public override void DoUnpatches() + { + QSBCore.Helper.HarmonyHelper.Unpatch("GetNextPage"); + QSBCore.Helper.HarmonyHelper.Unpatch("InputDialogueOption"); + QSBCore.Helper.HarmonyHelper.Unpatch("StartConversation"); + QSBCore.Helper.HarmonyHelper.Unpatch("EndConversation"); + QSBCore.Helper.HarmonyHelper.Unpatch("OnAnimatorIK"); + QSBCore.Helper.HarmonyHelper.Unpatch("OnZoneExit"); + } } } \ No newline at end of file diff --git a/QSB/DeathSync/Patches/DeathPatches.cs b/QSB/DeathSync/Patches/DeathPatches.cs index 43291e8f..7c416271 100644 --- a/QSB/DeathSync/Patches/DeathPatches.cs +++ b/QSB/DeathSync/Patches/DeathPatches.cs @@ -22,6 +22,16 @@ namespace QSB.DeathSync.Patches QSBCore.Helper.HarmonyHelper.AddPrefix("VanishShip", typeof(DeathPatches), nameof(DestructionVolume_VanishShip)); } + public override void DoUnpatches() + { + QSBCore.Helper.HarmonyHelper.Unpatch("KillPlayer"); + QSBCore.Helper.HarmonyHelper.Unpatch("Detach"); + QSBCore.Helper.HarmonyHelper.Unpatch("Detach"); + QSBCore.Helper.HarmonyHelper.Unpatch("OnPressInteract"); + QSBCore.Helper.HarmonyHelper.Unpatch("Awake"); + QSBCore.Helper.HarmonyHelper.Unpatch("VanishShip"); + } + public static bool PreFinishDeathSequence(DeathType deathType) { if (RespawnOnDeath.Instance == null) diff --git a/QSB/ElevatorSync/Patches/ElevatorPatches.cs b/QSB/ElevatorSync/Patches/ElevatorPatches.cs index 68282131..c28eff48 100644 --- a/QSB/ElevatorSync/Patches/ElevatorPatches.cs +++ b/QSB/ElevatorSync/Patches/ElevatorPatches.cs @@ -16,5 +16,7 @@ namespace QSB.ElevatorSync.Patches } public override void DoPatches() => QSBCore.Helper.HarmonyHelper.AddPostfix("StartLift", typeof(ElevatorPatches), nameof(StartLift)); + + public override void DoUnpatches() => QSBCore.Helper.HarmonyHelper.Unpatch("StartLift"); } } \ No newline at end of file diff --git a/QSB/FrequencySync/Patches/FrequencyPatches.cs b/QSB/FrequencySync/Patches/FrequencyPatches.cs index ad18b82b..5f1f9744 100644 --- a/QSB/FrequencySync/Patches/FrequencyPatches.cs +++ b/QSB/FrequencySync/Patches/FrequencyPatches.cs @@ -13,6 +13,12 @@ namespace QSB.FrequencySync.Patches QSBCore.Helper.HarmonyHelper.AddPostfix("IdentifySignal", typeof(FrequencyPatches), nameof(IdentifySignal)); } + public override void DoUnpatches() + { + QSBCore.Helper.HarmonyHelper.Unpatch("IdentifyFrequency"); + QSBCore.Helper.HarmonyHelper.Unpatch("IdentifySignal"); + } + public static void IdentifyFrequency(SignalFrequency ____frequency) => GlobalMessenger.FireEvent(EventNames.QSBIdentifyFrequency, ____frequency); diff --git a/QSB/LogSync/Patches/LogPatches.cs b/QSB/LogSync/Patches/LogPatches.cs index de402315..319c6d96 100644 --- a/QSB/LogSync/Patches/LogPatches.cs +++ b/QSB/LogSync/Patches/LogPatches.cs @@ -17,5 +17,7 @@ namespace QSB.LogSync.Patches } public override void DoPatches() => QSBCore.Helper.HarmonyHelper.AddPostfix("RevealFact", typeof(LogPatches), nameof(RevealFact)); + + public override void DoUnpatches() => QSBCore.Helper.HarmonyHelper.Unpatch("RevealFact"); } } \ No newline at end of file diff --git a/QSB/OrbSync/Patches/OrbPatches.cs b/QSB/OrbSync/Patches/OrbPatches.cs index 967c90dc..7eeef78c 100644 --- a/QSB/OrbSync/Patches/OrbPatches.cs +++ b/QSB/OrbSync/Patches/OrbPatches.cs @@ -60,5 +60,11 @@ namespace QSB.OrbSync.Patches QSBCore.Helper.HarmonyHelper.AddPostfix("StartDragFromPosition", typeof(OrbPatches), nameof(StartDragCallEvent)); QSBCore.Helper.HarmonyHelper.AddPrefix("CheckOrbCollision", typeof(OrbPatches), nameof(CheckOrbCollision)); } + + public override void DoUnpatches() + { + QSBCore.Helper.HarmonyHelper.Unpatch("StartDragFromPosition"); + QSBCore.Helper.HarmonyHelper.Unpatch("CheckOrbCollision"); + } } } \ No newline at end of file diff --git a/QSB/Patches/QSBPatch.cs b/QSB/Patches/QSBPatch.cs index 4f118b80..bd9a93e0 100644 --- a/QSB/Patches/QSBPatch.cs +++ b/QSB/Patches/QSBPatch.cs @@ -4,5 +4,6 @@ { public abstract QSBPatchTypes Type { get; } public abstract void DoPatches(); + public abstract void DoUnpatches(); } } \ No newline at end of file diff --git a/QSB/Patches/QSBPatchManager.cs b/QSB/Patches/QSBPatchManager.cs index d5e871e8..480126fb 100644 --- a/QSB/Patches/QSBPatchManager.cs +++ b/QSB/Patches/QSBPatchManager.cs @@ -18,6 +18,7 @@ namespace QSB.Patches public static class QSBPatchManager { public static event Action OnPatchType; + public static event Action OnUnpatchType; private static List _patchList = new List(); @@ -52,5 +53,16 @@ namespace QSB.Patches patch.DoPatches(); } } + + public static void DoUnpatchType(QSBPatchTypes type) + { + OnUnpatchType?.SafeInvoke(type); + DebugLog.DebugWrite($"Unpatch block {Enum.GetName(typeof(QSBPatchTypes), type)}", MessageType.Info); + foreach (var patch in _patchList.Where(x => x.Type == type)) + { + DebugLog.DebugWrite($" - Unpatching in {patch.GetType().Name}", MessageType.Info); + patch.DoUnpatches(); + } + } } } \ No newline at end of file diff --git a/QSB/Player/QSBPlayerManager.cs b/QSB/Player/QSBPlayerManager.cs index 119c49c2..1a5f4d3c 100644 --- a/QSB/Player/QSBPlayerManager.cs +++ b/QSB/Player/QSBPlayerManager.cs @@ -3,7 +3,9 @@ using QSB.Player.Events; using QSB.Tools; using QSB.TransformSync; using QSB.Utility; +using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; namespace QSB.Player @@ -18,6 +20,13 @@ namespace QSB.Player public static PlayerInfo GetPlayer(uint id) { + if (!QSBNetworkManager.Instance.IsReady) + { + var method = new StackTrace().GetFrame(1).GetMethod(); + DebugLog.DebugWrite($"Warning - GetPlayer() (id<{id}>) called when Network Manager not ready! Is a Player Sync Object still active? " + + $"{Environment.NewLine} Called from {method.DeclaringType.Name}.{method.Name}", MessageType.Warning); + } + if (id == uint.MaxValue || id == 0U) { return default; @@ -27,7 +36,8 @@ namespace QSB.Player { return player; } - DebugLog.DebugWrite($"Create Player : id<{id}>", MessageType.Info); + var trace = new StackTrace().GetFrame(1).GetMethod(); + DebugLog.DebugWrite($"Create Player : id<{id}> (Called from {trace.DeclaringType.Name}.{trace.Name})", MessageType.Info); player = new PlayerInfo(id); PlayerList.Add(player); return player; @@ -35,7 +45,8 @@ namespace QSB.Player public static void RemovePlayer(uint id) { - DebugLog.DebugWrite($"Remove Player : id<{id}>", MessageType.Info); + var trace = new StackTrace().GetFrame(1).GetMethod(); + DebugLog.DebugWrite($"Remove Player : id<{id}> (Called from {trace.DeclaringType.Name}.{trace.Name})", MessageType.Info); PlayerList.Remove(GetPlayer(id)); } diff --git a/QSB/QSBNetworkManager.cs b/QSB/QSBNetworkManager.cs index 38996d18..cf18997a 100644 --- a/QSB/QSBNetworkManager.cs +++ b/QSB/QSBNetworkManager.cs @@ -215,7 +215,13 @@ namespace QSB QSBWorldSync.OrbSyncList.Clear(); QSBWorldSync.OldDialogueTrees.Clear(); + var specificType = QNetworkServer.active ? QSBPatchTypes.OnServerClientConnect : QSBPatchTypes.OnNonServerClientConnect; + QSBPatchManager.DoUnpatchType(specificType); + QSBPatchManager.DoUnpatchType(QSBPatchTypes.OnClientConnect); + _lobby.CanEditName = true; + + IsReady = false; } public override void OnServerDisconnect(QNetworkConnection connection) // Called on the server when any client disconnects diff --git a/QSB/QuantumSync/Patches/ClientQuantumPatches.cs b/QSB/QuantumSync/Patches/ClientQuantumPatches.cs index 1bafdb7b..55b087bc 100644 --- a/QSB/QuantumSync/Patches/ClientQuantumPatches.cs +++ b/QSB/QuantumSync/Patches/ClientQuantumPatches.cs @@ -7,6 +7,7 @@ namespace QSB.QuantumSync.Patches public override QSBPatchTypes Type => QSBPatchTypes.OnNonServerClientConnect; public override void DoPatches() => QSBCore.Helper.HarmonyHelper.AddPrefix("ChangeQuantumState", typeof(ClientQuantumPatches), nameof(ReturnFalsePatch)); + public override void DoUnpatches() => QSBCore.Helper.HarmonyHelper.Unpatch("ChangeQuantumState"); public static bool ReturnFalsePatch() => false; } diff --git a/QSB/QuantumSync/Patches/QuantumPatches.cs b/QSB/QuantumSync/Patches/QuantumPatches.cs index 10dfd86e..8e35d36a 100644 --- a/QSB/QuantumSync/Patches/QuantumPatches.cs +++ b/QSB/QuantumSync/Patches/QuantumPatches.cs @@ -19,18 +19,28 @@ namespace QSB.QuantumSync.Patches { QSBCore.Helper.HarmonyHelper.AddPrefix("ChangeQuantumState", typeof(QuantumPatches), nameof(Socketed_ChangeQuantumState)); QSBCore.Helper.HarmonyHelper.AddPostfix("MoveToSocket", typeof(QuantumPatches), nameof(Socketed_MoveToSocket)); - QSBCore.Helper.HarmonyHelper.AddPrefix("ChangeQuantumState", typeof(QuantumPatches), nameof(Shuffle_ChangeQuantumState)); - QSBCore.Helper.HarmonyHelper.AddPrefix("ChangeQuantumState", typeof(QuantumPatches), nameof(MultiState_ChangeQuantumState)); QSBCore.Helper.HarmonyHelper.AddPostfix("SetVisible", typeof(QuantumPatches), nameof(QuantumState_SetVisible)); - QSBCore.Helper.HarmonyHelper.AddPrefix("IsPlayerInDarkness", typeof(QuantumPatches), nameof(Shrine_IsPlayerInDarkness)); QSBCore.Helper.HarmonyHelper.AddPrefix("ChangeQuantumState", typeof(QuantumPatches), nameof(Shrine_ChangeQuantumState)); QSBCore.Helper.HarmonyHelper.AddPrefix("OnEntry", typeof(QuantumPatches), nameof(Shrine_OnEntry)); QSBCore.Helper.HarmonyHelper.AddPrefix("OnExit", typeof(QuantumPatches), nameof(Shrine_OnExit)); } + public override void DoUnpatches() + { + QSBCore.Helper.HarmonyHelper.Unpatch("ChangeQuantumState"); + QSBCore.Helper.HarmonyHelper.Unpatch("MoveToSocket"); + QSBCore.Helper.HarmonyHelper.Unpatch("ChangeQuantumState"); + QSBCore.Helper.HarmonyHelper.Unpatch("ChangeQuantumState"); + QSBCore.Helper.HarmonyHelper.Unpatch("SetVisible"); + QSBCore.Helper.HarmonyHelper.Unpatch("IsPlayerInDarkness"); + QSBCore.Helper.HarmonyHelper.Unpatch("ChangeQuantumState"); + QSBCore.Helper.HarmonyHelper.Unpatch("OnEntry"); + QSBCore.Helper.HarmonyHelper.Unpatch("OnExit"); + } + public static bool Socketed_ChangeQuantumState(SocketedQuantumObject __instance) => QSBWorldSync.GetWorldObject(QuantumManager.Instance.GetId(__instance)).ControllingPlayer == QSBPlayerManager.LocalPlayerId; diff --git a/QSB/QuantumSync/Patches/QuantumVisibilityPatches.cs b/QSB/QuantumSync/Patches/QuantumVisibilityPatches.cs index e0050a24..2954d5cb 100644 --- a/QSB/QuantumSync/Patches/QuantumVisibilityPatches.cs +++ b/QSB/QuantumSync/Patches/QuantumVisibilityPatches.cs @@ -18,6 +18,14 @@ namespace QSB.QuantumSync.Patches QSBCore.Helper.HarmonyHelper.AddPrefix("CheckIllumination", typeof(QuantumVisibilityPatches), nameof(CheckIllumination)); } + public override void DoUnpatches() + { + QSBCore.Helper.HarmonyHelper.Unpatch("IsVisibleUsingCameraFrustum"); + QSBCore.Helper.HarmonyHelper.Unpatch("IsVisible"); + QSBCore.Helper.HarmonyHelper.Unpatch("IsVisibleUsingCameraFrustum"); + QSBCore.Helper.HarmonyHelper.Unpatch("CheckIllumination"); + } + // ShapeVisibilityTracker patches public static bool ShapeIsVisibleUsingCameraFrustum(ShapeVisibilityTracker __instance, ref bool __result) diff --git a/QSB/QuantumSync/Patches/ServerQuantumPatches.cs b/QSB/QuantumSync/Patches/ServerQuantumPatches.cs index 38fd190c..77b6ad92 100644 --- a/QSB/QuantumSync/Patches/ServerQuantumPatches.cs +++ b/QSB/QuantumSync/Patches/ServerQuantumPatches.cs @@ -18,6 +18,12 @@ namespace QSB.QuantumSync.Patches QSBCore.Helper.HarmonyHelper.AddPrefix("CheckPlayerFogProximity", typeof(ServerQuantumPatches), nameof(Moon_CheckPlayerFogProximity)); } + public override void DoUnpatches() + { + QSBCore.Helper.HarmonyHelper.Unpatch("ChangeQuantumState"); + QSBCore.Helper.HarmonyHelper.Unpatch("CheckPlayerFogProximity"); + } + public static bool Moon_ChangeQuantumState( QuantumMoon __instance, ref bool __result, diff --git a/QSB/TimeSync/Patches/WakeUpPatches.cs b/QSB/TimeSync/Patches/WakeUpPatches.cs index b73bc4b1..d277599d 100644 --- a/QSB/TimeSync/Patches/WakeUpPatches.cs +++ b/QSB/TimeSync/Patches/WakeUpPatches.cs @@ -17,5 +17,7 @@ namespace QSB.TimeSync.Patches } public override void DoPatches() => QSBCore.Helper.HarmonyHelper.AddPrefix("OnStartOfTimeLoop", typeof(WakeUpPatches), nameof(OnStartOfTimeLoopPrefix)); + + public override void DoUnpatches() => QSBCore.Helper.HarmonyHelper.Unpatch("OnStartOfTimeLoop"); } } \ No newline at end of file diff --git a/QSB/TranslationSync/Patches/SpiralPatches.cs b/QSB/TranslationSync/Patches/SpiralPatches.cs index 98f5ab88..7a8fef3a 100644 --- a/QSB/TranslationSync/Patches/SpiralPatches.cs +++ b/QSB/TranslationSync/Patches/SpiralPatches.cs @@ -14,6 +14,13 @@ namespace QSB.TranslationSync.Patches QSBCore.Helper.HarmonyHelper.AddPrefix("SetAsTranslated", typeof(SpiralPatches), nameof(VesselComputer_SetAsTranslated)); } + public override void DoUnpatches() + { + QSBCore.Helper.HarmonyHelper.Unpatch("SetAsTranslated"); + QSBCore.Helper.HarmonyHelper.Unpatch("SetAsTranslated"); + QSBCore.Helper.HarmonyHelper.Unpatch("SetAsTranslated"); + } + public static bool Wall_SetAsTranslated(NomaiWallText __instance, int id) { if (__instance.IsTranslated(id)) diff --git a/QuantumUNET/Components/QNetworkManager.cs b/QuantumUNET/Components/QNetworkManager.cs index a56b8db9..ef85547d 100644 --- a/QuantumUNET/Components/QNetworkManager.cs +++ b/QuantumUNET/Components/QNetworkManager.cs @@ -353,8 +353,8 @@ namespace QuantumUNET.Components public void StopHost() { OnStopHost(); - StopServer(); StopClient(); + StopServer(); } public void StopServer()