private static void AfterMainMenu_AddModCount(UIStateMainMenu __instance) { try { var revision = typeof(UIStateMainMenu).GetProperty("_buildRevisionModule", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(__instance) as UIModuleBuildRevision; var list = Api("mod_list", null) as IEnumerable <string>; if (revision == null || list == null) { return; } Info("Adding to main menu version string"); var loader_ver = new Regex("(?:\\.0){1,2}$").Replace(Api("version", "loader").ToString(), ""); revision.BuildRevisionNumber.text += $", Modnix {loader_ver}, {list.Count()} mods."; } catch (Exception ex) { Error(ex); } }
private static volatile MethodBase DebugConsoleAdder; // DebugConsole method to call. // Save a copy of the main menu, and get mod method through reflection. private static void Postfix(UIStateMainMenu __instance) { try { var asm = Mod.Api?.Invoke("assembly", "Sheepy.DebugConsole") as Assembly; if (asm == null) { return; // Abort if mod is not found. e.g. When using PPML. } MainMenu = __instance; // Vanilla reflection : // DebugConsoleAdder = asm.GetType( "Sheepy.PhoenixPt.DebugConsole.Mod" ).GetMethod( "AfterMainMenu_AddModCount", BindingFlags.NonPublic | BindingFlags.Static ); // Harmony reflection helper : DebugConsoleAdder = AccessTools.Method(asm.GetType("Sheepy.PhoenixPt.DebugConsole.Mod"), "AfterMainMenu_AddModCount"); } catch (Exception ex) { // Log error to Modnix. Modnix will highlight mods with runtime error to help debug. Mod.Api?.Invoke("log error", ex); // "error" specifier is unnecessary, but makes our intention clear. // Duplicate exceptions will be ignored, when it is logged as the solo parameter. } }