From 66b6b2b372eaa636aedc43f1960e7f47211280b8 Mon Sep 17 00:00:00 2001 From: Arne Kiesewetter Date: Fri, 22 Nov 2024 21:05:51 +0100 Subject: [PATCH] Call shutdown on monkeys that fail to run --- MonkeyLoader/MonkeyLoader.cs | 11 ++++++++++- MonkeyLoader/Patching/Monkey.cs | 14 +++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/MonkeyLoader/MonkeyLoader.cs b/MonkeyLoader/MonkeyLoader.cs index fdd56da..19e08a4 100644 --- a/MonkeyLoader/MonkeyLoader.cs +++ b/MonkeyLoader/MonkeyLoader.cs @@ -620,6 +620,8 @@ public void LoadMonkeys(IEnumerable mods) /// public void LogPotentialConflicts() { + Logger.Info(() => "Looking for potentially conflicting Harmony patches!"); + foreach (var patchedMethod in Harmony.GetAllPatchedMethods()) { var patches = Harmony.GetPatchInfo(patchedMethod); @@ -752,7 +754,14 @@ public void RunMonkeys(IEnumerable mods) var sw = Stopwatch.StartNew(); foreach (var monkey in monkeys) - monkey.Run(); + { + if (monkey.Run()) + continue; + + Logger.Warn(() => "Monkey failed to run, letting it shut down!"); + + monkey.Shutdown(false); + } Logger.Info(() => $"Done running monkeys in {sw.ElapsedMilliseconds}ms!"); diff --git a/MonkeyLoader/Patching/Monkey.cs b/MonkeyLoader/Patching/Monkey.cs index 531afdb..7fbadb9 100644 --- a/MonkeyLoader/Patching/Monkey.cs +++ b/MonkeyLoader/Patching/Monkey.cs @@ -106,8 +106,6 @@ public override sealed bool Run() Failed = true; Logger.Warn(() => "OnLoaded failed!"); } - - LogPatches(); } catch (Exception ex) { @@ -115,6 +113,8 @@ public override sealed bool Run() Logger.Error(ex.LogFormat("OnLoaded threw an Exception:")); } + LogPatches(); + return !Failed; } @@ -124,8 +124,16 @@ public override sealed bool Run() /// protected void LogPatches() { + var patchedMethods = Harmony.GetPatchedMethods(); + + if (!patchedMethods.Any()) + { + Logger.Debug(() => "Did not patch any methods!"); + return; + } + Logger.Debug(() => "Patched the following methods:"); - Logger.Debug(Harmony.GetPatchedMethods().Select(GeneralExtensions.FullDescription)); + Logger.Debug(patchedMethods.Select(GeneralExtensions.FullDescription)); } ///