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.

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