summaryrefslogtreecommitdiff
path: root/src/SMAPI.Mods.ErrorHandler/ModEntry.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-07-29 22:50:50 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-07-29 22:50:50 -0400
commit737a434ad6704d22776f463c192b9a9748ce2a21 (patch)
tree87d3a3e27e44f36f2a17776efa6492f1d4dd7797 /src/SMAPI.Mods.ErrorHandler/ModEntry.cs
parent880cd7b8bacfcee2cc6a8e15b6b8ea5e05e9467c (diff)
downloadSMAPI-737a434ad6704d22776f463c192b9a9748ce2a21.tar.gz
SMAPI-737a434ad6704d22776f463c192b9a9748ce2a21.tar.bz2
SMAPI-737a434ad6704d22776f463c192b9a9748ce2a21.zip
reduce ErrorHandler's direct references to internal SMAPI code
That will allow removing the InternalsVisibleTo attribute to avoid namespace conflicts in an upcoming commit.
Diffstat (limited to 'src/SMAPI.Mods.ErrorHandler/ModEntry.cs')
-rw-r--r--src/SMAPI.Mods.ErrorHandler/ModEntry.cs16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/SMAPI.Mods.ErrorHandler/ModEntry.cs b/src/SMAPI.Mods.ErrorHandler/ModEntry.cs
index 719eddab..b1081218 100644
--- a/src/SMAPI.Mods.ErrorHandler/ModEntry.cs
+++ b/src/SMAPI.Mods.ErrorHandler/ModEntry.cs
@@ -1,3 +1,4 @@
+using System;
using System.Reflection;
using StardewModdingAPI.Events;
using StardewModdingAPI.Framework;
@@ -71,12 +72,17 @@ namespace StardewModdingAPI.Mods.ErrorHandler
/// <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);
+ // get SMAPI core
+ Type coreType = Type.GetType("StardewModdingAPI.Framework.SCore, StardewModdingAPI", throwOnError: false)
+ ?? throw new InvalidOperationException("Can't access SMAPI's core type. This mod may not work correctly.");
+ object core = coreType.GetProperty("Instance", BindingFlags.Static | BindingFlags.NonPublic)?.GetValue(null)
+ ?? throw new InvalidOperationException("Can't access SMAPI's core instance. This mod may not work correctly.");
- return logManager?.MonitorForGame ?? this.Monitor;
+ // get monitor
+ MethodInfo getMonitorForGame = coreType.GetMethod("GetMonitorForGame")
+ ?? throw new InvalidOperationException("Can't access the SMAPI's 'GetMonitorForGame' method. This mod may not work correctly.");
+
+ return (IMonitor)getMonitorForGame.Invoke(core, new object[0]) ?? this.Monitor;
}
}
}