diff --git a/PulsarPluginLoader.Tests/Patches/PatchBySequenceTests.cs b/PulsarPluginLoader.Tests/Patches/PatchBySequenceTests.cs index dafa1e1..0172335 100644 --- a/PulsarPluginLoader.Tests/Patches/PatchBySequenceTests.cs +++ b/PulsarPluginLoader.Tests/Patches/PatchBySequenceTests.cs @@ -22,7 +22,7 @@ private static bool AreEqualSequences(IEnumerable first, IEnume CodeInstruction a = first.ElementAt(i); CodeInstruction b = second.ElementAt(i); - if (!a.opcode.Equals(b.opcode) && a.operand.Equals(b.operand)) + if (!a.opcode.Equals(b.opcode) || !a.operand.Equals(b.operand)) { return false; } @@ -133,7 +133,6 @@ public void CanReplace_SameLength() List expected = new List() { new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(SampleClass), "IntField")), - new CodeInstruction(OpCodes.Nop), new CodeInstruction(OpCodes.Ldc_R4, 12), new CodeInstruction(OpCodes.Ldc_R4, 18), }; @@ -167,7 +166,6 @@ public void CanReplace_SmallerInsert() List expected = new List() { new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(SampleClass), "IntField")), - new CodeInstruction(OpCodes.Nop), new CodeInstruction(OpCodes.Ldc_R4, 12) }; @@ -202,7 +200,6 @@ public void CanReplace_LargerInsert() List expected = new List() { new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(SampleClass), "IntField")), - new CodeInstruction(OpCodes.Nop), new CodeInstruction(OpCodes.Ldc_R4, 12), new CodeInstruction(OpCodes.Ldc_R4, 18), new CodeInstruction(OpCodes.Ldc_R4, 24), diff --git a/PulsarPluginLoader/Patches/HarmonyHelpers.cs b/PulsarPluginLoader/Patches/HarmonyHelpers.cs index 8701c4c..60dfdc5 100644 --- a/PulsarPluginLoader/Patches/HarmonyHelpers.cs +++ b/PulsarPluginLoader/Patches/HarmonyHelpers.cs @@ -1,5 +1,4 @@ using Harmony; -using Harmony.ILCopying; using PulsarPluginLoader.Utils; using System; using System.Collections.Generic; @@ -29,8 +28,12 @@ public static IEnumerable PatchBySequence(IEnumerable PatchBySequence(IEnumerable c.Clone())); } else if (patchMode == PatchMode.REPLACE) { - newInstructions[i].opcode = OpCodes.Nop; - newInstructions.RemoveRange(i + 1, targetSize - 1); - newInstructions.InsertRange(i + 1, patchSequence); + //newInstructions[i].opcode = OpCodes.Nop; + newInstructions.RemoveRange(i, targetSize); + newInstructions.InsertRange(i, patchSequence.Select(c => c.Clone())); } else { @@ -53,7 +56,7 @@ public static IEnumerable PatchBySequence(IEnumerable PatchBySequence(IEnumerable