summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Framework')
-rw-r--r--src/SMAPI/Framework/Commands/HarmonySummaryCommand.cs2
-rw-r--r--src/SMAPI/Framework/ModLoading/RewriteFacades/AccessToolsFacade.cs2
-rw-r--r--src/SMAPI/Framework/ModLoading/RewriteFacades/HarmonyInstanceFacade.cs2
-rw-r--r--src/SMAPI/Framework/ModLoading/RewriteFacades/HarmonyMethodFacade.cs2
-rw-r--r--src/SMAPI/Framework/ModLoading/Rewriters/Harmony1AssemblyRewriter.cs2
-rw-r--r--src/SMAPI/Framework/Patching/GamePatcher.cs8
-rw-r--r--src/SMAPI/Framework/Patching/IHarmonyPatch.cs8
-rw-r--r--src/SMAPI/Framework/Patching/PatchHelper.cs36
-rw-r--r--src/SMAPI/Framework/SCore.cs2
9 files changed, 64 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/Commands/HarmonySummaryCommand.cs b/src/SMAPI/Framework/Commands/HarmonySummaryCommand.cs
index 08233feb..8c20fbdd 100644
--- a/src/SMAPI/Framework/Commands/HarmonySummaryCommand.cs
+++ b/src/SMAPI/Framework/Commands/HarmonySummaryCommand.cs
@@ -1,3 +1,4 @@
+#if HARMONY_2
using System;
using System.Collections.Generic;
using System.Linq;
@@ -166,3 +167,4 @@ namespace StardewModdingAPI.Framework.Commands
}
}
}
+#endif
diff --git a/src/SMAPI/Framework/ModLoading/RewriteFacades/AccessToolsFacade.cs b/src/SMAPI/Framework/ModLoading/RewriteFacades/AccessToolsFacade.cs
index 8e4320b3..102f3364 100644
--- a/src/SMAPI/Framework/ModLoading/RewriteFacades/AccessToolsFacade.cs
+++ b/src/SMAPI/Framework/ModLoading/RewriteFacades/AccessToolsFacade.cs
@@ -1,3 +1,4 @@
+#if HARMONY_2
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -40,3 +41,4 @@ namespace StardewModdingAPI.Framework.ModLoading.RewriteFacades
}
}
}
+#endif
diff --git a/src/SMAPI/Framework/ModLoading/RewriteFacades/HarmonyInstanceFacade.cs b/src/SMAPI/Framework/ModLoading/RewriteFacades/HarmonyInstanceFacade.cs
index 54b91679..ad6d5e4f 100644
--- a/src/SMAPI/Framework/ModLoading/RewriteFacades/HarmonyInstanceFacade.cs
+++ b/src/SMAPI/Framework/ModLoading/RewriteFacades/HarmonyInstanceFacade.cs
@@ -1,3 +1,4 @@
+#if HARMONY_2
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -80,3 +81,4 @@ namespace StardewModdingAPI.Framework.ModLoading.RewriteFacades
}
}
}
+#endif
diff --git a/src/SMAPI/Framework/ModLoading/RewriteFacades/HarmonyMethodFacade.cs b/src/SMAPI/Framework/ModLoading/RewriteFacades/HarmonyMethodFacade.cs
index 44c97401..f3975558 100644
--- a/src/SMAPI/Framework/ModLoading/RewriteFacades/HarmonyMethodFacade.cs
+++ b/src/SMAPI/Framework/ModLoading/RewriteFacades/HarmonyMethodFacade.cs
@@ -1,3 +1,4 @@
+#if HARMONY_2
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
@@ -43,3 +44,4 @@ namespace StardewModdingAPI.Framework.ModLoading.RewriteFacades
}
}
}
+#endif
diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/Harmony1AssemblyRewriter.cs b/src/SMAPI/Framework/ModLoading/Rewriters/Harmony1AssemblyRewriter.cs
index 8fed170a..b30d686e 100644
--- a/src/SMAPI/Framework/ModLoading/Rewriters/Harmony1AssemblyRewriter.cs
+++ b/src/SMAPI/Framework/ModLoading/Rewriters/Harmony1AssemblyRewriter.cs
@@ -1,3 +1,4 @@
+#if HARMONY_2
using System;
using HarmonyLib;
using Mono.Cecil;
@@ -125,3 +126,4 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters
}
}
}
+#endif
diff --git a/src/SMAPI/Framework/Patching/GamePatcher.cs b/src/SMAPI/Framework/Patching/GamePatcher.cs
index dcad285a..82d7b9c8 100644
--- a/src/SMAPI/Framework/Patching/GamePatcher.cs
+++ b/src/SMAPI/Framework/Patching/GamePatcher.cs
@@ -1,5 +1,9 @@
using System;
+#if HARMONY_2
using HarmonyLib;
+#else
+using Harmony;
+#endif
namespace StardewModdingAPI.Framework.Patching
{
@@ -27,7 +31,11 @@ namespace StardewModdingAPI.Framework.Patching
/// <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
diff --git a/src/SMAPI/Framework/Patching/IHarmonyPatch.cs b/src/SMAPI/Framework/Patching/IHarmonyPatch.cs
index 7d5eb3d4..922243fa 100644
--- a/src/SMAPI/Framework/Patching/IHarmonyPatch.cs
+++ b/src/SMAPI/Framework/Patching/IHarmonyPatch.cs
@@ -1,4 +1,8 @@
+#if HARMONY_2
using HarmonyLib;
+#else
+using Harmony;
+#endif
namespace StardewModdingAPI.Framework.Patching
{
@@ -10,6 +14,10 @@ namespace StardewModdingAPI.Framework.Patching
/// <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
new file mode 100644
index 00000000..d1aa0185
--- /dev/null
+++ b/src/SMAPI/Framework/Patching/PatchHelper.cs
@@ -0,0 +1,36 @@
+#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
diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs
index 530b6754..1a2c97f4 100644
--- a/src/SMAPI/Framework/SCore.cs
+++ b/src/SMAPI/Framework/SCore.cs
@@ -511,7 +511,9 @@ namespace StardewModdingAPI.Framework
this.Monitor.Log("Type 'help' for help, or 'help <cmd>' for a command's usage", LogLevel.Info);
this.GameInstance.CommandManager
.Add(new HelpCommand(this.GameInstance.CommandManager), this.Monitor)
+#if HARMONY_2
.Add(new HarmonySummaryCommand(), this.Monitor)
+#endif
.Add(new ReloadI18nCommand(this.ReloadTranslations), this.Monitor);
// start handling command line input