Skip to content

Commit 2e7122d

Browse files
authored
Merge pull request #88 from EverestAPI/disable_ice_physics_trigger
Disable Ice Physics Trigger
2 parents a479c8b + cec25a2 commit 2e7122d

File tree

5 files changed

+76
-1
lines changed

5 files changed

+76
-1
lines changed

Ahorn/lang/en_gb.lang

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,6 @@ placements.entities.SpringCollab2020/GroupedTriggerSpikesRight.tooltips.type=Cha
106106
placements.entities.SpringCollab2020/MoveBlockCustomSpeed.tooltips.canSteer=Determines whether the move block can be moved by the player.
107107
placements.entities.SpringCollab2020/MoveBlockCustomSpeed.tooltips.direction=Determines the direction the move block moves in upon activation.
108108
placements.entities.SpringCollab2020/MoveBlockCustomSpeed.tooltips.moveSpeed=The block speed, in pixels per second. Vanilla speeds are 60 for "slow", 75 for "fast".
109+
110+
# Disable Ice Physics Trigger
111+
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

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
}
@@ -22,6 +26,7 @@ public override void Load() {
2226
SidewaysJumpThru.Load();
2327
CrystalBombDetonatorRenderer.Load();
2428
FlagTouchSwitch.Load();
29+
DisableIcePhysicsTrigger.Load();
2530
}
2631

2732
public override void LoadContent(bool firstLoad) {
@@ -42,6 +47,7 @@ public override void Unload() {
4247
SidewaysJumpThru.Unload();
4348
CrystalBombDetonatorRenderer.Unload();
4449
FlagTouchSwitch.Unload();
50+
DisableIcePhysicsTrigger.Unload();
4551
}
4652

4753
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+
}
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.Triggers {
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+
}

0 commit comments

Comments
 (0)