diff --git a/QSB/Anglerfish/TransformSync/AnglerTransformSync.cs b/QSB/Anglerfish/TransformSync/AnglerTransformSync.cs index 7b0dd4b8..6bd58767 100644 --- a/QSB/Anglerfish/TransformSync/AnglerTransformSync.cs +++ b/QSB/Anglerfish/TransformSync/AnglerTransformSync.cs @@ -64,7 +64,7 @@ public class AnglerTransformSync : UnsectoredRigidbodySync, ILinkedNetworkBehavi protected override void OnRenderObject() { - if (!QSBCore.DrawLines + if (!QSBCore.DebugSettings.DrawLines || !IsValid || !ReferenceTransform || !AttachedTransform.gameObject.activeInHierarchy) diff --git a/QSB/Animation/Player/Thrusters/RemoteThrusterFlameController.cs b/QSB/Animation/Player/Thrusters/RemoteThrusterFlameController.cs index 551349b6..835fb0b7 100644 --- a/QSB/Animation/Player/Thrusters/RemoteThrusterFlameController.cs +++ b/QSB/Animation/Player/Thrusters/RemoteThrusterFlameController.cs @@ -105,7 +105,7 @@ public class RemoteThrusterFlameController : MonoBehaviour private void OnRenderObject() { - if (!QSBCore.DrawLines || !QSBWorldSync.AllObjectsReady) + if (!QSBCore.DebugSettings.DrawLines || !QSBWorldSync.AllObjectsReady) { return; } diff --git a/QSB/HUD/MultiplayerHUDManager.cs b/QSB/HUD/MultiplayerHUDManager.cs index bce6cfbe..37886cd7 100644 --- a/QSB/HUD/MultiplayerHUDManager.cs +++ b/QSB/HUD/MultiplayerHUDManager.cs @@ -230,7 +230,7 @@ public class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart previousMessages.Push(message); - if (QSBCore.DebugMode && CommandInterpreter.InterpretCommand(message)) + if (QSBCore.DebugSettings.DebugMode && CommandInterpreter.InterpretCommand(message)) { return; } diff --git a/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs b/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs index 02b9389b..a389a920 100644 --- a/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs +++ b/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs @@ -88,7 +88,7 @@ public class JellyfishTransformSync : UnsectoredRigidbodySync, ILinkedNetworkBeh protected override void OnRenderObject() { - if (!QSBCore.DrawLines + if (!QSBCore.DebugSettings.DrawLines || !IsValid || !ReferenceTransform || !AttachedTransform.gameObject.activeInHierarchy) diff --git a/QSB/Menus/MenuManager.cs b/QSB/Menus/MenuManager.cs index 891487c7..865852a4 100644 --- a/QSB/Menus/MenuManager.cs +++ b/QSB/Menus/MenuManager.cs @@ -71,7 +71,7 @@ public class MenuManager : MonoBehaviour, IAddComponentOnStart QSBLocalization.LanguageChanged += OnLanguageChanged; - if (QSBCore.AutoStart) + if (QSBCore.DebugSettings.AutoStart) { // auto host/connect Delay.RunWhen(PlayerData.IsLoaded, () => diff --git a/QSB/Messaging/QSBMessageManager.cs b/QSB/Messaging/QSBMessageManager.cs index 0b8cb43d..c4be56f9 100644 --- a/QSB/Messaging/QSBMessageManager.cs +++ b/QSB/Messaging/QSBMessageManager.cs @@ -49,7 +49,7 @@ public static class QSBMessageManager NetworkServer.RegisterHandler((_, wrapper) => OnServerReceive(wrapper)); NetworkClient.RegisterHandler(wrapper => OnClientReceive(wrapper)); - if (!QSBCore.LogQSBMessages) + if (!QSBCore.DebugSettings.LogQSBMessages) { return; } @@ -169,7 +169,7 @@ public static class QSBMessageManager public static void SaveRXTX(QSBMessage msg, bool transmit) { - if (!QSBCore.LogQSBMessages) + if (!QSBCore.DebugSettings.LogQSBMessages) { return; } diff --git a/QSB/Player/TransformSync/PlayerTransformSync.cs b/QSB/Player/TransformSync/PlayerTransformSync.cs index 329a0b22..27f79e29 100644 --- a/QSB/Player/TransformSync/PlayerTransformSync.cs +++ b/QSB/Player/TransformSync/PlayerTransformSync.cs @@ -111,7 +111,7 @@ public class PlayerTransformSync : SectoredTransformSync protected override void OnRenderObject() { - if (!QSBCore.DrawLines + if (!QSBCore.DebugSettings.DrawLines || !IsValid || !ReferenceTransform) { diff --git a/QSB/QSBCore.cs b/QSB/QSBCore.cs index 4de146d6..d0aa5f3f 100644 --- a/QSB/QSBCore.cs +++ b/QSB/QSBCore.cs @@ -24,6 +24,7 @@ using QSB.Player.Messages; using UnityEngine; using UnityEngine.InputSystem; using QSB.Utility.Deterministic; +using Debug = System.Diagnostics.Debug; /* Copyright (C) 2020 - 2025 @@ -74,43 +75,12 @@ public class QSBCore : ModBehaviour public static string JetpackVariation { get; private set; } = "Orange"; public static int Timeout { get; private set; } - public static bool DebugMode { get; private set; } - - private static bool _instanceIdInLogs; - public static bool InstanceIDInLogs => DebugMode && _instanceIdInLogs; - - private static bool _hookDebugLogs; - public static bool HookDebugLogs => DebugMode && _hookDebugLogs; - - private static bool _avoidTimeSync; - public static bool AvoidTimeSync => DebugMode && _avoidTimeSync; - - private static bool _autoStart; - public static bool AutoStart => DebugMode && _autoStart; - - private static bool _drawGUI; - public static bool DrawGUI => DebugMode && _drawGUI; - - private static bool _drawLines; - public static bool DrawLines => DebugMode && _drawLines; - - private static bool _drawLabels; - public static bool DrawLabels => DebugMode && _drawLabels; - - private static bool _greySkybox; - public static bool GreySkybox => DebugMode && _greySkybox; - - private static float _latencySimulation; - public static float LatencySimulation => DebugMode ? _latencySimulation : 0; - - private static bool _logQSBMessages; - public static bool LogQSBMessages => DebugMode && _logQSBMessages; - public static GameVendor GameVendor { get; private set; } = GameVendor.None; public static bool IsStandalone => GameVendor is GameVendor.Epic or GameVendor.Steam; public static IProfileManager ProfileManager => IsStandalone ? QSBStandaloneProfileManager.SharedInstance : QSBMSStoreProfileManager.SharedInstance; + public static DebugSettings DebugSettings { get; private set; } public static Assembly QSBNHAssembly = null; @@ -247,7 +217,7 @@ public class QSBCore : ModBehaviour CheckNewHorizons(); - if (HookDebugLogs) + if (DebugSettings.HookDebugLogs) { Application.logMessageReceived += (condition, stackTrace, logType) => DebugLog.ToConsole( @@ -265,7 +235,7 @@ public class QSBCore : ModBehaviour ); } - if (AutoStart) + if (DebugSettings.AutoStart) { UseKcpTransport = true; } @@ -416,29 +386,18 @@ public class QSBCore : ModBehaviour public override void Configure(IModConfig config) { - DebugMode = config.GetSettingsValue("debugMode"); + DebugSettings = new DebugSettings(config); if (GetComponent() != null) { - GetComponent().enabled = DebugMode; - GetComponent().enabled = DebugMode; + GetComponent().enabled = DebugSettings.DebugMode; + GetComponent().enabled = DebugSettings.DebugMode; } - _instanceIdInLogs = config.GetSettingsValue("instanceIdInLogs"); - _hookDebugLogs = config.GetSettingsValue("hookDebugLogs"); - _avoidTimeSync = config.GetSettingsValue("avoidTimeSync"); - _autoStart = config.GetSettingsValue("autoStart"); - _drawGUI = config.GetSettingsValue("drawGui"); - _drawLines = config.GetSettingsValue("drawLines"); - _drawLabels = config.GetSettingsValue("drawLabels"); - _greySkybox = config.GetSettingsValue("greySkybox"); - _latencySimulation = config.GetSettingsValue("latencySimulation"); - _logQSBMessages = config.GetSettingsValue("logQSBMessages"); - DebugCameraSettings.UpdateFromDebugSetting(); Timeout = config.GetSettingsValue("timeout"); - UseKcpTransport = config.GetSettingsValue("useKcpTransport") || AutoStart; + UseKcpTransport = config.GetSettingsValue("useKcpTransport") || DebugSettings.AutoStart; var foundValue = config.GetSettingsValue("kcpPort"); KcpPort = (ushort)Mathf.Clamp(foundValue, ushort.MinValue, ushort.MaxValue); QSBNetworkManager.UpdateTransport(); @@ -470,13 +429,13 @@ public class QSBCore : ModBehaviour { if (Keyboard.current[Key.Q].isPressed && Keyboard.current[Key.NumpadEnter].wasPressedThisFrame) { - DebugMode = !DebugMode; + DebugSettings.DebugMode = !DebugSettings.DebugMode; - GetComponent().enabled = DebugMode; - GetComponent().enabled = DebugMode; + GetComponent().enabled = DebugSettings.DebugMode; + GetComponent().enabled = DebugSettings.DebugMode; DebugCameraSettings.UpdateFromDebugSetting(); - DebugLog.ToConsole($"DEBUG MODE = {DebugMode}"); + DebugLog.ToConsole($"DEBUG MODE = {DebugSettings.DebugMode}"); } if (_steamworksInitialized) diff --git a/QSB/QSBNetworkManager.cs b/QSB/QSBNetworkManager.cs index 9c119bf9..4171628f 100644 --- a/QSB/QSBNetworkManager.cs +++ b/QSB/QSBNetworkManager.cs @@ -91,11 +91,11 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart { _latencyTransport = gameObject.AddComponent(); - _latencyTransport.reliableLatency = _latencyTransport.unreliableLatency = QSBCore.LatencySimulation; + _latencyTransport.reliableLatency = _latencyTransport.unreliableLatency = QSBCore.DebugSettings.LatencySimulation; _latencyTransport.wrap = QSBCore.UseKcpTransport ? _kcpTransport : _steamTransport; } - transport = QSBCore.LatencySimulation > 0 + transport = QSBCore.DebugSettings.LatencySimulation > 0 ? _latencyTransport : QSBCore.UseKcpTransport ? _kcpTransport : _steamTransport; @@ -176,7 +176,7 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart if (singleton != null) { - if (QSBCore.LatencySimulation > 0) + if (QSBCore.DebugSettings.LatencySimulation > 0) { _latencyTransport.wrap = QSBCore.UseKcpTransport ? _kcpTransport : _steamTransport; singleton.transport = Transport.active = _latencyTransport; diff --git a/QSB/QuantumSync/QuantumManager.cs b/QSB/QuantumSync/QuantumManager.cs index c744759e..6769ccd5 100644 --- a/QSB/QuantumSync/QuantumManager.cs +++ b/QSB/QuantumSync/QuantumManager.cs @@ -56,7 +56,7 @@ public class QuantumManager : WorldObjectManager public void OnRenderObject() { - if (!QSBCore.DrawLines) + if (!QSBCore.DebugSettings.DrawLines) { return; } diff --git a/QSB/Syncs/SyncBase.cs b/QSB/Syncs/SyncBase.cs index f9672a93..c024455f 100644 --- a/QSB/Syncs/SyncBase.cs +++ b/QSB/Syncs/SyncBase.cs @@ -309,7 +309,7 @@ public abstract class SyncBase : QSBNetworkTransform protected virtual void OnRenderObject() { - if (!QSBCore.DrawLines + if (!QSBCore.DebugSettings.DrawLines || !IsValid || !ReferenceTransform) { @@ -334,7 +334,7 @@ public abstract class SyncBase : QSBNetworkTransform private void OnGUI() { - if (!QSBCore.DrawLabels + if (!QSBCore.DebugSettings.DrawLabels || Event.current.type != EventType.Repaint || !IsValid || !ReferenceTransform) diff --git a/QSB/TimeSync/WakeUpSync.cs b/QSB/TimeSync/WakeUpSync.cs index c6663480..a04af356 100644 --- a/QSB/TimeSync/WakeUpSync.cs +++ b/QSB/TimeSync/WakeUpSync.cs @@ -124,7 +124,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart } else { - if (!QSBCore.AvoidTimeSync) + if (!QSBCore.DebugSettings.AvoidTimeSync) { WakeUpOrSleep(); } @@ -275,7 +275,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart { UpdateServer(); } - else if (NetworkClient.active && QSBSceneManager.IsInUniverse && !QSBCore.AvoidTimeSync) + else if (NetworkClient.active && QSBSceneManager.IsInUniverse && !QSBCore.DebugSettings.AvoidTimeSync) { UpdateClient(); } diff --git a/QSB/Tools/TranslatorTool/QSBTranslatorScanBeam.cs b/QSB/Tools/TranslatorTool/QSBTranslatorScanBeam.cs index 952aee2b..4591349f 100644 --- a/QSB/Tools/TranslatorTool/QSBTranslatorScanBeam.cs +++ b/QSB/Tools/TranslatorTool/QSBTranslatorScanBeam.cs @@ -80,7 +80,7 @@ public class QSBTranslatorScanBeam : MonoBehaviour private void OnRenderObject() { - if (!QSBCore.DrawLines || !QSBWorldSync.AllObjectsReady) + if (!QSBCore.DebugSettings.DrawLines || !QSBWorldSync.AllObjectsReady) { return; } diff --git a/QSB/Utility/CommandInterpreter.cs b/QSB/Utility/CommandInterpreter.cs index 2f67378e..ee4a7ce8 100644 --- a/QSB/Utility/CommandInterpreter.cs +++ b/QSB/Utility/CommandInterpreter.cs @@ -60,7 +60,7 @@ public class CommandInterpreter : MonoBehaviour, IAddComponentOnStart public static void ShipCommand(string[] arguments) { - if (!QSBCore.DebugMode) + if (!QSBCore.DebugSettings.DebugMode) { return; } diff --git a/QSB/Utility/DebugActions.cs b/QSB/Utility/DebugActions.cs index 87b74de2..1cf23019 100644 --- a/QSB/Utility/DebugActions.cs +++ b/QSB/Utility/DebugActions.cs @@ -45,7 +45,7 @@ public class DebugActions : MonoBehaviour, IAddComponentOnStart private static void DamageShipElectricalSystem() => ShipManager.Instance.ShipElectricalComponent.SetDamaged(true); - private void Awake() => enabled = QSBCore.DebugMode; + private void Awake() => enabled = QSBCore.DebugSettings.DebugMode; private int _otherPlayerToTeleportTo; private int _backTimer; diff --git a/QSB/Utility/DebugCameraSettings.cs b/QSB/Utility/DebugCameraSettings.cs index b459b7b8..c05816fb 100644 --- a/QSB/Utility/DebugCameraSettings.cs +++ b/QSB/Utility/DebugCameraSettings.cs @@ -12,7 +12,7 @@ public class DebugCameraSettings : MonoBehaviour, IAddComponentOnStart Camera.main.backgroundColor = _origColor; } - if (!QSBCore.GreySkybox) + if (QSBCore.DebugSettings == null || !QSBCore.DebugSettings.GreySkybox) { return; } diff --git a/QSB/Utility/DebugGUI.cs b/QSB/Utility/DebugGUI.cs index 5e0e9c16..fc6afc04 100644 --- a/QSB/Utility/DebugGUI.cs +++ b/QSB/Utility/DebugGUI.cs @@ -37,7 +37,7 @@ public class DebugGUI : MonoBehaviour, IAddComponentOnStart private void Awake() { - enabled = QSBCore.DebugMode; + enabled = QSBCore.DebugSettings.DebugMode; guiGUIStyle.fontSize = 9; } @@ -105,7 +105,7 @@ public class DebugGUI : MonoBehaviour, IAddComponentOnStart WriteLine(1, $"FPS : {Mathf.Round(1f / Time.smoothDeltaTime)}"); WriteLine(1, $"Ping : {Math.Round(NetworkTime.rtt * 1000.0)} ms"); - if (!QSBCore.DrawGUI) + if (!QSBCore.DebugSettings.DrawGUI) { return; } @@ -408,7 +408,7 @@ public class DebugGUI : MonoBehaviour, IAddComponentOnStart private static void DrawWorldObjectLabels() { - if (QSBCore.DrawLabels) + if (QSBCore.DebugSettings.DrawLabels) { var list = DebugActions.WorldObjectSelection == null ? QSBWorldSync.GetWorldObjects() @@ -428,7 +428,7 @@ public class DebugGUI : MonoBehaviour, IAddComponentOnStart private static void DrawWorldObjectLines() { - if (QSBCore.DrawLines) + if (QSBCore.DebugSettings.DrawLines) { var list = DebugActions.WorldObjectSelection == null ? QSBWorldSync.GetWorldObjects() diff --git a/QSB/Utility/DebugLog.cs b/QSB/Utility/DebugLog.cs index f5a429b7..1b64b7fa 100644 --- a/QSB/Utility/DebugLog.cs +++ b/QSB/Utility/DebugLog.cs @@ -16,7 +16,7 @@ public static class DebugLog public static void ToConsole(string message, MessageType type = MessageType.Message) { - if (QSBCore.InstanceIDInLogs) + if (QSBCore.DebugSettings != null && QSBCore.DebugSettings.InstanceIDInLogs) { message = $"[{ProcessInstanceId}] " + message; } @@ -44,7 +44,7 @@ public static class DebugLog public static void DebugWrite(string message, MessageType type = MessageType.Message) { - if (QSBCore.Helper == null || QSBCore.DebugMode) + if (QSBCore.Helper == null || QSBCore.DebugSettings == null || QSBCore.DebugSettings.DebugMode) { ToConsole(message, type); } diff --git a/QSB/Utility/DebugSettings.cs b/QSB/Utility/DebugSettings.cs new file mode 100644 index 00000000..328c69e9 --- /dev/null +++ b/QSB/Utility/DebugSettings.cs @@ -0,0 +1,56 @@ +using Newtonsoft.Json; +using OWML.Common; + +namespace QSB.Utility; + +[JsonObject(MemberSerialization.OptIn)] +public class DebugSettings +{ + public bool DebugMode; + + private bool _logQSBMessages; + public bool LogQSBMessages => DebugMode && _logQSBMessages; + + private bool _instanceIdInLogs; + public bool InstanceIDInLogs => DebugMode && _instanceIdInLogs; + + private bool _hookDebugLogs; + public bool HookDebugLogs => DebugMode && _hookDebugLogs; + + private bool _avoidTimeSync; + public bool AvoidTimeSync => DebugMode && _avoidTimeSync; + + private bool _autoStart; + public bool AutoStart => DebugMode && _autoStart; + + private int _latencySimulation; + public int LatencySimulation => DebugMode ? _latencySimulation : 0; + + private bool _drawGUI; + public bool DrawGUI => DebugMode && _drawGUI; + + private bool _drawLines; + public bool DrawLines => DebugMode && _drawLines; + + private bool _drawLabels; + public bool DrawLabels => DebugMode && _drawLabels; + + private bool _greySkybox; + public bool GreySkybox => DebugMode && _greySkybox; + + public DebugSettings(IModConfig config) + { + DebugMode = config.GetSettingsValue("debugMode"); + + _instanceIdInLogs = config.GetSettingsValue("instanceIdInLogs"); + _hookDebugLogs = config.GetSettingsValue("hookDebugLogs"); + _avoidTimeSync = config.GetSettingsValue("avoidTimeSync"); + _autoStart = config.GetSettingsValue("autoStart"); + _drawGUI = config.GetSettingsValue("drawGui"); + _drawLines = config.GetSettingsValue("drawLines"); + _drawLabels = config.GetSettingsValue("drawLabels"); + _greySkybox = config.GetSettingsValue("greySkybox"); + _latencySimulation = config.GetSettingsValue("latencySimulation"); + _logQSBMessages = config.GetSettingsValue("logQSBMessages"); + } +} \ No newline at end of file