Skip to content

Commit 1199df4

Browse files
committed
Fix crashes on cassette fly and on squish on Linux
1 parent cd75124 commit 1199df4

File tree

2 files changed

+42
-24
lines changed

2 files changed

+42
-24
lines changed

Entities/BubbleReturnBerry.cs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Celeste.Mod.Entities;
22
using Microsoft.Xna.Framework;
33
using Monocle;
4+
using MonoMod.RuntimeDetour;
45
using System;
56
using System.Collections;
67

@@ -13,13 +14,33 @@ public BubbleReturnBerry(EntityData data, Vector2 position, EntityID gid) : base
1314
}
1415

1516
public static void Load() {
16-
On.Celeste.Player.OnSquish += ModOnSquish;
17+
using (new DetourContext { After = { "*" } }) {
18+
// fix player specific behavior allowing them to go through upside-down jumpthrus.
19+
On.Celeste.Player.ctor += onPlayerConstructor;
20+
}
1721
}
1822

1923
public static void Unload() {
20-
On.Celeste.Player.OnSquish -= ModOnSquish;
21-
}
22-
24+
On.Celeste.Player.ctor -= onPlayerConstructor;
25+
}
26+
27+
private static void onPlayerConstructor(On.Celeste.Player.orig_ctor orig, Player self, Vector2 position, PlayerSpriteMode spriteMode) {
28+
orig(self, position, spriteMode);
29+
30+
Collision originalSquishCallback = self.SquishCallback;
31+
32+
Collision patchedSquishCallback = collisionData => {
33+
// State 21 is the state where the player is located within the Cassette Bubble.
34+
// They shouldn't be squished by moving blocks inside of it, so we prevent that.
35+
if (self.StateMachine.State == 21)
36+
return;
37+
38+
originalSquishCallback(collisionData);
39+
};
40+
41+
self.SquishCallback = patchedSquishCallback;
42+
}
43+
2344
public new void OnPlayer(Player player) {
2445
base.OnPlayer(player);
2546

@@ -29,15 +50,6 @@ public static void Unload() {
2950
}
3051
}
3152

32-
private static void ModOnSquish(On.Celeste.Player.orig_OnSquish orig, Player player, CollisionData data) {
33-
// State 21 is the state where the player is located within the Cassette Bubble.
34-
// They shouldn't be squished by moving blocks inside of it, so we prevent that.
35-
if (player.StateMachine.State == 21)
36-
return;
37-
38-
orig(player, data);
39-
}
40-
4153
private IEnumerator Return(Player player) {
4254
yield return 0.3f;
4355

Entities/SafeRespawnCrumble.cs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
using Monocle;
55
using Celeste.Mod.Entities;
66
using System.Reflection;
7-
7+
using System;
8+
89
/*
910
* Safe Respawn Crumble (Spring Collab 2020)
1011
* https://github.com/EverestAPI/SpringCollab2020/
@@ -16,7 +17,7 @@
1617
* It performs a similar role to Mario Maker's pink block platform,
1718
* which only spawns when a user playtests their level from an aerial position
1819
* and disappears once the user jumps off of it.
19-
*/
20+
*/
2021
namespace Celeste.Mod.SpringCollab2020.Entities {
2122
[Tracked(false)]
2223
[CustomEntity("SpringCollab2020/safeRespawnCrumble")]
@@ -45,7 +46,7 @@ public override void Added(Scene scene) {
4546
outlineTiles.Add(toDraw);
4647
} else {
4748
// Select left, middle, or right
48-
for (int tile = 0; (float)tile < base.Width; tile += 8) {
49+
for (int tile = 0; (float) tile < base.Width; tile += 8) {
4950
int tileTex;
5051
if (tile == 0)
5152
tileTex = 0;
@@ -92,7 +93,7 @@ public override void Added(Scene scene) {
9293
}
9394

9495
private IEnumerator Sequence() {
95-
for (;;) {
96+
for (; ; ) {
9697
// Wait until activated
9798
Collidable = false;
9899
while (!activated)
@@ -153,18 +154,23 @@ private IEnumerator TileFade(float to, List<Image> targetTiles, bool fast = fals
153154

154155
// Bubble and player detection hooks
155156
public static void Load() {
156-
On.Celeste.Player.CassetteFlyEnd += SafeActivatorCasetteFly;
157+
On.Celeste.Player.CassetteFlyCoroutine += SafeActivatorCassetteFly;
157158
On.Celeste.Player.IntroRespawnBegin += SafeActivatorRespawn;
158-
}
159+
}
160+
159161
public static void Unload() {
160-
On.Celeste.Player.CassetteFlyEnd -= SafeActivatorCasetteFly;
162+
On.Celeste.Player.CassetteFlyCoroutine -= SafeActivatorCassetteFly;
161163
On.Celeste.Player.IntroRespawnBegin -= SafeActivatorRespawn;
164+
}
165+
166+
private static IEnumerator SafeActivatorCassetteFly(On.Celeste.Player.orig_CassetteFlyCoroutine orig, Player self) {
167+
IEnumerator origEnum = orig(self);
168+
while (origEnum.MoveNext())
169+
yield return origEnum.Current;
170+
171+
SafeActivate(self, false);
162172
}
163173

164-
private static void SafeActivatorCasetteFly(On.Celeste.Player.orig_CassetteFlyEnd orig, Player self) {
165-
orig(self);
166-
SafeActivate(self, false);
167-
}
168174
private static void SafeActivatorRespawn(On.Celeste.Player.orig_IntroRespawnBegin orig, Player self) {
169175
orig(self);
170176
SafeActivate(self, true);

0 commit comments

Comments
 (0)