Decompiled source of Severons Customizable Endless v0.5.45

OddsAndEnds.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using MortarLib;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("OddsAndEnds")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OddsAndEnds")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c6ff218e-780c-48ad-be27-6f6a178b97dd")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
public static class CustomLevelRegistry
{
	private static readonly Dictionary<string, M_Level> loaded = new Dictionary<string, M_Level>();

	public static void Register(string id, M_Level level)
	{
		loaded[id] = level;
	}

	public static M_Level Load(string id)
	{
		loaded.TryGetValue(id, out var value);
		return value;
	}
}
public static class CustomLevelLoader
{
	private static bool debug = false;

	private static readonly Dictionary<string, AssetBundle> _cachedBundles = new Dictionary<string, AssetBundle>(StringComparer.OrdinalIgnoreCase);

	public static LevelAssetHolder LoadRoom(string bundlePath, string assetName, string levelName)
	{
		//IL_0490: Unknown result type (might be due to invalid IL or missing references)
		//IL_04dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0638: Unknown result type (might be due to invalid IL or missing references)
		//IL_064c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0651: Unknown result type (might be due to invalid IL or missing references)
		//IL_0656: Unknown result type (might be due to invalid IL or missing references)
		//IL_0692: Unknown result type (might be due to invalid IL or missing references)
		//IL_0697: Unknown result type (might be due to invalid IL or missing references)
		//IL_06a7: Expected O, but got Unknown
		//IL_0668: Unknown result type (might be due to invalid IL or missing references)
		if (debug)
		{
			Debug.Log((object)("[LEVEL_LOADER] ---> LoadRoom started. Parameters passed: bundlePath='" + bundlePath + "', assetName='" + assetName + "', levelName='" + levelName + "'"));
		}
		string location = Assembly.GetExecutingAssembly().Location;
		if (debug)
		{
			Debug.Log((object)("[LEVEL_LOADER] Executing Assembly Location: '" + location + "'"));
		}
		string directoryName = Path.GetDirectoryName(location);
		if (debug)
		{
			Debug.Log((object)("[LEVEL_LOADER] Resolved Mod Folder: '" + directoryName + "'"));
		}
		if (string.IsNullOrEmpty(directoryName))
		{
			if (debug)
			{
				Debug.LogError((object)"[LEVEL_LOADER] CRITICAL: Mod folder path resolved to null or empty! Cannot safely build path.");
			}
			return null;
		}
		string text = Path.Combine(directoryName, bundlePath);
		if (debug)
		{
			Debug.Log((object)("[LEVEL_LOADER] Target AssetBundle Path: '" + text + "'"));
		}
		AssetBundle value = null;
		if (_cachedBundles.TryGetValue(text, out value) && (Object)(object)value != (Object)null)
		{
			if (debug)
			{
				Debug.Log((object)("[LEVEL_LOADER] Cache hit. Reusing already loaded AssetBundle for path: '" + text + "'"));
			}
		}
		else
		{
			if (debug)
			{
				Debug.Log((object)"[LEVEL_LOADER] Cache miss or stale reference. Loading AssetBundle from disk...");
			}
			if (!File.Exists(text))
			{
				if (debug)
				{
					Debug.LogError((object)("[LEVEL_LOADER] CRITICAL: AssetBundle file does NOT exist at path: '" + text + "'"));
				}
				return null;
			}
			if (debug)
			{
				Debug.Log((object)"[LEVEL_LOADER] File check passed. Attempting to load AssetBundle from file...");
			}
			try
			{
				value = AssetBundle.LoadFromFile(text);
			}
			catch (Exception ex)
			{
				if (debug)
				{
					Debug.LogError((object)("[LEVEL_LOADER] Exception thrown during AssetBundle.LoadFromFile: " + ex.Message + "\n" + ex.StackTrace));
				}
				return null;
			}
			if ((Object)(object)value == (Object)null)
			{
				if (debug)
				{
					Debug.LogError((object)("[LEVEL_LOADER] Failed to load AssetBundle '" + bundlePath + "'. Fucking dumbass."));
				}
				return null;
			}
			_cachedBundles[text] = value;
			if (debug)
			{
				Debug.Log((object)("[LEVEL_LOADER] AssetBundle successfully loaded and cached! Internal name: " + ((Object)value).name));
			}
		}
		if (debug)
		{
			Debug.Log((object)("[LEVEL_LOADER] Attempting to load asset '" + assetName + "' from bundle..."));
		}
		GameObject val = value.LoadAsset<GameObject>(assetName);
		if ((Object)(object)val == (Object)null)
		{
			if (debug)
			{
				Debug.LogError((object)("[LEVEL_LOADER] Couldn't find prefab '" + assetName + "' inside the bundle."));
			}
			string[] allAssetNames = value.GetAllAssetNames();
			if (debug)
			{
				Debug.LogWarning((object)$"[LEVEL_LOADER] Listing all ({allAssetNames.Length}) assets available inside this bundle to help identify mismatches:");
			}
			string[] array = allAssetNames;
			foreach (string text2 in array)
			{
				if (debug)
				{
					Debug.Log((object)(" -> Available Asset: '" + text2 + "'"));
				}
			}
			return null;
		}
		if (debug)
		{
			Debug.Log((object)("[LEVEL_LOADER] Prefab loaded successfully: " + ((Object)val).name));
		}
		if (debug)
		{
			Debug.Log((object)"[LEVEL_LOADER] Instantiating prefab...");
		}
		GameObject val2 = Object.Instantiate<GameObject>(val);
		Object.DontDestroyOnLoad((Object)(object)val2);
		((Object)val2).name = levelName;
		RestoreLightmaps(val2, value);
		if (debug)
		{
			Debug.Log((object)("[LEVEL_LOADER] Instantiated room instance named: '" + ((Object)val2).name + "'"));
		}
		if (debug)
		{
			Debug.Log((object)"[LEVEL_LOADER] Checking for M_Level component...");
		}
		M_Level val3 = val2.GetComponent<M_Level>();
		if ((Object)(object)val3 == (Object)null)
		{
			if (debug)
			{
				Debug.LogWarning((object)"[LEVEL_LOADER] M_Level component not found on root. Adding dynamically...");
			}
			val3 = val2.AddComponent<M_Level>();
		}
		else if (debug)
		{
			Debug.Log((object)"[LEVEL_LOADER] Existing M_Level component found on root.");
		}
		if (debug)
		{
			Debug.Log((object)"[LEVEL_LOADER] Searching for structural child components...");
		}
		Transform val4 = FindRecursiveContains(val2.transform, "entrance");
		Transform val5 = FindRecursiveContains(val2.transform, "exit");
		Transform val6 = FindRecursiveContains(val2.transform, "room");
		if ((Object)(object)val4 == (Object)null)
		{
			if (debug)
			{
				Debug.LogWarning((object)"[LEVEL_LOADER] Missing 'Entrance' Transform in hierarchy.");
			}
			else if (debug)
			{
				Debug.Log((object)$"[LEVEL_LOADER] Found 'Entrance' at local position: {val4.localPosition}");
			}
		}
		if ((Object)(object)val5 == (Object)null)
		{
			if (debug)
			{
				Debug.LogWarning((object)"[LEVEL_LOADER] Missing 'Exit' Transform in hierarchy.");
			}
			else if (debug)
			{
				Debug.Log((object)$"[LEVEL_LOADER] Found 'Exit' at local position: {val5.localPosition}");
			}
		}
		if ((Object)(object)val6 == (Object)null)
		{
			if (debug)
			{
				Debug.LogWarning((object)"[LEVEL_LOADER] Missing 'Room' geometry Transform in hierarchy.");
			}
			else if (debug)
			{
				Debug.Log((object)"[LEVEL_LOADER] Found 'Room' geometry component.");
			}
		}
		Transform[] componentsInChildren = val2.GetComponentsInChildren<Transform>(true);
		foreach (Transform val7 in componentsInChildren)
		{
			if (((Object)val7).name.IndexOf("handhold", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				ObjectTagger val8 = ((Component)val7).GetComponent<ObjectTagger>();
				if ((Object)(object)val8 == (Object)null)
				{
					val8 = ((Component)val7).gameObject.AddComponent<ObjectTagger>();
				}
				val8.AddTag("Handhold");
				((Object)val7).name = "handhold:basic-collide";
				MeshCollider component = ((Component)val7).GetComponent<MeshCollider>();
				if ((Object)(object)component != (Object)null)
				{
					((Collider)component).isTrigger = false;
				}
			}
		}
		if (debug)
		{
			Debug.Log((object)"[LEVEL_LOADER] Injecting properties into M_Level setup...");
		}
		val3.levelName = levelName;
		val3.levelEntrance = val4;
		val3.levelExit = val5;
		val3.isLODGap = false;
		val3.spawnPosition = val4;
		val3.customBounds = true;
		val3.levelBounds = new Bounds(new Vector3(0f, 0f, 0f), new Vector3(5f, 5f, 5f));
		if (debug)
		{
			Debug.Log((object)val3.CalculateBounds());
		}
		val3.canFlip = false;
		val3.showInLevelList = true;
		val3.allowEvents = true;
		val3.spawnSettings = new SpawnSettings
		{
			spawnChance = 1f
		};
		if (debug)
		{
			Debug.Log((object)"[LEVEL_LOADER] Invoking M_Level.LevelAssetHolder.GetNewHolderFromLevel...");
		}
		LevelAssetHolder val9 = null;
		try
		{
			val9 = LevelAssetHolder.GetNewHolderFromLevel(val3);
		}
		catch (Exception ex2)
		{
			if (debug)
			{
				Debug.LogError((object)("[LEVEL_LOADER] Exception thrown within GetNewHolderFromLevel: " + ex2.Message + "\n" + ex2.StackTrace));
			}
			return null;
		}
		if (val9 == null)
		{
			if (debug)
			{
				Debug.LogError((object)"[LEVEL_LOADER] GetNewHolderFromLevel returned null.");
			}
		}
		else if (debug)
		{
			Debug.Log((object)"[LEVEL_LOADER] Success! LevelAssetHolder generated and returned successfully.");
		}
		val2.SetActive(false);
		return val9;
	}

	private static Transform FindRecursiveContains(Transform root, string substring)
	{
		Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true);
		foreach (Transform val in componentsInChildren)
		{
			if (((Object)val).name.IndexOf(substring, StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return val;
			}
		}
		return null;
	}

	public static void ClearCache()
	{
		foreach (AssetBundle value in _cachedBundles.Values)
		{
			if ((Object)(object)value != (Object)null)
			{
				value.Unload(false);
			}
		}
		_cachedBundles.Clear();
		if (debug)
		{
			Debug.Log((object)"[LEVEL_LOADER] AssetBundle cache cleared.");
		}
	}

	private static void RestoreLightmaps(GameObject room, AssetBundle bundle)
	{
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: Expected O, but got Unknown
		//IL_026c: Unknown result type (might be due to invalid IL or missing references)
		if (debug)
		{
			Debug.Log((object)"[LIGHTMAP] ------------------------------");
		}
		List<Texture2D> list = new List<Texture2D>();
		List<Texture2D> list2 = new List<Texture2D>();
		Texture2D[] array = bundle.LoadAllAssets<Texture2D>();
		foreach (Texture2D val in array)
		{
			string text = ((Object)val).name.ToLowerInvariant();
			if (text.Contains("_comp_light"))
			{
				list.Add(val);
				if (debug)
				{
					Debug.Log((object)("[LIGHTMAP] Color: " + ((Object)val).name));
				}
			}
			else if (text.Contains("_comp_dir"))
			{
				list2.Add(val);
				if (debug)
				{
					Debug.Log((object)("[LIGHTMAP] Directional: " + ((Object)val).name));
				}
			}
		}
		list.Sort((Texture2D a, Texture2D b) => string.CompareOrdinal(((Object)a).name, ((Object)b).name));
		list2.Sort((Texture2D a, Texture2D b) => string.CompareOrdinal(((Object)a).name, ((Object)b).name));
		if (list.Count == 0)
		{
			if (debug)
			{
				Debug.LogWarning((object)"[LIGHTMAP] No baked lightmaps found.");
			}
			return;
		}
		LightmapData[] array2 = (LightmapData[])(object)new LightmapData[list.Count];
		for (int num = 0; num < list.Count; num++)
		{
			array2[num] = new LightmapData();
			array2[num].lightmapColor = list[num];
			if (num < list2.Count)
			{
				array2[num].lightmapDir = list2[num];
			}
			if (debug)
			{
				Debug.Log((object)$"[LIGHTMAP] Assigned map {num}");
			}
		}
		LightmapSettings.lightmaps = array2;
		if (debug)
		{
			Debug.Log((object)$"[LIGHTMAP] Installed {array2.Length} lightmaps.");
		}
		MeshRenderer[] componentsInChildren = room.GetComponentsInChildren<MeshRenderer>(true);
		foreach (MeshRenderer val2 in componentsInChildren)
		{
			if (debug)
			{
				Debug.Log((object)("[LIGHTMAP] " + ((Object)val2).name + "\n" + $"    index={((Renderer)val2).lightmapIndex}\n" + $"    scaleOffset={((Renderer)val2).lightmapScaleOffset}\n"));
			}
			if (((Renderer)val2).lightmapIndex >= array2.Length && debug)
			{
				Debug.LogWarning((object)$"{((Object)val2).name} references lightmap {((Renderer)val2).lightmapIndex} but only {array2.Length} exist.");
			}
		}
		Cubemap val3 = bundle.LoadAsset<Cubemap>("ReflectionProbe-0");
		if ((Object)(object)val3 != (Object)null)
		{
			RenderSettings.customReflectionTexture = (Texture)(object)val3;
			RenderSettings.defaultReflectionMode = (DefaultReflectionMode)1;
			if (debug)
			{
				Debug.Log((object)"[LIGHTMAP] Reflection probe restored.");
			}
		}
		DynamicGI.UpdateEnvironment();
		Renderer[] componentsInChildren2 = room.GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val4 in componentsInChildren2)
		{
			val4.enabled = false;
			val4.enabled = true;
		}
		if (debug)
		{
			Debug.Log((object)"[LIGHTMAP] Restore complete.");
		}
	}
}
namespace MortarLib
{
	public static class GameUtils
	{
		public static class Buffs
		{
			public const string WeaponSpeedUp = "weaponSpeedUp";

