Decompiled source of RespawnAtDeath v1.2.4

plugins/RespawnAtDeath.dll

Decompiled a day ago
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 HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("RespawnAtDeath.cs")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RespawnAtDeath.cs")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("aa85ea7d-d04a-4cc3-bfd3-47a13618fd5c")]
[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")]
[BepInPlugin("com.arathorv.RespawnAtDeath.Progressive", "RespawnAtDeath - Progressive", "1.2.4")]
public class ProgressiveDeathPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Player), "OnDeath")]
	public static class CaptureDeathLocationPatch
	{
		private static void Postfix(Player __instance)
		{
			//IL_0007: 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_0103: Unknown result type (might be due to invalid IL or missing references)
			lastDeathPosition = ((Component)__instance).transform.position;
			if (!isHurt && !isInjured && !isNearDeath && !deathRestarts)
			{
				isHurt = true;
				hurtUntil = DateTime.UtcNow.AddMinutes(5.0);
			}
			else if (isHurt)
			{
				isHurt = false;
				isInjured = true;
				injuredUntil = DateTime.UtcNow.AddMinutes(5.0);
			}
			else if (isInjured)
			{
				isInjured = false;
				isNearDeath = true;
				nearDeathUntil = DateTime.UtcNow.AddMinutes(5.0);
			}
			else if (isNearDeath)
			{
				deathRestarts = true;
			}
			_instance?.SaveState();
			ProgressiveDeathPlugin instance = _instance;
			if (instance != null)
			{
				((BaseUnityPlugin)instance).Logger.LogInfo((object)$"[ProgressiveRespawn] Death @ {lastDeathPosition} | H:{isHurt} I:{isInjured} N:{isNearDeath} D:{deathRestarts}");
			}
		}
	}

	[HarmonyPatch(typeof(Game), "SpawnPlayer")]
	public static class SpawnPlayerDelayGate
	{
		[CompilerGenerated]
		private sealed class <DelayedSpawnCo>d__1 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			private Game <game>5__1;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <DelayedSpawnCo>d__1(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<game>5__1 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(5f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					_allowImmediate = true;
					try
					{
						<game>5__1 = GetGameInstance();
						if ((Object)(object)<game>5__1 != (Object)null)
						{
							InvokeSpawnPlayer(<game>5__1);
						}
						<game>5__1 = null;
					}
					finally
					{
						_allowImmediate = false;
						_delayInProgress = false;
						IngameLoadingScreen.TryShow(on: false);
					}
					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();
			}
		}

		[HarmonyPrefix]
		[HarmonyPriority(800)]
		private static bool Prefix()
		{
			if (_allowImmediate)
			{
				return true;
			}
			if (_delayInProgress)
			{
				return false;
			}
			_delayInProgress = true;
			IngameLoadingScreen.TryShow(on: true);
			((MonoBehaviour)_instance).StartCoroutine(DelayedSpawnCo());
			return false;
		}

		[IteratorStateMachine(typeof(<DelayedSpawnCo>d__1))]
		private static IEnumerator DelayedSpawnCo()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DelayedSpawnCo>d__1(0);
		}
	}

	[HarmonyPatch(typeof(Game), "SpawnPlayer")]
	public static class OverrideSpawnLocationPatch
	{
		[HarmonyPrefix]
		[HarmonyPriority(400)]
		private static void Prefix(ref Vector3 spawnPoint)
		{
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			if (!_allowImmediate)
			{
				return;
			}
			_restoreBedAfterSpawn = false;
			queuedRespawnMessage = "";
			if (deathRestarts)
			{
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)localPlayer != (Object)null)
				{
					ReadBed(localPlayer, out _bedWasSet, out _bedSavedPoint);
					if (_bedWasSet)
					{
						SetBed(localPlayer, set: false, Vector3.zero);
						_restoreBedAfterSpawn = true;
						ProgressiveDeathPlugin instance = _instance;
						if (instance != null)
						{
							((BaseUnityPlugin)instance).Logger.LogInfo((object)"[ProgressiveRespawn] Dead: bed cleared for this respawn.");
						}
					}
				}
				isHurt = false;
				isInjured = false;
				isNearDeath = false;
				deathRestarts = false;
				ProgressiveDeathPlugin.lastDeathPosition = Vector3.zero;
				_instance?.SaveState();
			}
			else if ((isHurt || isInjured || isNearDeath) && ProgressiveDeathPlugin.lastDeathPosition != Vector3.zero)
			{
				Vector3 lastDeathPosition = ProgressiveDeathPlugin.lastDeathPosition;
				lastDeathPosition.y += 2f;
				Vector3 respawnPos = lastDeathPosition;
				RespawnHelper.WaitForAreaAndRespawn(lastDeathPosition, delegate(Vector3 pos)
				{
					//IL_0002: Unknown result type (might be due to invalid IL or missing references)
					//IL_0003: Unknown result type (might be due to invalid IL or missing references)
					respawnPos = pos;
				});
				spawnPoint = respawnPos;
				queuedRespawnMessage = (isNearDeath ? "Careful! You are near death." : (isInjured ? "You are injured." : "You feel hurt."));
				ProgressiveDeathPlugin instance2 = _instance;
				if (instance2 != null)
				{
					((BaseUnityPlugin)instance2).Logger.LogInfo((object)$"[ProgressiveRespawn] H/I/N spawn -> {spawnPoint}");
				}
			}
			else
			{
				isHurt = false;
				isInjured = false;
				isNearDeath = false;
				deathRestarts = false;
				ProgressiveDeathPlugin.lastDeathPosition = Vector3.zero;
				_instance?.SaveState();
			}
		}
	}

	[HarmonyPatch(typeof(Player), "OnSpawned")]
	public static class Player_OnSpawned_Post
	{
		[HarmonyPostfix]
		private static void Postfix(Player __instance)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			if (_restoreBedAfterSpawn)
			{
				SetBed(__instance, _bedWasSet, _bedSavedPoint);
				_restoreBedAfterSpawn = false;
				ProgressiveDeathPlugin instance = _instance;
				if (instance != null)
				{
					((BaseUnityPlugin)instance).Logger.LogInfo((object)"[ProgressiveRespawn] Bed restored after Dead respawn.");
				}
			}
			if (!string.IsNullOrEmpty(queuedRespawnMessage))
			{
				_instance.ShowCenterDelayed(queuedRespawnMessage);
				queuedRespawnMessage = "";
			}
		}
	}

	[CompilerGenerated]
	private sealed class <ShowCenterCo>d__30 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public string text;

		public ProgressiveDeathPlugin <>4__this;

		private Player <pl>5__1;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <ShowCenterCo>d__30(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<pl>5__1 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = (object)new WaitForEndOfFrame();
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				<>2__current = (object)new WaitForSeconds(0.15f);
				<>1__state = 2;
				return true;
			case 2:
				<>1__state = -1;
				<pl>5__1 = Player.m_localPlayer;
				if ((Object)(object)<pl>5__1 != (Object)null)
				{
					((Character)<pl>5__1).Message((MessageType)2, text, 0, (Sprite)null);
				}
				else if ((Object)(object)MessageHud.instance != (Object)null)
				{
					MessageHud.instance.ShowMessage((MessageType)2, text, 0, (Sprite)null, false);
				}
				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 static ProgressiveDeathPlugin _instance;

	private Harmony _harmony;

	private static Vector3 lastDeathPosition = Vector3.zero;

	private static bool isHurt = false;

	private static bool isInjured = false;

	private static bool isNearDeath = false;

	private static bool deathRestarts = false;

	private static DateTime hurtUntil = DateTime.MinValue;

	private static DateTime injuredUntil = DateTime.MinValue;

	private static DateTime nearDeathUntil = DateTime.MinValue;

	private const float SpawnDelaySeconds = 5f;

	private static bool _delayInProgress = false;

	private static bool _allowImmediate = false;

	private static bool _restoreBedAfterSpawn = false;

	private static bool _bedWasSet = false;

	private static Vector3 _bedSavedPoint = Vector3.zero;

	private static string queuedRespawnMessage = "";

	private void Awake()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		_instance = this;
		_harmony = new Harmony("com.arathorv.respawnatdeath.progressive");
		LoadState();
		_harmony.PatchAll(Assembly.GetExecutingAssembly());
		((BaseUnityPlugin)this).Logger.LogInfo((object)"[ProgressiveRespawn] Loaded (in-game loading screen 5s pre-respawn; H/I/N=death+2Y; Dead=vanilla with temp bed clear).");
	}

	private void OnDestroy()
	{
		try
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
		catch
		{
		}
	}

	private void Update()
	{
		if (isNearDeath && DateTime.UtcNow > nearDeathUntil)
		{
			isNearDeath = false;
			isInjured = true;
			injuredUntil = DateTime.UtcNow.AddMinutes(5.0);
			ShowCenterDelayed("You recover a little and are just injured now.");
		}
		else if (isInjured && DateTime.UtcNow > injuredUntil)
		{
			isInjured = false;
			isHurt = true;
			hurtUntil = DateTime.UtcNow.AddMinutes(5.0);
			ShowCenterDelayed("You recover a little and are only hurt now.");
		}
		else if (isHurt && DateTime.UtcNow > hurtUntil)
		{
			isHurt = false;
			ShowCenterDelayed("You feel recovered.");
		}
		SaveState();
	}

	private void OnApplicationQuit()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		lastDeathPosition = Vector3.zero;
		SaveState();
	}

	private static void ReadBed(Player p, out bool set, out Vector3 point)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		set = false;
		point = Vector3.zero;
		try
		{
			Type typeFromHandle = typeof(Player);
			FieldInfo field = typeFromHandle.GetField("m_customSpawnPointSet", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field2 = typeFromHandle.GetField("m_customSpawnPoint", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field != null)
			{
				set = (bool)field.GetValue(p);
			}
			if (field2 != null)
			{
				point = (Vector3)field2.GetValue(p);
			}
		}
		catch
		{
		}
	}

	private static void SetBed(Player p, bool set, Vector3 point)
	{
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			Type typeFromHandle = typeof(Player);
			FieldInfo field = typeFromHandle.GetField("m_customSpawnPointSet", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field2 = typeFromHandle.GetField("m_customSpawnPoint", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field != null)
			{
				field.SetValue(p, set);
			}
			if (field2 != null)
			{
				field2.SetValue(p, point);
			}
		}
		catch
		{
		}
	}

	private static Game GetGameInstance()
	{
		object? obj = typeof(Game).GetProperty("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(null);
		Game val = (Game)((obj is Game) ? obj : null);
		if (val != null)
		{
			return val;
		}
		object? obj2 = typeof(Game).GetField("m_instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(null);
		Game val2 = (Game)((obj2 is Game) ? obj2 : null);
		if (val2 != null)
		{
			return val2;
		}
		return Object.FindObjectOfType<Game>();
	}

	private static void InvokeSpawnPlayer(Game game)
	{
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		MethodInfo methodInfo = AccessTools.Method(typeof(Game), "SpawnPlayer", (Type[])null, (Type[])null);
		if (methodInfo == null)
		{
			ProgressiveDeathPlugin instance = _instance;
			if (instance != null)
			{
				((BaseUnityPlugin)instance).Logger.LogWarning((object)"[ProgressiveRespawn] Could not find Game.SpawnPlayer via reflection.");
			}
			return;
		}
		ParameterInfo[] parameters = methodInfo.GetParameters();
		try
		{
			if (parameters.Length == 0)
			{
				methodInfo.Invoke(game, null);
				return;
			}
			object[] array = new object[parameters.Length];
			for (int i = 0; i < parameters.Length; i++)
			{
				ParameterInfo parameterInfo = parameters[i];
				Type parameterType = parameterInfo.ParameterType;
				if (parameterType == typeof(Vector3) || parameterType == typeof(Vector3).MakeByRefType())
				{
					array[i] = Vector3.zero;
				}
				else if (parameterInfo.HasDefaultValue)
				{
					array[i] = parameterInfo.DefaultValue;
				}
				else
				{
					array[i] = (parameterType.IsValueType ? Activator.CreateInstance(parameterType) : null);
				}
			}
			methodInfo.Invoke(game, array);
		}
		catch (Exception ex)
		{
			ProgressiveDeathPlugin instance2 = _instance;
			if (instance2 != null)
			{
				((BaseUnityPlugin)instance2).Logger.LogError((object)("[ProgressiveRespawn] InvokeSpawnPlayer failed: " + ex));
			}
		}
	}

	private void ShowCenterDelayed(string text)
	{
		((MonoBehaviour)this).StartCoroutine(ShowCenterCo(text));
	}

	[IteratorStateMachine(typeof(<ShowCenterCo>d__30))]
	private IEnumerator ShowCenterCo(string text)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <ShowCenterCo>d__30(0)
		{
			<>4__this = this,
			text = text
		};
	}

	private void SaveState()
	{
		PlayerPrefs.SetInt("RespawnAtDeath_isHurt", isHurt ? 1 : 0);
		PlayerPrefs.SetInt("RespawnAtDeath_isInjured", isInjured ? 1 : 0);
		PlayerPrefs.SetInt("RespawnAtDeath_isNearDeath", isNearDeath ? 1 : 0);
		PlayerPrefs.SetInt("RespawnAtDeath_deathRestarts", deathRestarts ? 1 : 0);
		PlayerPrefs.SetString("RespawnAtDeath_hurtUntil", hurtUntil.ToBinary().ToString());
		PlayerPrefs.SetString("RespawnAtDeath_injuredUntil", injuredUntil.ToBinary().ToString());
		PlayerPrefs.SetString("RespawnAtDeath_nearDeathUntil", nearDeathUntil.ToBinary().ToString());
		PlayerPrefs.Save();
	}

	private void LoadState()
	{
		isHurt = PlayerPrefs.GetInt("RespawnAtDeath_isHurt", 0) == 1;
		isInjured = PlayerPrefs.GetInt("RespawnAtDeath_isInjured", 0) == 1;
		isNearDeath = PlayerPrefs.GetInt("RespawnAtDeath_isNearDeath", 0) == 1;
		deathRestarts = PlayerPrefs.GetInt("RespawnAtDeath_deathRestarts", 0) == 1;
		if (long.TryParse(PlayerPrefs.GetString("RespawnAtDeath_hurtUntil", "0"), out var result))
		{
			hurtUntil = DateTime.FromBinary(result);
		}
		else
		{
			hurtUntil = DateTime.MinValue;
		}
		if (long.TryParse(PlayerPrefs.GetString("RespawnAtDeath_injuredUntil", "0"), out var result2))
		{
			injuredUntil = DateTime.FromBinary(result2);
		}
		else
		{
			injuredUntil = DateTime.MinValue;
		}
		if (long.TryParse(PlayerPrefs.GetString("RespawnAtDeath_nearDeathUntil", "0"), out var result3))
		{
			nearDeathUntil = DateTime.FromBinary(result3);
		}
		else
		{
			nearDeathUntil = DateTime.MinValue;
		}
	}
}
internal static class IngameLoadingScreen
{
	public static void TryShow(bool on)
	{
		try
		{
			Object obj = Object.FindObjectOfType(typeof(FejdStartup));
			MonoBehaviour val = (MonoBehaviour)(object)((obj is MonoBehaviour) ? obj : null);
			if ((Object)(object)val != (Object)null)
			{
				Type type = ((object)val).GetType();
				object? obj2 = type.GetField("m_loading", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(val);
				GameObject val2 = (GameObject)((obj2 is GameObject) ? obj2 : null);
				if (val2 != null)
				{
					val2.SetActive(on);
					return;
				}
				object? obj3 = type.GetField("m_loadingScreen", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(val);
				GameObject val3 = (GameObject)((obj3 is GameObject) ? obj3 : null);
				if (val3 != null)
				{
					val3.SetActive(on);
					return;
				}
			}
			Game gameInstance = GetGameInstance();
			if ((Object)(object)gameInstance != (Object)null)
			{
				Type type2 = ((object)gameInstance).GetType();
				object? obj4 = type2.GetField("m_loadingScreen", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(gameInstance);
				GameObject val4 = (GameObject)((obj4 is GameObject) ? obj4 : null);
				if (val4 != null)
				{
					val4.SetActive(on);
				}
			}
		}
		catch
		{
		}
	}

	private static Game GetGameInstance()
	{
		object? obj = typeof(Game).GetProperty("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(null);
		Game val = (Game)((obj is Game) ? obj : null);
		if (val != null)
		{
			return val;
		}
		object? obj2 = typeof(Game).GetField("m_instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(null);
		Game val2 = (Game)((obj2 is Game) ? obj2 : null);
		if (val2 != null)
		{
			return val2;
		}
		return Object.FindObjectOfType<Game>();
	}
}
public class RespawnHelper : MonoBehaviour
{
	[CompilerGenerated]
	private sealed class <WaitForAreaCoroutine>d__1 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public Vector3 position;

		public Action<Vector3> onReady;

		public RespawnHelper <>4__this;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <WaitForAreaCoroutine>d__1(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				break;
			case 1:
				<>1__state = -1;
				break;
			}
			if ((Object)(object)ZNetScene.instance != (Object)null && !ZNetScene.instance.IsAreaReady(position))
			{
				<>2__current = (object)new WaitForSeconds(0.1f);
				<>1__state = 1;
				return true;
			}
			onReady?.Invoke(position);
			Object.Destroy((Object)(object)((Component)<>4__this).gameObject);
			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();
		}
	}

	public static void WaitForAreaAndRespawn(Vector3 position, Action<Vector3> onReady)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("RespawnHelper");
		RespawnHelper respawnHelper = val.AddComponent<RespawnHelper>();
		((MonoBehaviour)respawnHelper).StartCoroutine(respawnHelper.WaitForAreaCoroutine(position, onReady));
	}

	[IteratorStateMachine(typeof(<WaitForAreaCoroutine>d__1))]
	private IEnumerator WaitForAreaCoroutine(Vector3 position, Action<Vector3> onReady)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <WaitForAreaCoroutine>d__1(0)
		{
			<>4__this = this,
			position = position,
			onReady = onReady
		};
	}
}