Decompiled source of CustomEndless v1.0.7

OddsAndEnds.dll

Decompiled 20 hours ago
using System;
using System.Collections;
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 System.Threading;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using MortarLib;
using Severon.OddsAndEnds;
using TMPro;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.EventSystems;
using UnityEngine.Events;
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 class CollapsibleContainer : MonoBehaviour, IPointerClickHandler, IEventSystemHandler
{
	[SerializeField]
	private bool startExpanded = true;

	private bool isExpanded;

	private RectTransform rectTransform;

	private void Awake()
	{
		rectTransform = ((Component)this).GetComponent<RectTransform>();
		isExpanded = startExpanded;
		UpdateVisibility();
	}

	public void OnPointerClick(PointerEventData eventData)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		RaycastResult pointerCurrentRaycast = eventData.pointerCurrentRaycast;
		if (!((Object)(object)((RaycastResult)(ref pointerCurrentRaycast)).gameObject != (Object)(object)((Component)this).gameObject))
		{
			Toggle();
		}
	}

	public void Toggle()
	{
		isExpanded = !isExpanded;
		UpdateVisibility();
		RebuildLayouts(rectTransform);
	}

	private void UpdateVisibility()
	{
		int childCount = ((Component)this).transform.childCount;
		if (childCount > 0)
		{
			((Component)((Component)this).transform.GetChild(0)).gameObject.SetActive(true);
		}
		for (int i = 1; i < childCount; i++)
		{
			((Component)((Component)this).transform.GetChild(i)).gameObject.SetActive(isExpanded);
		}
	}

	private 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 class EndlessSettings : MonoBehaviour
{
	[SerializeField]
	private MenuSettingsManager menuSettingsManager;

	[SerializeField]
	private Button panelButton;

	public string menuTag = "EndlessSettings";

	private 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" },
		{ "item_cryogun", "Cryogun" }
	};

	private 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 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 void Awake()
	{
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		if ((Object)(object)menuSettingsManager == (Object)null)
		{
			menuSettingsManager = ((Component)((Component)this).transform.parent.parent).GetComponentInChildren<MenuSettingsManager>();
		}
		if ((Object)(object)panelButton == (Object)null)
		{
			panelButton = ((Component)this).GetComponent<Button>();
		}
		if ((Object)(object)panelButton != (Object)null)
		{
			((UnityEvent)panelButton.onClick).AddListener(new UnityAction(OnPanelClicked));
		}
		RegisterAllSettings();
	}

	public void RegisterAllSettings()
	{
		if ((Object)(object)menuSettingsManager == (Object)null)
		{
			return;
		}
		foreach (KeyValuePair<string, string> startingItemTitle in startingItemTitles)
		{
			menuSettingsManager.Register(menuTag, startingItemTitle.Value, startingItemTitle.Key, SettingType.Integer, "0", "STARTING ITEMS");
		}
		foreach (KeyValuePair<string, string> startingPerkTitle in startingPerkTitles)
		{
			menuSettingsManager.Register(menuTag, startingPerkTitle.Value, startingPerkTitle.Key, SettingType.Integer, "0", "STARTING PERKS");
		}
		(string, string, string)[] array = buffSettings;
		for (int i = 0; i < array.Length; i++)
		{
			(string, string, string) tuple = array[i];
			menuSettingsManager.Register(menuTag, tuple.Item2, tuple.Item1, SettingType.Float, "0", "BUFFS");
		}
		menuSettingsManager.Register(menuTag, "Mass Scaling Mult", "mass_speed_mult", SettingType.Float, "1", "MASS");
		menuSettingsManager.Register(menuTag, "Mass Starting Speed", "mass_start_speed", SettingType.Float, "1", "MASS");
		menuSettingsManager.Register(menuTag, "Mass Acceleration Mult", "mass_accel_mult", SettingType.Float, "1", "MASS");
		menuSettingsManager.Register(menuTag, "Rubberband Mult", "mass_rubberband_mult", SettingType.Float, "1", "MASS");
		menuSettingsManager.Register(menuTag, "Enable Rubberband", "mass_rubberband_enabled", SettingType.Bool, "true", "MASS");
		menuSettingsManager.Register(menuTag, "Cycles Condition", "cycles_win_enabled", SettingType.Bool, "false", "WIN CONDITION");
		menuSettingsManager.Register(menuTag, "Win After X Cycles", "cycles_win_amount", SettingType.Integer, "1", "WIN CONDITION");
		menuSettingsManager.Register(menuTag, "Height Condition", "height_win_enabled", SettingType.Bool, "false", "WIN CONDITION");
		menuSettingsManager.Register(menuTag, "Win After Climbing X", "height_win_amount", SettingType.Float, "1000", "WIN CONDITION");
		menuSettingsManager.Register(menuTag, "Always Snowing", "fun_always_snowing", SettingType.Bool, "false", "FUN");
		menuSettingsManager.Register(menuTag, "Consumah", "fun_consumah", SettingType.Bool, "false", "FUN");
	}

	public void OnPanelClicked()
	{
		if ((Object)(object)menuSettingsManager != (Object)null)
		{
			menuSettingsManager.LoadMenu(menuTag);
		}
	}
}
public class HoverDetector : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
{
	[SerializeField]
	private float fadeDuration = 0.15f;

	[SerializeField]
	private float toggleFadeDuration = 0.1f;

	[SerializeField]
	private Color enabledColor = Color.green;

	public bool toggled;

	private Image targetImage;

	private Image buttonImage;

	private Color disabledColor;

	private Coroutine currentFadeCoroutine;

	private UISettingsManager settingsManager;

	public string settingsTag = "default_bool";

	private void Awake()
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		if (((Component)this).TryGetComponent<Image>(ref buttonImage))
		{
			disabledColor = ((Graphic)buttonImage).color;
		}
		Transform val = ((Component)this).transform.Find("Image");
		if ((Object)(object)val != (Object)null && ((Component)val).TryGetComponent<Image>(ref targetImage))
		{
			SetImageAlpha(0f);
		}
		settingsManager = UISettingsManager.instance;
	}

	private void UpdateSettingState(bool isEnabled)
	{
		if ((Object)(object)settingsManager != (Object)null)
		{
			settingsManager.SetBool(settingsTag, isEnabled);
		}
	}

	public void OnPointerEnter(PointerEventData eventData)
	{
		StartFade(1f);
	}

	public void OnPointerExit(PointerEventData eventData)
	{
		StartFade(0f);
	}

	private void StartFade(float targetAlpha)
	{
		if (!((Object)(object)targetImage == (Object)null))
		{
			if (currentFadeCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(currentFadeCoroutine);
			}
			currentFadeCoroutine = ((MonoBehaviour)this).StartCoroutine(FadeRoutine(targetAlpha));
		}
	}

	private IEnumerator FadeRoutine(float targetAlpha)
	{
		float startAlpha = ((Graphic)targetImage).color.a;
		float elapsed = 0f;
		while (elapsed < fadeDuration)
		{
			elapsed += Time.deltaTime;
			SetImageAlpha(Mathf.Lerp(startAlpha, targetAlpha, elapsed / fadeDuration));
			yield return null;
		}
		SetImageAlpha(targetAlpha);
	}

	private IEnumerator ToggleFadeRoutine(Color targetColor)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)buttonImage == (Object)null))
		{
			Color startColor = ((Graphic)buttonImage).color;
			float elapsed = 0f;
			while (elapsed < toggleFadeDuration)
			{
				elapsed += Time.deltaTime;
				((Graphic)buttonImage).color = Color.Lerp(startColor, targetColor, elapsed / toggleFadeDuration);
				yield return null;
			}
			((Graphic)buttonImage).color = targetColor;
		}
	}

	private void SetImageAlpha(float alpha)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		Color color = ((Graphic)targetImage).color;
		color.a = alpha;
		((Graphic)targetImage).color = color;
	}
}
public static class CustomLevelLoader
{
	private static readonly Dictionary<string, AssetBundle> _cachedBundles = new Dictionary<string, AssetBundle>(StringComparer.OrdinalIgnoreCase);

	public static LevelAssetHolder LoadRoom(string bundlePath, string assetName, string levelName)
	{
		//IL_0230: Unknown result type (might be due to invalid IL or missing references)
		//IL_0307: Unknown result type (might be due to invalid IL or missing references)
		//IL_031b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0320: 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_032c: Unknown result type (might be due to invalid IL or missing references)
		//IL_034c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0351: Unknown result type (might be due to invalid IL or missing references)
		//IL_0361: Expected O, but got Unknown
		string location = Assembly.GetExecutingAssembly().Location;
		string directoryName = Path.GetDirectoryName(location);
		if (string.IsNullOrEmpty(directoryName))
		{
			return null;
		}
		string text = Path.Combine(directoryName, bundlePath);
		AssetBundle value = null;
		if (!_cachedBundles.TryGetValue(text, out value) || !((Object)(object)value != (Object)null))
		{
			if (!File.Exists(text))
			{
				return null;
			}
			try
			{
				value = AssetBundle.LoadFromFile(text);
			}
			catch
			{
				return null;
			}
			if ((Object)(object)value == (Object)null)
			{
				return null;
			}
			_cachedBundles[text] = value;
		}
		GameObject val = value.LoadAsset<GameObject>(assetName);
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		GameObject val2 = Object.Instantiate<GameObject>(val);
		Object.DontDestroyOnLoad((Object)(object)val2);
		((Object)val2).name = levelName;
		M_Level val3 = val2.GetComponent<M_Level>();
		if ((Object)(object)val3 == (Object)null)
		{
			val3 = val2.AddComponent<M_Level>();
		}
		Transform val4 = FindRecursiveContains(val2.transform, "entrance");
		Transform levelExit = FindRecursiveContains(val2.transform, "exit");
		Transform val5 = FindRecursiveContains(val2.transform, "room");
		Transform[] componentsInChildren = val2.GetComponentsInChildren<Transform>(true);
		foreach (Transform val6 in componentsInChildren)
		{
			if (((Object)val6).name.IndexOf("handhold", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				ObjectTagger val7 = ((Component)val6).GetComponent<ObjectTagger>();
				if ((Object)(object)val7 == (Object)null)
				{
					val7 = ((Component)val6).gameObject.AddComponent<ObjectTagger>();
				}
				val7.AddTag("Handhold");
				((Object)val6).name = "handhold:basic-collide";
			}
			if ((Object)(object)((Component)val6).GetComponent<Light>() != (Object)null)
			{
				CL_Lamp component = ((Component)val6).GetComponent<CL_Lamp>();
				if ((Object)(object)component == (Object)null)
				{
					component = ((Component)val6).gameObject.AddComponent<CL_Lamp>();
				}
			}
		}
		CL_Lamp[] componentsInChildren2 = val2.GetComponentsInChildren<CL_Lamp>(true);
		foreach (CL_Lamp val8 in componentsInChildren2)
		{
			val8.SetColor(((Component)val8).gameObject.GetComponent<Light>().color);
			val8.range = ((Component)val8).gameObject.GetComponent<Light>().range * 2f;
			val8.lampActive = true;
			if (val8.isEffector && !CL_Lamp.effectorLamps.Contains(val8))
			{
				CL_Lamp.effectorLamps.Add(val8);
			}
			if ((Object)(object)FXManager.fxMan != (Object)null)
			{
				FXManager.fxMan.AddLamp(val8);
			}
		}
		val3.levelName = levelName;
		val3.levelEntrance = val4;
		val3.levelExit = levelExit;
		val3.isLODGap = false;
		val3.spawnPosition = val4;
		val3.customBounds = true;
		val3.levelBounds = new Bounds(new Vector3(0f, 0f, 0f), new Vector3(5f, 5f, 5f));
		val3.CalculateBounds();
		val3.canFlip = false;
		val3.showInLevelList = true;
		val3.allowEvents = true;
		val3.spawnSettings = new SpawnSettings
		{
			spawnChance = 1f
		};
		LevelAssetHolder val9 = null;
		try
		{
			val9 = LevelAssetHolder.GetNewHolderFromLevel(val3);
		}
		catch
		{
			return null;
		}
		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();
	}
}
public enum SettingType
{
	Integer,
	Float,
	Bool
}
public class MenuSettingsManager : MonoBehaviour
{
	private class SettingData
	{
		public string menuTag;

