Skip to content

Commit c7b0530

Browse files
committed
Backport jumpthru fixes from Helping Hand
1 parent ae01d78 commit c7b0530

File tree

2 files changed

+31
-26
lines changed

2 files changed

+31
-26
lines changed

Entities/SidewaysJumpThru.cs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,20 @@ public static void activateHooks() {
6868
// block "climb hopping" on top of sideways jumpthrus, because this just looks weird.
6969
On.Celeste.Player.ClimbHopBlockedCheck += onPlayerClimbHopBlockedCheck;
7070

71-
using (new DetourContext()) {
72-
// mod collide checks to include sideways jumpthrus, so that the player behaves with them like with walls.
73-
IL.Celeste.Player.WallJumpCheck += modCollideChecks; // allow player to walljump off them
74-
IL.Celeste.Player.ClimbCheck += modCollideChecks; // allow player to climb on them
75-
IL.Celeste.Player.ClimbBegin += modCollideChecks; // if not applied, the player will clip through jumpthrus if trying to climb on them
76-
IL.Celeste.Player.ClimbUpdate += modCollideChecks; // when climbing, jumpthrus are handled like walls
77-
IL.Celeste.Player.SlipCheck += modCollideChecks; // make climbing on jumpthrus not slippery
78-
IL.Celeste.Player.NormalUpdate += modCollideChecks; // get the wall slide effect
79-
IL.Celeste.Player.OnCollideH += modCollideChecks; // handle dashes against jumpthrus properly, without "shifting" down
80-
81-
// have the push animation when Madeline runs against a jumpthru for example
82-
hookOnUpdateSprite = new ILHook(typeof(Player).GetMethod(updateSpriteMethodToPatch, BindingFlags.NonPublic | BindingFlags.Instance), modCollideChecks);
83-
}
71+
// mod collide checks to include sideways jumpthrus, so that the player behaves with them like with walls.
72+
IL.Celeste.Player.WallJumpCheck += modCollideChecks; // allow player to walljump off them
73+
IL.Celeste.Player.ClimbCheck += modCollideChecks; // allow player to climb on them
74+
IL.Celeste.Player.ClimbBegin += modCollideChecks; // if not applied, the player will clip through jumpthrus if trying to climb on them
75+
IL.Celeste.Player.ClimbUpdate += modCollideChecks; // when climbing, jumpthrus are handled like walls
76+
IL.Celeste.Player.SlipCheck += modCollideChecks; // make climbing on jumpthrus not slippery
77+
IL.Celeste.Player.NormalUpdate += modCollideChecks; // get the wall slide effect
78+
IL.Celeste.Player.OnCollideH += modCollideChecks; // handle dashes against jumpthrus properly, without "shifting" down
79+
80+
// don't make Madeline duck when dashing against a sideways jumpthru
81+
On.Celeste.Player.DuckFreeAt += preventDuckWhenDashingAgainstJumpthru;
82+
83+
// have the push animation when Madeline runs against a jumpthru for example
84+
hookOnUpdateSprite = new ILHook(typeof(Player).GetMethod(updateSpriteMethodToPatch, BindingFlags.NonPublic | BindingFlags.Instance), modCollideChecks);
8485

8586
// one extra hook that kills the player momentum when hitting a jumpthru so that they don't get "stuck" on them.
8687
On.Celeste.Player.NormalUpdate += onPlayerNormalUpdate;
@@ -107,15 +108,15 @@ public static void deactivateHooks() {
107108
IL.Celeste.Player.OnCollideH -= modCollideChecks;
108109
hookOnUpdateSprite?.Dispose();
109110

111+
On.Celeste.Player.DuckFreeAt -= preventDuckWhenDashingAgainstJumpthru;
112+
110113
On.Celeste.Player.NormalUpdate -= onPlayerNormalUpdate;
111114
}
112115

113116
private static void addSidewaysJumpthrusInHorizontalMoveMethods(ILContext il) {
114117
ILCursor cursor = new ILCursor(il);
115118

116-
if (cursor.TryGotoNext(MoveType.After, instr => instr.MatchCall<Entity>("CollideFirst"))
117-
&& cursor.TryGotoNext(instr => instr.OpCode == OpCodes.Brfalse_S || instr.OpCode == OpCodes.Brtrue_S)) {
118-
119+
if (cursor.TryGotoNext(MoveType.After, instr => instr.MatchCall<Entity>("CollideFirst"))) {
119120
Logger.Log("SpringCollab2020/SidewaysJumpThru", $"Injecting sideways jumpthru check at {cursor.Index} in IL for {il.Method.Name}");
120121
cursor.Emit(OpCodes.Ldarg_0);
121122
cursor.Emit(OpCodes.Ldarg_1);
@@ -205,6 +206,10 @@ private static void modCollideChecks(ILContext il) {
205206
}
206207
}
207208

209+
private static bool preventDuckWhenDashingAgainstJumpthru(On.Celeste.Player.orig_DuckFreeAt orig, Player self, Vector2 at) {
210+
return orig(self, at) && !entityCollideCheckWithSidewaysJumpthrus(self, at, false, false);
211+
}
212+
208213
private static void callOrigMethodKeepingEverythingOnStack(ILCursor cursor, VariableDefinition checkAtPositionStore, bool isSceneCollideCheck) {
209214
// store the position in the local variable
210215
cursor.Emit(OpCodes.Stloc, checkAtPositionStore);

Entities/UpsideDownJumpThru.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,17 @@ public static void activateHooks() {
7373
}
7474

7575

76-
using (new DetourContext()) {
77-
// block player if they try to climb past an upside-down jumpthru.
78-
IL.Celeste.Player.ClimbUpdate += patchPlayerClimbUpdate;
76+
// block player if they try to climb past an upside-down jumpthru.
77+
IL.Celeste.Player.ClimbUpdate += patchPlayerClimbUpdate;
7978

80-
// ignore upside-down jumpthrus in select places.
81-
playerOrigUpdateHook = new ILHook(typeof(Player).GetMethod("orig_Update"), filterOutJumpThrusFromCollideChecks);
82-
IL.Celeste.Player.DashUpdate += filterOutJumpThrusFromCollideChecks;
83-
IL.Celeste.Player.RedDashUpdate += filterOutJumpThrusFromCollideChecks;
79+
// ignore upside-down jumpthrus in select places.
80+
playerOrigUpdateHook = new ILHook(typeof(Player).GetMethod("orig_Update"), filterOutJumpThrusFromCollideChecks);
81+
IL.Celeste.Player.DashUpdate += filterOutJumpThrusFromCollideChecks;
82+
IL.Celeste.Player.RedDashUpdate += filterOutJumpThrusFromCollideChecks;
83+
IL.Celeste.Actor.MoveVExact += filterOutJumpThrusFromCollideChecks;
8484

85-
// listen for the player unducking, to knock the player down before they would go through upside down jumpthrus.
86-
On.Celeste.Player.Update += onPlayerUpdate;
87-
}
85+
// listen for the player unducking, to knock the player down before they would go through upside down jumpthrus.
86+
On.Celeste.Player.Update += onPlayerUpdate;
8887
}
8988

9089
public static void deactivateHooks() {
@@ -104,6 +103,7 @@ public static void deactivateHooks() {
104103
playerOrigUpdateHook?.Dispose();
105104
IL.Celeste.Player.DashUpdate -= filterOutJumpThrusFromCollideChecks;
106105
IL.Celeste.Player.RedDashUpdate -= filterOutJumpThrusFromCollideChecks;
106+
IL.Celeste.Actor.MoveVExact -= filterOutJumpThrusFromCollideChecks;
107107

108108
On.Celeste.Player.Update -= onPlayerUpdate;
109109
}

0 commit comments

Comments
 (0)