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.

147 lines
4.8KB

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