		public string displayName;

		public string settingTag;

		public SettingType settingType;

		public string defaultValue;

		public string dropdownName;
	}

	private GameObject templateFloat;

	private GameObject templateInteger;

	private GameObject templateBool;

	private GameObject templateDropdown;

	private UISettingsManager settingsManager;

	private Transform contentContainer;

	private List<SettingData> registeredSettings = new List<SettingData>();

	private List<GameObject> activeInstances = new List<GameObject>();

	private void Awake()
	{
		Transform parent = ((Component)this).transform.parent;
		settingsManager = ((parent != null) ? ((Component)parent).GetComponent<UISettingsManager>() : null);
		Transform obj = ((Component)this).transform.Find("TemplateFloat");
		templateFloat = ((obj != null) ? ((Component)obj).gameObject : null);
		Transform obj2 = ((Component)this).transform.Find("TemplateInteger");
		templateInteger = ((obj2 != null) ? ((Component)obj2).gameObject : null);
		Transform obj3 = ((Component)this).transform.Find("TemplateBool");
		templateBool = ((obj3 != null) ? ((Component)obj3).gameObject : null);
		Transform obj4 = ((Component)this).transform.Find("TemplateDropdown");
		templateDropdown = ((obj4 != null) ? ((Component)obj4).gameObject : null);
		SetupContentContainer();
	}

	private void SetupContentContainer()
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Expected O, but got Unknown
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		Transform val = ((Component)this).transform.Find("Content");
		if ((Object)(object)val != (Object)null)
		{
			contentContainer = val;
		}
		else
		{
			GameObject val2 = new GameObject("Content", new Type[1] { typeof(RectTransform) });
			contentContainer = val2.transform;
			contentContainer.SetParent(((Component)this).transform, false);
			RectTransform component = ((Component)contentContainer).GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 1f);
			component.anchorMax = new Vector2(1f, 1f);
			component.pivot = new Vector2(0.5f, 1f);
			component.anchoredPosition = Vector2.zero;
			component.sizeDelta = new Vector2(0f, component.sizeDelta.y);
			VerticalLayoutGroup component2 = ((Component)this).GetComponent<VerticalLayoutGroup>();
			if ((Object)(object)component2 != (Object)null)
			{
				VerticalLayoutGroup val3 = val2.AddComponent<VerticalLayoutGroup>();
				((LayoutGroup)val3).padding = ((LayoutGroup)component2).padding;
				((HorizontalOrVerticalLayoutGroup)val3).spacing = ((HorizontalOrVerticalLayoutGroup)component2).spacing;
				((LayoutGroup)val3).childAlignment = ((LayoutGroup)component2).childAlignment;
				((HorizontalOrVerticalLayoutGroup)val3).childControlWidth = ((HorizontalOrVerticalLayoutGroup)component2).childControlWidth;
				((HorizontalOrVerticalLayoutGroup)val3).childControlHeight = ((HorizontalOrVerticalLayoutGroup)component2).childControlHeight;
				((HorizontalOrVerticalLayoutGroup)val3).childScaleWidth = ((HorizontalOrVerticalLayoutGroup)component2).childScaleWidth;
				((HorizontalOrVerticalLayoutGroup)val3).childScaleHeight = ((HorizontalOrVerticalLayoutGroup)component2).childScaleHeight;
				((HorizontalOrVerticalLayoutGroup)val3).childForceExpandWidth = ((HorizontalOrVerticalLayoutGroup)component2).childForceExpandWidth;
				((HorizontalOrVerticalLayoutGroup)val3).childForceExpandHeight = ((HorizontalOrVerticalLayoutGroup)component2).childForceExpandHeight;
				((HorizontalOrVerticalLayoutGroup)val3).reverseArrangement = ((HorizontalOrVerticalLayoutGroup)component2).reverseArrangement;
				ContentSizeFitter val4 = val2.AddComponent<ContentSizeFitter>();
				val4.verticalFit = (FitMode)2;
			}
		}
		ScrollRect val5 = default(ScrollRect);
		if (((Component)this).TryGetComponent<ScrollRect>(ref val5))
		{
			val5.content = ((Component)contentContainer).GetComponent<RectTransform>();
			val5.viewport = ((Component)this).GetComponent<RectTransform>();
		}
		if ((Object)(object)((Component)this).GetComponent<RectMask2D>() == (Object)null && (Object)(object)((Component)this).GetComponent<Mask>() == (Object)null)
		{
			((Component)this).gameObject.AddComponent<RectMask2D>();
		}
	}

	public void Register(string menuTag, string displayName, string settingTag, SettingType settingType, string defaultValue, string dropdownName = "")
	{
		registeredSettings.Add(new SettingData
		{
			menuTag = menuTag,
			displayName = displayName,
			settingTag = settingTag,
			settingType = settingType,
			defaultValue = defaultValue,
			dropdownName = dropdownName
		});
		UISettingsManager uISettingsManager = (((Object)(object)settingsManager != (Object)null) ? settingsManager : UISettingsManager.instance);
		if (!((Object)(object)uISettingsManager != (Object)null))
		{
			return;
		}
		switch (settingType)
		{
		case SettingType.Integer:
		{
			if (int.TryParse(defaultValue, out var result2))
			{
				uISettingsManager.SetInt(settingTag, result2);
			}
			break;
		}
		case SettingType.Float:
		{
			if (float.TryParse(defaultValue, out var result3))
			{
				uISettingsManager.SetFloat(settingTag, result3);
			}
			break;
		}
		case SettingType.Bool:
		{
			if (bool.TryParse(defaultValue, out var result))
			{
				uISettingsManager.SetBool(settingTag, result);
			}
			break;
		}
		}
	}

	public void LoadMenu(string menuTag)
	{
		if ((Object)(object)contentContainer == (Object)null)
		{
			SetupContentContainer();
		}
		foreach (GameObject activeInstance in activeInstances)
		{
			if ((Object)(object)activeInstance != (Object)null)
			{
				Object.Destroy((Object)(object)activeInstance);
			}
		}
		activeInstances.Clear();
		Dictionary<string, Transform> dictionary = new Dictionary<string, Transform>();
		TMP_Text val3 = default(TMP_Text);
		Text val4 = default(Text);
		foreach (SettingData registeredSetting in registeredSettings)
		{
			if (registeredSetting.menuTag != menuTag)
			{
				continue;
			}
			bool active = true;
			Transform value = contentContainer;
			if (!string.IsNullOrEmpty(registeredSetting.dropdownName))
			{
				active = false;
				if (!dictionary.TryGetValue(registeredSetting.dropdownName, out value) && (Object)(object)templateDropdown != (Object)null)
				{
					GameObject val = Object.Instantiate<GameObject>(templateDropdown, contentContainer);
					((Object)val).name = registeredSetting.dropdownName;
					Transform val2 = val.transform.Find("Title");
					if ((Object)(object)val2 != (Object)null)
					{
						if (((Component)val2).TryGetComponent<TMP_Text>(ref val3))
						{
							val3.text = registeredSetting.dropdownName;
						}
						else if (((Component)val2).TryGetComponent<Text>(ref val4))
						{
							val4.text = registeredSetting.dropdownName;
						}
					}
					val.SetActive(true);
					dictionary[registeredSetting.dropdownName] = val.transform;
					value = val.transform;
					activeInstances.Add(val);
				}
			}
			GameObject val5 = null;
			switch (registeredSetting.settingType)
			{
			case SettingType.Integer:
				val5 = templateInteger;
				break;
			case SettingType.Float:
				val5 = templateFloat;
				break;
			case SettingType.Bool:
				val5 = templateBool;
				break;
			}
			if ((Object)(object)val5 != (Object)null)
			{
				GameObject val6 = Object.Instantiate<GameObject>(val5, value);
				MonoBehaviour val7 = null;
				object value2 = null;
				if (registeredSetting.settingType == SettingType.Integer)
				{
					val7 = (MonoBehaviour)(object)val6.GetComponent<TemplateInteger>();
					int result;
					int num = (int.TryParse(registeredSetting.defaultValue, out result) ? result : 0);
					value2 = (((Object)(object)settingsManager != (Object)null) ? settingsManager.GetInt(registeredSetting.settingTag, num) : num);
				}
				else if (registeredSetting.settingType == SettingType.Float)
				{
					val7 = (MonoBehaviour)(object)val6.GetComponent<TemplateFloat>();
					float result2;
					float num2 = (float.TryParse(registeredSetting.defaultValue, out result2) ? result2 : 0f);
					value2 = (((Object)(object)settingsManager != (Object)null) ? settingsManager.GetFloat(registeredSetting.settingTag, num2) : num2);
				}
				else if (registeredSetting.settingType == SettingType.Bool)
				{
					val7 = (MonoBehaviour)(object)val6.GetComponent<TemplateBool>();
					bool result3;
					bool flag = bool.TryParse(registeredSetting.defaultValue, out result3) && result3;
					value2 = (((Object)(object)settingsManager != (Object)null) ? settingsManager.GetBool(registeredSetting.settingTag, flag) : flag);
				}
				if ((Object)(object)val7 != (Object)null)
				{
					SetPrivateField(val7, "settingName", registeredSetting.displayName);
					SetPrivateField(val7, "settingsTag", registeredSetting.settingTag);
					SetPrivateField(val7, "defaultValue", value2);
				}
				val6.SetActive(active);
				if (string.IsNullOrEmpty(registeredSetting.dropdownName))
				{
					activeInstances.Add(val6);
				}
			}
		}
	}

	private void SetPrivateField(object target, string fieldName, object value)
	{
		FieldInfo field = target.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
		if (field != null)
		{
			field.SetValue(target, value);
		}
	}
}
public class OrderingContainer : MonoBehaviour
{
	public static OrderingContainer instance;

