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.

167 lines
5.7KB

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