From 306179653566a3d4df932050690a471f544d2434 Mon Sep 17 00:00:00 2001 From: PITR Date: Sat, 20 Apr 2024 19:16:35 -0500 Subject: [PATCH] Update 1.4.0 --- ButtplugManager.cs | 101 ++++++++++++++++++++++++------ PluginInfo.cs | 2 +- UKButt.csproj | 4 +- ULTRAKILL/CommandRootHelper.cs | 108 --------------------------------- ULTRAKILL/UKButt.cs | 5 +- lib/plog.dll | Bin 0 -> 11776 bytes 6 files changed, 88 insertions(+), 132 deletions(-) delete mode 100644 ULTRAKILL/CommandRootHelper.cs create mode 100644 lib/plog.dll diff --git a/ButtplugManager.cs b/ButtplugManager.cs index 9f5ff7f..243540f 100644 --- a/ButtplugManager.cs +++ b/ButtplugManager.cs @@ -11,6 +11,7 @@ namespace UKButt public class ButtplugManager : BaseUnityPlugin { public static ButtplugManager Instance; + public static readonly plog.Logger Log = new plog.Logger("UKButt"); public bool emergencyStop = false; private ButtplugClient buttplugClient; @@ -23,6 +24,10 @@ public class ButtplugManager : BaseUnityPlugin private UnscaledTimeSince _unscaledTimeSinceVibes; private UnscaledTimeSince _timeSinceVibes; private UnscaledTimeSince _timeSinceVibeUpdate; + + // Guh guh + private readonly Queue _logQueue = new Queue(); + private readonly Queue _errorLogQueue = new Queue(); private float TimeSinceVibes => PrefsManager.Instance.GetBoolLocal(UKButtProperties.UseUnscaledTime, true) ? (float)_unscaledTimeSinceVibes : (float)_timeSinceVibes; @@ -51,11 +56,17 @@ public class ButtplugManager : BaseUnityPlugin private void Awake() { - Logger.LogInfo("Initializing UKButt"); + gameObject.hideFlags = HideFlags.HideAndDontSave; + } + + private void Start() + { + Log.Info("Initializing UKButt"); Instance = this; // Start at the slowest Linear time. _moveTime = LinearTimeMax; + Log.Info("Patching Game..."); var harmony = HarmonyLib.Harmony.CreateAndPatchAll(typeof(CameraPatch)); harmony.PatchAll(typeof(CameraPatch)); // Intercepts shake calls harmony.PatchAll(typeof(CheatsPatch)); // Adds the bindable emergency stop cheat @@ -68,37 +79,63 @@ private void Awake() harmony.PatchAll(typeof(StyleDescendRank)); // Register the command to the ULTRAKILL console + Log.Info("Registering \"UKButt\" command"); GameConsole.Console.Instance.RegisterCommand(new Commands.UKButt(GameConsole.Console.Instance)); // Connect the buttplug.io client - Task.Run(RestartClient); + Task.Run(ReconnectClient); } - public async void RestartClient() + public void TryRestartClient() { - if (buttplugClient != null) - { - Logger.LogInfo("Disconnecting from Buttplug server"); - await buttplugClient.DisconnectAsync(); - buttplugClient = null; - } + Log.Info("Restarting Buttplug client..."); + Task.Run(ReconnectClient); + } + private Uri GetConnectionUri() + { + return new Uri($"{PrefsManager.Instance.GetStringLocal(UKButtProperties.SocketUri, "ws://localhost:12345")}/buttplug"); + } + + private async Task TryKillClient() + { + if (buttplugClient == null) return; + _logQueue.Enqueue("Disconnecting from Buttplug server..."); + buttplugClient.DeviceAdded -= AddDevice; + buttplugClient.DeviceRemoved -= RemoveDevice; + buttplugClient.ScanningFinished -= ScanningFinished; + buttplugClient.ErrorReceived -= ErrorReceived; + buttplugClient.ServerDisconnect -= ServerDisconnect; + + if (buttplugClient.IsScanning) await buttplugClient.StopScanningAsync(); + if (buttplugClient.Connected) await buttplugClient.DisconnectAsync(); + + buttplugClient = null; + } + + private async Task ReconnectClient() + { + var uri = GetConnectionUri(); + + await TryKillClient(); + buttplugClient = new ButtplugClient("ULTRAKILL"); buttplugClient.DeviceAdded += AddDevice; buttplugClient.DeviceRemoved += RemoveDevice; buttplugClient.ScanningFinished += ScanningFinished; + buttplugClient.ErrorReceived += ErrorReceived; + buttplugClient.ServerDisconnect += ServerDisconnect; - Logger.LogInfo("Connecting to Buttplug server"); - await buttplugClient.ConnectAsync(new ButtplugWebsocketConnectorOptions(new Uri($"{PrefsManager.Instance.GetStringLocal(UKButtProperties.SocketUri, "ws://localhost:12345")}/buttplug"))); - - var startScanningTask = buttplugClient.StartScanningAsync(); + _logQueue.Enqueue("Connecting to Buttplug server..."); try { - await startScanningTask; + await buttplugClient.ConnectAsync(new ButtplugWebsocketConnectorOptions(uri)); + + Task.Run(buttplugClient.StartScanningAsync); } - catch (ButtplugException ex) + catch (Exception ex) { - Logger.LogError($"Scanning failed: {ex.InnerException.Message}"); + _errorLogQueue.Enqueue(ex.ToString()); } } @@ -124,6 +161,21 @@ public static void Tap(bool isMenu = false) private void Update() { + if (_logQueue.Count > 0 || _errorLogQueue.Count > 0) + { + while (_logQueue.Count > 0) + { + var message = _logQueue.Dequeue(); + Log.Info(message); + } + + while (_errorLogQueue.Count > 0) + { + var message = _errorLogQueue.Dequeue(); + Log.Error(message); + } + } + if (buttplugClient == null) return; if (emergencyStop) currentSpeed = 0; @@ -214,19 +266,30 @@ private void UpdateHookArm() private void AddDevice(object sender, DeviceAddedEventArgs args) { - Debug.Log("Device Added: " + args.Device.Name); + _logQueue.Enqueue("Device Added: " + args.Device.Name); connectedDevices.Add(args.Device); } private void RemoveDevice(object sender, DeviceRemovedEventArgs args) { - Debug.Log("Device Removed: " + args.Device.Name); + _logQueue.Enqueue("Device Removed: " + args.Device.Name); connectedDevices.Remove(args.Device); } private void ScanningFinished(object sender, EventArgs args) { - Debug.Log("Scanning Finished"); + _logQueue.Enqueue("Scanning Finished"); + } + + private void ErrorReceived(object sender, ButtplugExceptionEventArgs args) + { + _errorLogQueue.Enqueue("Error: " + args.Exception.Message); + } + + private void ServerDisconnect(object sender, EventArgs args) + { + _logQueue.Enqueue("Server Disconnected"); + Task.Run(TryKillClient); } private void OnDestroy() diff --git a/PluginInfo.cs b/PluginInfo.cs index de4884b..b652771 100644 --- a/PluginInfo.cs +++ b/PluginInfo.cs @@ -4,6 +4,6 @@ internal class PluginInfo { public const string GUID = "dev.pitr.ukbutt"; public const string NAME = "UKButt"; - public const string VERSION = "1.2.0"; + public const string VERSION = "1.4.0"; } } diff --git a/UKButt.csproj b/UKButt.csproj index 5deff59..b3f63b8 100644 --- a/UKButt.csproj +++ b/UKButt.csproj @@ -46,6 +46,9 @@ lib\Newtonsoft.Json.dll + + lib\plog.dll + @@ -87,7 +90,6 @@ - diff --git a/ULTRAKILL/CommandRootHelper.cs b/ULTRAKILL/CommandRootHelper.cs deleted file mode 100644 index 3129145..0000000 --- a/ULTRAKILL/CommandRootHelper.cs +++ /dev/null @@ -1,108 +0,0 @@ -using System.Collections.Generic; -using System.Globalization; -using GameConsole; -using GameConsole.CommandTree; - -namespace UKButt.Commands -{ - public abstract class CommandRootBackport : CommandRoot - { - protected CommandRootBackport(Console con) : base(con) { } - - public abstract override string Name { get; } - public abstract override string Description { get; } - - protected abstract override Branch BuildTree(Console con); - - private const string KeyColor = "#db872c"; - private const string TypeColor = "#879fff"; - private const string ValueColor = "#4ac246"; - - public new Branch BuildPrefsEditor(List pref) => - Leaf("prefs", () => - { - Console.Instance.PrintLine("Available prefs:"); - foreach (var p in pref) - { - var isLocalString = p.Local ? "LOCAL" : string.Empty; - if (p.Type == typeof(int)) - { - string valueString; - if (!PrefsManager.Instance.HasKey(p.Key)) - { - valueString = string.IsNullOrEmpty(p.Default) - ? "NOT SET" - : p.Default; - } - else - { - var currentValue = p.Local - ? PrefsManager.Instance.GetIntLocal(p.Key) - : PrefsManager.Instance.GetInt(p.Key); - valueString = currentValue.ToString(); - } - - Console.Instance.PrintLine( - $"- {p.Key}: {valueString} [int] {isLocalString}"); - } - else if (p.Type == typeof(float)) - { - string valueString; - if (!PrefsManager.Instance.HasKey(p.Key)) - { - valueString = string.IsNullOrEmpty(p.Default) - ? "NOT SET" - : p.Default; - } - else - { - var currentValue = p.Local - ? PrefsManager.Instance.GetFloatLocal(p.Key) - : PrefsManager.Instance.GetFloat(p.Key); - valueString = currentValue.ToString(CultureInfo.InvariantCulture); - } - - Console.Instance.PrintLine( - $"- {p.Key}: {valueString} [float] {isLocalString}"); - } - else if (p.Type == typeof(bool)) - { - string valueString; - if (!PrefsManager.Instance.HasKey(p.Key)) - { - valueString = string.IsNullOrEmpty(p.Default) - ? "NOT SET" - : p.Default; - } - else - { - var currentValue = p.Local - ? PrefsManager.Instance.GetBoolLocal(p.Key) - : PrefsManager.Instance.GetBool(p.Key); - valueString = currentValue ? "True" : "False"; - } - - Console.Instance.PrintLine( - $"- {p.Key}: {valueString} [float] {isLocalString}"); - } - else if (p.Type == typeof(string)) - { - var currentValue = p.Local - ? PrefsManager.Instance.GetStringLocal(p.Key) - : PrefsManager.Instance.GetString(p.Key); - Console.Instance.PrintLine( - $"- {p.Key}: \"{(string.IsNullOrEmpty(currentValue) ? p.Default : currentValue)}\" [float] {isLocalString}"); - } - else - { - Console.Instance.PrintLine($"Pref {p.Key} is type {p.Type.Name} (Unrecognized)"); - } - } - - Console.Instance.PrintLine( - $"You can use `prefs set ` to change a pref"); - Console.Instance.PrintLine( - $"or `prefs set_local ` to change a local pref. (it matters)"); - }); - } -} \ No newline at end of file diff --git a/ULTRAKILL/UKButt.cs b/ULTRAKILL/UKButt.cs index b78b179..a1eb93c 100644 --- a/ULTRAKILL/UKButt.cs +++ b/ULTRAKILL/UKButt.cs @@ -1,11 +1,10 @@ using System.Collections.Generic; -using System.Threading.Tasks; using GameConsole; using GameConsole.CommandTree; namespace UKButt.Commands { - public class UKButt : CommandRootBackport + public class UKButt : CommandRoot { public UKButt(Console con) : base(con) { } public override string Name => "UKButt"; @@ -105,7 +104,7 @@ protected override Branch BuildTree(Console con) }), Leaf("restart_client", () => { - Task.Run(ButtplugManager.Instance.RestartClient); + ButtplugManager.Instance.TryRestartClient(); }) }); diff --git a/lib/plog.dll b/lib/plog.dll new file mode 100644 index 0000000000000000000000000000000000000000..50a1819efbaeae191088c4f7f0f45cdf267ea0e0 GIT binary patch literal 11776 zcmeHNdvqLUb-(l2+4WkMwUR8qWNRfqvX*3_hb`NQVq4mkY}vA{Sc)whC-O)dNgJ(p zl$l+{LPw5*Z2}z3qmV#S9wtC2oHXQ6(&IxZgp#JA!4M3DlR|=N5>8TDUIk7|+oZpH zXLhxYp|tZ7Fq~m_=HKL1n^0iy=zlM3Ji>p3gOrKkH zsrsVQbE&$2Jn2TK9DB?$C!@n=I&Ej7L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