	private void Start()
	{
		Debug.Log((object)"ORDERING CONTAINER INITIALIZED");
		instance = this;
	}

	public void AddSlot(string logicalName, bool fromRandom = false)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		int num = 0;
		foreach (Transform item in ((Component)this).transform)
		{
			Transform val = item;
			if (((Component)val).gameObject.activeSelf && (Object)(object)((Component)val).GetComponent<RemoveOnClick>() != (Object)null)
			{
				num++;
			}
		}
		UISettingsManager.instance.add_slot_to_end(logicalName);
		Transform val2 = ((Component)this).transform.Find("TemplateSlot");
		if (!((Object)(object)val2 != (Object)null))
		{
			return;
		}
		GameObject val3 = Object.Instantiate<GameObject>(((Component)val2).gameObject, ((Component)this).transform);
		val3.SetActive(true);
		Transform val4 = val3.transform.Find("Title");
		if ((Object)(object)val4 != (Object)null)
		{
			TMP_Text component = ((Component)val4).GetComponent<TMP_Text>();
			if ((Object)(object)component != (Object)null)
			{
				if (fromRandom)
				{
					component.text = "?";
				}
				else
				{
					component.text = ((logicalName.Length >= 3) ? logicalName.Substring(0, 3) : logicalName);
				}
			}
		}
		RemoveOnClick component2 = val3.GetComponent<RemoveOnClick>();
		if ((Object)(object)component2 != (Object)null)
		{
			component2.slot = num;
		}
	}

	public void UpdateSlotIndices()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		int num = 0;
		foreach (Transform item in ((Component)this).transform)
		{
			Transform val = item;
			if (((Component)val).gameObject.activeSelf && (Object)(object)((Component)val).GetComponent<RemoveOnClick>() != (Object)null)
			{
				RemoveOnClick component = ((Component)val).GetComponent<RemoveOnClick>();
				if ((Object)(object)component != (Object)null)
				{
					component.slot = num;
					num++;
				}
			}
		}
	}

	private void OnTransformChildrenChanged()
	{
		UpdateSlotIndices();
	}
}
public class ProcGen
{
	public abstract class PathNode
	{
		public virtual bool OffshootOnly { get; } = false;

		public virtual float MinHorizontalDistance { get; } = 3f;

		public virtual float MaxHorizontalDistance { get; } = 6f;

		public virtual float MinVerticalDistance { get; } = 3f;

		public virtual float MaxVerticalDistance { get; } = 6f;

		public virtual float NextHorizontalMultiplier { get; } = 1f;

		public virtual float NextVerticalMultiplier { get; } = 1f;

		public virtual float GetNextHorizontalDistance()
		{
			return Random.Range(MinHorizontalDistance, MaxHorizontalDistance) * NextHorizontalMultiplier;
		}

		public virtual float GetNextVerticalDistance()
		{
			return Random.Range(MinVerticalDistance, MaxVerticalDistance) * NextVerticalMultiplier;
		}

		public abstract void Spawn(Vector3 position, Quaternion rotation, M_Level level);

		protected GameObject GetPrefab(string name, M_Level level)
		{
			GameObject val = EndlessConfiguration.M_Level_OnLevelActivate_Items_Patch.FindChildByName(((Component)level).gameObject.transform, name);
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			return EndlessConfiguration.GetCachedObject<GameObject>(name);
		}
	}

	public class BasicPlatform : PathNode
	{
		public override float MinHorizontalDistance => 4f;

		public override float MaxHorizontalDistance => 7f;

		public override float MinVerticalDistance => 3f;

		public override float MaxVerticalDistance => 5f;

