diff options
Diffstat (limited to 'src/SMAPI/Framework/Patching')
-rw-r--r-- | src/SMAPI/Framework/Patching/GamePatcher.cs | 53 | ||||
-rw-r--r-- | src/SMAPI/Framework/Patching/IHarmonyPatch.cs | 23 | ||||
-rw-r--r-- | src/SMAPI/Framework/Patching/PatchHelper.cs | 36 |
3 files changed, 0 insertions, 112 deletions
diff --git a/src/SMAPI/Framework/Patching/GamePatcher.cs b/src/SMAPI/Framework/Patching/GamePatcher.cs deleted file mode 100644 index ddecda08..00000000 --- a/src/SMAPI/Framework/Patching/GamePatcher.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -#if HARMONY_2 -using HarmonyLib; -#else -using Harmony; -#endif - -namespace StardewModdingAPI.Framework.Patching -{ - /// <summary>Encapsulates applying Harmony patches to the game.</summary> - internal class GamePatcher - { - /********* - ** Fields - *********/ - /// <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) - { -#if HARMONY_2 - Harmony harmony = new Harmony("SMAPI"); -#else - HarmonyInstance harmony = HarmonyInstance.Create("SMAPI"); -#endif - 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); - } - } - } - } -} diff --git a/src/SMAPI/Framework/Patching/IHarmonyPatch.cs b/src/SMAPI/Framework/Patching/IHarmonyPatch.cs deleted file mode 100644 index 38d30ab2..00000000 --- a/src/SMAPI/Framework/Patching/IHarmonyPatch.cs +++ /dev/null @@ -1,23 +0,0 @@ -#if HARMONY_2 -using HarmonyLib; -#else -using Harmony; -#endif - -namespace StardewModdingAPI.Framework.Patching -{ - /// <summary>A Harmony patch to apply.</summary> - internal interface IHarmonyPatch - { - /********* - ** Methods - *********/ - /// <summary>Apply the Harmony patch.</summary> - /// <param name="harmony">The Harmony instance.</param> -#if HARMONY_2 - void Apply(Harmony harmony); -#else - void Apply(HarmonyInstance harmony); -#endif - } -} diff --git a/src/SMAPI/Framework/Patching/PatchHelper.cs b/src/SMAPI/Framework/Patching/PatchHelper.cs deleted file mode 100644 index d1aa0185..00000000 --- a/src/SMAPI/Framework/Patching/PatchHelper.cs +++ /dev/null @@ -1,36 +0,0 @@ -#if !HARMONY_2 -using System; -using System.Collections.Generic; - -namespace StardewModdingAPI.Framework.Patching -{ - /// <summary>Provides generic methods for implementing Harmony patches.</summary> - internal class PatchHelper - { - /********* - ** Fields - *********/ - /// <summary>The interception keys currently being intercepted.</summary> - private static readonly HashSet<string> InterceptingKeys = new HashSet<string>(StringComparer.OrdinalIgnoreCase); - - - /********* - ** Public methods - *********/ - /// <summary>Track a method that will be intercepted.</summary> - /// <param name="key">The intercept key.</param> - /// <returns>Returns false if the method was already marked for interception, else true.</returns> - public static bool StartIntercept(string key) - { - return PatchHelper.InterceptingKeys.Add(key); - } - - /// <summary>Track a method as no longer being intercepted.</summary> - /// <param name="key">The intercept key.</param> - public static void StopIntercept(string key) - { - PatchHelper.InterceptingKeys.Remove(key); - } - } -} -#endif |