summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/RewriteFacades
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-05-05 20:53:02 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-05-05 21:02:33 -0400
commitf4192663d78c7a45418f07f0bf4acb67b11291fe (patch)
tree6b5108ce0162123d2c71ee2798204feb0eb75a42 /src/SMAPI/Framework/RewriteFacades
parent2d37fe6819dd15a6e995ea55d625179106c22cd7 (diff)
downloadSMAPI-f4192663d78c7a45418f07f0bf4acb67b11291fe.tar.gz
SMAPI-f4192663d78c7a45418f07f0bf4acb67b11291fe.tar.bz2
SMAPI-f4192663d78c7a45418f07f0bf4acb67b11291fe.zip
add Harmony 2.0 rewriters (#711)
Diffstat (limited to 'src/SMAPI/Framework/RewriteFacades')
-rw-r--r--src/SMAPI/Framework/RewriteFacades/HarmonyInstanceMethods.cs33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/RewriteFacades/HarmonyInstanceMethods.cs b/src/SMAPI/Framework/RewriteFacades/HarmonyInstanceMethods.cs
new file mode 100644
index 00000000..0f906f51
--- /dev/null
+++ b/src/SMAPI/Framework/RewriteFacades/HarmonyInstanceMethods.cs
@@ -0,0 +1,33 @@
+using System.Linq;
+using System.Reflection;
+using System.Reflection.Emit;
+using HarmonyLib;
+
+namespace StardewModdingAPI.Framework.RewriteFacades
+{
+ /// <summary>Maps Harmony 1.x methods to Harmony 2.x to avoid breaking older mods.</summary>
+ /// <remarks>This is public to support SMAPI rewriting and should not be referenced directly by mods.</remarks>
+ public class HarmonyInstanceMethods : Harmony
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="id">The unique patch identifier.</param>
+ public HarmonyInstanceMethods(string id)
+ : base(id) { }
+
+ /// <summary>Creates a new Harmony instance.</summary>
+ /// <param name="id">A unique identifier for the instance.</param>
+ public static Harmony Create(string id)
+ {
+ return new Harmony(id);
+ }
+
+ public DynamicMethod Patch(MethodBase original, HarmonyMethod prefix = null, HarmonyMethod postfix = null, HarmonyMethod transpiler = null)
+ {
+ MethodInfo method = base.Patch(original: original, prefix: prefix, postfix: postfix, transpiler: transpiler);
+ return new DynamicMethod(method.Name, method.Attributes, method.CallingConvention, method.ReturnType, method.GetParameters().Select(p => p.ParameterType).ToArray(), method.Module, true);
+ }
+ }
+}