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