diff --git a/Celeste.Mod.mm/Patches/Player.cs b/Celeste.Mod.mm/Patches/Player.cs index eba189260..360d7171a 100644 --- a/Celeste.Mod.mm/Patches/Player.cs +++ b/Celeste.Mod.mm/Patches/Player.cs @@ -329,6 +329,10 @@ public override void SceneEnd(Scene scene) { [MonoModIgnore] [PatchPlayerApproachMaxMove] private extern int NormalUpdate(); + + [MonoModIgnore] + [PatchPlayerOnSquish] + protected extern override void OnSquish(CollisionData data); } public static class PlayerExt { @@ -404,6 +408,12 @@ class PatchPlayerExplodeLaunchAttribute : Attribute { } [MonoModCustomMethodAttribute(nameof(MonoModRules.PatchPlayerApproachMaxMove))] class PatchPlayerApproachMaxMoveAttribute : Attribute { } + /// + /// Patches the method to skip squish checks for the CassetteFly state + /// + [MonoModCustomMethodAttribute(nameof(MonoModRules.PatchPlayerOnSquish))] + class PatchPlayerOnSquishAttribute : Attribute { } + static partial class MonoModRules { public static void PatchPlayerOrigUpdate(ILContext context, CustomAttribute attrib) { @@ -601,5 +611,27 @@ public static void PatchPlayerApproachMaxMove(ILContext context, CustomAttribute } } } + + public static void PatchPlayerOnSquish(ILContext context, CustomAttribute attrib) { + FieldDefinition f_Player_StateMachine = context.Method.DeclaringType.FindField("StateMachine"); + MethodDefinition m_StateMachine_get_State = f_Player_StateMachine.FieldType.Resolve().FindMethod("System.Int32 get_State()"); + + ILCursor cursor = new ILCursor(context); + ILLabel label = cursor.DefineLabel(); + + /* + Add a cassette fly check at the start of the method: + + if (this.StateMachine.State == StCassetteFly) + + return; + */ + + cursor.EmitLdarg(0); + cursor.EmitLdfld(f_Player_StateMachine); + cursor.EmitCallvirt(m_StateMachine_get_State); + cursor.EmitLdcI4(21); + cursor.EmitBneUn(label); + cursor.EmitRet(); + cursor.MarkLabel(label); + } } }