summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/SMAPI.Mods.ErrorHandler/ModEntry.cs27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/SMAPI.Mods.ErrorHandler/ModEntry.cs b/src/SMAPI.Mods.ErrorHandler/ModEntry.cs
index f543814e..e4bcc5bc 100644
--- a/src/SMAPI.Mods.ErrorHandler/ModEntry.cs
+++ b/src/SMAPI.Mods.ErrorHandler/ModEntry.cs
@@ -26,21 +26,15 @@ namespace StardewModdingAPI.Mods.ErrorHandler
public override void Entry(IModHelper helper)
{
// get SMAPI core types
- SCore core = SCore.Instance;
- LogManager logManager = core.GetType().GetField("LogManager", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(core) as LogManager;
- if (logManager == null)
- {
- this.Monitor.Log("Can't access SMAPI's internal log manager. Error-handling patches won't be applied.", LogLevel.Error);
- return;
- }
+ IMonitor monitorForGame = this.GetMonitorForGame();
// apply patches
new GamePatcher(this.Monitor).Apply(
- new EventErrorPatch(logManager.MonitorForGame),
- new DialogueErrorPatch(logManager.MonitorForGame, this.Helper.Reflection),
+ new EventErrorPatch(monitorForGame),
+ new DialogueErrorPatch(monitorForGame, this.Helper.Reflection),
new ObjectErrorPatch(),
new LoadErrorPatch(this.Monitor, this.OnSaveContentRemoved),
- new ScheduleErrorPatch(logManager.MonitorForGame),
+ new ScheduleErrorPatch(monitorForGame),
new UtilityErrorPatches()
);
@@ -61,7 +55,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler
/// <summary>The method invoked when a save is loaded.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
- public void OnSaveLoaded(object sender, SaveLoadedEventArgs e)
+ private void OnSaveLoaded(object sender, SaveLoadedEventArgs e)
{
// show in-game warning for removed save content
if (this.IsSaveContentRemoved)
@@ -70,5 +64,16 @@ namespace StardewModdingAPI.Mods.ErrorHandler
Game1.addHUDMessage(new HUDMessage(this.Helper.Translation.Get("warn.invalid-content-removed"), HUDMessage.error_type));
}
}
+
+ /// <summary>Get the monitor with which to log game errors.</summary>
+ private IMonitor GetMonitorForGame()
+ {
+ SCore core = SCore.Instance;
+ LogManager logManager = core.GetType().GetField("LogManager", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(core) as LogManager;
+ if (logManager == null)
+ this.Monitor.Log("Can't access SMAPI's internal log manager. Some game errors may be reported as being from Error Handler.", LogLevel.Error);
+
+ return logManager?.MonitorForGame ?? this.Monitor;
+ }
}
}