Skip to content

Commit c84e3fb

Browse files
committed
Add DetourContexts to IL hooks for jumpthrus
1 parent 4d9b188 commit c84e3fb

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

Entities/SidewaysJumpThru.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,19 @@ public static void Load() {
3030
// block "climb hopping" on top of sideways jumpthrus, because this just looks weird.
3131
On.Celeste.Player.ClimbHopBlockedCheck += onPlayerClimbHopBlockedCheck;
3232

33-
// mod collide checks to include sideways jumpthrus, so that the player behaves with them like with walls.
34-
IL.Celeste.Player.WallJumpCheck += modCollideChecks; // allow player to walljump off them
35-
IL.Celeste.Player.ClimbCheck += modCollideChecks; // allow player to climb on them
36-
IL.Celeste.Player.ClimbBegin += modCollideChecks; // if not applied, the player will clip through jumpthrus if trying to climb on them
37-
IL.Celeste.Player.ClimbUpdate += modCollideChecks; // when climbing, jumpthrus are handled like walls
38-
IL.Celeste.Player.SlipCheck += modCollideChecks; // make climbing on jumpthrus not slippery
39-
IL.Celeste.Player.NormalUpdate += modCollideChecks; // get the wall slide effect
40-
IL.Celeste.Player.OnCollideH += modCollideChecks; // handle dashes against jumpthrus properly, without "shifting" down
41-
42-
// have the push animation when Madeline runs against a jumpthru for example
43-
hookOnUpdateSprite = new ILHook(typeof(Player).GetMethod(updateSpriteMethodToPatch, BindingFlags.NonPublic | BindingFlags.Instance), modCollideChecks);
33+
using (new DetourContext()) {
34+
// mod collide checks to include sideways jumpthrus, so that the player behaves with them like with walls.
35+
IL.Celeste.Player.WallJumpCheck += modCollideChecks; // allow player to walljump off them
36+
IL.Celeste.Player.ClimbCheck += modCollideChecks; // allow player to climb on them
37+
IL.Celeste.Player.ClimbBegin += modCollideChecks; // if not applied, the player will clip through jumpthrus if trying to climb on them
38+
IL.Celeste.Player.ClimbUpdate += modCollideChecks; // when climbing, jumpthrus are handled like walls
39+
IL.Celeste.Player.SlipCheck += modCollideChecks; // make climbing on jumpthrus not slippery
40+
IL.Celeste.Player.NormalUpdate += modCollideChecks; // get the wall slide effect
41+
IL.Celeste.Player.OnCollideH += modCollideChecks; // handle dashes against jumpthrus properly, without "shifting" down
42+
43+
// have the push animation when Madeline runs against a jumpthru for example
44+
hookOnUpdateSprite = new ILHook(typeof(Player).GetMethod(updateSpriteMethodToPatch, BindingFlags.NonPublic | BindingFlags.Instance), modCollideChecks);
45+
}
4446

4547
// one extra hook that kills the player momentum when hitting a jumpthru so that they don't get "stuck" on them.
4648
On.Celeste.Player.NormalUpdate += onPlayerNormalUpdate;

Entities/UpsideDownJumpThru.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@ public static void Load() {
3333
On.Celeste.Player.ctor += onPlayerConstructor;
3434
}
3535

36-
// block player if they try to climb past an upside-down jumpthru.
37-
IL.Celeste.Player.ClimbUpdate += patchPlayerClimbUpdate;
3836

39-
// ignore upside-down jumpthrus in select places.
40-
playerOrigUpdateHook = new ILHook(typeof(Player).GetMethod("orig_Update"), filterOutJumpThrusFromCollideChecks);
41-
IL.Celeste.Player.DashUpdate += filterOutJumpThrusFromCollideChecks;
42-
IL.Celeste.Player.RedDashUpdate += filterOutJumpThrusFromCollideChecks;
37+
using (new DetourContext()) {
38+
// block player if they try to climb past an upside-down jumpthru.
39+
IL.Celeste.Player.ClimbUpdate += patchPlayerClimbUpdate;
40+
41+
// ignore upside-down jumpthrus in select places.
42+
playerOrigUpdateHook = new ILHook(typeof(Player).GetMethod("orig_Update"), filterOutJumpThrusFromCollideChecks);
43+
IL.Celeste.Player.DashUpdate += filterOutJumpThrusFromCollideChecks;
44+
IL.Celeste.Player.RedDashUpdate += filterOutJumpThrusFromCollideChecks;
45+
}
4346
}
4447

4548
public static void Unload() {

0 commit comments

Comments
 (0)