Skip to content

Commit f85c4d1

Browse files
authored
Merge pull request #95 from EverestAPI/linux_fix
Work around game crashes on Linux caused by hooking Player.OnCollideV
2 parents 004c60a + f1779cb commit f85c4d1

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

Entities/UpsideDownJumpThru.cs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class UpsideDownJumpThru : JumpThru {
1717

1818
private static FieldInfo actorMovementCounter = typeof(Actor).GetField("movementCounter", BindingFlags.Instance | BindingFlags.NonPublic);
1919
private static FieldInfo playerVarJumpTimer = typeof(Player).GetField("varJumpTimer", BindingFlags.Instance | BindingFlags.NonPublic);
20+
private static FieldInfo playerOnCollideV = typeof(Player).GetField("onCollideV", BindingFlags.Instance | BindingFlags.NonPublic);
2021

2122
private static ILHook playerOrigUpdateHook;
2223

@@ -28,7 +29,7 @@ public static void Load() {
2829
}
2930

3031
// fix player specific behavior allowing them to go through upside-down jumpthrus.
31-
On.Celeste.Player.OnCollideV += onPlayerOnCollideV;
32+
On.Celeste.Player.ctor += onPlayerConstructor;
3233

3334
// block player if they try to climb past an upside-down jumpthru.
3435
IL.Celeste.Player.ClimbUpdate += patchPlayerClimbUpdate;
@@ -43,7 +44,7 @@ public static void Unload() {
4344
On.Celeste.Actor.MoveVExact -= onActorMoveVExact;
4445
On.Celeste.Platform.MoveVExactCollideSolids -= onPlatformMoveVExactCollideSolids;
4546

46-
On.Celeste.Player.OnCollideV -= onPlayerOnCollideV;
47+
On.Celeste.Player.ctor -= onPlayerConstructor;
4748
IL.Celeste.Player.ClimbUpdate -= patchPlayerClimbUpdate;
4849

4950
playerOrigUpdateHook?.Dispose();
@@ -164,19 +165,27 @@ private static bool onPlatformMoveVExactCollideSolids(On.Celeste.Platform.orig_M
164165
return platform != null;
165166
}
166167

167-
private static void onPlayerOnCollideV(On.Celeste.Player.orig_OnCollideV orig, Player self, CollisionData data) {
168-
// we just want to kill a piece of code that executes in these conditions (supposed to push the player left or right when hitting a wall angle).
169-
if (self.StateMachine.State != 19 && self.StateMachine.State != 3 && self.StateMachine.State != 9 && self.Speed.Y < 0
170-
&& self.CollideCheckOutside<UpsideDownJumpThru>(self.Position - Vector2.UnitY)) {
168+
private static void onPlayerConstructor(On.Celeste.Player.orig_ctor orig, Player self, Vector2 position, PlayerSpriteMode spriteMode) {
169+
orig(self, position, spriteMode);
171170

172-
// kill the player's vertical speed.
173-
self.Speed.Y = 0;
171+
Collision originalOnCollideV = (Collision) playerOnCollideV.GetValue(self);
174172

175-
// reset varJumpTimer to prevent a weird "stuck on ceiling" effect.
176-
playerVarJumpTimer.SetValue(self, 0);
177-
}
173+
Collision patchedOnCollideV = collisionData => {
174+
// we just want to kill a piece of code that executes in these conditions (supposed to push the player left or right when hitting a wall angle).
175+
if (self.StateMachine.State != 19 && self.StateMachine.State != 3 && self.StateMachine.State != 9 && self.Speed.Y < 0
176+
&& self.CollideCheckOutside<UpsideDownJumpThru>(self.Position - Vector2.UnitY)) {
177+
178+
// kill the player's vertical speed.
179+
self.Speed.Y = 0;
180+
181+
// reset varJumpTimer to prevent a weird "stuck on ceiling" effect.
182+
playerVarJumpTimer.SetValue(self, 0);
183+
}
184+
185+
originalOnCollideV(collisionData);
186+
};
178187

179-
orig(self, data);
188+
playerOnCollideV.SetValue(self, patchedOnCollideV);
180189
}
181190

182191
private static void filterOutJumpThrusFromCollideChecks(ILContext il) {

0 commit comments

Comments
 (0)