Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call shutdown on monkeys that fail to run #44

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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