2022-02-05 11:15:54 +00:00
|
|
|
|
using HarmonyLib;
|
2022-03-11 10:26:58 +00:00
|
|
|
|
using QSB.Patches;
|
2022-02-05 11:15:54 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
namespace QSB.Player;
|
|
|
|
|
|
|
|
|
|
[HarmonyPatch(typeof(PlayerAttachPoint))]
|
2022-03-11 10:26:58 +00:00
|
|
|
|
internal class PlayerAttachWatcher : QSBPatch
|
2022-02-05 11:15:54 +00:00
|
|
|
|
{
|
2022-03-11 10:26:58 +00:00
|
|
|
|
public override QSBPatchTypes Type => QSBPatchTypes.OnModStart;
|
2022-02-05 11:15:54 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public static PlayerAttachPoint Current { get; private set; }
|
2022-02-05 11:15:54 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
[HarmonyPrefix]
|
|
|
|
|
[HarmonyPatch(nameof(PlayerAttachPoint.AttachPlayer))]
|
|
|
|
|
private static void AttachPlayer(PlayerAttachPoint __instance)
|
|
|
|
|
{
|
|
|
|
|
if (Current != null)
|
2022-02-27 15:19:57 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
Current.DetachPlayer();
|
2022-02-27 15:19:57 +00:00
|
|
|
|
}
|
2022-02-05 11:15:54 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
Current = __instance;
|
|
|
|
|
}
|
2022-02-27 15:19:57 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
[HarmonyPrefix]
|
|
|
|
|
[HarmonyPatch(nameof(PlayerAttachPoint.DetachPlayer))]
|
|
|
|
|
private static void DetachPlayer(PlayerAttachPoint __instance)
|
|
|
|
|
{
|
|
|
|
|
if (!__instance.enabled)
|
|
|
|
|
{
|
|
|
|
|
return;
|
2022-02-27 15:19:57 +00:00
|
|
|
|
}
|
2022-03-03 03:46:33 +00:00
|
|
|
|
|
|
|
|
|
Current = null;
|
2022-02-27 12:40:44 +00:00
|
|
|
|
}
|
2022-03-03 03:46:33 +00:00
|
|
|
|
}
|