using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Photon.Pun;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Board Flight")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Board Flight")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("088bdbe1-e2f4-43bb-9b89-3fa225dca6ff")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.2.0.0")]
namespace WalkOnBoarding;
[BepInPlugin("tony4twenty.Walk_On_Boarding", "Walk On Boarding", "1.2.0")]
public class WalkOnBoardPlugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(AirportCheckInKiosk), "Start")]
private static class Patch_KioskStart
{
private static void Postfix(AirportCheckInKiosk __instance)
{
Instance?.OnAirportKioskReady(__instance);
}
}
[HarmonyPatch(typeof(CharacterSpawner), "SpawnSelfInAirport")]
private static class Patch_SpawnSelfInAirport
{
private static void Postfix()
{
Instance?.OnSpawnedInAirport();
}
}
[HarmonyPatch(typeof(AirportCheckInKiosk), "StartGame")]
private static class Patch_KioskStartGame
{
private static void Postfix()
{
Instance?.OnRunStarted();
}
}
[HarmonyPatch(typeof(AirportCheckInKiosk), "BeginIslandLoadRPC")]
private static class Patch_BeginIslandLoad
{
private static void Postfix()
{
Instance?.OnRunStarted();
}
}
private const string ZoneName = "WalkOnBoarding_Zone";
private const float MinTriggerHeight = 4f;
private readonly Vector3 endBoxMin = new Vector3(30f, 0f, 90f);
private readonly Vector3 endBoxMax = new Vector3(43f, 2f, 97f);
private static readonly Vector3 beginCornerA = new Vector3(2.3922f, 0.5546f, 107.3045f);
private static readonly Vector3 beginCornerB = new Vector3(22.0822f, 0.568f, 99.7617f);
private ConfigEntry<bool> useBeginningCfg;
private ConfigEntry<bool> removeKioskCfg;
private Harmony harmony;
private AirportCheckInKiosk armedKiosk;
private BoardingZone zone;
private bool gameStarted;
private bool triggeredBoarding;
internal static WalkOnBoardPlugin Instance { get; private set; }
internal bool IsArmed => (Object)(object)zone != (Object)null;
private void Awake()
{
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Expected O, but got Unknown
Instance = this;
useBeginningCfg = ((BaseUnityPlugin)this).Config.Bind<bool>("Trigger", "Use beginning of hallway?", false, "If true, uses beginning-of-hallway trigger box; otherwise uses end-of-hallway.");
useBeginningCfg.SettingChanged += delegate
{
if (IsArmed)
{
RebuildZone();
}
};
removeKioskCfg = ((BaseUnityPlugin)this).Config.Bind<bool>("Visuals", "Remove check-in kiosk?", true, "If true, hides the Airport check-in kiosk mesh and collider. Walk-in boarding still uses the real kiosk.");
removeKioskCfg.SettingChanged += delegate
{
if (IsArmed && removeKioskCfg.Value)
{
RemoveCheckInKioskVisuals();
}
};
harmony = new Harmony("tony4twenty.Walk_On_Boarding");
harmony.PatchAll(typeof(WalkOnBoardPlugin).Assembly);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Walk On Boarding idle. Arms from AirportCheckInKiosk / airport spawn only.");
}
internal void OnAirportKioskReady(AirportCheckInKiosk kiosk)
{
if ((Object)(object)kiosk == (Object)null)
{
return;
}
try
{
gameStarted = false;
triggeredBoarding = false;
ArmAirport(kiosk, ((Component)kiosk).gameObject);
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Failed to arm airport boarding: " + ex));
}
}
internal void OnSpawnedInAirport()
{
try
{
AirportCheckInKiosk val = (((Object)(object)armedKiosk != (Object)null) ? armedKiosk : Object.FindFirstObjectByType<AirportCheckInKiosk>());
GameObject layerSource = (((Object)(object)Character.localCharacter != (Object)null) ? ((Component)Character.localCharacter).gameObject : (((Object)(object)val != (Object)null) ? ((Component)val).gameObject : null));
ArmAirport(val, layerSource);
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Failed to arm after airport spawn: " + ex));
}
}
internal void OnRunStarted()
{
if (IsArmed || gameStarted)
{
gameStarted = true;
triggeredBoarding = true;
DestroyZone();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Run started. Walk On Boarding idle until the next Airport.");
}
}
internal void OnHostEnteredZone(Character character)
{
if (gameStarted || triggeredBoarding || !PhotonNetwork.IsMasterClient || (Object)(object)character == (Object)null || !((MonoBehaviourPun)character).photonView.IsMine)
{
return;
}
GUIManager instance = GUIManager.instance;
if (!((Object)(object)instance == (Object)null) && !((Object)(object)instance.boardingPass == (Object)null) && !((MenuWindow)instance.boardingPass).isOpen)
{
AirportCheckInKiosk val = (((Object)(object)armedKiosk != (Object)null) ? armedKiosk : Object.FindFirstObjectByType<AirportCheckInKiosk>());
if ((Object)(object)val == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"Host entered boarding zone, but AirportCheckInKiosk is missing.");
return;
}
triggeredBoarding = true;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Host entered boarding zone. Opening boarding pass.");
val.Interact_CastFinished(character);
}
}
internal void OnHostLeftZone()
{
if (!gameStarted)
{
triggeredBoarding = false;
}
}
internal void OnZoneDestroyed(BoardingZone destroyed)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)zone == (Object)(object)destroyed)
{
zone = null;
}
Scene activeScene = SceneManager.GetActiveScene();
if (((Scene)(ref activeScene)).name != "Airport")
{
armedKiosk = null;
gameStarted = false;
triggeredBoarding = false;
}
}
private void ArmAirport(AirportCheckInKiosk kiosk, GameObject layerSource)
{
if (!gameStarted)
{
if ((Object)(object)kiosk != (Object)null)
{
armedKiosk = kiosk;
}
RemoveSlidingDoors();
if (removeKioskCfg == null || removeKioskCfg.Value)
{
RemoveCheckInKioskVisuals();
}
if ((Object)(object)zone == (Object)null)
{
CreateZone(layerSource);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Airport ready. Boarding zone armed, otherwise idle.");
}
else if ((Object)(object)layerSource != (Object)null)
{
((Component)zone).gameObject.layer = layerSource.layer;
}
}
}
private void RebuildZone()
{
DestroyZone();
GameObject layerSource = (((Object)(object)Character.localCharacter != (Object)null) ? ((Component)Character.localCharacter).gameObject : (((Object)(object)armedKiosk != (Object)null) ? ((Component)armedKiosk).gameObject : null));
CreateZone(layerSource);
triggeredBoarding = false;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Boarding zone rebuilt from config.");
}
private void CreateZone(GameObject layerSource)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Expected O, but got Unknown
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
GetTriggerBounds(out var min, out var max);
Vector3 position = (min + max) * 0.5f;
Vector3 size = max - min;
GameObject val = new GameObject("WalkOnBoarding_Zone");
Scene val2 = (((Object)(object)armedKiosk != (Object)null) ? ((Component)armedKiosk).gameObject.scene : SceneManager.GetActiveScene());
if (((Scene)(ref val2)).IsValid())
{
SceneManager.MoveGameObjectToScene(val, val2);
}
val.transform.position = position;
if ((Object)(object)layerSource != (Object)null)
{
val.layer = layerSource.layer;
}
BoxCollider obj = val.AddComponent<BoxCollider>();
((Collider)obj).isTrigger = true;
obj.size = size;
Rigidbody obj2 = val.AddComponent<Rigidbody>();
obj2.isKinematic = true;
obj2.useGravity = false;
obj2.detectCollisions = true;
zone = val.AddComponent<BoardingZone>();
}
private void DestroyZone()
{
if (!((Object)(object)zone == (Object)null))
{
BoardingZone boardingZone = zone;
zone = null;
if ((Object)(object)boardingZone != (Object)null)
{
Object.Destroy((Object)(object)((Component)boardingZone).gameObject);
}
}
}
private void GetTriggerBounds(out Vector3 min, out Vector3 max)
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
if (useBeginningCfg != null && useBeginningCfg.Value)
{
min = Vector3.Min(beginCornerA, beginCornerB);
max = Vector3.Max(beginCornerA, beginCornerB);
}
else
{
min = endBoxMin;
max = endBoxMax;
}
if (max.y - min.y < 4f)
{
min.y = Mathf.Min(min.y, 0f);
max.y = min.y + 4f;
}
}
private void RemoveSlidingDoors()
{
Transform val = FindInActiveScene("Sliding Doors");
if ((Object)(object)val == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"Could not find 'Sliding Doors' in Airport.");
return;
}
((BaseUnityPlugin)this).Logger.LogInfo((object)"Found 'Sliding Doors'. Removing mesh and collider.");
Object.DestroyImmediate((Object)(object)((Component)val).GetComponent<MeshRenderer>());
Object.DestroyImmediate((Object)(object)((Component)val).GetComponent<MeshFilter>());
Object.DestroyImmediate((Object)(object)((Component)val).GetComponent<Collider>());
}
private void RemoveCheckInKioskVisuals()
{
Transform val = FindInActiveScene("AirportGateKiosk");
if ((Object)(object)val == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"Could not find 'AirportGateKiosk' in Airport.");
return;
}
((BaseUnityPlugin)this).Logger.LogInfo((object)"Found 'AirportGateKiosk'. Removing mesh and collider.");
Object.DestroyImmediate((Object)(object)((Component)val).GetComponent<MeshRenderer>());
Object.DestroyImmediate((Object)(object)((Component)val).GetComponent<MeshFilter>());
Object.DestroyImmediate((Object)(object)((Component)val).GetComponent<Collider>());
}
private static Transform FindInActiveScene(string name)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
Scene activeScene = SceneManager.GetActiveScene();
GameObject[] rootGameObjects = ((Scene)(ref activeScene)).GetRootGameObjects();
for (int i = 0; i < rootGameObjects.Length; i++)
{
Transform val = FindDeepChild(rootGameObjects[i].transform, name);
if ((Object)(object)val != (Object)null)
{
return val;
}
}
return null;
}
private static Transform FindDeepChild(Transform parent, string name)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Expected O, but got Unknown
foreach (Transform item in parent)
{
Transform val = item;
if (((Object)val).name == name)
{
return val;
}
Transform val2 = FindDeepChild(val, name);
if ((Object)(object)val2 != (Object)null)
{
return val2;
}
}
return null;
}
}
public class BoardingZone : MonoBehaviour
{
private void OnTriggerEnter(Collider other)
{
Character val = CharacterFrom(other);
if ((Object)(object)val != (Object)null)
{
WalkOnBoardPlugin.Instance?.OnHostEnteredZone(val);
}
}
private void OnTriggerExit(Collider other)
{
Character val = CharacterFrom(other);
if ((Object)(object)val != (Object)null && (Object)(object)((MonoBehaviourPun)val).photonView != (Object)null && ((MonoBehaviourPun)val).photonView.IsMine)
{
WalkOnBoardPlugin.Instance?.OnHostLeftZone();
}
}
private void OnDestroy()
{
WalkOnBoardPlugin.Instance?.OnZoneDestroyed(this);
}
private static Character CharacterFrom(Collider other)
{
if ((Object)(object)other == (Object)null)
{
return null;
}
Character componentInParent = ((Component)other).GetComponentInParent<Character>();
if (!((Object)(object)componentInParent != (Object)null))
{
return ((Component)other).GetComponent<Character>();
}
return componentInParent;
}
}