Skip to content

Commit

Permalink
Fix being able to clip through upside down jumpthrus by unducking
Browse files Browse the repository at this point in the history
  • Loading branch information
maddie480 authored and Vexatos committed Sep 13, 2020
1 parent 14754c9 commit af83dd7
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Entities/UpsideDownJumpThru.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class UpsideDownJumpThru : JumpThru {

private static ILHook playerOrigUpdateHook;

private static readonly Hitbox normalHitbox = new Hitbox(8f, 11f, -4f, -11f);

public static void Load() {
using (new DetourContext { Before = { "*" } }) { // these don't always call the orig methods, better apply them first.
// fix general actor/platform behavior to make them comply with jumpthrus.
Expand All @@ -42,6 +44,9 @@ public static void Load() {
playerOrigUpdateHook = new ILHook(typeof(Player).GetMethod("orig_Update"), filterOutJumpThrusFromCollideChecks);
IL.Celeste.Player.DashUpdate += filterOutJumpThrusFromCollideChecks;
IL.Celeste.Player.RedDashUpdate += filterOutJumpThrusFromCollideChecks;

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

Expand All @@ -55,6 +60,8 @@ public static void Unload() {
playerOrigUpdateHook?.Dispose();
IL.Celeste.Player.DashUpdate -= filterOutJumpThrusFromCollideChecks;
IL.Celeste.Player.RedDashUpdate -= filterOutJumpThrusFromCollideChecks;

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

private static bool onActorMoveVExact(On.Celeste.Actor.orig_MoveVExact orig, Actor self, int moveV, Collision onCollide, Solid pusher) {
Expand Down Expand Up @@ -289,6 +296,25 @@ private static void patchPlayerClimbUpdate(ILContext il) {
}
}

private static void onPlayerUpdate(On.Celeste.Player.orig_Update orig, Player self) {
bool unduckWouldGoThroughPlatform = self.Ducking && !self.CollideCheck<UpsideDownJumpThru>();
if (unduckWouldGoThroughPlatform) {
Collider bak = self.Collider;
self.Collider = normalHitbox;
unduckWouldGoThroughPlatform = self.CollideCheck<UpsideDownJumpThru>();
self.Collider = bak;
}

orig(self);

if (unduckWouldGoThroughPlatform && !self.Ducking) {
// we just unducked, and are now inside an upside-down jumpthru.
// knock the player down if possible!
while (self.CollideCheck<UpsideDownJumpThru>() && !self.CollideCheck<Solid>(self.Position + new Vector2(0f, 1f))) {
self.Position.Y++;
}
}
}



Expand Down

0 comments on commit af83dd7

Please sign in to comment.