using System;
using HarmonyLib;
namespace StardewModdingAPI.Framework.Patching
{
/// Encapsulates applying Harmony patches to the game.
internal class GamePatcher
{
/*********
** Fields
*********/
/// Encapsulates monitoring and logging.
private readonly IMonitor Monitor;
/*********
** Public methods
*********/
/// Construct an instance.
/// Encapsulates monitoring and logging.
public GamePatcher(IMonitor monitor)
{
this.Monitor = monitor;
}
/// Apply all loaded patches to the game.
/// The patches to apply.
public void Apply(params IHarmonyPatch[] patches)
{
Harmony harmony = new Harmony("SMAPI");
foreach (IHarmonyPatch patch in patches)
{
try
{
patch.Apply(harmony);
}
catch (Exception ex)
{
this.Monitor.Log($"Couldn't apply runtime patch '{patch.GetType().Name}' to the game. Some SMAPI features may not work correctly. See log file for details.", LogLevel.Error);
this.Monitor.Log(ex.GetLogSummary(), LogLevel.Trace);
}
}
}
}
}