From 8475b3062cb0c4090f63a22e24e218c0b70d1558 Mon Sep 17 00:00:00 2001 From: "Mr. Baguetter" Date: Tue, 13 Jan 2026 19:05:24 -0600 Subject: [PATCH] LabAPI Port --- AmazingDebugTool.sln | 8 +- .../API/Extensions/LabApiPluginExtensions.cs | 14 +++ .../API/Extensions/QueueExtensions.cs | 19 ++++ AmazingDebugTool/API/Features/LogService.cs | 11 +- AmazingDebugTool/API/Features/SocketServer.cs | 7 +- .../SerializedTargetPlugin.cs | 19 +++- .../SerializedElements/SerializedWelcome.cs | 11 +- AmazingDebugTool/Config.cs | 8 +- AmazingDebugTool/JITDebugTool.csproj | 107 ++++-------------- AmazingDebugTool/Patcher.cs | 38 +++++-- AmazingDebugTool/Plugin.cs | 36 +++++- AmazingDebugTool/Writer.cs | 17 ++- 12 files changed, 177 insertions(+), 118 deletions(-) create mode 100644 AmazingDebugTool/API/Extensions/LabApiPluginExtensions.cs create mode 100644 AmazingDebugTool/API/Extensions/QueueExtensions.cs diff --git a/AmazingDebugTool.sln b/AmazingDebugTool.sln index f0ac1c4..b7b2345 100644 --- a/AmazingDebugTool.sln +++ b/AmazingDebugTool.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.13.35931.197 +# Visual Studio Version 18 +VisualStudioVersion = 18.3.11312.210 d18.3 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JITDebugTool", "AmazingDebugTool\JITDebugTool.csproj", "{5B5B0766-0319-441F-A074-A4F81E2EFEC7}" EndProject @@ -13,8 +13,8 @@ Global Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {5B5B0766-0319-441F-A074-A4F81E2EFEC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5B5B0766-0319-441F-A074-A4F81E2EFEC7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5B5B0766-0319-441F-A074-A4F81E2EFEC7}.Debug|Any CPU.ActiveCfg = LabApi|Any CPU + {5B5B0766-0319-441F-A074-A4F81E2EFEC7}.Debug|Any CPU.Build.0 = LabApi|Any CPU {5B5B0766-0319-441F-A074-A4F81E2EFEC7}.Debug|x64.ActiveCfg = Debug|x64 {5B5B0766-0319-441F-A074-A4F81E2EFEC7}.Debug|x64.Build.0 = Debug|x64 {5B5B0766-0319-441F-A074-A4F81E2EFEC7}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/AmazingDebugTool/API/Extensions/LabApiPluginExtensions.cs b/AmazingDebugTool/API/Extensions/LabApiPluginExtensions.cs new file mode 100644 index 0000000..1638d92 --- /dev/null +++ b/AmazingDebugTool/API/Extensions/LabApiPluginExtensions.cs @@ -0,0 +1,14 @@ +using LabApi.Loader; +using System.Reflection; + +namespace JITDebugTool.API.Extensions +{ + public static class LabApiPluginExtensions + { + public static Assembly GetAssembly(this LabApi.Loader.Features.Plugins.Plugin plugin) + { + PluginLoader.Plugins.TryGetValue(plugin, out var asm); + return asm; + } + } +} diff --git a/AmazingDebugTool/API/Extensions/QueueExtensions.cs b/AmazingDebugTool/API/Extensions/QueueExtensions.cs new file mode 100644 index 0000000..f8b46a1 --- /dev/null +++ b/AmazingDebugTool/API/Extensions/QueueExtensions.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; + +namespace JITDebugTool.API.Extensions +{ + public static class QueueExtensions + { + public static bool TryDequeue(this Queue queue, out T element) + { + if (queue.Count > 0) + { + element = queue.Dequeue(); + return true; + } + + element = default(T); + return false; + } + } +} diff --git a/AmazingDebugTool/API/Features/LogService.cs b/AmazingDebugTool/API/Features/LogService.cs index 7d49e19..230107d 100644 --- a/AmazingDebugTool/API/Features/LogService.cs +++ b/AmazingDebugTool/API/Features/LogService.cs @@ -5,6 +5,9 @@ using System.Threading.Tasks; using WebSocketSharp; using WebSocketSharp.Server; +#if LABAPI +using static JITDebugTool.API.Extensions.QueueExtensions; +#endif namespace JITDebugTool.API.Features { @@ -37,7 +40,7 @@ protected override void OnMessage(MessageEventArgs e) { if (e.Data == "GET_EVENT_CHRONO") { - Exiled.API.Features.Log.Info("GETTING CHRONO v2!"); + Logger.Info("GETTING CHRONO v2!"); try { Task.Run(() => @@ -47,7 +50,7 @@ protected override void OnMessage(MessageEventArgs e) Queue queue = new(Plugin.Instance.writer.fullLogs.ToArray()); Queue methods = new(Plugin.Instance.writer.fullMethods.Values.ToArray()); - Exiled.API.Features.Log.Info($"PREPPING LOGS AS {queue.Count}! ({Plugin.Instance.writer.fullLogs.Count})"); + Logger.Info($"PREPPING LOGS AS {queue.Count}! ({Plugin.Instance.writer.fullLogs.Count})"); while (queue.Count > 0 || methods.Count > 0) { @@ -65,13 +68,13 @@ protected override void OnMessage(MessageEventArgs e) } catch (Exception ex) { - Exiled.API.Features.Log.Error(ex); + Logger.Error(ex); } }); } catch (Exception ex) { - Exiled.API.Features.Log.Error(ex); + Logger.Error(ex); } } else if (e.Data == "SUBSCRIBE") diff --git a/AmazingDebugTool/API/Features/SocketServer.cs b/AmazingDebugTool/API/Features/SocketServer.cs index a14ea91..ef5d0c6 100644 --- a/AmazingDebugTool/API/Features/SocketServer.cs +++ b/AmazingDebugTool/API/Features/SocketServer.cs @@ -1,4 +1,7 @@ -using Exiled.API.Features; +#if EXILED +using Exiled.API.Features; +#endif + using System; using System.Collections.Generic; using System.Linq; @@ -20,7 +23,7 @@ public SocketServer() Server = new WebSocketServer(IPAddress.Parse("0.0.0.0"), Plugin.Instance.Config.SocketPort); Server.AddWebSocketService("/logs"); Server.Start(); - Log.Info($"Socket server is ready and is listening on 0.0.0.0:{Plugin.Instance.Config.SocketPort}"); + Logger.Info($"Socket server is ready and is listening on 0.0.0.0:{Plugin.Instance.Config.SocketPort}"); } public void Stop() diff --git a/AmazingDebugTool/API/SerializedElements/SerializedTargetPlugin.cs b/AmazingDebugTool/API/SerializedElements/SerializedTargetPlugin.cs index 19a5146..82a6b97 100644 --- a/AmazingDebugTool/API/SerializedElements/SerializedTargetPlugin.cs +++ b/AmazingDebugTool/API/SerializedElements/SerializedTargetPlugin.cs @@ -1,19 +1,30 @@ -using Exiled.API.Interfaces; +#if EXILED +using Exiled.API.Interfaces; +#endif + +using JITDebugTool.API.Extensions; namespace JITDebugTool.API.SerializedElements { +#if EXILED internal class SerializedTargetPlugin(IPlugin plugin) +#else + internal class SerializedTargetPlugin(LabApi.Loader.Features.Plugins.Plugin plugin) +#endif { public string Name { get; } = plugin.Name; - +#if EXILED public string Prefix { get; } = plugin.Prefix; +#else + public string Description { get; } = plugin.Description; +#endif public string Author { get; } = plugin.Author; public string Version { get; } = plugin.Version.ToString(); - public string AssemblyName { get; } = plugin.Assembly.FullName; + public string AssemblyName { get; } = plugin.GetAssembly().FullName; - public string AssemblySimpleName { get; } = plugin.Assembly.GetName().Name; + public string AssemblySimpleName { get; } = plugin.GetAssembly().GetName().Name; } } diff --git a/AmazingDebugTool/API/SerializedElements/SerializedWelcome.cs b/AmazingDebugTool/API/SerializedElements/SerializedWelcome.cs index 413c429..8f14292 100644 --- a/AmazingDebugTool/API/SerializedElements/SerializedWelcome.cs +++ b/AmazingDebugTool/API/SerializedElements/SerializedWelcome.cs @@ -1,4 +1,8 @@ -using Exiled.Loader; +#if EXILED +using Exiled.Loader; +#endif + +using LabApi.Features; namespace JITDebugTool.API.SerializedElements { @@ -11,7 +15,10 @@ internal class SerializedWelcome public string TargetPluginName { get; } = Plugin.Instance.Config.Plugin; public bool Exiled { get; } = true; - +#if EXILED public string ExiledVersion { get; } = Loader.Version.ToString(); +#else + public string ExiledVersion { get; } = LabApiProperties.CompiledVersion; +#endif } } diff --git a/AmazingDebugTool/Config.cs b/AmazingDebugTool/Config.cs index fa5f663..63ca640 100644 --- a/AmazingDebugTool/Config.cs +++ b/AmazingDebugTool/Config.cs @@ -1,10 +1,16 @@ -using Exiled.API.Interfaces; +#if EXILED +using Exiled.API.Interfaces; +#endif using System.Collections.Generic; using System.ComponentModel; namespace JITDebugTool { +#if EXILED internal class Config : IConfig +#else + internal class Config +#endif { [Description("Whether the plugin is enabled")] public bool IsEnabled { get; set; } = true; diff --git a/AmazingDebugTool/JITDebugTool.csproj b/AmazingDebugTool/JITDebugTool.csproj index a616f5c..0f723f0 100644 --- a/AmazingDebugTool/JITDebugTool.csproj +++ b/AmazingDebugTool/JITDebugTool.csproj @@ -1,100 +1,41 @@ - - - + + - Debug - AnyCPU - {5B5B0766-0319-441F-A074-A4F81E2EFEC7} + net48 Library - Properties JITDebugTool JITDebugTool - v4.8 - 512 - true 13 + true + 512 + Exiled;LabApi + false - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - + + pdbonly true - bin\Release\ + bin\x64\Release\ TRACE - prompt - 4 - - - true - bin\x64\Debug\ - DEBUG;TRACE - embedded x64 - 13 - prompt + 4 - + + + pdbonly + true bin\x64\Release\ TRACE - true - pdbonly x64 - 13 - prompt + 4 + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 9.8.1 - - - 2.2.2 - - - 13.0.3 - - - 1.0.1 - + + + + + - - \ No newline at end of file + + diff --git a/AmazingDebugTool/Patcher.cs b/AmazingDebugTool/Patcher.cs index d46e2e9..205f5a6 100644 --- a/AmazingDebugTool/Patcher.cs +++ b/AmazingDebugTool/Patcher.cs @@ -1,6 +1,9 @@ -using Exiled.API.Features; +#if EXILED +using Exiled.API.Features; using Exiled.API.Interfaces; using Exiled.Loader; +#endif + using HarmonyLib; using JITDebugTool.API.SerializedElements; using System; @@ -15,8 +18,12 @@ internal class Patcher public readonly Assembly targetAssembly; public readonly IReadOnlyList types; +#if EXILED public readonly IPlugin plugin; +#else + public readonly LabApi.Loader.Features.Plugins.Plugin plugin; +#endif public SerializedPluginData pluginData = null; @@ -29,18 +36,31 @@ internal class Patcher public Patcher(Harmony harmony) { +#if EXILED plugin = Loader.GetPlugin(Plugin.Instance.Config.Plugin); - +#else + plugin = LabApi.Loader.PluginLoader.EnabledPlugins.FirstOrDefault(p => p.Name == Plugin.Instance.Config.Plugin); +#endif if (plugin is null) { - Log.Warn($"ERROR: Plugin {Plugin.Instance.Config.Plugin} not found!"); - Log.Warn($"Available plugins: {string.Join(",", Loader.Plugins.Select(p => p.Name))}"); + Logger.Warn($"ERROR: Plugin {Plugin.Instance.Config.Plugin} not found!"); +#if EXILED + Logger.Warn($"Available plugins: {string.Join(",", Loader.Plugins.Select(p => p.Name))}"); +#else + Logger.Warn($"Available plugins: {string.Join(",", LabApi.Loader.PluginLoader.EnabledPlugins.Select(p => p.Name))}"); +#endif return; } +#if EXILED targetAssembly = plugin.Assembly; - List types = [..plugin.Assembly.GetTypes()]; +#else + LabApi.Loader.PluginLoader.Plugins.TryGetValue(plugin, out var asm); + targetAssembly = asm; + List types = [.. asm.GetTypes()]; +#endif + types.RemoveAll(t => t.IsInterface); types.RemoveAll(t => Plugin.Instance.Config.IgnoreTypes.Contains(t.Name)); types.RemoveAll(t => t.GetCustomAttributes(typeof(HarmonyPatch), false).Any()); // Ignore harmony plz @@ -58,7 +78,7 @@ public void PatchMethods() if (!Plugin.Instance.Config.IgnoreMethods.Contains(method.Name)) PatchMethod(method, type); - Log.Info($"Successfully patched {types.Count} types and {PatchedMethods} methods!"); + Logger.Info($"Successfully patched {types.Count} types and {PatchedMethods} methods!"); pluginData.TotalPatchedMethods = PatchedMethods; } @@ -73,15 +93,15 @@ private void PatchMethod(MethodInfo method, Type type) ); PatchedMethods++; - Log.Info($"Successfully patched method {type.FullName}::{method.Name}() !"); + Logger.Info($"Successfully patched method {type.FullName}::{method.Name}() !"); pluginData.Methods.Add(new(method)); } catch (Exception e) { pluginData.NotPatchedMethods.Add(new(method)); if (e.GetType() == typeof(NotSupportedException)) - Log.Warn($"Wont patch method {type.FullName}{(method.IsStatic ? "::" : ".")}{method.Name}() - not supported!"); + Logger.Warn($"Wont patch method {type.FullName}{(method.IsStatic ? "::" : ".")}{method.Name}() - not supported!"); else - Log.Error($"Wont patch method {type.FullName}{(method.IsStatic ? "::" : ".")}{method.Name}() - Generic exception:\n{e}"); + Logger.Error($"Wont patch method {type.FullName}{(method.IsStatic ? "::" : ".")}{method.Name}() - Generic exception:\n{e}"); } } } diff --git a/AmazingDebugTool/Plugin.cs b/AmazingDebugTool/Plugin.cs index 3547259..6f6380d 100644 --- a/AmazingDebugTool/Plugin.cs +++ b/AmazingDebugTool/Plugin.cs @@ -1,8 +1,17 @@ -using Exiled.API.Enums; +global using Logger = LabApi.Features.Console.Logger; +#if EXILED +using Exiled.API.Enums; using Exiled.API.Features; +#else +using LabApi.Features; +using LabApi.Loader.Features.Plugins; +#endif + using HarmonyLib; using JITDebugTool.API.Features; + using System; +using LabApi.Loader.Features.Plugins.Enums; namespace JITDebugTool { @@ -10,13 +19,18 @@ internal class Plugin : Plugin { public override string Name => "JITDebugTool"; - public override string Prefix => "jit_debug_tool"; - public override string Author => "FoxWorn3365 & UCS Collective"; public override Version Version => new(1, 0, 0); - +#if EXILED public override PluginPriority Priority => PluginPriority.First; + public override string Prefix => "jit_debug_tool"; +#else + public override Version RequiredApiVersion { get; } = LabApiProperties.CurrentVersion; + public override string Description => ":3"; + public override LoadPriority Priority => LoadPriority.Lowest; + +#endif internal static Plugin Instance { get; private set; } @@ -26,7 +40,11 @@ internal class Plugin : Plugin private Harmony _harmony; +#if EXILED public override void OnEnabled() +#else + public override void Enable() +#endif { Instance = this; writer = new(); @@ -38,19 +56,27 @@ public override void OnEnabled() patcher = new(_harmony); patcher.PatchMethods(); - Log.Info("Welcome on JITDebugTool!"); + Logger.Info("Welcome on JITDebugTool!"); +#if EXILED base.OnEnabled(); +#endif } +#if EXILED public override void OnDisabled() +#else + public override void Disable() +#endif { _harmony.UnpatchAll(); _harmony = null; Instance = null; +#if EXILED base.OnDisabled(); +#endif } } } diff --git a/AmazingDebugTool/Writer.cs b/AmazingDebugTool/Writer.cs index c05c451..0900c98 100644 --- a/AmazingDebugTool/Writer.cs +++ b/AmazingDebugTool/Writer.cs @@ -1,8 +1,13 @@ -using System; +#if EXILED +using Exiled.API.Features; +#else +using LabApi.Features.Wrappers; +#endif + +using System; using System.Reflection; using System.Diagnostics; using System.Collections.Concurrent; -using Exiled.API.Features; using JITDebugTool.API.Features; using System.Collections.Generic; using System.Threading.Tasks; @@ -42,13 +47,17 @@ public static void Write(CallEntry entry, object obj, Stopwatch stopwatch, Metho } catch (Exception ex) { - Log.Error(ex); + Logger.Error(ex); } } private async Task Action() { +#if EXILED while (!Round.IsEnded) +#else + while (!Round.IsRoundEnded) +#endif { if (_builder.Count == 0 && _methods.Count == 0) goto rtx; @@ -74,7 +83,7 @@ private async Task Action() } catch (Exception ex) { - Log.Error(ex); + Logger.Error(ex); } rtx: