From f16e477fc22bf76c33d8860acda090a199a0dcdb Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 6 May 2020 00:02:10 -0400 Subject: add base instruction handler (#711) --- .../ModLoading/Rewriters/MethodParentRewriter.cs | 25 +++++----------------- 1 file changed, 5 insertions(+), 20 deletions(-) (limited to 'src/SMAPI/Framework/ModLoading/Rewriters') diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/MethodParentRewriter.cs b/src/SMAPI/Framework/ModLoading/Rewriters/MethodParentRewriter.cs index c4c740b3..c6388295 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/MethodParentRewriter.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/MethodParentRewriter.cs @@ -2,11 +2,12 @@ using System; using System.Linq; using Mono.Cecil; using Mono.Cecil.Cil; +using StardewModdingAPI.Framework.ModLoading.Framework; namespace StardewModdingAPI.Framework.ModLoading.Rewriters { /// Rewrites method references from one parent type to another if the signatures match. - internal class MethodParentRewriter : IInstructionHandler + internal class MethodParentRewriter : BaseInstructionHandler { /********* ** Fields @@ -21,13 +22,6 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters private readonly bool OnlyIfPlatformChanged; - /********* - ** Accessors - *********/ - /// A brief noun phrase indicating what the instruction finder matches. - public string NounPhrase { get; } - - /********* ** Public methods *********/ @@ -37,10 +31,10 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters /// Whether to only rewrite references if loading the assembly on a different platform than it was compiled on. /// A brief noun phrase indicating what the instruction finder matches (or null to generate one). public MethodParentRewriter(string fromType, Type toType, bool onlyIfPlatformChanged = false, string nounPhrase = null) + : base(nounPhrase ?? $"{fromType.Split('.').Last()} methods") { this.FromType = fromType; this.ToType = toType; - this.NounPhrase = nounPhrase ?? $"{fromType.Split('.').Last()} methods"; this.OnlyIfPlatformChanged = onlyIfPlatformChanged; } @@ -51,23 +45,14 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters public MethodParentRewriter(Type fromType, Type toType, bool onlyIfPlatformChanged = false) : this(fromType.FullName, toType, onlyIfPlatformChanged) { } - /// Perform the predefined logic for a method if applicable. - /// The assembly module containing the instruction. - /// The method definition containing the instruction. - /// Metadata for mapping assemblies to the current platform. - /// Whether the mod was compiled on a different platform. - public InstructionHandleResult Handle(ModuleDefinition module, MethodDefinition method, PlatformAssemblyMap assemblyMap, bool platformChanged) - { - return InstructionHandleResult.None; - } /// Perform the predefined logic for an instruction if applicable. /// The assembly module containing the instruction. /// The CIL processor. - /// The instruction to handle. + /// The CIL instruction to handle. /// Metadata for mapping assemblies to the current platform. /// Whether the mod was compiled on a different platform. - public InstructionHandleResult Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, PlatformAssemblyMap assemblyMap, bool platformChanged) + public override InstructionHandleResult Handle(ModuleDefinition module, ILProcessor cil, Instruction instruction, PlatformAssemblyMap assemblyMap, bool platformChanged) { if (!this.IsMatch(instruction, platformChanged)) return InstructionHandleResult.None; -- cgit