		public override void Spawn(Vector3 position, Quaternion rotation, M_Level level)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			GameObject prefab = GetPrefab("Cube", level);
			if ((Object)(object)prefab != (Object)null)
			{
				GeneratePlatform(position, 4, prefab);
			}
		}
	}

	public class BasicPlatform2 : PathNode
	{
		public override float MinHorizontalDistance => 4f;

		public override float MaxHorizontalDistance => 7f;

		public override float MinVerticalDistance => 3f;

		public override float MaxVerticalDistance => 5f;

		public override void Spawn(Vector3 position, Quaternion rotation, M_Level level)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			GameObject prefab = GetPrefab("Cube", level);
			if ((Object)(object)prefab != (Object)null)
			{
				GeneratePlatform(position, 3, prefab);
			}
		}
	}

	public class BasicPlatform3 : PathNode
	{
		public override float MinHorizontalDistance => 4f;

		public override float MaxHorizontalDistance => 7f;

		public override float MinVerticalDistance => 3f;

		public override float MaxVerticalDistance => 5f;

		public override void Spawn(Vector3 position, Quaternion rotation, M_Level level)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			GameObject prefab = GetPrefab("Cube", level);
			if ((Object)(object)prefab != (Object)null)
			{
				GeneratePlatform(position, 5, prefab);
			}
		}
	}

	public class DropPlatform : PathNode
	{
		public override float MinHorizontalDistance => 4f;

		public override float MaxHorizontalDistance => 7f;

		public override float MinVerticalDistance => -20f;

		public override float MaxVerticalDistance => 9f;

		public override void Spawn(Vector3 position, Quaternion rotation, M_Level level)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			GameObject prefab = GetPrefab("Cube", level);
			if ((Object)(object)prefab != (Object)null)
			{
				GeneratePlatform(position, 5, prefab);
			}
		}
	}

	public class LongJumpPlatform : PathNode
	{
		public override float MinHorizontalDistance => 7f;

		public override float MaxHorizontalDistance => 15f;

		public override float MinVerticalDistance => -1f;

		public override float MaxVerticalDistance => 1f;

		public override void Spawn(Vector3 position, Quaternion rotation, M_Level level)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			GameObject prefab = GetPrefab("Cube", level);
			if ((Object)(object)prefab != (Object)null)
			{
				SpawnVoxelPlatform(position, rotation, new Vector3Int(2, 1, 6), prefab, ((Component)level).transform);
			}
		}
	}

	public class LongJumpPlatform2 : PathNode
	{
		public override float MinHorizontalDistance => 14f;

		public override float MaxHorizontalDistance => 20f;

		public override float MinVerticalDistance => -1f;

		public override float MaxVerticalDistance => 1f;

		public override void Spawn(Vector3 position, Quaternion rotation, M_Level level)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			GameObject prefab = GetPrefab("Cube", level);
			if ((Object)(object)prefab != (Object)null)
			{
				SpawnVoxelPlatform(position, rotation, new Vector3Int(1, 1, Random.Range(13, 20)), prefab, ((Component)level).transform);
			}
		}
	}

	public class AirBarnacle : PathNode
	{
		public override bool OffshootOnly => true;

		public override float MinHorizontalDistance => 3f;

		public override float MaxHorizontalDistance => 5f;

		public override float MinVerticalDistance => -8f;

		public override float MaxVerticalDistance => -5f;

		public override void Spawn(Vector3 position, Quaternion rotation, M_Level level)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: 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_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Expected O, but got Unknown
			GameObject prefab = GetPrefab("Denizen_Barnacle_Small", level);
			if (!((Object)(object)prefab != (Object)null))
			{
				return;
			}
			GameObject val = Object.Instantiate<GameObject>(prefab, position, Quaternion.identity, ((Component)level).transform);
			((Renderer)val.GetComponentInChildren<SkinnedMeshRenderer>()).enabled = false;
			((Behaviour)val.GetComponentInChildren<Animator>()).enabled = false;
			DEN_Barnacle component = val.GetComponent<DEN_Barnacle>();
			component.spawnPolyps = false;
			if ((Object)(object)component.geo != (Object)null)
			{
				component.geo.localPosition = Vector3.zero;
				component.geo.localRotation = Quaternion.identity;
				Transform[] componentsInChildren = ((Component)component.geo).GetComponentsInChildren<Transform>();
				foreach (Transform val2 in componentsInChildren)
				{
					val2.localPosition = Vector3.zero;
				}
			}
			Barnacle_Tongue_Interface_Module tongueInterface = component.tongueInterface;
			Barnacle_Tongue_Interface_Module_Basic val3 = (Barnacle_Tongue_Interface_Module_Basic)(object)((tongueInterface is Barnacle_Tongue_Interface_Module_Basic) ? tongueInterface : null);
			if (val3 != null && val3.tongues != null && val3.tongues.Count > 0)
			{
				GameObject gameObject = ((Component)val3.tongues[0].tongue).gameObject;
				Transform val4 = (((Object)(object)gameObject.transform.parent != (Object)null) ? gameObject.transform.parent : ((Component)component).transform);
				gameObject.transform.localPosition = Vector3.zero;
				Transform[] componentsInChildren2 = gameObject.GetComponentsInChildren<Transform>();
				foreach (Transform val5 in componentsInChildren2)
				{
					val5.localPosition = Vector3.zero;
				}
				int num = 3;
				for (int k = 0; k < num; k++)
				{
					GameObject val6 = Object.Instantiate<GameObject>(gameObject, val4);
					((Object)val6).name = "Barnacle_Tongue_" + val3.tongues.Count;
					val6.transform.localPosition = Vector3.zero;
					val6.transform.localRotation = Quaternion.identity;
					val6.transform.localScale = gameObject.transform.localScale;
					Transform[] componentsInChildren3 = val6.GetComponentsInChildren<Transform>();
					foreach (Transform val7 in componentsInChildren3)
					{
						val7.localPosition = Vector3.zero;
					}
					Barnacle_Tongue_Basic val8 = new Barnacle_Tongue_Basic();
					val8.tongue = val6.transform;
					val8.canReachForAir = true;
					val3.tongues.Add(val8);
				}
				val3.tongueScatter = 3.15f;
				val3.scanDistance = 10f;
				val3.tongueAimTime = 2f;
				val3.tongueSpeed += 0.1f;
				((Barnacle_Tongue_Interface_Module)val3).Initialize(component);
			}
			Transform[] componentsInChildren4 = ((Component)component).GetComponentsInChildren<Transform>();
			foreach (Transform val9 in componentsInChildren4)
			{
				if ((Object)(object)val9 != (Object)(object)((Component)component).transform && (Object)(object)val9.parent == (Object)(object)((Component)component).transform)
				{
					val9.localPosition = Vector3.zero;
				}
			}
			GameObject prefab2 = GetPrefab("AirBarnacle", level);
			Object.Instantiate<GameObject>(prefab2, ((Component)component).transform.position, Quaternion.identity, val.transform);
			((Component)component).gameObject.SetActive(true);
			((Behaviour)component).enabled = true;
			val.SetActive(true);
			((GameEntity)component).Start();
		}
	}

	public class Ladder : PathNode
	{
		public override float MinHorizontalDistance => 3f;

		public override float MaxHorizontalDistance => 5f;

		public override float MinVerticalDistance => 20f;

		public override float MaxVerticalDistance => 25f;

		public override void Spawn(Vector3 position, Quaternion rotation, M_Level level)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			GameObject prefab = GetPrefab("Cube", level);
			if ((Object)(object)prefab != (Object)null)
			{
				GameObject val = SpawnVoxelPlatform(position, rotation, new Vector3Int(1, 10, 1), prefab, ((Component)level).transform, 2f);
				Transform transform = val.transform;
				transform.position += Vector3.up * 10f;
			}
		}
	}

	public class Handhold : PathNode
	{
		public override bool OffshootOnly => true;

		public override float MinHorizontalDistance => 17f;

		public override float MaxHorizontalDistance => 25f;

		public override float MinVerticalDistance => 15f;

		public override float MaxVerticalDistance => 23f;

		public override void Spawn(Vector3 position, Quaternion rotation, M_Level level)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			GameObject prefab = GetPrefab("Item_Artifact_Remote_Handhold", level);
			if ((Object)(object)prefab != (Object)null)
			{
				GameObject val = Object.Instantiate<GameObject>(prefab, position, rotation, ((Component)level).transform);
				UT_DestroyAfterTime component = val.GetComponent<UT_DestroyAfterTime>();
				if ((Object)(object)component != (Object)null)
				{
					((Behaviour)component).enabled = false;
				}
				UT_Timer component2 = val.GetComponent<UT_Timer>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.endEvent.Invoke();
					((Behaviour)component2).enabled = false;
				}
				CL_Handhold component3 = val.GetComponent<CL_Handhold>();
				if ((Object)(object)component3 != (Object)null)
				{
					component3.jumpMult *= 3f;
				}
				val.SetActive(false);
				GameObject val2 = new GameObject("HANDHOLD DADDY");
				val2.transform.position = val.transform.position;
				val2.AddComponent<ProximityChildActivator>();
			}
		}
	}

	public class Handhold2 : PathNode
	{
		public override float MinHorizontalDistance => 5f;

		public override float MaxHorizontalDistance => 13f;

		public override float MinVerticalDistance => 5f;

		public override float MaxVerticalDistance => 13f;

		public override void Spawn(Vector3 position, Quaternion rotation, M_Level level)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			GameObject prefab = GetPrefab("Item_Artifact_Remote_Handhold", level);
			if ((Object)(object)prefab != (Object)null)
			{
				GameObject val = Object.Instantiate<GameObject>(prefab, position, rotation, ((Component)level).transform);
				UT_DestroyAfterTime component = val.GetComponent<UT_DestroyAfterTime>();
				if ((Object)(object)component != (Object)null)
				{
					((Behaviour)component).enabled = false;
				}
				UT_Timer component2 = val.GetComponent<UT_Timer>();
				if ((Object)(object)component2 != (Object)null)
				{
					((Behaviour)component2).enabled = false;
				}
				val.SetActive(false);
				GameObject val2 = new GameObject("HANDHOLD DADDY");
				val2.transform.position = val.transform.position;
				val2.AddComponent<ProximityChildActivator>();
				val.transform.SetParent(val2.transform, true);
			}
		}
	}

	public class HighJumpPlatform : PathNode
	{
		public override float MinHorizontalDistance => 1f;

		public override float MaxHorizontalDistance => 2f;

		public override float MinVerticalDistance => 5f;

		public override float MaxVerticalDistance => 8f;

		public override void Spawn(Vector3 position, Quaternion rotation, M_Level level)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			GameObject prefab = GetPrefab("Cube", level);
			if ((Object)(object)prefab != (Object)null)
			{
				SpawnVoxelPlatform(position, rotation, new Vector3Int(2, 1, 2), prefab, ((Component)level).transform);
			}
		}
	}

	public class ItemPlatform : PathNode
	{
		public List<string> itemIds = new List<string>
		{
			"Item_Beans", "Item_Beans", "Item_Beans", "Item_Rebar_Bone", "Item_Beans", "Item_Rebar_Bone", "Item_Rebar_Bone", "Item_Rebar_Explosive", "Item_Injector", "Item_Food_Bar",
			"Item_Pillbottle"
		};

		public override bool OffshootOnly => true;

		public override float MinHorizontalDistance => 1f;

		public override float MaxHorizontalDistance => 2f;

		public override float MinVerticalDistance => 5f;

		public override float MaxVerticalDistance => 8f;

		public override void Spawn(Vector3 position, Quaternion rotation, M_Level level)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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)
			GameObject prefab = GetPrefab("Cube", level);
			if ((Object)(object)prefab != (Object)null)
			{
				Transform componentInChildren = SpawnVoxelPlatform(position, rotation, new Vector3Int(2, 1, 2), prefab, ((Component)level).transform).GetComponentInChildren<Transform>();
				SpawnRandomItems(position, rotation, level, componentInChildren);
			}
		}

		private void SpawnRandomItems(Vector3 position, Quaternion rotation, M_Level level, Transform parent)
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			if (itemIds == null || itemIds.Count == 0)
			{
				return;
			}
			int num = Random.Range(1, 4);
			Vector3 val = default(Vector3);
			for (int i = 0; i < num; i++)
			{
				string name = itemIds[Random.Range(0, itemIds.Count)];
				GameObject gameObject = ((Component)EndlessConfiguration.GetCachedObject<Item_Object>(name)).gameObject;
				if ((Object)(object)gameObject != (Object)null)
				{
					((Vector3)(ref val))..ctor(Random.Range(-0.8f, 0.8f), 0.6f, Random.Range(-0.8f, 0.8f));
					Vector3 val2 = position + rotation * val;
					Object.Instantiate<GameObject>(gameObject, val2, rotation, parent).GetComponent<Rigidbody>().useGravity = false;
				}
			}
		}
	}

	public class BapPlatform : PathNode
	{
		public override float MinHorizontalDistance => 1f;

		public override float MaxHorizontalDistance => 2f;

		public override float MinVerticalDistance => 5f;

		public override float MaxVerticalDistance => 8f;

		public override void Spawn(Vector3 position, Quaternion rotation, M_Level level)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			GameObject prefab = GetPrefab("Cube", level);
			if ((Object)(object)prefab != (Object)null)
			{
				SpawnVoxelPlatform(position, rotation, new Vector3Int(1, 1, 1), prefab, ((Component)level).transform);
			}
		}
	}

	public int targetHeight = 458;

	public int minPaths = 1;

	public int maxPaths = 2;

	public float centerBias = 0.001f;

	public float offshootChance = 0.3f;

	private static List<PathNode> availableNodes = new List<PathNode>();

	private static List<PathNode> mainPathNodes = new List<PathNode>();

	private static List<PathNode> offshootNodes = new List<PathNode>();

	private static bool initialized = false;

	public static void Init()
	{
		if (initialized)
		{
			return;
		}
		initialized = true;
		availableNodes.Clear();
		mainPathNodes.Clear();
		offshootNodes.Clear();
		IEnumerable<Type> enumerable = from t in Assembly.GetExecutingAssembly().GetTypes()
			where typeof(PathNode).IsAssignableFrom(t) && !t.IsAbstract && t != typeof(PathNode)
			select t;
		foreach (Type item in enumerable)
		{
			if (Activator.CreateInstance(item) is PathNode pathNode)
			{
				availableNodes.Add(pathNode);
				offshootNodes.Add(pathNode);
				if (!pathNode.OffshootOnly)
				{
					mainPathNodes.Add(pathNode);
				}
			}
		}
	}

	public static void Generate(M_Level level)
	{
		ProcGen procGen = new ProcGen();
		procGen.StartGeneration(level);
	}

	public virtual void StartGeneration(M_Level level)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//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_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: 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_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		if (!initialized)
		{
			Init();
		}
		Vector3 val = ((Component)level).transform.position + Vector3.up * 1.5f + Vector3.forward * 9f;
		Vector3 target = val + Vector3.up * (float)targetHeight;
		int num = Random.Range(minPaths, maxPaths + 1);
		for (int i = 0; i < num; i++)
		{
			GeneratePath(val, target, level);
		}
	}

	protected virtual void GeneratePath(Vector3 start, Vector3 target, M_Level level)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: 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_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: 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_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: 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_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = start;
		Vector2 val2 = default(Vector2);
		((Vector2)(ref val2))..ctor(start.x, start.z);
		PathNode pathNode = new BasicPlatform();
		Vector3 val5 = default(Vector3);
		while (val.y < target.y)
		{
			PathNode pathNode2 = mainPathNodes[Random.Range(0, mainPathNodes.Count)];
			float nextVerticalDistance = pathNode.GetNextVerticalDistance();
			float nextHorizontalDistance = pathNode.GetNextHorizontalDistance();
			Vector2 insideUnitCircle = Random.insideUnitCircle;
			Vector2 normalized = ((Vector2)(ref insideUnitCircle)).normalized;
			Vector2 val3 = new Vector2(val.x, val.z) + normalized * nextHorizontalDistance;
			Vector2 val4 = (val2 - val3) * centerBias;
			val3 += val4;
			((Vector3)(ref val5))..ctor(val3.x, val.y + nextVerticalDistance, val3.y);
			if (val5.y > target.y)
			{
				val5.y = target.y;
			}
			Vector3 val6 = val5 - val;
			val6.y = 0f;
			Quaternion rotation = Quaternion.identity;
			if (((Vector3)(ref val6)).sqrMagnitude > 0.001f)
			{
				rotation = Quaternion.LookRotation(((Vector3)(ref val6)).normalized);
			}
			pathNode2.Spawn(val5, rotation, level);
			if (Random.value < offshootChance)
			{
				GenerateOffshoot(val5, ((Vector3)(ref val6)).normalized, level);
			}
			val = val5;
			pathNode = pathNode2;
		}
		PathNode pathNode3 = new BasicPlatform();
		pathNode3.Spawn(new Vector3(val2.x, target.y, val2.y), Quaternion.identity, level);
	}

	protected virtual void GenerateOffshoot(Vector3 startPos, Vector3 mainDirection, M_Level level)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
		//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_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: 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_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: 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_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: 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_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		int num = Random.Range(2, 6);
		Vector3 val = startPos;
		PathNode pathNode = new BasicPlatform();
		Vector2 normalized = default(Vector2);
		((Vector2)(ref normalized))..ctor(mainDirection.x, mainDirection.z);
		Vector2 val2;
		if (((Vector2)(ref normalized)).sqrMagnitude < 0.001f)
		{
			val2 = Random.insideUnitCircle;
			normalized = ((Vector2)(ref val2)).normalized;
		}
		else
		{
			((Vector2)(ref normalized)).Normalize();
		}
		float num2 = ((Random.Range(0, 2) == 0) ? Random.Range(60f, 120f) : Random.Range(-120f, -60f));
		Vector2 val3 = Vector2.op_Implicit(Quaternion.Euler(0f, 0f, num2) * Vector2.op_Implicit(normalized));
		Vector3 val5 = default(Vector3);
		for (int i = 0; i < num; i++)
		{
			PathNode pathNode2 = offshootNodes[Random.Range(0, offshootNodes.Count)];
			float num3 = pathNode.GetNextVerticalDistance() * 0.5f;
			float nextHorizontalDistance = pathNode.GetNextHorizontalDistance();
			val2 = val3 + Random.insideUnitCircle * 0.2f;
			Vector2 normalized2 = ((Vector2)(ref val2)).normalized;
			Vector2 val4 = new Vector2(val.x, val.z) + normalized2 * nextHorizontalDistance;
			((Vector3)(ref val5))..ctor(val4.x, val.y + num3, val4.y);
			Vector3 val6 = val5 - val;
			val6.y = 0f;
			Quaternion rotation = Quaternion.identity;
			if (((Vector3)(ref val6)).sqrMagnitude > 0.001f)
			{
				rotation = Quaternion.LookRotation(((Vector3)(ref val6)).normalized);
			}
			pathNode2.Spawn(val5, rotation, level);
			val = val5;
			pathNode = pathNode2;
		}
	}

	public static void GeneratePlatform(Vector3 position, int size, GameObject cube)
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: 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_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
		float num = (float)(size - 1) / 2f;
		float num2 = (float)size / 2f;
		float num3 = Random.Range(0f, 500f);
		float num4 = Random.Range(0f, 500f);
		int num5 = Mathf.RoundToInt(position.x) - size / 2;
		int num6 = Mathf.RoundToInt(position.z) - size / 2;
		int num7 = Mathf.RoundToInt(position.y);
		Vector3Int val = default(Vector3Int);
		for (int i = 0; i < size; i++)
		{
			for (int j = 0; j < size; j++)
			{
				float num8 = Vector2.Distance(new Vector2((float)i, (float)j), new Vector2(num, num)) / num2;
				float num9 = Mathf.PerlinNoise((float)i * 0.3f + num3, (float)j * 0.3f + num4);
				if (num8 <= 0.45f || (num8 <= 1.1f && num9 > num8 * 0.65f))
				{
					((Vector3Int)(ref val))..ctor(num5 + i, num7, num6 + j);
					Object.Instantiate<GameObject>(cube, Vector3Int.op_Implicit(val), Quaternion.identity);
				}
			}
		}
	}

	private static GameObject SpawnVoxelPlatform(Vector3 position, Quaternion rotation, Vector3Int size, GameObject cubePrefab, Transform parent, float scale = 1f)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("VoxelPlatform");
		val.transform.SetParent(parent);
		val.transform.position = position;
		val.transform.rotation = rotation;
		Vector3 val2 = default(Vector3);
		((Vector3)(ref val2))..ctor(((float)((Vector3Int)(ref size)).x * scale - 1f) * 0.5f, ((float)((Vector3Int)(ref size)).y * scale - 1f) * 0.5f, ((float)((Vector3Int)(ref size)).z * scale - 1f) * 0.5f);
		for (int i = 0; i < ((Vector3Int)(ref size)).x; i++)
		{
			for (int j = 0; j < ((Vector3Int)(ref size)).y; j++)
			{
				for (int k = 0; k < ((Vector3Int)(ref size)).z; k++)
				{
					GameObject val3 = Object.Instantiate<GameObject>(cubePrefab, val.transform);
					val3.transform.localPosition = new Vector3((float)i * scale, (float)j * scale, (float)k * scale) - val2;
					val3.transform.localRotation = Quaternion.identity;
				}
			}
		}
		return val;
	}
}
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 class ProximityChildActivator : MonoBehaviour
{
	private bool currentState = false;

	private IEnumerator Start()
	{
		yield return (object)new WaitForSeconds(Random.Range(0f, 3f));
		WaitForSeconds wait = new WaitForSeconds(3f);
		while (true)
		{
			ENT_Player player = ENT_Player.GetPlayer();
			if ((Object)(object)player != (Object)null)
			{
				Vector3 val = ((Component)player).gameObject.transform.position - ((Component)this).transform.position;
				bool isNear = ((Vector3)(ref val)).sqrMagnitude <= 10000f;
				if (isNear != currentState)
				{
					currentState = isNear;
					int childCount = ((Component)this).transform.childCount;
					for (int i = 0; i < childCount; i++)
					{
						((Component)((Component)this).transform.GetChild(i)).gameObject.SetActive(currentState);
					}
				}
			}
			yield return wait;
		}
	}
}
public class RemoveOnClick : MonoBehaviour
{
	public int slot;

