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.

88 lines
2.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 string Version
  29. {
  30. get => Game.Utilities.VersionReader.GetVersion();
  31. }
  32. }
  33. public struct SetupEventArgs {}
  34. [HarmonyPatch(typeof(FrontEnd.MainFrontEnd), "SetupContainer")]
  35. class FrontEnd_SetupContainer_Patch
  36. {
  37. internal static event EventHandler<SetupEventArgs> postSyncSetup;
  38. internal static event EventHandler<SetupEventArgs> preSetup;
  39. [HarmonyPrefix]
  40. public static void BeforeMethodCall(FrontEnd.MainFrontEnd __instance)
  41. {
  42. if (preSetup != null) preSetup(__instance, new SetupEventArgs { });
  43. }
  44. [HarmonyPostfix]
  45. public static void AfterMethodCall(FrontEnd.MainFrontEnd __instance)
  46. {
  47. if (postSyncSetup != null) postSyncSetup(__instance, new SetupEventArgs { });
  48. }
  49. }
  50. [HarmonyPatch]
  51. class FrontEndGuiEngine_SetMainMenuEnabled_Patch
  52. {
  53. internal static event EventHandler<SetupEventArgs> preMenuEnabled;
  54. internal static event EventHandler<SetupEventArgs> postMenuEnabled;
  55. [HarmonyPrefix]
  56. public static void BeforeMethodCall(object __instance, bool enabled)
  57. {
  58. if (!enabled) return;
  59. if (preMenuEnabled != null) preMenuEnabled(__instance, new SetupEventArgs { });
  60. }
  61. [HarmonyPostfix]
  62. public static void AfterMethodCall(object __instance, bool enabled)
  63. {
  64. if (!enabled) return;
  65. if (postMenuEnabled != null) postMenuEnabled(__instance, new SetupEventArgs { });
  66. }
  67. [HarmonyTargetMethod]
  68. public static MethodBase ReflectToGetMethodBase()
  69. {
  70. return AccessTools.Method("FrontEnd.FrontEndGuiEngine:SetMainMenuEnabled");
  71. }
  72. }
  73. }