Skip to content

Commit 709d3e1

Browse files
committed
Fix new GMHS heart color being incorrect in overworld journal poem page
1 parent 37250e1 commit 709d3e1

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

GrandmasterHeartSideHelper.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ static class GrandmasterHeartSideHelper {
2121
private static ILHook hookLobbyJournal;
2222
private static ILHook hookOverworldJournal;
2323
private static Hook hookLevelExitToLobby;
24+
private static ILHook hookPoemColors;
2425

2526
public static void Load() {
2627
Assembly collabUtils = typeof(CollabUtils2.CollabModule).Assembly;
@@ -39,6 +40,19 @@ public static void Load() {
3940

4041
IL.Celeste.Level.CompleteArea_bool_bool_bool += modLevelComplete;
4142
IL.Celeste.OuiChapterPanel.Render += renderOldGMHSCompletionStamp;
43+
44+
// we are looking for a lambda in Celeste.Mod.CollabUtils2.LobbyHelper.modJournalPoemHeartColors...
45+
// except it is located in Celeste.Mod.CollabUtils2.LobbyHelper.<>c.<modJournalPoemHeartColors>b__{someRandomNumber}_0.
46+
// find it by bruteforcing it a bit.
47+
Type innerType = collabUtils.GetType("Celeste.Mod.CollabUtils2.LobbyHelper").GetNestedType("<>c", BindingFlags.NonPublic);
48+
for (int i = 0; i < 100; i++) {
49+
MethodInfo innerMethod = innerType.GetMethod($"<modJournalPoemHeartColors>b__{i}_0", BindingFlags.NonPublic | BindingFlags.Instance);
50+
if (innerMethod != null) {
51+
// found it!
52+
hookPoemColors = new ILHook(innerMethod, modifyGMHSeartColor);
53+
break;
54+
}
55+
}
4256
}
4357

4458
public static void Unload() {
@@ -53,6 +67,9 @@ public static void Unload() {
5367

5468
IL.Celeste.Level.CompleteArea_bool_bool_bool -= modLevelComplete;
5569
IL.Celeste.OuiChapterPanel.Render -= renderOldGMHSCompletionStamp;
70+
71+
hookPoemColors?.Dispose();
72+
hookPoemColors = null;
5673
}
5774

5875
private static bool modIsHeartSide(Func<string, bool> orig, string sid) {
@@ -173,5 +190,22 @@ private static void renderOldGMHSCompletionStamp(ILContext il) {
173190
});
174191
}
175192
}
193+
194+
private static void modifyGMHSeartColor(ILContext il) {
195+
ILCursor cursor = new ILCursor(il);
196+
197+
while (cursor.TryGotoNext(MoveType.After, instr => instr.MatchLdstr("_ZZ_HeartSide_A"), instr => instr.MatchCall<string>("Concat"))) {
198+
Logger.Log("SpringCollab2020/GrandmasterHeartSideHelper", $"Modifying new GMHS heart color at {cursor.Index} in IL for {il.Method.FullName}");
199+
200+
cursor.Emit(OpCodes.Ldarg_2); // "poem" argument
201+
cursor.EmitDelegate<Func<string, string, string>>((orig, poem) => {
202+
// alter the check so that it matches on the new GMHS like it does for old GMHS.
203+
if (orig == "poem_SpringCollab2020/5-Grandmaster_ZZ_HeartSide_A" && poem == Dialog.Clean("poem_SpringCollab2020_5_Grandmaster_ZZ_NewHeartSide_A")) {
204+
return "poem_SpringCollab2020_5_Grandmaster_ZZ_NewHeartSide_A";
205+
}
206+
return orig;
207+
});
208+
}
209+
}
176210
}
177211
}

0 commit comments

Comments
 (0)