PlayerAttachWatcher

This commit is contained in:
JohnCorby 2022-02-05 03:15:54 -08:00
parent 4f3c359946
commit f301af02f3
3 changed files with 28 additions and 3 deletions

View File

@ -2,7 +2,7 @@
{
/// <summary>
/// global messenger events built into outer wilds
/// that are also listened to with network messages.
/// that are also used by qsb.
/// <para/>
/// don't change unless they change in-game!
/// </summary>

View File

@ -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;
}
}

View File

@ -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())