diff --git a/QSB/Anglerfish/Patches/AnglerPatches.cs b/QSB/Anglerfish/Patches/AnglerPatches.cs index b7e174d4..c492b9dc 100644 --- a/QSB/Anglerfish/Patches/AnglerPatches.cs +++ b/QSB/Anglerfish/Patches/AnglerPatches.cs @@ -30,35 +30,6 @@ namespace QSB.Anglerfish.Patches return false; } - [HarmonyPrefix] - [HarmonyPatch(typeof(AnglerfishController), nameof(AnglerfishController.OnSectorOccupantsUpdated))] - public static bool OnSectorOccupantsUpdated(AnglerfishController __instance) - { - if (!WorldObjectManager.AllObjectsReady) - { - return true; - } - var qsbAngler = QSBWorldSync.GetWorldFromUnity(__instance); - - if (!__instance.gameObject.activeSelf && __instance._sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe | DynamicOccupant.Ship)) - { - __instance.gameObject.SetActive(true); - __instance._anglerBody.Unsuspend(); - __instance.RaiseEvent(nameof(__instance.OnAnglerUnsuspended), __instance._currentState); - qsbAngler.TransformSync.NetIdentity.FireAuthQueue(true); - return false; - } - if (__instance.gameObject.activeSelf && !__instance._sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe | DynamicOccupant.Ship)) - { - __instance._anglerBody.Suspend(); - __instance.gameObject.SetActive(false); - __instance.RaiseEvent(nameof(__instance.OnAnglerSuspended), __instance._currentState); - qsbAngler.TransformSync.NetIdentity.FireAuthQueue(false); - } - - return false; - } - [HarmonyPrefix] [HarmonyPatch(typeof(AnglerfishController), nameof(AnglerfishController.OnSectorOccupantRemoved))] public static bool OnSectorOccupantRemoved(AnglerfishController __instance, diff --git a/QSB/Anglerfish/TransformSync/AnglerTransformSync.cs b/QSB/Anglerfish/TransformSync/AnglerTransformSync.cs index 2da13c43..51fc1b1a 100644 --- a/QSB/Anglerfish/TransformSync/AnglerTransformSync.cs +++ b/QSB/Anglerfish/TransformSync/AnglerTransformSync.cs @@ -35,6 +35,8 @@ namespace QSB.Anglerfish.TransformSync { NetIdentity.UnregisterAuthQueue(); } + AttachedObject.OnUnsuspendOWRigidbody -= OnUnsuspend; + AttachedObject.OnSuspendOWRigidbody -= OnSuspend; } public override float GetNetworkSendInterval() => 1; @@ -51,10 +53,14 @@ namespace QSB.Anglerfish.TransformSync { NetIdentity.RegisterAuthQueue(); } - // for when you host/connect mid-game + AttachedObject.OnUnsuspendOWRigidbody += OnUnsuspend; + AttachedObject.OnSuspendOWRigidbody += OnSuspend; NetIdentity.FireAuthQueue(!AttachedObject.IsSuspended()); } + private void OnUnsuspend(OWRigidbody suspendedBody) => NetIdentity.FireAuthQueue(true); + private void OnSuspend(OWRigidbody suspendedBody) => NetIdentity.FireAuthQueue(false); + private bool _shouldUpdate; public override void DeserializeTransform(QNetworkReader reader, bool initialState) diff --git a/QSB/JellyfishSync/Patches/JellyfishPatches.cs b/QSB/JellyfishSync/Patches/JellyfishPatches.cs index aa0cb85a..ef6205d8 100644 --- a/QSB/JellyfishSync/Patches/JellyfishPatches.cs +++ b/QSB/JellyfishSync/Patches/JellyfishPatches.cs @@ -11,33 +11,6 @@ namespace QSB.JellyfishSync.Patches { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - [HarmonyPrefix] - [HarmonyPatch(typeof(JellyfishController), nameof(JellyfishController.OnSectorOccupantsUpdated))] - public static bool OnSectorOccupantsUpdated(JellyfishController __instance) - { - if (!WorldObjectManager.AllObjectsReady) - { - return true; - } - var qsbJellyfish = QSBWorldSync.GetWorldFromUnity(__instance); - - if (!__instance.gameObject.activeSelf && __instance._sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe | DynamicOccupant.Ship)) - { - __instance.gameObject.SetActive(true); - __instance._jellyfishBody.Unsuspend(); - qsbJellyfish.TransformSync.NetIdentity.FireAuthQueue(true); - return false; - } - if (__instance.gameObject.activeSelf && !__instance._sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe | DynamicOccupant.Ship)) - { - __instance._jellyfishBody.Suspend(); - __instance.gameObject.SetActive(false); - qsbJellyfish.TransformSync.NetIdentity.FireAuthQueue(false); - } - - return false; - } - [HarmonyPrefix] [HarmonyPatch(typeof(JellyfishController), nameof(JellyfishController.FixedUpdate))] public static bool FixedUpdate(JellyfishController __instance) diff --git a/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs b/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs index 6ec9d2e9..e3a3a6c9 100644 --- a/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs +++ b/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs @@ -36,6 +36,8 @@ namespace QSB.JellyfishSync.TransformSync { NetIdentity.UnregisterAuthQueue(); } + AttachedObject.OnUnsuspendOWRigidbody -= OnUnsuspend; + AttachedObject.OnSuspendOWRigidbody -= OnSuspend; } public override float GetNetworkSendInterval() => 10; @@ -52,10 +54,14 @@ namespace QSB.JellyfishSync.TransformSync { NetIdentity.RegisterAuthQueue(); } - // for when you host/connect mid-game + AttachedObject.OnUnsuspendOWRigidbody += OnUnsuspend; + AttachedObject.OnSuspendOWRigidbody += OnSuspend; NetIdentity.FireAuthQueue(!AttachedObject.IsSuspended()); } + private void OnUnsuspend(OWRigidbody suspendedBody) => NetIdentity.FireAuthQueue(true); + private void OnSuspend(OWRigidbody suspendedBody) => NetIdentity.FireAuthQueue(false); + public override void SerializeTransform(QNetworkWriter writer, bool initialState) { base.SerializeTransform(writer, initialState);