Skip to content

Commit

Permalink
Merge branch 'dev' into core
Browse files Browse the repository at this point in the history
# Conflicts:
#	Celeste.Mod.mm/Patches/Player.cs
  • Loading branch information
Kalobi committed Nov 9, 2023
2 parents 729739a + 94fb947 commit 9c5161b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 46 deletions.
27 changes: 12 additions & 15 deletions Celeste.Mod.mm/Patches/Level.cs
Original file line number Diff line number Diff line change
Expand Up @@ -896,21 +896,18 @@ public static void PatchLevelCanPause(ILContext il, CustomAttribute attrib) {
}


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);
});
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);
}
}
}
37 changes: 25 additions & 12 deletions Celeste.Mod.mm/Patches/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,19 +285,12 @@ public override void SceneEnd(Scene scene) {
[MonoModIgnore]
[PatchPlayerApproachMaxMove]
private extern int NormalUpdate();

private bool theoBlockingUpTransition() => level.Tracker.GetEntity<TheoCrystal>() != null && (!Holding?.IsHeld ?? true) && normalHitbox.Top + Position.Y < level.Bounds.Top + 1;

public extern bool orig_get_CanUnDuck();

public bool get_CanUnDuck() {
bool origCanUnDuck = orig_get_CanUnDuck();
bool theoBlockingUpTransition = false;

if (origCanUnDuck && level.Tracker.GetEntity<TheoCrystal>() != null && (!Holding?.IsHeld ?? true)) {
theoBlockingUpTransition = normalHitbox.Top + Position.Y < level.Bounds.Top + 1;
}

return origCanUnDuck && !theoBlockingUpTransition;
}
[MonoModIgnore]
[PatchPlayerGetCanUnDuck]
public extern bool get_CanUnDuck();
}

public static class PlayerExt {
Expand Down Expand Up @@ -366,6 +359,12 @@ class PatchPlayerCtorAttribute : Attribute { }
/// </summary>
[MonoModCustomMethodAttribute(nameof(MonoModRules.PatchPlayerExplodeLaunch))]
class PatchPlayerExplodeLaunchAttribute : Attribute { }

/// <summary>
/// Patches the property getter to prevent unducking into a screen transition when Theo is not carried.
/// </summary>
[MonoModCustomMethodAttribute(nameof(MonoModRules.PatchPlayerGetCanUnDuck))]
class PatchPlayerGetCanUnDuckAttribute : Attribute { }

/// <summary>
/// Patches the method to fix float jank when calculationg Calc.ApproachTo maxMove values
Expand Down Expand Up @@ -571,5 +570,19 @@ public static void PatchPlayerApproachMaxMove(ILContext context, CustomAttribute
}
}

public static void PatchPlayerGetCanUnDuck(ILContext context, CustomAttribute attrib) {
MethodDefinition m_theoBlockingUpTransition = context.Method.DeclaringType.FindMethod("theoBlockingUpTransition");
ILCursor cursor = new ILCursor(context);

// inserts: if (theoBlockingUpTransition()) return false;
cursor.GotoNext(MoveType.AfterLabel, instr => instr.MatchLdarg(0), instr => instr.MatchCall("Monocle.Entity", "get_Collider"));
cursor.Emit(OpCodes.Ldarg_0);
cursor.Emit(OpCodes.Call, m_theoBlockingUpTransition);
ILLabel orig = cursor.DefineLabel();
cursor.Emit(OpCodes.Brfalse_S, orig);
cursor.Emit(OpCodes.Ldc_I4_0);
cursor.Emit(OpCodes.Ret);
cursor.MarkLabel(orig);
}
}
}
35 changes: 16 additions & 19 deletions Celeste.Mod.mm/Patches/TheoCrystal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,23 @@ namespace MonoMod {
class PatchTheoCrystalUpdateAttribute : Attribute { }

static partial class MonoModRules {
public static void PatchTheoCrystalUpdate(MethodDefinition method, CustomAttribute attrib) {

MethodDefinition m_IsPlayerHoldingItemAndTransitioningUp = method.DeclaringType.FindMethod("IsPlayerHoldingItemAndTransitioningUp");
public static void PatchTheoCrystalUpdate(ILContext il, CustomAttribute attrib) {
MethodDefinition m_IsPlayerHoldingItemAndTransitioningUp = il.Method.DeclaringType.FindMethod("IsPlayerHoldingItemAndTransitioningUp");

ILLabel afterDieLabel = null;

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);
});
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);
}
}
}
Expand Down

0 comments on commit 9c5161b

Please sign in to comment.