Skip to content

Commit

Permalink
Keep Player Speed.X on StRedDash up transition
Browse files Browse the repository at this point in the history
  • Loading branch information
coloursofnoise committed Sep 20, 2021
1 parent 5894622 commit 6e7eadc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Celeste.Mod.mm/MonoModRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,12 @@ class PatchCassetteBlockAwakeAttribute : Attribute { }
[MonoModCustomMethodAttribute(nameof(MonoModRules.PatchMountainRendererUpdate))]
class PatchMountainRendererUpdate : Attribute { }

/// <summary>
/// Patches the method to only set the player Speed.X if not in the RedDash state.
/// </summary>
[MonoModCustomMethodAttribute(nameof(MonoModRules.PatchPlayerBeforeUpTransition))]
class PatchPlayerBeforeUpTransition: Attribute { }

static class MonoModRules {

static bool IsCeleste;
Expand Down Expand Up @@ -2249,6 +2255,20 @@ public static void PatchMountainRendererUpdate(ILContext context, CustomAttribut
throw new Exception("MountainRenderer failed to patch key presses for keys: " + pressedKeys.Keys);
}

public static void PatchPlayerBeforeUpTransition(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);

cursor.Emit(OpCodes.Ldarg_0);
cursor.Emit(OpCodes.Ldfld, f_Player_StateMachine);
cursor.Emit(OpCodes.Callvirt, m_StateMachine_get_State);
cursor.Emit(OpCodes.Ldc_I4_5);
Instruction target = cursor.Clone().GotoNext(instr => instr.OpCode == OpCodes.Ldarg_0, instr => instr.MatchLdfld("Celeste.Player", "StateMachine")).Next;
cursor.Emit(OpCodes.Beq_S, target);
}

public static void PostProcessor(MonoModder modder) {
// Patch CrushBlock::AttackSequence's first alarm delegate manually because how would you even annotate it?
PatchCrushBlockFirstAlarm(modder.Module.GetType("Celeste.CrushBlock/<>c__DisplayClass41_0").FindMethod("<AttackSequence>b__1"));
Expand Down
4 changes: 4 additions & 0 deletions Celeste.Mod.mm/Patches/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ public override void SceneEnd(Scene scene) {
level = null;
}
}

[MonoModIgnore]
[PatchPlayerBeforeUpTransition]
public new extern void BeforeUpTransition();
}
public static class PlayerExt {

Expand Down

0 comments on commit 6e7eadc

Please sign in to comment.