summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/Patching/GamePatcher.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-06-08 21:36:48 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-06-08 21:36:48 -0400
commit96c49021a1d943e2ade7dbb96be3de707d7665c9 (patch)
tree7400a0c0ab4e84fdcdd420367af62729ffc491b0 /src/SMAPI/Framework/Patching/GamePatcher.cs
parentf79431d6549e9fb447e295aa026a8eba8f5f1ba4 (diff)
parentdd7887e0beb94179886494d40359b02db8e6dbe4 (diff)
downloadSMAPI-96c49021a1d943e2ade7dbb96be3de707d7665c9.tar.gz
SMAPI-96c49021a1d943e2ade7dbb96be3de707d7665c9.tar.bz2
SMAPI-96c49021a1d943e2ade7dbb96be3de707d7665c9.zip
Merge branch 'add-harmony' into develop
# Conflicts: # docs/release-notes.md
Diffstat (limited to 'src/SMAPI/Framework/Patching/GamePatcher.cs')
-rw-r--r--src/SMAPI/Framework/Patching/GamePatcher.cs45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/Patching/GamePatcher.cs b/src/SMAPI/Framework/Patching/GamePatcher.cs
new file mode 100644
index 00000000..71ca8e55
--- /dev/null
+++ b/src/SMAPI/Framework/Patching/GamePatcher.cs
@@ -0,0 +1,45 @@
+using System;
+using Harmony;
+
+namespace StardewModdingAPI.Framework.Patching
+{
+ /// <summary>Encapsulates applying Harmony patches to the game.</summary>
+ internal class GamePatcher
+ {
+ /*********
+ ** Properties
+ *********/
+ /// <summary>Encapsulates monitoring and logging.</summary>
+ private readonly IMonitor Monitor;
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="monitor">Encapsulates monitoring and logging.</param>
+ public GamePatcher(IMonitor monitor)
+ {
+ this.Monitor = monitor;
+ }
+
+ /// <summary>Apply all loaded patches to the game.</summary>
+ /// <param name="patches">The patches to apply.</param>
+ public void Apply(params IHarmonyPatch[] patches)
+ {
+ HarmonyInstance harmony = HarmonyInstance.Create("io.smapi");
+ foreach (IHarmonyPatch patch in patches)
+ {
+ try
+ {
+ patch.Apply(harmony);
+ }
+ catch (Exception ex)
+ {
+ this.Monitor.Log($"Couldn't apply runtime patch '{patch.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);
+ }
+ }
+ }
+ }
+}