	private void Start()
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Expected O, but got Unknown
		Button component = ((Component)this).GetComponent<Button>();
		if ((Object)(object)component != (Object)null)
		{
			((UnityEvent)component.onClick).AddListener(new UnityAction(RemoveAndDestroy));
		}
	}

	private void RemoveAndDestroy()
	{
		if ((Object)(object)UISettingsManager.instance != (Object)null)
		{
			UISettingsManager.instance.remove_slot(slot);
		}
		Object.Destroy((Object)(object)((Component)this).gameObject);
	}
}
public class Rotator : MonoBehaviour
{
	[SerializeField]
	private float rotationSpeed = 20f;

	private void Update()
	{
		((Component)this).transform.Rotate(0f, 0f, rotationSpeed * Time.deltaTime, (Space)1);
	}
}
[RequireComponent(typeof(BoxCollider))]
public class TeleportTrigger : MonoBehaviour
{
	private bool hasTriggered;

	private void Reset()
	{
		BoxCollider component = ((Component)this).GetComponent<BoxCollider>();
		if ((Object)(object)component != (Object)null)
		{
			((Collider)component).isTrigger = true;
		}
	}

	private void OnTriggerEnter(Collider other)
	{
		if (!hasTriggered)
		{
			hasTriggered = true;
			EndlessConfiguration.TeleportPlayerToNextLevel(new string[1] { "" });
			EndlessConfiguration.DeathFloorHeightPatch.allowHeightUpdates = true;
		}
	}
}
public class UISettingsManager : MonoBehaviour
{
	private Dictionary<string, int> intSettings = new Dictionary<string, int>();

	private Dictionary<string, float> floatSettings = new Dictionary<string, float>();

	private Dictionary<string, string> stringSettings = new Dictionary<string, string>();

	private Dictionary<string, bool> boolSettings = new Dictionary<string, bool>();

	private int activeSlotCount = 0;

	private GameObject bgOverlay;

	public static UISettingsManager instance;

	private void Awake()
	{
		instance = this;
	}

	private void OnEnable()
	{
		instance = this;
		SetupBackgroundOverlay();
	}

	private void SetupBackgroundOverlay()
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Expected O, but got Unknown
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: 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_0107: Expected O, but got Unknown
		if ((Object)(object)bgOverlay != (Object)null)
		{
			Object.Destroy((Object)(object)bgOverlay);
		}
		bgOverlay = new GameObject("MenuBackgroundOverlay");
		bgOverlay.transform.SetParent(((Component)this).transform, false);
		bgOverlay.transform.SetAsFirstSibling();
		RectTransform val = bgOverlay.AddComponent<RectTransform>();
		val.anchorMin = Vector2.zero;
		val.anchorMax = Vector2.one;
		val.offsetMin = Vector2.zero;
		val.offsetMax = Vector2.zero;
		Image val2 = bgOverlay.AddComponent<Image>();
		((Graphic)val2).color = new Color(0.05f, 0.05f, 0.05f, 0.99f);
		Button closeButton = bgOverlay.AddComponent<Button>();
		((Selectable)closeButton).transition = (Transition)0;
		((UnityEvent)closeButton.onClick).AddListener((UnityAction)delegate
		{
			((Selectable)closeButton).interactable = false;
			bgOverlay.transform.SetParent(((Component)this).transform.parent, false);
			Object.Destroy((Object)(object)bgOverlay, 0.1f);
			bgOverlay = null;
			((Component)this).gameObject.SetActive(false);
		});
	}

	public void SetInt(string key, int value)
	{
		Debug.Log((object)(key + " " + value));
		intSettings[key] = value;
	}

	public int GetInt(string key, int defaultValue = 0)
	{
		if (intSettings.TryGetValue(key, out var value))
		{
			return value;
		}
		return defaultValue;
	}

	public void SetFloat(string key, float value)
	{
		floatSettings[key] = value;
	}

	public float GetFloat(string key, float defaultValue = 0f)
	{
		if (floatSettings.TryGetValue(key, out var value))
		{
			return value;
		}
		return defaultValue;
	}

	public void SetString(string key, string value)
	{
		stringSettings[key] = value;
	}

	public string GetString(string key, string defaultValue = "")
	{
		if (stringSettings.TryGetValue(key, out var value))
		{
			return value;
		}
		return defaultValue;
	}

	public void SetBool(string key, bool value)
	{
		Debug.Log((object)key);
		Debug.Log((object)value);
		boolSettings[key] = value;
	}

	public bool GetBool(string key, bool defaultValue = false)
	{
		if (boolSettings.TryGetValue(key, out var value))
		{
			return value;
		}
		return defaultValue;
	}

	public void add_slot_to_end(string logical_name)
	{
		if (activeSlotCount < 50)
		{
			SetString($"slot_{activeSlotCount}_contents", logical_name);
			SetInt($"slot_{activeSlotCount}_loops", 1);
			activeSlotCount++;
		}
	}

	public void remove_slot(int slot_index)
	{
		if (slot_index >= 0 && slot_index < activeSlotCount)
		{
			for (int i = slot_index; i < activeSlotCount - 1; i++)
			{
				SetString($"slot_{i}_contents", GetString($"slot_{i + 1}_contents"));
				SetInt($"slot_{i}_loops", GetInt($"slot_{i + 1}_loops"));
			}
			SetString($"slot_{activeSlotCount - 1}_contents", "None");
			SetInt($"slot_{activeSlotCount - 1}_loops", 0);
			activeSlotCount--;
		}
	}
}
public class TemplateBool : MonoBehaviour
{
	[SerializeField]
	private string settingName = "Bool Setting";

	[SerializeField]
	private string settingsTag = "default_bool";

	[SerializeField]
	private bool defaultValue = false;

	private TMP_Text titleText;

	private Toggle toggleInput;

	private UISettingsManager settingsManager;

	private void Awake()
	{
		settingsManager = UISettingsManager.instance;
		Transform val = ((Component)this).transform.Find("Title");
		if ((Object)(object)val != (Object)null)
		{
			titleText = ((Component)val).GetComponent<TMP_Text>();
		}
		Transform val2 = ((Component)this).transform.Find("Input");
		if ((Object)(object)val2 != (Object)null)
		{
			toggleInput = ((Component)val2).GetComponent<Toggle>();
		}
	}

	private void Start()
	{
		if ((Object)(object)titleText != (Object)null)
		{
			titleText.text = settingName;
		}
		if ((Object)(object)toggleInput != (Object)null)
		{
			toggleInput.isOn = defaultValue;
			((UnityEvent<bool>)(object)toggleInput.onValueChanged).AddListener((UnityAction<bool>)OnToggleValueChanged);
		}
		UpdateSettingState(defaultValue);
	}

	private void OnToggleValueChanged(bool newValue)
	{
		UpdateSettingState(newValue);
	}

	private void UpdateSettingState(bool value)
	{
		if ((Object)(object)settingsManager != (Object)null)
		{
			settingsManager.SetBool(settingsTag, value);
		}
	}
}
public class TemplateFloat : MonoBehaviour
{
	[SerializeField]
	private string settingName = "Float Setting";

	[SerializeField]
	private string settingsTag = "default_float";

	[SerializeField]
	private float defaultValue = 0f;

	private TMP_Text titleText;

	private TMP_InputField inputField;

	private UISettingsManager settingsManager;

	private void Awake()
	{
		settingsManager = UISettingsManager.instance;
		Transform val = ((Component)this).transform.Find("Title");
		if ((Object)(object)val != (Object)null)
		{
			titleText = ((Component)val).GetComponent<TMP_Text>();
		}
		Transform val2 = ((Component)this).transform.Find("Input");
		if ((Object)(object)val2 != (Object)null)
		{
			inputField = ((Component)val2).GetComponent<TMP_InputField>();
		}
	}

	private void Start()
	{
		if ((Object)(object)titleText != (Object)null)
		{
			titleText.text = settingName;
		}
		if ((Object)(object)inputField != (Object)null)
		{
			inputField.contentType = (ContentType)3;
			inputField.text = defaultValue.ToString();
			((UnityEvent<string>)(object)inputField.onValueChanged).AddListener((UnityAction<string>)OnInputValueChanged);
		}
		UpdateSettingState(defaultValue);
	}

	private void OnInputValueChanged(string newValue)
	{
		if (float.TryParse(newValue, out var result))
		{
			UpdateSettingState(result);
		}
		else if (string.IsNullOrEmpty(newValue))
		{
			UpdateSettingState(0f);
		}
	}

	private void UpdateSettingState(float value)
	{
		if ((Object)(object)settingsManager != (Object)null)
		{
			settingsManager.SetFloat(settingsTag, value);
		}
	}
}
public class TemplateInteger : MonoBehaviour
{
	[SerializeField]
	private string settingName = "Integer Setting";

	[SerializeField]
	private string settingsTag = "default_int";

	[SerializeField]
	private int defaultValue = 0;

	private TMP_Text titleText;

	private TMP_InputField inputField;

	private UISettingsManager settingsManager;

	private void Awake()
	{
		settingsManager = UISettingsManager.instance;
		Transform val = ((Component)this).transform.Find("Title");
		if ((Object)(object)val != (Object)null)
		{
			titleText = ((Component)val).GetComponent<TMP_Text>();
		}
		Transform val2 = ((Component)this).transform.Find("Input");
		if ((Object)(object)val2 != (Object)null)
		{
			inputField = ((Component)val2).GetComponent<TMP_InputField>();
		}
	}

	private void Start()
	{
		if ((Object)(object)titleText != (Object)null)
		{
			titleText.text = settingName;
		}
		if ((Object)(object)inputField != (Object)null)
		{
			inputField.contentType = (ContentType)2;
			inputField.text = defaultValue.ToString();
			((UnityEvent<string>)(object)inputField.onValueChanged).AddListener((UnityAction<string>)OnInputValueChanged);
		}
		UpdateSettingState(defaultValue);
	}

	private void OnInputValueChanged(string newValue)
	{
		if (int.TryParse(newValue, out var result))
		{
			UpdateSettingState(result);
		}
		else if (string.IsNullOrEmpty(newValue))
		{
			UpdateSettingState(0);
		}
	}

	private void UpdateSettingState(int value)
	{
		if ((Object)(object)settingsManager != (Object)null)
		{
			settingsManager.SetInt(settingsTag, value);
		}
	}
}
public class TemplateRegion : MonoBehaviour, IPointerClickHandler, IEventSystemHandler
{
	[SerializeField]
	private string regionName = "Silos";

	[SerializeField]
	private int defaultLoops = 0;

	[SerializeField]
	private float defaultLengthMult = 1f;

	[SerializeField]
	private int defaultBreakrooms = 1;

	[SerializeField]
	private bool defaultBreakroomFirst = false;

	[SerializeField]
	private string[] subregionKeys = new string[0];

	[SerializeField]
	private string[] subregionDisplayNames = new string[0];

	private TMP_Text titleTMP;

	private Text titleText;

	private MenuSettingsManager menuSettingsManager;

	private Coroutine fadeCoroutine;

	private void Awake()
	{
		if ((Object)(object)((Component)this).transform.parent != (Object)null && (Object)(object)((Component)this).transform.parent.parent != (Object)null)
		{
			menuSettingsManager = ((Component)((Component)this).transform.parent.parent).GetComponentInChildren<MenuSettingsManager>();
		}
		Transform val = ((Component)this).transform.Find("Title");
		if ((Object)(object)val != (Object)null && !((Component)val).TryGetComponent<TMP_Text>(ref titleTMP))
		{
			((Component)val).TryGetComponent<Text>(ref titleText);
		}
	}

	private void Start()
	{
		if ((Object)(object)titleTMP != (Object)null)
		{
			titleTMP.text = regionName;
		}
		else if ((Object)(object)titleText != (Object)null)
		{
			titleText.text = regionName;
		}
		RegisterRegionSettings();
	}

