using System; using System.Diagnostics.CodeAnalysis; using HarmonyLib; using StardewModdingAPI.Framework.Patching; using StardewValley; namespace StardewModdingAPI.Mods.ErrorHandler.Patches { /// Harmony patches for which intercept errors to log more details. /// Patch methods must be static for Harmony to work correctly. See the Harmony documentation before renaming patch arguments. [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Argument names are defined by Harmony and methods are named for clarity.")] [SuppressMessage("ReSharper", "IdentifierTypo", Justification = "Argument names are defined by Harmony and methods are named for clarity.")] internal class EventPatches : IHarmonyPatch { /********* ** Fields *********/ /// Writes messages to the console and log file on behalf of the game. private static IMonitor MonitorForGame; /********* ** Public methods *********/ /// Construct an instance. /// Writes messages to the console and log file on behalf of the game. public EventPatches(IMonitor monitorForGame) { EventPatches.MonitorForGame = monitorForGame; } /// public void Apply(Harmony harmony) { harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.LogErrorAndHalt)), postfix: new HarmonyMethod(this.GetType(), nameof(EventPatches.After_Event_LogErrorAndHalt)) ); } /********* ** Private methods *********/ /// The method to call after . /// The exception being logged. private static void After_Event_LogErrorAndHalt(Exception e) { EventPatches.MonitorForGame.Log(e.ToString(), LogLevel.Error); } } }