			public const string WeaponSpeedDown = "weaponSpeedDown";

			public const string WeaponRecoil = "weaponRecoil";

			public const string HangingGrounded = "hangingGrounded";

			public const string Jump = "addJump";

			public const string Stamina = "addStamina";

			public const string StaminaRegen = "addStaminaRegen";

			public const string ClimbSpeed = "addClimb";

			public const string Reach = "addReach";

			public const string Armor = "damageResist";

			public const string KnockbackArmor = "knockbackResist";

			public const string Vulnerability = "damageMult";

			public const string SlowMass = "massResist";

			public const string SlowTime = "slowTime";

			public const string Gravity = "addGravity";
		}

		private static Dictionary<string, GameObject> prefabCache = new Dictionary<string, GameObject>();

		public static float GetPlayerBuffAmount(string buffId)
		{
			ENT_Player player = ENT_Player.GetPlayer();
			if ((Object)(object)player != (Object)null && ((GameEntity)player).curBuffs != null)
			{
				return ((GameEntity)player).curBuffs.GetBuff(buffId);
			}
			return 0f;
		}

		private static void ApplyDamageAndForce(Collider collider, Vector3 hitPoint, float damage, float knockback, List<string> damageTags)
		{
			//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)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			ENT_Player player = ENT_Player.GetPlayer();
			ObjectTagger val = ((Component)collider).GetComponent<ObjectTagger>();
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Hitbox component = ((Component)val).GetComponent<Hitbox>();
			GameEntity val2 = ((component != null) ? component.GetGameEntity() : null);
			if ((Object)(object)val2 != (Object)null)
			{
				val = val2.GetTagger();
			}
			if (val.HasTag("Damageable"))
			{
				Damageable component2 = ((Component)collider).GetComponent<Damageable>();
				if (component2 != null)
				{
					DamageInfo val3 = DamageInfo.CreateDamageInfo(damage, "Melee", damageTags, (GameEntity)(object)player);
					val3.position = hitPoint;
					val3.sourceEntity = (GameEntity)(object)player;
					val3.sourceObject = ((Component)player).gameObject;
					component2.Damage(val3);
				}
			}
			if (knockback > 0f)
			{
				if ((val.HasTag("Prop") || val.HasTag("Denizen")) && (Object)(object)val2 != (Object)null)
				{
					val2.AddForceAtPosition(((Component)Camera.main).transform.forward * (knockback * 20f), hitPoint, "");
				}
				else if ((Object)(object)val2 != (Object)null)
				{
					val2.AddForce(((Component)Camera.main).transform.forward * (knockback * 10f), "");
				}
			}
		}

		public static GameObject GetCachedPrefab(string prefabName)
		{
			if (prefabCache.TryGetValue(prefabName, out var value) && (Object)(object)value != (Object)null)
			{
				return Object.Instantiate<GameObject>(value);
			}
			GameObject[] array = Resources.FindObjectsOfTypeAll<GameObject>();
			foreach (GameObject val in array)
			{
				if (((Object)val).name == prefabName)
				{
					prefabCache[prefabName] = val;
					return Object.Instantiate<GameObject>(val);
				}
			}
			return null;
		}

		public static bool ForceGrabHandhold(this Hand hand, Transform target, Vector3? customWorldPos = null)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			if (hand == null || (Object)(object)target == (Object)null)
			{
				return false;
			}
			CL_Handhold val = ((Component)target).GetComponent<CL_Handhold>() ?? ((Component)target).GetComponentInChildren<CL_Handhold>() ?? ((Component)target).GetComponentInParent<CL_Handhold>();
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			Vector3 val2 = (Vector3)(((??)customWorldPos) ?? ((Component)val).transform.position);
			if (hand.IsHolding())
			{
				hand.DropHand(true);
			}
			hand.GrabHold(((Component)val).transform, val2, (InteractionInfo)null);
			return true;
		}

		public static bool HasPlayerBuff(string buffId)
		{
			ENT_Player player = ENT_Player.GetPlayer();
			return (Object)(object)player != (Object)null && ((GameEntity)player).curBuffs != null && ((GameEntity)player).curBuffs.GetBuff(buffId) != 0f;
		}

