Decompiled source of GymMaps v1.5.2

GymMaps.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using GymMaps;
using HarmonyLib;
using Il2Cpp;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppRUMBLE.Audio;
using Il2CppRUMBLE.Economy.Interactables;
using Il2CppRUMBLE.Interactions.InteractionBase;
using Il2CppRUMBLE.Managers;
using Il2CppRUMBLE.MoveSystem;
using Il2CppRUMBLE.Players;
using Il2CppRUMBLE.Players.Subsystems;
using Il2CppRUMBLE.Pools;
using Il2CppRUMBLE.Social.Phone;
using Il2CppRUMBLE.Utilities;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using RumbleModdingAPI.RMAPI;
using UIFramework;
using UIFramework.Models;
using UIFramework.UiExtensions;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: MelonInfo(typeof(Mod), "GymMaps", "1.5.0", "Colli", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: MelonAdditionalDependencies(new string[] { "UIFramework", "RumbleModdingAPI" })]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : System.Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(/*Could not decode attribute arguments.*/)]
	internal sealed class RefSafetyRulesAttribute : System.Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace GymMaps
{
	internal static class AssetButtons
	{
		private sealed class OwnedButton
		{
			internal GameObject Object;

			internal UnityAction Callback;
		}

		[CompilerGenerated]
		private sealed class <LoadMap>d__7 : System.Collections.Generic.IEnumerator<object>, System.IDisposable, System.Collections.IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public GameObject source;

			public string mapName;

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

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

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

			[DebuggerHidden]
			void System.IDisposable.Dispose()
			{
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					try
					{
						if (Runtime.GameplayAllowed && MapCommands.Enabled && Object.op_Implicit((Object)(object)source) && source.activeInHierarchy && !Runtime.IsBusy)
						{
							Runtime.Request(mapName, append: false, teleport: true);
						}
					}
					catch (System.Exception ex)
					{
						MelonLogger.Warning("[MapButton] " + ex.Message);
						Runtime.ReportTrigger("Map button failed: " + ex.Message);
					}
					finally
					{
						returning = false;
					}
					return false;
				}
			}

			bool System.Collections.IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void System.Collections.IEnumerator.Reset()
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <ReturnGym>d__9 : System.Collections.Generic.IEnumerator<object>, System.IDisposable, System.Collections.IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public GameObject source;

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

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

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

			[DebuggerHidden]
			void System.IDisposable.Dispose()
			{
			}

