From 10531e537fda7c4901304b295f4ef60ac1f83eea Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 10 May 2020 11:50:35 -0400 Subject: rewrite AccessTools methods which changed in Harmony 2.0 (#711) --- .../Framework/RewriteFacades/AccessToolsMethods.cs | 32 ++++++++++++++++++++++ .../RewriteFacades/HarmonyInstanceMethods.cs | 11 ++------ 2 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 src/SMAPI/Framework/RewriteFacades/AccessToolsMethods.cs (limited to 'src/SMAPI/Framework/RewriteFacades') diff --git a/src/SMAPI/Framework/RewriteFacades/AccessToolsMethods.cs b/src/SMAPI/Framework/RewriteFacades/AccessToolsMethods.cs new file mode 100644 index 00000000..cb40bbcc --- /dev/null +++ b/src/SMAPI/Framework/RewriteFacades/AccessToolsMethods.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Reflection; +using HarmonyLib; + +namespace StardewModdingAPI.Framework.RewriteFacades +{ + /// Maps Harmony 1.x methods to Harmony 2.x to avoid breaking older mods. + /// This is public to support SMAPI rewriting and should not be referenced directly by mods. + [SuppressMessage("ReSharper", "CS1591", Justification = "Documentation not needed for facade classes.")] + public class AccessToolsMethods + { + /********* + ** Public methods + *********/ + public static ConstructorInfo DeclaredConstructor(Type type, Type[] parameters = null) + { + return AccessTools.DeclaredConstructor(type, parameters, searchForStatic: true); + } + + public static ConstructorInfo Constructor(Type type, Type[] parameters = null) + { + return AccessTools.Constructor(type, parameters, searchForStatic: true); + } + + public static List GetDeclaredConstructors(Type type) + { + return AccessTools.GetDeclaredConstructors(type, searchForStatic: true); + } + } +} diff --git a/src/SMAPI/Framework/RewriteFacades/HarmonyInstanceMethods.cs b/src/SMAPI/Framework/RewriteFacades/HarmonyInstanceMethods.cs index bca76981..aad62c9b 100644 --- a/src/SMAPI/Framework/RewriteFacades/HarmonyInstanceMethods.cs +++ b/src/SMAPI/Framework/RewriteFacades/HarmonyInstanceMethods.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; using System.Reflection.Emit; @@ -7,8 +8,9 @@ using HarmonyLib; namespace StardewModdingAPI.Framework.RewriteFacades { - /// Maps Harmony 1.x methods to Harmony 2.x to avoid breaking older mods. + /// Maps Harmony 1.x HarmonyInstance methods to Harmony 2.x's to avoid breaking older mods. /// This is public to support SMAPI rewriting and should not be referenced directly by mods. + [SuppressMessage("ReSharper", "CS1591", Justification = "Documentation not needed for facade classes.")] public class HarmonyInstanceMethods : Harmony { /********* @@ -19,18 +21,11 @@ namespace StardewModdingAPI.Framework.RewriteFacades public HarmonyInstanceMethods(string id) : base(id) { } - /// Creates a new Harmony instance. - /// A unique identifier for the instance. public static Harmony Create(string id) { return new Harmony(id); } - /// Apply one or more patches to a method. - /// The original method. - /// The prefix to apply. - /// The postfix to apply. - /// The transpiler to apply. public DynamicMethod Patch(MethodBase original, HarmonyMethod prefix = null, HarmonyMethod postfix = null, HarmonyMethod transpiler = null) { try -- cgit