diff --git a/AssetBundles/debug b/AssetBundles/debug index 98a62156..71c1eeac 100644 Binary files a/AssetBundles/debug and b/AssetBundles/debug differ diff --git a/AssetBundles/debug.manifest b/AssetBundles/debug.manifest index 58b6eecd..3c7b4d6c 100644 --- a/AssetBundles/debug.manifest +++ b/AssetBundles/debug.manifest @@ -1,9 +1,9 @@ ManifestFileVersion: 0 -CRC: 3009665417 +CRC: 3095198160 Hashes: AssetFileHash: serializedVersion: 2 - Hash: dbc913ca95e649d2e00d188ff573830e + Hash: aeeeeba83ed0a32973e863d3787067c0 TypeTreeHash: serializedVersion: 2 Hash: b2ece8ae09df261ff59d764d08696641 diff --git a/QSB/ClientServerStateSync/Events/ClientStateEvent.cs b/QSB/ClientServerStateSync/Events/ClientStateEvent.cs index 3e9b0890..b664a3e1 100644 --- a/QSB/ClientServerStateSync/Events/ClientStateEvent.cs +++ b/QSB/ClientServerStateSync/Events/ClientStateEvent.cs @@ -30,7 +30,7 @@ namespace QSB.ClientServerStateSync.Events { if (message.AboutId == uint.MaxValue) { - DebugLog.DebugWrite($"Error - ID is uint.MaxValue!", OWML.Common.MessageType.Error); + DebugLog.ToConsole($"Error - ID is uint.MaxValue!", OWML.Common.MessageType.Error); return; } diff --git a/QSB/ClientServerStateSync/ServerStateManager.cs b/QSB/ClientServerStateSync/ServerStateManager.cs index 70722429..42e93e1b 100644 --- a/QSB/ClientServerStateSync/ServerStateManager.cs +++ b/QSB/ClientServerStateSync/ServerStateManager.cs @@ -15,6 +15,7 @@ namespace QSB.ClientServerStateSync public delegate void ChangeStateEvent(ServerState newState); private ServerState _currentState; + private bool _blockNextCheck; private void Awake() => Instance = this; @@ -123,13 +124,21 @@ namespace QSB.ClientServerStateSync return; } + if (_blockNextCheck) + { + _blockNextCheck = false; + return; + } + if (_currentState == ServerState.WaitingForAllPlayersToReady) { - if (QSBPlayerManager.PlayerList.All(x => x.State == ClientState.WaitingForOthersToReadyInSolarSystem)) + if (QSBPlayerManager.PlayerList.All(x => x.State == ClientState.WaitingForOthersToReadyInSolarSystem) + || QSBPlayerManager.PlayerList.All(x => x.State == ClientState.AliveInSolarSystem)) { DebugLog.DebugWrite($"All ready!!"); QSBEventManager.FireEvent(EventNames.QSBStartLoop); QSBEventManager.FireEvent(EventNames.QSBServerState, ServerState.InSolarSystem); + _blockNextCheck = true; } } } diff --git a/QSB/DeathSync/RespawnManager.cs b/QSB/DeathSync/RespawnManager.cs index de9ae658..7b104e2e 100644 --- a/QSB/DeathSync/RespawnManager.cs +++ b/QSB/DeathSync/RespawnManager.cs @@ -26,6 +26,7 @@ namespace QSB.DeathSync private void OnSceneLoaded(OWScene oldScene, OWScene newScene, bool inUniverse) { + QSBPlayerManager.ShowAllPlayers(); QSBPlayerManager.PlayerList.ForEach(x => x.IsDead = false); _playersPendingRespawn.Clear(); } diff --git a/QSB/Events/EventNames.cs b/QSB/Events/EventNames.cs index cfbbc0d9..168d66c4 100644 --- a/QSB/Events/EventNames.cs +++ b/QSB/Events/EventNames.cs @@ -86,5 +86,6 @@ public static string QSBStartLoop = "QSBStartLoop"; public static string QSBServerState = "QSBServerState"; public static string QSBClientState = "QSBClientState"; + public static string QSBDebugEvent = "QSBDebugEvent"; } } \ No newline at end of file diff --git a/QSB/Events/EventType.cs b/QSB/Events/EventType.cs index 601253c0..be7a01f7 100644 --- a/QSB/Events/EventType.cs +++ b/QSB/Events/EventType.cs @@ -2,6 +2,11 @@ { public enum EventType { + /* + * MISC. + */ + DebugEvent, + /* * SERVER EVENTS */ diff --git a/QSB/Events/QSBEventManager.cs b/QSB/Events/QSBEventManager.cs index c3cd6c09..68029535 100644 --- a/QSB/Events/QSBEventManager.cs +++ b/QSB/Events/QSBEventManager.cs @@ -24,6 +24,7 @@ using QSB.Tools.Events; using QSB.Tools.ProbeLauncherTool.Events; using QSB.TranslationSync.Events; using QSB.Utility; +using QSB.Utility.Events; using System.Collections.Generic; namespace QSB.Events @@ -67,6 +68,7 @@ namespace QSB.Events new StartLoopEvent(), new ServerStateEvent(), new ClientStateEvent(), + new DebugEvent(), // World Objects new ElevatorEvent(), new GeyserEvent(), diff --git a/QSB/Menus/MenuManager.cs b/QSB/Menus/MenuManager.cs index cccdfb0d..b2077ad5 100644 --- a/QSB/Menus/MenuManager.cs +++ b/QSB/Menus/MenuManager.cs @@ -183,6 +183,9 @@ namespace QSB.Menus case KickReason.GameVersionNotMatching: text = "Server refused connection as Outer Wilds version does not match."; break; + case KickReason.GamePlatformNotMatching: + text = "Server refused connection as Outer Wilds platform does not match. (Steam/Epic)"; + break; case KickReason.None: text = "Kicked from server. No reason given."; break; diff --git a/QSB/OrbSync/OrbManager.cs b/QSB/OrbSync/OrbManager.cs index f2c7767b..50c842fb 100644 --- a/QSB/OrbSync/OrbManager.cs +++ b/QSB/OrbSync/OrbManager.cs @@ -4,6 +4,7 @@ using QSB.OrbSync.WorldObjects; using QSB.Utility; using QSB.WorldSync; using QuantumUNET; +using System.Collections.Generic; using System.Linq; using UnityEngine; @@ -11,6 +12,8 @@ namespace QSB.OrbSync { public class OrbManager : WorldObjectManager { + private List _orbs = new List(); + protected override void RebuildWorldObjects(OWScene scene) { QSBWorldSync.Init(); @@ -21,14 +24,17 @@ namespace QSB.OrbSync private void BuildOrbs() { QSBWorldSync.OldOrbList.Clear(); + NomaiOrbTransformSync.OrbTransformSyncs.Clear(); QSBWorldSync.OldOrbList = Resources.FindObjectsOfTypeAll().ToList(); if (QSBCore.IsHost) { - NomaiOrbTransformSync.OrbTransformSyncs.ForEach(x => QNetworkServer.Destroy(x.gameObject)); - NomaiOrbTransformSync.OrbTransformSyncs.Clear(); + _orbs.ForEach(x => QNetworkServer.Destroy(x)); + _orbs.Clear(); foreach (var orb in QSBWorldSync.OldOrbList) { - Instantiate(QSBNetworkManager.Instance.OrbPrefab).SpawnWithServerAuthority(); + var newOrb = Instantiate(QSBNetworkManager.Instance.OrbPrefab); + newOrb.SpawnWithServerAuthority(); + _orbs.Add(newOrb); } } diff --git a/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs b/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs index bcc44526..a2060a79 100644 --- a/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs +++ b/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs @@ -1,4 +1,5 @@ -using QSB.Syncs.Unsectored.Transforms; +using OWML.Common; +using QSB.Syncs.Unsectored.Transforms; using QSB.Utility; using QSB.WorldSync; using System.Collections.Generic; @@ -22,12 +23,25 @@ namespace QSB.OrbSync.TransformSync protected override void Init() { + if (!OrbTransformSyncs.Contains(this)) + { + OrbTransformSyncs.Add(this); + } + base.Init(); + + if (AttachedObject == null) + { + DebugLog.ToConsole($"Error - Trying to init orb with null AttachedObject.", MessageType.Error); + return; + } + var originalParent = AttachedObject.GetAttachedOWRigidbody().GetOrigParent(); if (originalParent == Locator.GetRootTransform()) { - DebugLog.DebugWrite($"{_logName} with AttachedObject {AttachedObject.name} had it's original parent as SolarSystemRoot - Destroying..."); - Destroy(this); + DebugLog.DebugWrite($"{_logName} with AttachedObject {AttachedObject.name} had it's original parent as SolarSystemRoot - Disabling..."); + enabled = false; + OrbTransformSyncs[_index] = null; } SetReferenceTransform(originalParent); @@ -37,19 +51,19 @@ namespace QSB.OrbSync.TransformSync { if (_index == -1) { - DebugLog.ToConsole($"Error - Index cannot be found.", OWML.Common.MessageType.Error); + DebugLog.ToConsole($"Error - Index cannot be found. OrbTransformSyncs count : {OrbTransformSyncs.Count}", MessageType.Error); return null; } if (QSBWorldSync.OldOrbList == null || QSBWorldSync.OldOrbList.Count <= _index) { - DebugLog.ToConsole($"Error - OldOrbList is null or does not contain index {_index}.", OWML.Common.MessageType.Error); + DebugLog.ToConsole($"Error - OldOrbList is null or does not contain index {_index}.", MessageType.Error); return null; } if (QSBWorldSync.OldOrbList[_index] == null) { - DebugLog.ToConsole($"Error - OldOrbList index {_index} is null.", OWML.Common.MessageType.Error); + DebugLog.ToConsole($"Error - OldOrbList index {_index} is null.", MessageType.Error); return null; } diff --git a/QSB/Patches/QSBPatchManager.cs b/QSB/Patches/QSBPatchManager.cs index 508c31a7..c0bb40f6 100644 --- a/QSB/Patches/QSBPatchManager.cs +++ b/QSB/Patches/QSBPatchManager.cs @@ -94,7 +94,7 @@ namespace QSB.Patches } catch (Exception ex) { - DebugLog.DebugWrite($"Error while patching {patch.GetType().Name} :\r\n{ex}", MessageType.Error); + DebugLog.ToConsole($"Error while patching {patch.GetType().Name} :\r\n{ex}", MessageType.Error); } } } diff --git a/QSB/Player/Events/PlayerJoinEvent.cs b/QSB/Player/Events/PlayerJoinEvent.cs index b5d6ee1a..7a3f0149 100644 --- a/QSB/Player/Events/PlayerJoinEvent.cs +++ b/QSB/Player/Events/PlayerJoinEvent.cs @@ -18,7 +18,8 @@ namespace QSB.Player.Events AboutId = LocalPlayerId, PlayerName = name, QSBVersion = QSBCore.QSBVersion, - GameVersion = QSBCore.GameVersion + GameVersion = QSBCore.GameVersion, + Platform = QSBCore.Platform }; public override void OnReceiveRemote(bool server, PlayerJoinMessage message) @@ -45,10 +46,19 @@ namespace QSB.Player.Events return; } + if (message.Platform != QSBCore.Platform) + { + if (server) + { + DebugLog.ToConsole($"Error - Client {message.PlayerName} connecting with wrong game platform. (Client:{message.Platform}, Server:{QSBCore.Platform})", MessageType.Error); + QSBEventManager.FireEvent(EventNames.QSBPlayerKick, message.AboutId, KickReason.GamePlatformNotMatching); + } + } + var player = QSBPlayerManager.GetPlayer(message.AboutId); player.Name = message.PlayerName; DebugLog.ToAll($"{player.Name} joined!", MessageType.Info); - DebugLog.DebugWrite($"{player.Name} joined. id:{player.PlayerId}, qsbVersion:{message.QSBVersion}, gameVersion:{message.GameVersion}", MessageType.Info); + DebugLog.DebugWrite($"{player.Name} joined. id:{player.PlayerId}, qsbVersion:{message.QSBVersion}, gameVersion:{message.GameVersion}, platform:{message.Platform}", MessageType.Info); } public override void OnReceiveLocal(bool server, PlayerJoinMessage message) diff --git a/QSB/Player/Events/PlayerJoinMessage.cs b/QSB/Player/Events/PlayerJoinMessage.cs index 1dab8bda..a07f5f4d 100644 --- a/QSB/Player/Events/PlayerJoinMessage.cs +++ b/QSB/Player/Events/PlayerJoinMessage.cs @@ -8,6 +8,7 @@ namespace QSB.Player.Events public string PlayerName { get; set; } public string QSBVersion { get; set; } public string GameVersion { get; set; } + public GamePlatform Platform { get; set; } public override void Deserialize(QNetworkReader reader) { @@ -15,6 +16,7 @@ namespace QSB.Player.Events PlayerName = reader.ReadString(); QSBVersion = reader.ReadString(); GameVersion = reader.ReadString(); + Platform = (GamePlatform)reader.ReadInt32(); } public override void Serialize(QNetworkWriter writer) @@ -23,6 +25,7 @@ namespace QSB.Player.Events writer.Write(PlayerName); writer.Write(QSBVersion); writer.Write(GameVersion); + writer.Write((int)Platform); } } } \ No newline at end of file diff --git a/QSB/Player/GamePlatform.cs b/QSB/Player/GamePlatform.cs new file mode 100644 index 00000000..6aedb3f1 --- /dev/null +++ b/QSB/Player/GamePlatform.cs @@ -0,0 +1,9 @@ +namespace QSB.Player +{ + public enum GamePlatform + { + None, + Steam, + Epic + } +} diff --git a/QSB/Player/KickReason.cs b/QSB/Player/KickReason.cs index 4e911581..d02b4159 100644 --- a/QSB/Player/KickReason.cs +++ b/QSB/Player/KickReason.cs @@ -4,6 +4,7 @@ { None, QSBVersionNotMatching, - GameVersionNotMatching + GameVersionNotMatching, + GamePlatformNotMatching } } diff --git a/QSB/Player/PlayerHUDMarker.cs b/QSB/Player/PlayerHUDMarker.cs index 9fdf8047..9835b3da 100644 --- a/QSB/Player/PlayerHUDMarker.cs +++ b/QSB/Player/PlayerHUDMarker.cs @@ -50,7 +50,7 @@ namespace QSB.Player } else { - DebugLog.DebugWrite($"Warning - _canvasMarker for {_player.PlayerId} is null!", OWML.Common.MessageType.Warning); + DebugLog.ToConsole($"Warning - _canvasMarker for {_player.PlayerId} is null!", OWML.Common.MessageType.Warning); } } diff --git a/QSB/Player/PlayerInfo.cs b/QSB/Player/PlayerInfo.cs index 01a28795..9d8430a9 100644 --- a/QSB/Player/PlayerInfo.cs +++ b/QSB/Player/PlayerInfo.cs @@ -1,4 +1,5 @@ -using QSB.Animation.Player; +using OWML.Common; +using QSB.Animation.Player; using QSB.Animation.Player.Thrusters; using QSB.CampfireSync.WorldObjects; using QSB.ClientServerStateSync; @@ -23,9 +24,49 @@ namespace QSB.Player public PlayerTransformSync TransformSync { get; set; } // Body Objects - public OWCamera Camera { get; set; } + public OWCamera Camera + { + get + { + if (_camera == null && PlayerStates.IsReady) + { + DebugLog.ToConsole($"Warning - {PlayerId}.Camera is null!", MessageType.Warning); + } + return _camera; + } + set + { + if (value == null) + { + DebugLog.ToConsole($"Warning - Setting {PlayerId}.Camera to null.", MessageType.Warning); + } + _camera = value; + } + } + private OWCamera _camera; + public GameObject CameraBody { get; set; } - public GameObject Body { get; set; } + public GameObject Body + { + get + { + if (_body == null && PlayerStates.IsReady) + { + DebugLog.ToConsole($"Warning - {PlayerId}.Body is null!", MessageType.Warning); + } + return _body; + } + set + { + if (value == null) + { + DebugLog.ToConsole($"Warning - Setting {PlayerId}.Body to null.", MessageType.Warning); + } + _body = value; + } + } + private GameObject _body; + public GameObject RoastingStick { get; set; } public bool Visible { get; set; } = true; @@ -79,7 +120,7 @@ namespace QSB.Player { if (QSBPlayerManager.LocalPlayer != this) { - DebugLog.ToConsole($"Warning - Tried to access local-only property LocalProbeLauncher in PlayerInfo for non local player!", OWML.Common.MessageType.Warning); + DebugLog.ToConsole($"Warning - Tried to access local-only property LocalProbeLauncher in PlayerInfo for non local player!", MessageType.Warning); return null; } @@ -93,7 +134,7 @@ namespace QSB.Player { if (QSBPlayerManager.LocalPlayer != this) { - DebugLog.ToConsole($"Warning - Tried to access local-only property LocalFlashlight in PlayerInfo for non local player!", OWML.Common.MessageType.Warning); + DebugLog.ToConsole($"Warning - Tried to access local-only property LocalFlashlight in PlayerInfo for non local player!", MessageType.Warning); return null; } @@ -107,7 +148,7 @@ namespace QSB.Player { if (QSBPlayerManager.LocalPlayer != this) { - DebugLog.ToConsole($"Warning - Tried to access local-only property LocalSignalscope in PlayerInfo for non local player!", OWML.Common.MessageType.Warning); + DebugLog.ToConsole($"Warning - Tried to access local-only property LocalSignalscope in PlayerInfo for non local player!", MessageType.Warning); return null; } @@ -121,7 +162,7 @@ namespace QSB.Player { if (QSBPlayerManager.LocalPlayer != this) { - DebugLog.ToConsole($"Warning - Tried to access local-only property LocalTranslator in PlayerInfo for non local player!", OWML.Common.MessageType.Warning); + DebugLog.ToConsole($"Warning - Tried to access local-only property LocalTranslator in PlayerInfo for non local player!", MessageType.Warning); return null; } diff --git a/QSB/Player/QSBPlayerManager.cs b/QSB/Player/QSBPlayerManager.cs index 7cfc2560..377b1ef4 100644 --- a/QSB/Player/QSBPlayerManager.cs +++ b/QSB/Player/QSBPlayerManager.cs @@ -120,7 +120,8 @@ namespace QSB.Player return cameraList; } - DebugLog.DebugWrite($"Error - LocalPlayer.Camera is null.", MessageType.Error); + DebugLog.ToConsole($"Error - LocalPlayer.Camera is null.", MessageType.Error); + LocalPlayer.Camera = Locator.GetPlayerCamera(); } return cameraList; @@ -158,6 +159,12 @@ namespace QSB.Player public static PlayerInfo GetClosestPlayerToWorldPoint(List playerList, Vector3 worldPoint) { + if (playerList == null) + { + DebugLog.ToConsole($"Error - Cannot get closest player from null player list.", MessageType.Error); + return null; + } + if (playerList.Count == 0) { DebugLog.ToConsole($"Error - Cannot get closest player from empty player list.", MessageType.Error); diff --git a/QSB/ProbeSync/QSBProbe.cs b/QSB/ProbeSync/QSBProbe.cs index aad3382c..198645fb 100644 --- a/QSB/ProbeSync/QSBProbe.cs +++ b/QSB/ProbeSync/QSBProbe.cs @@ -111,7 +111,7 @@ namespace QSB.ProbeSync break; case ProbeEvent.Invalid: default: - DebugLog.DebugWrite($"Warning - Unknown/Invalid probe event.", OWML.Common.MessageType.Warning); + DebugLog.ToConsole($"Warning - Unknown/Invalid probe event.", OWML.Common.MessageType.Warning); break; } } diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index 494c074a..294f9217 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -109,6 +109,7 @@ + @@ -275,6 +276,8 @@ + + diff --git a/QSB/QSBCore.cs b/QSB/QSBCore.cs index 784c7f49..ef1c7bc0 100644 --- a/QSB/QSBCore.cs +++ b/QSB/QSBCore.cs @@ -26,6 +26,7 @@ using QSB.Utility; using QSB.WorldSync; using QuantumUNET; using QuantumUNET.Components; +using System.Linq; using UnityEngine; /* @@ -65,6 +66,9 @@ namespace QSB public static bool IsInMultiplayer => QNetworkManager.singleton.isNetworkActive; public static string QSBVersion => Helper.Manifest.Version; public static string GameVersion => Application.version; + public static GamePlatform Platform => typeof(Achievements).Assembly.GetTypes().Any(x => x.Name == "EpicEntitlementRetriever") + ? GamePlatform.Epic + : GamePlatform.Steam; public static IMenuAPI MenuApi { get; private set; } public void Awake() @@ -127,6 +131,10 @@ namespace QSB if (type == QSBPatchTypes.OnClientConnect) { Application.runInBackground = true; + if (Locator.GetSceneMenuManager() != null && Locator.GetSceneMenuManager().pauseMenu.IsOpen()) + { + Locator.GetSceneMenuManager().pauseMenu._pauseMenu.EnableMenu(false); + } } } diff --git a/QSB/QSBNetworkManager.cs b/QSB/QSBNetworkManager.cs index 62d23dc4..65254a34 100644 --- a/QSB/QSBNetworkManager.cs +++ b/QSB/QSBNetworkManager.cs @@ -87,11 +87,19 @@ namespace QSB private string GetPlayerName() { - var profileManager = StandaloneProfileManager.SharedInstance; - profileManager.Initialize(); - var profile = profileManager.GetValue("_currentProfile"); - var profileName = profile.profileName; - return profileName; + try + { + var profileManager = StandaloneProfileManager.SharedInstance; + profileManager.Initialize(); + var profile = profileManager._currentProfile; + var profileName = profile.profileName; + return profileName; + } + catch (Exception ex) + { + DebugLog.ToConsole($"Error - Exception when getting player name : {ex}", MessageType.Error); + return "Player"; + } } private void SetupNetworkId(GameObject go, int assetId) @@ -234,6 +242,11 @@ namespace QSB foreach (var item in NomaiOrbTransformSync.OrbTransformSyncs) { + if (item is null) + { + continue; + } + var identity = item.GetComponent(); if (identity.ClientAuthorityOwner == connection) { diff --git a/QSB/QuantumSync/Patches/QuantumPatches.cs b/QSB/QuantumSync/Patches/QuantumPatches.cs index aef42d5e..0ebd1e96 100644 --- a/QSB/QuantumSync/Patches/QuantumPatches.cs +++ b/QSB/QuantumSync/Patches/QuantumPatches.cs @@ -295,7 +295,7 @@ namespace QSB.QuantumSync.Patches var owner = allMultiStates.FirstOrDefault(x => x.QuantumStates.Contains(stateObject)); if (owner == default) { - DebugLog.DebugWrite($"Error - Could not find QSBMultiStateQuantumObject for state {__instance.name}", MessageType.Error); + DebugLog.ToConsole($"Error - Could not find QSBMultiStateQuantumObject for state {__instance.name}", MessageType.Error); return; } diff --git a/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs b/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs index c0f700c3..38920856 100644 --- a/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs +++ b/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs @@ -64,29 +64,32 @@ namespace QSB.QuantumSync.WorldObjects shape.OnShapeDeactivated += (Shape s) => QSBCore.UnityEvents.FireOnNextUpdate(() => OnDisable(s)); - if (shape is BoxShape boxShape) + if (QSBCore.DebugMode) { - var newCube = UnityEngine.Object.Instantiate(cube); - newCube.transform.parent = shape.transform; - newCube.transform.localPosition = Vector3.zero; - newCube.transform.localRotation = Quaternion.Euler(0, 0, 0); - newCube.transform.localScale = boxShape.size; - } - else if (shape is SphereShape sphereShape) - { - var newSphere = UnityEngine.Object.Instantiate(sphere); - newSphere.transform.parent = shape.transform; - newSphere.transform.localPosition = Vector3.zero; - newSphere.transform.localRotation = Quaternion.Euler(0, 0, 0); - newSphere.transform.localScale = Vector3.one * (sphereShape.radius * 2); - } - else if (shape is CapsuleShape capsuleShape) - { - var newCapsule = Object.Instantiate(capsule); - newCapsule.transform.parent = shape.transform; - newCapsule.transform.localPosition = Vector3.zero; - newCapsule.transform.localRotation = Quaternion.Euler(0, 0, 0); - newCapsule.transform.localScale = new Vector3(capsuleShape.radius * 2, capsuleShape.height, capsuleShape.radius * 2); + if (shape is BoxShape boxShape) + { + var newCube = UnityEngine.Object.Instantiate(cube); + newCube.transform.parent = shape.transform; + newCube.transform.localPosition = Vector3.zero; + newCube.transform.localRotation = Quaternion.Euler(0, 0, 0); + newCube.transform.localScale = boxShape.size; + } + else if (shape is SphereShape sphereShape) + { + var newSphere = UnityEngine.Object.Instantiate(sphere); + newSphere.transform.parent = shape.transform; + newSphere.transform.localPosition = Vector3.zero; + newSphere.transform.localRotation = Quaternion.Euler(0, 0, 0); + newSphere.transform.localScale = Vector3.one * (sphereShape.radius * 2); + } + else if (shape is CapsuleShape capsuleShape) + { + var newCapsule = Object.Instantiate(capsule); + newCapsule.transform.parent = shape.transform; + newCapsule.transform.localPosition = Vector3.zero; + newCapsule.transform.localRotation = Quaternion.Euler(0, 0, 0); + newCapsule.transform.localScale = new Vector3(capsuleShape.radius * 2, capsuleShape.height, capsuleShape.radius * 2); + } } } diff --git a/QSB/SectorSync/SectorSync.cs b/QSB/SectorSync/SectorSync.cs index 457e6421..2b998c98 100644 --- a/QSB/SectorSync/SectorSync.cs +++ b/QSB/SectorSync/SectorSync.cs @@ -131,7 +131,18 @@ namespace QSB.SectorSync return null; } - var numSectorsCurrentlyIn = SectorList.Count(x => x.ShouldSyncTo(_targetType)); + bool ShouldSyncTo(QSBSector sector, TargetType type) + { + if (sector == null) + { + DebugLog.ToConsole($"Warning - Tried to check if we should sync to null sector!", MessageType.Warning); + return false; + } + + return sector.ShouldSyncTo(type); + } + + var numSectorsCurrentlyIn = SectorList.Count(x => ShouldSyncTo(x, _targetType)); var listToCheck = numSectorsCurrentlyIn == 0 ? QSBWorldSync.GetWorldObjects().Where(x => !x.IsFakeSector && x.Type != Sector.Name.Unnamed) diff --git a/QSB/SectorSync/WorldObjects/QSBSector.cs b/QSB/SectorSync/WorldObjects/QSBSector.cs index c0be4c60..dbd76ccf 100644 --- a/QSB/SectorSync/WorldObjects/QSBSector.cs +++ b/QSB/SectorSync/WorldObjects/QSBSector.cs @@ -2,6 +2,7 @@ using OWML.Utils; using QSB.Utility; using QSB.WorldSync; +using System; using System.Linq; using UnityEngine; @@ -10,7 +11,19 @@ namespace QSB.SectorSync.WorldObjects public class QSBSector : WorldObject { public Sector.Name Type => AttachedObject.GetName(); - public Transform Transform => AttachedObject.transform; + public Transform Transform + { + get + { + if (AttachedObject == null) + { + DebugLog.ToConsole($"Error - Tried to get Transform from QSBSector {ObjectId} with null AttachedObject!\r\n{Environment.StackTrace}", MessageType.Error); + return null; + } + + return AttachedObject.transform; + } + } public Vector3 Position => Transform.position; public bool IsFakeSector => AttachedObject.GetType() == typeof(FakeSector); diff --git a/QSB/Syncs/IntermediaryTransform.cs b/QSB/Syncs/IntermediaryTransform.cs index ea5f95de..f4ec1ae8 100644 --- a/QSB/Syncs/IntermediaryTransform.cs +++ b/QSB/Syncs/IntermediaryTransform.cs @@ -58,7 +58,7 @@ namespace QSB.Syncs { if (_referenceTransform == null) { - DebugLog.ToConsole($"Error - _referenceTransform has not been set for {_attachedTransform.name} \r\n{Environment.StackTrace}", MessageType.Error); + DebugLog.ToConsole($"Error - _referenceTransform has not been set for {_attachedTransform.name}", MessageType.Error); return; } @@ -73,7 +73,7 @@ namespace QSB.Syncs { if (_referenceTransform == null) { - DebugLog.ToConsole($"Error - _referenceTransform has not been set for {_attachedTransform.name} \r\n{Environment.StackTrace}", MessageType.Error); + DebugLog.ToConsole($"Error - _referenceTransform has not been set for {_attachedTransform.name}", MessageType.Error); return; } @@ -99,7 +99,7 @@ namespace QSB.Syncs { if (_referenceTransform == null) { - DebugLog.ToConsole($"Error - _referenceTransform has not been set for {_attachedTransform.name} \r\n{Environment.StackTrace}", MessageType.Error); + DebugLog.ToConsole($"Error - _referenceTransform has not been set for {_attachedTransform.name}", MessageType.Error); return Vector3.zero; } @@ -113,7 +113,7 @@ namespace QSB.Syncs { if (_referenceTransform == null) { - DebugLog.ToConsole($"Error - _referenceTransform has not been set for {_attachedTransform.name} \r\n{Environment.StackTrace}", MessageType.Error); + DebugLog.ToConsole($"Error - _referenceTransform has not been set for {_attachedTransform.name}", MessageType.Error); return Quaternion.identity; } diff --git a/QSB/Syncs/Sectored/BaseSectoredSync.cs b/QSB/Syncs/Sectored/BaseSectoredSync.cs index f52a6239..36064dab 100644 --- a/QSB/Syncs/Sectored/BaseSectoredSync.cs +++ b/QSB/Syncs/Sectored/BaseSectoredSync.cs @@ -34,6 +34,12 @@ namespace QSB.Syncs.Sectored } } + protected override void OnSceneLoaded(OWScene oldScene, OWScene newScene, bool isInUniverse) + { + base.OnSceneLoaded(oldScene, newScene, isInUniverse); + SetReferenceSector(null); + } + protected override void Init() { base.Init(); @@ -67,6 +73,12 @@ namespace QSB.Syncs.Sectored { if (_sectorIdWaitingSlot == int.MinValue) { + if (ReferenceSector != null && ReferenceSector.Transform != ReferenceTransform) + { + DebugLog.ToConsole($"Warning - {_logName} : ReferenceSector.Transform was different to ReferenceTransform. Correcting...", OWML.Common.MessageType.Warning); + SetReferenceTransform(ReferenceSector.Transform); + } + base.Update(); return; } diff --git a/QSB/Syncs/SyncBase.cs b/QSB/Syncs/SyncBase.cs index 5171b2cf..1c98238c 100644 --- a/QSB/Syncs/SyncBase.cs +++ b/QSB/Syncs/SyncBase.cs @@ -86,7 +86,7 @@ namespace QSB.Syncs public Component AttachedObject { get; set; } public Transform ReferenceTransform { get; set; } - protected string _logName => $"{PlayerId}.{GetType().Name}"; + protected string _logName => $"{PlayerId}.{NetId.Value}:{GetType().Name}"; protected virtual float DistanceLeeway { get; } = 5f; private float _previousDistance; protected const float SmoothTime = 0.1f; @@ -223,6 +223,14 @@ namespace QSB.Syncs return; } + if (ShouldReparentAttachedObject + && !HasAuthority + && AttachedObject.transform.parent != ReferenceTransform) + { + DebugLog.ToConsole($"Warning : {_logName} : AttachedObject's parent is different to ReferenceTransform. Correcting...", MessageType.Warning); + ReparentAttachedObject(ReferenceTransform); + } + UpdateTransform(); base.Update(); diff --git a/QSB/TimeSync/WakeUpSync.cs b/QSB/TimeSync/WakeUpSync.cs index 06cdc885..e3a8d806 100644 --- a/QSB/TimeSync/WakeUpSync.cs +++ b/QSB/TimeSync/WakeUpSync.cs @@ -255,6 +255,16 @@ namespace QSB.TimeSync } } + if (serverState == ServerState.WaitingForAllPlayersToDie && clientState == ClientState.WaitingForOthersToReadyInSolarSystem) + { + if (CurrentState == State.Pausing && (PauseReason)CurrentReason == PauseReason.WaitingForAllPlayersToBeReady) + { + //? + DebugLog.ToConsole($"Warning - Server waiting for players to die, but players waiting for ready signal! Assume players correct.", MessageType.Warning); + QSBEventManager.FireEvent(EventNames.QSBServerState, ServerState.WaitingForAllPlayersToReady); + } + } + if (CurrentState != State.Loaded) { return; @@ -293,7 +303,7 @@ namespace QSB.TimeSync if (CurrentState != State.Loaded && CurrentState != State.NotLoaded && CurrentReason == null) { - DebugLog.DebugWrite($"Warning - CurrentReason is null.", MessageType.Warning); + DebugLog.ToConsole($"Warning - CurrentReason is null.", MessageType.Warning); } // Checks to pause/fastforward diff --git a/QSB/Utility/DebugActions.cs b/QSB/Utility/DebugActions.cs index f0a5b5e8..03c773de 100644 --- a/QSB/Utility/DebugActions.cs +++ b/QSB/Utility/DebugActions.cs @@ -1,6 +1,9 @@ using OWML.Utils; +using QSB.Events; using QSB.ShipSync; +using QSB.Utility.Events; using UnityEngine; +using UnityEngine.InputSystem; namespace QSB.Utility { @@ -29,34 +32,32 @@ namespace QSB.Utility public void Update() { - return; - if (!QSBCore.DebugMode) { return; } - if (Input.GetKeyDown(KeyCode.Keypad5)) - { - Locator.GetDeathManager().KillPlayer(DeathType.Supernova); - } - - if (Input.GetKeyDown(KeyCode.Keypad4)) + if (Keyboard.current[Key.Numpad4].wasPressedThisFrame) { DamageShipElectricalSystem(); } - if (Input.GetKeyDown(KeyCode.Keypad7)) + if (Keyboard.current[Key.Numpad5].wasPressedThisFrame) + { + QSBEventManager.FireEvent(EventNames.QSBDebugEvent, DebugEventEnum.TriggerSupernova); + } + + if (Keyboard.current[Key.Numpad7].wasPressedThisFrame) { GoToVessel(); } - if (Input.GetKeyDown(KeyCode.Keypad8)) + if (Keyboard.current[Key.Numpad8].wasPressedThisFrame) { InsertWarpCore(); } - if (Input.GetKeyDown(KeyCode.Keypad9)) + if (Keyboard.current[Key.Numpad9].wasPressedThisFrame) { LoadManager.LoadSceneAsync(OWScene.EyeOfTheUniverse, true, LoadManager.FadeType.ToWhite); } diff --git a/QSB/Utility/DebugGUI.cs b/QSB/Utility/DebugGUI.cs index 68bada16..d09d0baf 100644 --- a/QSB/Utility/DebugGUI.cs +++ b/QSB/Utility/DebugGUI.cs @@ -1,4 +1,6 @@ -using QSB.ClientServerStateSync; +using OWML.Utils; +using QSB.ClientServerStateSync; +using QSB.OrbSync.TransformSync; using QSB.Player; using QSB.ProbeSync.TransformSync; using QSB.Syncs; @@ -63,6 +65,8 @@ namespace QSB.Utility } var offset2 = 10f; + GUI.Label(new Rect(420, offset2, 200f, 20f), $"OrbList count : {NomaiOrbTransformSync.OrbTransformSyncs.Count}", guiStyle); + offset2 += _debugLineSpacing; GUI.Label(new Rect(420, offset2, 200f, 20f), $"Player data :", guiStyle); offset2 += _debugLineSpacing; foreach (var player in QSBPlayerManager.PlayerList) @@ -73,16 +77,30 @@ namespace QSB.Utility offset2 += _debugLineSpacing; GUI.Label(new Rect(420, offset2, 400f, 20f), $"Dead : {player.IsDead}", guiStyle); offset2 += _debugLineSpacing; + GUI.Label(new Rect(420, offset2, 400f, 20f), $"Visible : {player.Visible}", guiStyle); + offset2 += _debugLineSpacing; if (player.PlayerStates.IsReady && QSBCore.WorldObjectsReady) { var networkTransform = player.TransformSync; - var sector = networkTransform.ReferenceSector; + var referenceSector = networkTransform.ReferenceSector; + var referenceTransform = networkTransform.ReferenceTransform; + var parent = networkTransform.AttachedObject?.transform.parent; + var intermediary = networkTransform.GetValue("_intermediaryTransform"); + var interTransform = intermediary.GetReferenceTransform(); GUI.Label(new Rect(420, offset2, 400f, 20f), $" - L.Pos : {networkTransform.transform.localPosition}", guiStyle); offset2 += _debugLineSpacing; - GUI.Label(new Rect(420, offset2, 400f, 20f), $" - Sector : {(sector == null ? "NULL" : sector.Name)}", guiStyle); + GUI.Label(new Rect(420, offset2, 400f, 20f), $" - Ref. Sector : {(referenceSector == null ? "NULL" : referenceSector.Name)}", guiStyle); offset2 += _debugLineSpacing; + GUI.Label(new Rect(420, offset2, 400f, 20f), $" - Ref. Transform : {(referenceTransform == null ? "NULL" : referenceTransform.name)}", guiStyle); + offset2 += _debugLineSpacing; + GUI.Label(new Rect(420, offset2, 400f, 20f), $" - Inter. Ref. Transform : {(interTransform == null ? "NULL" : interTransform.name)}", guiStyle); + offset2 += _debugLineSpacing; + GUI.Label(new Rect(420, offset2, 400f, 20f), $" - Parent : {(parent == null ? "NULL" : parent.name)}", guiStyle); + offset2 += _debugLineSpacing; + + /* var probeSync = SyncBase.GetPlayers(player); if (probeSync != default) { @@ -90,6 +108,7 @@ namespace QSB.Utility GUI.Label(new Rect(420, offset2, 400f, 20f), $" - Probe Sector : {(probeSector == null ? "NULL" : probeSector.Name)}", guiStyle); offset2 += _debugLineSpacing; } + */ } } } diff --git a/QSB/Utility/Events/DebugEvent.cs b/QSB/Utility/Events/DebugEvent.cs new file mode 100644 index 00000000..0cde719a --- /dev/null +++ b/QSB/Utility/Events/DebugEvent.cs @@ -0,0 +1,36 @@ +using QSB.Events; +using QSB.Messaging; + +namespace QSB.Utility.Events +{ + public class DebugEvent : QSBEvent> + { + public override EventType Type => EventType.DebugEvent; + + public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBDebugEvent, Handler); + public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBDebugEvent, Handler); + + private void Handler(DebugEventEnum type) => SendEvent(CreateMessage(type)); + + private EnumMessage CreateMessage(DebugEventEnum type) => new EnumMessage + { + AboutId = LocalPlayerId, + EnumValue = type + }; + + public override void OnReceiveLocal(bool isHost, EnumMessage message) + { + OnReceiveRemote(isHost, message); + } + + public override void OnReceiveRemote(bool isHost, EnumMessage message) + { + switch (message.EnumValue) + { + case DebugEventEnum.TriggerSupernova: + TimeLoop.SetSecondsRemaining(0f); + break; + } + } + } +} diff --git a/QSB/Utility/Events/DebugEventEnum.cs b/QSB/Utility/Events/DebugEventEnum.cs new file mode 100644 index 00000000..1f74bc9c --- /dev/null +++ b/QSB/Utility/Events/DebugEventEnum.cs @@ -0,0 +1,7 @@ +namespace QSB.Utility.Events +{ + public enum DebugEventEnum + { + TriggerSupernova + } +} \ No newline at end of file diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index a61f9fa5..0d7a31de 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -90,17 +90,29 @@ namespace QSB.WorldSync public static void RemoveWorldObjects() { + if (WorldObjects == null || WorldObjects.Count == 0) + { + DebugLog.ToConsole($"Warning - Trying to remove WorldObjects of type {typeof(TWorldObject).Name}, but there are no WorldObjects!"); + } + var itemsToRemove = WorldObjects.Where(x => x is TWorldObject); + foreach (var item in itemsToRemove) { - WorldObjectsToUnityObjects.Remove(item.ReturnObject()); + if (item is null) + { + DebugLog.ToConsole($"Error - Trying to remove a null WorldObject of type {typeof(TWorldObject).Name}.", MessageType.Error); + continue; + } + try { + WorldObjectsToUnityObjects.Remove(item.ReturnObject()); item.OnRemoval(); } catch (Exception e) { - DebugLog.ToConsole($"Error - Exception in OnRemoval() for {item.GetType()}. Message : {e.InnerException.Message}, Stack trace : {e.InnerException.StackTrace}", MessageType.Error); + DebugLog.ToConsole($"Error - Exception in OnRemoval() for {item.GetType()}. Message : {e.Message}, Stack trace : {e.StackTrace}", MessageType.Error); } } diff --git a/QSB/default-config.json b/QSB/default-config.json index fedee1d0..ffe88285 100644 --- a/QSB/default-config.json +++ b/QSB/default-config.json @@ -3,7 +3,7 @@ "settings": { "defaultServerIP": "localhost", "port": 7777, - "debugMode": true, + "debugMode": false, "showLinesInDebug": false } } \ No newline at end of file diff --git a/QSB/manifest.json b/QSB/manifest.json index 32918373..fd9f720f 100644 --- a/QSB/manifest.json +++ b/QSB/manifest.json @@ -9,6 +9,6 @@ }, "uniqueName": "Raicuparta.QuantumSpaceBuddies", "version": "0.12.0-pr4", - "owmlVersion": "2.0.0", + "owmlVersion": "2.1.0", "dependencies": [ "_nebula.MenuFramework" ] } \ No newline at end of file diff --git a/UnityProject/Assets/DebugVis.mat b/UnityProject/Assets/DebugVis.mat index 21ccb8f7..78da8673 100644 --- a/UnityProject/Assets/DebugVis.mat +++ b/UnityProject/Assets/DebugVis.mat @@ -73,5 +73,5 @@ Material: - _UVSec: 0 - _ZWrite: 0 m_Colors: - - _Color: {r: 1, g: 0.51526886, b: 0, a: 0.09803922} + - _Color: {r: 1, g: 0.51526886, b: 0, a: 0.05882353} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1}