using System;
using HarmonyLib;
namespace StardewModdingAPI.Internal.Patching
{
/// Simplifies applying instances to the game.
internal static class HarmonyPatcher
{
/*********
** Public methods
*********/
/// Apply the given Harmony patchers.
/// The mod ID applying the patchers.
/// The monitor with which to log any errors.
/// The patchers to apply.
public static Harmony Apply(string id, IMonitor monitor, params IPatcher[] patchers)
{
Harmony harmony = new Harmony(id);
foreach (IPatcher patcher in patchers)
{
try
{
patcher.Apply(harmony, monitor);
}
catch (Exception ex)
{
monitor.Log($"Couldn't apply runtime patch '{patcher.GetType().Name}' to the game. Some SMAPI features may not work correctly. See log file for details.", LogLevel.Error);
monitor.Log($"Technical details:\n{ex.GetLogSummary()}");
}
}
return harmony;
}
}
}