|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- using System;
- using System.Reflection;
- using HarmonyLib;
- using User;
-
- 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 event EventHandler<MenuReady> MenuReady
- {
- add => MenuReadyEngine.menuEngineReady += value;
- remove => MenuReadyEngine.menuEngineReady -= value;
- }
-
- public static event EventHandler<GameReady> GameReady
- {
- add => GameReadyEngine.gameEngineReady += value;
- remove => GameReadyEngine.gameEngineReady -= value;
- }
-
- public static event EventHandler<GameReady> GameFrameworkReady
- {
- add => GameFrameworkEngine.gameFrameworkReady += value;
- remove => GameFrameworkEngine.gameFrameworkReady += value;
- }
-
- public static event EventHandler<GameExit> GameFrameworkExit
- {
- add => GameFrameworkEngine.gameFrameworkExit += value;
- remove => GameFrameworkEngine.gameFrameworkExit += value;
- }
-
- public static event EventHandler<GameJoin> GameJoin
- {
- add => ClientGameJoinSequence_OnUserValidated_Patch.gameJoin += value;
- remove => ClientGameJoinSequence_OnUserValidated_Patch.gameJoin += value;
- }
-
- public static string Version
- {
- get => Game.Utilities.VersionReader.GetVersion();
- }
-
- static Client()
- {
- new MenuReadyEngine();
- new GameReadyEngine();
- new GameFrameworkEngine();
- }
- }
-
- [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");
- }
- }
-
- // TODO patch OnUserValidationFailed as well
- [HarmonyPatch]
- class ClientGameJoinSequence_OnUserValidated_Patch
- {
- internal static event EventHandler<GameJoin> gameJoin;
-
- [HarmonyPostfix]
- public static void AfterMethodCall(object __instance, ref SerializedAccountInfo validated)
- {
- if (gameJoin != null) gameJoin(__instance, new GameJoin
- {
- Success = true,
- Data = validated,
- });
- }
-
- [HarmonyTargetMethod]
- public static MethodBase Target()
- {
- return AccessTools.Method("MultiplayerClient.ClientGameJoinSequence:OnUserValidated");
- }
- }
- }
|