		public static void ApplyRecoil(float forceMultiplier)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			ENT_Player player = ENT_Player.GetPlayer();
			if ((Object)(object)player != (Object)null && (Object)(object)Camera.main != (Object)null)
			{
				Vector3 val = -((Component)Camera.main).transform.forward * forceMultiplier;
				((GameEntity)player).AddForce(val, "");
			}
		}

		public static void RestoreHandItemState(HandItem item, int targetUses = 3)
		{
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Invalid comparison between Unknown and I4
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Invalid comparison between Unknown and I4
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Invalid comparison between Unknown and I4
			item.used = false;
			Traverse val = Traverse.Create((object)item.item).Method("SetUsed", new object[1] { false });
			if (val.MethodExists())
			{
				val.GetValue();
			}
			string firstDataStringByType = item.item.GetFirstDataStringByType("uses", false);
			if (!string.IsNullOrEmpty(firstDataStringByType) && int.TryParse(firstDataStringByType, out var result) && result <= 0)
			{
				item.item.SetFirstDataStringsofType("uses", "1");
				Traverse val2 = Traverse.Create((object)item).Field("uses");
				if (val2.FieldExists())
				{
					val2.SetValue((object)targetUses);
				}
			}
			if ((Object)(object)item.anim != (Object)null)
			{
				item.anim.Rebind();
				AnimatorControllerParameter[] parameters = item.anim.parameters;
				foreach (AnimatorControllerParameter val3 in parameters)
				{
					int result2;
					if (val3.name == "Empty" && (int)val3.type == 4)
					{
						item.anim.SetBool("Empty", false);
					}
					else if (val3.name == "Squeeze" && (int)val3.type == 4)
					{
						item.anim.SetBool("Squeeze", false);
					}
					else if (val3.name == "Uses" && (int)val3.type == 3 && int.TryParse(item.item.GetFirstDataStringByType("uses", false), out result2))
					{
						item.anim.SetInteger("Uses", result2);
					}
				}
				item.anim.Update(0f);
			}
			Hand_Takeover val4 = ((Component)item).GetComponent<Hand_Takeover>() ?? ((Component)item).GetComponentInChildren<Hand_Takeover>();
			if ((Object)(object)val4 != (Object)null)
			{
				val4.blend = 0f;
				Traverse val5 = Traverse.Create((object)val4).Field("curBlend");
				if (val5.FieldExists())
				{
					val5.SetValue((object)0f);
				}
			}
			HandItem_BlinkEye val6 = (HandItem_BlinkEye)(object)((item is HandItem_BlinkEye) ? item : null);
			if (val6 != null)
			{
				val6.CancelBlink();
				if ((Object)(object)val6.crushEffect != (Object)null)
				{
					val6.crushEffect.Stop();
				}
			}
			HandItem_Food val7 = (HandItem_Food)(object)((item is HandItem_Food) ? item : null);
			if (val7 != null)
			{
				val7.FinishEating();
			}
			item.Refresh();
		}

		public static void PlaySoundByName(string clipName, Vector3 position)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			AudioClip[] array = Resources.FindObjectsOfTypeAll<AudioClip>();
			AudioClip[] array2 = array;
			foreach (AudioClip val in array2)
			{
				if (((Object)val).name == clipName)
				{
					AudioManager.PlaySound(val, position, 1f, 1f, 1f, false, 1f, (AudioMixerGroup)null, "");
					break;
				}
			}
		}

		public static void ModifyHandhold(CL_Handhold handhold, float climb = 0f, float jump = 0f, float staminaDrain = 0f, float staminaJumpDrain = 0f, float grav = 0f)
		{
			if (!((Object)(object)handhold == (Object)null))
			{
				handhold.climbMult += climb;
				handhold.jumpMult += jump;
				handhold.strainRate += staminaDrain;
				handhold.jumpStrainMult += staminaJumpDrain;
				handhold.climbGrav += grav;
			}
		}
	}
	[HarmonyPatch(typeof(HandItem_Shoot), "Update")]
	public class Patch_HandItem_Shoot_Speed
	{
		private static void Postfix(HandItem_Shoot __instance)
		{
			if (!((Object)(object)((HandItem)__instance).anim == (Object)null) && ((Hand_Base)__instance).hand != null)
			{
				float num = 1f;
				num += GameUtils.GetPlayerBuffAmount("weaponSpeedUp");
				num -= GameUtils.GetPlayerBuffAmount("weaponSpeedDown");
				((HandItem)__instance).anim.speed = Mathf.Max(0.04f, num);
			}
		}
	}
	[HarmonyPatch(typeof(HandItem_Melee), "Update")]
	public class Patch_HandItem_Melee_Speed
	{
		private static readonly AnimationCurve SlowIntensityCurve = new AnimationCurve((Keyframe[])(object)new Keyframe[3]
		{
			new Keyframe(0f, 3f),
			new Keyframe(0.05f, 0f),
			new Keyframe(1f, 0.2f)
		});

		private static void Postfix(HandItem_Melee __instance)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)((HandItem)__instance).anim == (Object)null) && ((Hand_Base)__instance).hand != null)
			{
				float num = 1f;
				num += GameUtils.GetPlayerBuffAmount("weaponSpeedUp");
				float playerBuffAmount = GameUtils.GetPlayerBuffAmount("weaponSpeedDown");
				if (playerBuffAmount > 0f)
				{
					AnimatorStateInfo currentAnimatorStateInfo = ((HandItem)__instance).anim.GetCurrentAnimatorStateInfo(0);
					float num2 = ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).normalizedTime % 1f;
					float num3 = SlowIntensityCurve.Evaluate(num2);
					num -= playerBuffAmount * num3;
				}
				((HandItem)__instance).anim.speed = Mathf.Max(0.04f, num);
			}
		}
	}
	[HarmonyPatch(typeof(HandItem_Shoot), "Shoot")]
	public class Patch_HandItem_Shoot_Recoil
	{
		public static void Postfix()
		{
			float playerBuffAmount = GameUtils.GetPlayerBuffAmount("weaponRecoil");
			if (playerBuffAmount > 0f)
			{
				GameUtils.ApplyRecoil(playerBuffAmount);
			}
		}
	}
	[HarmonyPatch(typeof(HandItem_Melee), "Hit")]
	public class Patch_HandItem_Melee_Hit_Recoil
	{
		public static void Postfix()
		{
			float playerBuffAmount = GameUtils.GetPlayerBuffAmount("weaponRecoil");
			if (playerBuffAmount > 0f)
			{
				GameUtils.ApplyRecoil(playerBuffAmount * 0.65f);
			}
		}
	}
	[HarmonyPatch(typeof(HandItem_Melee), "OnChargeAttack")]
	public class Patch_HandItem_Melee_Charge_Recoil
	{
		public static void Postfix()
		{
			float playerBuffAmount = GameUtils.GetPlayerBuffAmount("weaponRecoil");
			if (playerBuffAmount > 0f)
			{
				GameUtils.ApplyRecoil(playerBuffAmount);
			}
		}
	}
	[HarmonyPatch(typeof(Hand), "DamageGripStrength")]
	public class Patch_PlayerHand_IronGrip
	{
		public static bool Prefix()
		{
			return !GameUtils.HasPlayerBuff("ironGrip");
		}
	}
	public static class Patch_PlayerGroundedSpoofer
	{
		[HarmonyPatch(typeof(ENT_Player), "Movement")]
		public static class MovementPatch
		{
			[HarmonyPrefix]
			public static void Prefix()
			{
				_isUpdatingPhysics = true;
			}

			[HarmonyPostfix]
			public static void Postfix()
			{
				_isUpdatingPhysics = false;
			}
		}

		[HarmonyPatch(typeof(ENT_Player), "IsGrounded", new Type[] { typeof(bool) })]
		public static class IsGroundedPatch
		{
			[HarmonyPrefix]
			public static bool Prefix(ENT_Player __instance, ref bool __result)
			{
				if (_isUpdatingPhysics)
				{
					return true;
				}
				if (GameUtils.HasPlayerBuff("hangingGrounded") && __instance.IsHanging())
				{
					__result = true;
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(ENT_Player), "IsCrouching")]
		public static class IsCrouchingPatch
		{
			[HarmonyPrefix]
			public static bool Prefix(ENT_Player __instance, ref bool __result)
			{
				if (_isUpdatingPhysics)
				{
					return true;
				}
				if (GameUtils.HasPlayerBuff("hangingGrounded") && __instance.IsHanging())
				{
					__result = true;
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(ENT_Player), "Jump")]
		public static class JumpPatch
		{
			private static bool _wasSpoofed;

			private static bool _realCrouching;

			private static bool _realIsGrounded;

			private static PlayerState _realPlayerState;

			[HarmonyPrefix]
			public static void Prefix(ENT_Player __instance, ref bool ___crouching, ref bool ___isGrounded, ref PlayerState ___playerState)
			{
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Invalid comparison between Unknown and I4
				//IL_006b: Unknown result type (might be due to invalid IL or missing references)
				if (!GameUtils.HasPlayerBuff("hangingGrounded") || !__instance.IsHanging())
				{
					return;
				}
				Hand[] hands = __instance.hands;
				foreach (Hand val in hands)
				{
					if ((int)val.interactState == 4)
					{
						__instance.StopInteraction(val.id, "jump", true);
					}
				}
				_realCrouching = ___crouching;
				_realIsGrounded = ___isGrounded;
				_realPlayerState = ___playerState;
				_wasSpoofed = true;
				___crouching = true;
				___isGrounded = true;
				___playerState = (PlayerState)0;
			}

			[HarmonyPostfix]
			public static void Postfix(ref bool ___crouching, ref bool ___isGrounded, ref PlayerState ___playerState)
			{
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Expected I4, but got Unknown
				if (_wasSpoofed)
				{
					___crouching = _realCrouching;
					___isGrounded = _realIsGrounded;
					___playerState = (PlayerState)(int)_realPlayerState;
					_wasSpoofed = false;
				}
			}
		}

		private static bool _isUpdatingPhysics;
	}
	public class PerkBuilder
	{
		private readonly Perk _perk;

		public PerkBuilder(string id, string title)
		{
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Expected O, but got Unknown
			_perk = ScriptableObject.CreateInstance<Perk>();
			((Object)_perk).hideFlags = (HideFlags)61;
			_perk.id = id;
			((Object)_perk).name = "perk_" + id.Replace("_perk", "");
			_perk.title = title;
			_perk.description = string.Empty;
			_perk.cost = 0;
			_perk.canStack = true;
			_perk.stackMax = 100;
			_perk.useBuff = false;
			_perk.buffMultiplier = 1f;
			_perk.multiplierCurve = AnimationCurve.Linear(0f, 1f, 1f, 1f);
			_perk.modules = new List<PerkModule>();
			_perk.buff = new BuffContainer
			{
				buffs = new List<Buff>()
			};
		}

		public PerkBuilder WithDescription(string description)
		{
			_perk.description = description;
			return this;
		}

		public PerkBuilder WithStacking(bool canStack, int maxStack = 100)
		{
			_perk.canStack = canStack;
			_perk.stackMax = ((!canStack) ? 1 : maxStack);
			return this;
		}

		public PerkBuilder WithBuff(string buffId, string statId, float amount, float maxAmount = -1f)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			_perk.useBuff = true;
			_perk.buff.id = buffId;
			_perk.buff.loseOverTime = false;
			_perk.buff.buffTime = 1f;
			_perk.buff.multiplier = 1f;
			_perk.buff.buffs.Add(new Buff
			{
				id = statId,
				amount = amount,
				maxAmount = ((maxAmount == -1f) ? amount : maxAmount)
			});
			return this;
		}

		public PerkBuilder AddModule(PerkModule module)
		{
			_perk.modules.Add(module);
			return this;
		}

		public Perk Build()
		{
			return _perk;
		}
	}
	public static class PerkRegistry
	{
		private static readonly Dictionary<string, List<Perk>> _registry = new Dictionary<string, List<Perk>>();

		public static void Register(string modId, Perk perk)
		{
			if (!_registry.ContainsKey(modId))
			{
				_registry[modId] = new List<Perk>();
			}
			if (!_registry[modId].Contains(perk))
			{
				_registry[modId].Add(perk);
			}
		}

		public static void Inject(string modId, string databaseId, PerkPool pool = (PerkPool)5, string tag = "mortar")
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			if (!_registry.TryGetValue(modId, out var value) || value.Count == 0)
			{
				return;
			}
			WKAssetDatabase val = ScriptableObject.CreateInstance<WKAssetDatabase>();
			val.id = databaseId;
			foreach (Perk item in value)
			{
				item.spawnPool = pool;
				if (item.tags == null)
				{
					item.tags = new List<string>();
				}
				if (!item.tags.Contains(tag))
				{
					item.tags.Add(tag);
				}
			}
			val.perkAssets.AddRange(value);
			CL_AssetManager.AddNewDatabase(val.id, val);
		}
	}
}
namespace Severon.OddsAndEnds
{
	[HarmonyPatch(typeof(UI_GamemodeSetting), "ToggleSetting")]
	public static class UI_GamemodeSetting_ToggleSetting_Patch
	{
		private static void Postfix()
		{
			EndlessConfiguration.UpdateRegions();
		}
	}
	[HarmonyPatch(typeof(UI_GamemodeScreen_Panel), "LoadGamemode")]
	public static class UI_GamemodeScreen_Panel_LoadGamemode_Patch
	{
		private static void Postfix(UI_GamemodeScreen_Panel __instance)
		{
			if ((Object)(object)__instance.GetGamemode() == (Object)(object)EndlessConfiguration.EndlessMode)
			{
				EndlessConfiguration.UpdateRegions();
				EndlessConfiguration.CustomUIManager.SetCustomUIVisibility(visible: true);
			}
			else
			{
				EndlessConfiguration.CustomUIManager.SetCustomUIVisibility(visible: false);
			}
		}
	}
	[HarmonyPatch(typeof(DEN_DeathFloor), "Start")]
	internal class DeathFloor_Start
	{
		private static void Postfix(DEN_DeathFloor __instance)
		{
			if (!((Object)(object)CL_GameManager.GetCurrentGamemode() != (Object)(object)EndlessConfiguration.EndlessMode))
			{
				EndlessConfiguration.ApplyConfiguredBuffs();
				__instance.SetSpeedMultiplier(__instance.GetCurrentSpeedMult() * EndlessConfiguration.CustomUIManager.GetFloatState("mass_speed_mult"));
				__instance.SetSpeed(__instance.GetCurrentSpeed() * EndlessConfiguration.CustomUIManager.GetFloatState("mass_start_speed"));
				__instance.SetSpeedIncreaseMultiplier(EndlessConfiguration.CustomUIManager.GetFloatState("mass_accel_mult"));
				__instance.rubberbandMult = EndlessConfiguration.CustomUIManager.GetFloatState("mass_rubberband_mult");
				__instance.SetRubberbandActive(EndlessConfiguration.CustomUIManager.GetToggleState("mass_rubberband_enabled"));
			}
		}
	}
	[HarmonyPatch(typeof(UI_GamemodeScreen_Panel), "Initialize")]
	public static class UI_GamemodeScreen_Panel_ScrollSettings_Patch
	{
		private static readonly string Marker = "Custom_Settings_Scroll";

