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.

CLre_server.cs 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Diagnostics;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6. using CLre_server.API.Tools;
  7. using CLre_server.WebStatus;
  8. using GameNetworkLayer.Shared;
  9. using HarmonyLib;
  10. using Svelto.ECS;
  11. using UnityEngine;
  12. namespace CLre_server
  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. WebServer.Deinit();
  23. harmonyInstance.UnpatchAll();
  24. }
  25. // called when Cardlife starts up
  26. public override void OnApplicationStart()
  27. {
  28. #if DEBUG
  29. FileLog.Reset();
  30. Harmony.DEBUG = true;
  31. // enable CLre debug functionality
  32. AccessToolsWarnings.Enable();
  33. NetServerListener.Enable();
  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(); // log plugins again so they show up in the log, and not just stdout
  42. Fixes.BugfixAttributeUtility.LogBugfixes(); // log bugfixes that are applied
  43. #if DEBUG
  44. // test CLre debug functionality
  45. Type netData = AccessTools.TypeByName("Game.Handhelds.DrawingStateMessage");
  46. NetServerSender.DebugSendMessage(netData, harmonyInstance,
  47. NetServerSender.GetLogMethod(netData));
  48. API.Utility.Logging.MetaLog("Patched SendMessage<Game.Handhelds.DrawingStateMessage>");
  49. netData = AccessTools.TypeByName("Shared.Inventory.HandheldEquipmentRequest");
  50. NetServerSender.DebugSendMessage(netData, harmonyInstance,
  51. NetServerSender.GetLogMethod(netData));
  52. API.Utility.Logging.MetaLog("Patched SendMessage<Shared.Inventory.HandheldEquipmentRequest>");
  53. NetServerListener.DebugReceiveMessage(NetworkDispatcherCode.EACMessageServerToClient,
  54. NetServerListener.Log);
  55. // API debug and testing
  56. API.MainServer.Server.Instance.FrameworkReady += (_, __) => API.Utility.Logging.MetaLog("(!) Server framework ready for business");
  57. API.MainServer.Server.Instance.FrameworkExit += (_, __) => API.Utility.Logging.MetaLog("(!) Server framework shutting down"); // this seems to never happen
  58. API.MainServer.Server.Instance.InitStart += (_, __) => API.Utility.Logging.MetaLog("(!) Server initialising");
  59. API.MainServer.Server.Instance.InitComplete += (_, __) => API.Utility.Logging.MetaLog("(!) Server successfully initialised");
  60. #endif
  61. WebServer.Init();
  62. // Log info
  63. API.Utility.Logging.MetaLog($"{Name} init complete.");
  64. }
  65. private static void LogIPAPlugins()
  66. {
  67. StringBuilder sb = new StringBuilder();
  68. sb.AppendFormat("Running on Unity {0}\n", Application.unityVersion);
  69. sb.AppendFormat("Running on CardLife Server {0} (aka {1})\n", Game.Utilities.VersionReader.GetVersion(), Application.version);
  70. sb.AppendFormat("-----------------------------\n");
  71. sb.AppendFormat("Loading plugins from {0} and found {1}\n", System.IO.Path.Combine(Environment.CurrentDirectory, "Plugins"), IllusionInjector.PluginManager.Plugins.Count());
  72. sb.AppendFormat("-----------------------------\n");
  73. foreach (IllusionPlugin.IPlugin plugin in IllusionInjector.PluginManager.Plugins)
  74. {
  75. sb.AppendFormat(" {0}: {1}\n", plugin.Name, plugin.Version);
  76. }
  77. sb.AppendFormat("-----------------------------\n");
  78. API.Utility.Logging.Log(sb.ToString());
  79. }
  80. public override void OnGUI()
  81. {
  82. if (GUI.Button(new Rect(10, 10, 50, 50), "QUIT"))
  83. {
  84. Application.Quit(); // yeet
  85. }
  86. }
  87. }
  88. }