From f301af02f3a07593031d25c2b2524ab46f3309ca Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 5 Feb 2022 03:15:54 -0800 Subject: [PATCH] PlayerAttachWatcher --- QSB/Messaging/OWEvents.cs | 2 +- QSB/Player/PlayerAttachWatcher.cs | 24 ++++++++++++++++++++++++ QSB/ShipSync/ShipCustomAttach.cs | 5 +++-- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 QSB/Player/PlayerAttachWatcher.cs diff --git a/QSB/Messaging/OWEvents.cs b/QSB/Messaging/OWEvents.cs index db03aa85..68641e5a 100644 --- a/QSB/Messaging/OWEvents.cs +++ b/QSB/Messaging/OWEvents.cs @@ -2,7 +2,7 @@ { /// /// global messenger events built into outer wilds - /// that are also listened to with network messages. + /// that are also used by qsb. /// /// don't change unless they change in-game! /// diff --git a/QSB/Player/PlayerAttachWatcher.cs b/QSB/Player/PlayerAttachWatcher.cs new file mode 100644 index 00000000..7d8bd38f --- /dev/null +++ b/QSB/Player/PlayerAttachWatcher.cs @@ -0,0 +1,24 @@ +using HarmonyLib; +using QSB.Utility; +using UnityEngine; + +namespace QSB.Player +{ + [HarmonyPatch(typeof(PlayerAttachPoint))] + internal class PlayerAttachWatcher : MonoBehaviour, IAddComponentOnStart + { + private void Awake() + { + Harmony.CreateAndPatchAll(typeof(PlayerAttachWatcher)); + Destroy(this); + } + + public static PlayerAttachPoint Current { get; private set; } + + [HarmonyPatch(nameof(PlayerAttachPoint.AttachPlayer))] + private static void AttachPlayer(PlayerAttachPoint __instance) => Current = __instance; + + [HarmonyPatch(nameof(PlayerAttachPoint.DetachPlayer))] + private static void DetachPlayer() => Current = null; + } +} diff --git a/QSB/ShipSync/ShipCustomAttach.cs b/QSB/ShipSync/ShipCustomAttach.cs index 2b40df6c..36d7866f 100644 --- a/QSB/ShipSync/ShipCustomAttach.cs +++ b/QSB/ShipSync/ShipCustomAttach.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using QSB.Player; +using UnityEngine; namespace QSB.ShipSync { @@ -38,7 +39,7 @@ namespace QSB.ShipSync return; } - var attachedToUs = _playerAttachPoint.enabled; + var attachedToUs = PlayerAttachWatcher.Current == _playerAttachPoint; if (!attachedToUs) { if (PlayerState.IsAttached())