Skip to content

Commit

Permalink
Call shutdown on monkeys that fail to run
Browse files Browse the repository at this point in the history
  • Loading branch information
Banane9 committed Nov 22, 2024
1 parent ed753c8 commit 66b6b2b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
11 changes: 10 additions & 1 deletion MonkeyLoader/MonkeyLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,8 @@ public void LoadMonkeys(IEnumerable<Mod> mods)
/// </summary>
public void LogPotentialConflicts()
{
Logger.Info(() => "Looking for potentially conflicting Harmony patches!");

foreach (var patchedMethod in Harmony.GetAllPatchedMethods())
{
var patches = Harmony.GetPatchInfo(patchedMethod);
Expand Down Expand Up @@ -752,7 +754,14 @@ public void RunMonkeys(IEnumerable<Mod> 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!");

Expand Down
14 changes: 11 additions & 3 deletions MonkeyLoader/Patching/Monkey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ public override sealed bool Run()
Failed = true;
Logger.Warn(() => "OnLoaded failed!");
}

LogPatches();
}
catch (Exception ex)
{
Failed = true;
Logger.Error(ex.LogFormat("OnLoaded threw an Exception:"));
}

LogPatches();

return !Failed;
}

Expand All @@ -124,8 +124,16 @@ public override sealed bool Run()
/// </summary>
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));
}

/// <summary>
Expand Down

0 comments on commit 66b6b2b

Please sign in to comment.