CLre/CLre/CLre.cs

149 lines
5 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using CLre.API.Characters;
using CLre.API.Tools;
using GameNetworkLayer.Shared;
using HarmonyLib;
using Svelto.ECS;
using UnityEngine;
namespace CLre
{
public class CLre : IllusionPlugin.IEnhancedPlugin // the Illusion Plugin Architecture (IPA) will ignore classes that don't implement IPlugin
{
public override string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name;
public override string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString();
internal static Harmony harmonyInstance = null;
internal static bool _isInidicatorActive = true;
internal static string _indicatorMsg = " CLre loading...";
// called when Cardlife shuts down
public override void OnApplicationQuit()
{
harmonyInstance.UnpatchAll();
}
// called when Cardlife starts up
public override void OnApplicationStart()
{
#if DEBUG
FileLog.Reset();
Harmony.DEBUG = true;
// enable CLre debug functionality
AccessToolsWarnings.Enable();
NetClientListener.Enable();
Stopwatch startup = Stopwatch.StartNew();
#endif
// init all Harmony patches in project
harmonyInstance = new Harmony(Name);
harmonyInstance.PatchAll();
// patches for bugs
Fixes.InitLogSooner.Init();
Fixes.MiniScreenHelper.Init();
Fixes.UnderStructureCollider.Init();
// misc
LogIPAPlugins();
Fixes.BugfixAttributeUtility.LogBugfixes();
BuildIndicatorMessage();
API.App.Client.MenuReady += (_, __) => { _isInidicatorActive = false; }; // dismiss CLre msg
// Log info
API.Utility.Logging.MetaLog($"{Name} init complete.");
#if DEBUG
// configure CLre debug functionality
Type netData = AccessTools.TypeByName("Game.Handhelds.DrawingStateMessage");
NetClientSender.DebugSendMessage(netData, harmonyInstance,
NetClientSender.GetLogMethod(netData));
API.Utility.Logging.MetaLog("Patched SendMessage<Game.Handhelds.DrawingStateMessage>");
netData = AccessTools.TypeByName("Shared.Inventory.HandheldEquipmentRequest");
NetClientSender.DebugSendMessage(netData, harmonyInstance,
NetClientSender.GetLogMethod(netData));
API.Utility.Logging.MetaLog("Patched SendMessage<Shared.Inventory.HandheldEquipmentRequest>");
NetClientListener.DebugReceiveMessage(NetworkDispatcherCode.EACMessageServerToClient,
NetClientListener.Log);
// API debug and testing
API.App.Client.InitComplete += (_, __) =>
{
startup.Stop();
API.Utility.Logging.Log($"Startup took {startup.ElapsedMilliseconds}ms");
API.Utility.Logging.Log(
$"EAC has detected code mods? {EasyAntiCheat.Client.Hydra.Runtime.Integrity.Violated}" +
(EasyAntiCheat.Client.Hydra.Runtime.Integrity.Violated
? EasyAntiCheat.Client.Hydra.Runtime.Integrity.ViolationMessage
: ""));
};
API.App.Client.MenuReady += (_, __) => { API.Utility.Logging.MetaLog("Menu engine ready event fired!"); };
API.App.Client.GameReady += (_, __) => { API.Utility.Logging.MetaLog("Game engine ready event fired!"); };
API.App.Client.GameFrameworkReady += (_, __) => { API.Utility.Logging.MetaLog("Game framework ready event fired!"); };
API.App.Client.GameFrameworkExit += (_, __) => { API.Utility.Logging.MetaLog("Game framework exit event fired!"); };
Character c = Character.Local();
c.Superuser = true;
#endif
}
private static void LogIPAPlugins()
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("Running on Unity {0}\n", Application.unityVersion);
sb.AppendFormat("Running on CardLife {0} (aka {1})\n", API.App.Client.Version, Application.version);
sb.AppendFormat("-----------------------------\n");
sb.AppendFormat("Loading plugins from {0} and found {1}\n", System.IO.Path.Combine(Environment.CurrentDirectory, "Plugins"), IllusionInjector.PluginManager.Plugins.Count());
sb.AppendFormat("-----------------------------\n");
foreach (IllusionPlugin.IPlugin plugin in IllusionInjector.PluginManager.Plugins)
{
sb.AppendFormat(" {0}: {1}\n", plugin.Name, plugin.Version);
}
sb.AppendFormat("-----------------------------\n");
API.Utility.Logging.Log(sb.ToString());
}
private void BuildIndicatorMessage()
{
int fixCount = Fixes.BugfixAttributeUtility.Count;
int modCount = IllusionInjector.PluginManager.Plugins.Count();
StringBuilder sb = new StringBuilder();
sb.AppendFormat(" {0} {1}\n", Name, Version);
sb.AppendFormat(" {0} bugfixes, {1} plugins, no frills\n", fixCount, modCount);
#if DEBUG
sb.AppendFormat(" DEBUG version\n");
#endif
#if RELEASE
sb.AppendFormat(" RELEASE version\n");
#endif
sb.AppendFormat(" Starting up...\n");
_indicatorMsg = sb.ToString();
}
public override void OnGUI()
{
// CLre startup inidicator
if (_isInidicatorActive)
{
GUILayout.BeginVertical();
GUILayout.Label(_indicatorMsg);
if (GUILayout.Button("Hide"))
{
_isInidicatorActive = false;
}
GUILayout.EndVertical();
}
}
}
}