From d1bf3d52352df4bb720cf0fa87dcd6a64f35446a Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 18 May 2020 22:44:06 -0400 Subject: move facade namespace (#711) --- .../RewriteFacades/AccessToolsMethods.cs | 32 ++++++++++++ .../RewriteFacades/HarmonyInstanceMethods.cs | 49 +++++++++++++++++ .../RewriteFacades/SpriteBatchMethods.cs | 61 ++++++++++++++++++++++ .../Framework/RewriteFacades/AccessToolsMethods.cs | 32 ------------ .../RewriteFacades/HarmonyInstanceMethods.cs | 49 ----------------- .../Framework/RewriteFacades/SpriteBatchMethods.cs | 61 ---------------------- src/SMAPI/Metadata/InstructionMetadata.cs | 2 +- 7 files changed, 143 insertions(+), 143 deletions(-) create mode 100644 src/SMAPI/Framework/ModLoading/RewriteFacades/AccessToolsMethods.cs create mode 100644 src/SMAPI/Framework/ModLoading/RewriteFacades/HarmonyInstanceMethods.cs create mode 100644 src/SMAPI/Framework/ModLoading/RewriteFacades/SpriteBatchMethods.cs delete mode 100644 src/SMAPI/Framework/RewriteFacades/AccessToolsMethods.cs delete mode 100644 src/SMAPI/Framework/RewriteFacades/HarmonyInstanceMethods.cs delete mode 100644 src/SMAPI/Framework/RewriteFacades/SpriteBatchMethods.cs (limited to 'src') diff --git a/src/SMAPI/Framework/ModLoading/RewriteFacades/AccessToolsMethods.cs b/src/SMAPI/Framework/ModLoading/RewriteFacades/AccessToolsMethods.cs new file mode 100644 index 00000000..ea35fec9 --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/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.ModLoading.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/ModLoading/RewriteFacades/HarmonyInstanceMethods.cs b/src/SMAPI/Framework/ModLoading/RewriteFacades/HarmonyInstanceMethods.cs new file mode 100644 index 00000000..78cf25f8 --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/RewriteFacades/HarmonyInstanceMethods.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Reflection; +using System.Reflection.Emit; +using HarmonyLib; + +namespace StardewModdingAPI.Framework.ModLoading.RewriteFacades +{ + /// 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 + { + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The unique patch identifier. + public HarmonyInstanceMethods(string id) + : base(id) { } + + public static Harmony Create(string id) + { + return new Harmony(id); + } + + public DynamicMethod Patch(MethodBase original, HarmonyMethod prefix = null, HarmonyMethod postfix = null, HarmonyMethod transpiler = null) + { + try + { + MethodInfo method = base.Patch(original: original, prefix: prefix, postfix: postfix, transpiler: transpiler); + return (DynamicMethod)method; + } + catch (Exception ex) + { + var patchTypes = new List(); + if (prefix != null) + patchTypes.Add("prefix"); + if (postfix != null) + patchTypes.Add("postfix"); + if (transpiler != null) + patchTypes.Add("transpiler"); + + throw new Exception($"Harmony instance {this.Id} failed applying {string.Join("/", patchTypes)} to method {original.DeclaringType?.FullName}.{original.Name}.", ex); + } + } + } +} diff --git a/src/SMAPI/Framework/ModLoading/RewriteFacades/SpriteBatchMethods.cs b/src/SMAPI/Framework/ModLoading/RewriteFacades/SpriteBatchMethods.cs new file mode 100644 index 00000000..75bb61ef --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/RewriteFacades/SpriteBatchMethods.cs @@ -0,0 +1,61 @@ +using System.Diagnostics.CodeAnalysis; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +#pragma warning disable 1591 // missing documentation +namespace StardewModdingAPI.Framework.ModLoading.RewriteFacades +{ + /// Provides method signatures that can be injected into mod code for compatibility between Linux/Mac or Windows. + /// This is public to support SMAPI rewriting and should not be referenced directly by mods. + public class SpriteBatchMethods : SpriteBatch + { + /********* + ** Public methods + *********/ + /// Construct an instance. + public SpriteBatchMethods(GraphicsDevice graphicsDevice) : base(graphicsDevice) { } + + + /**** + ** MonoGame signatures + ****/ + [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Linux/Mac.")] + public new void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix? matrix) + { + base.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, matrix ?? Matrix.Identity); + } + + /**** + ** XNA signatures + ****/ + [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Windows.")] + public new void Begin() + { + base.Begin(); + } + + [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Windows.")] + public new void Begin(SpriteSortMode sortMode, BlendState blendState) + { + base.Begin(sortMode, blendState); + } + + [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Windows.")] + public new void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState) + { + base.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState); + } + + [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Windows.")] + public new void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect) + { + base.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect); + } + + [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Windows.")] + public new void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix transformMatrix) + { + base.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, transformMatrix); + } + } +} diff --git a/src/SMAPI/Framework/RewriteFacades/AccessToolsMethods.cs b/src/SMAPI/Framework/RewriteFacades/AccessToolsMethods.cs deleted file mode 100644 index cb40bbcc..00000000 --- a/src/SMAPI/Framework/RewriteFacades/AccessToolsMethods.cs +++ /dev/null @@ -1,32 +0,0 @@ -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 deleted file mode 100644 index 8e4ef7df..00000000 --- a/src/SMAPI/Framework/RewriteFacades/HarmonyInstanceMethods.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Reflection; -using System.Reflection.Emit; -using HarmonyLib; - -namespace StardewModdingAPI.Framework.RewriteFacades -{ - /// 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 - { - /********* - ** Public methods - *********/ - /// Construct an instance. - /// The unique patch identifier. - public HarmonyInstanceMethods(string id) - : base(id) { } - - public static Harmony Create(string id) - { - return new Harmony(id); - } - - public DynamicMethod Patch(MethodBase original, HarmonyMethod prefix = null, HarmonyMethod postfix = null, HarmonyMethod transpiler = null) - { - try - { - MethodInfo method = base.Patch(original: original, prefix: prefix, postfix: postfix, transpiler: transpiler); - return (DynamicMethod)method; - } - catch (Exception ex) - { - var patchTypes = new List(); - if (prefix != null) - patchTypes.Add("prefix"); - if (postfix != null) - patchTypes.Add("postfix"); - if (transpiler != null) - patchTypes.Add("transpiler"); - - throw new Exception($"Harmony instance {this.Id} failed applying {string.Join("/", patchTypes)} to method {original.DeclaringType?.FullName}.{original.Name}.", ex); - } - } - } -} diff --git a/src/SMAPI/Framework/RewriteFacades/SpriteBatchMethods.cs b/src/SMAPI/Framework/RewriteFacades/SpriteBatchMethods.cs deleted file mode 100644 index 26b22315..00000000 --- a/src/SMAPI/Framework/RewriteFacades/SpriteBatchMethods.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -#pragma warning disable 1591 // missing documentation -namespace StardewModdingAPI.Framework.RewriteFacades -{ - /// Provides method signatures that can be injected into mod code for compatibility between Linux/Mac or Windows. - /// This is public to support SMAPI rewriting and should not be referenced directly by mods. - public class SpriteBatchMethods : SpriteBatch - { - /********* - ** Public methods - *********/ - /// Construct an instance. - public SpriteBatchMethods(GraphicsDevice graphicsDevice) : base(graphicsDevice) { } - - - /**** - ** MonoGame signatures - ****/ - [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Linux/Mac.")] - public new void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix? matrix) - { - base.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, matrix ?? Matrix.Identity); - } - - /**** - ** XNA signatures - ****/ - [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Windows.")] - public new void Begin() - { - base.Begin(); - } - - [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Windows.")] - public new void Begin(SpriteSortMode sortMode, BlendState blendState) - { - base.Begin(sortMode, blendState); - } - - [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Windows.")] - public new void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState) - { - base.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState); - } - - [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Windows.")] - public new void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect) - { - base.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect); - } - - [SuppressMessage("ReSharper", "CS0109", Justification = "The 'new' modifier applies when compiled on Windows.")] - public new void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix transformMatrix) - { - base.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, transformMatrix); - } - } -} diff --git a/src/SMAPI/Metadata/InstructionMetadata.cs b/src/SMAPI/Metadata/InstructionMetadata.cs index 40a7588e..d80f64e2 100644 --- a/src/SMAPI/Metadata/InstructionMetadata.cs +++ b/src/SMAPI/Metadata/InstructionMetadata.cs @@ -3,8 +3,8 @@ using Microsoft.Xna.Framework.Graphics; using StardewModdingAPI.Events; using StardewModdingAPI.Framework.ModLoading; using StardewModdingAPI.Framework.ModLoading.Finders; +using StardewModdingAPI.Framework.ModLoading.RewriteFacades; using StardewModdingAPI.Framework.ModLoading.Rewriters; -using StardewModdingAPI.Framework.RewriteFacades; using StardewValley; namespace StardewModdingAPI.Metadata -- cgit