|
| 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