Unofficial CardLife revival project, pronounced like "celery"
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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