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.

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