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.

116 lines
4.0KB

  1. using System;
  2. using System.Diagnostics;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6. using CLre.API.Characters;
  7. using CLre.API.Tools;
  8. using GameNetworkLayer.Shared;
  9. using HarmonyLib;
  10. using Svelto.ECS;
  11. using UnityEngine;
  12. namespace CLre
  13. {
  14. public class CLre : IllusionPlugin.IEnhancedPlugin // the Illusion Plugin Architecture (IPA) will ignore classes that don't implement IPlugin
  15. {
  16. public override string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name;
  17. public override string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString();
  18. internal static Harmony harmonyInstance = null;
  19. // called when Cardlife shuts down
  20. public override void OnApplicationQuit()
  21. {
  22. harmonyInstance.UnpatchAll();
  23. }
  24. // called when Cardlife starts up
  25. public override void OnApplicationStart()
  26. {
  27. #if DEBUG
  28. FileLog.Reset();
  29. Harmony.DEBUG = true;
  30. // enable CLre debug functionality
  31. AccessToolsWarnings.Enable();
  32. NetClientListener.Enable();
  33. Stopwatch startup = Stopwatch.StartNew();
  34. #endif
  35. // init all Harmony patches in project
  36. harmonyInstance = new Harmony(Name);
  37. harmonyInstance.PatchAll();
  38. // patches for bugs
  39. Fixes.InitLogSooner.Init();
  40. // misc
  41. LogIPAPlugins();
  42. Fixes.BugfixAttributeUtility.LogBugfixes();
  43. // Log info
  44. API.Utility.Logging.MetaLog($"{Name} init complete.");
  45. #if DEBUG
  46. // configure CLre debug functionality
  47. Type netData = AccessTools.TypeByName("Game.Handhelds.DrawingStateMessage");
  48. NetClientSender.DebugSendMessage(netData, harmonyInstance,
  49. NetClientSender.GetLogMethod(netData));
  50. API.Utility.Logging.MetaLog("Patched SendMessage<Game.Handhelds.DrawingStateMessage>");
  51. netData = AccessTools.TypeByName("Shared.Inventory.HandheldEquipmentRequest");
  52. NetClientSender.DebugSendMessage(netData, harmonyInstance,
  53. NetClientSender.GetLogMethod(netData));
  54. API.Utility.Logging.MetaLog("Patched SendMessage<Shared.Inventory.HandheldEquipmentRequest>");
  55. NetClientListener.DebugReceiveMessage(NetworkDispatcherCode.EACMessageServerToClient,
  56. NetClientListener.Log);
  57. // API debug and testing
  58. API.App.Client.InitComplete += (_, __) =>
  59. {
  60. startup.Stop();
  61. API.Utility.Logging.Log($"Startup took {startup.ElapsedMilliseconds}ms");
  62. API.Utility.Logging.Log(
  63. $"EAC has detected code mods? {EasyAntiCheat.Client.Hydra.Runtime.Integrity.Violated}" +
  64. (EasyAntiCheat.Client.Hydra.Runtime.Integrity.Violated
  65. ? EasyAntiCheat.Client.Hydra.Runtime.Integrity.ViolationMessage
  66. : ""));
  67. };
  68. API.App.Client.MenuReady += (_, __) => { API.Utility.Logging.MetaLog("Menu engine ready event fired!"); };
  69. API.App.Client.GameReady += (_, __) => { API.Utility.Logging.MetaLog("Game engine ready event fired!"); };
  70. API.App.Client.GameFrameworkReady += (_, __) => { API.Utility.Logging.MetaLog("Game framework ready event fired!"); };
  71. API.App.Client.GameFrameworkExit += (_, __) => { API.Utility.Logging.MetaLog("Game framework exit event fired!"); };
  72. Character c = Character.Local();
  73. c.Superuser = true;
  74. #endif
  75. }
  76. private static void LogIPAPlugins()
  77. {
  78. StringBuilder sb = new StringBuilder();
  79. sb.AppendFormat("Running on Unity {0}\n", Application.unityVersion);
  80. sb.AppendFormat("Running on CardLife {0} (aka {1})\n", API.App.Client.Version, Application.version);
  81. sb.AppendFormat("-----------------------------\n");
  82. sb.AppendFormat("Loading plugins from {0} and found {1}\n", System.IO.Path.Combine(Environment.CurrentDirectory, "Plugins"), IllusionInjector.PluginManager.Plugins.Count());
  83. sb.AppendFormat("-----------------------------\n");
  84. foreach (IllusionPlugin.IPlugin plugin in IllusionInjector.PluginManager.Plugins)
  85. {
  86. sb.AppendFormat(" {0}: {1}\n", plugin.Name, plugin.Version);
  87. }
  88. sb.AppendFormat("-----------------------------\n");
  89. API.Utility.Logging.Log(sb.ToString());
  90. }
  91. public override void OnGUI()
  92. {
  93. if (GUI.Button(new Rect(10, 10, 50, 50), "TEST"))
  94. {
  95. }
  96. }
  97. }
  98. }