Transpiler has label issue for specific CIL.
Applying an empty Transpiler Patch to the following function will change the jump label position.
leave IL_002f was modified to leave IL_0024, causing unexpected execution.
using HarmonyLib;
using HarmonyLib.Tools;
using System.Reflection.Emit;
namespace Test
{
[HarmonyDebug]
public class Program
{
static void Test()
{
int i = 0;
try
{
if (i == 0)
{
try
{
Console.WriteLine("jump");
goto Label;
}
finally {}
}
Console.WriteLine("test");
Label:;
}
finally {}
}
[HarmonyPatch(typeof(Program), "Test")]
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> TestTranspiler(IEnumerable<CodeInstruction> instructions)
{
return instructions;
// temp solve
var codeMatcher = new CodeMatcher(instructions);
codeMatcher.MatchForward(false, new [] {new CodeMatch(OpCodes.Leave)});
codeMatcher.Insert(codeMatcher.Instruction);
return codeMatcher.InstructionEnumeration();
}
static void Main(string[] args)
{
HarmonyFileLog.Enabled = true;
Harmony.CreateAndPatchAll(typeof(Program));
Test();
}
}
}
Transpiler has label issue for specific CIL. Applying an empty Transpiler Patch to the following function will change the jump label position.
leave IL_002f
was modified toleave IL_0024
, causing unexpected execution.log