diff --git a/GrandmasterHeartSideHelper.cs b/GrandmasterHeartSideHelper.cs index f24567e..e063d3b 100755 --- a/GrandmasterHeartSideHelper.cs +++ b/GrandmasterHeartSideHelper.cs @@ -21,6 +21,7 @@ static class GrandmasterHeartSideHelper { private static ILHook hookLobbyJournal; private static ILHook hookOverworldJournal; private static Hook hookLevelExitToLobby; + private static ILHook hookPoemColors; public static void Load() { Assembly collabUtils = typeof(CollabUtils2.CollabModule).Assembly; @@ -39,6 +40,19 @@ public static void Load() { IL.Celeste.Level.CompleteArea_bool_bool_bool += modLevelComplete; IL.Celeste.OuiChapterPanel.Render += renderOldGMHSCompletionStamp; + + // we are looking for a lambda in Celeste.Mod.CollabUtils2.LobbyHelper.modJournalPoemHeartColors... + // except it is located in Celeste.Mod.CollabUtils2.LobbyHelper.<>c.b__{someRandomNumber}_0. + // find it by bruteforcing it a bit. + Type innerType = collabUtils.GetType("Celeste.Mod.CollabUtils2.LobbyHelper").GetNestedType("<>c", BindingFlags.NonPublic); + for (int i = 0; i < 100; i++) { + MethodInfo innerMethod = innerType.GetMethod($"b__{i}_0", BindingFlags.NonPublic | BindingFlags.Instance); + if (innerMethod != null) { + // found it! + hookPoemColors = new ILHook(innerMethod, modifyGMHSeartColor); + break; + } + } } public static void Unload() { @@ -53,6 +67,9 @@ public static void Unload() { IL.Celeste.Level.CompleteArea_bool_bool_bool -= modLevelComplete; IL.Celeste.OuiChapterPanel.Render -= renderOldGMHSCompletionStamp; + + hookPoemColors?.Dispose(); + hookPoemColors = null; } private static bool modIsHeartSide(Func orig, string sid) { @@ -173,5 +190,22 @@ private static void renderOldGMHSCompletionStamp(ILContext il) { }); } } + + private static void modifyGMHSeartColor(ILContext il) { + ILCursor cursor = new ILCursor(il); + + while (cursor.TryGotoNext(MoveType.After, instr => instr.MatchLdstr("_ZZ_HeartSide_A"), instr => instr.MatchCall("Concat"))) { + Logger.Log("SpringCollab2020/GrandmasterHeartSideHelper", $"Modifying new GMHS heart color at {cursor.Index} in IL for {il.Method.FullName}"); + + cursor.Emit(OpCodes.Ldarg_2); // "poem" argument + cursor.EmitDelegate>((orig, poem) => { + // alter the check so that it matches on the new GMHS like it does for old GMHS. + if (orig == "poem_SpringCollab2020/5-Grandmaster_ZZ_HeartSide_A" && poem == Dialog.Clean("poem_SpringCollab2020_5_Grandmaster_ZZ_NewHeartSide_A")) { + return "poem_SpringCollab2020_5_Grandmaster_ZZ_NewHeartSide_A"; + } + return orig; + }); + } + } } }