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); + }); } } }