Skip to content

Commit

Permalink
Revert "Use overload taking ILContext for patches"
Browse files Browse the repository at this point in the history
This reverts commit 26618fa.
  • Loading branch information
maddie480 committed Nov 9, 2023
1 parent 9c2360f commit fdcb1cb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
27 changes: 15 additions & 12 deletions Celeste.Mod.mm/Patches/Level.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
}
}
35 changes: 19 additions & 16 deletions Celeste.Mod.mm/Patches/TheoCrystal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
}
}
Expand Down

0 comments on commit fdcb1cb

Please sign in to comment.