|
- using System;
- using System.Reflection;
- using HarmonyLib;
-
- namespace CLre.API.App
- {
- public static class Client
- {
- public static event EventHandler<SetupEventArgs> InitStart
- {
- add => FrontEnd_SetupContainer_Patch.preSetup += value;
- remove => FrontEnd_SetupContainer_Patch.preSetup -= value;
- }
-
- public static event EventHandler<SetupEventArgs> LogInitComplete
- {
- add => FrontEnd_SetupContainer_Patch.postSyncSetup += value;
- remove => FrontEnd_SetupContainer_Patch.postSyncSetup -= value;
- }
-
- public static event EventHandler<SetupEventArgs> AsynchronousInitComplete
- {
- add => FrontEndGuiEngine_SetMainMenuEnabled_Patch.preMenuEnabled += value;
- remove => FrontEndGuiEngine_SetMainMenuEnabled_Patch.preMenuEnabled -= value;
- }
-
- public static event EventHandler<SetupEventArgs> 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<SetupEventArgs> postSyncSetup;
-
- internal static event EventHandler<SetupEventArgs> 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<SetupEventArgs> preMenuEnabled;
-
- internal static event EventHandler<SetupEventArgs> 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");
- }
- }
- }
|