using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Photon.Pun;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Plane Crash Passports")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Plane Crash Passports")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("80764f1f-06de-42bb-8278-6e60e646e4f3")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PlaneCrashPassports;
[BepInPlugin("tony4twentys.Plane_Crash_Passports", "Plane Crash Passports", "1.0.0")]
public class PlaneCrashPassportsPlugin : BaseUnityPlugin
{
[CompilerGenerated]
private sealed class <DelayedPassportSpawn>d__9 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public PlaneCrashPassportsPlugin <>4__this;
private Character <localChar>5__1;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <DelayedPassportSpawn>d__9(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<localChar>5__1 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(<>4__this.passportDelaySeconds.Value);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)"[PlaneCrashPassports] Delay complete. Giving passport to local player.");
<localChar>5__1 = Character.localCharacter;
if ((Object)(object)<localChar>5__1 != (Object)null && (Object)(object)((MonoBehaviourPun)<localChar>5__1).photonView != (Object)null)
{
<>4__this.GivePassport(<localChar>5__1);
}
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
private bool playerSpawned = false;
private bool passportSpawnStarted = false;
private bool isInAirport = false;
private bool dropEnabled = false;
private ConfigEntry<float> passportDelaySeconds;
private void Awake()
{
passportDelaySeconds = ((BaseUnityPlugin)this).Config.Bind<float>("General", "PassportSpawnDelay", 5f, "Time in seconds to wait after player spawn before giving passports.");
SceneManager.sceneLoaded += OnSceneLoaded;
}
private void OnDestroy()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
passportSpawnStarted = false;
playerSpawned = false;
((BaseUnityPlugin)this).Logger.LogInfo((object)("[PlaneCrashPassports] Scene changed to " + ((Scene)(ref scene)).name + ", reset spawn flags."));
}
private void Update()
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
if (!PhotonNetwork.InRoom)
{
return;
}
Scene activeScene = SceneManager.GetActiveScene();
string name = ((Scene)(ref activeScene)).name;
isInAirport = name == "Airport";
if (!dropEnabled)
{
EnablePassportDropping();
dropEnabled = true;
}
if (!isInAirport && !passportSpawnStarted)
{
Character localCharacter = Character.localCharacter;
if ((Object)(object)localCharacter != (Object)null && (Object)(object)((MonoBehaviourPun)localCharacter).photonView != (Object)null && ((MonoBehaviourPun)localCharacter).photonView.IsMine)
{
playerSpawned = true;
passportSpawnStarted = true;
((BaseUnityPlugin)this).Logger.LogInfo((object)"[PlaneCrashPassports] Local player spawned and not in Airport. Starting delayed coroutine for passport.");
((MonoBehaviour)this).StartCoroutine(DelayedPassportSpawn());
}
}
}
[IteratorStateMachine(typeof(<DelayedPassportSpawn>d__9))]
private IEnumerator DelayedPassportSpawn()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <DelayedPassportSpawn>d__9(0)
{
<>4__this = this
};
}
private void GivePassport(Character character)
{
if (character.refs == null || (Object)(object)character.refs.items == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("[PlaneCrashPassports] " + character.characterName + " has no item references."));
return;
}
CharacterItems items = character.refs.items;
MethodInfo method = ((object)items).GetType().GetMethod("SpawnItemInHand", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (method == null)
{
((BaseUnityPlugin)this).Logger.LogError((object)"[PlaneCrashPassports] SpawnItemInHand method not found via reflection.");
return;
}
method.Invoke(items, new object[1] { "passport" });
((BaseUnityPlugin)this).Logger.LogInfo((object)("[PlaneCrashPassports] Spawned passport in hand for " + character.characterName));
}
private void EnablePassportDropping()
{
GameObject[] array = Resources.FindObjectsOfTypeAll<GameObject>();
GameObject[] array2 = array;
foreach (GameObject val in array2)
{
if (((Object)val).name == "Passport")
{
Item component = val.GetComponent<Item>();
if ((Object)(object)component != (Object)null && component.UIData != null)
{
component.UIData.canDrop = true;
component.UIData.canThrow = true;
((BaseUnityPlugin)this).Logger.LogInfo((object)"[PlaneCrashPassports] Passport can now be dropped and thrown.");
}
}
}
}
}