using System; using System.Diagnostics.CodeAnalysis; using HarmonyLib; using StardewModdingAPI.Internal.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 EventPatcher : BasePatcher { /********* ** 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 EventPatcher(IMonitor monitorForGame) { EventPatcher.MonitorForGame = monitorForGame; } /// public override void Apply(Harmony harmony, IMonitor monitor) { harmony.Patch( original: this.RequireMethod(nameof(Event.LogErrorAndHalt)), postfix: this.GetHarmonyMethod(nameof(EventPatcher.After_LogErrorAndHalt)) ); } /********* ** Private methods *********/ /// The method to call after . /// The exception being logged. private static void After_LogErrorAndHalt(Exception e) { EventPatcher.MonitorForGame.Log(e.ToString(), LogLevel.Error); } } }