			private bool MoveNext()
			{
				//IL_0064: Unknown result type (might be due to invalid IL or missing references)
				//IL_0069: Unknown result type (might be due to invalid IL or missing references)
				//IL_0083: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
				//IL_010e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0116: Unknown result type (might be due to invalid IL or missing references)
				//IL_011b: Unknown result type (might be due to invalid IL or missing references)
				//IL_011f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0124: Unknown result type (might be due to invalid IL or missing references)
				//IL_0128: Unknown result type (might be due to invalid IL or missing references)
				//IL_012d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0142: Unknown result type (might be due to invalid IL or missing references)
				//IL_0144: Unknown result type (might be due to invalid IL or missing references)
				//IL_0151: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					try
					{
						if (!Runtime.GameplayAllowed || !MapCommands.Enabled || !Object.op_Implicit((Object)(object)source) || !source.activeInHierarchy || Runtime.IsBusy)
						{
							return false;
						}
						Scene activeScene = SceneManager.GetActiveScene();
						if (((Scene)(ref activeScene)).name != "Gym")
						{
							throw new InvalidOperationException("Gym teleport buttons are available on Gym custom maps.");
						}
						PlayerManager instance = Singleton<PlayerManager>.instance;
						object obj;
						if (instance == null)
						{
							obj = null;
						}
						else
						{
							Player localPlayer = instance.localPlayer;
							obj = ((localPlayer != null) ? localPlayer.Controller : null);
						}
						PlayerController val = (PlayerController)obj;
						SpawnPointHandler val2 = ((instance != null) ? instance.activeSpawnPointHandler : null);
						if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2))
						{
							throw new InvalidOperationException("Gym player or spawn-point handler unavailable.");
						}
						PlayerMovement componentInChildren = ((Component)val).GetComponentInChildren<PlayerMovement>(true);
						PlayerPhysics componentInChildren2 = ((Component)val).GetComponentInChildren<PlayerPhysics>(true);
						if (!Object.op_Implicit((Object)(object)componentInChildren))
						{
							throw new InvalidOperationException("Player movement subsystem unavailable.");
						}
						bool flag = default(bool);
						SpawnPoint desiredSpawnPoint = val2.GetDesiredSpawnPoint((SpawnPointType)0, ref flag);
						if (!flag || desiredSpawnPoint == null)
						{
							throw new InvalidOperationException("Gym startup spawn point unavailable.");
						}
						Vector3 position = desiredSpawnPoint.Position;
						Quaternion rotation = desiredSpawnPoint.Rotation;
						Features activeFeatures = componentInChildren.ActiveFeatures;
						if (Object.op_Implicit((Object)(object)componentInChildren2))
						{
							componentInChildren2.ClearAllVelocities((RigidbodyTarget)2);
						}
						componentInChildren.RepositionWithFade(position, rotation, 0.25f, 0.1f, true, activeFeatures, true);
						Runtime.Unload();
						Runtime.ReportTrigger("Returned to the Gym start.");
					}
					catch (System.Exception ex)
					{
						MelonLogger.Warning("[GymButton] " + ex.Message);
						Runtime.ReportTrigger("Gym teleport failed: " + ex.Message);
					}
					finally
					{
						returning = false;
					}
					return false;
				}
			}

			bool System.Collections.IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void System.Collections.IEnumerator.Reset()
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				throw new NotSupportedException();
			}
		}

		private static readonly List<OwnedButton> owned = new List<OwnedButton>();

		private static bool returning;

		internal static void SpawnGym(GameObject marker)
		{
			Spawn(marker, "TeleportGym", RequestGym);
		}

		internal static void SpawnMap(GameObject marker, string mapName)
		{
			Spawn(marker, "TeleportMap." + mapName, delegate(GameObject source)
			{
				RequestMap(source, mapName);
			});
		}

		private static void Spawn(GameObject marker, string purpose, Action<GameObject> pressed)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Expected O, but got Unknown
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Expected O, but got Unknown
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)Create.newButtonGameObject))
			{
				throw new InvalidOperationException("RumbleModdingAPI's native button asset is not ready.");
			}
			GameObject clone = Object.Instantiate<GameObject>(Create.newButtonGameObject);
			try
			{
				clone.SetActive(false);
				((Object)clone).name = "GymMaps.Button." + purpose + "." + ((Object)marker).name;
				clone.transform.SetParent(marker.transform.parent, false);
				clone.transform.SetPositionAndRotation(marker.transform.position, marker.transform.rotation);
				InteractionButton componentInChildren = clone.GetComponentInChildren<InteractionButton>(true);
				if (!Object.op_Implicit((Object)(object)componentInChildren))
				{
					throw new InvalidOperationException("Native button asset has no InteractionButton.");
				}
				componentInChildren.onPressed = new UnityEvent();
				componentInChildren.onPressedByPlayer = new UnityEvent<Player>();
				componentInChildren.onToggledByPlayerController = new UnityEvent<bool, PlayerController>();
				componentInChildren.isToggleButton = false;
				componentInChildren.useLongPress = false;
				componentInChildren.disableButtonAfterInit = false;
				componentInChildren.pressInterval = 0.75f;
				((Behaviour)componentInChildren).enabled = true;
				UnityAction val = UnityAction.op_Implicit((Action)delegate
				{
					if (Runtime.GameplayAllowed && MapCommands.Enabled)
					{
						pressed.Invoke(clone);
					}
				});
				componentInChildren.onPressed.AddListener(val);
				OwnedButton ownedButton = new OwnedButton
				{
					Object = clone,
					Callback = val
				};
				owned.Add(ownedButton);
				clone.SetActive(true);
				MelonLogger.Msg("[MapLoad] Spawned " + purpose + " button at " + ((Object)marker).name);
			}
			catch
			{
				if (Object.op_Implicit((Object)(object)clone))
				{
					Object.Destroy((Object)(object)clone);
				}
				throw;
			}
		}

		private static void RequestMap(GameObject source, string mapName)
		{
			if (!returning && !Runtime.IsBusy && Object.op_Implicit((Object)(object)source) && source.activeInHierarchy)
			{
				returning = true;
				MelonCoroutines.Start(LoadMap(source, mapName));
			}
		}

		[IteratorStateMachine(typeof(<LoadMap>d__7))]
		private static System.Collections.IEnumerator LoadMap(GameObject source, string mapName)
		{
			yield return null;
			try
			{
				if (Runtime.GameplayAllowed && MapCommands.Enabled && Object.op_Implicit((Object)(object)source) && source.activeInHierarchy && !Runtime.IsBusy)
				{
					Runtime.Request(mapName, append: false, teleport: true);
				}
			}
			catch (System.Exception ex)
			{
				MelonLogger.Warning("[MapButton] " + ex.Message);
				Runtime.ReportTrigger("Map button failed: " + ex.Message);
			}
			finally
			{
				returning = false;
			}
		}

		private static void RequestGym(GameObject source)
		{
			if (!returning && !Runtime.IsBusy && Object.op_Implicit((Object)(object)source) && source.activeInHierarchy)
			{
				returning = true;
				MelonCoroutines.Start(ReturnGym(source));
			}
		}

		[IteratorStateMachine(typeof(<ReturnGym>d__9))]
		private static System.Collections.IEnumerator ReturnGym(GameObject source)
		{
			yield return null;
			try
			{
				if (Runtime.GameplayAllowed && MapCommands.Enabled && Object.op_Implicit((Object)(object)source) && source.activeInHierarchy && !Runtime.IsBusy)
				{
					Scene activeScene = SceneManager.GetActiveScene();
					if (((Scene)(ref activeScene)).name != "Gym")
					{
						throw new InvalidOperationException("Gym teleport buttons are available on Gym custom maps.");
					}
					PlayerManager instance = Singleton<PlayerManager>.instance;
					object obj;
					if (instance == null)
					{
						obj = null;
					}
					else
					{
						Player localPlayer = instance.localPlayer;
						obj = ((localPlayer != null) ? localPlayer.Controller : null);
					}
					PlayerController val = (PlayerController)obj;
					SpawnPointHandler val2 = ((instance != null) ? instance.activeSpawnPointHandler : null);
					if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2))
					{
						throw new InvalidOperationException("Gym player or spawn-point handler unavailable.");
					}
					PlayerMovement componentInChildren = ((Component)val).GetComponentInChildren<PlayerMovement>(true);
					PlayerPhysics componentInChildren2 = ((Component)val).GetComponentInChildren<PlayerPhysics>(true);
					if (!Object.op_Implicit((Object)(object)componentInChildren))
					{
						throw new InvalidOperationException("Player movement subsystem unavailable.");
					}
					bool flag = default(bool);
					SpawnPoint desiredSpawnPoint = val2.GetDesiredSpawnPoint((SpawnPointType)0, ref flag);
					if (!flag || desiredSpawnPoint == null)
					{
						throw new InvalidOperationException("Gym startup spawn point unavailable.");
					}
					Vector3 position = desiredSpawnPoint.Position;
					Quaternion rotation = desiredSpawnPoint.Rotation;
					Features activeFeatures = componentInChildren.ActiveFeatures;
					if (Object.op_Implicit((Object)(object)componentInChildren2))
					{
						componentInChildren2.ClearAllVelocities((RigidbodyTarget)2);
					}
					componentInChildren.RepositionWithFade(position, rotation, 0.25f, 0.1f, true, activeFeatures, true);
					Runtime.Unload();
					Runtime.ReportTrigger("Returned to the Gym start.");
				}
			}
			catch (System.Exception ex)
			{
				MelonLogger.Warning("[GymButton] " + ex.Message);
				Runtime.ReportTrigger("Gym teleport failed: " + ex.Message);
			}
			finally
			{
				returning = false;
			}
		}

		internal static void Clear()
		{
			//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)
			Enumerator<OwnedButton> enumerator = owned.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					OwnedButton current = enumerator.Current;
					if (Object.op_Implicit((Object)(object)current.Object))
					{
						current.Object.SetActive(false);
						Object.Destroy((Object)(object)current.Object);
					}
				}
			}
			finally
			{
				((System.IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
			}
			owned.Clear();
		}
	}
	internal static class DeathSurfaces
	{
		private static float nextReset;

		internal static bool Handle(KillPlayerOnCollision surface, Transform contact)
		{
			if (!Object.op_Implicit((Object)(object)surface) || (!Runtime.OwnsMapObject(((Component)surface).gameObject) && !MapTools.ControlsDeathSurface(surface)))
			{
				return false;
			}
			PlayerManager instance = Singleton<PlayerManager>.instance;
			object obj;
			if (instance == null)
			{
				obj = null;
			}
			else
			{
				Player localPlayer = instance.localPlayer;
				obj = ((localPlayer != null) ? localPlayer.Controller : null);
			}
			PlayerController val = (PlayerController)obj;
			if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)contact) && contact.IsChildOf(((Component)val).transform))
			{
				ResetLocal();
			}
			return true;
		}

		internal static void ResetLocal()
		{
			//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();
			if (!(((Scene)(ref activeScene)).name != "Gym") && !Runtime.IsBusy && !(Time.realtimeSinceStartup < nextReset))
			{
				PlayerManager instance = Singleton<PlayerManager>.instance;
				object obj;
				if (instance == null)
				{
					obj = null;
				}
				else
				{
					Player localPlayer = instance.localPlayer;
					obj = ((localPlayer != null) ? localPlayer.Controller : null);
				}
				PlayerController val = (PlayerController)obj;
				PlayerResetSystem val2 = (Object.op_Implicit((Object)(object)val) ? ((Component)val).GetComponentInChildren<PlayerResetSystem>(true) : null);
				if (Object.op_Implicit((Object)(object)val2) && val2.currentResetRoutine == null)
				{
					nextReset = Time.realtimeSinceStartup + 1.25f;
					MelonLogger.Msg("[KillFloor] Local player reached a death surface; native reset requested.");
					val2.ResetPlayerController();
				}
			}
		}
	}
	[HarmonyPatch(typeof(KillPlayerOnCollision), "AttemptKillPlayer")]
	internal static class MapDeathSurfacePatch
	{
		private static bool Prefix(KillPlayerOnCollision __instance, Transform tr)
		{
			return !DeathSurfaces.Handle(__instance, tr);
		}
	}
	internal static class DefaultMaps
	{
		private const string Prefix = "GymMaps.DefaultMaps.";

		internal static void AddMissing(string directory)
		{
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Expected O, but got Unknown
			Directory.CreateDirectory(directory);
			string text = Path.Combine(directory, ".default-maps-installed");
			if (File.Exists(text))
			{
				return;
			}
			Assembly assembly = typeof(DefaultMaps).Assembly;
			int num = 0;
			bool flag = true;
			System.Collections.Generic.IEnumerator<string> enumerator = ((System.Collections.Generic.IEnumerable<string>)Enumerable.OrderBy<string, string>(Enumerable.Where<string>((System.Collections.Generic.IEnumerable<string>)assembly.GetManifestResourceNames(), (Func<string, bool>)((string name) => name.StartsWith("GymMaps.DefaultMaps.", (StringComparison)4) && name.EndsWith(".txt", (StringComparison)5))), (Func<string, string>)((string name) => name), (IComparer<string>)(object)StringComparer.OrdinalIgnoreCase)).GetEnumerator();
			try
			{
				while (((System.Collections.IEnumerator)enumerator).MoveNext())
				{
					string current = enumerator.Current;
					string text2 = current.Substring("GymMaps.DefaultMaps.".Length);
					string text3 = null;
					try
					{
						if (text2.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0 || !Path.GetFileName(text2).Equals(text2, (StringComparison)4))
						{
							throw new InvalidDataException("Invalid bundled map filename.");
						}
						string text4 = Path.Combine(directory, text2);
						if (File.Exists(text4))
						{
							continue;
						}
						Guid val = Guid.NewGuid();
						text3 = Path.Combine(directory, ".GymMaps-" + ((Guid)(ref val)).ToString("N") + ".tmp");
						Stream val2 = assembly.GetManifestResourceStream(current) ?? throw new InvalidDataException("Bundled map resource unavailable.");
						try
						{
							FileStream val3 = new FileStream(text3, (FileMode)1, (FileAccess)2, (FileShare)0);
							try
							{
								val2.CopyTo((Stream)(object)val3);
							}
							finally
							{
								((System.IDisposable)val3)?.Dispose();
							}
						}
						finally
						{
							((System.IDisposable)val2)?.Dispose();
						}
						MapFile.Read(text3);
						try
						{
							File.Move(text3, text4);
							num++;
						}
						catch (object obj) when (obj is IOException && File.Exists(text4))
						{
						}
					}
					catch (System.Exception ex)
					{
						flag = false;
						MelonLogger.Warning("[GymMaps] Could not add default map " + text2 + ": " + ex.Message);
					}
					finally
					{
						if (text3 != null)
						{
							try
							{
								File.Delete(text3);
							}
							catch (System.Exception ex2)
							{
								MelonLogger.Warning("[GymMaps] Temporary map cleanup: " + ex2.Message);
							}
						}
					}
				}
			}
			finally
			{
				((System.IDisposable)enumerator)?.Dispose();
			}
			if (num > 0)
			{
				MelonLogger.Msg("[GymMaps] Added " + num + " bundled default maps to " + directory);
			}
			if (flag)
			{
				File.WriteAllText(text, "Default maps installed once.");
			}
		}
	}
	internal static class FireworkSound
	{
		private static readonly List<GameObject> playing = new List<GameObject>();

		internal static void Play(GameObject marker)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Expected O, but got Unknown
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			AudioCall val = null;
			System.Collections.Generic.IEnumerator<GearMarket> enumerator = Resources.FindObjectsOfTypeAll<GearMarket>().GetEnumerator();
			try
			{
				while (((System.Collections.IEnumerator)enumerator).MoveNext())
				{
					GearMarket current = enumerator.Current;
					if (Object.op_Implicit((Object)(object)current))
					{
						Scene scene = ((Component)current).gameObject.scene;
						if (((Scene)(ref scene)).IsValid() && Object.op_Implicit((Object)(object)current.unlockPurchaseSFX))
						{
							val = current.unlockPurchaseSFX;
							break;
						}
					}
				}
			}
			finally
			{
				((System.IDisposable)enumerator)?.Dispose();
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				throw new InvalidOperationException("The shop purchase sound asset is not loaded in this scene.");
			}
			WeightedClip randomClip = val.GetRandomClip();
			if (randomClip == null || !Object.op_Implicit((Object)(object)randomClip.Clip))
			{
				throw new InvalidOperationException("The shop purchase sound asset has no playable clip.");
			}
			playing.RemoveAll((Predicate<GameObject>)((GameObject go) => !Object.op_Implicit((Object)(object)go)));
			GameObject val2 = new GameObject("GymMaps.FireworkSound");
			playing.Add(val2);
			try
			{
				val2.transform.position = marker.transform.position;
				AudioSource val3 = val2.AddComponent<AudioSource>();
				val3.playOnAwake = false;
				val3.loop = false;
				val3.clip = randomClip.Clip;
				GeneralAudioSettings generalSettings = val.GeneralSettings;
				val3.outputAudioMixerGroup = generalSettings.MixerGroup;
				val3.volume = generalSettings.GetRandomVolume();
				val3.pitch = generalSettings.GetRandomPitch();
				val3.spatialBlend = 1f;
				SpatialAudioSettings spatialSettings = val.SpatialSettings;
				val3.minDistance = ((spatialSettings != null) ? spatialSettings.MinMaxDistance.x : 2f);
				val3.maxDistance = ((spatialSettings != null) ? spatialSettings.MinMaxDistance.y : 30f);
				val3.Play();
				Object.Destroy((Object)(object)val2, randomClip.Clip.length / Math.Max(0.01f, Math.Abs(val3.pitch)) + 0.25f);
				MelonLogger.Msg("[MapTrigger] play.sound.firework: shop unlockPurchaseSFX / " + ((Object)randomClip.Clip).name + " at " + ((Object)marker).name);
			}
			catch
			{
				if (Object.op_Implicit((Object)(object)val2))
				{
					Object.Destroy((Object)(object)val2);
				}
				throw;
			}
		}

		internal static void Clear()
		{
			//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)
			Enumerator<GameObject> enumerator = playing.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					GameObject current = enumerator.Current;
					if (Object.op_Implicit((Object)(object)current))
					{
						Object.Destroy((Object)(object)current);
					}
				}
			}
			finally
			{
				((System.IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
			}
			playing.Clear();
		}
	}
	public sealed class Mod : MelonMod
	{
		public override void OnInitializeMelon()
		{
			Runtime.Boot((MelonBase)(object)this);
		}

		public override void OnDeinitializeMelon()
		{
			Runtime.Shutdown();
		}

		public override void OnSceneWasUnloaded(int buildIndex, string sceneName)
		{
			if (sceneName == "Gym")
			{
				Runtime.SuspendForScene();
			}
		}
	}
	public sealed class MenuEntry : DataEntryModelBase
	{
		private readonly string id;

		private readonly string title;

		private readonly string description;

		private readonly IUiExtension extension;

		public override string Identifier => id;

		public override string DisplayName => title;

		public override string Description => description;

		[field: CompilerGenerated]
		public override object ModelBoxedValue
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			protected set;
		}

		public override IUiExtension UiExtension => extension;

		public MenuEntry(CategoryModelBase category, string id, string title, string description, object value, IUiExtension extension)
			: base(category)
		{
			this.id = id;
			this.title = title;
			this.description = description;
			((DataEntryModelBase)this).ModelBoxedValue = value;
			this.extension = extension;
		}

		public void Set(object value)
		{
			((DataEntryModelBase)this).ModelBoxedValue = value;
		}
	}
	public sealed class ActionDescriptor : DefaultValidator, IButtonDescriptor, IUiExtension
	{
		[field: CompilerGenerated]
		public string DisplayName
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			set;
		} = "";

		[field: CompilerGenerated]
		public string Description
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			set;
		} = "";

		[field: CompilerGenerated]
		public string ButtonText
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			set;
		}

		[field: CompilerGenerated]
		public Action Handler
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			set;
		}
	}
	public static class Runtime
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static Action <0>__LoadSelected;

			public static Action <1>__Refresh;

			public static Action <2>__Unload;

			public static Action <3>__RaiseKillFloor;

			public static LemonAction <4>__Tick;

			public static Func<string, string> <5>__GetFileNameWithoutExtension;
		}

		[CompilerGenerated]
		private sealed class <Switch>d__39 : System.Collections.Generic.IEnumerator<object>, System.IDisposable, System.Collections.IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public string filename;

			public bool teleport;

			public bool append;

			public int ticket;

			private GameObject <staged>5__2;

			private List<Material> <stagedMaterials>5__3;

			private List<TrackedPrimitive> <stagedTriggers>5__4;

			private MapEntry[] <entries>5__5;

			private bool <retain>5__6;

			private int <removed>5__7;

			private bool <safetyRequested>5__8;

			private double <deadline>5__9;

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

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

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

			[DebuggerHidden]
			void System.IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || (uint)(num - 1) <= 3u)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
			}

			private bool MoveNext()
			{
				//IL_09d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_09de: Expected O, but got Unknown
				//IL_0116: Unknown result type (might be due to invalid IL or missing references)
				//IL_0120: Expected O, but got Unknown
				//IL_0146: Unknown result type (might be due to invalid IL or missing references)
				//IL_0819: Unknown result type (might be due to invalid IL or missing references)
				//IL_081e: Unknown result type (might be due to invalid IL or missing references)
				//IL_00db: Unknown result type (might be due to invalid IL or missing references)
				//IL_0254: Unknown result type (might be due to invalid IL or missing references)
				//IL_0294: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0193: Unknown result type (might be due to invalid IL or missing references)
				//IL_019a: Expected O, but got Unknown
				//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_0220: Unknown result type (might be due to invalid IL or missing references)
				//IL_0225: Unknown result type (might be due to invalid IL or missing references)
				//IL_022a: Unknown result type (might be due to invalid IL or missing references)
				//IL_022f: Unknown result type (might be due to invalid IL or missing references)
				//IL_085c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0861: Unknown result type (might be due to invalid IL or missing references)
				//IL_07c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_07ca: Expected O, but got Unknown
				//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
				//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
				//IL_043b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0440: Unknown result type (might be due to invalid IL or missing references)
				//IL_045c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0468: Expected O, but got Unknown
				bool result;
				try
				{
					switch (<>1__state)
					{
					default:
						result = false;
						goto end_IL_0000;
					case 0:
					{
						<>1__state = -1;
						<>1__state = -3;
						<staged>5__2 = null;
						<stagedMaterials>5__3 = new List<Material>();
						<stagedTriggers>5__4 = new List<TrackedPrimitive>();
						<entries>5__5 = null;
						System.Exception ex = null;
						try
						{
							<entries>5__5 = MapFile.Read(Path.Combine(MapDirectory, filename));
							MapEntry[] array = <entries>5__5;
							for (int i = 0; i < array.Length; i++)
							{
								MapCommands.Validate(array[i].Tags);
							}
							if (teleport && !Enumerable.Any<MapEntry>((System.Collections.Generic.IEnumerable<MapEntry>)<entries>5__5, (Func<MapEntry, bool>)((MapEntry e) => Enumerable.Any<string>((System.Collections.Generic.IEnumerable<string>)e.Tags.OnLoad, (Func<string, bool>)((string c) => c.Equals("interface.respawn.start", (StringComparison)5))))))
							{
								throw new FormatException("Map teleport requires CubeStart.OnMapLoad.interface.respawn.start in the destination map.");
							}
						}
						catch (System.Exception ex2)
						{
							ex = ex2;
						}
						if (ex != null)
						{
							Fail(ex);
							result = false;
							break;
						}
						SetStatus("Loading " + Path.GetFileNameWithoutExtension(filename));
						try
						{
							<staged>5__2 = new GameObject("GymMaps.ActiveMap.Staging");
							<staged>5__2.SetActive(false);
							Shader val = Shader.Find("Universal Render Pipeline/Lit");
							if (!Object.op_Implicit((Object)(object)val))
							{
								throw new InvalidOperationException("RUMBLE surface shader unavailable.");
							}
							Dictionary<string, Material> val2 = new Dictionary<string, Material>();
							MapEntry[] array = <entries>5__5;
							Material val5 = default(Material);
							foreach (MapEntry mapEntry in array)
							{
								if (mapEntry.Tags.Placeholder)
								{
									continue;
								}
								if (mapEntry.Tags.Marker)
								{
									GameObject val3 = new GameObject(mapEntry.Name);
									val3.transform.SetParent(<staged>5__2.transform, false);
									val3.transform.localPosition = Vector(mapEntry.Position);
									val3.transform.localRotation = Quaternion.Euler(Vector(mapEntry.Rotation));
									val3.transform.localScale = Vector(mapEntry.Scale);
									<stagedTriggers>5__4.Add(new TrackedPrimitive
									{
										Object = val3,
										Tags = mapEntry.Tags,
										LocalBounds = new Bounds(Vector3.zero, Vector3.one)
									});
									continue;
								}
								GameObject val4 = GameObject.CreatePrimitive((PrimitiveType)System.Enum.Parse(typeof(PrimitiveType), mapEntry.Shape));
								val4.transform.SetParent(<staged>5__2.transform, false);
								((Object)val4).name = mapEntry.Name;
								val4.transform.localPosition = Vector(mapEntry.Position);
								val4.transform.localRotation = Quaternion.Euler(Vector(mapEntry.Rotation));
								val4.transform.localScale = Vector(mapEntry.Scale);
								System.Collections.Generic.IEnumerator<Collider> enumerator = val4.GetComponents<Collider>().GetEnumerator();
								try
								{
									while (((System.Collections.IEnumerator)enumerator).MoveNext())
									{
										Collider current = enumerator.Current;
										current.enabled = false;
										Object.Destroy((Object)(object)current);
									}
								}
								finally
								{
									((System.IDisposable)enumerator)?.Dispose();
								}
								if (mapEntry.Has("visual") || mapEntry.Tags.TriggerOnly)
								{
									val4.layer = 0;
								}
								else
								{
									val4.layer = (mapEntry.Has("environment") ? 10 : 9);
									val4.AddComponent<MeshCollider>().sharedMesh = val4.GetComponent<MeshFilter>().sharedMesh;
									if (mapEntry.Has("wall"))
									{
										val4.AddComponent<BoxCollider>();
									}
									if (mapEntry.Has("death"))
									{
										val4.AddComponent<KillPlayerOnCollision>();
									}
									if (mapEntry.Has("environment"))
									{
										val4.AddComponent<KillStructureOnImpact>();
									}
								}
								if (mapEntry.Tags.OnEnter.Count > 0)
								{
									<stagedTriggers>5__4.Add(new TrackedPrimitive
									{
										Object = val4,
										Tags = mapEntry.Tags,
										LocalBounds = val4.GetComponent<MeshFilter>().sharedMesh.bounds
									});
								}
								Renderer component = val4.GetComponent<Renderer>();
								if (mapEntry.Has("invisible"))
								{
									component.enabled = false;
									continue;
								}
								string text = string.Join<float>("|", (System.Collections.Generic.IEnumerable<float>)mapEntry.Color);
								if (!val2.TryGetValue(text, ref val5))
								{
									val5 = new Material(val)
									{
										color = new Color(mapEntry.Color[0], mapEntry.Color[1], mapEntry.Color[2])
									};
									val2.Add(text, val5);
									<stagedMaterials>5__3.Add(val5);
								}
								component.sharedMaterial = val5;
							}
						}
						catch (System.Exception ex3)
						{
							ex = ex3;
						}
						if (ex != null)
						{
							if (Object.op_Implicit((Object)(object)<staged>5__2))
							{
								Object.Destroy((Object)(object)<staged>5__2);
							}
							ReleaseMaterials(<stagedMaterials>5__3);
							Fail(ex);
							result = false;
							break;
						}
						<retain>5__6 = append && Object.op_Implicit((Object)(object)activeMap);
						if (!<retain>5__6)
						{
							DestroyActive();
						}
						<removed>5__7 = ((!<retain>5__6) ? ClearMapCreator() : 0);
						<>2__current = null;
						<>1__state = 1;
						result = true;
						goto end_IL_0000;
					}
					case 1:
					{
						<>1__state = -3;
						if (ticket != generation || !started || !InGym() || !Object.op_Implicit((Object)(object)<staged>5__2))
						{
							if (Object.op_Implicit((Object)(object)<staged>5__2))
							{
								Object.Destroy((Object)(object)<staged>5__2);
							}
							ReleaseMaterials(<stagedMaterials>5__3);
							if (ticket == generation)
							{
								busy = false;
							}
							result = false;
							break;
						}
						List<TrackedPrimitive> entries = Enumerable.ToList<TrackedPrimitive>(Enumerable.Where<TrackedPrimitive>((System.Collections.Generic.IEnumerable<TrackedPrimitive>)<stagedTriggers>5__4, (Func<TrackedPrimitive, bool>)((TrackedPrimitive e) => e.Tags.OnEnter.Count > 0)));
						if (<retain>5__6)
						{
							while (<staged>5__2.transform.childCount > 0)
							{
								<staged>5__2.transform.GetChild(0).SetParent(activeMap.transform, true);
							}
							Object.Destroy((Object)(object)<staged>5__2);
							mapMaterials.AddRange((System.Collections.Generic.IEnumerable<Material>)<stagedMaterials>5__3);
							TriggerTracking.Append(entries);
						}
						else
						{
							activeMap = <staged>5__2;
							mapMaterials = <stagedMaterials>5__3;
							((Object)<staged>5__2).name = "GymMaps.ActiveMap";
							<staged>5__2.SetActive(true);
							TriggerTracking.Set(entries);
						}
						loadedFiles.Add(filename);
						ActiveName = string.Join(" + ", Enumerable.Select<string, string>((System.Collections.Generic.IEnumerable<string>)loadedFiles, (Func<string, string>)Path.GetFileNameWithoutExtension));
						SetStatus($"{(<retain>5__6 ? "Appended" : "Loaded")} {Path.GetFileNameWithoutExtension(filename)} - {ActiveCount} objects, {TriggerTracking.Count} entry triggers");
						Log($"{(<retain>5__6 ? "Appended" : "Loaded")} {filename}: {<entries>5__5.Length} objects; cleared {<removed>5__7} MapCreator objects.");
						<safetyRequested>5__8 = LoadFeatures.Enabled;
						<>2__current = (object)new WaitForFixedUpdate();
						<>1__state = 2;
						result = true;
						goto end_IL_0000;
					}
					case 2:
					{
						<>1__state = -3;
						if (ticket != generation || !started || !InGym() || !Object.op_Implicit((Object)(object)activeMap))
						{
							result = false;
							break;
						}
						Physics.SyncTransforms();
						Enumerator<TrackedPrimitive> enumerator2 = <stagedTriggers>5__4.GetEnumerator();
						try
						{
							while (enumerator2.MoveNext())
							{
								TrackedPrimitive current2 = enumerator2.Current;
								if (ticket != generation || !Object.op_Implicit((Object)(object)current2.Object))
								{
									result = false;
									goto end_IL_0008;
								}
								Enumerator<string> enumerator3 = current2.Tags.OnLoad.GetEnumerator();
								try
								{
									while (enumerator3.MoveNext())
									{
										string current3 = enumerator3.Current;
										if (ticket != generation || !Object.op_Implicit((Object)(object)current2.Object))
										{
											result = false;
											goto end_IL_0008;
										}
										MapCommands.Run(current2.Object, current3);
									}
								}
								finally
								{
									((System.IDisposable)enumerator3/*cast due to .constrained prefix*/).Dispose();
								}
							}
						}
						finally
						{
							((System.IDisposable)enumerator2/*cast due to .constrained prefix*/).Dispose();
						}
						<deadline>5__9 = Time.realtimeSinceStartupAsDouble + 5.0;
						goto IL_0935;
					}
					case 3:
						<>1__state = -3;
						goto IL_0935;
					case 4:
						{
							<>1__state = -3;
							if (ticket != generation || !started || !InGym() || !Object.op_Implicit((Object)(object)activeMap))
							{
								result = false;
								break;
							}
							ReportTrigger("Loaded and teleported to " + Path.GetFileNameWithoutExtension(filename) + ".");
							goto IL_0a41;
						}
						IL_0a41:
						if (((ticket == generation && started && InGym() && Object.op_Implicit((Object)(object)activeMap)) & <safetyRequested>5__8) && LoadFeatures.Enabled)
						{
							LoadFeatures.CheckSafetyOnce();
						}
						if (ticket == generation)
						{
							busy = false;
						}
						<staged>5__2 = null;
						<stagedMaterials>5__3 = null;
						<stagedTriggers>5__4 = null;
						<entries>5__5 = null;
						<>m__Finally1();
						result = false;
						goto end_IL_0000;
						IL_0935:
						if ((teleport || (<safetyRequested>5__8 && LoadFeatures.Enabled)) && !Object.op_Implicit((Object)(object)LoadFeatures.PlayerBody()) && Time.realtimeSinceStartupAsDouble < <deadline>5__9)
						{
							if (ticket != generation || !started || !InGym() || !Object.op_Implicit((Object)(object)activeMap))
							{
								result = false;
								break;
							}
							<>2__current = null;
							<>1__state = 3;
							result = true;
						}
						else
						{
							if (!teleport || ticket != generation || !started || !InGym() || !Object.op_Implicit((Object)(object)activeMap))
							{
								goto IL_0a41;
							}
							bool flag = false;
							try
							{
								RespawnPoint.TeleportLocal();
								flag = true;
							}
							catch (System.Exception ex4)
							{
								ReportTrigger("Map loaded; teleport failed: " + ex4.Message);
							}
							if (!flag)
							{
								goto IL_0a41;
							}
							<>2__current = (object)new WaitForSecondsRealtime(0.5f);
							<>1__state = 4;
							result = true;
						}
						goto end_IL_0000;
						end_IL_0008:
						break;
					}
					<>m__Finally1();
					end_IL_0000:;
				}
				catch
				{
					//try-fault
					((System.IDisposable)this).Dispose();
					throw;
				}
				return result;
			}

			bool System.Collections.IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (ticket == generation)
				{
					busy = false;
				}
			}

			[DebuggerHidden]
			void System.Collections.IEnumerator.Reset()
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <TestAll>d__55 : System.Collections.Generic.IEnumerator<object>, System.IDisposable, System.Collections.IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			private string[] <>7__wrap1;

			private int <>7__wrap2;

			private string <file>5__4;

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

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

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

			[DebuggerHidden]
			void System.IDisposable.Dispose()
			{
			}

			private bool MoveNext()
			{
				//IL_0075: Unknown result type (might be due to invalid IL or missing references)
				//IL_007f: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>7__wrap1 = files.ToArray();
					<>7__wrap2 = 0;
					goto IL_0283;
				case 1:
				{
					<>1__state = -1;
					MapEntry[] array = MapFile.Read(Path.Combine(MapDirectory, <file>5__4));
					int num = Enumerable.Count<Transform>((System.Collections.Generic.IEnumerable<Transform>)Object.FindObjectsOfType<Transform>(), (Func<Transform, bool>)((Transform t) => ((Object)t).name == "GymMaps.ActiveMap"));
					int num2 = Enumerable.Count<MapEntry>((System.Collections.Generic.IEnumerable<MapEntry>)array, (Func<MapEntry, bool>)((MapEntry e) => !e.Has("visual") && !e.Tags.TriggerOnly && !e.Tags.Placeholder));
					Il2CppArrayBase<MeshCollider> val = (Object.op_Implicit((Object)(object)activeMap) ? activeMap.GetComponentsInChildren<MeshCollider>(true) : null);
					bool flag = ActiveName == Path.GetFileNameWithoutExtension(<file>5__4) && ActiveCount == Enumerable.Count<MapEntry>((System.Collections.Generic.IEnumerable<MapEntry>)array, (Func<MapEntry, bool>)((MapEntry e) => !e.Tags.Placeholder)) && num == 1 && val != null && val.Length == num2 && Enumerable.All<MeshCollider>((System.Collections.Generic.IEnumerable<MeshCollider>)val, (Func<MeshCollider, bool>)((MeshCollider c) => Object.op_Implicit((Object)(object)c.sharedMesh)));
					Log($"TEST {(flag ? "PASS" : "FAIL")} {<file>5__4}: objects={ActiveCount}/{array.Length}, roots={num}, colliders={val?.Length}/{num2}");
					if (!flag)
					{
						return false;
					}
					<file>5__4 = null;
					<>7__wrap2++;
					goto IL_0283;
				}
				case 2:
					<>1__state = -1;
					Log("TEST " + ((ActiveCount == 0 && !Enumerable.Any<Transform>((System.Collections.Generic.IEnumerable<Transform>)Object.FindObjectsOfType<Transform>(), (Func<Transform, bool>)((Transform t) => ((Object)t).name == "GymMaps.ActiveMap"))) ? "PASS" : "FAIL") + " unload");
					if (files.Count > 0)
					{
						LoadSelected();
						Unload();
						<>2__current = null;
						<>1__state = 3;
						return true;
					}
					break;
				case 3:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 4;
					return true;
				case 4:
					{
						<>1__state = -1;
						Log("TEST " + ((ActiveCount == 0 && !Enumerable.Any<Transform>((System.Collections.Generic.IEnumerable<Transform>)Object.FindObjectsOfType<Transform>(), (Func<Transform, bool>)((Transform t) => ((Object)t).name.StartsWith("GymMaps.ActiveMap")))) ? "PASS" : "FAIL") + " cancel pending load");
						break;
					}
					IL_0283:
					if (<>7__wrap2 < <>7__wrap1.Length)
					{
						<file>5__4 = <>7__wrap1[<>7__wrap2];
						((DataEntryModelBase)selection).TryApply((object)<file>5__4);
						LoadSelected();
						<>2__current = (object)new WaitForSecondsRealtime(0.5f);
						<>1__state = 1;
						return true;
					}
					<>7__wrap1 = null;
					Unload();
					<>2__current = null;
					<>1__state = 2;
					return true;
				}
				return false;
			}

			bool System.Collections.IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void System.Collections.IEnumerator.Reset()
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				throw new NotSupportedException();
			}
		}

		private static bool started;

		private static bool busy;

		private static bool wasInGym;

		private static int generation;

		private static readonly List<string> loadedFiles = new List<string>();

		private static GameObject activeMap;

		private static List<Material> mapMaterials = new List<Material>();

		private static MelonModel menu;

		private static MenuEntry selection;

		private static MenuEntry statusEntry;

		private static DynamicDropdownDescriptor dropdown;

		private static List<string> files = new List<string>();

		private const string RootName = "GymMaps.ActiveMap";

		internal static bool IsBusy => busy;

		[field: CompilerGenerated]
		public static string ActiveName
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			private set;
		} = "None";

		[field: CompilerGenerated]
		public static string Status
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			private set;
		} = "Ready";

		public static int ActiveCount
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)activeMap))
				{
					return 0;
				}
				return activeMap.transform.childCount;
			}
		}

		public static string MapDirectory => Path.Combine(MelonEnvironment.GameRootDirectory, "UserData", "GymMaps");

		internal static bool GameplayAllowed
		{
			get
			{
				//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)
				if (started)
				{
					Scene activeScene = SceneManager.GetActiveScene();
					return ((Scene)(ref activeScene)).name == "Gym";
				}
				return false;
			}
		}

		public static void Boot(MelonBase owner)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Expected O, but got Unknown
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Expected O, but got Unknown
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Expected O, but got Unknown
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Expected O, but got Unknown
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Expected O, but got Unknown
			//IL_01f8: Expected O, but got Unknown
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Expected O, but got Unknown
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Expected O, but got Unknown
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Expected O, but got Unknown
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Expected O, but got Unknown
			if (started)
			{
				return;
			}
			LoadFeatures.SetEnabled(enabled: false);
			MapCommands.Boot();
			menu = UI.RegisterMelon(owner);
			((ModModelBase)menu)._displayName = "GymMaps";
			EmptyCategory val = new EmptyCategory("Maps", "Maps", (ModModelBase)(object)menu);
			((ModModelBase)menu).AddModelCategory((CategoryModelBase[])(object)new CategoryModelBase[1] { (CategoryModelBase)val });
			dropdown = new DynamicDropdownDescriptor();
			selection = new MenuEntry((CategoryModelBase)(object)val, "SelectedMap", "Map", "Choose a map, then press Load.", "", (IUiExtension)(object)dropdown);
			statusEntry = new MenuEntry((CategoryModelBase)(object)val, "Status", "Status", "Map actions are available in the Gym.", Status, (IUiExtension)new TextInputBehaviorDescriptor
			{
				IsReadOnly = true
			});
			((CategoryModelBase)val).AddEntry((IEntry[])(object)new IEntry[1] { (IEntry)selection });
			object obj = <>O.<0>__LoadSelected;
			if (obj == null)
			{
				Action val2 = LoadSelected;
				<>O.<0>__LoadSelected = val2;
				obj = (object)val2;
			}
			AddButton(val, "Load", "Load selected map", (Action)obj);
			object obj2 = <>O.<1>__Refresh;
			if (obj2 == null)
			{
				Action val3 = Refresh;
				<>O.<1>__Refresh = val3;
				obj2 = (object)val3;
			}
			AddButton(val, "Refresh", "Refresh map list", (Action)obj2);
			object obj3 = <>O.<2>__Unload;
			if (obj3 == null)
			{
				Action val4 = Unload;
				<>O.<2>__Unload = val4;
				obj3 = (object)val4;
			}
			AddButton(val, "Unload", "Unload custom map", (Action)obj3);
			((CategoryModelBase)val).AddEntry((IEntry[])(object)new IEntry[2]
			{
				(IEntry)statusEntry,
				(IEntry)new MenuEntry((CategoryModelBase)(object)val, "Folder", "Map folder", "Add MapCreator .txt maps here, then press Refresh.", MapDirectory, (IUiExtension)new TextInputBehaviorDescriptor
				{
					IsReadOnly = true
				})
			});
			EmptyCategory val5 = new EmptyCategory("Tools", "Tools", (ModModelBase)(object)menu);
			((ModModelBase)menu).AddModelCategory((CategoryModelBase[])(object)new CategoryModelBase[1] { (CategoryModelBase)val5 });
			((CategoryModelBase)val5).AddEntry((IEntry[])(object)new IEntry[1] { (IEntry)new MenuEntry((CategoryModelBase)(object)val5, "EnableTriggerCommands", "Enable trigger commands", "Allows commands that change game and player behavior. Use at your own risk.", false, (IUiExtension)new UserEditNotifier
			{
				OnUserEdit = delegate(object value)
				{
					bool flag = default(bool);
					int num;
					if (value is bool)
					{
						flag = (bool)value;
						num = 1;
					}
					else
					{
						num = 0;
					}
					MapCommands.SetEnabled((byte)((uint)num & (flag ? 1u : 0u)) != 0);
				}
			}) });
			((CategoryModelBase)val5).AddEntry((IEntry[])(object)new IEntry[1] { (IEntry)new MenuEntry((CategoryModelBase)(object)val5, "SafetyPlatform", "Safety Platform", "Spawns in a safety platform preventing you from falling on map loading", false, (IUiExtension)new UserEditNotifier
			{
				OnUserEdit = delegate(object value)
				{
					bool flag = default(bool);
					int num;
					if (value is bool)
					{
						flag = (bool)value;
						num = 1;
					}
					else
					{
						num = 0;
					}
					LoadFeatures.SetEnabled((byte)((uint)num & (flag ? 1u : 0u)) != 0);
				}
			}) });
			((CategoryModelBase)val5).AddEntry((IEntry[])(object)new IEntry[1] { (IEntry)new MenuEntry((CategoryModelBase)(object)val5, "KillFloorStep", "Kill floor raise amount", "World units raised per click. A missing floor starts below the course.", 1f, (IUiExtension)new SliderDescriptor
			{
				Min = 0.25f,
				Max = 25f,
				DecimalPlaces = 2,
				OnUserEdit = delegate(object value)
				{
					MapTools.SetRaiseAmount(Convert.ToSingle(value));
				}
			}) });
			object obj4 = <>O.<3>__RaiseKillFloor;
			if (obj4 == null)
			{
				Action val6 = MapTools.RaiseKillFloor;
				<>O.<3>__RaiseKillFloor = val6;
				obj4 = (object)val6;
			}
			AddButton(val5, "RaiseKillFloor", "Raise Kill Floor", (Action)obj4);
			started = true;
			wasInGym = InGym();
			MelonEvent onUpdate = MelonEvents.OnUpdate;
			object obj5 = <>O.<4>__Tick;
			if (obj5 == null)
			{
				LemonAction val7 = Tick;
				<>O.<4>__Tick = val7;
				obj5 = (object)val7;
			}
			((MelonEventBase<LemonAction>)(object)onUpdate).Subscribe((LemonAction)obj5, 0, false);
			try
			{
				DefaultMaps.AddMissing(MapDirectory);
			}
			catch (System.Exception ex)
			{
				MelonLogger.Warning("Default map installation: " + ex.Message);
			}
			Refresh();
			Log("GymMaps UI ready. F9; folder: " + MapDirectory);
		}

		private static void AddButton(EmptyCategory category, string id, string title, Action action)
		{
			((CategoryModelBase)category).AddEntry((IEntry[])(object)new IEntry[1] { (IEntry)new MenuEntry((CategoryModelBase)(object)category, id, title, "", id, (IUiExtension)(object)new ActionDescriptor
			{
				ButtonText = id,
				Handler = action
			}) });
		}

		private static bool InGym()
		{
			//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();
			return ((Scene)(ref activeScene)).name == "Gym";
		}

		internal static void SuspendForScene()
		{
			if (started)
			{
				ClearOwned();
				wasInGym = false;
				SetStatus("GymMaps disabled outside the Gym (matches and Park).");
			}
		}

		private static void Tick()
		{
			bool flag = InGym();
			if (wasInGym && !flag)
			{
				SuspendForScene();
			}
			if (!wasInGym && flag)
			{
				SetStatus("Ready — select a map and press Load.");
			}
			wasInGym = flag;
			if (flag && !busy)
			{
				MapTools.CheckKillFloor();
				TriggerTracking.Tick();
			}
		}

		public static void Refresh()
		{
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Expected O, but got Unknown
			try
			{
				Directory.CreateDirectory(MapDirectory);
				List<string> val = new List<string>();
				int num = 0;
				System.Collections.Generic.IEnumerator<string> enumerator = ((System.Collections.Generic.IEnumerable<string>)Enumerable.OrderBy<string, string>(Enumerable.Where<string>(Directory.EnumerateFiles(MapDirectory, "*", (SearchOption)0), (Func<string, bool>)((string p) => Path.GetExtension(p).Equals(".txt", (StringComparison)5))), (Func<string, string>)((string p) => p), (IComparer<string>)(object)StringComparer.OrdinalIgnoreCase)).GetEnumerator();
				try
				{
					while (((System.Collections.IEnumerator)enumerator).MoveNext())
					{
						string current = enumerator.Current;
						try
						{
							MapFile.Read(current);
							val.Add(Path.GetFileName(current));
						}
						catch (System.Exception ex)
						{
							num++;
							Log("Skipped " + Path.GetFileName(current) + ": " + ex.Message);
						}
					}
				}
				finally
				{
					((System.IDisposable)enumerator)?.Dispose();
				}
				files = val;
				string text = ((DataEntryModelBase)selection).ModelBoxedValue as string;
				if (!files.Contains(text))
				{
					text = Enumerable.FirstOrDefault<string>((System.Collections.Generic.IEnumerable<string>)files) ?? "";
				}
				selection.Set(text);
				DynamicDropdownDescriptor obj = dropdown;
				List<DropdownItem> obj2;
				if (files.Count <= 0)
				{
					obj2 = new List<DropdownItem>();
					obj2.Add(new DropdownItem("No valid maps found", (object)""));
				}
				else
				{
					obj2 = Enumerable.ToList<DropdownItem>(Enumerable.Select<string, DropdownItem>((System.Collections.Generic.IEnumerable<string>)files, (Func<string, DropdownItem>)((string f) => new DropdownItem(Path.GetFileNameWithoutExtension(f), (object)f))));
				}
				obj.SetDropdownItems(obj2);
				SetStatus($"Found {files.Count} maps" + ((num > 0) ? $"; skipped {num} invalid files" : "") + ". Active: " + ActiveName);
			}
			catch (System.Exception ex2)
			{
				SetStatus("Refresh failed: " + ex2.Message);
				Log(((object)ex2).ToString());
			}
		}

		public static void LoadSelected()
		{
			Request(((DataEntryModelBase)selection).ModelBoxedValue as string);
		}

		internal static string ResolveMap(string mapName)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrWhiteSpace(mapName) || mapName == "." || mapName == ".." || mapName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0 || !Path.GetFileName(mapName).Equals(mapName, (StringComparison)4))
			{
				throw new FormatException("Invalid map name: " + mapName);
			}
			string text = (mapName.EndsWith(".txt", (StringComparison)5) ? mapName : (mapName + ".txt"));
			System.Collections.Generic.IEnumerator<string> enumerator = Directory.EnumerateFiles(MapDirectory, "*", (SearchOption)0).GetEnumerator();
			try
			{
				while (((System.Collections.IEnumerator)enumerator).MoveNext())
				{
					string current = enumerator.Current;
					if (Path.GetFileName(current).Equals(text, (StringComparison)5))
					{
						return Path.GetFileName(current);
					}
				}
			}
			finally
			{
				((System.IDisposable)enumerator)?.Dispose();
			}
			throw new FileNotFoundException("Map not found: " + text);
		}

		public static void Request(string filename)
		{
			Request(filename, append: false);
		}

		public static void Request(string filename, bool append, bool teleport = false)
		{
			if (busy)
			{
				return;
			}
			if (!GameplayAllowed)
			{
				SetStatus("GymMaps disabled outside the Gym (matches and Park).");
				return;
			}
			try
			{
				filename = ResolveMap(filename);
			}
			catch (System.Exception ex)
			{
				SetStatus(ex.Message);
				return;
			}
			if (append && Enumerable.Contains<string>((System.Collections.Generic.IEnumerable<string>)loadedFiles, filename, (IEqualityComparer<string>)(object)StringComparer.OrdinalIgnoreCase))
			{
				SetStatus("Map already present: " + Path.GetFileNameWithoutExtension(filename));
				return;
			}
			busy = true;
			MelonCoroutines.Start(Switch(filename, ++generation, append, teleport));
		}

		[IteratorStateMachine(typeof(<Switch>d__39))]
		private static System.Collections.IEnumerator Switch(string filename, int ticket, bool append = false, bool teleport = false)
		{
			try
			{
				GameObject staged = null;
				List<Material> stagedMaterials = new List<Material>();
				List<TrackedPrimitive> stagedTriggers = new List<TrackedPrimitive>();
				MapEntry[] entries = null;
				System.Exception ex = null;
				try
				{
					entries = MapFile.Read(Path.Combine(MapDirectory, filename));
					MapEntry[] array = entries;
					for (int i = 0; i < array.Length; i++)
					{
						MapCommands.Validate(array[i].Tags);
					}
					if (teleport && !Enumerable.Any<MapEntry>((System.Collections.Generic.IEnumerable<MapEntry>)entries, (Func<MapEntry, bool>)((MapEntry e) => Enumerable.Any<string>((System.Collections.Generic.IEnumerable<string>)e.Tags.OnLoad, (Func<string, bool>)((string c) => c.Equals("interface.respawn.start", (StringComparison)5))))))
					{
						throw new FormatException("Map teleport requires CubeStart.OnMapLoad.interface.respawn.start in the destination map.");
					}
				}
				catch (System.Exception ex2)
				{
					ex = ex2;
				}
				if (ex != null)
				{
					Fail(ex);
					yield break;
				}
				SetStatus("Loading " + Path.GetFileNameWithoutExtension(filename));
				try
				{
					staged = new GameObject("GymMaps.ActiveMap.Staging");
					staged.SetActive(false);
					Shader val = Shader.Find("Universal Render Pipeline/Lit");
					if (!Object.op_Implicit((Object)(object)val))
					{
						throw new InvalidOperationException("RUMBLE surface shader unavailable.");
					}
					Dictionary<string, Material> val2 = new Dictionary<string, Material>();
					MapEntry[] array = entries;
					Material val5 = default(Material);
					foreach (MapEntry mapEntry in array)
					{
						if (mapEntry.Tags.Placeholder)
						{
							continue;
						}
						if (mapEntry.Tags.Marker)
						{
							GameObject val3 = new GameObject(mapEntry.Name);
							val3.transform.SetParent(staged.transform, false);
							val3.transform.localPosition = Vector(mapEntry.Position);
							val3.transform.localRotation = Quaternion.Euler(Vector(mapEntry.Rotation));
							val3.transform.localScale = Vector(mapEntry.Scale);
							stagedTriggers.Add(new TrackedPrimitive
							{
								Object = val3,
								Tags = mapEntry.Tags,
								LocalBounds = new Bounds(Vector3.zero, Vector3.one)
							});
							continue;
						}
						GameObject val4 = GameObject.CreatePrimitive((PrimitiveType)System.Enum.Parse(typeof(PrimitiveType), mapEntry.Shape));
						val4.transform.SetParent(staged.transform, false);
						((Object)val4).name = mapEntry.Name;
						val4.transform.localPosition = Vector(mapEntry.Position);
						val4.transform.localRotation = Quaternion.Euler(Vector(mapEntry.Rotation));
						val4.transform.localScale = Vector(mapEntry.Scale);
						System.Collections.Generic.IEnumerator<Collider> enumerator = val4.GetComponents<Collider>().GetEnumerator();
						try
						{
							while (((System.Collections.IEnumerator)enumerator).MoveNext())
							{
								Collider current = enumerator.Current;
								current.enabled = false;
								Object.Destroy((Object)(object)current);
							}
						}
						finally
						{
							((System.IDisposable)enumerator)?.Dispose();
						}
						if (mapEntry.Has("visual") || mapEntry.Tags.TriggerOnly)
						{
							val4.layer = 0;
						}
						else
						{
							val4.layer = (mapEntry.Has("environment") ? 10 : 9);
							val4.AddComponent<MeshCollider>().sharedMesh = val4.GetComponent<MeshFilter>().sharedMesh;
							if (mapEntry.Has("wall"))
							{
								val4.AddComponent<BoxCollider>();
							}
							if (mapEntry.Has("death"))
							{
								val4.AddComponent<KillPlayerOnCollision>();
							}
							if (mapEntry.Has("environment"))
							{
								val4.AddComponent<KillStructureOnImpact>();
							}
						}
						if (mapEntry.Tags.OnEnter.Count > 0)
						{
							stagedTriggers.Add(new TrackedPrimitive
							{
								Object = val4,
								Tags = mapEntry.Tags,
								LocalBounds = val4.GetComponent<MeshFilter>().sharedMesh.bounds
							});
						}
						Renderer component = val4.GetComponent<Renderer>();
						if (mapEntry.Has("invisible"))
						{
							component.enabled = false;
							continue;
						}
						string text = string.Join<float>("|", (System.Collections.Generic.IEnumerable<float>)mapEntry.Color);
						if (!val2.TryGetValue(text, ref val5))
						{
							val5 = new Material(val)
							{
								color = new Color(mapEntry.Color[0], mapEntry.Color[1], mapEntry.Color[2])
							};
							val2.Add(text, val5);
							stagedMaterials.Add(val5);
						}
						component.sharedMaterial = val5;
					}
				}
				catch (System.Exception ex3)
				{
					ex = ex3;
				}
				if (ex != null)
				{
					if (Object.op_Implicit((Object)(object)staged))
					{
						Object.Destroy((Object)(object)staged);
					}
					ReleaseMaterials(stagedMaterials);
					Fail(ex);
					yield break;
				}
				bool retain = append && Object.op_Implicit((Object)(object)activeMap);
				if (!retain)
				{
					DestroyActive();
				}
				int removed = ((!retain) ? ClearMapCreator() : 0);
				yield return null;
				if (ticket != generation || !started || !InGym() || !Object.op_Implicit((Object)(object)staged))
				{
					if (Object.op_Implicit((Object)(object)staged))
					{
						Object.Destroy((Object)(object)staged);
					}
					ReleaseMaterials(stagedMaterials);
					if (ticket == generation)
					{
						busy = false;
					}
					yield break;
				}
				List<TrackedPrimitive> entries2 = Enumerable.ToList<TrackedPrimitive>(Enumerable.Where<TrackedPrimitive>((System.Collections.Generic.IEnumerable<TrackedPrimitive>)stagedTriggers, (Func<TrackedPrimitive, bool>)((TrackedPrimitive e) => e.Tags.OnEnter.Count > 0)));
				if (retain)
				{
					while (staged.transform.childCount > 0)
					{
						staged.transform.GetChild(0).SetParent(activeMap.transform, true);
					}
					Object.Destroy((Object)(object)staged);
					mapMaterials.AddRange((System.Collections.Generic.IEnumerable<Material>)stagedMaterials);
					TriggerTracking.Append(entries2);
				}
				else
				{
					activeMap = staged;
					mapMaterials = stagedMaterials;
					((Object)staged).name = "GymMaps.ActiveMap";
					staged.SetActive(true);
					TriggerTracking.Set(entries2);
				}
				loadedFiles.Add(filename);
				ActiveName = string.Join(" + ", Enumerable.Select<string, string>((System.Collections.Generic.IEnumerable<string>)loadedFiles, (Func<string, string>)Path.GetFileNameWithoutExtension));
				SetStatus($"{(retain ? "Appended" : "Loaded")} {Path.GetFileNameWithoutExtension(filename)} - {ActiveCount} objects, {TriggerTracking.Count} entry triggers");
				Log($"{(retain ? "Appended" : "Loaded")} {filename}: {entries.Length} objects; cleared {removed} MapCreator objects.");
				bool safetyRequested = LoadFeatures.Enabled;
				yield return (object)new WaitForFixedUpdate();
				if (ticket != generation || !started || !InGym() || !Object.op_Implicit((Object)(object)activeMap))
				{
					yield break;
				}
				Physics.SyncTransforms();
				Enumerator<TrackedPrimitive> enumerator2 = stagedTriggers.GetEnumerator();
				try
				{
					while (enumerator2.MoveNext())
					{
						TrackedPrimitive current2 = enumerator2.Current;
						if (ticket != generation || !Object.op_Implicit((Object)(object)current2.Object))
						{
							yield break;
						}
						Enumerator<string> enumerator3 = current2.Tags.OnLoad.GetEnumerator();
						try
						{
							while (enumerator3.MoveNext())
							{
								string current3 = enumerator3.Current;
								if (ticket != generation || !Object.op_Implicit((Object)(object)current2.Object))
								{
									yield break;
								}
								MapCommands.Run(current2.Object, current3);
							}
						}
						finally
						{
							((System.IDisposable)enumerator3/*cast due to .constrained prefix*/).Dispose();
						}
					}
				}
				finally
				{
					((System.IDisposable)enumerator2/*cast due to .constrained prefix*/).Dispose();
				}
				double deadline = Time.realtimeSinceStartupAsDouble + 5.0;
				while ((teleport || (safetyRequested && LoadFeatures.Enabled)) && !Object.op_Implicit((Object)(object)LoadFeatures.PlayerBody()) && Time.realtimeSinceStartupAsDouble < deadline)
				{
					if (ticket != generation || !started || !InGym() || !Object.op_Implicit((Object)(object)activeMap))
					{
						yield break;
					}
					yield return null;
				}
				if (teleport && ticket == generation && started && InGym() && Object.op_Implicit((Object)(object)activeMap))
				{
					bool flag = false;
					try
					{
						RespawnPoint.TeleportLocal();
						flag = true;
					}
					catch (System.Exception ex4)
					{
						ReportTrigger("Map loaded; teleport failed: " + ex4.Message);
					}
					if (flag)
					{
						yield return (object)new WaitForSecondsRealtime(0.5f);
						if (ticket != generation || !started || !InGym() || !Object.op_Implicit((Object)(object)activeMap))
						{
							yield break;
						}
						ReportTrigger("Loaded and teleported to " + Path.GetFileNameWithoutExtension(filename) + ".");
					}
				}
				if (ticket == generation && started && InGym() && Object.op_Implicit((Object)(object)activeMap) && safetyRequested && LoadFeatures.Enabled)
				{
					LoadFeatures.CheckSafetyOnce();
				}
				if (ticket == generation)
				{
					busy = false;
				}
			}
			finally
			{
				if (ticket == generation)
				{
					busy = false;
				}
			}
		}

		private static int ClearMapCreator()
		{
			GameObject val = GameObject.Find("StoreHere");
			int num = 0;
			if (Object.op_Implicit((Object)(object)val))
			{
				for (int num2 = val.transform.childCount - 1; num2 >= 0; num2--)
				{
					GameObject gameObject = ((Component)val.transform.GetChild(num2)).gameObject;
					gameObject.SetActive(false);
					Object.Destroy((Object)(object)gameObject);
					num++;
				}
			}
			return num;
		}

		private static void DestroyActive()
		{
			TriggerTracking.Clear();
			if (Object.op_Implicit((Object)(object)activeMap))
			{
				activeMap.SetActive(false);
				Object.Destroy((Object)(object)activeMap);
			}
			activeMap = null;
			ReleaseMaterials(mapMaterials);
			loadedFiles.Clear();
			ActiveName = "None";
		}

		private static void ClearOwned()
		{
			generation++;
			busy = false;
			DestroyActive();
		}

		public static void Unload()
		{
			ClearOwned();
			if (InGym())
			{
				ClearMapCreator();
			}
			SetStatus("Custom map unloaded. Active: None");
		}

		private static Vector3 Vector(float[] a)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(a[0], a[1], a[2]);
		}

		private static void ReleaseMaterials(List<Material> materials)
		{
			//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)
			Enumerator<Material> enumerator = materials.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					Material current = enumerator.Current;
					if (Object.op_Implicit((Object)(object)current))
					{
						Object.Destroy((Object)(object)current);
					}
				}
			}
			finally
			{
				((System.IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
			}
			materials.Clear();
		}

		private static void SetStatus(string value)
		{
			Status = value;
			statusEntry?.Set(value);
			MelonModel obj = menu;
			if (obj != null)
			{
				((ModModelBase)obj).RequestUpdateUI();
			}
		}

		internal static bool TryCourseBounds(out Bounds bounds)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			bounds = default(Bounds);
			bool flag = false;
			if (!Object.op_Implicit((Object)(object)activeMap))
			{
				return false;
			}
			System.Collections.Generic.IEnumerator<MeshFilter> enumerator = activeMap.GetComponentsInChildren<MeshFilter>().GetEnumerator();
			try
			{
				while (((System.Collections.IEnumerator)enumerator).MoveNext())
				{
					Renderer component = ((Component)enumerator.Current).GetComponent<Renderer>();
					if (Object.op_Implicit((Object)(object)component))
					{
						if (!flag)
						{
							bounds = component.bounds;
							flag = true;
						}
						else
						{
							((Bounds)(ref bounds)).Encapsulate(component.bounds);
						}
					}
				}
				return flag;
			}
			finally
			{
				((System.IDisposable)enumerator)?.Dispose();
			}
		}

		internal static bool OwnsMapObject(GameObject source)
		{
			if (Object.op_Implicit((Object)(object)activeMap) && Object.op_Implicit((Object)(object)source))
			{
				return source.transform.IsChildOf(activeMap.transform);
			}
			return false;
		}

		internal static void ReportTrigger(string value)
		{
			SetStatus(value);
			Log(value);
		}

		private static void Fail(System.Exception ex)
		{
			busy = false;
			SetStatus("Load failed; previous map kept. " + ex.Message);
			Log("LOAD FAILED: " + (object)ex);
		}

		private static void Log(string text)
		{
			MelonLogger.Msg("[GymMaps] " + text);
		}

		public static string Inspect()
		{
			string obj = $"Gym={InGym()}; active={ActiveName}; count={ActiveCount}; busy={busy}; maps={files.Count}; status={Status}";
			Log(obj);
			return obj;
		}

		public static void Shutdown()
		{
			//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)
			//IL_0020: Expected O, but got Unknown
			MelonEvent onUpdate = MelonEvents.OnUpdate;
			object obj = <>O.<4>__Tick;
			if (obj == null)
			{
				LemonAction val = Tick;
				<>O.<4>__Tick = val;
				obj = (object)val;
			}
			((MelonEventBase<LemonAction>)(object)onUpdate).Unsubscribe((LemonAction)obj);
			started = false;
			ClearOwned();
			MapCommands.Shutdown();
			Log("Stopped.");
		}

		public static void RunTests()
		{
			MelonCoroutines.Start(TestAll());
		}

		[IteratorStateMachine(typeof(<TestAll>d__55))]
		private static System.Collections.IEnumerator TestAll()
		{
			string[] array = files.ToArray();
			foreach (string file in array)
			{
				((DataEntryModelBase)selection).TryApply((object)file);
				LoadSelected();
				yield return (object)new WaitForSecondsRealtime(0.5f);
				MapEntry[] array2 = MapFile.Read(Path.Combine(MapDirectory, file));
				int num = Enumerable.Count<Transform>((System.Collections.Generic.IEnumerable<Transform>)Object.FindObjectsOfType<Transform>(), (Func<Transform, bool>)((Transform t) => ((Object)t).name == "GymMaps.ActiveMap"));
				int num2 = Enumerable.Count<MapEntry>((System.Collections.Generic.IEnumerable<MapEntry>)array2, (Func<MapEntry, bool>)((MapEntry e) => !e.Has("visual") && !e.Tags.TriggerOnly && !e.Tags.Placeholder));
				Il2CppArrayBase<MeshCollider> val = (Object.op_Implicit((Object)(object)activeMap) ? activeMap.GetComponentsInChildren<MeshCollider>(true) : null);
				bool flag = ActiveName == Path.GetFileNameWithoutExtension(file) && ActiveCount == Enumerable.Count<MapEntry>((System.Collections.Generic.IEnumerable<MapEntry>)array2, (Func<MapEntry, bool>)((MapEntry e) => !e.Tags.Placeholder)) && num == 1 && val != null && val.Length == num2 && Enumerable.All<MeshCollider>((System.Collections.Generic.IEnumerable<MeshCollider>)val, (Func<MeshCollider, bool>)((MeshCollider c) => Object.op_Implicit((Object)(object)c.sharedMesh)));
				Log($"TEST {(flag ? "PASS" : "FAIL")} {file}: objects={ActiveCount}/{array2.Length}, roots={num}, colliders={val?.Length}/{num2}");
				if (!flag)
				{
					yield break;
				}
			}
			Unload();
			yield return null;
			Log("TEST " + ((ActiveCount == 0 && !Enumerable.Any<Transform>((System.Collections.Generic.IEnumerable<Transform>)Object.FindObjectsOfType<Transform>(), (Func<Transform, bool>)((Transform t) => ((Object)t).name == "GymMaps.ActiveMap"))) ? "PASS" : "FAIL") + " unload");
			if (files.Count > 0)
			{
				LoadSelected();
				Unload();
				yield return null;
				yield return null;
				Log("TEST " + ((ActiveCount == 0 && !Enumerable.Any<Transform>((System.Collections.Generic.IEnumerable<Transform>)Object.FindObjectsOfType<Transform>(), (Func<Transform, bool>)((Transform t) => ((Object)t).name.StartsWith("GymMaps.ActiveMap")))) ? "PASS" : "FAIL") + " cancel pending load");
			}
		}
	}
	internal static class LoadFeatures
	{
		private static GameObject platform;

		private static Material platformMaterial;

		private static readonly Dictionary<int, Structure> structures = new Dictionary<int, Structure>();

		[field: CompilerGenerated]
		internal static bool Enabled
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			private set;
		}

		internal static void SetEnabled(bool enabled)
		{
			Enabled = enabled;
			if (!enabled)
			{
				ClearPlatform();
			}
		}

		internal static PlayerPhysics PlayerBody()
		{
			PlayerManager instance = Singleton<PlayerManager>.instance;
			object obj;
			if (instance == null)
			{
				obj = null;
			}
			else
			{
				Player localPlayer = instance.localPlayer;
				obj = ((localPlayer != null) ? localPlayer.Controller : null);
			}
			PlayerController val = (PlayerController)obj;
			if (!Object.op_Implicit((Object)(object)val))
			{
				return null;
			}
			return ((Component)val).GetComponentInChildren<PlayerPhysics>(true);
		}

		private static bool Nearest(Vector3 origin, float distance, out RaycastHit nearest)
		{
			//IL_0001: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			nearest = default(RaycastHit);
			float num = 1f / 0f;
			PlayerManager instance = Singleton<PlayerManager>.instance;
			object obj;
			if (instance == null)
			{
				obj = null;
			}
			else
			{
				Player localPlayer = instance.localPlayer;
				obj = ((localPlayer != null) ? localPlayer.Controller : null);
			}
			PlayerController val = (PlayerController)obj;
			System.Collections.Generic.IEnumerator<RaycastHit> enumerator = ((Il2CppArrayBase<RaycastHit>)(object)Physics.RaycastAll(origin, Vector3.down, distance, -1, (QueryTriggerInteraction)1)).GetEnumerator();
			try
			{
				while (((System.Collections.IEnumerator)enumerator).MoveNext())
				{
					RaycastHit current = enumerator.Current;
					if (Object.op_Implicit((Object)(object)((RaycastHit)(ref current)).collider) && (!Object.op_Implicit((Object)(object)val) || !((Component)((RaycastHit)(ref current)).collider).transform.IsChildOf(((Component)val).transform)) && ((RaycastHit)(ref current)).distance < num)
					{
						nearest = current;
						num = ((RaycastHit)(ref current)).distance;
					}
				}
			}
			finally
			{
				((System.IDisposable)enumerator)?.Dispose();
			}
			return !float.IsPositiveInfinity(num);
		}

		internal static void CheckSafetyOnce()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			if (!Enabled || !Runtime.GameplayAllowed)
			{
				return;
			}
			try
			{
				PlayerPhysics val = PlayerBody();
				if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val.PhysicsRigidbody))
				{
					MelonLogger.Warning("[SafetyPlatform] Player body unavailable; check skipped for this load.");
					return;
				}
				Vector3 position = val.PhysicsRigidbody.position;
				bool flag = false;
				float num = 1f / 0f;
				System.Collections.Generic.IEnumerator<Collider> enumerator = ((Component)val.PhysicsRigidbody).GetComponentsInChildren<Collider>().GetEnumerator();
				try
				{
					while (((System.Collections.IEnumerator)enumerator).MoveNext())
					{
						Collider current = enumerator.Current;
						if (current.enabled && !current.isTrigger && (Object)(object)current.attachedRigidbody == (Object)(object)val.PhysicsRigidbody)
						{
							float num2 = num;
							Bounds bounds = current.bounds;
							num = Math.Min(num2, ((Bounds)(ref bounds)).min.y);
							flag = true;
						}
					}
				}
				finally
				{
					((System.IDisposable)enumerator)?.Dispose();
				}
				if (!flag)
				{
					MelonLogger.Warning("[SafetyPlatform] Body collider unavailable; check skipped.");
					return;
				}
				position.y = num;
				CheckSafetyAt(position);
			}
			catch (System.Exception ex)
			{
				MelonLogger.Warning("[SafetyPlatform] " + ex.Message);
			}
		}

		internal static void CheckSafetyAt(Vector3 feet)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: 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)
			//IL_0112: Expected O, but got Unknown
			if (!Enabled || !Runtime.GameplayAllowed)
			{
				return;
			}
			Physics.SyncTransforms();
			if (Nearest(feet + Vector3.up * 0.1f, 0.6f, out var nearest) && ((RaycastHit)(ref nearest)).normal.y > 0.3f && !Object.op_Implicit((Object)(object)((Component)((RaycastHit)(ref nearest)).collider).GetComponentInParent<KillPlayerOnCollision>()))
			{
				MelonLogger.Msg("[SafetyPlatform] Supporting ground found; no platform needed.");
				return;
			}
			ClearPlatform();
			platform = GameObject.CreatePrimitive((PrimitiveType)3);
			((Object)platform).name = "GymMaps.SafetyPlatform";
			platform.layer = 9;
			platform.transform.localScale = new Vector3(4f, 0.25f, 4f);
			platform.transform.position = feet - Vector3.up * 0.175f;
			Shader val = Shader.Find("Universal Render Pipeline/Lit");
			if (Object.op_Implicit((Object)(object)val))
			{
				platformMaterial = new Material(val)
				{
					color = new Color(0.35f, 0.8f, 1f)
				};
				platform.GetComponent<Renderer>().sharedMaterial = platformMaterial;
			}
			Physics.SyncTransforms();
			MelonLogger.Msg("[SafetyPlatform] Created once beneath player after map load.");
		}

		internal static void SummonCube(GameObject marker)
		{
			Summon(marker, "RockCube");
		}

		internal static void Summon(GameObject marker, string resourceName)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			if (!Runtime.GameplayAllowed)
			{
				return;
			}
			Physics.SyncTransforms();
			if (!Nearest(marker.transform.position, 100f, out var nearest) || ((Component)((RaycastHit)(ref nearest)).collider).gameObject.layer != 9 || ((RaycastHit)(ref nearest)).normal.y < 0.5f || Object.op_Implicit((Object)(object)((Component)((RaycastHit)(ref nearest)).collider).GetComponentInParent<KillPlayerOnCollision>()) || Object.op_Implicit((Object)(object)((Component)((RaycastHit)(ref nearest)).collider).GetComponentInParent<KillStructureOnImpact>()) || Object.op_Implicit((Object)(object)((Component)((RaycastHit)(ref nearest)).collider).GetComponentInParent<Structure>()))
			{
				MelonLogger.Msg("[MapLoad] " + ((Object)marker).name + ": skipped; no summonable ground directly below.");
				return;
			}
			PoolManager instance = Singleton<PoolManager>.instance;
			if (!Object.op_Implicit((Object)(object)instance))
			{
				throw new InvalidOperationException("Structure pool unavailable.");
			}
			Structure val = null;
			Enumerator<Structure> enumerator = instance.GetAllStructurePrefabsFromPool().GetEnumerator();
			while (enumerator.MoveNext())
			{
				Structure current = enumerator.Current;
				if (Object.op_Implicit((Object)(object)current) && string.Equals(((PooledMonoBehaviour)current).ResourceName, resourceName, (StringComparison)5))
				{
					val = current;
					break;
				}
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				throw new InvalidOperationException("Gameplay " + resourceName + " prefab unavailable in structure pool.");
			}
			PooledMonoBehaviour pooledObject = instance.GetPooledObject(((PooledMonoBehaviour)val).ResourceName, ((RaycastHit)(ref nearest)).point, marker.transform.rotation);
			Structure cube = (Object.op_Implicit((Object)(object)pooledObject) ? ((Il2CppObjectBase)pooledObject).TryCast<Structure>() : null);
			if (!Object.op_Implicit((Object)(object)cube))
			{
				if (Object.op_Implicit((Object)(object)pooledObject))
				{
					pooledObject.ReturnToPool();
				}
				throw new InvalidOperationException("Pool did not return a gameplay Structure.");
			}
			structures[((Object)cube).GetInstanceID()] = cube;
			try
			{
				((Component)cube).transform.SetPositionAndRotation(((RaycastHit)(ref nearest)).point, marker.transform.rotation);
				Physics.SyncTransforms();
				if (!Object.op_Implicit((Object)(object)cube.rigidBody))
				{
					cube.rigidBody = ((Component)cube).GetComponentInChildren<Rigidbody>(true);
				}
				if (!Object.op_Implicit((Object)(object)cube.collider))
				{
					cube.collider = Enumerable.FirstOrDefault<Collider>((System.Collections.Generic.IEnumerable<Collider>)((Component)cube).GetComponentsInChildren<Collider>(true), (Func<Collider, bool>)((Collider c) => Object.op_Implicit((Object)(object)c) && !c.isTrigger && (Object)(object)c.attachedRigidbody == (Object)(object)cube.rigidBody));
				}
				if (!Object.op_Implicit((Object)(object)cube.collider))
				{
					throw new InvalidOperationException("Structure collider unavailable.");
				}
				Vector3 position = ((Component)cube).transform.position;
				ref float y = ref position.y;
				float num = y;
				float y2 = ((RaycastHit)(ref nearest)).point.y;
				Bounds bounds = cube.collider.bounds;
				y = num + (y2 - ((Bounds)(ref bounds)).min.y + 0.02f);
				((Component)cube).transform.SetPositionAndRotation(position, marker.transform.rotation);
				if (Object.op_Implicit((Object)(object)cube.rigidBody))
				{
					cube.rigidBody.position = position;
					cube.rigidBody.rotation = marker.transform.rotation;
					cube.rigidBody.velocity = Vector3.zero;
					cube.rigidBody.angularVelocity = Vector3.zero;
				}
				cube.CurrentPhysicsState = (PhysicsState)0;
				Physics.SyncTransforms();
				MelonLogger.Msg("[MapLoad] Summoned " + ((PooledMonoBehaviour)val).ResourceName + " for " + ((Object)marker).name);
			}
			catch
			{
				structures.Remove(((Object)cube).GetInstanceID());
				((PooledMonoBehaviour)cube).ReturnToPool();
				throw;
			}
		}

		internal static void Forget(Structure cube)
		{
			if (Object.op_Implicit((Object)(object)cube))
			{
				structures.Remove(((Object)cube).GetInstanceID());
			}
		}

		private static void ClearPlatform()
		{
			if (Object.op_Implicit((Object)(object)platform))
			{
				platform.SetActive(false);
				Object.Destroy((Object)(object)platform);
			}
			platform = null;
			if (Object.op_Implicit((Object)(object)platformMaterial))
			{
				Object.Destroy((Object)(object)platformMaterial);
			}
			platformMaterial = null;
		}

		internal static void Clear()
		{
			//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)
			ClearPlatform();
			List<Structure> obj = new List<Structure>((System.Collections.Generic.IEnumerable<Structure>)structures.Values);
			structures.Clear();
			Enumerator<Structure> enumerator = obj.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					Structure current = enumerator.Current;
					try
					{
						if (Object.op_Implicit((Object)(object)current) && !((PooledMonoBehaviour)current).IsInPool)
						{
							((PooledMonoBehaviour)current).ReturnToPool();
						}
					}
					catch (System.Exception ex)
					{
						MelonLogger.Warning("[MapLoad] Structure cleanup: " + ex.Message);
					}
				}
			}
			finally
			{
				((System.IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
			}
		}
	}
	[HarmonyPatch(typeof(Structure), "OnFetchFromPool")]
	internal static class CubeLeasePatch
	{
		private static void Prefix(Structure __instance)
		{
			LoadFeatures.Forget(__instance);
		}
	}
	public sealed class CommandContext
	{
		[field: CompilerGenerated]
		public string PrimitiveName
		{
			[CompilerGenerated]
			get;
		}

		public string MapName => Runtime.ActiveName;

		[field: CompilerGenerated]
		public GameObject Primitive
		{
			[CompilerGenerated]
			get;
		}

		internal CommandContext(GameObject primitive)
		{
			Primitive = primitive;
			PrimitiveName = ((Object)primitive).name;
		}
	}
	public static class MapCommands
	{
		private static readonly Dictionary<string, Action<CommandContext, string>> handlers = new Dictionary<string, Action<CommandContext, string>>((IEqualityComparer<string>)(object)StringComparer.OrdinalIgnoreCase);

		private static readonly Stopwatch timer = new Stopwatch();

		[field: CompilerGenerated]
		internal static bool Enabled
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			private set;
		}

		internal static void SetEnabled(bool enabled)
		{
			Enabled = enabled;
		}

		public static void Register(string name, Action<CommandContext, string> callback)
		{
			//IL_0027: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			if (!string.IsNullOrWhiteSpace(name))
			{
				char[] array = new char[4];
				RuntimeHelpers.InitializeArray((System.Array)array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
				if (name.IndexOfAny(array) < 0)
				{
					if (callback == null)
					{
						throw new ArgumentNullException("callback");
					}
					if (!handlers.TryAdd(name, callback))
					{
						throw new ArgumentException("Command already registered: " + name);
					}
					return;
				}
			}
			throw new ArgumentException("Command name must be one word.");
		}

		public static bool Unregister(string name)
		{
			return handlers.Remove(name);
		}

		private static string Name(string command)
		{
			return command.Split(new char[1] { ' ' }, 2)[0];
		}

		internal static void Validate(TriggerTags tags)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			System.Collections.Generic.IEnumerator<string> enumerator = Enumerable.Concat<string>((System.Collections.Generic.IEnumerable<string>)tags.OnEnter, (System.Collections.Generic.IEnumerable<string>)tags.OnLoad).GetEnumerator();
			try
			{
				while (((System.Collections.IEnumerator)enumerator).MoveNext())
				{
					string current = enumerator.Current;
					if (Name(current).Equals("interface.killfloor.height", (StringComparison)5) && !tags.Height.HasValue)
					{
						throw new FormatException("interface.killfloor.height requires a (Height=NUMBER) tag.");
					}
					string target;
					bool append;
					if (TryMapButton(current, out var mapName))
					{
						Runtime.ResolveMap(mapName);
					}
					else if (TryMapLoad(current, out target, out append))
					{
						Runtime.ResolveMap(target);
					}
					else if (!GameSounds.IsCommand(current) && !handlers.ContainsKey(Name(current)))
					{
						throw new FormatException("Unknown map command: " + Name(current));
					}
				}
			}
			finally
			{
				((System.IDisposable)enumerator)?.Dispose();
			}
		}

		internal static void Boot()
		{
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			SetEnabled(enabled: false);
			Register("log", delegate(CommandContext c, string args)
			{
				MelonLogger.Msg("[MapTrigger] " + c.PrimitiveName + ": " + args);
			});
			Register("status", delegate(CommandContext c, string args)
			{
				Runtime.ReportTrigger(args);
			});
			Register("timer.start", delegate
			{
				timer.Restart();
				Runtime.ReportTrigger("Timer started");
			});
			Register("timer.stop", delegate
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				timer.Stop();
				System.Runtime.CompilerServices.DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new System.Runtime.CompilerServices.DefaultInterpolatedStringHandler(9, 1);
				defaultInterpolatedStringHandler.AppendLiteral("Finish: ");
				TimeSpan elapsed = timer.Elapsed;
				defaultInterpolatedStringHandler.AppendFormatted<double>(((TimeSpan)(ref elapsed)).TotalSeconds, "F3");
				defaultInterpolatedStringHandler.AppendLiteral("s");
				Runtime.ReportTrigger(defaultInterpolatedStringHandler.ToStringAndClear());
			});
			Register("timer.reset", delegate
			{
				timer.Reset();
				Runtime.ReportTrigger("Timer reset");
			});
			Register("structure.summon.cube", delegate(CommandContext c, string args)
			{
				LoadFeatures.SummonCube(c.Primitive);
			});
			Enumerator<string, string> enumerator = new Dictionary<string, string>
			{
				["wall"] = "Wall",
				["pillar"] = "Pillar",
				["ball"] = "Ball",
				["disk"] = "Disc",
				["disc"] = "Disc"
			}.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					KeyValuePair<string, string> current = enumerator.Current;
					string resource = current.Value;
					Register("structure.summon." + current.Key, delegate(CommandContext c, string args)
					{
						LoadFeatures.Summon(c.Primitive, resource);
					});
				}
			}
			finally
			{
				((System.IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
			}
			Register("summon.asset.button.interface.teleport.gym", delegate(CommandContext c, string args)
			{
				AssetButtons.SpawnGym(c.Primitive);
			});
			Register("interface.respawn.start", delegate(CommandContext c, string args)
			{
				RespawnPoint.Set(c.Primitive);
			});
			Register("interface.killfloor.height", delegate(CommandContext c, string args)
			{
				MapTools.SetKillFloorHeight(TriggerTags.Parse(c.PrimitiveName).Height.Value);
			});
			Register("play.sound.telephone", delegate(CommandContext c, string args)
			{
				TelephoneSound.Play(c.Primitive);
			});
			Register("play.sound.firework", delegate(CommandContext c, string args)
			{
				FireworkSound.Play(c.Primitive);
			});
		}

		internal static void ResetMap()
		{
			timer.Reset();
			TelephoneSound.Clear();
			FireworkSound.Clear();
			GameSounds.Clear();
			LoadFeatures.Clear();
			RespawnPoint.Clear();
			MapTools.Clear();
			AssetButtons.Clear();
		}

		internal static void Shutdown()
		{
			handlers.Clear();
			ResetMap();
		}

		private static bool TryMapLoad(string command, out string target, out bool append)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			target = null;
			append = false;
			if (!command.StartsWith("map.load.", (StringComparison)5))
			{
				return false;
			}
			int num = command.LastIndexOf('.');
			if (num <= "map.load.".Length)
			{
				throw new FormatException("Map command needs a map name and replace/append: " + command);
			}
			string text = command.Substring(num + 1);
			append = text.Equals("append", (StringComparison)5);
			if (!append && !text.Equals("replace", (StringComparison)5))
			{
				throw new FormatException("Map command must end in .replace or .append: " + command);
			}
			target = command.Substring("map.load.".Length, num - "map.load.".Length);
			return true;
		}

		private static bool TryMapButton(string command, out string mapName)
		{
			//IL_0033: Unknown result type (might be due to i