summaryrefslogtreecommitdiff
path: root/src/SMAPI
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-05-10 11:50:35 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-05-10 11:50:35 -0400
commit10531e537fda7c4901304b295f4ef60ac1f83eea (patch)
treeda5ecb928b483fda8d55ff7b6733ad29fbb01d8b /src/SMAPI
parent1ff09685906b03b46b23e69b7bfe95df24c8184f (diff)
downloadSMAPI-10531e537fda7c4901304b295f4ef60ac1f83eea.tar.gz
SMAPI-10531e537fda7c4901304b295f4ef60ac1f83eea.tar.bz2
SMAPI-10531e537fda7c4901304b295f4ef60ac1f83eea.zip
rewrite AccessTools methods which changed in Harmony 2.0 (#711)
Diffstat (limited to 'src/SMAPI')
-rw-r--r--src/SMAPI/Framework/ModLoading/Rewriters/MethodParentRewriter.cs5
-rw-r--r--src/SMAPI/Framework/RewriteFacades/AccessToolsMethods.cs32
-rw-r--r--src/SMAPI/Framework/RewriteFacades/HarmonyInstanceMethods.cs11
-rw-r--r--src/SMAPI/Metadata/InstructionMetadata.cs3
4 files changed, 40 insertions, 11 deletions
diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/MethodParentRewriter.cs b/src/SMAPI/Framework/ModLoading/Rewriters/MethodParentRewriter.cs
index c6388295..d0fe8b13 100644
--- a/src/SMAPI/Framework/ModLoading/Rewriters/MethodParentRewriter.cs
+++ b/src/SMAPI/Framework/ModLoading/Rewriters/MethodParentRewriter.cs
@@ -42,8 +42,9 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters
/// <param name="fromType">The type whose methods to remap.</param>
/// <param name="toType">The type with methods to map to.</param>
/// <param name="onlyIfPlatformChanged">Whether to only rewrite references if loading the assembly on a different platform than it was compiled on.</param>
- public MethodParentRewriter(Type fromType, Type toType, bool onlyIfPlatformChanged = false)
- : this(fromType.FullName, toType, onlyIfPlatformChanged) { }
+ /// <param name="nounPhrase">A brief noun phrase indicating what the instruction finder matches (or <c>null</c> to generate one).</param>
+ public MethodParentRewriter(Type fromType, Type toType, bool onlyIfPlatformChanged = false, string nounPhrase = null)
+ : this(fromType.FullName, toType, onlyIfPlatformChanged, nounPhrase) { }
/// <summary>Perform the predefined logic for an instruction if applicable.</summary>
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
+{
+ /// <summary>Maps Harmony 1.x <see cref="AccessTools"/> 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>
+ [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<ConstructorInfo> 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
{
- /// <summary>Maps Harmony 1.x methods to Harmony 2.x to avoid breaking older mods.</summary>
+ /// <summary>Maps Harmony 1.x <code>HarmonyInstance</code> methods to Harmony 2.x's <see cref="Harmony"/> to avoid breaking older mods.</summary>
/// <remarks>This is public to support SMAPI rewriting and should not be referenced directly by mods.</remarks>
+ [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) { }
- /// <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);
}
- /// <summary>Apply one or more patches to a method.</summary>
- /// <param name="original">The original method.</param>
- /// <param name="prefix">The prefix to apply.</param>
- /// <param name="postfix">The postfix to apply.</param>
- /// <param name="transpiler">The transpiler to apply.</param>
public DynamicMethod Patch(MethodBase original, HarmonyMethod prefix = null, HarmonyMethod postfix = null, HarmonyMethod transpiler = null)
{
try
diff --git a/src/SMAPI/Metadata/InstructionMetadata.cs b/src/SMAPI/Metadata/InstructionMetadata.cs
index 64216138..40a7588e 100644
--- a/src/SMAPI/Metadata/InstructionMetadata.cs
+++ b/src/SMAPI/Metadata/InstructionMetadata.cs
@@ -38,7 +38,8 @@ namespace StardewModdingAPI.Metadata
// rewrite for SMAPI 3.6 (Harmony 1.x => 2.0 update)
yield return new Harmony1AssemblyRewriter();
- yield return new MethodParentRewriter("HarmonyLib.Harmony", typeof(HarmonyInstanceMethods), onlyIfPlatformChanged: false, nounPhrase: Harmony1AssemblyRewriter.DefaultNounPhrase);
+ yield return new MethodParentRewriter(typeof(HarmonyLib.Harmony), typeof(HarmonyInstanceMethods), onlyIfPlatformChanged: false, nounPhrase: Harmony1AssemblyRewriter.DefaultNounPhrase);
+ yield return new MethodParentRewriter(typeof(HarmonyLib.AccessTools), typeof(AccessToolsMethods), onlyIfPlatformChanged: false, nounPhrase: Harmony1AssemblyRewriter.DefaultNounPhrase);
/****
** detect mod issues