From f817039a3a71e6e67c3bebb5e7fbd189c9a5da87 Mon Sep 17 00:00:00 2001 From: ZaneYork Date: Fri, 29 May 2020 14:25:01 +0800 Subject: Bug fix: make it possible for multi patch(When one patch replace an instruction, another patch didn't aware it due to the variable capture) --- src/SMAPI/Framework/ModLoading/AssemblyLoader.cs | 3 ++- src/SMAPI/Framework/ModLoading/Framework/RecursiveRewriter.cs | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs index eadb2997..dbb5f696 100644 --- a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs +++ b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Reflection; using Mono.Cecil; +using Mono.Cecil.Cil; using StardewModdingAPI.Framework.Exceptions; using StardewModdingAPI.Framework.ModLoading.Framework; using StardewModdingAPI.Metadata; @@ -304,7 +305,7 @@ namespace StardewModdingAPI.Framework.ModLoading rewritten |= handler.Handle(module, type, replaceWith); return rewritten; }, - rewriteInstruction: (instruction, cil, replaceWith) => + rewriteInstruction: (ref Instruction instruction, ILProcessor cil, Action replaceWith) => { bool rewritten = false; foreach (IInstructionHandler handler in handlers) diff --git a/src/SMAPI/Framework/ModLoading/Framework/RecursiveRewriter.cs b/src/SMAPI/Framework/ModLoading/Framework/RecursiveRewriter.cs index a0f075bd..c774c038 100644 --- a/src/SMAPI/Framework/ModLoading/Framework/RecursiveRewriter.cs +++ b/src/SMAPI/Framework/ModLoading/Framework/RecursiveRewriter.cs @@ -23,7 +23,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Framework /// The CIL instruction processor. /// Replaces the CIL instruction with the given instruction. /// Returns whether the instruction was changed. - public delegate bool RewriteInstructionDelegate(Instruction instruction, ILProcessor cil, Action replaceWith); + public delegate bool RewriteInstructionDelegate(ref Instruction instruction, ILProcessor cil, Action replaceWith); /********* @@ -144,7 +144,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Framework // instruction itself // (should be done after the above type rewrites to ensure valid types) - rewritten |= this.RewriteInstructionImpl(instruction, cil, newInstruction => + rewritten |= this.RewriteInstructionImpl(ref instruction, cil, newInstruction => { rewritten = true; cil.Replace(instruction, newInstruction); -- cgit