quantum-space-buddies/QSB/Player/PlayerAttachWatcher.cs

27 lines
743 B
C#
Raw Normal View History

2022-02-05 11:15:54 +00:00
using HarmonyLib;
using QSB.Utility;
using UnityEngine;
namespace QSB.Player
2022-02-05 11:15:54 +00:00
{
[HarmonyPatch(typeof(PlayerAttachPoint))]
internal class PlayerAttachWatcher : MonoBehaviour, IAddComponentOnStart
2022-02-05 11:15:54 +00:00
{
private void Awake()
{
Harmony.CreateAndPatchAll(typeof(PlayerAttachWatcher));
QSBSceneManager.OnSceneLoaded += (_, _, _) => Current = null;
Destroy(this);
}
2022-02-05 11:15:54 +00:00
public static PlayerAttachPoint Current { get; private set; }
2022-02-05 11:15:54 +00:00
[HarmonyPrefix]
[HarmonyPatch(nameof(PlayerAttachPoint.AttachPlayer))]
private static void AttachPlayer(PlayerAttachPoint __instance) => Current = __instance;
2022-02-05 11:15:54 +00:00
[HarmonyPrefix]
[HarmonyPatch(nameof(PlayerAttachPoint.DetachPlayer))]
private static void DetachPlayer() => Current = null;
}
}