Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cassette fly check to Player.OnSquish #846

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Celeste.Mod.mm/Patches/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -404,6 +408,12 @@ class PatchPlayerExplodeLaunchAttribute : Attribute { }
[MonoModCustomMethodAttribute(nameof(MonoModRules.PatchPlayerApproachMaxMove))]
class PatchPlayerApproachMaxMoveAttribute : Attribute { }

/// <summary>
/// Patches the method to skip squish checks for the CassetteFly state
/// </summary>
[MonoModCustomMethodAttribute(nameof(MonoModRules.PatchPlayerOnSquish))]
class PatchPlayerOnSquishAttribute : Attribute { }

static partial class MonoModRules {

public static void PatchPlayerOrigUpdate(ILContext context, CustomAttribute attrib) {
Expand Down Expand Up @@ -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);
Copy link
Member

@microlith57 microlith57 Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nitpick:

Suggested change
cursor.EmitLdcI4(21);
cursor.EmitLdcI4(21 /* StCassetteFly */);

cursor.EmitBneUn(label);
cursor.EmitRet();
cursor.MarkLabel(label);
}
}
}
Loading