From 6ccb8c00586d90d7e265147956e94dabc7edaffe Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 29 Aug 2022 20:54:59 -0700 Subject: [PATCH 01/47] BuildWorldObjects: wait --- QSB/WorldSync/QSBWorldSync.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 5d788f70..f3604883 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -49,6 +49,10 @@ public static class QSBWorldSync await UniTask.WaitUntil(() => PlayerTransformSync.LocalInstance, cancellationToken: _cts.Token); } + // let nh do things first :) + // makin it nice and long to be safe + await UniTask.DelayFrame(100, cancellationToken: _cts.Token); + GameInit(); foreach (var manager in Managers) From a57c4265ae06e07411f31cb56b6f5b2c525ca067 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 29 Aug 2022 21:31:13 -0700 Subject: [PATCH 02/47] fake sector check --- QSB/SectorSync/QSBSectorManager.cs | 12 ++++++++---- QSB/WorldSync/QSBWorldSync.cs | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/QSB/SectorSync/QSBSectorManager.cs b/QSB/SectorSync/QSBSectorManager.cs index 3d345bfd..389060ff 100644 --- a/QSB/SectorSync/QSBSectorManager.cs +++ b/QSB/SectorSync/QSBSectorManager.cs @@ -91,11 +91,15 @@ public class QSBSectorManager : WorldObjectManager // time loop spinning ring { + // NH can remove this var TimeLoopRing_Body = GameObject.Find("TimeLoopRing_Body"); - var Sector_TimeLoopInterior = GameObject.Find("Sector_TimeLoopInterior").GetComponent(); - // use the same trigger as the parent sector - FakeSector.Create(TimeLoopRing_Body, Sector_TimeLoopInterior, - x => x._triggerRoot = Sector_TimeLoopInterior._triggerRoot); + if (TimeLoopRing_Body) + { + var Sector_TimeLoopInterior = GameObject.Find("Sector_TimeLoopInterior").GetComponent(); + // use the same trigger as the parent sector + FakeSector.Create(TimeLoopRing_Body, Sector_TimeLoopInterior, + x => x._triggerRoot = Sector_TimeLoopInterior._triggerRoot); + } } // TH elevators diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index f3604883..ce53ade5 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -49,8 +49,8 @@ public static class QSBWorldSync await UniTask.WaitUntil(() => PlayerTransformSync.LocalInstance, cancellationToken: _cts.Token); } - // let nh do things first :) - // makin it nice and long to be safe + // let NH do things first :) + // makin it nice and long to be safe. dw things still work no matter the delay await UniTask.DelayFrame(100, cancellationToken: _cts.Token); GameInit(); From c1ed02f97cff1429b2141c231cbdcdefa6595386 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 29 Aug 2022 21:37:30 -0700 Subject: [PATCH 03/47] occaisonal --- QSB/Syncs/Occasional/OccasionalManager.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/QSB/Syncs/Occasional/OccasionalManager.cs b/QSB/Syncs/Occasional/OccasionalManager.cs index 6f229299..2597f694 100644 --- a/QSB/Syncs/Occasional/OccasionalManager.cs +++ b/QSB/Syncs/Occasional/OccasionalManager.cs @@ -21,6 +21,11 @@ internal class OccasionalManager : WorldObjectManager foreach (var proxy in cannon._realDebrisSectorProxies) { + // NH can remove these + if (!proxy) + { + continue; + } SpawnOccasional(proxy.transform.root.GetAttachedOWRigidbody(), gdBody); } @@ -58,4 +63,4 @@ internal class OccasionalManager : WorldObjectManager Bodies.Clear(); } -} \ No newline at end of file +} From 887da7fc49530f07877a1fa4337783cda8783a79 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 29 Aug 2022 21:45:20 -0700 Subject: [PATCH 04/47] change da delay --- QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs | 2 ++ QSB/WorldSync/QSBWorldSync.cs | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs b/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs index 7fc2bb43..6d74e810 100644 --- a/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs +++ b/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs @@ -1,6 +1,7 @@ using QSB.AuthoritySync; using QSB.OrbSync.WorldObjects; using QSB.Syncs.Unsectored.Transforms; +using QSB.Utility; using QSB.Utility.LinkedWorldObject; using QSB.WorldSync; using UnityEngine; @@ -47,6 +48,7 @@ public class NomaiOrbTransformSync : UnsectoredTransformSync, ILinkedNetworkBeha protected override void Init() { base.Init(); + DebugLog.DebugWrite($"{this} - attached = {AttachedTransform}\nbody = {AttachedTransform?.GetAttachedOWRigidbody()}\nparent = {AttachedTransform?.GetAttachedOWRigidbody()?.GetOrigParent()}"); var body = AttachedTransform.GetAttachedOWRigidbody(); SetReferenceTransform(body.GetOrigParent()); diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index ce53ade5..4c0d6518 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -50,8 +50,8 @@ public static class QSBWorldSync } // let NH do things first :) - // makin it nice and long to be safe. dw things still work no matter the delay - await UniTask.DelayFrame(100, cancellationToken: _cts.Token); + // i think NH only takes like 3 frames to do stuff so this should be okay + await UniTask.DelayFrame(10, cancellationToken: _cts.Token); GameInit(); From e1b2670fa264679904454d59d253f3b22a5e9ff0 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 29 Aug 2022 21:49:13 -0700 Subject: [PATCH 05/47] nh makes model ship null --- QSB/ModelShip/ModelShipManager.cs | 7 +++++++ QSB/WorldSync/QSBWorldSync.cs | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/QSB/ModelShip/ModelShipManager.cs b/QSB/ModelShip/ModelShipManager.cs index 23417fb3..4caae0ff 100644 --- a/QSB/ModelShip/ModelShipManager.cs +++ b/QSB/ModelShip/ModelShipManager.cs @@ -37,6 +37,13 @@ internal class ModelShipManager : WorldObjectManager public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct) { + // NH can remove this + var modelShip = QSBWorldSync.GetUnityObject()._modelShipBody; + if (!modelShip) + { + return; + } + if (QSBCore.IsHost) { Instantiate(QSBNetworkManager.singleton.ModelShipPrefab).SpawnWithServerAuthority(); diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 4c0d6518..f48d9e11 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -51,7 +51,7 @@ public static class QSBWorldSync // let NH do things first :) // i think NH only takes like 3 frames to do stuff so this should be okay - await UniTask.DelayFrame(10, cancellationToken: _cts.Token); + await UniTask.DelayFrame(1000, cancellationToken: _cts.Token); GameInit(); From 1db3edb0cc2c3012a5ac74d14fb9a2dd04018cda Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 29 Aug 2022 21:51:53 -0700 Subject: [PATCH 06/47] WHITE HOLE BRUH --- QSB/MeteorSync/MeteorManager.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/QSB/MeteorSync/MeteorManager.cs b/QSB/MeteorSync/MeteorManager.cs index 65226a38..8bf325bd 100644 --- a/QSB/MeteorSync/MeteorManager.cs +++ b/QSB/MeteorSync/MeteorManager.cs @@ -17,7 +17,8 @@ public class MeteorManager : WorldObjectManager // wait for all late initializers (which includes meteor launchers) to finish await UniTask.WaitUntil(() => LateInitializerManager.isDoneInitializing, cancellationToken: ct); - WhiteHoleVolume = QSBWorldSync.GetUnityObject(); + // NH can make multiple so fuck it just choose one + WhiteHoleVolume = QSBWorldSync.GetUnityObjects().First(); QSBWorldSync.Init(); QSBWorldSync.Init(); QSBWorldSync.Init(); From a6f61b873f7d4b9d02fea4c794977cc97dcc14c0 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 29 Aug 2022 21:53:24 -0700 Subject: [PATCH 07/47] ITEM --- QSB/ItemSync/WorldObjects/Items/QSBItem.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/QSB/ItemSync/WorldObjects/Items/QSBItem.cs b/QSB/ItemSync/WorldObjects/Items/QSBItem.cs index d7e57e70..89757767 100644 --- a/QSB/ItemSync/WorldObjects/Items/QSBItem.cs +++ b/QSB/ItemSync/WorldObjects/Items/QSBItem.cs @@ -54,7 +54,8 @@ public class QSBItem : WorldObject, IQSBItem _lastSector = sector.GetWorldObject(); } - var socket = _lastParent.GetComponent(); + // NH can make item not have parent + var socket = _lastParent?.GetComponent(); if (socket != null) { _lastSocket = socket.GetWorldObject(); From a4b356e9eb526ac764c740e3ed2164a6d3e52d72 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 29 Aug 2022 21:53:41 -0700 Subject: [PATCH 08/47] bitch --- QSB/WorldSync/QSBWorldSync.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index f48d9e11..4c0d6518 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -51,7 +51,7 @@ public static class QSBWorldSync // let NH do things first :) // i think NH only takes like 3 frames to do stuff so this should be okay - await UniTask.DelayFrame(1000, cancellationToken: _cts.Token); + await UniTask.DelayFrame(10, cancellationToken: _cts.Token); GameInit(); From 834ce04dfdcf65640f1f33d9040cd266e98a075d Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 29 Aug 2022 22:04:38 -0700 Subject: [PATCH 09/47] NOPE it has to be LOONG --- QSB/WorldSync/QSBWorldSync.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 4c0d6518..ce53ade5 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -50,8 +50,8 @@ public static class QSBWorldSync } // let NH do things first :) - // i think NH only takes like 3 frames to do stuff so this should be okay - await UniTask.DelayFrame(10, cancellationToken: _cts.Token); + // makin it nice and long to be safe. dw things still work no matter the delay + await UniTask.DelayFrame(100, cancellationToken: _cts.Token); GameInit(); From 0bb6e86bc5c29f96725c4dbbc52de43a5fd78471 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 29 Aug 2022 22:06:36 -0700 Subject: [PATCH 10/47] ORB --- QSB/OrbSync/OrbManager.cs | 7 ++++++- QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs | 1 - 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/QSB/OrbSync/OrbManager.cs b/QSB/OrbSync/OrbManager.cs index 0b5879f8..054caed7 100644 --- a/QSB/OrbSync/OrbManager.cs +++ b/QSB/OrbSync/OrbManager.cs @@ -1,6 +1,8 @@ using Cysharp.Threading.Tasks; using QSB.OrbSync.WorldObjects; +using QSB.Utility; using QSB.WorldSync; +using System.Linq; using System.Threading; namespace QSB.OrbSync; @@ -10,5 +12,8 @@ public class OrbManager : WorldObjectManager public override WorldObjectScene WorldObjectScene => WorldObjectScene.Both; public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct) => - QSBWorldSync.Init(); + // NH sometimes makes the body (BUT NOT THE ORB) null SOMEHOW!!!!!! + QSBWorldSync.Init(QSBWorldSync.GetUnityObjects() + .Where(x => x.GetAttachedOWRigidbody()) + .SortDeterministic()); } diff --git a/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs b/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs index 6d74e810..975f0b24 100644 --- a/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs +++ b/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs @@ -48,7 +48,6 @@ public class NomaiOrbTransformSync : UnsectoredTransformSync, ILinkedNetworkBeha protected override void Init() { base.Init(); - DebugLog.DebugWrite($"{this} - attached = {AttachedTransform}\nbody = {AttachedTransform?.GetAttachedOWRigidbody()}\nparent = {AttachedTransform?.GetAttachedOWRigidbody()?.GetOrigParent()}"); var body = AttachedTransform.GetAttachedOWRigidbody(); SetReferenceTransform(body.GetOrigParent()); From 1030e81274470ce69bba154bc009b5e0dfc67f7d Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 29 Aug 2022 22:07:25 -0700 Subject: [PATCH 11/47] i cry --- QSB/WorldSync/QSBWorldSync.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index ce53ade5..137eaa32 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -50,7 +50,7 @@ public static class QSBWorldSync } // let NH do things first :) - // makin it nice and long to be safe. dw things still work no matter the delay + // yes it has to be this long for it to always work. dw things still work no matter the delay await UniTask.DelayFrame(100, cancellationToken: _cts.Token); GameInit(); From 965c90abb2c0d5dc0fb06538bde1f03c150529e6 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 29 Aug 2022 22:27:33 -0700 Subject: [PATCH 12/47] world object ready checks on SolanumPatches --- QSB/Animation/NPC/Patches/SolanumPatches.cs | 11 ++++++++++- QSB/Syncs/Occasional/OccasionalManager.cs | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/QSB/Animation/NPC/Patches/SolanumPatches.cs b/QSB/Animation/NPC/Patches/SolanumPatches.cs index 0fbe03b6..69c3e616 100644 --- a/QSB/Animation/NPC/Patches/SolanumPatches.cs +++ b/QSB/Animation/NPC/Patches/SolanumPatches.cs @@ -17,6 +17,11 @@ public class SolanumPatches : QSBPatch [HarmonyPatch(typeof(SolanumAnimController), nameof(SolanumAnimController.LateUpdate))] public static bool SolanumLateUpdateReplacement(SolanumAnimController __instance) { + if (!QSBWorldSync.AllObjectsReady) + { + return true; + } + if (__instance._animatorStateEvents == null) { __instance._animatorStateEvents = __instance._animator.GetBehaviour(); @@ -43,6 +48,10 @@ public class SolanumPatches : QSBPatch [HarmonyPatch(typeof(NomaiConversationManager), nameof(NomaiConversationManager.Update))] public static bool ReplacementUpdate(NomaiConversationManager __instance) { + if (!QSBWorldSync.AllObjectsReady) + { + return true; + } var qsbObj = __instance._solanumAnimController.GetWorldObject(); __instance._playerInWatchVolume = qsbObj.Trigger.Occupants.Any(); @@ -206,4 +215,4 @@ public class SolanumPatches : QSBPatch return false; } -} \ No newline at end of file +} diff --git a/QSB/Syncs/Occasional/OccasionalManager.cs b/QSB/Syncs/Occasional/OccasionalManager.cs index 2597f694..b9d8cb56 100644 --- a/QSB/Syncs/Occasional/OccasionalManager.cs +++ b/QSB/Syncs/Occasional/OccasionalManager.cs @@ -1,7 +1,9 @@ using Cysharp.Threading.Tasks; using Mirror; +using OWML.Common; using QSB.Utility; using QSB.WorldSync; +using System; using System.Collections.Generic; using System.Threading; @@ -44,6 +46,8 @@ internal class OccasionalManager : WorldObjectManager public static void SpawnOccasional(OWRigidbody body, OWRigidbody refBody) { Bodies.Add((body, refBody)); + if (!body) DebugLog.DebugWrite($"BODY IS NULL {Environment.StackTrace}", MessageType.Error); + if (!refBody) DebugLog.DebugWrite($"BODY IS NULL {Environment.StackTrace}", MessageType.Error); if (QSBCore.IsHost) { From 9f9b61ebf61806ebd52801c606925dff50b3dd7b Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 29 Aug 2022 22:34:10 -0700 Subject: [PATCH 13/47] WEE IS SHORTER --- QSB/Syncs/Occasional/OccasionalManager.cs | 2 ++ QSB/WorldSync/QSBWorldSync.cs | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/QSB/Syncs/Occasional/OccasionalManager.cs b/QSB/Syncs/Occasional/OccasionalManager.cs index b9d8cb56..a003cc08 100644 --- a/QSB/Syncs/Occasional/OccasionalManager.cs +++ b/QSB/Syncs/Occasional/OccasionalManager.cs @@ -19,6 +19,8 @@ internal class OccasionalManager : WorldObjectManager { var gdBody = Locator._giantsDeep.GetOWRigidbody(); var cannon = Locator._orbitalProbeCannon.GetRequiredComponent(); + if (!cannon) DebugLog.DebugWrite(" CANNON IS NULL!", MessageType.Error); + if (!cannon.GetAttachedOWRigidbody()) DebugLog.DebugWrite(" CANNON BODY IS NULL!", MessageType.Error); SpawnOccasional(cannon.GetAttachedOWRigidbody(), gdBody); foreach (var proxy in cannon._realDebrisSectorProxies) diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 137eaa32..4c0d6518 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -50,8 +50,8 @@ public static class QSBWorldSync } // let NH do things first :) - // yes it has to be this long for it to always work. dw things still work no matter the delay - await UniTask.DelayFrame(100, cancellationToken: _cts.Token); + // i think NH only takes like 3 frames to do stuff so this should be okay + await UniTask.DelayFrame(10, cancellationToken: _cts.Token); GameInit(); From 78c7ee6c2ae1ba04dd96bc56e4b76477272c0458 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 29 Aug 2022 22:36:40 -0700 Subject: [PATCH 14/47] CANNON BODY CAN BE NULL --- QSB/Syncs/Occasional/OccasionalManager.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/QSB/Syncs/Occasional/OccasionalManager.cs b/QSB/Syncs/Occasional/OccasionalManager.cs index a003cc08..f1fb4045 100644 --- a/QSB/Syncs/Occasional/OccasionalManager.cs +++ b/QSB/Syncs/Occasional/OccasionalManager.cs @@ -1,9 +1,7 @@ using Cysharp.Threading.Tasks; using Mirror; -using OWML.Common; using QSB.Utility; using QSB.WorldSync; -using System; using System.Collections.Generic; using System.Threading; @@ -19,9 +17,11 @@ internal class OccasionalManager : WorldObjectManager { var gdBody = Locator._giantsDeep.GetOWRigidbody(); var cannon = Locator._orbitalProbeCannon.GetRequiredComponent(); - if (!cannon) DebugLog.DebugWrite(" CANNON IS NULL!", MessageType.Error); - if (!cannon.GetAttachedOWRigidbody()) DebugLog.DebugWrite(" CANNON BODY IS NULL!", MessageType.Error); - SpawnOccasional(cannon.GetAttachedOWRigidbody(), gdBody); + // NH sometimes makes the body (BUT NOT THE CANNON) null SOMEHOW!!!!!! + if (cannon.GetAttachedOWRigidbody()) + { + SpawnOccasional(cannon.GetAttachedOWRigidbody(), gdBody); + } foreach (var proxy in cannon._realDebrisSectorProxies) { @@ -48,8 +48,6 @@ internal class OccasionalManager : WorldObjectManager public static void SpawnOccasional(OWRigidbody body, OWRigidbody refBody) { Bodies.Add((body, refBody)); - if (!body) DebugLog.DebugWrite($"BODY IS NULL {Environment.StackTrace}", MessageType.Error); - if (!refBody) DebugLog.DebugWrite($"BODY IS NULL {Environment.StackTrace}", MessageType.Error); if (QSBCore.IsHost) { From 9411e7ba0ae204ceab15489f129fc60b468e694b Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 29 Aug 2022 22:47:24 -0700 Subject: [PATCH 15/47] NOPE NVM --- QSB/WorldSync/QSBWorldSync.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 4c0d6518..137eaa32 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -50,8 +50,8 @@ public static class QSBWorldSync } // let NH do things first :) - // i think NH only takes like 3 frames to do stuff so this should be okay - await UniTask.DelayFrame(10, cancellationToken: _cts.Token); + // yes it has to be this long for it to always work. dw things still work no matter the delay + await UniTask.DelayFrame(100, cancellationToken: _cts.Token); GameInit(); From bcababd4661adf68438d36d1b5f6ae52e4db77e5 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 29 Aug 2022 22:50:55 -0700 Subject: [PATCH 16/47] OK IT WORKS WITH 20 --- QSB/WorldSync/QSBWorldSync.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 137eaa32..95142319 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -51,7 +51,7 @@ public static class QSBWorldSync // let NH do things first :) // yes it has to be this long for it to always work. dw things still work no matter the delay - await UniTask.DelayFrame(100, cancellationToken: _cts.Token); + await UniTask.DelayFrame(20, cancellationToken: _cts.Token); GameInit(); From 5b4fb78ee6f3e3c71c505333c681715dd346d8c9 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Tue, 30 Aug 2022 14:00:04 -0700 Subject: [PATCH 17/47] calm the comments down a bit now that im not cuckoo crazy --- QSB/MeteorSync/MeteorManager.cs | 1 + QSB/OrbSync/OrbManager.cs | 2 +- QSB/Syncs/Occasional/OccasionalManager.cs | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/QSB/MeteorSync/MeteorManager.cs b/QSB/MeteorSync/MeteorManager.cs index 8bf325bd..6a98443f 100644 --- a/QSB/MeteorSync/MeteorManager.cs +++ b/QSB/MeteorSync/MeteorManager.cs @@ -18,6 +18,7 @@ public class MeteorManager : WorldObjectManager await UniTask.WaitUntil(() => LateInitializerManager.isDoneInitializing, cancellationToken: ct); // NH can make multiple so fuck it just choose one + // TODO: do GameObject.Find here instead WhiteHoleVolume = QSBWorldSync.GetUnityObjects().First(); QSBWorldSync.Init(); QSBWorldSync.Init(); diff --git a/QSB/OrbSync/OrbManager.cs b/QSB/OrbSync/OrbManager.cs index 054caed7..478e93f3 100644 --- a/QSB/OrbSync/OrbManager.cs +++ b/QSB/OrbSync/OrbManager.cs @@ -12,7 +12,7 @@ public class OrbManager : WorldObjectManager public override WorldObjectScene WorldObjectScene => WorldObjectScene.Both; public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct) => - // NH sometimes makes the body (BUT NOT THE ORB) null SOMEHOW!!!!!! + // NH sometimes makes the body (but not the orb) null QSBWorldSync.Init(QSBWorldSync.GetUnityObjects() .Where(x => x.GetAttachedOWRigidbody()) .SortDeterministic()); diff --git a/QSB/Syncs/Occasional/OccasionalManager.cs b/QSB/Syncs/Occasional/OccasionalManager.cs index f1fb4045..ebc3c43a 100644 --- a/QSB/Syncs/Occasional/OccasionalManager.cs +++ b/QSB/Syncs/Occasional/OccasionalManager.cs @@ -17,7 +17,7 @@ internal class OccasionalManager : WorldObjectManager { var gdBody = Locator._giantsDeep.GetOWRigidbody(); var cannon = Locator._orbitalProbeCannon.GetRequiredComponent(); - // NH sometimes makes the body (BUT NOT THE CANNON) null SOMEHOW!!!!!! + // NH sometimes makes the body (but not the cannon) null if (cannon.GetAttachedOWRigidbody()) { SpawnOccasional(cannon.GetAttachedOWRigidbody(), gdBody); From 1a1c7601af9631ec224302298c08e7375421222c Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Tue, 30 Aug 2022 14:01:03 -0700 Subject: [PATCH 18/47] mark my confusion --- QSB/ItemSync/WorldObjects/Items/QSBItem.cs | 2 +- QSB/OrbSync/OrbManager.cs | 2 +- QSB/Syncs/Occasional/OccasionalManager.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/QSB/ItemSync/WorldObjects/Items/QSBItem.cs b/QSB/ItemSync/WorldObjects/Items/QSBItem.cs index 89757767..ffb17065 100644 --- a/QSB/ItemSync/WorldObjects/Items/QSBItem.cs +++ b/QSB/ItemSync/WorldObjects/Items/QSBItem.cs @@ -54,7 +54,7 @@ public class QSBItem : WorldObject, IQSBItem _lastSector = sector.GetWorldObject(); } - // NH can make item not have parent + // NH can make item not have parent. what var socket = _lastParent?.GetComponent(); if (socket != null) { diff --git a/QSB/OrbSync/OrbManager.cs b/QSB/OrbSync/OrbManager.cs index 478e93f3..183687af 100644 --- a/QSB/OrbSync/OrbManager.cs +++ b/QSB/OrbSync/OrbManager.cs @@ -12,7 +12,7 @@ public class OrbManager : WorldObjectManager public override WorldObjectScene WorldObjectScene => WorldObjectScene.Both; public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct) => - // NH sometimes makes the body (but not the orb) null + // NH sometimes makes the body (but not the orb) null. what QSBWorldSync.Init(QSBWorldSync.GetUnityObjects() .Where(x => x.GetAttachedOWRigidbody()) .SortDeterministic()); diff --git a/QSB/Syncs/Occasional/OccasionalManager.cs b/QSB/Syncs/Occasional/OccasionalManager.cs index ebc3c43a..93b583a6 100644 --- a/QSB/Syncs/Occasional/OccasionalManager.cs +++ b/QSB/Syncs/Occasional/OccasionalManager.cs @@ -17,7 +17,7 @@ internal class OccasionalManager : WorldObjectManager { var gdBody = Locator._giantsDeep.GetOWRigidbody(); var cannon = Locator._orbitalProbeCannon.GetRequiredComponent(); - // NH sometimes makes the body (but not the cannon) null + // NH sometimes makes the body (but not the cannon) null. what if (cannon.GetAttachedOWRigidbody()) { SpawnOccasional(cannon.GetAttachedOWRigidbody(), gdBody); From ddd42330fed6e559e29b1bdd5dca080f767de091 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Tue, 30 Aug 2022 14:06:32 -0700 Subject: [PATCH 19/47] remove using --- QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs b/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs index 975f0b24..7fc2bb43 100644 --- a/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs +++ b/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs @@ -1,7 +1,6 @@ using QSB.AuthoritySync; using QSB.OrbSync.WorldObjects; using QSB.Syncs.Unsectored.Transforms; -using QSB.Utility; using QSB.Utility.LinkedWorldObject; using QSB.WorldSync; using UnityEngine; From e04cf85825c24d16b53ecf32ff49fcb548efb5f5 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 31 Aug 2022 23:13:36 -0700 Subject: [PATCH 20/47] increase the delay, but only do it when nh is installed --- QSB/WorldSync/QSBWorldSync.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 95142319..39a9aab6 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -50,8 +50,11 @@ public static class QSBWorldSync } // let NH do things first :) - // yes it has to be this long for it to always work. dw things still work no matter the delay - await UniTask.DelayFrame(20, cancellationToken: _cts.Token); + // yes it has to be this long for things to be the most stable with addons + if (QSBCore.Helper.Interaction.ModExists("xen.NewHorizons")) + { + await UniTask.DelayFrame(100, cancellationToken: _cts.Token); + } GameInit(); From e29fb169a57f91e4af39bb4da73be50c37331c03 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 2 Sep 2022 18:44:37 -0700 Subject: [PATCH 21/47] fuck me man idc anymore --- QSB/WorldSync/QSBWorldSync.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 39a9aab6..d9354f83 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -53,7 +53,7 @@ public static class QSBWorldSync // yes it has to be this long for things to be the most stable with addons if (QSBCore.Helper.Interaction.ModExists("xen.NewHorizons")) { - await UniTask.DelayFrame(100, cancellationToken: _cts.Token); + await UniTask.DelayFrame(1000, cancellationToken: _cts.Token); } GameInit(); From 4aa8c2bd825ce863e44dbe4b038f677da8bfc3d1 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 2 Sep 2022 22:12:15 -0700 Subject: [PATCH 22/47] raft what moment --- QSB/EchoesOfTheEye/RaftSync/RaftManager.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/QSB/EchoesOfTheEye/RaftSync/RaftManager.cs b/QSB/EchoesOfTheEye/RaftSync/RaftManager.cs index 4dc784a0..d1e3c3f2 100644 --- a/QSB/EchoesOfTheEye/RaftSync/RaftManager.cs +++ b/QSB/EchoesOfTheEye/RaftSync/RaftManager.cs @@ -1,6 +1,8 @@ using Cysharp.Threading.Tasks; using QSB.EchoesOfTheEye.RaftSync.WorldObjects; +using QSB.Utility; using QSB.WorldSync; +using System.Linq; using System.Threading; namespace QSB.EchoesOfTheEye.RaftSync; @@ -12,7 +14,10 @@ public class RaftManager : WorldObjectManager public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct) { - QSBWorldSync.Init(); + // NH sometimes makes the body (but not the raft) null. what + QSBWorldSync.Init(QSBWorldSync.GetUnityObjects() + .Where(x => x.GetAttachedOWRigidbody()) + .SortDeterministic()); QSBWorldSync.Init(); } } From 3cf3728e800fb8acc1bb57dd747865d7d66bfd39 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 2 Sep 2022 22:53:30 -0700 Subject: [PATCH 23/47] fix thruster variable syncer trying to get the local player before local player exists --- QSB/ModelShip/ModelShipThrusterVariableSyncer.cs | 9 +++------ QSB/ShipSync/ShipThrusterVariableSyncer.cs | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/QSB/ModelShip/ModelShipThrusterVariableSyncer.cs b/QSB/ModelShip/ModelShipThrusterVariableSyncer.cs index 30c82784..3e896587 100644 --- a/QSB/ModelShip/ModelShipThrusterVariableSyncer.cs +++ b/QSB/ModelShip/ModelShipThrusterVariableSyncer.cs @@ -1,9 +1,6 @@ -using Mirror; -using QSB.Player; -using QSB.Utility; +using QSB.Player; +using QSB.Player.TransformSync; using QSB.Utility.VariableSync; -using System.Collections.Generic; -using System.Linq; using UnityEngine; namespace QSB.ModelShip; @@ -26,7 +23,7 @@ public class ModelShipThrusterVariableSyncer : MonoBehaviour public void Update() { - if (QSBPlayerManager.LocalPlayer.FlyingModelShip) + if (PlayerTransformSync.LocalInstance && QSBPlayerManager.LocalPlayer.FlyingModelShip) { GetFromShip(); return; diff --git a/QSB/ShipSync/ShipThrusterVariableSyncer.cs b/QSB/ShipSync/ShipThrusterVariableSyncer.cs index c8e31673..bb722be1 100644 --- a/QSB/ShipSync/ShipThrusterVariableSyncer.cs +++ b/QSB/ShipSync/ShipThrusterVariableSyncer.cs @@ -1,7 +1,7 @@ using Mirror; using QSB.Player; +using QSB.Player.TransformSync; using QSB.Utility.VariableSync; -using QSB.WorldSync; using UnityEngine; namespace QSB.ShipSync; @@ -21,7 +21,7 @@ public class ShipThrusterVariableSyncer : NetworkBehaviour public void Update() { - if (QSBPlayerManager.LocalPlayer.FlyingShip) + if (PlayerTransformSync.LocalInstance && QSBPlayerManager.LocalPlayer.FlyingShip) { GetFromShip(); return; From 18f97fca78a87f9deddf772b25f4c9dd0aad8234 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 2 Sep 2022 22:54:07 -0700 Subject: [PATCH 24/47] TODO --- QSB/WorldSync/QSBWorldSync.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index d9354f83..6c6a1777 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -53,6 +53,7 @@ public static class QSBWorldSync // yes it has to be this long for things to be the most stable with addons if (QSBCore.Helper.Interaction.ModExists("xen.NewHorizons")) { + // TODO: convince NH to use a boolean for Star System Loaded event instead of having to track it manually myself await UniTask.DelayFrame(1000, cancellationToken: _cts.Token); } From 03e864e0ee9f32ac7be0beff331e4209e43c4206 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 6 Oct 2022 14:45:40 -0700 Subject: [PATCH 25/47] remove "what"s --- QSB/EchoesOfTheEye/RaftSync/RaftManager.cs | 7 +------ QSB/ItemSync/WorldObjects/Items/QSBItem.cs | 3 ++- QSB/OrbSync/OrbManager.cs | 7 +------ QSB/Syncs/Occasional/OccasionalManager.cs | 6 +----- QSB/WorldSync/QSBWorldSync.cs | 11 ++--------- 5 files changed, 7 insertions(+), 27 deletions(-) diff --git a/QSB/EchoesOfTheEye/RaftSync/RaftManager.cs b/QSB/EchoesOfTheEye/RaftSync/RaftManager.cs index d1e3c3f2..4dc784a0 100644 --- a/QSB/EchoesOfTheEye/RaftSync/RaftManager.cs +++ b/QSB/EchoesOfTheEye/RaftSync/RaftManager.cs @@ -1,8 +1,6 @@ using Cysharp.Threading.Tasks; using QSB.EchoesOfTheEye.RaftSync.WorldObjects; -using QSB.Utility; using QSB.WorldSync; -using System.Linq; using System.Threading; namespace QSB.EchoesOfTheEye.RaftSync; @@ -14,10 +12,7 @@ public class RaftManager : WorldObjectManager public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct) { - // NH sometimes makes the body (but not the raft) null. what - QSBWorldSync.Init(QSBWorldSync.GetUnityObjects() - .Where(x => x.GetAttachedOWRigidbody()) - .SortDeterministic()); + QSBWorldSync.Init(); QSBWorldSync.Init(); } } diff --git a/QSB/ItemSync/WorldObjects/Items/QSBItem.cs b/QSB/ItemSync/WorldObjects/Items/QSBItem.cs index 1df80696..1b7f91c1 100644 --- a/QSB/ItemSync/WorldObjects/Items/QSBItem.cs +++ b/QSB/ItemSync/WorldObjects/Items/QSBItem.cs @@ -55,7 +55,8 @@ public class QSBItem : WorldObject, IQSBItem } // NH can make item not have parent. what - var socket = _lastParent?.GetComponent(); + // BUG: this happens because qsb finds nh prefabs. we need to make it not do this + var socket = _lastParent.GetComponent(); if (socket != null) { _lastSocket = socket.GetWorldObject(); diff --git a/QSB/OrbSync/OrbManager.cs b/QSB/OrbSync/OrbManager.cs index 183687af..0b5879f8 100644 --- a/QSB/OrbSync/OrbManager.cs +++ b/QSB/OrbSync/OrbManager.cs @@ -1,8 +1,6 @@ using Cysharp.Threading.Tasks; using QSB.OrbSync.WorldObjects; -using QSB.Utility; using QSB.WorldSync; -using System.Linq; using System.Threading; namespace QSB.OrbSync; @@ -12,8 +10,5 @@ public class OrbManager : WorldObjectManager public override WorldObjectScene WorldObjectScene => WorldObjectScene.Both; public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct) => - // NH sometimes makes the body (but not the orb) null. what - QSBWorldSync.Init(QSBWorldSync.GetUnityObjects() - .Where(x => x.GetAttachedOWRigidbody()) - .SortDeterministic()); + QSBWorldSync.Init(); } diff --git a/QSB/Syncs/Occasional/OccasionalManager.cs b/QSB/Syncs/Occasional/OccasionalManager.cs index 93b583a6..2597f694 100644 --- a/QSB/Syncs/Occasional/OccasionalManager.cs +++ b/QSB/Syncs/Occasional/OccasionalManager.cs @@ -17,11 +17,7 @@ internal class OccasionalManager : WorldObjectManager { var gdBody = Locator._giantsDeep.GetOWRigidbody(); var cannon = Locator._orbitalProbeCannon.GetRequiredComponent(); - // NH sometimes makes the body (but not the cannon) null. what - if (cannon.GetAttachedOWRigidbody()) - { - SpawnOccasional(cannon.GetAttachedOWRigidbody(), gdBody); - } + SpawnOccasional(cannon.GetAttachedOWRigidbody(), gdBody); foreach (var proxy in cannon._realDebrisSectorProxies) { diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 6c6a1777..d28ddb77 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -49,14 +49,6 @@ public static class QSBWorldSync await UniTask.WaitUntil(() => PlayerTransformSync.LocalInstance, cancellationToken: _cts.Token); } - // let NH do things first :) - // yes it has to be this long for things to be the most stable with addons - if (QSBCore.Helper.Interaction.ModExists("xen.NewHorizons")) - { - // TODO: convince NH to use a boolean for Star System Loaded event instead of having to track it manually myself - await UniTask.DelayFrame(1000, cancellationToken: _cts.Token); - } - GameInit(); foreach (var manager in Managers) @@ -196,7 +188,8 @@ public static class QSBWorldSync { // So objects have time to be deleted, made, whatever // i.e. wait until Start has been called - Delay.RunNextFrame(() => BuildWorldObjects(loadScene).Forget()); + // TODO: see if this number of frames actually works. TWEAK! + Delay.RunFramesLater(10, () => BuildWorldObjects(loadScene).Forget()); } }; From 75813e0921843969607136b8fec028bb5e315e94 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 6 Oct 2022 18:52:32 -0700 Subject: [PATCH 26/47] do a null check here for now so at least it doesnt throw --- QSB/ItemSync/WorldObjects/Items/QSBItem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/ItemSync/WorldObjects/Items/QSBItem.cs b/QSB/ItemSync/WorldObjects/Items/QSBItem.cs index 1b7f91c1..24327d55 100644 --- a/QSB/ItemSync/WorldObjects/Items/QSBItem.cs +++ b/QSB/ItemSync/WorldObjects/Items/QSBItem.cs @@ -56,7 +56,7 @@ public class QSBItem : WorldObject, IQSBItem // NH can make item not have parent. what // BUG: this happens because qsb finds nh prefabs. we need to make it not do this - var socket = _lastParent.GetComponent(); + var socket = _lastParent?.GetComponent(); if (socket != null) { _lastSocket = socket.GetWorldObject(); From b74897486d43c1ace7cc3063e586b2dab23aeb7b Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 6 Oct 2022 18:54:57 -0700 Subject: [PATCH 27/47] make NewHorizons not incompatible --- QSB/QSBCore.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/QSBCore.cs b/QSB/QSBCore.cs index b7107571..75f1ee3c 100644 --- a/QSB/QSBCore.cs +++ b/QSB/QSBCore.cs @@ -69,7 +69,7 @@ public class QSBCore : ModBehaviour { // incompatible mods "Raicuparta.NomaiVR", - "xen.NewHorizons", + // "xen.NewHorizons", "Vesper.AutoResume", "Vesper.OuterWildsMMO", "_nebula.StopTime", From a70f20e1961849a5a90d9d6e5abf32729dbdca46 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 19 Oct 2022 23:54:35 -0700 Subject: [PATCH 28/47] TEMPORARY: disable time sync --- QSB/QSBCore.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/QSB/QSBCore.cs b/QSB/QSBCore.cs index 75f1ee3c..bf0c5eba 100644 --- a/QSB/QSBCore.cs +++ b/QSB/QSBCore.cs @@ -149,6 +149,8 @@ public class QSBCore : ModBehaviour DebugSettings.UseKcpTransport = true; DebugSettings.DebugMode = true; } + // TODO: TEMPORARY - REMOVE LATER + DebugSettings.AvoidTimeSync = true; RegisterAddons(); From 14e59cd7ceef6ec5763852e4420de1aa1b614946 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 29 Oct 2022 14:43:57 -0700 Subject: [PATCH 29/47] make it not include DontDestroyOnLoad things --- QSB/ItemSync/WorldObjects/Items/QSBItem.cs | 4 +--- QSB/WorldSync/QSBWorldSync.cs | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/QSB/ItemSync/WorldObjects/Items/QSBItem.cs b/QSB/ItemSync/WorldObjects/Items/QSBItem.cs index 24327d55..bfb67695 100644 --- a/QSB/ItemSync/WorldObjects/Items/QSBItem.cs +++ b/QSB/ItemSync/WorldObjects/Items/QSBItem.cs @@ -54,9 +54,7 @@ public class QSBItem : WorldObject, IQSBItem _lastSector = sector.GetWorldObject(); } - // NH can make item not have parent. what - // BUG: this happens because qsb finds nh prefabs. we need to make it not do this - var socket = _lastParent?.GetComponent(); + var socket = _lastParent.GetComponent(); if (socket != null) { _lastSocket = socket.GetWorldObject(); diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 7ec4d732..972b6909 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -312,7 +312,7 @@ public static class QSBWorldSync public static IEnumerable GetUnityObjects() where TUnityObject : MonoBehaviour => Resources.FindObjectsOfTypeAll() - .Where(x => x.gameObject.scene.name != null); + .Where(x => x.gameObject.scene.name is not (null or "DontDestroyOnLoad")); public static void Init() where TWorldObject : WorldObject, new() From eb8b473546c8c19b081f0227c35e4bc3cef1ab9d Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 29 Oct 2022 14:45:52 -0700 Subject: [PATCH 30/47] add comment --- QSB/WorldSync/QSBWorldSync.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 972b6909..26a9aa9e 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -307,7 +307,8 @@ public static class QSBWorldSync => GetUnityObjects().Single(); /// - /// not deterministic across platforms + /// not deterministic across platforms. + /// excludes prefabs and DontDestroyOnLoad objects. /// public static IEnumerable GetUnityObjects() where TUnityObject : MonoBehaviour From 585ee0a89e47ca9fe115bbac4d65597e437b2ced Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 29 Oct 2022 15:37:40 -0700 Subject: [PATCH 31/47] okay that didnt work --- QSB/ItemSync/WorldObjects/Items/QSBItem.cs | 3 ++- QSB/WorldSync/QSBWorldSync.cs | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/QSB/ItemSync/WorldObjects/Items/QSBItem.cs b/QSB/ItemSync/WorldObjects/Items/QSBItem.cs index bfb67695..1df80696 100644 --- a/QSB/ItemSync/WorldObjects/Items/QSBItem.cs +++ b/QSB/ItemSync/WorldObjects/Items/QSBItem.cs @@ -54,7 +54,8 @@ public class QSBItem : WorldObject, IQSBItem _lastSector = sector.GetWorldObject(); } - var socket = _lastParent.GetComponent(); + // NH can make item not have parent. what + var socket = _lastParent?.GetComponent(); if (socket != null) { _lastSocket = socket.GetWorldObject(); diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 26a9aa9e..7ec4d732 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -307,13 +307,12 @@ public static class QSBWorldSync => GetUnityObjects().Single(); /// - /// not deterministic across platforms. - /// excludes prefabs and DontDestroyOnLoad objects. + /// not deterministic across platforms /// public static IEnumerable GetUnityObjects() where TUnityObject : MonoBehaviour => Resources.FindObjectsOfTypeAll() - .Where(x => x.gameObject.scene.name is not (null or "DontDestroyOnLoad")); + .Where(x => x.gameObject.scene.name != null); public static void Init() where TWorldObject : WorldObject, new() From 5374e0722d59f585cf5dc235ebc841740545e5b7 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 29 Oct 2022 15:48:35 -0700 Subject: [PATCH 32/47] nvm the nvm bruh --- QSB/ItemSync/WorldObjects/Items/QSBItem.cs | 2 +- QSB/Syncs/Occasional/OccasionalManager.cs | 1 + QSB/WorldSync/QSBWorldSync.cs | 5 +++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/QSB/ItemSync/WorldObjects/Items/QSBItem.cs b/QSB/ItemSync/WorldObjects/Items/QSBItem.cs index 1df80696..226221d6 100644 --- a/QSB/ItemSync/WorldObjects/Items/QSBItem.cs +++ b/QSB/ItemSync/WorldObjects/Items/QSBItem.cs @@ -54,7 +54,7 @@ public class QSBItem : WorldObject, IQSBItem _lastSector = sector.GetWorldObject(); } - // NH can make item not have parent. what + // BUG: even when not including DontDestroyOnLoad things, NH still can make parent null sometimes. what var socket = _lastParent?.GetComponent(); if (socket != null) { diff --git a/QSB/Syncs/Occasional/OccasionalManager.cs b/QSB/Syncs/Occasional/OccasionalManager.cs index 2597f694..c53a6dfd 100644 --- a/QSB/Syncs/Occasional/OccasionalManager.cs +++ b/QSB/Syncs/Occasional/OccasionalManager.cs @@ -7,6 +7,7 @@ using System.Threading; namespace QSB.Syncs.Occasional; +// BUG: somehow, not including DontDestroyOnLoad things makes this fuck up with NH internal class OccasionalManager : WorldObjectManager { public override WorldObjectScene WorldObjectScene => WorldObjectScene.SolarSystem; diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 7ec4d732..26a9aa9e 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -307,12 +307,13 @@ public static class QSBWorldSync => GetUnityObjects().Single(); /// - /// not deterministic across platforms + /// not deterministic across platforms. + /// excludes prefabs and DontDestroyOnLoad objects. /// public static IEnumerable GetUnityObjects() where TUnityObject : MonoBehaviour => Resources.FindObjectsOfTypeAll() - .Where(x => x.gameObject.scene.name != null); + .Where(x => x.gameObject.scene.name is not (null or "DontDestroyOnLoad")); public static void Init() where TWorldObject : WorldObject, new() From f58bd7ad7cd2e6c95c146eab364e9455e49e1401 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 2 Nov 2022 00:00:30 -0400 Subject: [PATCH 33/47] This was NRE-ing --- QSB/EchoesOfTheEye/QSBRotatingElements.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/QSB/EchoesOfTheEye/QSBRotatingElements.cs b/QSB/EchoesOfTheEye/QSBRotatingElements.cs index 05b08c69..9be7c3eb 100644 --- a/QSB/EchoesOfTheEye/QSBRotatingElements.cs +++ b/QSB/EchoesOfTheEye/QSBRotatingElements.cs @@ -37,10 +37,13 @@ internal abstract class QSBRotatingElements : LinkedWorldObject { base.OnRemoval(); - foreach (var lightSensor in _qsbLightSensors) + if (_qsbLightSensors != null) { - lightSensor.OnDetectLocalLight -= OnDetectLocalLight; - lightSensor.OnDetectLocalDarkness -= OnDetectLocalDarkness; + foreach (var lightSensor in _qsbLightSensors) + { + lightSensor.OnDetectLocalLight -= OnDetectLocalLight; + lightSensor.OnDetectLocalDarkness -= OnDetectLocalDarkness; + } } } From d74b766366eeb799a7224d019e42911bc5343d81 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 2 Nov 2022 00:00:56 -0400 Subject: [PATCH 34/47] Just use the base game white hole --- QSB/MeteorSync/MeteorManager.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/QSB/MeteorSync/MeteorManager.cs b/QSB/MeteorSync/MeteorManager.cs index 6a98443f..29c841f8 100644 --- a/QSB/MeteorSync/MeteorManager.cs +++ b/QSB/MeteorSync/MeteorManager.cs @@ -17,9 +17,9 @@ public class MeteorManager : WorldObjectManager // wait for all late initializers (which includes meteor launchers) to finish await UniTask.WaitUntil(() => LateInitializerManager.isDoneInitializing, cancellationToken: ct); - // NH can make multiple so fuck it just choose one - // TODO: do GameObject.Find here instead - WhiteHoleVolume = QSBWorldSync.GetUnityObjects().First(); + // NH can make multiple so ensure its the stock whitehole + var whiteHole = QSBWorldSync.GetUnityObjects().First(x => x.GetAstroObjectName() == AstroObject.Name.WhiteHole); + WhiteHoleVolume = whiteHole?.GetComponentInChildren(); QSBWorldSync.Init(); QSBWorldSync.Init(); QSBWorldSync.Init(); From 7a4922315254ffa6f030ef26504d6300efab8938 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 2 Nov 2022 00:59:48 -0400 Subject: [PATCH 35/47] Wait for NH to make system before building world objects --- QSB/ModInteractions/ModInteractionManager.cs | 36 +++++++++++++++++++ .../NewHorizons/INewHorizons.cs | 12 +++++++ QSB/QSBCore.cs | 5 +-- QSB/WorldSync/QSBWorldSync.cs | 13 +++++-- 4 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 QSB/ModInteractions/ModInteractionManager.cs create mode 100644 QSB/ModInteractions/NewHorizons/INewHorizons.cs diff --git a/QSB/ModInteractions/ModInteractionManager.cs b/QSB/ModInteractions/ModInteractionManager.cs new file mode 100644 index 00000000..5d788ce8 --- /dev/null +++ b/QSB/ModInteractions/ModInteractionManager.cs @@ -0,0 +1,36 @@ +using QSB.ModInteractions.NewHorizons; +using QSB.Utility; +using UnityEngine.SceneManagement; + +namespace QSB.ModInteractions; + +internal static class ModInteractionManager +{ + public static bool IsNHInstalled { get; private set; } + public static bool IsNHReady { get; private set; } + + private static bool _init = false; + + private static INewHorizons _newHorizons; + + public static void Init() + { + if (_init) return; + + _init = true; + + _newHorizons = QSBCore.Helper.Interaction.TryGetModApi("xen.NewHorizons"); + IsNHInstalled = _newHorizons != null; + + if (IsNHInstalled) + { + _newHorizons.GetStarSystemLoadedEvent().AddListener(OnStarSystemLoaded); + SceneManager.sceneUnloaded += SceneManager_sceneUnloaded; + } + + DebugLog.DebugWrite($"New Horizons is {(IsNHInstalled ? "installed" : "not installed")}"); + } + + private static void OnStarSystemLoaded(string _) => IsNHReady = true; + private static void SceneManager_sceneUnloaded(Scene _) => IsNHReady = false; +} diff --git a/QSB/ModInteractions/NewHorizons/INewHorizons.cs b/QSB/ModInteractions/NewHorizons/INewHorizons.cs new file mode 100644 index 00000000..497217a2 --- /dev/null +++ b/QSB/ModInteractions/NewHorizons/INewHorizons.cs @@ -0,0 +1,12 @@ +using UnityEngine.Events; + +namespace QSB.ModInteractions.NewHorizons; + +internal interface INewHorizons +{ + /// + /// An event invoked when NH has finished generating all planets for a new star system. + /// Gives the name of the star system that was just loaded. + /// + UnityEvent GetStarSystemLoadedEvent(); +} diff --git a/QSB/QSBCore.cs b/QSB/QSBCore.cs index bf0c5eba..de5cf882 100644 --- a/QSB/QSBCore.cs +++ b/QSB/QSBCore.cs @@ -4,6 +4,7 @@ using OWML.Common; using OWML.ModHelper; using QSB.Localization; using QSB.Menus; +using QSB.ModInteractions; using QSB.Patches; using QSB.QuantumSync; using QSB.SaveSync; @@ -149,8 +150,6 @@ public class QSBCore : ModBehaviour DebugSettings.UseKcpTransport = true; DebugSettings.DebugMode = true; } - // TODO: TEMPORARY - REMOVE LATER - DebugSettings.AvoidTimeSync = true; RegisterAddons(); @@ -183,6 +182,8 @@ public class QSBCore : ModBehaviour QSBWorldSync.Managers = components.OfType().ToArray(); QSBPatchManager.OnPatchType += OnPatchType; QSBPatchManager.OnUnpatchType += OnUnpatchType; + + ModInteractionManager.Init(); } private static void OnPatchType(QSBPatchTypes type) diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 26a9aa9e..765a1650 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -5,6 +5,7 @@ using QSB.ConversationSync.Messages; using QSB.LogSync; using QSB.LogSync.Messages; using QSB.Messaging; +using QSB.ModInteractions; using QSB.Player.TransformSync; using QSB.TriggerSync.WorldObjects; using QSB.Utility; @@ -193,8 +194,16 @@ public static class QSBWorldSync { // So objects have time to be deleted, made, whatever // i.e. wait until Start has been called - // TODO: see if this number of frames actually works. TWEAK! - Delay.RunFramesLater(10, () => BuildWorldObjects(loadScene).Forget()); + + // If NH is installed, wait for it to finish generating the solar system + if (ModInteractionManager.IsNHInstalled) + { + Delay.RunWhen(() => ModInteractionManager.IsNHReady, () => BuildWorldObjects(loadScene).Forget()); + } + else + { + Delay.RunNextFrame(() => BuildWorldObjects(loadScene).Forget()); + } } }; From c8ccccf9c88c01e5966958338081737f13265baa Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Wed, 9 Nov 2022 14:15:12 +0000 Subject: [PATCH 36/47] fix hash issue --- QSB/WorldSync/QSBWorldSync.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 765a1650..421a836f 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -190,19 +190,25 @@ public static class QSBWorldSync RemoveWorldObjects(); QSBSceneManager.OnPostSceneLoad += (_, loadScene) => { + var allDestroyOnDlc = GetUnityObjects(); + var allHaveChecked = allDestroyOnDlc.All(x => x._hasChecked == true); + if (QSBCore.IsInMultiplayer && loadScene.IsUniverseScene()) { - // So objects have time to be deleted, made, whatever - // i.e. wait until Start has been called + // wait for DLC (or non-DLC) objects to be checked for destruction + // then wait another frame so they can actually be destroyed + // this also means that we wait for Awake() and Start() to run - // If NH is installed, wait for it to finish generating the solar system if (ModInteractionManager.IsNHInstalled) { - Delay.RunWhen(() => ModInteractionManager.IsNHReady, () => BuildWorldObjects(loadScene).Forget()); + // If NH is installed, wait for it to finish generating the solar system + Delay.RunWhen(() => ModInteractionManager.IsNHReady && allHaveChecked, + () => Delay.RunNextFrame(() => BuildWorldObjects(loadScene).Forget())); } else { - Delay.RunNextFrame(() => BuildWorldObjects(loadScene).Forget()); + Delay.RunWhen(() => allHaveChecked, + () => Delay.RunNextFrame(() => BuildWorldObjects(loadScene).Forget())); } } }; From 98def9885ab436a699f38fd67b1b13c22999c13d Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 9 Nov 2022 12:01:54 -0800 Subject: [PATCH 37/47] Revert "fix hash issue" This reverts commit c8ccccf9c88c01e5966958338081737f13265baa. --- QSB/WorldSync/QSBWorldSync.cs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 421a836f..765a1650 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -190,25 +190,19 @@ public static class QSBWorldSync RemoveWorldObjects(); QSBSceneManager.OnPostSceneLoad += (_, loadScene) => { - var allDestroyOnDlc = GetUnityObjects(); - var allHaveChecked = allDestroyOnDlc.All(x => x._hasChecked == true); - if (QSBCore.IsInMultiplayer && loadScene.IsUniverseScene()) { - // wait for DLC (or non-DLC) objects to be checked for destruction - // then wait another frame so they can actually be destroyed - // this also means that we wait for Awake() and Start() to run + // So objects have time to be deleted, made, whatever + // i.e. wait until Start has been called + // If NH is installed, wait for it to finish generating the solar system if (ModInteractionManager.IsNHInstalled) { - // If NH is installed, wait for it to finish generating the solar system - Delay.RunWhen(() => ModInteractionManager.IsNHReady && allHaveChecked, - () => Delay.RunNextFrame(() => BuildWorldObjects(loadScene).Forget())); + Delay.RunWhen(() => ModInteractionManager.IsNHReady, () => BuildWorldObjects(loadScene).Forget()); } else { - Delay.RunWhen(() => allHaveChecked, - () => Delay.RunNextFrame(() => BuildWorldObjects(loadScene).Forget())); + Delay.RunNextFrame(() => BuildWorldObjects(loadScene).Forget()); } } }; From fac4abd39bb2451e1ae24289e07c1b79172a37c6 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 9 Nov 2022 12:02:22 -0800 Subject: [PATCH 38/47] just run next frame here too --- QSB/WorldSync/QSBWorldSync.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 765a1650..6281bc30 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -198,7 +198,8 @@ public static class QSBWorldSync // If NH is installed, wait for it to finish generating the solar system if (ModInteractionManager.IsNHInstalled) { - Delay.RunWhen(() => ModInteractionManager.IsNHReady, () => BuildWorldObjects(loadScene).Forget()); + Delay.RunWhen(() => ModInteractionManager.IsNHReady, + () => Delay.RunNextFrame(() => BuildWorldObjects(loadScene).Forget())); } else { From 2912c27f05c6d0d1ff894febfb65b53fc3a4f5cf Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 9 Nov 2022 12:43:22 -0800 Subject: [PATCH 39/47] Revert "Wait for NH to make system before building world objects" This reverts commit 7a492231 --- QSB/ModInteractions/ModInteractionManager.cs | 36 ------------------- .../NewHorizons/INewHorizons.cs | 12 ------- QSB/QSBCore.cs | 5 ++- QSB/WorldSync/QSBWorldSync.cs | 14 ++------ 4 files changed, 4 insertions(+), 63 deletions(-) delete mode 100644 QSB/ModInteractions/ModInteractionManager.cs delete mode 100644 QSB/ModInteractions/NewHorizons/INewHorizons.cs diff --git a/QSB/ModInteractions/ModInteractionManager.cs b/QSB/ModInteractions/ModInteractionManager.cs deleted file mode 100644 index 5d788ce8..00000000 --- a/QSB/ModInteractions/ModInteractionManager.cs +++ /dev/null @@ -1,36 +0,0 @@ -using QSB.ModInteractions.NewHorizons; -using QSB.Utility; -using UnityEngine.SceneManagement; - -namespace QSB.ModInteractions; - -internal static class ModInteractionManager -{ - public static bool IsNHInstalled { get; private set; } - public static bool IsNHReady { get; private set; } - - private static bool _init = false; - - private static INewHorizons _newHorizons; - - public static void Init() - { - if (_init) return; - - _init = true; - - _newHorizons = QSBCore.Helper.Interaction.TryGetModApi("xen.NewHorizons"); - IsNHInstalled = _newHorizons != null; - - if (IsNHInstalled) - { - _newHorizons.GetStarSystemLoadedEvent().AddListener(OnStarSystemLoaded); - SceneManager.sceneUnloaded += SceneManager_sceneUnloaded; - } - - DebugLog.DebugWrite($"New Horizons is {(IsNHInstalled ? "installed" : "not installed")}"); - } - - private static void OnStarSystemLoaded(string _) => IsNHReady = true; - private static void SceneManager_sceneUnloaded(Scene _) => IsNHReady = false; -} diff --git a/QSB/ModInteractions/NewHorizons/INewHorizons.cs b/QSB/ModInteractions/NewHorizons/INewHorizons.cs deleted file mode 100644 index 497217a2..00000000 --- a/QSB/ModInteractions/NewHorizons/INewHorizons.cs +++ /dev/null @@ -1,12 +0,0 @@ -using UnityEngine.Events; - -namespace QSB.ModInteractions.NewHorizons; - -internal interface INewHorizons -{ - /// - /// An event invoked when NH has finished generating all planets for a new star system. - /// Gives the name of the star system that was just loaded. - /// - UnityEvent GetStarSystemLoadedEvent(); -} diff --git a/QSB/QSBCore.cs b/QSB/QSBCore.cs index de5cf882..bf0c5eba 100644 --- a/QSB/QSBCore.cs +++ b/QSB/QSBCore.cs @@ -4,7 +4,6 @@ using OWML.Common; using OWML.ModHelper; using QSB.Localization; using QSB.Menus; -using QSB.ModInteractions; using QSB.Patches; using QSB.QuantumSync; using QSB.SaveSync; @@ -150,6 +149,8 @@ public class QSBCore : ModBehaviour DebugSettings.UseKcpTransport = true; DebugSettings.DebugMode = true; } + // TODO: TEMPORARY - REMOVE LATER + DebugSettings.AvoidTimeSync = true; RegisterAddons(); @@ -182,8 +183,6 @@ public class QSBCore : ModBehaviour QSBWorldSync.Managers = components.OfType().ToArray(); QSBPatchManager.OnPatchType += OnPatchType; QSBPatchManager.OnUnpatchType += OnUnpatchType; - - ModInteractionManager.Init(); } private static void OnPatchType(QSBPatchTypes type) diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 6281bc30..26a9aa9e 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -5,7 +5,6 @@ using QSB.ConversationSync.Messages; using QSB.LogSync; using QSB.LogSync.Messages; using QSB.Messaging; -using QSB.ModInteractions; using QSB.Player.TransformSync; using QSB.TriggerSync.WorldObjects; using QSB.Utility; @@ -194,17 +193,8 @@ public static class QSBWorldSync { // So objects have time to be deleted, made, whatever // i.e. wait until Start has been called - - // If NH is installed, wait for it to finish generating the solar system - if (ModInteractionManager.IsNHInstalled) - { - Delay.RunWhen(() => ModInteractionManager.IsNHReady, - () => Delay.RunNextFrame(() => BuildWorldObjects(loadScene).Forget())); - } - else - { - Delay.RunNextFrame(() => BuildWorldObjects(loadScene).Forget()); - } + // TODO: see if this number of frames actually works. TWEAK! + Delay.RunFramesLater(10, () => BuildWorldObjects(loadScene).Forget()); } }; From 6d85487857a17667cf229c2b672db53b6c0634ca Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 9 Nov 2022 22:11:00 -0800 Subject: [PATCH 40/47] gorp --- QSB/QSBCore.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/QSB/QSBCore.cs b/QSB/QSBCore.cs index bf0c5eba..75f1ee3c 100644 --- a/QSB/QSBCore.cs +++ b/QSB/QSBCore.cs @@ -149,8 +149,6 @@ public class QSBCore : ModBehaviour DebugSettings.UseKcpTransport = true; DebugSettings.DebugMode = true; } - // TODO: TEMPORARY - REMOVE LATER - DebugSettings.AvoidTimeSync = true; RegisterAddons(); From 546da61a7e2789707b7fa137e2fb76d679a135c5 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 10 Nov 2022 15:16:53 -0800 Subject: [PATCH 41/47] do error here --- QSB/ItemSync/WorldObjects/Items/QSBItem.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/QSB/ItemSync/WorldObjects/Items/QSBItem.cs b/QSB/ItemSync/WorldObjects/Items/QSBItem.cs index 226221d6..9ca206f5 100644 --- a/QSB/ItemSync/WorldObjects/Items/QSBItem.cs +++ b/QSB/ItemSync/WorldObjects/Items/QSBItem.cs @@ -1,9 +1,11 @@ using Cysharp.Threading.Tasks; +using OWML.Common; using QSB.ItemSync.Messages; using QSB.ItemSync.WorldObjects.Sockets; using QSB.Messaging; using QSB.Player; using QSB.SectorSync.WorldObjects; +using QSB.Utility; using QSB.WorldSync; using System.Threading; using UnityEngine; @@ -54,8 +56,13 @@ public class QSBItem : WorldObject, IQSBItem _lastSector = sector.GetWorldObject(); } - // BUG: even when not including DontDestroyOnLoad things, NH still can make parent null sometimes. what - var socket = _lastParent?.GetComponent(); + // TODO test and then remove + if (!_lastParent) + { + DebugLog.DebugWrite($"{this} - parent for item {AttachedObject} at {AttachedObject.DeterministicPath()} is null! wtf!", MessageType.Error); + return; + } + var socket = _lastParent.GetComponent(); if (socket != null) { _lastSocket = socket.GetWorldObject(); From ce08715f5ee4c46ce9d2aa295d4bcc1f075cef3b Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Fri, 11 Nov 2022 14:33:49 +0000 Subject: [PATCH 42/47] actually make line numbers work smh --- QSB/QSB.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index 8bfae7dd..f1f11988 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -21,6 +21,7 @@ $(UnityAssetsDir)\Dlls + portable From df2783e05ffc65c6635b90cc886d11918b151ecc Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Fri, 11 Nov 2022 14:42:04 +0000 Subject: [PATCH 43/47] add fatal log --- QSB/QSBCore.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/QSB/QSBCore.cs b/QSB/QSBCore.cs index 75f1ee3c..32ff5fa1 100644 --- a/QSB/QSBCore.cs +++ b/QSB/QSBCore.cs @@ -65,6 +65,9 @@ public class QSBCore : ModBehaviour public static DebugSettings DebugSettings { get; private set; } = new(); public static Storage Storage { get; private set; } = new(); + public const string NEW_HORIZONS = "xen.NewHorizons"; + public const string NEW_HORIZONS_COMPAT = "xen.NHQSBCompat"; + public static readonly string[] IncompatibleMods = { // incompatible mods @@ -123,6 +126,8 @@ public class QSBCore : ModBehaviour Helper = ModHelper; DebugLog.ToConsole($"* Start of QSB version {QSBVersion} - authored by {Helper.Manifest.Author}", MessageType.Info); + CheckCompatibilityMods(); + DebugSettings = Helper.Storage.Load("debugsettings.json") ?? new DebugSettings(); Storage = Helper.Storage.Load("storage.json") ?? new Storage(); @@ -258,6 +263,26 @@ public class QSBCore : ModBehaviour DebugLog.ToConsole($"DEBUG MODE = {DebugSettings.DebugMode}"); } } + + private void CheckCompatibilityMods() + { + var mainMod = ""; + var compatMod = ""; + var missingCompat = false; + + if (Helper.Interaction.ModExists(NEW_HORIZONS) && !Helper.Interaction.ModExists(NEW_HORIZONS_COMPAT)) + { + mainMod = NEW_HORIZONS; + compatMod = NEW_HORIZONS_COMPAT; + missingCompat = true; + } + + if (missingCompat) + { + DebugLog.ToConsole($"FATAL - You have mod \"{mainMod}\" installed, which is not compatible with QSB without the compatibility mod \"{compatMod}\". " + + $"Either disable the mod, or install/enable the compatibility mod.", MessageType.Fatal); + } + } } /* From 4edb2c8cc7e5fdad835f5fb1c8a17d3e8f58942f Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 11 Nov 2022 12:50:21 -0800 Subject: [PATCH 44/47] Revert "actually make line numbers work smh" This reverts commit ce08715f5ee4c46ce9d2aa295d4bcc1f075cef3b. --- QSB/QSB.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index f1f11988..8bfae7dd 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -21,7 +21,6 @@ $(UnityAssetsDir)\Dlls - portable From d1da2faf6a5cad2ab11167dc7d5ed6cf84f029bc Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 14 Nov 2022 18:11:21 -0800 Subject: [PATCH 45/47] ok i tested now i remove --- QSB/ItemSync/WorldObjects/Items/QSBItem.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/QSB/ItemSync/WorldObjects/Items/QSBItem.cs b/QSB/ItemSync/WorldObjects/Items/QSBItem.cs index 9ca206f5..c1417b32 100644 --- a/QSB/ItemSync/WorldObjects/Items/QSBItem.cs +++ b/QSB/ItemSync/WorldObjects/Items/QSBItem.cs @@ -56,12 +56,6 @@ public class QSBItem : WorldObject, IQSBItem _lastSector = sector.GetWorldObject(); } - // TODO test and then remove - if (!_lastParent) - { - DebugLog.DebugWrite($"{this} - parent for item {AttachedObject} at {AttachedObject.DeterministicPath()} is null! wtf!", MessageType.Error); - return; - } var socket = _lastParent.GetComponent(); if (socket != null) { From 8c6075740728c3cdec1118ae4d6f223d9d072fc2 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Tue, 6 Dec 2022 17:12:25 +0000 Subject: [PATCH 46/47] add manager hashes --- QSB/WorldSync/QSBWorldSync.cs | 76 ++++++++++++++++++++++-- QSB/WorldSync/WorldObjectsHashMessage.cs | 14 ++--- 2 files changed, 79 insertions(+), 11 deletions(-) diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 570191f9..fa1c62c1 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -11,6 +11,7 @@ using QSB.Utility; using QSB.Utility.LinkedWorldObject; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Threading; using UnityEngine; @@ -20,7 +21,8 @@ namespace QSB.WorldSync; public static class QSBWorldSync { public static WorldObjectManager[] Managers; - public static string WorldObjectsHash { get; private set; } + public static Dictionary ManagerHashes { get; private set; } = new(); + public static Dictionary> ManagerToBuiltObjects { get; private set; } = new(); /// /// Set when all WorldObjectManagers have called Init() on all their objects (AKA all the objects are created) @@ -85,12 +87,21 @@ public static class QSBWorldSync DeterministicManager.OnWorldObjectsAdded(); - WorldObjectsHash = WorldObjects.Select(x => x.GetType().Name).GetMD5Hash(); - DebugLog.DebugWrite($"WorldObject hash is {WorldObjectsHash}"); + foreach (var item in ManagerToBuiltObjects) + { + var worldObjects = item.Value; + var hash = worldObjects.Select(x => x.GetType().Name).GetMD5Hash(); + ManagerHashes[item.Key] = hash; + DebugLog.DebugWrite($"hash for {item.Key} is {hash}"); + } if (!QSBCore.IsHost) { - new WorldObjectsHashMessage().Send(); + foreach (var item in ManagerHashes) + { + new WorldObjectsHashMessage(item.Key, item.Value).Send(); + } + new RequestLinksMessage().Send(); } @@ -135,6 +146,9 @@ public static class QSBWorldSync AllObjectsAdded = false; AllObjectsReady = false; + ManagerToBuiltObjects = new(); + ManagerHashes = new(); + GameReset(); foreach (var worldObject in WorldObjects) @@ -315,6 +329,48 @@ public static class QSBWorldSync => Resources.FindObjectsOfTypeAll() .Where(x => x.gameObject.scene.name is not (null or "DontDestroyOnLoad")); + // https://stackoverflow.com/a/48570616 + public static string NameOfCallingClass() + { + string fullName; + Type declaringType; + var skipFrames = 2; + do + { + var method = new StackFrame(skipFrames, false).GetMethod(); + declaringType = method.DeclaringType; + if (declaringType == null) + { + return method.Name; + } + + skipFrames++; + fullName = CleanupFullName(declaringType.FullName); + } + while (declaringType.Module.Name.Equals("mscorlib.dll", StringComparison.OrdinalIgnoreCase) || declaringType == typeof(QSBWorldSync)); + + return fullName; + } + + private static string CleanupFullName(string fullName) + { + var ret = fullName; + + var indexOfPlus = fullName.LastIndexOf('+'); + if (indexOfPlus != -1) + { + ret = fullName.Remove(indexOfPlus); + } + + var indexOfDot = ret.LastIndexOf('.'); + if (indexOfDot != -1) + { + ret = ret.Substring(indexOfDot + 1); + } + + return ret; + } + public static void Init() where TWorldObject : WorldObject, new() where TUnityObject : MonoBehaviour @@ -384,6 +440,18 @@ public static class QSBWorldSync return; } + var className = NameOfCallingClass(); + + if (!ManagerToBuiltObjects.ContainsKey(className)) + { + ManagerToBuiltObjects.Add(className, new List { worldObject }); + DebugLog.DebugWrite($"Adding {className} to dictionary."); + } + else + { + ManagerToBuiltObjects[className].Add(worldObject); + } + WorldObjects.Add(worldObject); RequestInitialStatesMessage.SendInitialState += worldObject.SendInitialState; diff --git a/QSB/WorldSync/WorldObjectsHashMessage.cs b/QSB/WorldSync/WorldObjectsHashMessage.cs index 4d5e6bd2..51bedcc0 100644 --- a/QSB/WorldSync/WorldObjectsHashMessage.cs +++ b/QSB/WorldSync/WorldObjectsHashMessage.cs @@ -8,23 +8,23 @@ namespace QSB.WorldSync; /// /// sends QSBWorldSync.WorldObjectsHash to the server for sanity checking /// -internal class WorldObjectsHashMessage : QSBMessage +internal class WorldObjectsHashMessage : QSBMessage<(string managerName, string hash)> { - public WorldObjectsHashMessage() : base(QSBWorldSync.WorldObjectsHash) => To = 0; + public WorldObjectsHashMessage(string managerName, string hash) : base((managerName, hash)) => To = 0; public override void OnReceiveRemote() { - var serverHash = QSBWorldSync.WorldObjectsHash; + var serverHash = QSBWorldSync.ManagerHashes[Data.managerName]; - if (serverHash != Data) + if (serverHash != Data.hash) { // oh fuck oh no oh god - DebugLog.ToConsole($"Kicking {From} because their WorldObjects hash is wrong. (server:{serverHash}, client:{Data})", MessageType.Error); - new PlayerKickMessage(From, $"WorldObject hash error. (Server:{serverHash}, Client:{Data})").Send(); + DebugLog.ToConsole($"Kicking {From} because their WorldObjects hash for {Data.managerName} is wrong. (server:{serverHash}, client:{Data.hash})", MessageType.Error); + new PlayerKickMessage(From, $"WorldObject hash error for {Data.managerName}. (Server:{serverHash}, Client:{Data.hash})").Send(); } else { - DebugLog.DebugWrite($"WorldObject hash from {From} verified!", MessageType.Success); + DebugLog.DebugWrite($"{From} - {Data.managerName} verified!", MessageType.Success); } } } From cd6c376549ae7a9d344261be5a3aa920d424f8e5 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Tue, 6 Dec 2022 19:16:00 +0000 Subject: [PATCH 47/47] remove some logs --- QSB/WorldSync/QSBWorldSync.cs | 2 -- QSB/WorldSync/WorldObjectsHashMessage.cs | 4 ---- 2 files changed, 6 deletions(-) diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index fa1c62c1..d6446f37 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -92,7 +92,6 @@ public static class QSBWorldSync var worldObjects = item.Value; var hash = worldObjects.Select(x => x.GetType().Name).GetMD5Hash(); ManagerHashes[item.Key] = hash; - DebugLog.DebugWrite($"hash for {item.Key} is {hash}"); } if (!QSBCore.IsHost) @@ -445,7 +444,6 @@ public static class QSBWorldSync if (!ManagerToBuiltObjects.ContainsKey(className)) { ManagerToBuiltObjects.Add(className, new List { worldObject }); - DebugLog.DebugWrite($"Adding {className} to dictionary."); } else { diff --git a/QSB/WorldSync/WorldObjectsHashMessage.cs b/QSB/WorldSync/WorldObjectsHashMessage.cs index 51bedcc0..fc18ec15 100644 --- a/QSB/WorldSync/WorldObjectsHashMessage.cs +++ b/QSB/WorldSync/WorldObjectsHashMessage.cs @@ -22,9 +22,5 @@ internal class WorldObjectsHashMessage : QSBMessage<(string managerName, string DebugLog.ToConsole($"Kicking {From} because their WorldObjects hash for {Data.managerName} is wrong. (server:{serverHash}, client:{Data.hash})", MessageType.Error); new PlayerKickMessage(From, $"WorldObject hash error for {Data.managerName}. (Server:{serverHash}, Client:{Data.hash})").Send(); } - else - { - DebugLog.DebugWrite($"{From} - {Data.managerName} verified!", MessageType.Success); - } } }