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