	private void RegisterRegionSettings()
	{
		if ((Object)(object)menuSettingsManager == (Object)null)
		{
			return;
		}
		string text = regionName.ToLower();
		string dropdownName = regionName.ToUpper() + " SETTINGS";
		menuSettingsManager.Register(regionName, "Loops", text + "_loops", SettingType.Integer, defaultLoops.ToString(), dropdownName);
		menuSettingsManager.Register(regionName, "Length Multiplier", text + "_length_mult", SettingType.Float, defaultLengthMult.ToString(), dropdownName);
		if (defaultBreakrooms != 0)
		{
			menuSettingsManager.Register(regionName, "Break Rooms", text + "_breakrooms", SettingType.Integer, defaultBreakrooms.ToString(), dropdownName);
			if (!(text == "interlude"))
			{
				menuSettingsManager.Register(regionName, "Break Rooms First", text + "_breakroom_first", SettingType.Bool, defaultBreakroomFirst.ToString(), dropdownName);
			}
			else
			{
				UISettingsManager.instance.SetBool(text + "_breakroom_first", value: true);
			}
		}
		menuSettingsManager.Register(regionName, "Faces", text + "_faces", SettingType.Integer, 0.ToString(), dropdownName);
		if (text == "checkpoint")
		{
			menuSettingsManager.Register(regionName, "Save", text + "_save", SettingType.Bool, false.ToString(), dropdownName);
			menuSettingsManager.Register(regionName, "Experimental", text + "_experimental", SettingType.Bool, false.ToString(), dropdownName);
		}
		if ((Object)(object)UISettingsManager.instance != (Object)null)
		{
			UISettingsManager.instance.SetBool(text + "_randomizable", value: true);
		}
		int num = Mathf.Min(subregionKeys.Length, subregionDisplayNames.Length);
		for (int i = 0; i < num; i++)
		{
			if (!string.IsNullOrEmpty(subregionKeys[i]))
			{
				string dropdownName2 = subregionDisplayNames[i].ToUpper();
				menuSettingsManager.Register(regionName, "Exclude", "subregion_" + subregionKeys[i] + "_disabled", SettingType.Bool, "false", dropdownName2);
				menuSettingsManager.Register(regionName, "Difficulty", "subregion_" + subregionKeys[i] + "_difficulty_mult", SettingType.Float, "1", dropdownName2);
				menuSettingsManager.Register(regionName, "Mass Speed", "subregion_" + subregionKeys[i] + "_mass_mult", SettingType.Float, "1", dropdownName2);
				menuSettingsManager.Register(regionName, "Space Compression", "subregion_" + subregionKeys[i] + "_space_mult", SettingType.Float, "1", dropdownName2);
			}
		}
	}

