Skip to content

Commit

Permalink
Fix "$" not printed in PICO-8
Browse files Browse the repository at this point in the history
  • Loading branch information
WEGFan committed Oct 17, 2021
1 parent 285ed42 commit 382993d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Celeste.Mod.mm/MonoModRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,12 @@ class PatchDeathEffectUpdateAttribute : Attribute { }
[MonoModCustomMethodAttribute(nameof(MonoModRules.PatchMiniTextboxRoutine))]
class PatchMiniTextboxRoutine : Attribute { }

/// <summary>
/// Patches the method to fix "$" not printed in PICO-8.
/// </summary>
[MonoModCustomMethodAttribute(nameof(MonoModRules.PatchEmulatorConstructor))]
class PatchEmulatorConstructorAttribute : Attribute { }

static class MonoModRules {

static bool IsCeleste;
Expand Down Expand Up @@ -2352,6 +2358,21 @@ public static void PatchMiniTextboxRoutine(MethodDefinition method, CustomAttrib
});
}

/// <summary>
/// <inheritdoc cref="MonoMod.PatchEmulatorConstructorAttribute" />
/// </summary>
public static void PatchEmulatorConstructor(ILContext il, CustomAttribute attrib) {
ILCursor cursor = new ILCursor(il);

string fontMap = null;
cursor.GotoNext(MoveType.Before,
instr => instr.MatchLdstr(out fontMap),
instr => instr.MatchStfld("Celeste.Pico8.Emulator", "fontMap"));
// devs forgot to press shift when typing "$" for some reason
fontMap = fontMap.Replace("#4%", "#$%");
cursor.Next.Operand = fontMap;
}

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
3 changes: 3 additions & 0 deletions Celeste.Mod.mm/Patches/Pico8/Emulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ public patch_Emulator(Scene returnTo, int levelX = 0, int levelY = 0)
// no-op. MonoMod ignores this - we only need this to make the compiler shut up.
}

[MonoModIgnore]
[PatchEmulatorConstructor]
public extern void orig_ctor(Scene returnTo, int levelX = 0, int levelY = 0);

[MonoModConstructor]
public void ctor(Scene returnTo, int levelX = 0, int levelY = 0) {
orig_ctor(returnTo, levelX, levelY);
Expand Down

0 comments on commit 382993d

Please sign in to comment.