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.

172 lines
5.9KB

  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; } = "21Q3 " + 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. Fixes.TerrainModifyReset.Init();
  47. // API init
  48. API.Synergy.ClientHandshakeEngine.Init();
  49. // misc
  50. LogIPAPlugins();
  51. Fixes.BugfixAttributeUtility.LogBugfixes();
  52. BuildIndicatorMessage();
  53. API.App.Client.MenuReady += (_, __) => { _isInidicatorActive = false; }; // dismiss CLre msg
  54. // Log info
  55. API.Utility.Logging.MetaLog($"{Name} init complete.");
  56. #if DEBUG
  57. // configure CLre debug functionality
  58. Type netData = AccessTools.TypeByName("Game.Handhelds.DrawingStateMessage");
  59. NetClientSender.DebugSendMessage(netData, harmonyInstance,
  60. NetClientSender.GetLogMethod(netData));
  61. API.Utility.Logging.MetaLog("Patched SendMessage<Game.Handhelds.DrawingStateMessage>");
  62. netData = AccessTools.TypeByName("Shared.Inventory.HandheldEquipmentRequest");
  63. NetClientSender.DebugSendMessage(netData, harmonyInstance,
  64. NetClientSender.GetLogMethod(netData));
  65. API.Utility.Logging.MetaLog("Patched SendMessage<Shared.Inventory.HandheldEquipmentRequest>");
  66. netData = typeof(API.Synergy.SerializedCLreHandshake);
  67. NetClientSender.DebugSendMessage(netData, harmonyInstance,
  68. NetClientSender.GetLogMethod(netData));
  69. API.Utility.Logging.MetaLog("Patched SendMessage<SerializedCLreHandshake>");
  70. NetClientListener.DebugReceiveMessage(NetworkDispatcherCode.EACMessageServerToClient,
  71. NetClientListener.Log);
  72. NetClientListener.DebugReceiveMessage(API.Synergy.ClientHandshakeEngine.CLre_HANDSHAKE_NETCODE,
  73. NetClientListener.Log);
  74. NetClientListener.DebugReceiveMessage(NetworkDispatcherCode.SendIsPvEToClient,
  75. NetClientListener.Log);
  76. API.Utility.Logging.MetaLog($"Highest NetworkDispatcherCode number is {(int) NetworkDispatcherCode.StructureDestroyed} damn it Photon");
  77. // API debug and testing
  78. API.App.Client.InitComplete += (_, __) =>
  79. {
  80. startup.Stop();
  81. API.Utility.Logging.Log($"Startup took {startup.ElapsedMilliseconds}ms");
  82. API.Utility.Logging.Log(
  83. $"EAC has detected code mods? {EasyAntiCheat.Client.Hydra.Runtime.Integrity.Violated}" +
  84. (EasyAntiCheat.Client.Hydra.Runtime.Integrity.Violated
  85. ? EasyAntiCheat.Client.Hydra.Runtime.Integrity.ViolationMessage
  86. : ""));
  87. };
  88. API.App.Client.MenuReady += (_, __) => { API.Utility.Logging.MetaLog("Menu engine ready event fired!"); };
  89. API.App.Client.GameReady += (_, __) => { API.Utility.Logging.MetaLog("Game engine ready event fired!"); };
  90. API.App.Client.GameFrameworkReady += (_, __) =>
  91. {
  92. API.Utility.Logging.MetaLog("Game framework ready event fired!");
  93. API.Utility.Logging.MetaLog($"PhotonChat Connection Protocol: {PhotonChatUI.Chat.Instance.ConnectionProtocol}");
  94. };
  95. API.App.Client.GameFrameworkExit += (_, __) => { API.Utility.Logging.MetaLog("Game framework exit event fired!"); };
  96. Character c = Character.Local();
  97. c.Superuser = true;
  98. #endif
  99. }
  100. private static void LogIPAPlugins()
  101. {
  102. StringBuilder sb = new StringBuilder();
  103. sb.AppendFormat("Running on Unity {0}\n", Application.unityVersion);
  104. sb.AppendFormat("Running on CardLife {0} (aka {1})\n", API.App.Client.Version, Application.version);
  105. sb.AppendFormat("-----------------------------\n");
  106. sb.AppendFormat("Loading plugins from {0} and found {1}\n", System.IO.Path.Combine(Environment.CurrentDirectory, "Plugins"), IllusionInjector.PluginManager.Plugins.Count());
  107. sb.AppendFormat("-----------------------------\n");
  108. foreach (IllusionPlugin.IPlugin plugin in IllusionInjector.PluginManager.Plugins)
  109. {
  110. sb.AppendFormat(" {0}: {1}\n", plugin.Name, plugin.Version);
  111. }
  112. sb.AppendFormat("-----------------------------\n");
  113. API.Utility.Logging.Log(sb.ToString());
  114. }
  115. private void BuildIndicatorMessage()
  116. {
  117. int fixCount = Fixes.BugfixAttributeUtility.Count;
  118. int modCount = IllusionInjector.PluginManager.Plugins.Count();
  119. StringBuilder sb = new StringBuilder();
  120. sb.AppendFormat(" {0} {1}\n", Name, Version);
  121. sb.AppendFormat(" {0} bugfixes, {1} plugins, no frills\n", fixCount, modCount);
  122. #if DEBUG
  123. sb.AppendFormat(" DEBUG version\n");
  124. #endif
  125. #if RELEASE
  126. sb.AppendFormat(" RELEASE version\n");
  127. #endif
  128. sb.AppendFormat(" Starting up...\n");
  129. _indicatorMsg = sb.ToString();
  130. }
  131. public override void OnGUI()
  132. {
  133. // CLre startup inidicator
  134. if (_isInidicatorActive)
  135. {
  136. GUILayout.BeginVertical();
  137. GUILayout.Label(_indicatorMsg);
  138. if (GUILayout.Button("Hide"))
  139. {
  140. _isInidicatorActive = false;
  141. }
  142. GUILayout.EndVertical();
  143. }
  144. }
  145. }
  146. }