	public void OnPointerClick(PointerEventData eventData)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Invalid comparison between Unknown and I4
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		if ((int)eventData.button == 2)
		{
			ToggleRandomizable();
			return;
		}
		RaycastResult pointerCurrentRaycast = eventData.pointerCurrentRaycast;
		if ((Object)(object)((RaycastResult)(ref pointerCurrentRaycast)).gameObject != (Object)(object)((Component)this).gameObject)
		{
			OpenMenu();
		}
		else
		{
			if (!((Object)(object)OrderingContainer.instance != (Object)null))
			{
				return;
			}
			if (regionName == "Random")
			{
				List<string> list = new List<string>();
				TemplateRegion[] array = Object.FindObjectsOfType<TemplateRegion>();
				TemplateRegion[] array2 = array;
				foreach (TemplateRegion templateRegion in array2)
				{
					if (!(templateRegion.regionName == "Random"))
					{
						string key = templateRegion.regionName.ToLower() + "_randomizable";
						if ((Object)(object)UISettingsManager.instance == (Object)null || UISettingsManager.instance.GetBool(key, defaultValue: true))
						{
							list.Add(templateRegion.regionName);
						}
					}
				}
				if (list.Count > 0)
				{
					string logicalName = list[Random.Range(0, list.Count)];
					OrderingContainer.instance.AddSlot(logicalName, fromRandom: true);
				}
			}
			else
			{
				OrderingContainer.instance.AddSlot(regionName);
			}
		}
	}

	private void ToggleRandomizable()
	{
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		string text = regionName.ToLower();
		bool flag = (Object)(object)UISettingsManager.instance == (Object)null || UISettingsManager.instance.GetBool(text + "_randomizable", defaultValue: true);
		bool flag2 = !flag;
		if ((Object)(object)UISettingsManager.instance != (Object)null)
		{
			UISettingsManager.instance.SetBool(text + "_randomizable", flag2);
		}
		Color targetColor = (flag2 ? Color.white : Color.red);
		if (fadeCoroutine != null)
		{
			((MonoBehaviour)this).StopCoroutine(fadeCoroutine);
		}
		fadeCoroutine = ((MonoBehaviour)this).StartCoroutine(FadeTitleColor(targetColor));
	}

	private IEnumerator FadeTitleColor(Color targetColor)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		Graphic targetGraphic = null;
		if ((Object)(object)titleTMP != (Object)null)
		{
			targetGraphic = (Graphic)(object)titleTMP;
		}
		else if ((Object)(object)titleText != (Object)null)
		{
			targetGraphic = (Graphic)(object)titleText;
		}
		if (!((Object)(object)targetGraphic == (Object)null))
		{
			Color startColor = targetGraphic.color;
			float duration = 0.2f;
			float elapsed = 0f;
			while (elapsed < duration)
			{
				elapsed += Time.deltaTime;
				targetGraphic.color = Color.Lerp(startColor, targetColor, elapsed / duration);
				yield return null;
			}
			targetGraphic.color = targetColor;
		}
	}

	public void OpenMenu()
	{
		if ((Object)(object)menuSettingsManager != (Object)null)
		{
			menuSettingsManager.LoadMenu(regionName);
		}
	}
}
namespace Severon.OddsAndEnds
{
	[BepInPlugin("com.severon.oddsandends", "Severon's Odds and Ends", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony val = new Harmony("com.severon.oddsandends");
			val.PatchAll();
			val.PatchAll(typeof(EndlessConfiguration));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Severon's Odds And Ends Mod loaded successfully, hell yeah.");
		}
	}
	[HarmonyPatch(typeof(M_Gamemode), "Initialize")]
	public static class M_Gamemode_Initialize_Patch
	{
		private static void Postfix(M_Gamemode __instance)
		{
			__instance.allowLeaderboardScoring = false;
			__instance.allowCheatedScores = false;
			__instance.allowAchievements = false;
			if ((Object)(object)__instance == (Object)(object)EndlessConfiguration.EndlessMode)
			{
				EndlessConfiguration.UpdateRegions();
			}
		}
	}
	[HarmonyPatch(typeof(CL_GameManager), "Win")]
	public static class WinPatch
	{
		public static bool Prefix()
		{
			if (!EndlessConfiguration.canWin)
			{
				string[] args = new string[0];
				EndlessConfiguration.TeleportPlayerToNextLevel(args);
				UI_ObjectiveViewer.ClearAllObjectives();
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(UI_GamemodeSetting), "ToggleSetting")]
	public static class UI_GamemodeSetting_ToggleSetting_Patch
	{
		private static void Postfix()
		{
		}
	}
	[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))
			{
			}
		}
	}
	[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))
			{
				__instance.SetHeight(-50f);
				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"));
			}
		}
	}
	public class UIProxySync : MonoBehaviour
	{
		public GameObject linkedUI;

		private void OnEnable()
		{
			if ((Object)(object)linkedUI != (Object)null)
			{
				linkedUI.SetActive(true);
			}
		}

		private void OnDisable()
		{
			if ((Object)(object)linkedUI != (Object)null)
			{
				linkedUI.SetActive(false);
			}
		}

		private void OnDestroy()
		{
			if ((Object)(object)linkedUI != (Object)null)
			{
				Object.Destroy((Object)(object)linkedUI);
			}
		}
	}
	[HarmonyPatch(typeof(UI_GamemodeScreen_Panel), "Initialize")]
	public static class UI_GamemodeScreen_Panel_ScrollSettings_Patch
	{
		private static readonly string Marker = "Custom_Settings_Scroll";

		private static AssetBundle _cachedBundle;

		private static GameObject _cachedCanvasPrefab;

		private static void Postfix(UI_GamemodeScreen_Panel __instance)
		{
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			Transform settingRoot = __instance.settingRoot;
			if ((Object)(object)settingRoot == (Object)null || (Object)(object)settingRoot.Find(Marker) != (Object)null)
			{
				return;
			}
			if ((Object)(object)_cachedBundle == (Object)null)
			{
				string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
				string text = Path.Combine(directoryName, "menu_ui");
				if (File.Exists(text))
				{
					_cachedBundle = AssetBundle.LoadFromFile(text);
				}
				if ((Object)(object)_cachedBundle == (Object)null)
				{
					Debug.LogError((object)("Could not load AssetBundle at: " + text));
					return;
				}
			}
			if ((Object)(object)_cachedCanvasPrefab == (Object)null)
			{
				_cachedCanvasPrefab = ((IEnumerable<GameObject>)_cachedBundle.LoadAllAssets<GameObject>()).FirstOrDefault((Func<GameObject, bool>)((GameObject go) => (Object)(object)go.GetComponent<Canvas>() != (Object)null)) ?? _cachedBundle.LoadAllAssets<GameObject>().FirstOrDefault();
				if ((Object)(object)_cachedCanvasPrefab == (Object)null)
				{
					Debug.LogError((object)"No valid GameObject asset found in AssetBundle 'menu_ui'.");
					return;
				}
			}
			GameObject val = Object.Instantiate<GameObject>(_cachedCanvasPrefab);
			((Object)val).name = Marker;
			Canvas componentInParent = ((Component)settingRoot).GetComponentInParent<Canvas>();
			Transform val2 = (((Object)(object)componentInParent != (Object)null) ? ((Component)componentInParent).transform : settingRoot.parent.parent);
			RectTransform component = val.GetComponent<RectTransform>();
			if ((Object)(object)component != (Object)null)
			{
				((Transform)component).SetParent(val2, false);
				component.anchorMin = new Vector2(0.5f, 0.5f);
				component.anchorMax = new Vector2(0.5f, 0.5f);
				component.pivot = new Vector2(0.5f, 0.5f);
				component.anchoredPosition = Vector2.zero;
				((Transform)component).localScale = Vector3.one;
			}
			UIProxySync uIProxySync = ((Component)settingRoot).gameObject.GetComponent<UIProxySync>();
			if ((Object)(object)uIProxySync == (Object)null)
			{
				uIProxySync = ((Component)settingRoot).gameObject.AddComponent<UIProxySync>();
			}
			if ((Object)(object)uIProxySync.linkedUI != (Object)null && (Object)(object)uIProxySync.linkedUI != (Object)(object)val)
			{
				Object.Destroy((Object)(object)uIProxySync.linkedUI);
			}
			uIProxySync.linkedUI = val;
			EndlessConfiguration.CustomUIManager.UISettingsCacheSync component2 = ((Component)settingRoot).gameObject.GetComponent<EndlessConfiguration.CustomUIManager.UISettingsCacheSync>();
			if ((Object)(object)component2 == (Object)null)
			{
				component2 = ((Component)settingRoot).gameObject.AddComponent<EndlessConfiguration.CustomUIManager.UISettingsCacheSync>();
			}
			Canvas component3 = val.GetComponent<Canvas>();
			if ((Object)(object)component3 != (Object)null)
			{
				component3.renderMode = (RenderMode)0;
				component3.overrideSorting = true;
				component3.sortingOrder = 9999;
			}
			val.SetActive(false);
		}

		private static void SetLayerRecursively(GameObject go, int layer)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			if ((Object)(object)go == (Object)null)
			{
				return;
			}
			go.layer = layer;
			foreach (Transform item in go.transform)
			{
				Transform val = item;
				SetLayerRecursively(((Component)val).gameObject, layer);
			}
		}
	}
	public static class EndlessConfiguration
	{
		private class RegionDefinition
		{
			public string RegionAsset;

			public string BreakroomAsset;
		}

		public static class CustomUIManager
		{
			public class UISettingsCacheSync : MonoBehaviour
			{
				private void OnDisable()
				{
					UISettingsManager instance = UISettingsManager.instance;
					if (!((Object)(object)instance == (Object)null))
					{
						Cache("boolSettings", SettingToggles, instance);
						Cache("intSettings", SettingCounts, instance);
						Cache("floatSettings", SettingFloats, instance);
						Cache("stringSettings", SettingStrings, instance);
					}
				}

				private static void Cache<T>(string fieldName, Dictionary<string, T> destination, UISettingsManager manager)
				{
					if (!(typeof(UISettingsManager).GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(manager) is Dictionary<string, T> dictionary))
					{
						return;
					}
					destination.Clear();
					foreach (KeyValuePair<string, T> item in dictionary)
					{
						destination[item.Key] = item.Value;
					}
				}
			}

			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;
			}
		}

		[HarmonyPatch(typeof(CH_RoachCollector), "Start")]
		public static class CH_RoachCollector_Start_Patch
		{
			[HarmonyPrefix]
			public static void Prefix(CH_RoachCollector __instance, ref int ___currentRoaches, ref int ___bankTarget)
			{
				___currentRoaches = CL_GameManager.GetRoaches(false);
				___bankTarget += cycles * 5;
				collector = __instance;
			}
		}

		[HarmonyPatch(typeof(CL_GameManager), "AddRoaches")]
		private static class AddRoachesPatch
		{
			[HarmonyPostfix]
			public static void Postfix(int i)
			{
				if (CL_GameManager.GetRoaches(false) == 999 && (Object)(object)collector != (Object)null)
				{
					FieldInfo field = typeof(CH_RoachCollector).GetField("currentRoaches", BindingFlags.Instance | BindingFlags.NonPublic);
					int num = ConversionUtility.ConvertTo<int>(field.GetValue(collector));
					field.SetValue(collector, num - i);
				}
			}
		}

		[HarmonyPatch(typeof(M_Level), "OnEnter")]
		public static class M_Level_OnLevelActivate_Patch
		{
			[HarmonyPrefix]
			public static void Prefix(M_Level __instance)
			{
				//IL_02ff: 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_0318: Unknown result type (might be due to invalid IL or missing references)
				//IL_031d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0320: Unknown result type (might be due to invalid IL or missing references)
				//IL_0322: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)CL_GameManager.GetCurrentGamemode() != (Object)(object)EndlessMode)
				{
					return;
				}
				if (canWin)
				{
					canWin = false;
				}
				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)
					{
						SkyboxManager.UnloadSkyboxes();
						cycles++;
						checkCycle = false;
					}
				}
				else
				{
					checkCycle = true;
				}
				if (CustomUIManager.GetToggleState("height_win_enabled") && CustomUIManager.GetFloatState("height_win_amount") <= CL_GameManager.gMan.GetPlayerCorrectedHeight())
				{
					canWin = true;
					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])
				{
					canWin = true;
					CL_GameManager.gMan.Win();
				}
				if ((Object)(object)lastRegion == (Object)null)
				{
					lastRegion = __instance.region;
				}
				if (!gaveFlashlight && (StringUtility.ContainsInsensitive(__instance.levelName, "Habitation") || StringUtility.ContainsInsensitive(__instance.levelName, "Abyss") || StringUtility.ContainsInsensitive(__instance.levelName, "Ladder")) && !StringUtility.ContainsInsensitive(__instance.levelName, "interlude"))
				{
					gaveFlashlight = true;
					GiveItem("Item_Flashlight", 1);
					GiveItem("Item_Flaregun", 1);
					GiveItem("Item_Flaregun_Ammo", 3);
				}
				if (StringUtility.ContainsInsensitive(__instance.levelName, "Nest") && !gaveGun)
				{
					gaveGun = true;
					GiveItem("Item_Handgun", 1);
					GiveItem("Item_10mm_Ammo", 3);
				}
				DEN_Face cachedObject = EndlessConfiguration.GetCachedObject<DEN_Face>("Denizen_Face");
				if ((Object)(object)cachedObject == (Object)null)
				{
					return;
				}
				int faceCountForLevel = GetFaceCountForLevel(__instance);
				if (spawnedFaces.Count > 0 && (Object)(object)spawnedFaces[0] == (Object)null)
				{
					spawnedFaces.Clear();
				}
				while (spawnedFaces.Count > faceCountForLevel)
				{
					int index = spawnedFaces.Count - 1;
					DEN_Face val = spawnedFaces[index];
					spawnedFaces.RemoveAt(index);
					DEN_Face.RemoveFaceInstance(val);
					if ((Object)(object)val != (Object)null)
					{
						Object.Destroy((Object)(object)((Component)val).gameObject);
					}
				}
				while (spawnedFaces.Count < faceCountForLevel)
				{
					Vector3 val2 = ((Component)ENT_Player.GetPlayer()).transform.position + new Vector3(0f, -20f, 0f);
					DEN_Face val3 = Object.Instantiate<DEN_Face>(cachedObject, val2, Quaternion.identity);
					spawnedFaces.Add(val3);
					DEN_Face.AddFaceInstance(val3);
				}
				if (StringUtility.ContainsInsensitive(__instance.levelName, "Abyss") || StringUtility.ContainsInsensitive(__instance.levelName, "Extraction") || StringUtility.ContainsInsensitive(__instance.levelName, "Comms") || StringUtility.ContainsInsensitive(__instance.levelName, "Boost"))
				{
					DestroyMassInstance();
				}
				else
				{
					DEN_DeathFloor.instance.SetActive(true);
				}
				if (BEGONE_FOUL_SPIRIT)
				{
					DestroyMassInstance();
					BEGONE_FOUL_SPIRIT = false;
				}
				if (StringUtility.ContainsInsensitive(__instance.levelName, "Entryway") || StringUtility.ContainsInsensitive(__instance.levelName, "Campaign_Interlude_Sink_To_Pipeworks_01"))
				{
					string[] args = new string[1] { "" };
					TeleportPlayerToNextLevel(args);
				}
				if ((StringUtility.ContainsInsensitive(__instance.levelName, "To_") || StringUtility.ContainsInsensitive(__instance.levelName, "To_Comms Array") || StringUtility.ContainsInsensitive(__instance.levelName, "From")) && !StringUtility.ContainsInsensitive(__instance.levelName, "interlude"))
				{
					DeathFloorHeightPatch.allowHeightUpdates = false;
				}
				else
				{
					DeathFloorHeightPatch.allowHeightUpdates = true;
				}
				Debug.Log((object)((Object)__instance).name);
				if (StringUtility.ContainsInsensitive(__instance.levelName, "Habitation_Shaft_Intro"))
				{
					Debug.Log((object)"HIII");
					RemoveLODs(((Component)__instance).gameObject.transform);
				}
				if (CustomUIManager.GetToggleState("fun_consumah"))
				{
					UnloadPreviousLevels(__instance);
					DEN_DeathFloor.instance.SetVisualActive(false);
					if (Random.Range(0.01f, 1f) > 0.9f)
					{
						SpawnEntity("Denizen_Hunter_BindingVariant", __instance);
					}
				}
				bool flag = StringUtility.ContainsInsensitive(__instance.levelName, "chimney") || CustomUIManager.GetToggleState("fun_always_snowing");
				Event_Cold val4 = GetInstanceInternal();
				if ((Object)(object)val4 == (Object)null)
				{
					val4 = Object.FindObjectOfType<Event_Cold>(true);
				}
				if (cutOff && !StringUtility.ContainsInsensitive(((Object)__instance).name, "To_"))
				{
					cutOff = false;
					UnloadPreviousLevels(__instance);
				}
				if (StringUtility.ContainsInsensitive(((Object)__instance).name, "Prototype"))
				{
					teleportCTS?.Cancel();
					teleportCTS?.Dispose();
					teleportCTS = new CancellationTokenSource();
					TeleportAtEndOfLevel(__instance, teleportCTS.Token);
				}
				if (StringUtility.ContainsInsensitive(((Object)__instance).name, "From_Anywhere"))
				{
					WorldLoader.instance.UnloadPreviousLevels(0);
				}
				if (StringUtility.ContainsInsensitive(((Object)__instance).name, "To_"))
				{
					cutOff = true;
				}
				if (flag)
				{
					if ((Object)(object)val4 == (Object)null)
					{
						val4 = GetOrSpawnEventCold();
					}
					if ((Object)(object)val4 != (Object)null)
					{
						if (!((Component)val4).gameObject.activeSelf)
						{
							((Component)val4).gameObject.SetActive(true);
						}
						Event_Cold.SetEventStatus(true);
					}
				}
				else
				{
					Event_Cold.SetEventStatus(false);
					if ((Object)(object)val4 != (Object)null && ((Component)val4).gameObject.activeSelf)
					{
						DisableEventCold(val4);
						RemoveColdDebuff();
					}
				}
				static void RemoveLODs(Transform parent)
				{
					for (int num = parent.childCount - 1; num >= 0; num--)
					{
						Transform child = parent.GetChild(num);
						RemoveLODs(child);
						if (StringUtility.ContainsInsensitive(((Object)child).name, "Props"))
						{
							Debug.Log((object)((Object)child).name);
							Object.Destroy((Object)(object)((Component)child).gameObject);
						}
					}
				}
			}
		}

		[HarmonyPatch(typeof(DEN_DeathFloor))]
		public static class DeathFloorHeightPatch
		{
			public static bool allowHeightUpdates = true;

			private static float accumulatedHeightDelta = 0f;

			private static float? pendingTarget