summaryrefslogtreecommitdiff
path: root/src/SMAPI.Mods.ErrorHandler/ModEntry.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-08-01 13:11:51 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-08-01 13:11:51 -0400
commit5b31be76dd90711ff475341de8dfdb6e1f50b98a (patch)
treee120bc62af72e94e8e924ba124382d0c6f9304de /src/SMAPI.Mods.ErrorHandler/ModEntry.cs
parent8f96a97f070d654764de3b138678d8f62707f485 (diff)
parentd688cdf8c3c852d4b11cdd046d67c4b35443cc95 (diff)
downloadSMAPI-5b31be76dd90711ff475341de8dfdb6e1f50b98a.tar.gz
SMAPI-5b31be76dd90711ff475341de8dfdb6e1f50b98a.tar.bz2
SMAPI-5b31be76dd90711ff475341de8dfdb6e1f50b98a.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI.Mods.ErrorHandler/ModEntry.cs')
-rw-r--r--src/SMAPI.Mods.ErrorHandler/ModEntry.cs40
1 files changed, 23 insertions, 17 deletions
diff --git a/src/SMAPI.Mods.ErrorHandler/ModEntry.cs b/src/SMAPI.Mods.ErrorHandler/ModEntry.cs
index d9426d75..067f6a8d 100644
--- a/src/SMAPI.Mods.ErrorHandler/ModEntry.cs
+++ b/src/SMAPI.Mods.ErrorHandler/ModEntry.cs
@@ -1,8 +1,7 @@
+using System;
using System.Reflection;
using StardewModdingAPI.Events;
-using StardewModdingAPI.Framework;
-using StardewModdingAPI.Framework.Logging;
-using StardewModdingAPI.Framework.Patching;
+using StardewModdingAPI.Internal.Patching;
using StardewModdingAPI.Mods.ErrorHandler.Patches;
using StardewValley;
@@ -29,15 +28,17 @@ namespace StardewModdingAPI.Mods.ErrorHandler
IMonitor monitorForGame = this.GetMonitorForGame();
// apply patches
- new GamePatcher(this.Monitor).Apply(
- new DialogueErrorPatch(monitorForGame, this.Helper.Reflection),
- new EventPatches(monitorForGame),
- new GameLocationPatches(monitorForGame),
- new ObjectErrorPatch(),
- new LoadErrorPatch(this.Monitor, this.OnSaveContentRemoved),
- new ScheduleErrorPatch(monitorForGame),
- new SpriteBatchValidationPatches(),
- new UtilityErrorPatches()
+ HarmonyPatcher.Apply(this.ModManifest.UniqueID, this.Monitor,
+ new DialoguePatcher(monitorForGame, this.Helper.Reflection),
+ new DictionaryPatcher(this.Helper.Reflection),
+ new EventPatcher(monitorForGame),
+ new GameLocationPatcher(monitorForGame),
+ new IClickableMenuPatcher(),
+ new NpcPatcher(monitorForGame),
+ new ObjectPatcher(),
+ new SaveGamePatcher(this.Monitor, this.OnSaveContentRemoved),
+ new SpriteBatchPatcher(),
+ new UtilityPatcher()
);
// hook events
@@ -70,12 +71,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;
}
}
}