From 2414efd65f4899f9a6330e224057c556493c6d4d Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 11 Dec 2021 14:38:54 -0800 Subject: [PATCH 01/17] set AttachedObject and ObjectId in QSBWorldSync.cs, meaning many Init()s can be removed --- QSB/Anglerfish/WorldObjects/QSBAngler.cs | 5 +---- .../NPC/WorldObjects/NpcAnimController.cs | 6 ------ .../NPC/WorldObjects/QSBSolanumAnimController.cs | 6 ------ QSB/CampfireSync/WorldObjects/QSBCampfire.cs | 6 ------ .../AirlockSync/WorldObjects/QSBGhostAirlock.cs | 5 ----- .../WorldObjects/QSBSingleLightSensor.cs | 5 ----- QSB/ElevatorSync/WorldObjects/QSBElevator.cs | 4 +--- QSB/GeyserSync/WorldObjects/QSBGeyser.cs | 4 +--- .../Items/QSBNomaiConversationStone.cs | 6 ------ QSB/ItemSync/WorldObjects/Items/QSBOWItem.cs | 14 +++++++------- QSB/ItemSync/WorldObjects/Items/QSBScrollItem.cs | 7 ------- QSB/ItemSync/WorldObjects/Items/QSBSharedStone.cs | 7 ------- .../WorldObjects/Items/QSBSimpleLanternItem.cs | 7 ------- .../WorldObjects/Items/QSBSlideReelItem.cs | 7 ------- QSB/ItemSync/WorldObjects/Items/QSBWarpCoreItem.cs | 7 ------- .../Sockets/QSBNomaiConversationStoneSocket.cs | 6 ------ .../WorldObjects/Sockets/QSBOWItemDoubleSocket.cs | 2 -- .../WorldObjects/Sockets/QSBOWItemSocket.cs | 2 -- .../WorldObjects/Sockets/QSBScrollSocket.cs | 6 ------ .../WorldObjects/Sockets/QSBSharedStoneSocket.cs | 6 ------ .../Sockets/QSBSlideProjectorSocket.cs | 6 ------ .../WorldObjects/Sockets/QSBSlideReelSocket.cs | 6 ------ .../WorldObjects/Sockets/QSBWarpCoreSocket.cs | 6 ------ QSB/JellyfishSync/WorldObjects/QSBJellyfish.cs | 4 +--- QSB/MeteorSync/WorldObjects/QSBFragment.cs | 4 +--- QSB/MeteorSync/WorldObjects/QSBMeteor.cs | 6 ------ QSB/MeteorSync/WorldObjects/QSBMeteorLauncher.cs | 6 ------ QSB/OrbSync/WorldObjects/QSBOrbSlot.cs | 4 +--- .../WorldObjects/QSBEyeProxyQuantumMoon.cs | 6 ++---- .../WorldObjects/QSBMultiStateQuantumObject.cs | 9 +++------ QSB/QuantumSync/WorldObjects/QSBQuantumMoon.cs | 6 ++---- QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs | 2 +- .../WorldObjects/QSBQuantumShuffleObject.cs | 7 ------- QSB/QuantumSync/WorldObjects/QSBQuantumSocket.cs | 4 +--- QSB/QuantumSync/WorldObjects/QSBQuantumState.cs | 6 ------ .../WorldObjects/QSBSocketedQuantumObject.cs | 6 ++---- QSB/SectorSync/WorldObjects/QSBSector.cs | 4 +--- QSB/ShipSync/WorldObjects/QSBShipComponent.cs | 6 ------ QSB/ShipSync/WorldObjects/QSBShipHull.cs | 6 ------ .../WorldObjects/QSBProbeLauncher.cs | 4 +--- .../TranslationSync/WorldObjects/QSBComputer.cs | 6 ------ .../WorldObjects/QSBVesselComputer.cs | 6 ------ .../TranslationSync/WorldObjects/QSBWallText.cs | 6 ------ QSB/WorldSync/QSBWorldSync.cs | 4 +++- QSB/WorldSync/WorldObject.cs | 6 +++--- QSB/ZeroGCaveSync/WorldObjects/QSBSatelliteNode.cs | 6 ------ 46 files changed, 32 insertions(+), 228 deletions(-) diff --git a/QSB/Anglerfish/WorldObjects/QSBAngler.cs b/QSB/Anglerfish/WorldObjects/QSBAngler.cs index dbf06475..97e8d36c 100644 --- a/QSB/Anglerfish/WorldObjects/QSBAngler.cs +++ b/QSB/Anglerfish/WorldObjects/QSBAngler.cs @@ -14,11 +14,8 @@ namespace QSB.Anglerfish.WorldObjects private Vector3 _lastTargetPosition; - public override void Init(AnglerfishController attachedObject, int id) + public override void Init() { - ObjectId = id; - AttachedObject = attachedObject; - if (QSBCore.IsHost) { QNetworkServer.Spawn(Object.Instantiate(QSBNetworkManager.Instance.AnglerPrefab)); diff --git a/QSB/Animation/NPC/WorldObjects/NpcAnimController.cs b/QSB/Animation/NPC/WorldObjects/NpcAnimController.cs index 86ca2d77..74a41b5d 100644 --- a/QSB/Animation/NPC/WorldObjects/NpcAnimController.cs +++ b/QSB/Animation/NPC/WorldObjects/NpcAnimController.cs @@ -7,12 +7,6 @@ namespace QSB.Animation.NPC.WorldObjects internal abstract class NpcAnimController : WorldObject, INpcAnimController where T : MonoBehaviour { - public override void Init(T controller, int id) - { - ObjectId = id; - AttachedObject = controller; - } - public abstract CharacterDialogueTree GetDialogueTree(); public virtual void StartConversation() diff --git a/QSB/Animation/NPC/WorldObjects/QSBSolanumAnimController.cs b/QSB/Animation/NPC/WorldObjects/QSBSolanumAnimController.cs index 3505f973..e940c8c9 100644 --- a/QSB/Animation/NPC/WorldObjects/QSBSolanumAnimController.cs +++ b/QSB/Animation/NPC/WorldObjects/QSBSolanumAnimController.cs @@ -8,12 +8,6 @@ namespace QSB.Animation.NPC.WorldObjects { private readonly List _playersInHeadZone = new(); - public override void Init(SolanumAnimController controller, int id) - { - ObjectId = id; - AttachedObject = controller; - } - public List GetPlayersInHeadZone() => _playersInHeadZone; diff --git a/QSB/CampfireSync/WorldObjects/QSBCampfire.cs b/QSB/CampfireSync/WorldObjects/QSBCampfire.cs index b4d43649..60e08cbd 100644 --- a/QSB/CampfireSync/WorldObjects/QSBCampfire.cs +++ b/QSB/CampfireSync/WorldObjects/QSBCampfire.cs @@ -5,12 +5,6 @@ namespace QSB.CampfireSync.WorldObjects { public class QSBCampfire : WorldObject { - public override void Init(Campfire campfire, int id) - { - ObjectId = id; - AttachedObject = campfire; - } - public void StartRoasting() => AttachedObject .GetType() diff --git a/QSB/EchoesOfTheEye/AirlockSync/WorldObjects/QSBGhostAirlock.cs b/QSB/EchoesOfTheEye/AirlockSync/WorldObjects/QSBGhostAirlock.cs index 67b73576..b19bf457 100644 --- a/QSB/EchoesOfTheEye/AirlockSync/WorldObjects/QSBGhostAirlock.cs +++ b/QSB/EchoesOfTheEye/AirlockSync/WorldObjects/QSBGhostAirlock.cs @@ -4,10 +4,5 @@ namespace QSB.EchoesOfTheEye.AirlockSync.WorldObjects { internal class QSBGhostAirlock : WorldObject { - public override void Init(GhostAirlock airlock, int id) - { - ObjectId = id; - AttachedObject = airlock; - } } } diff --git a/QSB/EchoesOfTheEye/LightSensorSync/WorldObjects/QSBSingleLightSensor.cs b/QSB/EchoesOfTheEye/LightSensorSync/WorldObjects/QSBSingleLightSensor.cs index 089e67d3..92aab307 100644 --- a/QSB/EchoesOfTheEye/LightSensorSync/WorldObjects/QSBSingleLightSensor.cs +++ b/QSB/EchoesOfTheEye/LightSensorSync/WorldObjects/QSBSingleLightSensor.cs @@ -4,10 +4,5 @@ namespace QSB.EchoesOfTheEye.LightSensorSync.WorldObjects { internal class QSBSingleLightSensor : WorldObject { - public override void Init(SingleLightSensor sensor, int id) - { - ObjectId = id; - AttachedObject = sensor; - } } } diff --git a/QSB/ElevatorSync/WorldObjects/QSBElevator.cs b/QSB/ElevatorSync/WorldObjects/QSBElevator.cs index f322af7a..7ca93dee 100644 --- a/QSB/ElevatorSync/WorldObjects/QSBElevator.cs +++ b/QSB/ElevatorSync/WorldObjects/QSBElevator.cs @@ -13,10 +13,8 @@ namespace QSB.ElevatorSync.WorldObjects private OWAudioSource _owAudioSourceLP; private OWTriggerVolume _elevatorTrigger; - public override void Init(Elevator elevator, int id) + public override void Init() { - AttachedObject = elevator; - ObjectId = id; QSBCore.UnityEvents.RunWhen(() => AttachedObject._interactVolume != null, InitValues); } diff --git a/QSB/GeyserSync/WorldObjects/QSBGeyser.cs b/QSB/GeyserSync/WorldObjects/QSBGeyser.cs index 0cac3e86..34ef9b94 100644 --- a/QSB/GeyserSync/WorldObjects/QSBGeyser.cs +++ b/QSB/GeyserSync/WorldObjects/QSBGeyser.cs @@ -6,10 +6,8 @@ namespace QSB.GeyserSync.WorldObjects { public class QSBGeyser : WorldObject { - public override void Init(GeyserController geyserController, int id) + public override void Init() { - ObjectId = id; - AttachedObject = geyserController; AttachedObject.OnGeyserActivateEvent += () => HandleEvent(true); AttachedObject.OnGeyserDeactivateEvent += () => HandleEvent(false); } diff --git a/QSB/ItemSync/WorldObjects/Items/QSBNomaiConversationStone.cs b/QSB/ItemSync/WorldObjects/Items/QSBNomaiConversationStone.cs index 97a2798e..05f8de45 100644 --- a/QSB/ItemSync/WorldObjects/Items/QSBNomaiConversationStone.cs +++ b/QSB/ItemSync/WorldObjects/Items/QSBNomaiConversationStone.cs @@ -2,11 +2,5 @@ { internal class QSBNomaiConversationStone : QSBOWItem { - public override void Init(NomaiConversationStone attachedObject, int id) - { - ObjectId = id; - AttachedObject = attachedObject; - base.Init(attachedObject, id); - } } } diff --git a/QSB/ItemSync/WorldObjects/Items/QSBOWItem.cs b/QSB/ItemSync/WorldObjects/Items/QSBOWItem.cs index cb335596..6feb597d 100644 --- a/QSB/ItemSync/WorldObjects/Items/QSBOWItem.cs +++ b/QSB/ItemSync/WorldObjects/Items/QSBOWItem.cs @@ -17,9 +17,9 @@ namespace QSB.ItemSync.WorldObjects.Items public QSBSector InitialSector { get; private set; } public uint HoldingPlayer { get; private set; } - public override void Init(T attachedObject, int id) + public override void Init() { - if (attachedObject == null) + if (AttachedObject == null) { DebugLog.ToConsole($"Error - AttachedObject is null! Type:{GetType().Name}", OWML.Common.MessageType.Error); return; @@ -30,10 +30,10 @@ namespace QSB.ItemSync.WorldObjects.Items { FinishDelayedReady(); - InitialParent = attachedObject.transform.parent; - InitialPosition = attachedObject.transform.localPosition; - InitialRotation = attachedObject.transform.localRotation; - var initialSector = attachedObject.GetSector(); + InitialParent = AttachedObject.transform.parent; + InitialPosition = AttachedObject.transform.localPosition; + InitialRotation = AttachedObject.transform.localRotation; + var initialSector = AttachedObject.GetSector(); if (initialSector != null) { InitialSector = QSBWorldSync.GetWorldFromUnity(initialSector); @@ -41,7 +41,7 @@ namespace QSB.ItemSync.WorldObjects.Items if (InitialParent == null) { - DebugLog.ToConsole($"Warning - InitialParent of {attachedObject.name} is null!", OWML.Common.MessageType.Warning); + DebugLog.ToConsole($"Warning - InitialParent of {AttachedObject.name} is null!", OWML.Common.MessageType.Warning); } if (InitialParent?.GetComponent() != null) diff --git a/QSB/ItemSync/WorldObjects/Items/QSBScrollItem.cs b/QSB/ItemSync/WorldObjects/Items/QSBScrollItem.cs index 425f980c..ef66c5b3 100644 --- a/QSB/ItemSync/WorldObjects/Items/QSBScrollItem.cs +++ b/QSB/ItemSync/WorldObjects/Items/QSBScrollItem.cs @@ -2,13 +2,6 @@ { internal class QSBScrollItem : QSBOWItem { - public override void Init(ScrollItem attachedObject, int id) - { - ObjectId = id; - AttachedObject = attachedObject; - base.Init(attachedObject, id); - } - public override void PlaySocketAnimation() => AttachedObject.PlaySocketAnimation(); diff --git a/QSB/ItemSync/WorldObjects/Items/QSBSharedStone.cs b/QSB/ItemSync/WorldObjects/Items/QSBSharedStone.cs index fe2830f4..1b10bb63 100644 --- a/QSB/ItemSync/WorldObjects/Items/QSBSharedStone.cs +++ b/QSB/ItemSync/WorldObjects/Items/QSBSharedStone.cs @@ -2,13 +2,6 @@ { internal class QSBSharedStone : QSBOWItem { - public override void Init(SharedStone attachedObject, int id) - { - ObjectId = id; - AttachedObject = attachedObject; - base.Init(attachedObject, id); - } - public override void PlaySocketAnimation() => AttachedObject.PlaySocketAnimation(); diff --git a/QSB/ItemSync/WorldObjects/Items/QSBSimpleLanternItem.cs b/QSB/ItemSync/WorldObjects/Items/QSBSimpleLanternItem.cs index 12bf9c7b..782dbf3e 100644 --- a/QSB/ItemSync/WorldObjects/Items/QSBSimpleLanternItem.cs +++ b/QSB/ItemSync/WorldObjects/Items/QSBSimpleLanternItem.cs @@ -2,13 +2,6 @@ { internal class QSBSimpleLanternItem : QSBOWItem { - public override void Init(SimpleLanternItem attachedObject, int id) - { - ObjectId = id; - AttachedObject = attachedObject; - base.Init(attachedObject, id); - } - public override void PlaySocketAnimation() => AttachedObject.PlaySocketAnimation(); diff --git a/QSB/ItemSync/WorldObjects/Items/QSBSlideReelItem.cs b/QSB/ItemSync/WorldObjects/Items/QSBSlideReelItem.cs index 41735ea0..ae7ceefc 100644 --- a/QSB/ItemSync/WorldObjects/Items/QSBSlideReelItem.cs +++ b/QSB/ItemSync/WorldObjects/Items/QSBSlideReelItem.cs @@ -2,13 +2,6 @@ { internal class QSBSlideReelItem : QSBOWItem { - public override void Init(SlideReelItem attachedObject, int id) - { - ObjectId = id; - AttachedObject = attachedObject; - base.Init(attachedObject, id); - } - public override void PlaySocketAnimation() => AttachedObject.PlaySocketAnimation(); diff --git a/QSB/ItemSync/WorldObjects/Items/QSBWarpCoreItem.cs b/QSB/ItemSync/WorldObjects/Items/QSBWarpCoreItem.cs index 3be29380..e82308bf 100644 --- a/QSB/ItemSync/WorldObjects/Items/QSBWarpCoreItem.cs +++ b/QSB/ItemSync/WorldObjects/Items/QSBWarpCoreItem.cs @@ -2,13 +2,6 @@ { internal class QSBWarpCoreItem : QSBOWItem { - public override void Init(WarpCoreItem attachedObject, int id) - { - ObjectId = id; - AttachedObject = attachedObject; - base.Init(attachedObject, id); - } - public bool IsVesselCoreType() => AttachedObject.IsVesselCoreType(); } diff --git a/QSB/ItemSync/WorldObjects/Sockets/QSBNomaiConversationStoneSocket.cs b/QSB/ItemSync/WorldObjects/Sockets/QSBNomaiConversationStoneSocket.cs index bc48b86e..8a678bd1 100644 --- a/QSB/ItemSync/WorldObjects/Sockets/QSBNomaiConversationStoneSocket.cs +++ b/QSB/ItemSync/WorldObjects/Sockets/QSBNomaiConversationStoneSocket.cs @@ -2,11 +2,5 @@ { internal class QSBNomaiConversationStoneSocket : QSBOWItemSocket { - public override void Init(NomaiConversationStoneSocket attachedObject, int id) - { - ObjectId = id; - AttachedObject = attachedObject; - base.Init(attachedObject, id); - } } } diff --git a/QSB/ItemSync/WorldObjects/Sockets/QSBOWItemDoubleSocket.cs b/QSB/ItemSync/WorldObjects/Sockets/QSBOWItemDoubleSocket.cs index 7ca06e54..286cbb3d 100644 --- a/QSB/ItemSync/WorldObjects/Sockets/QSBOWItemDoubleSocket.cs +++ b/QSB/ItemSync/WorldObjects/Sockets/QSBOWItemDoubleSocket.cs @@ -6,8 +6,6 @@ namespace QSB.ItemSync.WorldObjects.Sockets internal class QSBOWItemDoubleSocket : WorldObject, IQSBOWItemSocket where T : OWItemSocket { - public override void Init(T attachedObject, int id) { } - public virtual bool AcceptsItem(IQSBOWItem item) { var itemType = item.GetItemType(); diff --git a/QSB/ItemSync/WorldObjects/Sockets/QSBOWItemSocket.cs b/QSB/ItemSync/WorldObjects/Sockets/QSBOWItemSocket.cs index 545e8ca1..96a6c0da 100644 --- a/QSB/ItemSync/WorldObjects/Sockets/QSBOWItemSocket.cs +++ b/QSB/ItemSync/WorldObjects/Sockets/QSBOWItemSocket.cs @@ -6,8 +6,6 @@ namespace QSB.ItemSync.WorldObjects.Sockets internal class QSBOWItemSocket : WorldObject, IQSBOWItemSocket where T : OWItemSocket { - public override void Init(T attachedObject, int id) { } - public virtual bool AcceptsItem(IQSBOWItem item) { var itemType = item.GetItemType(); diff --git a/QSB/ItemSync/WorldObjects/Sockets/QSBScrollSocket.cs b/QSB/ItemSync/WorldObjects/Sockets/QSBScrollSocket.cs index 79755b9d..b6bc98b1 100644 --- a/QSB/ItemSync/WorldObjects/Sockets/QSBScrollSocket.cs +++ b/QSB/ItemSync/WorldObjects/Sockets/QSBScrollSocket.cs @@ -2,11 +2,5 @@ { internal class QSBScrollSocket : QSBOWItemSocket { - public override void Init(ScrollSocket attachedObject, int id) - { - ObjectId = id; - AttachedObject = attachedObject; - base.Init(attachedObject, id); - } } } diff --git a/QSB/ItemSync/WorldObjects/Sockets/QSBSharedStoneSocket.cs b/QSB/ItemSync/WorldObjects/Sockets/QSBSharedStoneSocket.cs index 357b3a0b..3efe3002 100644 --- a/QSB/ItemSync/WorldObjects/Sockets/QSBSharedStoneSocket.cs +++ b/QSB/ItemSync/WorldObjects/Sockets/QSBSharedStoneSocket.cs @@ -2,11 +2,5 @@ { internal class QSBSharedStoneSocket : QSBOWItemSocket { - public override void Init(SharedStoneSocket attachedObject, int id) - { - ObjectId = id; - AttachedObject = attachedObject; - base.Init(attachedObject, id); - } } } diff --git a/QSB/ItemSync/WorldObjects/Sockets/QSBSlideProjectorSocket.cs b/QSB/ItemSync/WorldObjects/Sockets/QSBSlideProjectorSocket.cs index 6d353c95..87e6aefd 100644 --- a/QSB/ItemSync/WorldObjects/Sockets/QSBSlideProjectorSocket.cs +++ b/QSB/ItemSync/WorldObjects/Sockets/QSBSlideProjectorSocket.cs @@ -2,11 +2,5 @@ { internal class QSBSlideProjectorSocket : QSBOWItemDoubleSocket { - public override void Init(SlideProjectorSocket attachedObject, int id) - { - ObjectId = id; - AttachedObject = attachedObject; - base.Init(attachedObject, id); - } } } diff --git a/QSB/ItemSync/WorldObjects/Sockets/QSBSlideReelSocket.cs b/QSB/ItemSync/WorldObjects/Sockets/QSBSlideReelSocket.cs index 72ed11e3..de18c9ee 100644 --- a/QSB/ItemSync/WorldObjects/Sockets/QSBSlideReelSocket.cs +++ b/QSB/ItemSync/WorldObjects/Sockets/QSBSlideReelSocket.cs @@ -2,11 +2,5 @@ { internal class QSBSlideReelSocket : QSBOWItemSocket { - public override void Init(SlideReelSocket attachedObject, int id) - { - ObjectId = id; - AttachedObject = attachedObject; - base.Init(attachedObject, id); - } } } diff --git a/QSB/ItemSync/WorldObjects/Sockets/QSBWarpCoreSocket.cs b/QSB/ItemSync/WorldObjects/Sockets/QSBWarpCoreSocket.cs index 5afa4e20..e834888c 100644 --- a/QSB/ItemSync/WorldObjects/Sockets/QSBWarpCoreSocket.cs +++ b/QSB/ItemSync/WorldObjects/Sockets/QSBWarpCoreSocket.cs @@ -2,11 +2,5 @@ { internal class QSBWarpCoreSocket : QSBOWItemSocket { - public override void Init(WarpCoreSocket attachedObject, int id) - { - ObjectId = id; - AttachedObject = attachedObject; - base.Init(attachedObject, id); - } } } diff --git a/QSB/JellyfishSync/WorldObjects/QSBJellyfish.cs b/QSB/JellyfishSync/WorldObjects/QSBJellyfish.cs index 53f801c1..3a5429ba 100644 --- a/QSB/JellyfishSync/WorldObjects/QSBJellyfish.cs +++ b/QSB/JellyfishSync/WorldObjects/QSBJellyfish.cs @@ -11,10 +11,8 @@ namespace QSB.JellyfishSync.WorldObjects public JellyfishTransformSync TransformSync; private AlignWithTargetBody _alignWithTargetBody; - public override void Init(JellyfishController attachedObject, int id) + public override void Init() { - ObjectId = id; - AttachedObject = attachedObject; _alignWithTargetBody = AttachedObject.GetRequiredComponent(); if (QSBCore.IsHost) diff --git a/QSB/MeteorSync/WorldObjects/QSBFragment.cs b/QSB/MeteorSync/WorldObjects/QSBFragment.cs index bb95c0a6..ccec51ae 100644 --- a/QSB/MeteorSync/WorldObjects/QSBFragment.cs +++ b/QSB/MeteorSync/WorldObjects/QSBFragment.cs @@ -5,10 +5,8 @@ namespace QSB.MeteorSync.WorldObjects { public class QSBFragment : WorldObject { - public override void Init(FragmentIntegrity attachedObject, int id) + public override void Init() { - ObjectId = id; - AttachedObject = attachedObject; DetachableFragment = AttachedObject.GetComponent(); if (QSBCore.IsHost) diff --git a/QSB/MeteorSync/WorldObjects/QSBMeteor.cs b/QSB/MeteorSync/WorldObjects/QSBMeteor.cs index f3214007..4ea4b704 100644 --- a/QSB/MeteorSync/WorldObjects/QSBMeteor.cs +++ b/QSB/MeteorSync/WorldObjects/QSBMeteor.cs @@ -5,12 +5,6 @@ namespace QSB.MeteorSync.WorldObjects { public class QSBMeteor : WorldObject { - public override void Init(MeteorController attachedObject, int id) - { - ObjectId = id; - AttachedObject = attachedObject; - } - public static bool IsSpecialImpact(GameObject go) => go == Locator.GetPlayerCollider().gameObject || go == Locator.GetProbe()._anchor._collider.gameObject; diff --git a/QSB/MeteorSync/WorldObjects/QSBMeteorLauncher.cs b/QSB/MeteorSync/WorldObjects/QSBMeteorLauncher.cs index a2321a5b..d9a2903c 100644 --- a/QSB/MeteorSync/WorldObjects/QSBMeteorLauncher.cs +++ b/QSB/MeteorSync/WorldObjects/QSBMeteorLauncher.cs @@ -4,12 +4,6 @@ namespace QSB.MeteorSync.WorldObjects { public class QSBMeteorLauncher : WorldObject { - public override void Init(MeteorLauncher attachedObject, int id) - { - ObjectId = id; - AttachedObject = attachedObject; - } - public int MeteorId; public float LaunchSpeed; diff --git a/QSB/OrbSync/WorldObjects/QSBOrbSlot.cs b/QSB/OrbSync/WorldObjects/QSBOrbSlot.cs index 65c5a5c9..58f64047 100644 --- a/QSB/OrbSync/WorldObjects/QSBOrbSlot.cs +++ b/QSB/OrbSync/WorldObjects/QSBOrbSlot.cs @@ -11,10 +11,8 @@ namespace QSB.OrbSync.WorldObjects private bool _initialized; - public override void Init(NomaiInterfaceSlot slot, int id) + public override void Init() { - ObjectId = id; - AttachedObject = slot; _initialized = true; } diff --git a/QSB/QuantumSync/WorldObjects/QSBEyeProxyQuantumMoon.cs b/QSB/QuantumSync/WorldObjects/QSBEyeProxyQuantumMoon.cs index 6f21d9c0..7166b578 100644 --- a/QSB/QuantumSync/WorldObjects/QSBEyeProxyQuantumMoon.cs +++ b/QSB/QuantumSync/WorldObjects/QSBEyeProxyQuantumMoon.cs @@ -4,12 +4,10 @@ namespace QSB.QuantumSync.WorldObjects { internal class QSBEyeProxyQuantumMoon : QSBQuantumObject { - public override void Init(EyeProxyQuantumMoon moonObject, int id) + public override void Init() { - ObjectId = id; - AttachedObject = moonObject; ControllingPlayer = QSBPlayerManager.LocalPlayerId; - base.Init(moonObject, id); + base.Init(); } } } diff --git a/QSB/QuantumSync/WorldObjects/QSBMultiStateQuantumObject.cs b/QSB/QuantumSync/WorldObjects/QSBMultiStateQuantumObject.cs index a35c019c..18ee5aef 100644 --- a/QSB/QuantumSync/WorldObjects/QSBMultiStateQuantumObject.cs +++ b/QSB/QuantumSync/WorldObjects/QSBMultiStateQuantumObject.cs @@ -21,17 +21,14 @@ namespace QSB.QuantumSync.WorldObjects } } - public override void Init(MultiStateQuantumObject attachedObject, int id) + public override void Init() { - ObjectId = id; - AttachedObject = attachedObject; - if (QSBCore.ShowQuantumDebugBoxes) { - DebugBoxText = DebugBoxManager.CreateBox(AttachedObject.transform, 0, $"Multistate\r\nid:{id}\r\nstate:{CurrentState}").GetComponent(); + DebugBoxText = DebugBoxManager.CreateBox(AttachedObject.transform, 0, $"Multistate\r\nid:{ObjectId}\r\nstate:{CurrentState}").GetComponent(); } - base.Init(attachedObject, id); + base.Init(); StartDelayedReady(); QSBCore.UnityEvents.RunWhen(() => WorldObjectManager.AllObjectsAdded, () => diff --git a/QSB/QuantumSync/WorldObjects/QSBQuantumMoon.cs b/QSB/QuantumSync/WorldObjects/QSBQuantumMoon.cs index 184cedfb..3e4572ee 100644 --- a/QSB/QuantumSync/WorldObjects/QSBQuantumMoon.cs +++ b/QSB/QuantumSync/WorldObjects/QSBQuantumMoon.cs @@ -5,14 +5,12 @@ namespace QSB.QuantumSync.WorldObjects { internal class QSBQuantumMoon : QSBQuantumObject { - public override void Init(QuantumMoon moonObject, int id) + public override void Init() { - ObjectId = id; - AttachedObject = moonObject; ControllingPlayer = QSBCore.IsHost ? QSBPlayerManager.LocalPlayerId : QSBPlayerManager.PlayerList.OrderBy(x => x.PlayerId).First().PlayerId; - base.Init(moonObject, id); + base.Init(); } } } diff --git a/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs b/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs index 8005135a..7d5bd64d 100644 --- a/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs +++ b/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs @@ -24,7 +24,7 @@ namespace QSB.QuantumSync.WorldObjects } } - public override void Init(T attachedObject, int id) + public override void Init() { var debugBundle = QSBCore.DebugAssetBundle; var sphere = debugBundle.LoadAsset("Assets/Prefabs/Sphere.prefab"); diff --git a/QSB/QuantumSync/WorldObjects/QSBQuantumShuffleObject.cs b/QSB/QuantumSync/WorldObjects/QSBQuantumShuffleObject.cs index e663b87c..b02fed69 100644 --- a/QSB/QuantumSync/WorldObjects/QSBQuantumShuffleObject.cs +++ b/QSB/QuantumSync/WorldObjects/QSBQuantumShuffleObject.cs @@ -5,13 +5,6 @@ namespace QSB.QuantumSync.WorldObjects { internal class QSBQuantumShuffleObject : QSBQuantumObject { - public override void Init(QuantumShuffleObject shuffleObject, int id) - { - ObjectId = id; - AttachedObject = shuffleObject; - base.Init(shuffleObject, id); - } - public void ShuffleObjects(int[] indexArray) { var shuffledObjects = AttachedObject.GetValue("_shuffledObjects"); diff --git a/QSB/QuantumSync/WorldObjects/QSBQuantumSocket.cs b/QSB/QuantumSync/WorldObjects/QSBQuantumSocket.cs index 69ef33d9..5c1d2336 100644 --- a/QSB/QuantumSync/WorldObjects/QSBQuantumSocket.cs +++ b/QSB/QuantumSync/WorldObjects/QSBQuantumSocket.cs @@ -5,10 +5,8 @@ namespace QSB.QuantumSync.WorldObjects { internal class QSBQuantumSocket : WorldObject { - public override void Init(QuantumSocket quantumSocket, int id) + public override void Init() { - ObjectId = id; - AttachedObject = quantumSocket; AttachedObject.GetType().SetValue("_randomYRotation", false); } } diff --git a/QSB/QuantumSync/WorldObjects/QSBQuantumState.cs b/QSB/QuantumSync/WorldObjects/QSBQuantumState.cs index 4461b5a2..c05ae8ac 100644 --- a/QSB/QuantumSync/WorldObjects/QSBQuantumState.cs +++ b/QSB/QuantumSync/WorldObjects/QSBQuantumState.cs @@ -6,12 +6,6 @@ namespace QSB.QuantumSync.WorldObjects { public bool IsMeantToBeEnabled; - public override void Init(QuantumState state, int id) - { - ObjectId = id; - AttachedObject = state; - } - public void SetVisible(bool visible) { IsMeantToBeEnabled = visible; diff --git a/QSB/QuantumSync/WorldObjects/QSBSocketedQuantumObject.cs b/QSB/QuantumSync/WorldObjects/QSBSocketedQuantumObject.cs index 621881c9..89f38cfd 100644 --- a/QSB/QuantumSync/WorldObjects/QSBSocketedQuantumObject.cs +++ b/QSB/QuantumSync/WorldObjects/QSBSocketedQuantumObject.cs @@ -13,11 +13,9 @@ namespace QSB.QuantumSync.WorldObjects { public Text DebugBoxText; - public override void Init(SocketedQuantumObject quantumObject, int id) + public override void Init() { - ObjectId = id; - AttachedObject = quantumObject; - base.Init(quantumObject, id); + base.Init(); if (QSBCore.ShowQuantumDebugBoxes) { DebugBoxText = DebugBoxManager.CreateBox(AttachedObject.transform, 0, $"Socketed\r\nid:{ObjectId}").GetComponent(); diff --git a/QSB/SectorSync/WorldObjects/QSBSector.cs b/QSB/SectorSync/WorldObjects/QSBSector.cs index 0a85a8e5..cbb2aabc 100644 --- a/QSB/SectorSync/WorldObjects/QSBSector.cs +++ b/QSB/SectorSync/WorldObjects/QSBSector.cs @@ -27,10 +27,8 @@ namespace QSB.SectorSync.WorldObjects public Vector3 Position => Transform.position; public bool IsFakeSector => AttachedObject.GetType() == typeof(FakeSector); - public override void Init(Sector sector, int id) + public override void Init() { - ObjectId = id; - AttachedObject = sector; if (IsFakeSector) { QSBSectorManager.Instance.FakeSectors.Add(this); diff --git a/QSB/ShipSync/WorldObjects/QSBShipComponent.cs b/QSB/ShipSync/WorldObjects/QSBShipComponent.cs index 15bba4e0..5b193859 100644 --- a/QSB/ShipSync/WorldObjects/QSBShipComponent.cs +++ b/QSB/ShipSync/WorldObjects/QSBShipComponent.cs @@ -6,12 +6,6 @@ namespace QSB.ShipSync.WorldObjects { internal class QSBShipComponent : WorldObject { - public override void Init(ShipComponent component, int id) - { - ObjectId = id; - AttachedObject = component; - } - public void SetDamaged() { DebugLog.DebugWrite($"[S COMPONENT] {AttachedObject} Set damaged."); diff --git a/QSB/ShipSync/WorldObjects/QSBShipHull.cs b/QSB/ShipSync/WorldObjects/QSBShipHull.cs index 01b69f40..3f928bcc 100644 --- a/QSB/ShipSync/WorldObjects/QSBShipHull.cs +++ b/QSB/ShipSync/WorldObjects/QSBShipHull.cs @@ -6,12 +6,6 @@ namespace QSB.ShipSync.WorldObjects { internal class QSBShipHull : WorldObject { - public override void Init(ShipHull hull, int id) - { - ObjectId = id; - AttachedObject = hull; - } - public void SetDamaged() { DebugLog.DebugWrite($"[HULL] {AttachedObject} Set damaged."); diff --git a/QSB/Tools/ProbeLauncherTool/WorldObjects/QSBProbeLauncher.cs b/QSB/Tools/ProbeLauncherTool/WorldObjects/QSBProbeLauncher.cs index f703712b..c3517b02 100644 --- a/QSB/Tools/ProbeLauncherTool/WorldObjects/QSBProbeLauncher.cs +++ b/QSB/Tools/ProbeLauncherTool/WorldObjects/QSBProbeLauncher.cs @@ -12,10 +12,8 @@ namespace QSB.Tools.ProbeLauncherTool.WorldObjects private ProbeLauncherEffects _effects; private SingularityWarpEffect _probeRetrievalEffect; - public override void Init(ProbeLauncher launcher, int id) + public override void Init() { - ObjectId = id; - AttachedObject = launcher; _probeRetrievalLength = AttachedObject.GetValue("_probeRetrievalLength"); _preLaunchProbeProxy = AttachedObject.GetValue("_preLaunchProbeProxy"); _effects = AttachedObject.GetValue("_effects"); diff --git a/QSB/Tools/TranslatorTool/TranslationSync/WorldObjects/QSBComputer.cs b/QSB/Tools/TranslatorTool/TranslationSync/WorldObjects/QSBComputer.cs index 7f645870..7e6cd03d 100644 --- a/QSB/Tools/TranslatorTool/TranslationSync/WorldObjects/QSBComputer.cs +++ b/QSB/Tools/TranslatorTool/TranslationSync/WorldObjects/QSBComputer.cs @@ -6,12 +6,6 @@ namespace QSB.Tools.TranslatorTool.TranslationSync.WorldObjects { internal class QSBComputer : WorldObject { - public override void Init(NomaiComputer computer, int id) - { - ObjectId = id; - AttachedObject = computer; - } - public void HandleSetAsTranslated(int id) { if (AttachedObject.IsTranslated(id)) diff --git a/QSB/Tools/TranslatorTool/TranslationSync/WorldObjects/QSBVesselComputer.cs b/QSB/Tools/TranslatorTool/TranslationSync/WorldObjects/QSBVesselComputer.cs index e50b64fd..f993e914 100644 --- a/QSB/Tools/TranslatorTool/TranslationSync/WorldObjects/QSBVesselComputer.cs +++ b/QSB/Tools/TranslatorTool/TranslationSync/WorldObjects/QSBVesselComputer.cs @@ -7,12 +7,6 @@ namespace QSB.Tools.TranslatorTool.TranslationSync.WorldObjects { internal class QSBVesselComputer : WorldObject { - public override void Init(NomaiVesselComputer computer, int id) - { - ObjectId = id; - AttachedObject = computer; - } - public void HandleSetAsTranslated(int id) { if (AttachedObject.IsTranslated(id)) diff --git a/QSB/Tools/TranslatorTool/TranslationSync/WorldObjects/QSBWallText.cs b/QSB/Tools/TranslatorTool/TranslationSync/WorldObjects/QSBWallText.cs index 249ffc04..2102f50d 100644 --- a/QSB/Tools/TranslatorTool/TranslationSync/WorldObjects/QSBWallText.cs +++ b/QSB/Tools/TranslatorTool/TranslationSync/WorldObjects/QSBWallText.cs @@ -6,12 +6,6 @@ namespace QSB.Tools.TranslatorTool.TranslationSync.WorldObjects { internal class QSBWallText : WorldObject { - public override void Init(NomaiWallText wallText, int id) - { - ObjectId = id; - AttachedObject = wallText; - } - public void HandleSetAsTranslated(int id) { if (AttachedObject.IsTranslated(id)) diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 5342543f..7f335ac9 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -149,7 +149,9 @@ namespace QSB.WorldSync for (var id = 0; id < list.Count; id++) { var obj = CreateWorldObject(); - obj.Init(list[id], id); + obj.AttachedObject = list[id]; + obj.ObjectId = id; + obj.Init(); WorldObjectsToUnityObjects.Add(list[id], obj); } } diff --git a/QSB/WorldSync/WorldObject.cs b/QSB/WorldSync/WorldObject.cs index 0d05a26e..b2d699b7 100644 --- a/QSB/WorldSync/WorldObject.cs +++ b/QSB/WorldSync/WorldObject.cs @@ -6,12 +6,12 @@ namespace QSB.WorldSync public abstract class WorldObject : IWorldObject where T : MonoBehaviour { - public int ObjectId { get; protected set; } - public T AttachedObject { get; protected set; } + public int ObjectId { get; set; } + public T AttachedObject { get; set; } public string Name => AttachedObject == null ? "" : AttachedObject.name; public string LogName => $"{QSBPlayerManager.LocalPlayerId}.{ObjectId}:{GetType().Name}"; - public abstract void Init(T attachedObject, int id); + public virtual void Init() { } public virtual void OnRemoval() { } public MonoBehaviour ReturnObject() => AttachedObject; diff --git a/QSB/ZeroGCaveSync/WorldObjects/QSBSatelliteNode.cs b/QSB/ZeroGCaveSync/WorldObjects/QSBSatelliteNode.cs index 6be183d7..0598d3be 100644 --- a/QSB/ZeroGCaveSync/WorldObjects/QSBSatelliteNode.cs +++ b/QSB/ZeroGCaveSync/WorldObjects/QSBSatelliteNode.cs @@ -5,12 +5,6 @@ namespace QSB.ZeroGCaveSync.WorldObjects { internal class QSBSatelliteNode : WorldObject { - public override void Init(SatelliteNode component, int id) - { - ObjectId = id; - AttachedObject = component; - } - public void SetRepaired() { DebugLog.DebugWrite($"[SATELLITE NODE] {AttachedObject} Set repaired."); From cbc495f9ba6b013f3f1ed9349eab5ccdb47fafb3 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 11 Dec 2021 15:08:56 -0800 Subject: [PATCH 02/17] use new(), make IWorldObjectTypeSubset derive IWorldObject, add constraints --- .../NPC/WorldObjects/INpcAnimController.cs | 6 ++- QSB/ItemSync/Events/SocketItemEvent.cs | 2 +- QSB/ItemSync/Patches/ItemPatches.cs | 14 +++--- QSB/ItemSync/WorldObjects/Items/QSBOWItem.cs | 2 +- .../Sockets/QSBOWItemDoubleSocket.cs | 4 +- .../WorldObjects/Sockets/QSBOWItemSocket.cs | 4 +- QSB/Player/PlayerEntanglementWatcher.cs | 2 +- QSB/QuantumSync/QuantumManager.cs | 6 +-- QSB/WorldSync/IWorldObjectTypeSubset.cs | 2 +- QSB/WorldSync/QSBWorldSync.cs | 46 ++++--------------- QuantumUNET/Messages/QNetworkMessage.cs | 3 +- QuantumUNET/Transport/QNetworkReader.cs | 2 +- 12 files changed, 32 insertions(+), 61 deletions(-) diff --git a/QSB/Animation/NPC/WorldObjects/INpcAnimController.cs b/QSB/Animation/NPC/WorldObjects/INpcAnimController.cs index d6533a4b..1449d417 100644 --- a/QSB/Animation/NPC/WorldObjects/INpcAnimController.cs +++ b/QSB/Animation/NPC/WorldObjects/INpcAnimController.cs @@ -1,6 +1,8 @@ -namespace QSB.Animation.NPC.WorldObjects +using QSB.WorldSync; + +namespace QSB.Animation.NPC.WorldObjects { - public interface INpcAnimController + public interface INpcAnimController : IWorldObjectTypeSubset { CharacterDialogueTree GetDialogueTree(); void StartConversation(); diff --git a/QSB/ItemSync/Events/SocketItemEvent.cs b/QSB/ItemSync/Events/SocketItemEvent.cs index 80665ccb..4b50952d 100644 --- a/QSB/ItemSync/Events/SocketItemEvent.cs +++ b/QSB/ItemSync/Events/SocketItemEvent.cs @@ -42,7 +42,7 @@ namespace QSB.ItemSync.Events case SocketEventType.StartUnsocket: if (!socketWorldObject.IsSocketOccupied()) { - DebugLog.ToConsole($"Warning - Trying to start unsocket on socket that is unoccupied! Socket:{(socketWorldObject as IWorldObject).Name}"); + DebugLog.ToConsole($"Warning - Trying to start unsocket on socket that is unoccupied! Socket:{socketWorldObject.Name}"); return; } diff --git a/QSB/ItemSync/Patches/ItemPatches.cs b/QSB/ItemSync/Patches/ItemPatches.cs index f9d6edeb..2e953430 100644 --- a/QSB/ItemSync/Patches/ItemPatches.cs +++ b/QSB/ItemSync/Patches/ItemPatches.cs @@ -20,7 +20,7 @@ namespace QSB.ItemSync.Patches [HarmonyPatch(typeof(ItemTool), nameof(ItemTool.MoveItemToCarrySocket))] public static bool ItemTool_MoveItemToCarrySocket(OWItem item) { - var qsbObj = (IQSBOWItem)QSBWorldSync.GetWorldFromUnity(item); + var qsbObj = QSBWorldSync.GetWorldFromUnity(item); var itemId = QSBWorldSync.GetIdFromTypeSubset(qsbObj); QSBPlayerManager.LocalPlayer.HeldItem = qsbObj; QSBEventManager.FireEvent(EventNames.QSBMoveToCarry, itemId); @@ -31,8 +31,8 @@ namespace QSB.ItemSync.Patches [HarmonyPatch(typeof(ItemTool), nameof(ItemTool.SocketItem))] public static bool ItemTool_SocketItem(OWItem ____heldItem, OWItemSocket socket) { - var qsbObj = (IQSBOWItem)QSBWorldSync.GetWorldFromUnity(____heldItem); - var socketId = QSBWorldSync.GetIdFromTypeSubset((IQSBOWItemSocket)QSBWorldSync.GetWorldFromUnity(socket)); + var qsbObj = QSBWorldSync.GetWorldFromUnity(____heldItem); + var socketId = QSBWorldSync.GetIdFromTypeSubset(QSBWorldSync.GetWorldFromUnity(socket)); var itemId = QSBWorldSync.GetIdFromTypeSubset(qsbObj); QSBPlayerManager.LocalPlayer.HeldItem = null; QSBEventManager.FireEvent(EventNames.QSBSocketItem, socketId, itemId, SocketEventType.Socket); @@ -43,9 +43,9 @@ namespace QSB.ItemSync.Patches [HarmonyPatch(typeof(ItemTool), nameof(ItemTool.StartUnsocketItem))] public static bool ItemTool_StartUnsocketItem(OWItemSocket socket) { - var item = (IQSBOWItem)QSBWorldSync.GetWorldFromUnity(socket.GetSocketedItem()); + var item = QSBWorldSync.GetWorldFromUnity(socket.GetSocketedItem()); QSBPlayerManager.LocalPlayer.HeldItem = item; - var socketId = QSBWorldSync.GetIdFromTypeSubset((IQSBOWItemSocket)QSBWorldSync.GetWorldFromUnity(socket)); + var socketId = QSBWorldSync.GetIdFromTypeSubset(QSBWorldSync.GetWorldFromUnity(socket)); QSBEventManager.FireEvent(EventNames.QSBSocketItem, socketId, 0, SocketEventType.StartUnsocket); return true; } @@ -54,7 +54,7 @@ namespace QSB.ItemSync.Patches [HarmonyPatch(typeof(ItemTool), nameof(ItemTool.CompleteUnsocketItem))] public static bool ItemTool_CompleteUnsocketItem(OWItem ____heldItem) { - var itemId = QSBWorldSync.GetIdFromTypeSubset((IQSBOWItem)QSBWorldSync.GetWorldFromUnity(____heldItem)); + var itemId = QSBWorldSync.GetIdFromTypeSubset(QSBWorldSync.GetWorldFromUnity(____heldItem)); QSBEventManager.FireEvent(EventNames.QSBSocketItem, 0, itemId, SocketEventType.CompleteUnsocket); return true; } @@ -90,7 +90,7 @@ namespace QSB.ItemSync.Patches var parent = (customDropTarget == null) ? targetRigidbody.transform : customDropTarget.GetItemDropTargetTransform(hit.collider.gameObject); - var objectId = QSBWorldSync.GetIdFromTypeSubset((IQSBOWItem)QSBWorldSync.GetWorldFromUnity(____heldItem)); + var objectId = QSBWorldSync.GetIdFromTypeSubset(QSBWorldSync.GetWorldFromUnity(____heldItem)); ____heldItem.DropItem(hit.point, hit.normal, parent, sector, customDropTarget); ____heldItem = null; QSBPlayerManager.LocalPlayer.HeldItem = null; diff --git a/QSB/ItemSync/WorldObjects/Items/QSBOWItem.cs b/QSB/ItemSync/WorldObjects/Items/QSBOWItem.cs index 6feb597d..7e0ee773 100644 --- a/QSB/ItemSync/WorldObjects/Items/QSBOWItem.cs +++ b/QSB/ItemSync/WorldObjects/Items/QSBOWItem.cs @@ -46,7 +46,7 @@ namespace QSB.ItemSync.WorldObjects.Items if (InitialParent?.GetComponent() != null) { - var qsbObj = (IQSBOWItemSocket)QSBWorldSync.GetWorldFromUnity(InitialParent.GetComponent()); + var qsbObj = QSBWorldSync.GetWorldFromUnity(InitialParent.GetComponent()); InitialSocket = qsbObj; } }); diff --git a/QSB/ItemSync/WorldObjects/Sockets/QSBOWItemDoubleSocket.cs b/QSB/ItemSync/WorldObjects/Sockets/QSBOWItemDoubleSocket.cs index 286cbb3d..9aaa0571 100644 --- a/QSB/ItemSync/WorldObjects/Sockets/QSBOWItemDoubleSocket.cs +++ b/QSB/ItemSync/WorldObjects/Sockets/QSBOWItemDoubleSocket.cs @@ -17,9 +17,9 @@ namespace QSB.ItemSync.WorldObjects.Sockets => AttachedObject.IsSocketOccupied(); public virtual bool PlaceIntoSocket(IQSBOWItem item) - => AttachedObject.PlaceIntoSocket((OWItem)(item as IWorldObject).ReturnObject()); + => AttachedObject.PlaceIntoSocket((OWItem)item.ReturnObject()); public virtual IQSBOWItem RemoveFromSocket() - => (IQSBOWItem)QSBWorldSync.GetWorldFromUnity(AttachedObject.RemoveFromSocket()); + => QSBWorldSync.GetWorldFromUnity(AttachedObject.RemoveFromSocket()); } } diff --git a/QSB/ItemSync/WorldObjects/Sockets/QSBOWItemSocket.cs b/QSB/ItemSync/WorldObjects/Sockets/QSBOWItemSocket.cs index 96a6c0da..a0ef9b9b 100644 --- a/QSB/ItemSync/WorldObjects/Sockets/QSBOWItemSocket.cs +++ b/QSB/ItemSync/WorldObjects/Sockets/QSBOWItemSocket.cs @@ -17,9 +17,9 @@ namespace QSB.ItemSync.WorldObjects.Sockets => AttachedObject.IsSocketOccupied(); public virtual bool PlaceIntoSocket(IQSBOWItem item) - => AttachedObject.PlaceIntoSocket((OWItem)(item as IWorldObject).ReturnObject()); + => AttachedObject.PlaceIntoSocket((OWItem)item.ReturnObject()); public virtual IQSBOWItem RemoveFromSocket() - => (IQSBOWItem)QSBWorldSync.GetWorldFromUnity(AttachedObject.RemoveFromSocket()); + => QSBWorldSync.GetWorldFromUnity(AttachedObject.RemoveFromSocket()); } } diff --git a/QSB/Player/PlayerEntanglementWatcher.cs b/QSB/Player/PlayerEntanglementWatcher.cs index 8fa44700..aafa4f58 100644 --- a/QSB/Player/PlayerEntanglementWatcher.cs +++ b/QSB/Player/PlayerEntanglementWatcher.cs @@ -27,7 +27,7 @@ namespace QSB.Player if (_previousCollidingQuantumObject != collidingQuantumObject) { var objectIndex = (collidingQuantumObject != null) - ? QSBWorldSync.GetIdFromTypeSubset((IQSBQuantumObject)QSBWorldSync.GetWorldFromUnity(collidingQuantumObject)) + ? QSBWorldSync.GetIdFromTypeSubset(QSBWorldSync.GetWorldFromUnity(collidingQuantumObject)) : -1; QSBEventManager.FireEvent( diff --git a/QSB/QuantumSync/QuantumManager.cs b/QSB/QuantumSync/QuantumManager.cs index e525d100..b335ad37 100644 --- a/QSB/QuantumSync/QuantumManager.cs +++ b/QSB/QuantumSync/QuantumManager.cs @@ -83,7 +83,7 @@ namespace QSB.QuantumSync { if (quantumObject.IsEnabled) { - Popcron.Gizmos.Line((quantumObject as IWorldObject).ReturnObject().transform.position, + Popcron.Gizmos.Line(quantumObject.ReturnObject().transform.position, QSBPlayerManager.LocalPlayer.Body.transform.position, Color.magenta * 0.25f); } @@ -91,7 +91,7 @@ namespace QSB.QuantumSync continue; } - Popcron.Gizmos.Line((quantumObject as IWorldObject).ReturnObject().transform.position, + Popcron.Gizmos.Line(quantumObject.ReturnObject().transform.position, QSBPlayerManager.GetPlayer(quantumObject.ControllingPlayer).Body.transform.position, Color.magenta); } @@ -151,7 +151,7 @@ namespace QSB.QuantumSync return Enumerable.Empty(); } - var worldObj = (IQSBQuantumObject)QSBWorldSync.GetWorldFromUnity(obj); + var worldObj = QSBWorldSync.GetWorldFromUnity(obj); return QSBPlayerManager.PlayerList.Where(x => x.EntangledObject == worldObj); } } diff --git a/QSB/WorldSync/IWorldObjectTypeSubset.cs b/QSB/WorldSync/IWorldObjectTypeSubset.cs index a4fe56c2..02d47c27 100644 --- a/QSB/WorldSync/IWorldObjectTypeSubset.cs +++ b/QSB/WorldSync/IWorldObjectTypeSubset.cs @@ -1,4 +1,4 @@ namespace QSB.WorldSync { - public interface IWorldObjectTypeSubset { } + public interface IWorldObjectTypeSubset : IWorldObject { } } diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 7f335ac9..39790cc3 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -20,9 +20,11 @@ namespace QSB.WorldSync private static readonly Dictionary WorldObjectsToUnityObjects = new(); public static IEnumerable GetWorldObjects() + where TWorldObject : IWorldObject => WorldObjects.OfType(); public static TWorldObject GetWorldFromId(int id) + where TWorldObject : IWorldObject { var worldObjects = GetWorldObjects().ToList(); if (id < 0 || id >= worldObjects.Count) @@ -34,35 +36,6 @@ namespace QSB.WorldSync return worldObjects[id]; } - public static IWorldObject GetWorldFromUnity(MonoBehaviour unityObject) - { - if (unityObject == null) - { - DebugLog.ToConsole($"Error - Trying to run GetWorldFromUnity with a null unity object! TUnityObject:NULL, Stacktrace:\r\n{Environment.StackTrace}", MessageType.Error); - return default; - } - - if (!QSBCore.IsInMultiplayer) - { - DebugLog.ToConsole($"Warning - Trying to run GetWorldFromUnity while not in multiplayer! TUnityObject:{unityObject.GetType().Name}, Stacktrace:\r\n{Environment.StackTrace}", MessageType.Warning); - return default; - } - - if (!WorldObjectsToUnityObjects.TryGetValue(unityObject, out var returnObject)) - { - DebugLog.ToConsole($"Error - WorldObjectsToUnityObjects does not contain \"{unityObject.name}\"! TUnityObject:{unityObject.GetType().Name}, Stacktrace:\r\n{Environment.StackTrace}", MessageType.Error); - return default; - } - - if (returnObject == null) - { - DebugLog.ToConsole($"Error - World object for unity object {unityObject.name} is null! TUnityObject:{unityObject.GetType().Name}, Stacktrace:\r\n{Environment.StackTrace}", MessageType.Error); - return default; - } - - return returnObject; - } - public static TWorldObject GetWorldFromUnity(MonoBehaviour unityObject) where TWorldObject : IWorldObject { @@ -98,17 +71,19 @@ namespace QSB.WorldSync => GetWorldFromUnity(unityObject).ObjectId; public static int GetIdFromTypeSubset(TTypeSubset typeSubset) + where TTypeSubset : IWorldObjectTypeSubset { var index = GetWorldObjects().ToList().IndexOf(typeSubset); if (index == -1) { - DebugLog.ToConsole($"Warning - {((IWorldObject)typeSubset).Name} doesn't exist in list of {typeof(TTypeSubset).Name} !", MessageType.Warning); + DebugLog.ToConsole($"Warning - {typeSubset.Name} doesn't exist in list of {typeof(TTypeSubset).Name} !", MessageType.Warning); } return index; } public static void RemoveWorldObjects() + where TWorldObject : IWorldObject { if (WorldObjects.Count == 0) { @@ -140,7 +115,7 @@ namespace QSB.WorldSync .Where(x => x.gameObject.scene.name != null); public static void Init() - where TWorldObject : WorldObject + where TWorldObject : WorldObject, new() where TUnityObject : MonoBehaviour { RemoveWorldObjects(); @@ -157,15 +132,10 @@ namespace QSB.WorldSync } private static TWorldObject CreateWorldObject() - where TWorldObject : IWorldObject + where TWorldObject : IWorldObject, new() { - var worldObject = (TWorldObject)Activator.CreateInstance(typeof(TWorldObject)); + var worldObject = new TWorldObject(); WorldObjects.Add(worldObject); - if (worldObject == null) - { - // if this happens, god help you - DebugLog.ToConsole($"Error - CreateWorldObject is returning a null value! This is very bad!", MessageType.Error); - } return worldObject; } diff --git a/QuantumUNET/Messages/QNetworkMessage.cs b/QuantumUNET/Messages/QNetworkMessage.cs index e5dbc590..957ae567 100644 --- a/QuantumUNET/Messages/QNetworkMessage.cs +++ b/QuantumUNET/Messages/QNetworkMessage.cs @@ -1,5 +1,4 @@ using QuantumUNET.Transport; -using System; namespace QuantumUNET.Messages { @@ -12,7 +11,7 @@ namespace QuantumUNET.Messages public TMsg ReadMessage() where TMsg : QMessageBase, new() { - var result = Activator.CreateInstance(); + var result = new TMsg(); result.Deserialize(Reader); return result; } diff --git a/QuantumUNET/Transport/QNetworkReader.cs b/QuantumUNET/Transport/QNetworkReader.cs index 6cf66cc4..60b081ae 100644 --- a/QuantumUNET/Transport/QNetworkReader.cs +++ b/QuantumUNET/Transport/QNetworkReader.cs @@ -458,7 +458,7 @@ namespace QuantumUNET.Transport public TMsg ReadMessage() where TMsg : QMessageBase, new() { - var result = Activator.CreateInstance(); + var result = new TMsg(); result.Deserialize(this); return result; } From a812d9a9cfe57fd6683f1eaecb4a59611a9d2a72 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 11 Dec 2021 15:30:35 -0800 Subject: [PATCH 03/17] delayed ready for some world objects was missing the methods --- QSB/ElevatorSync/WorldObjects/QSBElevator.cs | 2 ++ QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/QSB/ElevatorSync/WorldObjects/QSBElevator.cs b/QSB/ElevatorSync/WorldObjects/QSBElevator.cs index 7ca93dee..53372f45 100644 --- a/QSB/ElevatorSync/WorldObjects/QSBElevator.cs +++ b/QSB/ElevatorSync/WorldObjects/QSBElevator.cs @@ -15,11 +15,13 @@ namespace QSB.ElevatorSync.WorldObjects public override void Init() { + StartDelayedReady(); QSBCore.UnityEvents.RunWhen(() => AttachedObject._interactVolume != null, InitValues); } private void InitValues() { + FinishDelayedReady(); _startLocalPos = AttachedObject._startLocalPos; _endLocalPos = AttachedObject._endLocalPos; _interactVolume = AttachedObject._interactVolume; diff --git a/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs b/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs index 7d5bd64d..f0d6a129 100644 --- a/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs +++ b/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs @@ -82,11 +82,13 @@ namespace QSB.QuantumSync.WorldObjects } } + StartDelayedReady(); QSBCore.UnityEvents.FireInNUpdates(LateInit, 5); } private void LateInit() { + FinishDelayedReady(); foreach (var shape in GetAttachedShapes()) { shape.OnShapeActivated += OnEnable; From 6e3845c10b1639a54c9e718936a05c9d29b73175 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 11 Dec 2021 15:36:59 -0800 Subject: [PATCH 04/17] IWorldObjectTypeSubset is IWorldObject, so no need to RemoveWorldObjects --- QSB/QSBNetworkManager.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/QSB/QSBNetworkManager.cs b/QSB/QSBNetworkManager.cs index 6abaab80..d9586e1f 100644 --- a/QSB/QSBNetworkManager.cs +++ b/QSB/QSBNetworkManager.cs @@ -253,7 +253,6 @@ namespace QSB private void RemoveWorldObjects() { - QSBWorldSync.RemoveWorldObjects(); QSBWorldSync.RemoveWorldObjects(); foreach (var platform in QSBWorldSync.GetUnityObjects()) { From 76171103abf7d4f0462decc77736737528572bcc Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 11 Dec 2021 17:36:44 -0800 Subject: [PATCH 05/17] fixed quit button being wrong --- QSB/Menus/MenuManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/Menus/MenuManager.cs b/QSB/Menus/MenuManager.cs index 15b9e5a6..647dfddd 100644 --- a/QSB/Menus/MenuManager.cs +++ b/QSB/Menus/MenuManager.cs @@ -176,7 +176,7 @@ namespace QSB.Menus DisconnectButton = MenuApi.PauseMenu_MakeMenuOpenButton("DISCONNECT", DisconnectPopup); - QuitButton = Resources.FindObjectsOfTypeAll().First(x => x.name == "Button-ExitToMainMenu").gameObject; + QuitButton = FindObjectOfType()._exitToMainMenuAction.gameObject; if (QSBCore.IsInMultiplayer) { From 0c833c4f8c1261b1173ed4578b1872b4408afac7 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 11 Dec 2021 18:16:00 -0800 Subject: [PATCH 06/17] bubba --- QSB/TornadoSync/WorldObjects/QSBTornado.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/QSB/TornadoSync/WorldObjects/QSBTornado.cs b/QSB/TornadoSync/WorldObjects/QSBTornado.cs index 4295be74..2b97199b 100644 --- a/QSB/TornadoSync/WorldObjects/QSBTornado.cs +++ b/QSB/TornadoSync/WorldObjects/QSBTornado.cs @@ -4,12 +4,6 @@ namespace QSB.TornadoSync.WorldObjects { public class QSBTornado : WorldObject { - public override void Init(TornadoController attachedObject, int id) - { - ObjectId = id; - AttachedObject = attachedObject; - } - public bool FormState { get => AttachedObject._tornadoRoot.activeSelf // forming or formed or collapsing From 4fb68a9283e0fd79837262f74e8c04f2b1761243 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 11 Dec 2021 20:13:49 -0800 Subject: [PATCH 07/17] inline CreateWorldObject --- QSB/WorldSync/QSBWorldSync.cs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 8b22f0ef..2477e41f 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -123,23 +123,17 @@ namespace QSB.WorldSync //DebugLog.DebugWrite($"{typeof(TWorldObject).Name} init : {list.Count} instances.", MessageType.Info); for (var id = 0; id < list.Count; id++) { - var obj = CreateWorldObject(); - obj.AttachedObject = list[id]; - obj.ObjectId = id; + var obj = new TWorldObject + { + AttachedObject = list[id], + ObjectId = id + }; obj.Init(); + WorldObjects.Add(obj); WorldObjectsToUnityObjects.Add(list[id], obj); } } - private static TWorldObject CreateWorldObject() - where TWorldObject : IWorldObject, new() - { - var worldObject = new TWorldObject(); - WorldObjects.Add(worldObject); - - return worldObject; - } - public static void HandleSlotStateChange(NomaiInterfaceSlot slot, NomaiInterfaceOrb affectingOrb, bool state) { var slotList = GetWorldObjects().ToList(); From 46bc97418fddff586b6e26e5e8a87950647a0d1f Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 11 Dec 2021 21:45:28 -0800 Subject: [PATCH 08/17] bruh --- QSB/WorldSync/WorldObjectManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/WorldSync/WorldObjectManager.cs b/QSB/WorldSync/WorldObjectManager.cs index 76394646..ad2e80c3 100644 --- a/QSB/WorldSync/WorldObjectManager.cs +++ b/QSB/WorldSync/WorldObjectManager.cs @@ -79,7 +79,7 @@ namespace QSB.WorldSync } catch (Exception ex) { - DebugLog.ToConsole($"Exception - Exception when trying to rebuild WorldObjects of manager {manager.GetType().Name} : {ex.Message} Stacktrace :\r\n{ex.StackTrace}", OWML.Common.MessageType.Error); + DebugLog.ToConsole($"Exception - Exception when trying to rebuild WorldObjects of manager {manager.GetType().Name} : {ex.Message} Stacktrace :\r\n{ex.StackTrace}", MessageType.Error); } } From fce0a7d7d83eaf52a5b35d22b55edb01a2b337a7 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 11 Dec 2021 21:57:00 -0800 Subject: [PATCH 09/17] remove world objects in Rebuild (all at once), and use ObjectId = WorldObjects.Count --- QSB/WorldSync/QSBWorldSync.cs | 3 +-- QSB/WorldSync/WorldObjectManager.cs | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 2477e41f..bc628ae2 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -118,7 +118,6 @@ namespace QSB.WorldSync where TWorldObject : WorldObject, new() where TUnityObject : MonoBehaviour { - RemoveWorldObjects(); var list = GetUnityObjects().ToList(); //DebugLog.DebugWrite($"{typeof(TWorldObject).Name} init : {list.Count} instances.", MessageType.Info); for (var id = 0; id < list.Count; id++) @@ -126,7 +125,7 @@ namespace QSB.WorldSync var obj = new TWorldObject { AttachedObject = list[id], - ObjectId = id + ObjectId = WorldObjects.Count }; obj.Init(); WorldObjects.Add(obj); diff --git a/QSB/WorldSync/WorldObjectManager.cs b/QSB/WorldSync/WorldObjectManager.cs index ad2e80c3..57c63f1e 100644 --- a/QSB/WorldSync/WorldObjectManager.cs +++ b/QSB/WorldSync/WorldObjectManager.cs @@ -66,6 +66,7 @@ namespace QSB.WorldSync private static void DoRebuild(OWScene scene) { + QSBWorldSync.RemoveWorldObjects(); _numManagersReadying = 0; _numObjectsReadying = 0; AllObjectsAdded = false; From e9b4ebc4d85ab0abd3a1ccd7b868b18c4d594b25 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 11 Dec 2021 21:34:50 -0800 Subject: [PATCH 10/17] remove TypeSubset --- QSB/Animation/NPC/WorldObjects/INpcAnimController.cs | 2 +- QSB/ItemSync/WorldObjects/Items/IQSBOWItem.cs | 2 +- .../WorldObjects/Sockets/IQSBOWItemSocket.cs | 2 +- QSB/QuantumSync/WorldObjects/IQSBQuantumObject.cs | 2 +- QSB/WorldSync/IWorldObjectTypeSubset.cs | 4 ---- QSB/WorldSync/QSBWorldSync.cs | 12 ------------ 6 files changed, 4 insertions(+), 20 deletions(-) delete mode 100644 QSB/WorldSync/IWorldObjectTypeSubset.cs diff --git a/QSB/Animation/NPC/WorldObjects/INpcAnimController.cs b/QSB/Animation/NPC/WorldObjects/INpcAnimController.cs index 1449d417..807adf7c 100644 --- a/QSB/Animation/NPC/WorldObjects/INpcAnimController.cs +++ b/QSB/Animation/NPC/WorldObjects/INpcAnimController.cs @@ -2,7 +2,7 @@ namespace QSB.Animation.NPC.WorldObjects { - public interface INpcAnimController : IWorldObjectTypeSubset + public interface INpcAnimController : IWorldObject { CharacterDialogueTree GetDialogueTree(); void StartConversation(); diff --git a/QSB/ItemSync/WorldObjects/Items/IQSBOWItem.cs b/QSB/ItemSync/WorldObjects/Items/IQSBOWItem.cs index 4fc184e0..035d43c2 100644 --- a/QSB/ItemSync/WorldObjects/Items/IQSBOWItem.cs +++ b/QSB/ItemSync/WorldObjects/Items/IQSBOWItem.cs @@ -3,7 +3,7 @@ using UnityEngine; namespace QSB.ItemSync.WorldObjects.Items { - public interface IQSBOWItem : IWorldObjectTypeSubset + public interface IQSBOWItem : IWorldObject { ItemType GetItemType(); void SetColliderActivation(bool active); diff --git a/QSB/ItemSync/WorldObjects/Sockets/IQSBOWItemSocket.cs b/QSB/ItemSync/WorldObjects/Sockets/IQSBOWItemSocket.cs index a1cc6887..ba51ec1e 100644 --- a/QSB/ItemSync/WorldObjects/Sockets/IQSBOWItemSocket.cs +++ b/QSB/ItemSync/WorldObjects/Sockets/IQSBOWItemSocket.cs @@ -3,7 +3,7 @@ using QSB.WorldSync; namespace QSB.ItemSync.WorldObjects.Sockets { - public interface IQSBOWItemSocket : IWorldObjectTypeSubset + public interface IQSBOWItemSocket : IWorldObject { bool AcceptsItem(IQSBOWItem item); bool IsSocketOccupied(); diff --git a/QSB/QuantumSync/WorldObjects/IQSBQuantumObject.cs b/QSB/QuantumSync/WorldObjects/IQSBQuantumObject.cs index 8d314a44..3d38c3f9 100644 --- a/QSB/QuantumSync/WorldObjects/IQSBQuantumObject.cs +++ b/QSB/QuantumSync/WorldObjects/IQSBQuantumObject.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; namespace QSB.QuantumSync { - public interface IQSBQuantumObject : IWorldObjectTypeSubset + public interface IQSBQuantumObject : IWorldObject { uint ControllingPlayer { get; set; } bool IsEnabled { get; set; } diff --git a/QSB/WorldSync/IWorldObjectTypeSubset.cs b/QSB/WorldSync/IWorldObjectTypeSubset.cs deleted file mode 100644 index 02d47c27..00000000 --- a/QSB/WorldSync/IWorldObjectTypeSubset.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace QSB.WorldSync -{ - public interface IWorldObjectTypeSubset : IWorldObject { } -} diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index bc628ae2..124563f3 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -70,18 +70,6 @@ namespace QSB.WorldSync where TWorldObject : IWorldObject => GetWorldFromUnity(unityObject).ObjectId; - public static int GetIdFromTypeSubset(TTypeSubset typeSubset) - where TTypeSubset : IWorldObjectTypeSubset - { - var index = GetWorldObjects().ToList().IndexOf(typeSubset); - if (index == -1) - { - DebugLog.ToConsole($"Warning - {typeSubset.Name} doesn't exist in list of {typeof(TTypeSubset).Name} !", MessageType.Warning); - } - - return index; - } - public static void RemoveWorldObjects() where TWorldObject : IWorldObject { From 8c4004fc58f0fbd6971445f9101eec8c3dd473b5 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 11 Dec 2021 21:36:41 -0800 Subject: [PATCH 11/17] use ObjectId instead --- .../NPC/Patches/CharacterAnimationPatches.cs | 4 ++-- QSB/ItemSync/Patches/ItemPatches.cs | 12 ++++++------ QSB/Player/Events/RequestStateResyncEvent.cs | 7 ++----- QSB/Player/PlayerEntanglementWatcher.cs | 2 +- QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs | 4 ++-- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/QSB/Animation/NPC/Patches/CharacterAnimationPatches.cs b/QSB/Animation/NPC/Patches/CharacterAnimationPatches.cs index 9ffeb4b3..16203540 100644 --- a/QSB/Animation/NPC/Patches/CharacterAnimationPatches.cs +++ b/QSB/Animation/NPC/Patches/CharacterAnimationPatches.cs @@ -153,7 +153,7 @@ namespace QSB.Animation.NPC.Patches return true; } - var id = QSBWorldSync.GetIdFromTypeSubset(ownerOfThis); + var id = ownerOfThis.ObjectId; QSBEventManager.FireEvent(EventNames.QSBNpcAnimEvent, AnimationEvent.StartConversation, id); return true; } @@ -169,7 +169,7 @@ namespace QSB.Animation.NPC.Patches return true; } - var id = QSBWorldSync.GetIdFromTypeSubset(ownerOfThis); + var id = ownerOfThis.ObjectId; QSBEventManager.FireEvent(EventNames.QSBNpcAnimEvent, AnimationEvent.EndConversation, id); return true; } diff --git a/QSB/ItemSync/Patches/ItemPatches.cs b/QSB/ItemSync/Patches/ItemPatches.cs index 2e953430..ef59d941 100644 --- a/QSB/ItemSync/Patches/ItemPatches.cs +++ b/QSB/ItemSync/Patches/ItemPatches.cs @@ -21,7 +21,7 @@ namespace QSB.ItemSync.Patches public static bool ItemTool_MoveItemToCarrySocket(OWItem item) { var qsbObj = QSBWorldSync.GetWorldFromUnity(item); - var itemId = QSBWorldSync.GetIdFromTypeSubset(qsbObj); + var itemId = qsbObj.ObjectId; QSBPlayerManager.LocalPlayer.HeldItem = qsbObj; QSBEventManager.FireEvent(EventNames.QSBMoveToCarry, itemId); return true; @@ -32,8 +32,8 @@ namespace QSB.ItemSync.Patches public static bool ItemTool_SocketItem(OWItem ____heldItem, OWItemSocket socket) { var qsbObj = QSBWorldSync.GetWorldFromUnity(____heldItem); - var socketId = QSBWorldSync.GetIdFromTypeSubset(QSBWorldSync.GetWorldFromUnity(socket)); - var itemId = QSBWorldSync.GetIdFromTypeSubset(qsbObj); + var socketId = QSBWorldSync.GetWorldFromUnity(socket).ObjectId; + var itemId = qsbObj.ObjectId; QSBPlayerManager.LocalPlayer.HeldItem = null; QSBEventManager.FireEvent(EventNames.QSBSocketItem, socketId, itemId, SocketEventType.Socket); return true; @@ -45,7 +45,7 @@ namespace QSB.ItemSync.Patches { var item = QSBWorldSync.GetWorldFromUnity(socket.GetSocketedItem()); QSBPlayerManager.LocalPlayer.HeldItem = item; - var socketId = QSBWorldSync.GetIdFromTypeSubset(QSBWorldSync.GetWorldFromUnity(socket)); + var socketId = QSBWorldSync.GetWorldFromUnity(socket).ObjectId; QSBEventManager.FireEvent(EventNames.QSBSocketItem, socketId, 0, SocketEventType.StartUnsocket); return true; } @@ -54,7 +54,7 @@ namespace QSB.ItemSync.Patches [HarmonyPatch(typeof(ItemTool), nameof(ItemTool.CompleteUnsocketItem))] public static bool ItemTool_CompleteUnsocketItem(OWItem ____heldItem) { - var itemId = QSBWorldSync.GetIdFromTypeSubset(QSBWorldSync.GetWorldFromUnity(____heldItem)); + var itemId = QSBWorldSync.GetWorldFromUnity(____heldItem).ObjectId; QSBEventManager.FireEvent(EventNames.QSBSocketItem, 0, itemId, SocketEventType.CompleteUnsocket); return true; } @@ -90,7 +90,7 @@ namespace QSB.ItemSync.Patches var parent = (customDropTarget == null) ? targetRigidbody.transform : customDropTarget.GetItemDropTargetTransform(hit.collider.gameObject); - var objectId = QSBWorldSync.GetIdFromTypeSubset(QSBWorldSync.GetWorldFromUnity(____heldItem)); + var objectId = QSBWorldSync.GetWorldFromUnity(____heldItem).ObjectId; ____heldItem.DropItem(hit.point, hit.normal, parent, sector, customDropTarget); ____heldItem = null; QSBPlayerManager.LocalPlayer.HeldItem = null; diff --git a/QSB/Player/Events/RequestStateResyncEvent.cs b/QSB/Player/Events/RequestStateResyncEvent.cs index a590ff98..0dc2925e 100644 --- a/QSB/Player/Events/RequestStateResyncEvent.cs +++ b/QSB/Player/Events/RequestStateResyncEvent.cs @@ -108,11 +108,8 @@ namespace QSB.Player.Events => QSBEventManager.FireEvent(EventNames.QSBTextTranslated, NomaiTextType.VesselComputer, vesselComputer.ObjectId, id)); } - var list = QSBWorldSync.GetWorldObjects().ToList(); - for (var i = 0; i < list.Count; i++) - { - QSBEventManager.FireEvent(EventNames.QSBQuantumAuthority, i, list[i].ControllingPlayer); - } + QSBWorldSync.GetWorldObjects().ForEach(x + => QSBEventManager.FireEvent(EventNames.QSBQuantumAuthority, x.ObjectId, x.ControllingPlayer)); QSBWorldSync.GetWorldObjects().ForEach(campfire => QSBEventManager.FireEvent(EventNames.QSBCampfireState, campfire.ObjectId, campfire.GetState())); diff --git a/QSB/Player/PlayerEntanglementWatcher.cs b/QSB/Player/PlayerEntanglementWatcher.cs index aafa4f58..0ca9e1f7 100644 --- a/QSB/Player/PlayerEntanglementWatcher.cs +++ b/QSB/Player/PlayerEntanglementWatcher.cs @@ -27,7 +27,7 @@ namespace QSB.Player if (_previousCollidingQuantumObject != collidingQuantumObject) { var objectIndex = (collidingQuantumObject != null) - ? QSBWorldSync.GetIdFromTypeSubset(QSBWorldSync.GetWorldFromUnity(collidingQuantumObject)) + ? QSBWorldSync.GetWorldFromUnity(collidingQuantumObject).ObjectId : -1; QSBEventManager.FireEvent( diff --git a/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs b/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs index e8923116..68b70870 100644 --- a/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs +++ b/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs @@ -173,7 +173,7 @@ namespace QSB.QuantumSync.WorldObjects return; } - var id = QSBWorldSync.GetIdFromTypeSubset(this); + var id = ObjectId; // no one is controlling this object right now, request authority QSBEventManager.FireEvent(EventNames.QSBQuantumAuthority, id, QSBPlayerManager.LocalPlayerId); } @@ -202,7 +202,7 @@ namespace QSB.QuantumSync.WorldObjects return; } - var id = QSBWorldSync.GetIdFromTypeSubset(this); + var id = ObjectId; // send event to other players that we're releasing authority QSBEventManager.FireEvent(EventNames.QSBQuantumAuthority, id, 0u); } From a83744bb99f4a97f66c1a9db2da1855c903f2bf2 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 11 Dec 2021 22:00:21 -0800 Subject: [PATCH 12/17] better RemoveWorldObjects --- QSB/QSBNetworkManager.cs | 2 +- QSB/WorldSync/QSBWorldSync.cs | 13 +++++-------- QSB/WorldSync/WorldObjectManager.cs | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/QSB/QSBNetworkManager.cs b/QSB/QSBNetworkManager.cs index d6d69dbc..13fc7025 100644 --- a/QSB/QSBNetworkManager.cs +++ b/QSB/QSBNetworkManager.cs @@ -277,7 +277,7 @@ namespace QSB private void RemoveWorldObjects() { - QSBWorldSync.RemoveWorldObjects(); + QSBWorldSync.RemoveWorldObjects(); foreach (var platform in QSBWorldSync.GetUnityObjects()) { Destroy(platform); diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 124563f3..f6b612e2 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -70,22 +70,18 @@ namespace QSB.WorldSync where TWorldObject : IWorldObject => GetWorldFromUnity(unityObject).ObjectId; - public static void RemoveWorldObjects() - where TWorldObject : IWorldObject + public static void RemoveWorldObjects() { if (WorldObjects.Count == 0) { - DebugLog.ToConsole($"Warning - Trying to remove WorldObjects of type {typeof(TWorldObject).Name}, but there are no WorldObjects!", MessageType.Warning); + DebugLog.ToConsole($"Warning - Trying to remove WorldObjects, but there are no WorldObjects!", MessageType.Warning); return; } - var itemsToRemove = WorldObjects.Where(x => x is TWorldObject); - - foreach (var item in itemsToRemove) + foreach (var item in WorldObjects) { try { - WorldObjectsToUnityObjects.Remove(item.ReturnObject()); item.OnRemoval(); } catch (Exception e) @@ -94,7 +90,8 @@ namespace QSB.WorldSync } } - WorldObjects.RemoveAll(x => x is TWorldObject); + WorldObjects.Clear(); + WorldObjectsToUnityObjects.Clear(); } public static IEnumerable GetUnityObjects() diff --git a/QSB/WorldSync/WorldObjectManager.cs b/QSB/WorldSync/WorldObjectManager.cs index 57c63f1e..bd70ab9f 100644 --- a/QSB/WorldSync/WorldObjectManager.cs +++ b/QSB/WorldSync/WorldObjectManager.cs @@ -66,7 +66,7 @@ namespace QSB.WorldSync private static void DoRebuild(OWScene scene) { - QSBWorldSync.RemoveWorldObjects(); + QSBWorldSync.RemoveWorldObjects(); _numManagersReadying = 0; _numObjectsReadying = 0; AllObjectsAdded = false; From 07dc6242dcb0b7c5db0ca01600e652ab65a7e2ef Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 11 Dec 2021 22:04:48 -0800 Subject: [PATCH 13/17] make GetWorldFromId work --- QSB/WorldSync/QSBWorldSync.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index f6b612e2..02c487df 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -26,14 +26,19 @@ namespace QSB.WorldSync public static TWorldObject GetWorldFromId(int id) where TWorldObject : IWorldObject { - var worldObjects = GetWorldObjects().ToList(); - if (id < 0 || id >= worldObjects.Count) + if (id < 0 || id >= WorldObjects.Count) { - DebugLog.ToConsole($"Warning - Tried to find {typeof(TWorldObject).Name} id {id}. Count is {worldObjects.Count}.", MessageType.Warning); + DebugLog.ToConsole($"Warning - Tried to find {typeof(TWorldObject).Name} id {id}. Count is {WorldObjects.Count}.", MessageType.Warning); return default; } - return worldObjects[id]; + if (WorldObjects[id] is not TWorldObject worldObject) + { + DebugLog.ToConsole($"Error - {typeof(TWorldObject).Name} id {id} is actually {WorldObjects[id].GetType().Name}.", MessageType.Error); + return default; + } + + return worldObject; } public static TWorldObject GetWorldFromUnity(MonoBehaviour unityObject) From 9f62fff9fd22f68747c859568734f1ab3c84fa64 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 11 Dec 2021 22:18:44 -0800 Subject: [PATCH 14/17] fix transform syncs that depended on ObjectId --- QSB/Anglerfish/TransformSync/AnglerTransformSync.cs | 3 ++- QSB/Anglerfish/WorldObjects/QSBAngler.cs | 2 ++ QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs | 3 ++- QSB/JellyfishSync/WorldObjects/QSBJellyfish.cs | 2 ++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/QSB/Anglerfish/TransformSync/AnglerTransformSync.cs b/QSB/Anglerfish/TransformSync/AnglerTransformSync.cs index 01d874e0..38b2a731 100644 --- a/QSB/Anglerfish/TransformSync/AnglerTransformSync.cs +++ b/QSB/Anglerfish/TransformSync/AnglerTransformSync.cs @@ -14,6 +14,7 @@ namespace QSB.Anglerfish.TransformSync public override bool IsPlayerObject => false; private QSBAngler _qsbAngler; + public static readonly List Anglers = new(); private static readonly List _instances = new(); protected override OWRigidbody GetRigidbody() @@ -35,7 +36,7 @@ namespace QSB.Anglerfish.TransformSync protected override void Init() { - _qsbAngler = QSBWorldSync.GetWorldFromId(_instances.IndexOf(this)); + _qsbAngler = QSBWorldSync.GetWorldFromUnity(Anglers[_instances.IndexOf(this)]); _qsbAngler.TransformSync = this; base.Init(); diff --git a/QSB/Anglerfish/WorldObjects/QSBAngler.cs b/QSB/Anglerfish/WorldObjects/QSBAngler.cs index 97e8d36c..8e383810 100644 --- a/QSB/Anglerfish/WorldObjects/QSBAngler.cs +++ b/QSB/Anglerfish/WorldObjects/QSBAngler.cs @@ -16,6 +16,7 @@ namespace QSB.Anglerfish.WorldObjects public override void Init() { + AnglerTransformSync.Anglers.Add(AttachedObject); if (QSBCore.IsHost) { QNetworkServer.Spawn(Object.Instantiate(QSBNetworkManager.Instance.AnglerPrefab)); @@ -38,6 +39,7 @@ namespace QSB.Anglerfish.WorldObjects public override void OnRemoval() { + AnglerTransformSync.Anglers.Remove(AttachedObject); if (QSBCore.IsHost) { TransformSync.NetIdentity.UnregisterAuthQueue(); diff --git a/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs b/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs index 9114b439..25648ef2 100644 --- a/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs +++ b/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs @@ -16,6 +16,7 @@ namespace QSB.JellyfishSync.TransformSync public override bool IsPlayerObject => false; private QSBJellyfish _qsbJellyfish; + public static readonly List Jellyfish = new(); private static readonly List _instances = new(); protected override OWRigidbody GetRigidbody() @@ -37,7 +38,7 @@ namespace QSB.JellyfishSync.TransformSync protected override void Init() { - _qsbJellyfish = QSBWorldSync.GetWorldFromId(_instances.IndexOf(this)); + _qsbJellyfish = QSBWorldSync.GetWorldFromUnity(Jellyfish[_instances.IndexOf(this)]); _qsbJellyfish.TransformSync = this; base.Init(); diff --git a/QSB/JellyfishSync/WorldObjects/QSBJellyfish.cs b/QSB/JellyfishSync/WorldObjects/QSBJellyfish.cs index 3a5429ba..cc94b169 100644 --- a/QSB/JellyfishSync/WorldObjects/QSBJellyfish.cs +++ b/QSB/JellyfishSync/WorldObjects/QSBJellyfish.cs @@ -15,6 +15,7 @@ namespace QSB.JellyfishSync.WorldObjects { _alignWithTargetBody = AttachedObject.GetRequiredComponent(); + JellyfishTransformSync.Jellyfish.Add(AttachedObject); if (QSBCore.IsHost) { QNetworkServer.Spawn(Object.Instantiate(QSBNetworkManager.Instance.JellyfishPrefab)); @@ -37,6 +38,7 @@ namespace QSB.JellyfishSync.WorldObjects public override void OnRemoval() { + JellyfishTransformSync.Jellyfish.Remove(AttachedObject); if (QSBCore.IsHost) { TransformSync.NetIdentity.UnregisterAuthQueue(); From 7ad0c5ae157997aa59baaa39a4c1d165622d87e3 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 11 Dec 2021 17:55:36 -0800 Subject: [PATCH 15/17] player creation as separate method --- QSB/Player/QSBPlayerManager.cs | 24 ++++++++++++------- .../TransformSync/PlayerTransformSync.cs | 1 + 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/QSB/Player/QSBPlayerManager.cs b/QSB/Player/QSBPlayerManager.cs index 6895a1da..9ee8503f 100644 --- a/QSB/Player/QSBPlayerManager.cs +++ b/QSB/Player/QSBPlayerManager.cs @@ -47,26 +47,32 @@ namespace QSB.Player { if (id is uint.MaxValue or 0U) { + DebugLog.ToConsole($"Warning - GetPlayer was given bad id {id}! Stacktrace : {Environment.StackTrace}", MessageType.Warning); return default; } var player = PlayerList.FirstOrDefault(x => x.PlayerId == id); - if (player != null) + if (player == null) { - return player; - } - - if (!QSBCore.IsInMultiplayer) - { - DebugLog.ToConsole($"Error - Tried to create player id:{id} when not in multiplayer! Stacktrace : {Environment.StackTrace}", MessageType.Error); + DebugLog.ToConsole($"Error - Player with id {id} does not exist! Stacktrace : {Environment.StackTrace}", MessageType.Error); return default; } + return player; + } + + public static void AddPlayer(uint id) + { + if (!QSBCore.IsInMultiplayer) + { + DebugLog.ToConsole($"Error - Tried to create player id:{id} when not in multiplayer!", MessageType.Error); + return; + } + DebugLog.DebugWrite($"Create Player : id<{id}>", MessageType.Info); - player = new PlayerInfo(id); + var player = new PlayerInfo(id); PlayerList.Add(player); OnAddPlayer?.Invoke(id); - return player; } public static void RemovePlayer(uint id) diff --git a/QSB/Player/TransformSync/PlayerTransformSync.cs b/QSB/Player/TransformSync/PlayerTransformSync.cs index 8c90ead7..ef2e0209 100644 --- a/QSB/Player/TransformSync/PlayerTransformSync.cs +++ b/QSB/Player/TransformSync/PlayerTransformSync.cs @@ -50,6 +50,7 @@ namespace QSB.Player.TransformSync public override void Start() { base.Start(); + QSBPlayerManager.AddPlayer(PlayerId); Player.TransformSync = this; } From 3e8dee7c594129aa8e720c2c0bafc63136963d9f Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 11 Dec 2021 18:00:54 -0800 Subject: [PATCH 16/17] remove warning. it's okay --- QSB/Player/QSBPlayerManager.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/QSB/Player/QSBPlayerManager.cs b/QSB/Player/QSBPlayerManager.cs index 9ee8503f..762f375d 100644 --- a/QSB/Player/QSBPlayerManager.cs +++ b/QSB/Player/QSBPlayerManager.cs @@ -47,7 +47,6 @@ namespace QSB.Player { if (id is uint.MaxValue or 0U) { - DebugLog.ToConsole($"Warning - GetPlayer was given bad id {id}! Stacktrace : {Environment.StackTrace}", MessageType.Warning); return default; } From dd6b9f19e36b91e4250299a0ca7c9e58d85b4107 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 11 Dec 2021 18:02:30 -0800 Subject: [PATCH 17/17] remove error that can't happen --- QSB/Player/QSBPlayerManager.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/QSB/Player/QSBPlayerManager.cs b/QSB/Player/QSBPlayerManager.cs index 762f375d..59a5361c 100644 --- a/QSB/Player/QSBPlayerManager.cs +++ b/QSB/Player/QSBPlayerManager.cs @@ -62,12 +62,6 @@ namespace QSB.Player public static void AddPlayer(uint id) { - if (!QSBCore.IsInMultiplayer) - { - DebugLog.ToConsole($"Error - Tried to create player id:{id} when not in multiplayer!", MessageType.Error); - return; - } - DebugLog.DebugWrite($"Create Player : id<{id}>", MessageType.Info); var player = new PlayerInfo(id); PlayerList.Add(player);