From 558221491e6217d3730ede87803c5e5392e653dd Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 15 Nov 2021 00:29:36 -0800 Subject: [PATCH] resync event done --- QSB/MeteorSync/Events/FragmentResyncEvent.cs | 49 +++++++++---------- .../Events/FragmentResyncMessage.cs | 10 ++-- QSB/MeteorSync/WorldObjects/QSBFragment.cs | 15 ++++++ 3 files changed, 43 insertions(+), 31 deletions(-) diff --git a/QSB/MeteorSync/Events/FragmentResyncEvent.cs b/QSB/MeteorSync/Events/FragmentResyncEvent.cs index 2943da5a..98885493 100644 --- a/QSB/MeteorSync/Events/FragmentResyncEvent.cs +++ b/QSB/MeteorSync/Events/FragmentResyncEvent.cs @@ -1,4 +1,5 @@ using System; +using OWML.Common; using QSB.Events; using QSB.MeteorSync.WorldObjects; using QSB.Utility; @@ -33,20 +34,14 @@ namespace QSB.MeteorSync.Events if (msg.Integrity <= 0) { - var detachableFragment = qsbFragment.AttachedObject.GetRequiredComponent(); + msg.IsThruWhiteHole = qsbFragment.IsThruWhiteHole; - msg.IsThruWhitehole = detachableFragment._sector._parentSector == MeteorManager.WhiteHoleVolume._whiteHoleSector; + var refBody = GetRefBody(msg.IsThruWhiteHole); + var body = qsbFragment.AttachedObject.transform.parent.parent.GetAttachedOWRigidbody(); - var refBody = GetRefBody(msg.IsThruWhitehole); - var body = detachableFragment.transform.parent.parent.GetAttachedOWRigidbody(); - if (!body.CompareTag("DetachedFragment")) + if (msg.IsThruWhiteHole) { - throw new Exception("HUGE BRUH MOMENT"); - } - - if (msg.IsThruWhitehole) - { - msg.LeashLength = body.gameObject.GetRequiredComponent()._leashLength; + msg.LeashLength = qsbFragment.LeashLength; } msg.Pos = refBody.transform.InverseTransformPoint(body.transform.position); @@ -75,23 +70,26 @@ namespace QSB.MeteorSync.Events // the detach is delay, so wait even more until that happens lol QSBCore.UnityEvents.FireInNUpdates(() => { - var detachableFragment = qsbFragment.AttachedObject.GetRequiredComponent(); + var refBody = GetRefBody(msg.IsThruWhiteHole); + var body = qsbFragment.AttachedObject.transform.parent.parent.GetAttachedOWRigidbody(); - var refBody = GetRefBody(msg.IsThruWhitehole); - var body = detachableFragment.transform.parent.parent.GetAttachedOWRigidbody(); - if (!body.CompareTag("DetachedFragment")) + if (msg.IsThruWhiteHole && !qsbFragment.IsThruWhiteHole) { - throw new Exception("HUGE BRUH MOMENT"); - } - - if (msg.IsThruWhitehole - && detachableFragment._sector._parentSector != MeteorManager.WhiteHoleVolume._whiteHoleSector) - { - detachableFragment.ChangeFragmentSector(MeteorManager.WhiteHoleVolume._whiteHoleSector, + qsbFragment.DetachableFragment.ChangeFragmentSector(MeteorManager.WhiteHoleVolume._whiteHoleSector, MeteorManager.WhiteHoleVolume._whiteHoleProxyShadowSuperGroup); body.gameObject.AddComponent().Init(MeteorManager.WhiteHoleVolume._whiteHoleBody, msg.LeashLength); } + else if (msg.IsThruWhiteHole && qsbFragment.IsThruWhiteHole) + { + qsbFragment.LeashLength = msg.LeashLength; + } + else if (!msg.IsThruWhiteHole && qsbFragment.IsThruWhiteHole) + { + // should only happen if client is way too far ahead and they try to connect. we fail here. + DebugLog.ToConsole($"{qsbFragment.LogName} is thru white hole, but msg is not. goodbye", MessageType.Quit); + Application.Quit(); + } var targetPos = refBody.transform.TransformPoint(msg.Pos); var targetRot = refBody.transform.TransformRotation(msg.Rot); @@ -106,16 +104,15 @@ namespace QSB.MeteorSync.Events } - private static OWRigidbody GetRefBody(bool isThruWhitehole) => - isThruWhitehole ? MeteorManager.WhiteHoleVolume._whiteHoleBody : Locator._brittleHollow._owRigidbody; + private static OWRigidbody GetRefBody(bool isThruWhiteHole) => + isThruWhiteHole ? MeteorManager.WhiteHoleVolume._whiteHoleBody : Locator._brittleHollow._owRigidbody; // code yoink from transform sync lol private static void SetVelocity(OWRigidbody rigidbody, Vector3 relativeVelocity) { - var isRunningKinematic = rigidbody.RunningKinematicSimulation(); var currentVelocity = rigidbody._currentVelocity; - if (isRunningKinematic) + if (rigidbody.RunningKinematicSimulation()) { rigidbody._kinematicRigidbody.velocity = relativeVelocity + Locator.GetCenterOfTheUniverse().GetStaticFrameVelocity_Internal(); } diff --git a/QSB/MeteorSync/Events/FragmentResyncMessage.cs b/QSB/MeteorSync/Events/FragmentResyncMessage.cs index db6c3d96..e6fa8562 100644 --- a/QSB/MeteorSync/Events/FragmentResyncMessage.cs +++ b/QSB/MeteorSync/Events/FragmentResyncMessage.cs @@ -13,7 +13,7 @@ namespace QSB.MeteorSync.Events public Quaternion Rot; public Vector3 Vel; public Vector3 AngVel; - public bool IsThruWhitehole; + public bool IsThruWhiteHole; public float LeashLength; public override void Deserialize(QNetworkReader reader) @@ -28,8 +28,8 @@ namespace QSB.MeteorSync.Events Vel = reader.ReadVector3(); AngVel = reader.ReadVector3(); - IsThruWhitehole = reader.ReadBoolean(); - if (IsThruWhitehole) + IsThruWhiteHole = reader.ReadBoolean(); + if (IsThruWhiteHole) { LeashLength = reader.ReadSingle(); } @@ -48,8 +48,8 @@ namespace QSB.MeteorSync.Events writer.Write(Vel); writer.Write(AngVel); - writer.Write(IsThruWhitehole); - if (IsThruWhitehole) + writer.Write(IsThruWhiteHole); + if (IsThruWhiteHole) { writer.Write(LeashLength); } diff --git a/QSB/MeteorSync/WorldObjects/QSBFragment.cs b/QSB/MeteorSync/WorldObjects/QSBFragment.cs index 2474bd66..3bcee515 100644 --- a/QSB/MeteorSync/WorldObjects/QSBFragment.cs +++ b/QSB/MeteorSync/WorldObjects/QSBFragment.cs @@ -8,6 +8,7 @@ namespace QSB.MeteorSync.WorldObjects { ObjectId = id; AttachedObject = attachedObject; + DetachableFragment = AttachedObject.GetRequiredComponent(); } public override void OnRemoval() @@ -16,6 +17,20 @@ namespace QSB.MeteorSync.WorldObjects } + public DetachableFragment DetachableFragment; + public bool IsThruWhiteHole => DetachableFragment._sector._parentSector == MeteorManager.WhiteHoleVolume._whiteHoleSector; + + public float LeashLength + { + get => AttachedObject.GetComponent()._leashLength; + set + { + var debrisLeash = AttachedObject.GetComponent(); + debrisLeash._deccelerating = false; + debrisLeash._leashLength = value; + } + } + public void AddDamage(float damage) { AttachedObject.AddDamage(damage);