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.

149 lines
5.0KB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Text;
  7. using CLre.API.Characters;
  8. using CLre.API.Tools;
  9. using GameNetworkLayer.Shared;
  10. using HarmonyLib;
  11. using Svelto.ECS;
  12. using UnityEngine;
  13. namespace CLre
  14. {
  15. public class CLre : IllusionPlugin.IEnhancedPlugin // the Illusion Plugin Architecture (IPA) will ignore classes that don't implement IPlugin
  16. {
  17. public override string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name;
  18. public override string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString();
  19. internal static Harmony harmonyInstance = null;
  20. internal static bool _isInidicatorActive = true;
  21. internal static string _indicatorMsg = " CLre loading...";
  22. // called when Cardlife shuts down
  23. public override void OnApplicationQuit()
  24. {
  25. harmonyInstance.UnpatchAll();
  26. }
  27. // called when Cardlife starts up
  28. public override void OnApplicationStart()
  29. {
  30. #if DEBUG
  31. FileLog.Reset();
  32. Harmony.DEBUG = true;
  33. // enable CLre debug functionality
  34. AccessToolsWarnings.Enable();
  35. NetClientListener.Enable();
  36. Stopwatch startup = Stopwatch.StartNew();
  37. #endif
  38. // init all Harmony patches in project
  39. harmonyInstance = new Harmony(Name);
  40. harmonyInstance.PatchAll();
  41. // patches for bugs
  42. Fixes.InitLogSooner.Init();
  43. Fixes.MiniScreenHelper.Init();
  44. // misc
  45. LogIPAPlugins();
  46. Fixes.BugfixAttributeUtility.LogBugfixes();
  47. BuildIndicatorMessage();
  48. API.App.Client.MenuReady += (_, __) => { _isInidicatorActive = false; }; // dismiss CLre msg
  49. // Log info
  50. API.Utility.Logging.MetaLog($"{Name} init complete.");
  51. #if DEBUG
  52. // configure CLre debug functionality
  53. Type netData = AccessTools.TypeByName("Game.Handhelds.DrawingStateMessage");
  54. NetClientSender.DebugSendMessage(netData, harmonyInstance,
  55. NetClientSender.GetLogMethod(netData));
  56. API.Utility.Logging.MetaLog("Patched SendMessage<Game.Handhelds.DrawingStateMessage>");
  57. netData = AccessTools.TypeByName("Shared.Inventory.HandheldEquipmentRequest");
  58. NetClientSender.DebugSendMessage(netData, harmonyInstance,
  59. NetClientSender.GetLogMethod(netData));
  60. API.Utility.Logging.MetaLog("Patched SendMessage<Shared.Inventory.HandheldEquipmentRequest>");
  61. NetClientListener.DebugReceiveMessage(NetworkDispatcherCode.EACMessageServerToClient,
  62. NetClientListener.Log);
  63. // API debug and testing
  64. API.App.Client.InitComplete += (_, __) =>
  65. {
  66. startup.Stop();
  67. API.Utility.Logging.Log($"Startup took {startup.ElapsedMilliseconds}ms");
  68. API.Utility.Logging.Log(
  69. $"EAC has detected code mods? {EasyAntiCheat.Client.Hydra.Runtime.Integrity.Violated}" +
  70. (EasyAntiCheat.Client.Hydra.Runtime.Integrity.Violated
  71. ? EasyAntiCheat.Client.Hydra.Runtime.Integrity.ViolationMessage
  72. : ""));
  73. };
  74. API.App.Client.MenuReady += (_, __) => { API.Utility.Logging.MetaLog("Menu engine ready event fired!"); };
  75. API.App.Client.GameReady += (_, __) => { API.Utility.Logging.MetaLog("Game engine ready event fired!"); };
  76. API.App.Client.GameFrameworkReady += (_, __) => { API.Utility.Logging.MetaLog("Game framework ready event fired!"); };
  77. API.App.Client.GameFrameworkExit += (_, __) => { API.Utility.Logging.MetaLog("Game framework exit event fired!"); };
  78. Character c = Character.Local();
  79. c.Superuser = true;
  80. #endif
  81. }
  82. private static void LogIPAPlugins()
  83. {
  84. StringBuilder sb = new StringBuilder();
  85. sb.AppendFormat("Running on Unity {0}\n", Application.unityVersion);
  86. sb.AppendFormat("Running on CardLife {0} (aka {1})\n", API.App.Client.Version, Application.version);
  87. sb.AppendFormat("-----------------------------\n");
  88. sb.AppendFormat("Loading plugins from {0} and found {1}\n", System.IO.Path.Combine(Environment.CurrentDirectory, "Plugins"), IllusionInjector.PluginManager.Plugins.Count());
  89. sb.AppendFormat("-----------------------------\n");
  90. foreach (IllusionPlugin.IPlugin plugin in IllusionInjector.PluginManager.Plugins)
  91. {
  92. sb.AppendFormat(" {0}: {1}\n", plugin.Name, plugin.Version);
  93. }
  94. sb.AppendFormat("-----------------------------\n");
  95. API.Utility.Logging.Log(sb.ToString());
  96. }
  97. private void BuildIndicatorMessage()
  98. {
  99. int fixCount = Fixes.BugfixAttributeUtility.Count;
  100. int modCount = IllusionInjector.PluginManager.Plugins.Count();
  101. StringBuilder sb = new StringBuilder();
  102. sb.AppendFormat(" {0} {1}\n", Name, Version);
  103. sb.AppendFormat("{0} bugfixes, {1} plugins, no frills\n", fixCount, modCount);
  104. #if DEBUG
  105. sb.AppendFormat(" DEBUG version\n");
  106. #endif
  107. #if RELEASE
  108. sb.AppendFormat(" RELEASE version\n");
  109. #endif
  110. sb.AppendFormat(" Starting up...\n");
  111. _indicatorMsg = sb.ToString();
  112. }
  113. public override void OnGUI()
  114. {
  115. // CLre startup inidicator
  116. if (_isInidicatorActive)
  117. {
  118. GUILayout.BeginVertical();
  119. GUILayout.Label(_indicatorMsg);
  120. if (GUILayout.Button("Hide"))
  121. {
  122. _isInidicatorActive = false;
  123. }
  124. GUILayout.EndVertical();
  125. }
  126. }
  127. }
  128. }