From fdcb1cb926a98fc82677614a51a445e6723445d7 Mon Sep 17 00:00:00 2001 From: maddie480 <52103563+maddie480@users.noreply.github.com> Date: Thu, 9 Nov 2023 20:59:52 +0100 Subject: [PATCH] Revert "Use overload taking ILContext for patches" This reverts commit 26618fa89da322a118aa76c90a9670be9958523e. --- Celeste.Mod.mm/Patches/Level.cs | 27 ++++++++++++--------- Celeste.Mod.mm/Patches/TheoCrystal.cs | 35 +++++++++++++++------------ 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/Celeste.Mod.mm/Patches/Level.cs b/Celeste.Mod.mm/Patches/Level.cs index 4223d4d92..5ede78009 100644 --- a/Celeste.Mod.mm/Patches/Level.cs +++ b/Celeste.Mod.mm/Patches/Level.cs @@ -803,18 +803,21 @@ public static void PatchLevelCanPause(ILContext il, CustomAttribute attrib) { } - public static void PatchLevelEnforceBounds(ILContext il, CustomAttribute attrib) { - MethodDefinition m_BlockUpTransitionsWithoutHoldable = il.Method.DeclaringType.FindMethod("BlockUpTransitionsWithoutHoldable"); - - ILCursor cursor = new(il); - - cursor.GotoNext(MoveType.After, - instr => instr.MatchCallvirt("Monocle.Tracker", "GetEntity"), - instr => instr.MatchStloc(2)); - cursor.Emit(OpCodes.Ldloc_2); - cursor.Emit(OpCodes.Ldarg_1); - cursor.Emit(OpCodes.Ldloc_0); - cursor.Emit(OpCodes.Call, m_BlockUpTransitionsWithoutHoldable); + public static void PatchLevelEnforceBounds(MethodDefinition method, CustomAttribute attrib) { + + MethodDefinition m_BlockUpTransitionsWithoutHoldable = method.DeclaringType.FindMethod("BlockUpTransitionsWithoutHoldable"); + + new ILContext(method).Invoke(il => { + ILCursor cursor = new(il); + + cursor.GotoNext(MoveType.After, + instr => instr.MatchCallvirt("Monocle.Tracker", "GetEntity"), + instr => instr.MatchStloc(2)); + cursor.Emit(OpCodes.Ldloc_2); + cursor.Emit(OpCodes.Ldarg_1); + cursor.Emit(OpCodes.Ldloc_0); + cursor.Emit(OpCodes.Call, m_BlockUpTransitionsWithoutHoldable); + }); } } } diff --git a/Celeste.Mod.mm/Patches/TheoCrystal.cs b/Celeste.Mod.mm/Patches/TheoCrystal.cs index 29ea5bb96..bf10dea5d 100644 --- a/Celeste.Mod.mm/Patches/TheoCrystal.cs +++ b/Celeste.Mod.mm/Patches/TheoCrystal.cs @@ -57,23 +57,26 @@ namespace MonoMod { class PatchTheoCrystalUpdateAttribute : Attribute { } static partial class MonoModRules { - public static void PatchTheoCrystalUpdate(ILContext il, CustomAttribute attrib) { - MethodDefinition m_IsPlayerHoldingItemAndTransitioningUp = il.Method.DeclaringType.FindMethod("IsPlayerHoldingItemAndTransitioningUp"); - + public static void PatchTheoCrystalUpdate(MethodDefinition method, CustomAttribute attrib) { + + MethodDefinition m_IsPlayerHoldingItemAndTransitioningUp = method.DeclaringType.FindMethod("IsPlayerHoldingItemAndTransitioningUp"); ILLabel afterDieLabel = null; - ILCursor cursor = new(il); - cursor.GotoNext(MoveType.After, - instr => instr.MatchCall("Microsoft.Xna.Framework.Rectangle", "get_Bottom"), - instr => instr.MatchConvR4(), - instr => instr.MatchBleUn(out afterDieLabel), - instr => instr.MatchLdarg(0), - instr => instr.MatchCallvirt("Celeste.TheoCrystal", "Die")); - - cursor.Index -= 2; - - cursor.Emit(OpCodes.Ldarg_0); - cursor.Emit(OpCodes.Call, m_IsPlayerHoldingItemAndTransitioningUp); - cursor.Emit(OpCodes.Brtrue, afterDieLabel); + + new ILContext(method).Invoke(il => { + ILCursor curser = new(il); + curser.GotoNext(MoveType.After, + instr => instr.MatchCall("Microsoft.Xna.Framework.Rectangle", "get_Bottom"), + instr => instr.MatchConvR4(), + instr => instr.MatchBleUn(out afterDieLabel), + instr => instr.MatchLdarg(0), + instr => instr.MatchCallvirt("Celeste.TheoCrystal", "Die")); + + curser.Index -= 2; + + curser.Emit(OpCodes.Ldarg_0); + curser.Emit(OpCodes.Call, m_IsPlayerHoldingItemAndTransitioningUp); + curser.Emit(OpCodes.Brtrue, afterDieLabel); + }); } } }