Unofficial CardLife revival project, pronounced like "celery"
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
3.9KB

  1. using System;
  2. using System.Reflection;
  3. using HarmonyLib;
  4. namespace CLre.API.App
  5. {
  6. public static class Client
  7. {
  8. public static event EventHandler<SetupEventArgs> InitStart
  9. {
  10. add => FrontEnd_SetupContainer_Patch.preSetup += value;
  11. remove => FrontEnd_SetupContainer_Patch.preSetup -= value;
  12. }
  13. public static event EventHandler<SetupEventArgs> LogInitComplete
  14. {
  15. add => FrontEnd_SetupContainer_Patch.postSyncSetup += value;
  16. remove => FrontEnd_SetupContainer_Patch.postSyncSetup -= value;
  17. }
  18. public static event EventHandler<SetupEventArgs> AsynchronousInitComplete
  19. {
  20. add => FrontEndGuiEngine_SetMainMenuEnabled_Patch.preMenuEnabled += value;
  21. remove => FrontEndGuiEngine_SetMainMenuEnabled_Patch.preMenuEnabled -= value;
  22. }
  23. public static event EventHandler<SetupEventArgs> InitComplete
  24. {
  25. add => FrontEndGuiEngine_SetMainMenuEnabled_Patch.postMenuEnabled += value;
  26. remove => FrontEndGuiEngine_SetMainMenuEnabled_Patch.postMenuEnabled -= value;
  27. }
  28. public static event EventHandler<MenuReady> MenuReady
  29. {
  30. add => MenuReadyEngine.menuEngineReady += value;
  31. remove => MenuReadyEngine.menuEngineReady -= value;
  32. }
  33. public static event EventHandler<GameReady> GameReady
  34. {
  35. add => GameReadyEngine.gameEngineReady += value;
  36. remove => GameReadyEngine.gameEngineReady -= value;
  37. }
  38. public static event EventHandler<GameReady> GameFrameworkReady
  39. {
  40. add => GameFrameworkEngine.gameFrameworkReady += value;
  41. remove => GameFrameworkEngine.gameFrameworkReady += value;
  42. }
  43. public static event EventHandler<GameExit> GameFrameworkExit
  44. {
  45. add => GameFrameworkEngine.gameFrameworkExit += value;
  46. remove => GameFrameworkEngine.gameFrameworkExit += value;
  47. }
  48. public static string Version
  49. {
  50. get => Game.Utilities.VersionReader.GetVersion();
  51. }
  52. static Client()
  53. {
  54. new MenuReadyEngine();
  55. new GameReadyEngine();
  56. new GameFrameworkEngine();
  57. }
  58. }
  59. [HarmonyPatch(typeof(FrontEnd.MainFrontEnd), "SetupContainer")]
  60. class FrontEnd_SetupContainer_Patch
  61. {
  62. internal static event EventHandler<SetupEventArgs> postSyncSetup;
  63. internal static event EventHandler<SetupEventArgs> preSetup;
  64. [HarmonyPrefix]
  65. public static void BeforeMethodCall(FrontEnd.MainFrontEnd __instance)
  66. {
  67. if (preSetup != null) preSetup(__instance, new SetupEventArgs { });
  68. }
  69. [HarmonyPostfix]
  70. public static void AfterMethodCall(FrontEnd.MainFrontEnd __instance)
  71. {
  72. if (postSyncSetup != null) postSyncSetup(__instance, new SetupEventArgs { });
  73. }
  74. }
  75. [HarmonyPatch]
  76. class FrontEndGuiEngine_SetMainMenuEnabled_Patch
  77. {
  78. internal static event EventHandler<SetupEventArgs> preMenuEnabled;
  79. internal static event EventHandler<SetupEventArgs> postMenuEnabled;
  80. [HarmonyPrefix]
  81. public static void BeforeMethodCall(object __instance, bool enabled)
  82. {
  83. if (!enabled) return;
  84. if (preMenuEnabled != null) preMenuEnabled(__instance, new SetupEventArgs { });
  85. }
  86. [HarmonyPostfix]
  87. public static void AfterMethodCall(object __instance, bool enabled)
  88. {
  89. if (!enabled) return;
  90. if (postMenuEnabled != null) postMenuEnabled(__instance, new SetupEventArgs { });
  91. }
  92. [HarmonyTargetMethod]
  93. public static MethodBase ReflectToGetMethodBase()
  94. {
  95. return AccessTools.Method("FrontEnd.FrontEndGuiEngine:SetMainMenuEnabled");
  96. }
  97. }
  98. }