		private static void Postfix(UI_GamemodeScreen_Panel __instance)
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: 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_01e7: Expected O, but got Unknown
			EndlessConfiguration.CustomUIManager.InitializeCustomUI(__instance);
			Transform settingRoot = __instance.settingRoot;
			if (!((Object)(object)settingRoot == (Object)null) && !((Object)(object)settingRoot.Find(Marker) != (Object)null))
			{
				RectTransform component = ((Component)settingRoot).GetComponent<RectTransform>();
				GameObject val = new GameObject(Marker, new Type[4]
				{
					typeof(RectTransform),
					typeof(Image),
					typeof(Mask),
					typeof(ScrollRect)
				});
				RectTransform component2 = val.GetComponent<RectTransform>();
				((Transform)component2).SetParent(settingRoot.parent, false);
				component2.anchorMin = component.anchorMin;
				component2.anchorMax = component.anchorMax;
				component2.offsetMin = component.offsetMin;
				component2.offsetMax = component.offsetMax;
				component2.pivot = component.pivot;
				Image component3 = val.GetComponent<Image>();
				((Behaviour)component3).enabled = false;
				Mask component4 = val.GetComponent<Mask>();
				component4.showMaskGraphic = false;
				settingRoot.SetParent(val.transform, false);
				component.anchorMin = new Vector2(0f, 1f);
				component.anchorMax = new Vector2(1f, 1f);
				component.pivot = new Vector2(0.5f, 1f);
				component.offsetMin = new Vector2(0f, component.offsetMin.y);
				component.offsetMax = new Vector2(0f, component.offsetMax.y);
				VerticalLayoutGroup val2 = ((Component)settingRoot).GetComponent<VerticalLayoutGroup>();
				if ((Object)(object)val2 == (Object)null)
				{
					val2 = ((Component)settingRoot).gameObject.AddComponent<VerticalLayoutGroup>();
				}
				((HorizontalOrVerticalLayoutGroup)val2).childControlHeight = false;
				((HorizontalOrVerticalLayoutGroup)val2).childControlWidth = true;
				((HorizontalOrVerticalLayoutGroup)val2).childForceExpandHeight = false;
				((HorizontalOrVerticalLayoutGroup)val2).childForceExpandWidth = true;
				((HorizontalOrVerticalLayoutGroup)val2).spacing = 0f;
				((LayoutGroup)val2).padding = new RectOffset(8, 8, 0, 0);
				ContentSizeFitter val3 = ((Component)settingRoot).GetComponent<ContentSizeFitter>();
				if ((Object)(object)val3 == (Object)null)
				{
					val3 = ((Component)settingRoot).gameObject.AddComponent<ContentSizeFitter>();
				}
				val3.verticalFit = (FitMode)2;
				val3.horizontalFit = (FitMode)0;
				ScrollRect component5 = val.GetComponent<ScrollRect>();
				component5.content = component;
				component5.horizontal = false;
				component5.vertical = true;
				component5.movementType = (MovementType)2;
				LayoutRebuilder.ForceRebuildLayoutImmediate(component);
			}
		}
	}
	public static class EndlessConfiguration
	{
		private class RegionDefinition
		{
			public string RegionAsset;

			public string BreakroomAsset;
		}

		public static class CustomUIManager
		{
			public static GameObject CustomToggleButton;

			public static GameObject CustomMenuPanel;

			public static Dictionary<string, bool> SettingToggles = new Dictionary<string, bool>();

			public static Dictionary<string, int> SettingCounts = new Dictionary<string, int>();

			public static Dictionary<string, float> SettingFloats = new Dictionary<string, float>();

			public static Dictionary<string, string> SettingStrings = new Dictionary<string, string>();

			private static void RebuildLayouts(RectTransform rect)
			{
				while ((Object)(object)rect != (Object)null)
				{
					LayoutRebuilder.ForceRebuildLayoutImmediate(rect);
					Canvas.ForceUpdateCanvases();
					Transform parent = ((Transform)rect).parent;
					rect = (RectTransform)(object)((parent is RectTransform) ? parent : null);
				}
			}

			public static void ApplyConfiguredBuffs()
			{
				ENT_Player player = ENT_Player.GetPlayer();
				if ((Object)(object)player == (Object)null)
				{
					return;
				}
				(string, string, string)[] buffSettings = BuffSettings;
				for (int i = 0; i < buffSettings.Length; i++)
				{
					(string, string, string) tuple = buffSettings[i];
					float floatState = GetFloatState(tuple.Item1);
					if (!Mathf.Approximately(floatState, 0f))
					{
						Perk val = new PerkBuilder("endless_" + tuple.Item1, tuple.Item2).WithBuff("endless_" + tuple.Item1 + "_buff", tuple.Item3, floatState).Build();
						player.AddPerk(val, 1, true);
					}
				}
				if (GetToggleState("buff_inf_charge"))
				{
					player.AddPerk(new PerkBuilder("endless_infcharge", "Infinite Charge").WithBuff("endless_infcharge_buff", "infiniteCharge", 1f).Build(), 1, true);
				}
				if (GetToggleState("buff_hang_grounded"))
				{
					player.AddPerk(new PerkBuilder("endless_grounded", "Grounded While Hanging").WithBuff("endless_grounded_buff", "hangingGrounded", 1f).Build(), 1, true);
				}
			}

			public static string GetStringState(string id)
			{
				string value;
				return SettingStrings.TryGetValue(id, out value) ? value : string.Empty;
			}

			public static bool GetToggleState(string id)
			{
				bool value;
				return SettingToggles.TryGetValue(id, out value) && value;
			}

			public static int GetCountState(string id)
			{
				int value;
				return SettingCounts.TryGetValue(id, out value) ? value : 0;
			}

			public static float GetFloatState(string id)
			{
				float value;
				return SettingFloats.TryGetValue(id, out value) ? value : 0f;
			}

			public static void SetCustomUIVisibility(bool visible)
			{
				if ((Object)(object)CustomToggleButton != (Object)null)
				{
					CustomToggleButton.SetActive(visible);
				}
				if ((Object)(object)CustomMenuPanel != (Object)null)
				{
					CustomMenuPanel.SetActive(false);
				}
			}

			public static void InitializeCustomUI(UI_GamemodeScreen_Panel panel)
			{
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: Expected O, but got Unknown
				//IL_0083: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0135: Unknown result type (might be due to invalid IL or missing references)
				//IL_015a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0170: 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)
				//IL_019c: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_01db: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
				//IL_0207: Unknown result type (might be due to invalid IL or missing references)
				//IL_021d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0233: Unknown result type (might be due to invalid IL or missing references)
				//IL_0276: 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_02ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
				//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0326: Unknown result type (might be due to invalid IL or missing references)
				//IL_032d: Expected O, but got Unknown
				//IL_0350: Unknown result type (might be due to invalid IL or missing references)
				//IL_035d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0374: Unknown result type (might be due to invalid IL or missing references)
				//IL_038b: Unknown result type (might be due to invalid IL or missing references)
				//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
				//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_0413: Unknown result type (might be due to invalid IL or missing references)
				//IL_041a: Expected O, but got Unknown
				//IL_0444: Unknown result type (might be due to invalid IL or missing references)
				//IL_045b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0472: Unknown result type (might be due to invalid IL or missing references)
				//IL_0489: Unknown result type (might be due to invalid IL or missing references)
				//IL_04d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_04de: Expected O, but got Unknown
				if ((Object)(object)CustomToggleButton != (Object)null)
				{
					return;
				}
				CustomMenuPanel = new GameObject("CustomMenuPanel", new Type[2]
				{
					typeof(RectTransform),
					typeof(Image)
				});
				CustomMenuPanel.transform.SetParent(((Component)panel).transform, false);
				RectTransform panelRt = CustomMenuPanel.GetComponent<RectTransform>();
				panelRt.anchorMin = new Vector2(0.5f, 0.5f);
				panelRt.anchorMax = new Vector2(0.5f, 0.5f);
				panelRt.pivot = new Vector2(0.5f, 0.5f);
				panelRt.sizeDelta = new Vector2(450f, 550f);
				((Graphic)CustomMenuPanel.GetComponent<Image>()).color = new Color(0.12f, 0.12f, 0.12f, 0.95f);
				CustomMenuPanel.SetActive(true);
				CustomToggleButton = CreateButton("E+", ((Component)panel).transform, delegate
				{
					if ((Object)(object)CustomMenuPanel != (Object)null)
					{
						RebuildLayouts(panelRt);
						CustomMenuPanel.SetActive(!CustomMenuPanel.activeSelf);
						RebuildLayouts(panelRt);
					}
				}, new Vector2(40f, 40f));
				RectTransform component = CustomToggleButton.GetComponent<RectTransform>();
				component.anchorMin = new Vector2(0.5f, 0.9f);
				component.anchorMax = new Vector2(0.5f, 0.9f);
				component.pivot = new Vector2(0.5f, 0.5f);
				component.anchoredPosition = new Vector2(0f, -15f);
				GameObject val = CreateText("ENDLESS SETTINGS", CustomMenuPanel.transform, 16, (TextAnchor)4, Color.yellow);
				RectTransform component2 = val.GetComponent<RectTransform>();
				component2.anchorMin = new Vector2(0f, 1f);
				component2.anchorMax = new Vector2(1f, 1f);
				component2.pivot = new Vector2(0.5f, 1f);
				component2.sizeDelta = new Vector2(0f, 40f);
				component2.anchoredPosition = new Vector2(0f, 0f);
				GameObject val2 = CreateButton("X", CustomMenuPanel.transform, delegate
				{
					CustomMenuPanel.SetActive(false);
				}, new Vector2(30f, 30f));
				RectTransform component3 = val2.GetComponent<RectTransform>();
				component3.anchorMin = new Vector2(1f, 1f);
				component3.anchorMax = new Vector2(1f, 1f);
				component3.pivot = new Vector2(1f, 1f);
				component3.anchoredPosition = new Vector2(-5f, -5f);
				GameObject val3 = new GameObject("ScrollContainer", new Type[4]
				{
					typeof(RectTransform),
					typeof(Image),
					typeof(Mask),
					typeof(ScrollRect)
				});
				val3.transform.SetParent(CustomMenuPanel.transform, false);
				RectTransform component4 = val3.GetComponent<RectTransform>();
				component4.anchorMin = Vector2.zero;
				component4.anchorMax = Vector2.one;
				component4.pivot = new Vector2(0.5f, 0.5f);
				component4.offsetMin = new Vector2(10f, 10f);
				component4.offsetMax = new Vector2(-10f, -45f);
				((Graphic)val3.GetComponent<Image>()).color = new Color(0f, 0f, 0f, 0.3f);
				val3.GetComponent<Mask>().showMaskGraphic = false;
				GameObject val4 = new GameObject("Content", new Type[3]
				{
					typeof(RectTransform),
					typeof(VerticalLayoutGroup),
					typeof(ContentSizeFitter)
				});
				val4.transform.SetParent(val3.transform, false);
				RectTransform component5 = val4.GetComponent<RectTransform>();
				component5.anchorMin = new Vector2(0f, 1f);
				component5.anchorMax = new Vector2(1f, 1f);
				component5.pivot = new Vector2(0.5f, 1f);
				component5.sizeDelta = new Vector2(0f, 0f);
				VerticalLayoutGroup component6 = val4.GetComponent<VerticalLayoutGroup>();
				((HorizontalOrVerticalLayoutGroup)component6).childControlWidth = true;
				((HorizontalOrVerticalLayoutGroup)component6).childControlHeight = false;
				((HorizontalOrVerticalLayoutGroup)component6).childForceExpandWidth = true;
				((HorizontalOrVerticalLayoutGroup)component6).childForceExpandHeight = false;
				((HorizontalOrVerticalLayoutGroup)component6).spacing = 10f;
				((LayoutGroup)component6).padding = new RectOffset(5, 5, 5, 5);
				ContentSizeFitter component7 = val4.GetComponent<ContentSizeFitter>();
				component7.verticalFit = (FitMode)2;
				component7.horizontalFit = (FitMode)0;
				ScrollRect component8 = val3.GetComponent<ScrollRect>();
				component8.content = component5;
				component8.horizontal = false;
				component8.vertical = true;
				component8.movementType = (MovementType)2;
				component8.scrollSensitivity = 7f;
				RebuildLayouts(component5);
				SetCustomUIVisibility(visible: true);
				CreateCollapsibleGroup("REGIONS", val4.transform, out var groupContent);
				string[] array = new string[6] { "Silos", "Pipeworks", "Habitation", "Abyss", "Nest", "Ladder" };
				List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>(SubregionKeywords);
				for (int num = 0; num < array.Length; num++)
				{
					string text = array[num];
					string text2 = text.ToLower();
					CreateCollapsibleGroup(text.ToUpper() + " SETTINGS", groupContent, out var groupContent2);
					CreateCounter("Loops", text2 + "_loops", groupContent2, delegate
					{
						UpdateRegions();
					}, (text == "Silos") ? 1 : 0);
					CreateFloatCounter("Length Multiplier", text2 + "_length_mult", groupContent2, delegate
					{
						UpdateRegions();
					}, 1f, 0.25f);
					CreateCounter("Break Rooms", text2 + "_breakrooms", groupContent2, delegate
					{
						UpdateRegions();
					}, 1);
					CreateToggle("Break Rooms First", text2 + "_breakroom_first", groupContent2, delegate
					{
						UpdateRegions();
					});
					for (int num2 = 0; num2 < 3; num2++)
					{
						int num3 = num * 3 + num2;
						if (num3 < list.Count)
						{
							KeyValuePair<string, string> keyValuePair = list[num3];
							CreateCollapsibleGroup(keyValuePair.Value.ToUpper(), groupContent2, out var groupContent3);
							CreateToggle("Exclude", "subregion_" + keyValuePair.Key + "_disabled", groupContent3, delegate
							{
								UpdateRegions();
							});
							CreateFloatCounter("Difficulty", "subregion_" + keyValuePair.Key + "_difficulty_mult", groupContent3, delegate
							{
								UpdateRegions();
							});
							CreateFloatCounter("Mass Speed", "subregion_" + keyValuePair.Key + "_mass_mult", groupContent3, delegate
							{
								UpdateRegions();
							});
							CreateFloatCounter("Space Compression", "subregion_" + keyValuePair.Key + "_space_mult", groupContent3, delegate
							{
								UpdateRegions();
							});
						}
					}
				}
				CreateCollapsibleGroup("ORDERING", groupContent, out var groupContent4);
				CreateToggle("USE ORDERED GENERATION", "ordered_gen_enabled", groupContent4, delegate
				{
				});
				List<string> list2 = new List<string>(array) { "Silos Breakroom", "Silos Campaign Breakroom" };
				list2.Insert(0, "None");
				string[] options = list2.ToArray();
				for (int num4 = 0; num4 < 20; num4++)
				{
					CreateDropdownSelector($"SLOT {num4 + 1}", $"slot_{num4}_contents", groupContent4, options, delegate
					{
					});
					CreateCounter($"SLOT {num4 + 1} loops", $"slot_{num4}_loops", groupContent4, delegate
					{
					}, 1);
				}
				CreateCollapsibleGroup("STARTING ITEMS", val4.transform, out var groupContent5);
				foreach (KeyValuePair<string, string> startingItemTitle in StartingItemTitles)
				{
					CreateCounter(startingItemTitle.Value, startingItemTitle.Key, groupContent5, delegate
					{
					});
				}
				CreateCollapsibleGroup("STARTING PERKS", val4.transform, out var groupContent6);
				foreach (KeyValuePair<string, string> startingPerkTitle in StartingPerkTitles)
				{
					CreateCounter(startingPerkTitle.Value, startingPerkTitle.Key, groupContent6, delegate
					{
					});
				}
				CreateCollapsibleGroup("BUFFS", val4.transform, out var groupContent7);
				(string, string, string)[] buffSettings = BuffSettings;
				for (int num5 = 0; num5 < buffSettings.Length; num5++)
				{
					(string, string, string) tuple = buffSettings[num5];
					CreateFloatCounter(tuple.Item2, tuple.Item1, groupContent7, delegate
					{
					}, 0f, 0.05f);
				}
				CreateCollapsibleGroup("MASS", val4.transform, out var groupContent8);
				CreateFloatCounter("Mass Scaling Mult", "mass_speed_mult", groupContent8, delegate
				{
				});
				CreateFloatCounter("Mass Starting Speed", "mass_start_speed", groupContent8, delegate
				{
				});
				CreateFloatCounter("Mass Acceleration Mult", "mass_accel_mult", groupContent8, delegate
				{
				});
				CreateFloatCounter("Rubberband Mult", "mass_rubberband_mult", groupContent8, delegate
				{
				});
				CreateToggle("Enable Rubberband", "mass_rubberband_enabled", groupContent8, delegate
				{
				}, defaultVal: true);
				CreateCollapsibleGroup("WIN CONDITION", val4.transform, out var groupContent9);
				CreateToggle("Cycles Condition", "cycles_win_enabled", groupContent9, delegate
				{
				});
				CreateCounter("Win After X Cycles", "cycles_win_amount", groupContent9, delegate
				{
				}, 1);
				CreateToggle("Height Condition", "height_win_enabled", groupContent9, delegate
				{
				});
				CreateFloatCounter("Win After Climbing X", "height_win_amount", groupContent9, delegate
				{
				}, 1000f, 100f);
				RebuildLayouts(component5);
				CustomMenuPanel.SetActive(false);
				Canvas.ForceUpdateCanvases();
			}

			private static GameObject CreateText(string textContent, Transform parent, int fontSize = 14, TextAnchor alignment = (TextAnchor)3, Color? color = null)
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Expected O, but got Unknown
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				//IL_0080: Unknown result type (might be due to invalid IL or missing references)
				//IL_0077: Unknown result type (might be due to invalid IL or missing references)
				GameObject val = new GameObject("Text", new Type[2]
				{
					typeof(RectTransform),
					typeof(Text)
				});
				val.transform.SetParent(parent, false);
				Text component = val.GetComponent<Text>();
				component.text = textContent;
				component.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
				component.fontSize = fontSize;
				component.alignment = alignment;
				((Graphic)component).color = (Color)(((??)color) ?? Color.white);
				return val;
			}

			private static GameObject CreateButton(string text, Transform parent, Action onClick, Vector2 size)
			{
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Expected O, but got Unknown
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_007f: 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)
				//IL_00aa: Expected O, but got Unknown
				//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00de: Unknown result type (might be due to invalid IL or missing references)
				//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
				GameObject val = new GameObject("Button", new Type[3]
				{
					typeof(RectTransform),
					typeof(Image),
					typeof(Button)
				});
				val.transform.SetParent(parent, false);
				RectTransform component = val.GetComponent<RectTransform>();
				component.sizeDelta = size;
				Image component2 = val.GetComponent<Image>();
				((Graphic)component2).color = new Color(0.25f, 0.25f, 0.25f, 1f);
				Button component3 = val.GetComponent<Button>();
				((UnityEvent)component3.onClick).AddListener((UnityAction)delegate
				{
					onClick?.Invoke();
				});
				GameObject val2 = CreateText(text, val.transform, 14, (TextAnchor)4);
				RectTransform component4 = val2.GetComponent<RectTransform>();
				component4.anchorMin = Vector2.zero;
				component4.anchorMax = Vector2.one;
				component4.sizeDelta = Vector2.zero;
				return val;
			}

			private static GameObject CreateToggle(string label, string settingKey, Transform parent, Action<bool> onToggleChanged, bool defaultVal = false)
			{
				//IL_0073: Unknown result type (might be due to invalid IL or missing references)
				//IL_0079: Expected O, but got Unknown
				//IL_0099: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e6: Expected O, but got Unknown
				//IL_0113: Unknown result type (might be due to invalid IL or missing references)
				//IL_0150: Unknown result type (might be due to invalid IL or missing references)
				//IL_0157: Expected O, but got Unknown
				//IL_0180: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
				//IL_021e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0228: Expected O, but got Unknown
				if (!SettingToggles.ContainsKey(settingKey))
				{
					SettingToggles[settingKey] = defaultVal;
				}
				GameObject val = new GameObject("Toggle_" + settingKey, new Type[2]
				{
					typeof(RectTransform),
					typeof(HorizontalLayoutGroup)
				});
				val.transform.SetParent(parent, false);
				RectTransform component = val.GetComponent<RectTransform>();
				component.sizeDelta = new Vector2(400f, 35f);
				HorizontalLayoutGroup component2 = val.GetComponent<HorizontalLayoutGroup>();
				((HorizontalOrVerticalLayoutGroup)component2).childControlWidth = false;
				((HorizontalOrVerticalLayoutGroup)component2).childControlHeight = true;
				((HorizontalOrVerticalLayoutGroup)component2).childForceExpandWidth = false;
				((HorizontalOrVerticalLayoutGroup)component2).childForceExpandHeight = true;
				((HorizontalOrVerticalLayoutGroup)component2).spacing = 10f;
				((LayoutGroup)component2).padding = new RectOffset(5, 5, 5, 5);
				GameObject val2 = CreateText(label, val.transform, 14, (TextAnchor)3);
				val2.GetComponent<RectTransform>().sizeDelta = new Vector2(230f, 35f);
				GameObject val3 = new GameObject("Button", new Type[3]
				{
					typeof(RectTransform),
					typeof(Image),
					typeof(Button)
				});
				val3.transform.SetParent(val.transform, false);
				RectTransform component3 = val3.GetComponent<RectTransform>();
				component3.sizeDelta = new Vector2(100f, 30f);
				Image img = val3.GetComponent<Image>();
				Button component4 = val3.GetComponent<Button>();
				GameObject val4 = CreateText("", val3.transform, 12, (TextAnchor)4);
				Text btnText = val4.GetComponent<Text>();
				RectTransform component5 = val4.GetComponent<RectTransform>();
				component5.anchorMin = Vector2.zero;
				component5.anchorMax = Vector2.one;
				component5.sizeDelta = Vector2.zero;
				Action updateUI = delegate
				{
					//IL_0065: Unknown result type (might be due to invalid IL or missing references)
					//IL_004a: Unknown result type (might be due to invalid IL or missing references)
					bool flag = SettingToggles[settingKey];
					btnText.text = (flag ? "ENABLED" : "DISABLED");
					((Graphic)img).color = (flag ? new Color(0.15f, 0.6f, 0.15f, 1f) : new Color(0.6f, 0.15f, 0.15f, 1f));
				};
				((UnityEvent)component4.onClick).AddListener((UnityAction)delegate
				{
					SettingToggles[settingKey] = !SettingToggles[settingKey];
					updateUI();
					onToggleChanged?.Invoke(SettingToggles[settingKey]);
				});
				updateUI();
				return val;
			}

			public static GameObject CreateDropdownSelector(string label, string settingKey, Transform parent, string[] options, Action<string> onSelectionChanged, string defaultValue = "")
			{
				//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bb: Expected O, but got Unknown
				//IL_0147: Unknown result type (might be due to invalid IL or missing references)
				//IL_014d: Expected O, but got Unknown
				//IL_0175: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c9: Expected O, but got Unknown
				//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
				//IL_0217: Unknown result type (might be due to invalid IL or missing references)
				//IL_0270: Unknown result type (might be due to invalid IL or missing references)
				//IL_027a: Expected O, but got Unknown
				//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
				//IL_0305: Unknown result type (might be due to invalid IL or missing references)
				//IL_030f: Expected O, but got Unknown
				//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
				//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
				//IL_0408: Expected O, but got Unknown
				if (options == null || options.Length == 0)
				{
					options = new string[1] { "None" };
				}
				if (!SettingStrings.ContainsKey(settingKey))
				{
					SettingStrings[settingKey] = (string.IsNullOrEmpty(defaultValue) ? options[0] : defaultValue);
				}
				GameObject container = new GameObject("Dropdown_" + settingKey, new Type[3]
				{
					typeof(RectTransform),
					typeof(VerticalLayoutGroup),
					typeof(ContentSizeFitter)
				});
				container.transform.SetParent(parent, false);
				VerticalLayoutGroup component = container.GetComponent<VerticalLayoutGroup>();
				((HorizontalOrVerticalLayoutGroup)component).childControlWidth = true;
				((HorizontalOrVerticalLayoutGroup)component).childControlHeight = false;
				((HorizontalOrVerticalLayoutGroup)component).childForceExpandWidth = true;
				((HorizontalOrVerticalLayoutGroup)component).childForceExpandHeight = false;
				((HorizontalOrVerticalLayoutGroup)component).spacing = 2f;
				ContentSizeFitter component2 = container.GetComponent<ContentSizeFitter>();
				component2.verticalFit = (FitMode)2;
				component2.horizontalFit = (FitMode)0;
				GameObject val = new GameObject("HeaderRow", new Type[2]
				{
					typeof(RectTransform),
					typeof(HorizontalLayoutGroup)
				});
				val.transform.SetParent(container.transform, false);
				val.GetComponent<RectTransform>().sizeDelta = new Vector2(400f, 35f);
				HorizontalLayoutGroup component3 = val.GetComponent<HorizontalLayoutGroup>();
				((HorizontalOrVerticalLayoutGroup)component3).childControlWidth = false;
				((HorizontalOrVerticalLayoutGroup)component3).childControlHeight = true;
				((HorizontalOrVerticalLayoutGroup)component3).childForceExpandWidth = false;
				((HorizontalOrVerticalLayoutGroup)component3).childForceExpandHeight = true;
				((HorizontalOrVerticalLayoutGroup)component3).spacing = 10f;
				((LayoutGroup)component3).padding = new RectOffset(5, 5, 5, 5);
				GameObject val2 = CreateText(label, val.transform, 14, (TextAnchor)3);
				val2.GetComponent<RectTransform>().sizeDelta = new Vector2(200f, 35f);
				GameObject val3 = CreateButton("", val.transform, null, new Vector2(150f, 30f));
				Text mainBtnText = val3.GetComponentInChildren<Text>();
				GameObject optionsContainer = new GameObject("OptionsContainer", new Type[4]
				{
					typeof(RectTransform),
					typeof(Image),
					typeof(VerticalLayoutGroup),
					typeof(ContentSizeFitter)
				});
				optionsContainer.transform.SetParent(container.transform, false);
				((Graphic)optionsContainer.GetComponent<Image>()).color = new Color(0.18f, 0.18f, 0.18f, 0.95f);
				VerticalLayoutGroup component4 = optionsContainer.GetComponent<VerticalLayoutGroup>();
				((HorizontalOrVerticalLayoutGroup)component4).childControlWidth = true;
				((HorizontalOrVerticalLayoutGroup)component4).childControlHeight = false;
				((HorizontalOrVerticalLayoutGroup)component4).childForceExpandWidth = true;
				((HorizontalOrVerticalLayoutGroup)component4).childForceExpandHeight = false;
				((HorizontalOrVerticalLayoutGroup)component4).spacing = 2f;
				((LayoutGroup)component4).padding = new RectOffset(5, 5, 5, 5);
				ContentSizeFitter component5 = optionsContainer.GetComponent<ContentSizeFitter>();
				component5.verticalFit = (FitMode)2;
				bool isOpen = false;
				optionsContainer.SetActive(false);
				Action updateUI = delegate
				{
					string text2 = SettingStrings[settingKey];
					mainBtnText.text = text2 + " " + (isOpen ? "▲" : "▼");
				};
				string[] array = options;
				foreach (string text in array)
				{
					string optionText = text;
					GameObject val4 = CreateButton(optionText, optionsContainer.transform, delegate
					{
						SettingStrings[settingKey] = optionText;
						isOpen = false;
						optionsContainer.SetActive(false);
						updateUI();
						onSelectionChanged?.Invoke(optionText);
						if ((Object)(object)container.transform.parent != (Object)null)
						{
							RebuildLayouts(((Component)container.transform.parent).GetComponent<RectTransform>());
						}
					}, new Vector2(0f, 25f));
					((Graphic)val4.GetComponent<Image>()).color = new Color(0.22f, 0.22f, 0.25f, 1f);
				}
				((UnityEvent)val3.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
				{
					isOpen = !isOpen;
					optionsContainer.SetActive(isOpen);
					updateUI();
					if ((Object)(object)container.transform.parent != (Object)null)
					{
						RebuildLayouts(((Component)container.transform.parent).GetComponent<RectTransform>());
					}
				});
				updateUI();
				return container;
			}

			private static GameObject CreateCounter(string label, string settingKey, Transform parent, Action<int> onCountChanged, int defaultVal = 0)
			{
				//IL_0073: Unknown result type (might be due to invalid IL or missing references)
				//IL_0079: Expected O, but got Unknown
				//IL_0099: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e6: Expected O, but got Unknown
				//IL_0113: Unknown result type (might be due to invalid IL or missing references)
				//IL_0150: Unknown result type (might be due to invalid IL or missing references)
				//IL_0157: Expected O, but got Unknown
				//IL_017c: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
				//IL_0233: Unknown result type (might be due to invalid IL or missing references)
				//IL_027d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0284: Expected O, but got Unknown
				//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
				//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
				//IL_0301: Unknown result type (might be due to invalid IL or missing references)
				//IL_0313: Unknown result type (might be due to invalid IL or missing references)
				//IL_0325: Unknown result type (might be due to invalid IL or missing references)
				//IL_0355: Unknown result type (might be due to invalid IL or missing references)
				//IL_035f: Expected O, but got Unknown
				//IL_0373: Unknown result type (might be due to invalid IL or missing references)
				//IL_037d: Expected O, but got Unknown
				if (!SettingCounts.ContainsKey(settingKey))
				{
					SettingCounts[settingKey] = defaultVal;
				}
				GameObject val = new GameObject("Counter_" + settingKey, new Type[2]
				{
					typeof(RectTransform),
					typeof(HorizontalLayoutGroup)
				});
				val.transform.SetParent(parent, false);
				RectTransform component = val.GetComponent<RectTransform>();
				component.sizeDelta = new Vector2(400f, 35f);
				HorizontalLayoutGroup component2 = val.GetComponent<HorizontalLayoutGroup>();
				((HorizontalOrVerticalLayoutGroup)component2).childControlWidth = false;
				((HorizontalOrVerticalLayoutGroup)component2).childControlHeight = true;
				((HorizontalOrVerticalLayoutGroup)component2).childForceExpandWidth = false;
				((HorizontalOrVerticalLayoutGroup)component2).childForceExpandHeight = true;
				((HorizontalOrVerticalLayoutGroup)component2).spacing = 10f;
				((LayoutGroup)component2).padding = new RectOffset(5, 5, 5, 5);
				GameObject val2 = CreateText(label, val.transform, 14, (TextAnchor)3);
				val2.GetComponent<RectTransform>().sizeDelta = new Vector2(230f, 35f);
				GameObject val3 = new GameObject("Minus", new Type[3]
				{
					typeof(RectTransform),
					typeof(Image),
					typeof(Button)
				});
				val3.transform.SetParent(val.transform, false);
				val3.GetComponent<RectTransform>().sizeDelta = new Vector2(30f, 30f);
				((Graphic)val3.GetComponent<Image>()).color = new Color(0.3f, 0.3f, 0.3f, 1f);
				GameObject val4 = CreateText("-", val3.transform, 14, (TextAnchor)4);
				val4.GetComponent<RectTransform>().anchorMin = Vector2.zero;
				val4.GetComponent<RectTransform>().anchorMax = Vector2.one;
				val4.GetComponent<RectTransform>().sizeDelta = Vector2.zero;
				GameObject val5 = CreateText("0", val.transform, 14, (TextAnchor)4);
				val5.GetComponent<RectTransform>().sizeDelta = new Vector2(40f, 35f);
				Text valText = val5.GetComponent<Text>();
				GameObject val6 = new GameObject("Plus", new Type[3]
				{
					typeof(RectTransform),
					typeof(Image),
					typeof(Button)
				});
				val6.transform.SetParent(val.transform, false);
				val6.GetComponent<RectTransform>().sizeDelta = new Vector2(30f, 30f);
				((Graphic)val6.GetComponent<Image>()).color = new Color(0.3f, 0.3f, 0.3f, 1f);
				GameObject val7 = CreateText("+", val6.transform, 14, (TextAnchor)4);
				val7.GetComponent<RectTransform>().anchorMin = Vector2.zero;
				val7.GetComponent<RectTransform>().anchorMax = Vector2.one;
				val7.GetComponent<RectTransform>().sizeDelta = Vector2.zero;
				Action updateUI = delegate
				{
					valText.text = SettingCounts[settingKey].ToString();
				};
				((UnityEvent)val3.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
				{
					int num = SettingCounts[settingKey];
					if (num > 0)
					{
						SettingCounts[settingKey] = num - 1;
						updateUI();
						onCountChanged?.Invoke(SettingCounts[settingKey]);
					}
				});
				((UnityEvent)val6.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
				{
					SettingCounts[settingKey] += 1;
					updateUI();
					onCountChanged?.Invoke(SettingCounts[settingKey]);
				});
				updateUI();
				return val;
			}

			private static GameObject CreateFloatCounter(string label, string settingKey, Transform parent, Action<float> onChanged, float defaultValue = 1f, float step = 0.1f)
			{
				//IL_0079: Unknown result type (might be due to invalid IL or missing references)
				//IL_007f: Expected O, but got Unknown
				//IL_009d: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e2: Expected O, but got Unknown
				//IL_010d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0148: Unknown result type (might be due to invalid IL or missing references)
				//IL_0181: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
				if (!SettingFloats.ContainsKey(settingKey))
				{
					SettingFloats[settingKey] = defaultValue;
				}
				GameObject val = new GameObject("Float_" + settingKey, new Type[2]
				{
					typeof(RectTransform),
					typeof(HorizontalLayoutGroup)
				});
				val.transform.SetParent(parent, false);
				val.GetComponent<RectTransform>().sizeDelta = new Vector2(400f, 35f);
				HorizontalLayoutGroup component = val.GetComponent<HorizontalLayoutGroup>();
				((HorizontalOrVerticalLayoutGroup)component).childControlWidth = false;
				((HorizontalOrVerticalLayoutGroup)component).childControlHeight = true;
				((HorizontalOrVerticalLayoutGroup)component).childForceExpandWidth = false;
				((HorizontalOrVerticalLayoutGroup)component).spacing = 10f;
				((LayoutGroup)component).padding = new RectOffset(5, 5, 5, 5);
				GameObject val2 = CreateText(label, val.transform, 14, (TextAnchor)3);
				val2.GetComponent<RectTransform>().sizeDelta = new Vector2(200f, 35f);
				GameObject val3 = CreateText("", val.transform, 14, (TextAnchor)4);
				val3.GetComponent<RectTransform>().sizeDelta = new Vector2(70f, 35f);
				Text valueText = val3.GetComponent<Text>();
				GameObject val4 = CreateButton("-", val.transform, delegate
				{
					SettingFloats[settingKey] -= step;
					Update();
				}, new Vector2(30f, 30f));
				GameObject val5 = CreateButton("+", val.transform, delegate
				{
					SettingFloats[settingKey] += step;
					Update();
				}, new Vector2(30f, 30f));
				Update();
				return val;
				void Update()
				{
					valueText.text = SettingFloats[settingKey].ToString("0.00");
					onChanged?.Invoke(SettingFloats[settingKey]);
				}
			}

			private static GameObject CreateCollapsibleGroup(string title, Transform parent, out Transform groupContent)
			{
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0056: Expected O, but got Unknown
				//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f5: Expected O, but got Unknown
				//IL_011d: 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_0167: Unknown result type (might be due to invalid IL or missing references)
				//IL_018f: Unknown result type (might be due to invalid IL or missing references)
				//IL_019c: 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_01c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
				//IL_0208: Expected O, but got Unknown
				//IL_0278: Unknown result type (might be due to invalid IL or missing references)
				//IL_0282: Expected O, but got Unknown
				//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d2: Expected O, but got Unknown
				GameObject groupRoot = new GameObject("Group_" + title, new Type[3]
				{
					typeof(RectTransform),
					typeof(VerticalLayoutGroup),
					typeof(ContentSizeFitter)
				});
				groupRoot.transform.SetParent(parent, false);
				VerticalLayoutGroup component = groupRoot.GetComponent<VerticalLayoutGroup>();
				((HorizontalOrVerticalLayoutGroup)component).childControlWidth = true;
				((HorizontalOrVerticalLayoutGroup)component).childControlHeight = false;
				((HorizontalOrVerticalLayoutGroup)component).childForceExpandWidth = true;
				((HorizontalOrVerticalLayoutGroup)component).childForceExpandHeight = false;
				((HorizontalOrVerticalLayoutGroup)component).spacing = 2f;
				ContentSizeFitter component2 = groupRoot.GetComponent<ContentSizeFitter>();
				component2.verticalFit = (FitMode)2;
				component2.horizontalFit = (FitMode)0;
				GameObject val = new GameObject("Header", new Type[3]
				{
					typeof(RectTransform),
					typeof(Image),
					typeof(Button)
				});
				val.transform.SetParent(groupRoot.transform, false);
				val.GetComponent<RectTransform>().sizeDelta = new Vector2(400f, 30f);
				((Graphic)val.GetComponent<Image>()).color = new Color(0.2f, 0.2f, 0.2f, 1f);
				Text headerText = CreateText("► " + title, val.transform, 14, (TextAnchor)3, Color.yellow).GetComponent<Text>();
				RectTransform component3 = ((Component)headerText).GetComponent<RectTransform>();
				component3.anchorMin = Vector2.zero;
				component3.anchorMax = Vector2.one;
				component3.sizeDelta = Vector2.zero;
				component3.offsetMin = new Vector2(10f, 0f);
				GameObject contentGo = new GameObject("Content", new Type[3]
				{
					typeof(RectTransform),
					typeof(VerticalLayoutGroup),
					typeof(ContentSizeFitter)
				});
				contentGo.transform.SetParent(groupRoot.transform, false);
				groupContent = contentGo.transform;
				VerticalLayoutGroup component4 = contentGo.GetComponent<VerticalLayoutGroup>();
				((HorizontalOrVerticalLayoutGroup)component4).childControlWidth = true;
				((HorizontalOrVerticalLayoutGroup)component4).childControlHeight = false;
				((HorizontalOrVerticalLayoutGroup)component4).childForceExpandWidth = true;
				((HorizontalOrVerticalLayoutGroup)component4).childForceExpandHeight = false;
				((HorizontalOrVerticalLayoutGroup)component4).spacing = 2f;
				((LayoutGroup)component4).padding = new RectOffset(10, 10, 5, 5);
				ContentSizeFitter component5 = contentGo.GetComponent<ContentSizeFitter>();
				component5.verticalFit = (FitMode)2;
				component5.horizontalFit = (FitMode)0;
				bool expanded = false;
				contentGo.SetActive(true);
				((UnityEvent)val.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
				{
					expanded = !expanded;
					contentGo.SetActive(expanded);
					headerText.text = (expanded ? "▼ " : "► ") + title;
					RebuildLayouts(groupRoot.GetComponent<RectTransform>());
					Canvas.ForceUpdateCanvases();
				});
				RebuildLayouts(groupRoot.GetComponent<RectTransform>());
				RebuildLayouts(((Component)parent).GetComponent<RectTransform>());
				Canvas.ForceUpdateCanvases();
				LayoutRebuilder.ForceRebuildLayoutImmediate(groupRoot.GetComponent<RectTransform>());
				if ((Object)(object)parent != (Object)null)
				{
					LayoutRebuilder.ForceRebuildLayoutImmediate(((Component)parent).GetComponent<RectTransform>());
				}
				Canvas.ForceUpdateCanvases();
				contentGo.SetActive(false);
				return groupRoot;
			}
		}

		[HarmonyPatch(typeof(M_Level), "OnEnter")]
		public static class M_Level_OnLevelActivate_Patch
		{
			[HarmonyPrefix]
			public static void Prefix(M_Level __instance)
			{
				if ((Object)(object)CL_GameManager.GetCurrentGamemode() != (Object)(object)EndlessMode)
				{
					return;
				}
				Debug.Log((object)$"CYCLES:::::::::::::{cycles}");
				if ((Object)(object)__instance?.region?.nextRegion == (Object)(object)EndlessMode.regions[0])
				{
					Debug.Log((object)"NEXT CYCLE IS NEW CYCLE");
					if (checkCycle)
					{
						cycles++;
						checkCycle = false;
					}
				}
				else
				{
					checkCycle = true;
				}
				if (CustomUIManager.GetToggleState("height_win_enabled") && CustomUIManager.GetFloatState("height_win_amount") <= CL_GameManager.gMan.GetPlayerCorrectedHeight())
				{
					CL_GameManager.gMan.Win();
				}
				if (CustomUIManager.GetToggleState("cycles_win_enabled") && CustomUIManager.GetCountState("cycles_win_amount") <= cycles && (Object)(object)__instance.region == (Object)(object)EndlessMode.regions[0])
				{
					CL_GameManager.gMan.Win();
				}
				if ((Object)(object)lastRegion == (Object)null)
				{
					lastRegion = __instance.region;
				}
				if ((Object)(object)__instance.region != (Object)(object)lastRegion)
				{
					int num = 2;
					WorldLoader.instance.UnloadPreviousLevels(num);
					lastRegion = __instance.region;
				}
				if (StringUtility.ContainsInsensitive(__instance.levelName, "Abyss"))
				{
					DestroyMassInstance();
				}
				if (BEGONE_FOUL_SPIRIT)
				{
					DestroyMassInstance();
					BEGONE_FOUL_SPIRIT = false;
				}
			}
		}

		[HarmonyPatch(typeof(M_Level), "OnLevelActivate")]
		public static class M_Level_OnLevelActivate_Items_Patch
		{
			[HarmonyPrefix]
			public static void Prefix(M_Level __instance)
			{
				if (giveStartingItems)
				{
					checkCycle = true;
					cycles = 0;
					GiveStartingItems();
					GiveStartingPerks();
					giveStartingItems = false;
				}
			}
		}

		public static M_Gamemode EndlessMode;

		private static bool added;

		private static Dictionary<string, Object> regionCache = new Dictionary<string, Object>();

		public static bool BEGONE_FOUL_SPIRIT;

		public static bool giveStartingItems;

		public static Dictionary<string, bool> SettingToggles = new Dictionary<string, bool>();

		public static Dictionary<string, int> SettingCounts = new Dictionary<string, int>();

		public static Dictionary<string, float> SettingFloats = new Dictionary<string, float>();

		private static readonly (string Key, string Name, string BuffId)[] BuffSettings = new(string, string, string)[13]
		{
			("buff_jump", "Jump Height", "addJump"),
			("buff_stamina", "Stamina", "addStamina"),
			("buff_stamina_regen", "Stamina Regen", "addStaminaRegen"),
			("buff_climb_speed", "Climb Speed", "addClimb"),
			("buff_reach", "Reach", "addReach"),
			("buff_armor", "Damage Resist", "damageResist"),
			("buff_vulnerability", "Damage Multiplier", "damageMult"),
			("buff_knockback_resist", "Knockback Resist", "knockbackResist"),
			("buff_weapon_speed", "Weapon Speed", "weaponSpeedUp"),
			("buff_weapon_slow", "Weapon Slow", "weaponSpeedDown"),
			("buff_weapon_recoil", "Weapon Recoil", "weaponRecoil"),
			("buff_time_slow", "Time Slow", "slowTime"),
			("buff_gravity", "Gravity", "addGravity")
		};

		private static readonly Dictionary<string, RegionDefinition> RegionDefinitions = new Dictionary<string, RegionDefinition>();

		private static readonly Dictionary<(string From, string To), string> TransitionDefinitions = new Dictionary<(string, string), string>();

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

		private static int cycles = 0;

		private static bool checkCycle = true;

		private static M_Region lastRegion = null;

		private static readonly Dictionary<string, string> SubregionKeywords = new Dictionary<string, string>
		{
			{ "Storage", "Deep Storage" },
			{ "Ventilation", "Air Exchange" },
			{ "Chambers", "Shattered Chambers" },
			{ "Drainage", "Drainage System" },
			{ "Waste", "Waste Heap" },
			{ "Organ", "Pipe Organ" },
			{ "Shaft", "Service Shaft" },
			{ "Pier", "Lost Pier" },
			{ "Labs", "Delta Labs" },
			{ "Scaffolds", "Transit Scaffolds" },
			{ "Handle", "Deadman's Handle" },
			{ "Gardens", "Hanging Gardens" },
			{ "Zone", "Hot Zone" },
			{ "Infested", "Infested Labs" },
			{ "Trough", "Feeding Trough" }
		};

		private static readonly Dictionary<string, string> StartingItemTitles = new Dictionary<string, string>
		{
			{ "item_timepiece", "Timepiece" },
			{ "item_translocator", "Translocator" },
			{ "item_evaglove", "EVA Glove" },
			{ "item_rapier", "Rapier" },
			{ "item_rebar_return", "Rho Spear" },
			{ "item_remote", "Remote" },
			{ "item_handgun_kit", "Handgun" },
			{ "item_flaregun_kit", "Flaregun" },
			{ "item_flashlight", "Flashlight" }
		};

		private static Dictionary<string, string> StartingPerkTitles => (from p in CL_AssetManager.GetFullCombinedAssetDatabase().perkAssets
			where (Object)(object)p != (Object)null
			orderby p.title
			select p).ToDictionary((Perk p) => p.id, (Perk p) => p.title);

		private static void RegisterRegion(string name, string regionAsset, string breakroomAsset, params (string To, string Transition)[] transitions)
		{
			RegionDefinitions[name] = new RegionDefinition
			{
				RegionAsset = regionAsset,
				BreakroomAsset = breakroomAsset
			};
			if (!RegionOrder.Contains(name))
			{
				RegionOrder.Add(name);
			}
			for (int i = 0; i < transitions.Length; i++)
			{
				(string, string) tuple = transitions[i];
				TransitionDefinitions[(name, tuple.Item1)] = tuple.Item2;
			}
		}

		private static void RegisterRegions()
		{
			if (RegionDefinitions.Count <= 0)
			{
				RegisterRegion("Silos", "Region_Silos_Endless", "Region_Silos_Saferoom_Endless", ("Pipeworks", "Transition_Silo_To_Pipeworks_01"));
				RegisterRegion("Pipeworks", "Region_Pipeworks_Endless", "Region_Pipeworks_Breakroom", ("Habitation", "Transition_Pipeworks_To_Habitation"), ("Chute", "Transition_Pipeworks_To_Habitation"), ("Silos", "Transition_Pipeworks_To_Silo"));
				RegisterRegion("Habitation", "Region_Habitation_Endless", "Region_Habitation_Breakroom", ("Abyss", "Transition_Habitation_To_Abyss_01"), ("Silos", "Transition_Habitation_To_Silo"));
				RegisterRegion("Abyss", "Region_Abyss_Endless", "Region_Abyss_Breakroom", ("Nest", "M5_Nest_Endless_Transition_Intro"), ("Silos", "Transition_Abyss_To_Silo"));
				RegisterRegion("Nest", "Region_Nest_Endless", "Region_Nest_Endless_Breakroom", ("Silos", "Transition_Nest_To_Silo"));
				RegisterRegion("Ladder", "Region_Ladder_Endless", "");
				LevelAssetHolder val = CustomLevelLoader.LoadRoom("custom_level_test.test", "From_Silos", "From_Silos");
				CustomLevelRegistry.Register("From_Silos", val.level);
				val = CustomLevelLoader.LoadRoom("custom_level_test.test", "From_Silos", "From_Chute");
				CustomLevelRegistry.Register("From_Chute", val.level);
				val = CustomLevelLoader.LoadRoom("custom_level_test.test", "To_Silos", "To_Silos");
				CustomLevelRegistry.Register("To_Silos", val.level);
				val = CustomLevelLoader.LoadRoom("custom_level_test.test", "To_Nest", "To_Nest");
				CustomLevelRegistry.Register("To_Nest", val.level);
				val = CustomLevelLoader.LoadRoom("custom_level_test.test", "From_Nest", "From_Nest");
				CustomLevelRegistry.Register("From_Nest", val.level);
				val = CustomLevelLoader.LoadRoom("custom_level_test.test", "To_Ladder", "To_Ladder");
				CustomLevelRegistry.Register("To_Ladder", val.level);
				val = CustomLevelLoader.LoadRoom("custom_level_test.test", "From_Ladder", "From_Ladder");
				CustomLevelRegistry.Register("From_Ladder", val.level);
				val = CustomLevelLoader.LoadRoom("custom_level_test.test", "To_Abyss", "To_Abyss");
				CustomLevelRegistry.Register("To_Abyss", val.level);
				val = CustomLevelLoader.LoadRoom("custom_level_test.test", "From_Abyss", "From_Abyss");
				CustomLevelRegistry.Register("From_Abyss", val.level);
				val = CustomLevelLoader.LoadRoom("custom_level_test.test", "To_Habitation", "To_Habitation");
				CustomLevelRegistry.Register("To_Habitation", val.level);
				val = CustomLevelLoader.LoadRoom("custom_level_test.test", "From_Habitation", "From_Habitation");
				CustomLevelRegistry.Register("From_Habitation", val.level);
				val = CustomLevelLoader.LoadRoom("custom_level_test.test", "To_Pipeworks", "To_Pipeworks");
				CustomLevelRegistry.Register("To_Pipeworks", val.level);
				val = CustomLevelLoader.LoadRoom("custom_level_test.test", "From_Pipeworks", "From_Pipeworks");
				CustomLevelRegistry.Register("From_Pipeworks", val.level);
			}
		}

		public static void ApplyConfiguredBuffs()
		{
			ENT_Player player = ENT_Player.GetPlayer();
			if ((Object)(object)player == (Object)null)
			{
				return;
			}
			(string, string, string)[] buffSettings = BuffSettings;
			for (int i = 0; i < buffSettings.Length; i++)
			{
				(string, string, string) tuple = buffSettings[i];
				float floatState = CustomUIManager.GetFloatState(tuple.Item1);
				if (!Mathf.Approximately(floatState, 0f))
				{
					Perk val = new PerkBuilder("endless_" + tuple.Item1, tuple.Item2).WithBuff("endless_" + tuple.Item1 + "_buff", tuple.Item3, floatState).Build();
					player.AddPerk(val, 1, true);
				}
			}
			if (CustomUIManager.GetToggleState("buff_inf_charge"))
			{
				player.AddPerk(new PerkBuilder("endless_infcharge", "Infinite Charge").WithBuff("endless_infcharge_buff", "infiniteCharge", 1f).Build(), 1, true);
			}
			if (CustomUIManager.GetToggleState("buff_hang_grounded"))
			{
				player.AddPerk(new PerkBuilder("endless_grounded", "Grounded While Hanging").WithBuff("endless_grounded_buff", "hangingGrounded", 1f).Build(), 1, true);
			}
		}

		private static void DestroyMassInstance()
		{
			if ((Object)(object)DEN_DeathFloor.instance != (Object)null)
			{
				DEN_DeathFloor.instance.SetActive(false);
				DEN_DeathFloor.instance.SetVisualActive(false);
				DEN_DeathFloor.instance.SetHeight(-1000f);
			}
		}

		[HarmonyPatch(typeof(CL_Initializer), "Awake")]
		[HarmonyPrefix]
		public static void InitializerAwake(ref CL_Initializer __instance)
		{
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: 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)
			if (added)
			{
				return;
			}
			M_Gamemode val = __instance.baseDatabase.gamemodeAssets.First((M_Gamemode x) => ((Object)x).name == "GM_Endless_Nest");
			foreach (M_Gamemode gamemodeAsset in __instance.baseDatabase.gamemodeAssets)
			{
				if (!((Object)(object)gamemodeAsset != (Object)null) || gamemodeAsset.regions == null)
				{
					continue;
				}
				foreach (M_Region region in gamemodeAsset.regions)
				{
					if ((Object)(object)region != (Object)null && !regionCache.ContainsKey(((Object)region).name))
					{
						regionCache[((Object)region).name] = (Object)(object)region;
					}
				}
			}
			EndlessMode = ScriptableObject.CreateInstance<M_Gamemode>();
			EndlessMode.gamemodeName = "Custom Endless";
			((Object)EndlessMode).name = "GM_Custom_Endless";
			EndlessMode.introText = "ASCEND";
			EndlessMode.newGameText = "Start";
			EndlessMode.modeDescription = "Customize your Endless";
			EndlessMode.allowAchievements = true;
			EndlessMode.allowCheatedScores = false;
			EndlessMode.allowCheats = true;
			EndlessMode.allowLeaderboardScoring = false;
			EndlessMode.steamLeaderboardName = "";
			EndlessMode.allowHeightAchievements = true;
			EndlessMode.baseGamemode = true;
			EndlessMode.useGamemodeSettings = true;
			EndlessMode.isEndless = true;
			EndlessMode.hasPerks = val.hasPerks;
			EndlessMode.hasRevives = val.hasRevives;
			EndlessMode.modeType = val.modeType;
			EndlessMode.gamemodeScene = val.gamemodeScene;
			EndlessMode.capsuleName = "";
			EndlessMode.capsuleArt = val.capsuleArt;
			EndlessMode.screenArt = val.screenArt;
			EndlessMode.roachEndSprite = val.roachEndSprite;
			EndlessMode.gamemodePanel = val.gamemodePanel;
			EndlessMode.roachBankID = val.roachBankID;
			EndlessMode.loseScreen = val.loseScreen;
			EndlessMode.winScreen = val.winScreen;
			EndlessMode.gamemodeColor = val.gamemodeColor;
			EndlessMode.modeTags = val.modeTags;
			EndlessMode.unlockAchievement = val.unlockAchievement;
			EndlessMode.gamemodeModule = val.gamemodeModule;
			EndlessMode.levelsToGenerate = val.levelsToGenerate;
			EndlessMode.availableTrinkets = val.availableTrinkets;
			EndlessMode.playlistLevelAssets = new List<LevelAssetHolder>();
			EndlessMode.playlistLevels = new List<M_Level>();
			EndlessMode.gamemodeObjects = val.gamemodeObjects;
			EndlessMode.unlockHint = val.unlockHint;
			EndlessMode.startItems = val.startItems;
			EndlessMode.regions = new List<M_Region>();
			EndlessMode.regions.Clear();
			EndlessMode.gamemodeSettings = val.gamemodeSettings;
			EndlessMode.winScreen.SetDeathText("YOU BEAT YOUR ARBITRARY GOAL");
			__instance.baseDatabase.gamemodeAssets.Add(EndlessMode);
			added = true;
		}

		[HarmonyPatch(typeof(UI_PlayPane), "Start")]
		[HarmonyPrefix]
		public static void PlayPaneStart(ref UI_PlayPane __instance)
		{
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Expected O, but got Unknown
			GameObject val = ((IEnumerable<GameObject>)Object.FindObjectsOfType<GameObject>(true)).FirstOrDefault((Func<GameObject, bool>)((GameObject x) => (((Object)x).name == "Other Endless 02" || ((Object)x).name == "Other Endless 01") && ((Object)x.transform.parent.parent.parent).name == "Play Pane - Scroll View Tab - Endless Variant"));
			if (!((Object)(object)val != (Object)null))
			{
				return;
			}
			GameObject val2 = Object.Instantiate<GameObject>(val);
			((Object)val2).name = "Custom Endless Tab";
			val2.transform.SetParent(val.transform.parent, false);
			Transform child = val2.transform.GetChild(0);
			for (int num = 0; num < val2.transform.childCount; num++)
			{
				if (num != 0)
				{
					Object.Destroy((Object)(object)((Component)val2.transform.GetChild(num)).gameObject);
				}
			}
			GameObject gameObject = ((Component)child).gameObject;
			((Object)gameObject).name = "Mode Selection Button - Custom Endless";
			((UnityEventBase)gameObject.GetComponent<Button>().onClick).RemoveAllListeners();
			gameObject.GetComponent<UI_CapsuleButton>().unlockAchievement = EndlessMode.unlockAchievement;
			gameObject.GetComponent<UI_Gamemode_Button>().gamemode = EndlessMode;
			gameObject.GetComponent<UI_Gamemode_Button>().Initialize();
			val2.transform.localScale = Vector3.one;
			ContentSizeFitter csf = ((Component)val2.transform.parent).GetComponent<ContentSizeFitter>();
			UI_TabGroup component = ((Component)val2.transform.parent.parent.parent.parent.parent.Find("Tabs")).GetComponent<UI_TabGroup>();
			component.EventOnChangeTab.AddListener((UnityAction)delegate
			{
				((MonoBehaviour)csf).Invoke("SetLayoutHorizontal", 0.05f);
			});
		}

		public static void UpdateRegions()
		{
			RegisterRegions();
			if (CustomUIManager.GetToggleState("ordered_gen_enabled"))
			{
				UpdateOrderedRegions();
			}
			else
			{
				if ((Object)(object)EndlessMode == (Object)null || EndlessMode.regions == null)
				{
					return;
				}
				EndlessMode.regions.Clear();
				List<int> list = new List<int>();
				for (int i = 0; i < RegionOrder.Count; i++)
				{
					if (CustomUIManager.GetCountState(RegionOrder[i].ToLower() + "_loops") > 0)
					{
						list.Add(i);
					}
				}
				if (list.Count == 0)
				{
					M_Region andFilterRegion = GetAndFilterRegion(RegionDefinitions["Silos"].BreakroomAsset);
					if ((Object)(object)andFilterRegion != (Object)null)
					{
						EndlessMode.regions.Add(andFilterRegion);
					}
					return;
				}
				BEGONE_FOUL_SPIRIT = RegionOrder[list[0]] == "Abyss";
				giveStartingItems = true;
				for (int j = 0; j < list.Count; j++)
				{
					int num = list[j];
					string text = RegionOrder[num];
					string text2 = text.ToLower();
					int num2 = Mathf.Max(1, CustomUIManager.GetCountState(text2 + "_loops"));
					M_Region andFilterRegion2 = GetAndFilterRegion(RegionDefinitions[text].RegionAsset);
					M_Region andFilterRegion3 = GetAndFilterRegion(RegionDefinitions[text].BreakroomAsset);
					int num3 = Mathf.Max(0, CustomUIManager.GetCountState(text2 + "_breakrooms"));
					bool toggleState = CustomUIManager.GetToggleState(text2 + "_breakroom_first");
					for (int k = 0; k < num2; k++)
					{
						if (toggleState)
						{
							for (int l = 0; l < num3; l++)
							{
								if ((Object)(object)andFilterRegion3 != (Object)null)
								{
									EndlessMode.regions.Add(GetAndFilterRegion(((Object)andFilterRegion3).name.Replace("_RuntimeCopy", "")));
								}
							}
							if ((Object)(object)andFilterRegion2 != (Object)null)
							{
								EndlessMode.regions.Add(GetAndFilterRegion(((Object)andFilterRegion2).name.Replace("_RuntimeCopy", "")));
							}
							continue;
						}
						if ((Object)(object)andFilterRegion2 != (Object)null)
						{
							EndlessMode.regions.Add(GetAndFilterRegion(((Object)andFilterRegion2).name.Replace("_RuntimeCopy", "")));
						}
						for (int m = 0; m < num3; m++)
						{
							if ((Object)(object)andFilterRegion3 != (Object)null)
							{
								EndlessMode.regions.Add(GetAndFilterRegion(((Object)andFilterRegion3).name.Replace("_RuntimeCopy", "")));
							}
						}
					}
					if (list.Count <= 1)
					{
						continue;
					}
					int index = list[(j + 1) % list.Count];
					string text3 = RegionOrder[num];
					string text4 = RegionOrder[index];
					int num4 = num;
					List<(string, string)> list2 = new List<(string, string)>();
					foreach (var item in ResolveTransitions(text3, text4))
					{
						list2.Add(item);
						num4 = (num4 + 1) % RegionOrder.Count;
					}
					InjectTransitionRegion(list2, text3, text4);
				}
				for (int n = 0; n < EndlessMode.regions.Count; n++)
				{
					M_Region val = EndlessMode.regions[n];
					val.nextRegion = EndlessMode.regions[(n + 1) % EndlessMode.regions.Count];
				}
			}
		}

		public static void UpdateOrderedRegions()
		{
			RegisterRegions();
			if ((Object)(object)EndlessMode == (Object)null || EndlessMode.regions == null)
			{
				return;
			}
			EndlessMode.regions.Clear();
			List<(string, string, string, int, bool)> list = new List<(string, string, string, int, bool)>();
			for (int i = 0; i < 20; i++)
			{
				string stringState = CustomUIManager.GetStringState($"slot_{i}_contents");
				int countState = CustomUIManager.GetCountState($"slot_{i}_loops");
				if (string.IsNullOrEmpty(stringState) || stringState == "None" || countState <= 0)
				{
					continue;
				}
				string text = stringState;
				string text2 = "";
				bool item = true;
				if (stringState == "Silos Breakroom")
				{
					text = "Silos";
					text2 = RegionDefinitions["Silos"].BreakroomAsset;
					item = false;
				}
				else if (stringState == "Silos Campaign Breakroom")
				{
					text = "Silos";
					text2 = "Region_Silos_Saferoom";
					item = false;
				}
				else
				{
					if (!RegionDefinitions.ContainsKey(stringState))
					{
						continue;
					}
					text = stringState;
					text2 = RegionDefinitions[stringState].RegionAsset;
				}
				list.Add((stringState, text, text2, countState, item));
			}
			if (list.Count == 0)
			{
				M_Region andFilterRegion = GetAndFilterRegion(RegionDefinitions["Silos"].BreakroomAsset);
				if ((Object)(object)andFilterRegion != (Object)null)
				{
					EndlessMode.regions.Add(andFilterRegion);
				}
				return;
			}
			BEGONE_FOUL_SPIRIT = list[0].Item2 == "Abyss";
			giveStartingItems = true;
			for (int j = 0; j < list.Count; j++)
			{
				(string, string, string, int, bool) tuple = list[j];
				string text3 = tuple.Item2.ToLower();
				M_Region andFilterRegion2 = GetAndFilterRegion(tuple.Item3);
				M_Region val = (RegionDefinitions.ContainsKey(tuple.Item2) ? GetAndFilterRegion(RegionDefinitions[tuple.Item2].BreakroomAsset) : null);
				int num = Mathf.Max(0, CustomUIManager.GetCountState(text3 + "_breakrooms"));
				bool toggleState = CustomUIManager.GetToggleState(text3 + "_breakroom_first");
				for (int k = 0; k < tuple.Item4; k++)
				{
					if (toggleState)
					{
						for (int l = 0; l < num; l++)
						{
							if ((Object)(object)val != (Object)null && tuple.Item5)
							{
								EndlessMode.regions.Add(GetAndFilterRegion(((Object)val).name.Replace("_RuntimeCopy", "")));
							}
						}
						if ((Object)(object)andFilterRegion2 != (Object)null)
						{
							EndlessMode.regions.Add(GetAndFilterRegion(((Object)andFilterRegion2).name.Replace("_RuntimeCopy", "")));
						}
						continue;
					}
					if ((Object)(object)andFilterRegion2 != (Object)null)
					{
						EndlessMode.regions.Add(GetAndFilterRegion(((Object)andFilterRegion2).name.Replace("_RuntimeCopy", "")));
					}
					for (int m = 0; m < num; m++)
					{
						if ((Object)(object)val != (Object)null && tuple.Item5)
						{
							EndlessMode.regions.Add(GetAndFilterRegion(((Object)val).name.Replace("_RuntimeCopy", "")));
						}
					}
				}
				if (list.Count <= 1)
				{
					continue;
				}
				(string, string, string, int, bool) tuple2 = list[(j + 1) % list.Count];
				string item2 = tuple.Item2;
				string item3 = tuple2.Item2;
				if (!(item2 != item3))
				{
					continue;
				}
				List<(string, string)> list2 = new List<(string, string)>();
				foreach (var item4 in ResolveTransitions(item2, item3))
				{
					list2.Add(item4);
				}
				InjectTransitionRegion(list2, item2, item3);
			}
			for (int n = 0; n < EndlessMode.regions.Count; n++)
			{
				M_Region val2 = EndlessMode.regions[n];
				val2.nextRegion = EndlessMode.regions[(n + 1) % EndlessMode.regions.Count];
			}
		}

		public static void GiveStartingItems()
		{
			if (!((Object)(object)EndlessMode == (Object)null))
			{
				int countState = CustomUIManager.GetCountState("item_timepiece");
				if (countState > 0)
				{
					GiveItem("Item_Artifact_Timepiece", countState);
				}
				int countState2 = CustomUIManager.GetCountState("item_translocator");
				if (countState2 > 0)
				{
					GiveItem("Item_Artifact_Translocator", countState2);
				}
				int countState3 = CustomUIManager.GetCountState("item_evaglove");
				if (countState3 > 0)
				{
					GiveItem("Item_Artifact_EVAGlove", countState3);
				}
				int countState4 = CustomUIManager.GetCountState("item_rapier");
				if (countState4 > 0)
				{
					GiveItem("Item_Artifact_Rapier", countState4);
				}
				int countState5 = CustomUIManager.GetCountState("item_rebar_return");
				if (countState5 > 0)
				{
					GiveItem("Item_Artifact_Rebar_Return", countState5);
				}
				int countState6 = CustomUIManager.GetCountState("item_remote");
				if (countState6 > 0)
				{
					GiveItem("Item_Artifact_Remote", countState6);
				}
				int countState7 = CustomUIManager.GetCountState("item_handgun_kit");
				if (countState7 > 0)
				{
					GiveItem("Item_Handgun", countState7);
					GiveItem("Item_10mm_Ammo", countState7 * 2);
				}
				int countState8 = CustomUIManager.GetCountState("item_flaregun_kit");
				if (countState8 > 0)
				{
					GiveItem("Item_Flaregun", countState8);
					GiveItem("Item_Flaregun_Ammo", countState8 * 2);
				}
				int countState9 = CustomUIManager.GetCountState("item_flashlight");
				if (countState9 > 0)
				{
					GiveItem("Item_Flashlight", countState9);
				}
			}
		}

		public static void GiveStartingPerks()
		{
			if ((Object)(object)EndlessMode == (Object)null)
			{
				return;
			}
			ENT_Player player = ENT_Player.GetPlayer();
			if ((Object)(object)player == (Object)null)
			{
				return;
			}
			foreach (KeyValuePair<string, string> startingPerkTitle in StartingPerkTitles)
			{
				int countState = CustomUIManager.GetCountState(startingPerkTitle.Key);
				if (countState <= 0)
				{
					continue;
				}
				Perk perkAsset = CL_AssetManager.GetPerkAsset(startingPerkTitle.Key, "");
				if ((Object)(object)perkAsset != (Object)null)
				{
					for (int i = 0; i < countState; i++)
					{
						player.AddPerk(perkAsset, 1, true);
					}
				}
			}
		}

		private static void GiveItem(string prefabName, int cou