using System; using System.Reflection; using HarmonyLib; namespace CLre.API.App { public static class Client { public static event EventHandler InitStart { add => FrontEnd_SetupContainer_Patch.preSetup += value; remove => FrontEnd_SetupContainer_Patch.preSetup -= value; } public static event EventHandler LogInitComplete { add => FrontEnd_SetupContainer_Patch.postSyncSetup += value; remove => FrontEnd_SetupContainer_Patch.postSyncSetup -= value; } public static event EventHandler AsynchronousInitComplete { add => FrontEndGuiEngine_SetMainMenuEnabled_Patch.preMenuEnabled += value; remove => FrontEndGuiEngine_SetMainMenuEnabled_Patch.preMenuEnabled -= value; } public static event EventHandler InitComplete { add => FrontEndGuiEngine_SetMainMenuEnabled_Patch.postMenuEnabled += value; remove => FrontEndGuiEngine_SetMainMenuEnabled_Patch.postMenuEnabled -= value; } public static string Version { get => Game.Utilities.VersionReader.GetVersion(); } } public struct SetupEventArgs {} [HarmonyPatch(typeof(FrontEnd.MainFrontEnd), "SetupContainer")] class FrontEnd_SetupContainer_Patch { internal static event EventHandler postSyncSetup; internal static event EventHandler preSetup; [HarmonyPrefix] public static void BeforeMethodCall(FrontEnd.MainFrontEnd __instance) { if (preSetup != null) preSetup(__instance, new SetupEventArgs { }); } [HarmonyPostfix] public static void AfterMethodCall(FrontEnd.MainFrontEnd __instance) { if (postSyncSetup != null) postSyncSetup(__instance, new SetupEventArgs { }); } } [HarmonyPatch] class FrontEndGuiEngine_SetMainMenuEnabled_Patch { internal static event EventHandler preMenuEnabled; internal static event EventHandler postMenuEnabled; [HarmonyPrefix] public static void BeforeMethodCall(object __instance, bool enabled) { if (!enabled) return; if (preMenuEnabled != null) preMenuEnabled(__instance, new SetupEventArgs { }); } [HarmonyPostfix] public static void AfterMethodCall(object __instance, bool enabled) { if (!enabled) return; if (postMenuEnabled != null) postMenuEnabled(__instance, new SetupEventArgs { }); } [HarmonyTargetMethod] public static MethodBase ReflectToGetMethodBase() { return AccessTools.Method("FrontEnd.FrontEndGuiEngine:SetMainMenuEnabled"); } } }