Skip to content

Commit 98f4844

Browse files
committed
Added Disable Ice Physics Trigger
1 parent 004c60a commit 98f4844

File tree

5 files changed

+77
-2
lines changed

5 files changed

+77
-2
lines changed

Ahorn/lang/en_gb.lang

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,7 @@ placements.entities.SpringCollab2020/FlagSwitchGate.tooltips.persistent=If enabl
8989
placements.entities.SpringCollab2020/FlagSwitchGate.tooltips.inactiveColor=The gate icon colour when not triggered yet.
9090
placements.entities.SpringCollab2020/FlagSwitchGate.tooltips.activeColor=The gate icon colour when triggered, but the group is not complete yet.
9191
placements.entities.SpringCollab2020/FlagSwitchGate.tooltips.finishColor=The gate icon colour when the group is complete.
92-
placements.entities.SpringCollab2020/FlagSwitchGate.tooltips.sprite=The texture for the gate block.
92+
placements.entities.SpringCollab2020/FlagSwitchGate.tooltips.sprite=The texture for the gate block.
93+
94+
# Disable Ice Physics Trigger
95+
placements.triggers.SpringCollab2020/DisableIcePhysicsTrigger.tooltips.disableIcePhysics=Check to disable ice physics when entering the trigger. Uncheck to enable them again.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module SpringCollab2020DisableIcePhysicsTrigger
2+
3+
using ..Ahorn, Maple
4+
5+
@mapdef Trigger "SpringCollab2020/DisableIcePhysicsTrigger" DisableIcePhysicsTrigger(x::Integer, y::Integer,
6+
width::Integer=Maple.defaultTriggerWidth, height::Integer=Maple.defaultTriggerHeight, disableIcePhysics::Bool=true)
7+
8+
const placements = Ahorn.PlacementDict(
9+
"Disable Ice Physics (Spring Collab 2020)" => Ahorn.EntityPlacement(
10+
DisableIcePhysicsTrigger,
11+
"rectangle"
12+
)
13+
)
14+
15+
end
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using Celeste.Mod.Entities;
2+
using Microsoft.Xna.Framework;
3+
using MonoMod.Cil;
4+
using System;
5+
6+
namespace Celeste.Mod.SpringCollab2020.Entities {
7+
[CustomEntity("SpringCollab2020/DisableIcePhysicsTrigger")]
8+
class DisableIcePhysicsTrigger : Trigger {
9+
public static void Load() {
10+
IL.Celeste.Player.NormalUpdate += modPlayerNormalUpdate;
11+
}
12+
13+
public static void Unload() {
14+
IL.Celeste.Player.NormalUpdate -= modPlayerNormalUpdate;
15+
}
16+
17+
private static void modPlayerNormalUpdate(ILContext il) {
18+
ILCursor cursor = new ILCursor(il);
19+
20+
while (cursor.TryGotoNext(MoveType.After, instr => instr.MatchCallvirt<Level>("get_CoreMode"))) {
21+
Logger.Log("SpringCollab2020/DisableIcePhysicsTrigger", $"Patching ice mode checking at {cursor.Index} in IL for Player.NormalUpdate");
22+
23+
cursor.EmitDelegate<Func<Session.CoreModes, Session.CoreModes>>(coreMode => {
24+
if (SpringCollab2020Module.Instance.Session.IcePhysicsDisabled) {
25+
// pretend there is no core mode, so that the ground is not slippery anymore.
26+
return Session.CoreModes.None;
27+
}
28+
return coreMode;
29+
});
30+
}
31+
}
32+
33+
private bool disableIcePhysics;
34+
35+
public DisableIcePhysicsTrigger(EntityData data, Vector2 offset) : base(data, offset) {
36+
disableIcePhysics = data.Bool("disableIcePhysics", true);
37+
}
38+
39+
public override void OnEnter(Player player) {
40+
base.OnEnter(player);
41+
42+
SpringCollab2020Module.Instance.Session.IcePhysicsDisabled = disableIcePhysics;
43+
}
44+
}
45+
}

SpringCollab2020Module.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
using Celeste.Mod.SpringCollab2020.Entities;
22
using Celeste.Mod.SpringCollab2020.Triggers;
3-
3+
using System;
4+
45
namespace Celeste.Mod.SpringCollab2020 {
56
public class SpringCollab2020Module : EverestModule {
67

78
public static SpringCollab2020Module Instance;
89

10+
public override Type SessionType => typeof(SpringCollab2020Session);
11+
public SpringCollab2020Session Session => (SpringCollab2020Session) _Session;
12+
913
public SpringCollab2020Module() {
1014
Instance = this;
1115
}
@@ -21,6 +25,7 @@ public override void Load() {
2125
BubbleReturnBerry.Load();
2226
SidewaysJumpThru.Load();
2327
CrystalBombDetonatorRenderer.Load();
28+
DisableIcePhysicsTrigger.Load();
2429
}
2530

2631
public override void LoadContent(bool firstLoad) {
@@ -40,6 +45,7 @@ public override void Unload() {
4045
BubbleReturnBerry.Unload();
4146
SidewaysJumpThru.Unload();
4247
CrystalBombDetonatorRenderer.Unload();
48+
DisableIcePhysicsTrigger.Unload();
4349
}
4450

4551
public override void PrepareMapDataProcessors(MapDataFixup context) {

SpringCollab2020Session.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+

2+
namespace Celeste.Mod.SpringCollab2020 {
3+
public class SpringCollab2020Session : EverestModuleSession {
4+
public bool IcePhysicsDisabled { get; set; } = false;
5+
}
6+
}

0 commit comments

Comments
 (0)