Decompiled source of Severons Customizable Endless v0.5.1

OddsAndEnds.dll

Decompiled 19 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
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")]
namespace Severon.OddsAndEnds;

[HarmonyPatch(typeof(UI_GamemodeSetting), "ToggleSetting")]
public static class UI_GamemodeSetting_ToggleSetting_Patch
{
	private static void Postfix()
	{
		EndlessConfiguration.UpdateRegions();
	}
}
[HarmonyPatch(typeof(UI_GamemodeScreen_Panel), "LoadGamemode")]
public static class UI_GamemodeScreen_Panel_LoadGamemode_Patch
{
	private static void Prefix(UI_GamemodeScreen_Panel __instance)
	{
		if ((Object)(object)__instance.GetGamemode() == (Object)(object)EndlessConfiguration.EndlessMode)
		{
			EndlessConfiguration.UpdateRegions();
		}
	}
}
[HarmonyPatch(typeof(UI_GamemodeScreen_Panel), "Initialize")]
public static class UI_GamemodeScreen_Panel_ScrollSettings_Patch
{
	private static readonly string Marker = "Custom_Settings_Scroll";

	private static void Postfix(UI_GamemodeScreen_Panel __instance)
	{
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Expected O, but got Unknown
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: 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_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Expected O, but got Unknown
		Transform settingRoot = __instance.settingRoot;
		if (!((Object)(object)settingRoot == (Object)null) && !((Object)(object)settingRoot.Find(Marker) != (Object)null))
		{
			RectTransform component = ((Component)settingRoot).GetComponent<RectTransform>();
			GameObject val = new GameObject(Marker, new Type[4]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Mask),
				typeof(ScrollRect)
			});
			RectTransform component2 = val.GetComponent<RectTransform>();
			((Transform)component2).SetParent(settingRoot.parent, false);
			component2.anchorMin = component.anchorMin;
			component2.anchorMax = component.anchorMax;
			component2.offsetMin = component.offsetMin;
			component2.offsetMax = component.offsetMax;
			component2.pivot = component.pivot;
			Image component3 = val.GetComponent<Image>();
			((Behaviour)component3).enabled = false;
			Mask component4 = val.GetComponent<Mask>();
			component4.showMaskGraphic = false;
			settingRoot.SetParent(val.transform, false);
			component.anchorMin = new Vector2(0f, 1f);
			component.anchorMax = new Vector2(1f, 1f);
			component.pivot = new Vector2(0.5f, 1f);
			component.offsetMin = new Vector2(0f, component.offsetMin.y);
			component.offsetMax = new Vector2(0f, component.offsetMax.y);
			VerticalLayoutGroup val2 = ((Component)settingRoot).GetComponent<VerticalLayoutGroup>();
			if ((Object)(object)val2 == (Object)null)
			{
				val2 = ((Component)settingRoot).gameObject.AddComponent<VerticalLayoutGroup>();
			}
			((HorizontalOrVerticalLayoutGroup)val2).childControlHeight = false;
			((HorizontalOrVerticalLayoutGroup)val2).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)val2).childForceExpandHeight = false;
			((HorizontalOrVerticalLayoutGroup)val2).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)val2).spacing = 0f;
			((LayoutGroup)val2).padding = new RectOffset(8, 8, 0, 0);
			ContentSizeFitter val3 = ((Component)settingRoot).GetComponent<ContentSizeFitter>();
			if ((Object)(object)val3 == (Object)null)
			{
				val3 = ((Component)settingRoot).gameObject.AddComponent<ContentSizeFitter>();
			}
			val3.verticalFit = (FitMode)2;
			val3.horizontalFit = (FitMode)0;
			ScrollRect component5 = val.GetComponent<ScrollRect>();
			component5.content = component;
			component5.horizontal = false;
			component5.vertical = true;
			component5.movementType = (MovementType)2;
			LayoutRebuilder.ForceRebuildLayoutImmediate(component);
		}
	}
}
[HarmonyPatch(typeof(UI_GamemodeScreen_Panel), "LoadGamemodeSave")]
public static class UI_GamemodeScreen_Panel_LoadGamemodeSave_Patch
{
	private static void Prefix(UI_GamemodeScreen_Panel __instance)
	{
		if ((Object)(object)__instance.GetGamemode() == (Object)(object)EndlessConfiguration.EndlessMode)
		{
			EndlessConfiguration.UpdateRegions();
		}
	}
}
public static class EndlessConfiguration
{
	[HarmonyPatch(typeof(M_Level), "OnLevelActivate")]
	public static class M_Level_OnLevelActivate_Patch
	{
		[HarmonyPrefix]
		public static void Prefix(M_Level __instance)
		{
			if (BEGONE_FOUL_SPIRIT)
			{
				DestroyMassInstance();
				BEGONE_FOUL_SPIRIT = false;
			}
		}
	}

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

	[HarmonyPatch(typeof(M_Region), "GetLevels")]
	internal static class TransitionRegionPatch
	{
		private static bool Prefix(M_Region __instance, M_Region lastRegion, M_Subregion lastSubregion, ref List<LevelAssetHolder> __result)
		{
			if (!((Object)__instance).name.StartsWith("CustomTransition_"))
			{
				return true;
			}
			__result = new List<LevelAssetHolder>();
			if (__instance.subregionGroups == null || __instance.subregionGroups.Count == 0)
			{
				return false;
			}
			SubregionGroup val = __instance.subregionGroups[0];
			if (val.subregions == null || val.subregions.Count == 0)
			{
				return false;
			}
			M_Subregion val2 = val.subregions[0];
			if (val2.levelGroups == null || val2.levelGroups.Count == 0)
			{
				return false;
			}
			if (val2.levelGroups[0].levelReferences == null || val2.levelGroups[0].levelReferences.Count == 0)
			{
				return false;
			}
			LevelAssetHolder val3 = val2.levelGroups[0].levelReferences[0];
			val3.region = __instance;
			val3.subregion = val2;
			__result.Add(val3);
			return false;
		}
	}

	public static M_Gamemode EndlessMode;

	private static bool added;

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

	public static bool BEGONE_FOUL_SPIRIT;

	public static bool giveStartingItems;

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

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

	private static readonly Dictionary<string, string> StartingPerkTitles = new Dictionary<string, string>
	{
		{ "Perk_U_T1_EmployeeMotivator", "Employee Motivator" },
		{ "Perk_U_T1_EmployeeRetention", "Employee Retention" },
		{ "Perk_U_T1_OnlyClimbing", "Only Climbing" },
		{ "Perk_U_T1_SlowAndSteady", "Slow And Steady" },
		{ "Perk_U_T2_PitonEnthusiast", "Piton Enthusiast" },
		{ "Perk_U_T2_PulseBladder", "Pulse Bladder" },
		{ "Perk_U_T3_ConditionedPolyphagia", "Conditioned Polyphagia" },
		{ "Perk_U_T4_FunniestTimeline", "Funniest Timeline" },
		{ "Perk_U_T3_PeripheralBinding", "Peripheral Binding" }
	};

	private static void DestroyMassInstance()
	{
		if ((Object)(object)DEN_DeathFloor.instance != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)DEN_DeathFloor.instance).gameObject);
			DEN_DeathFloor.instance = null;
		}
	}

	[HarmonyPatch(typeof(CL_Initializer), "Awake")]
	[HarmonyPrefix]
	public static void InitializerAwake(ref CL_Initializer __instance)
	{
		//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0297: Unknown result type (might be due to invalid IL or missing references)
		//IL_029c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0444: Unknown result type (might be due to invalid IL or missing references)
		//IL_0449: Unknown result type (might be due to invalid IL or missing references)
		//IL_0460: Unknown result type (might be due to invalid IL or missing references)
		//IL_0468: Unknown result type (might be due to invalid IL or missing references)
		//IL_047a: Unknown result type (might be due to invalid IL or missing references)
		//IL_047b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0480: Unknown result type (might be due to invalid IL or missing references)
		//IL_0485: Unknown result type (might be due to invalid IL or missing references)
		//IL_0490: Unknown result type (might be due to invalid IL or missing references)
		//IL_049c: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ad: Expected O, but got Unknown
		//IL_04e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_04eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0502: Unknown result type (might be due to invalid IL or missing references)
		//IL_050f: Unknown result type (might be due to invalid IL or missing references)
		//IL_052b: Unknown result type (might be due to invalid IL or missing references)
		//IL_052c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0531: Unknown result type (might be due to invalid IL or missing references)
		//IL_0536: Unknown result type (might be due to invalid IL or missing references)
		//IL_0541: Unknown result type (might be due to invalid IL or missing references)
		//IL_054d: Unknown result type (might be due to invalid IL or missing references)
		//IL_055e: Expected O, but got Unknown
		//IL_05a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0603: Unknown result type (might be due to invalid IL or missing references)
		//IL_060f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0620: Expected O, but got Unknown
		//IL_0665: Unknown result type (might be due to invalid IL or missing references)
		//IL_066a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0686: Unknown result type (might be due to invalid IL or missing references)
		//IL_0691: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_06b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_06b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_06c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_06cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e0: Expected O, but got Unknown
		if (added)
		{
			return;
		}
		M_Gamemode val = __instance.baseDatabase.gamemodeAssets.First((M_Gamemode x) => ((Object)x).name == "GM_Endless_Silos");
		foreach (M_Gamemode gamemodeAsset in __instance.baseDatabase.gamemodeAssets)
		{
			if (!((Object)(object)gamemodeAsset != (Object)null) || gamemodeAsset.regions == null)
			{
				continue;
			}
			foreach (M_Region region in gamemodeAsset.regions)
			{
				if ((Object)(object)region != (Object)null && !regionCache.ContainsKey(((Object)region).name))
				{
					regionCache[((Object)region).name] = (Object)(object)region;
				}
			}
		}
		EndlessMode = ScriptableObject.CreateInstance<M_Gamemode>();
		EndlessMode.gamemodeName = "Custom Endless";
		((Object)EndlessMode).name = "GM_Custom_Endless";
		EndlessMode.introText = "ASCEND";
		EndlessMode.newGameText = "Start";
		EndlessMode.modeDescription = "Customize your Endless";
		EndlessMode.allowAchievements = true;
		EndlessMode.allowCheatedScores = false;
		EndlessMode.allowCheats = true;
		EndlessMode.allowLeaderboardScoring = false;
		EndlessMode.steamLeaderboardName = "";
		EndlessMode.allowHeightAchievements = true;
		EndlessMode.baseGamemode = true;
		EndlessMode.useGamemodeSettings = true;
		EndlessMode.isEndless = true;
		EndlessMode.hasPerks = val.hasPerks;
		EndlessMode.hasRevives = val.hasRevives;
		EndlessMode.modeType = val.modeType;
		EndlessMode.gamemodeScene = val.gamemodeScene;
		EndlessMode.capsuleName = "";
		EndlessMode.capsuleArt = val.capsuleArt;
		EndlessMode.screenArt = val.screenArt;
		EndlessMode.roachEndSprite = val.roachEndSprite;
		EndlessMode.gamemodePanel = val.gamemodePanel;
		EndlessMode.roachBankID = val.roachBankID;
		EndlessMode.loseScreen = val.loseScreen;
		EndlessMode.winScreen = val.winScreen;
		EndlessMode.gamemodeColor = val.gamemodeColor;
		EndlessMode.modeTags = val.modeTags;
		EndlessMode.unlockAchievement = val.unlockAchievement;
		EndlessMode.gamemodeModule = val.gamemodeModule;
		EndlessMode.levelsToGenerate = val.levelsToGenerate;
		EndlessMode.availableTrinkets = val.availableTrinkets;
		EndlessMode.playlistLevelAssets = val.playlistLevelAssets;
		EndlessMode.playlistLevels = val.playlistLevels;
		EndlessMode.gamemodeObjects = val.gamemodeObjects;
		EndlessMode.unlockHint = val.unlockHint;
		EndlessMode.startItems = val.startItems;
		EndlessMode.regions = val.regions.ToList();
		EndlessMode.regions.Clear();
		EndlessMode.gamemodeSettings = val.gamemodeSettings;
		GamemodeSetting val2 = val.gamemodeSettings.FirstOrDefault();
		if ((Object)(object)val2 == (Object)null || (Object)(object)val2.unlock == (Object)null)
		{
			val2 = __instance.baseDatabase.gamemodeAssets.SelectMany((M_Gamemode x) => x.gamemodeSettings).First((GamemodeSetting x) => (Object)(object)x != (Object)null && (Object)(object)x.unlock != (Object)null);
		}
		string[] array = new string[5] { "Silos", "Pipeworks", "Habitation", "Abyss", "Nest" };
		string[] array2 = array;
		foreach (string text in array2)
		{
			EndlessMode.gamemodeSettings.Add(new GamemodeSetting
			{
				id = text.ToLower() + "_enabled",
				title = text,
				description = "Enable " + text,
				color = Color.gray,
				exclusiveSettings = new List<string>(),
				unlock = val2.unlock,
				gamemodeButtonAsset = val2.gamemodeButtonAsset
			});
		}
		foreach (KeyValuePair<string, string> startingItemTitle in StartingItemTitles)
		{
			EndlessMode.gamemodeSettings.Add(new GamemodeSetting
			{
				id = startingItemTitle.Key + "_enabled",
				title = startingItemTitle.Value,
				description = "Start with " + startingItemTitle.Value + ".",
				color = Color.gray,
				exclusiveSettings = new List<string>(),
				unlock = val2.unlock,
				gamemodeButtonAsset = val2.gamemodeButtonAsset
			});
		}
		foreach (KeyValuePair<string, string> startingPerkTitle in StartingPerkTitles)
		{
			EndlessMode.gamemodeSettings.Add(new GamemodeSetting
			{
				id = startingPerkTitle.Key.ToLower() + "_enabled",
				title = startingPerkTitle.Value,
				description = "Start with " + startingPerkTitle.Value + " perk.",
				color = Color.gray,
				exclusiveSettings = new List<string>(),
				unlock = val2.unlock,
				gamemodeButtonAsset = val2.gamemodeButtonAsset
			});
		}
		foreach (KeyValuePair<string, string> subregionKeyword in SubregionKeywords)
		{
			EndlessMode.gamemodeSettings.Add(new GamemodeSetting
			{
				id = "subregion_" + subregionKeyword.Key + "_disabled",
				title = "Disable Subregion",
				description = "Exclude " + subregionKeyword.Value + ".",
				color = Color.gray,
				exclusiveSettings = new List<string>(),
				unlock = val2.unlock,
				gamemodeButtonAsset = val2.gamemodeButtonAsset
			});
		}
		__instance.baseDatabase.gamemodeAssets.Add(EndlessMode);
		added = true;
	}

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

	public static void UpdateRegions()
	{
		if ((Object)(object)EndlessMode == (Object)null || EndlessMode.regions == null)
		{
			return;
		}
		EndlessMode.regions.Clear();
		string[] array = new string[5] { "Silos", "Pipeworks", "Habitation", "Abyss", "Nest" };
		List<int> list = new List<int>();
		for (int i = 0; i < array.Length; i++)
		{
			if (EndlessMode.HasActiveSetting(array[i].ToLower() + "_enabled"))
			{
				list.Add(i);
			}
		}
		if (list.Count == 0)
		{
			M_Region andFilterRegion = GetAndFilterRegion("Region_Silos_Saferoom_Endless");
			if ((Object)(object)andFilterRegion != (Object)null)
			{
				EndlessMode.regions.Add(andFilterRegion);
			}
			return;
		}
		BEGONE_FOUL_SPIRIT = list.Count > 0 && array[list[0]] == "Abyss";
		giveStartingItems = true;
		for (int j = 0; j < list.Count; j++)
		{
			int num = list[j];
			string text = array[num];
			M_Region andFilterRegion2 = GetAndFilterRegion("Region_" + text + "_Endless");
			if ((Object)(object)andFilterRegion2 != (Object)null)
			{
				EndlessMode.regions.Add(andFilterRegion2);
			}
			if (text == "Silos")
			{
				M_Region andFilterRegion3 = GetAndFilterRegion("Region_Silos_Saferoom_Endless");
				if ((Object)(object)andFilterRegion3 != (Object)null)
				{
					EndlessMode.regions.Add(andFilterRegion3);
				}
			}
			else
			{
				M_Region andFilterRegion4 = GetAndFilterRegion("Region_" + text + "_Breakroom");
				if ((Object)(object)andFilterRegion4 != (Object)null)
				{
					EndlessMode.regions.Add(andFilterRegion4);
				}
			}
			if (list.Count > 1)
			{
				int num2 = list[(j + 1) % list.Count];
				int num3 = num;
				while (num3 != num2)
				{
					int num4 = (num3 + 1) % array.Length;
					string transFrom = array[num3];
					string transTo = array[num4];
					InjectTransitionRegion(GetTransitionAssetName(transFrom, transTo), transFrom, transTo);
					num3 = num4;
				}
			}
		}
	}

	public static void GiveStartingItems()
	{
		if (!((Object)(object)EndlessMode == (Object)null))
		{
			if (EndlessMode.HasActiveSetting("item_timepiece_enabled"))
			{
				GiveItem("Item_Artifact_Timepiece", 1);
			}
			if (EndlessMode.HasActiveSetting("item_translocator_enabled"))
			{
				GiveItem("Item_Artifact_Translocator", 1);
			}
			if (EndlessMode.HasActiveSetting("item_evaglove_enabled"))
			{
				GiveItem("Item_Artifact_EVAGlove", 1);
			}
			if (EndlessMode.HasActiveSetting("item_rapier_enabled"))
			{
				GiveItem("Item_Artifact_Rapier", 1);
			}
			if (EndlessMode.HasActiveSetting("item_rebar_return_enabled"))
			{
				GiveItem("Item_Artifact_Rebar_Return", 1);
			}
			if (EndlessMode.HasActiveSetting("item_remote_enabled"))
			{
				GiveItem("Item_Artifact_Remote", 1);
			}
			if (EndlessMode.HasActiveSetting("item_handgun_kit_enabled"))
			{
				GiveItem("Item_Handgun", 1);
				GiveItem("Item_10mm_Ammo", 2);
			}
			if (EndlessMode.HasActiveSetting("item_flaregun_kit_enabled"))
			{
				GiveItem("Item_Flaregun", 1);
				GiveItem("Item_Flaregun_Ammo", 2);
			}
			if (EndlessMode.HasActiveSetting("item_flashlight_enabled"))
			{
				GiveItem("Item_Flashlight", 1);
			}
		}
	}

	public static void GiveStartingPerks()
	{
		if ((Object)(object)EndlessMode == (Object)null)
		{
			return;
		}
		ENT_Player player = ENT_Player.GetPlayer();
		if ((Object)(object)player == (Object)null)
		{
			return;
		}
		foreach (KeyValuePair<string, string> startingPerkTitle in StartingPerkTitles)
		{
			if (EndlessMode.HasActiveSetting(startingPerkTitle.Key.ToLower() + "_enabled"))
			{
				Perk perkAsset = CL_AssetManager.GetPerkAsset(startingPerkTitle.Key, "");
				if ((Object)(object)perkAsset != (Object)null)
				{
					player.AddPerk(perkAsset, 1, true);
				}
			}
		}
	}

	private static void GiveItem(string prefabName, int count)
	{
		for (int i = 0; i < count; i++)
		{
			Item_Object itemObjectPrefab = CL_AssetManager.GetItemObjectPrefab(prefabName, "");
			if ((Object)(object)itemObjectPrefab != (Object)null && itemObjectPrefab.itemData != null)
			{
				Inventory.instance.AddItemToInventoryCenter(itemObjectPrefab.itemData.GetClone((Item)null, false));
			}
		}
	}

	private static M_Region GetAndFilterRegion(string name)
	{
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Expected O, but got Unknown
		//IL_022d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Expected O, but got Unknown
		M_Region cachedObject = GetCachedObject<M_Region>(name);
		if ((Object)(object)cachedObject == (Object)null)
		{
			return null;
		}
		M_Region val = Object.Instantiate<M_Region>(cachedObject);
		((Object)val).name = ((Object)cachedObject).name + "_RuntimeCopy";
		val.subregionGroups = new List<SubregionGroup>();
		if (cachedObject.subregionGroups == null)
		{
			return val;
		}
		bool flag = name.Contains("Abyss");
		foreach (SubregionGroup subregionGroup in cachedObject.subregionGroups)
		{
			if (subregionGroup == null || subregionGroup.subregions == null)
			{
				continue;
			}
			SubregionGroup val2 = new SubregionGroup();
			val2.name = subregionGroup.name;
			val2.subregions = new List<M_Subregion>();
			foreach (M_Subregion subregion in subregionGroup.subregions)
			{
				if ((Object)(object)subregion == (Object)null)
				{
					continue;
				}
				bool flag2 = false;
				foreach (KeyValuePair<string, string> subregionKeyword in SubregionKeywords)
				{
					string text = "subregion_" + subregionKeyword.Key + "_disabled";
					if (EndlessMode.HasActiveSetting(text))
					{
						bool flag3 = !string.IsNullOrEmpty(((Object)subregion).name) && ((Object)subregion).name.Contains(subregionKeyword.Key);
						bool flag4 = !string.IsNullOrEmpty(subregion.subregionName) && subregion.subregionName.Contains(subregionKeyword.Key);
						if (flag3 || flag4)
						{
							flag2 = true;
							break;
						}
					}
				}
				if (flag2)
				{
					continue;
				}
				M_Subregion val3 = Object.Instantiate<M_Subregion>(subregion);
				((Object)val3).name = ((Object)subregion).name;
				val3.levelGroups = new List<LevelGroup>();
				if (subregion.levelGroups != null)
				{
					foreach (LevelGroup levelGroup in subregion.levelGroups)
					{
						if (levelGroup != null)
						{
							LevelGroup val4 = new LevelGroup();
							val4.name = levelGroup.name;
							val4.length = levelGroup.length;
							val4.endSubregion = levelGroup.endSubregion;
							val4.levelReferences = ((levelGroup.levelReferences != null) ? new List<LevelAssetHolder>(levelGroup.levelReferences) : new List<LevelAssetHolder>());
							val3.levelGroups.Add(val4);
						}
					}
				}
				val2.subregions.Add(val3);
			}
			val.subregionGroups.Add(val2);
		}
		return val;
	}

	private static string GetTransitionAssetName(string transFrom, string transTo)
	{
		if (transFrom == "Silos" && transTo == "Pipeworks")
		{
			return "Transition_Silo_To_Pipeworks_01";
		}
		if (transFrom == "Pipeworks" && transTo == "Habitation")
		{
			return "Transition_Pipeworks_To_Habitation";
		}
		if (transFrom == "Habitation" && transTo == "Abyss")
		{
			return "Transition_Habitation_To_Abyss_01";
		}
		if (transFrom == "Abyss" && transTo == "Nest")
		{
			return "M5_Nest_Endless_Transition_Intro";
		}
		if (transFrom == "Habitation" && transTo == "Silos")
		{
			return "Transition_Habitation_To_Silo";
		}
		if (transFrom == "Pipeworks" && transTo == "Silos")
		{
			return "Transition_Pipeworks_To_Silo";
		}
		if (transFrom == "Nest" && transTo == "Silos")
		{
			return "Transition_Nest_To_Silo";
		}
		return "Transition_" + transFrom + "_To_" + transTo;
	}

	private static void InjectTransitionRegion(string transitionName, string transFrom, string transTo)
	{
		//IL_00c4: 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_0152: 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_0162: 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_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Expected O, but got Unknown
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Expected O, but got Unknown
		M_Level cachedObject = GetCachedObject<M_Level>(transitionName);
		if (!((Object)(object)cachedObject == (Object)null))
		{
			M_Region val = GetCachedObject<M_Region>("Region_" + transFrom + "_Breakroom") ?? GetCachedObject<M_Region>("Region_" + transFrom + "_Endless") ?? GetCachedObject<M_Region>("Region_" + transFrom + "_Endless_Start") ?? GetCachedObject<M_Region>("Region_Silos_Saferoom_Endless");
			if (!((Object)(object)val == (Object)null))
			{
				M_Region val2 = Object.Instantiate<M_Region>(val);
				((Object)val2).name = "CustomTransition_" + transFrom + "_To_" + transTo;
				val2.regionName = ((Object)val2).name;
				val2.useRegionHeight = false;
				val2.regionHeight = cachedObject.GetLength();
				val2.regionOrder = (RegionOrder)1;
				val2.forceStartLevel = false;
				val2.nextRegion = null;
				LevelAssetHolder newHolderFromLevel = LevelAssetHolder.GetNewHolderFromLevel(cachedObject);
				newHolderFromLevel.region = val2;
				M_Subregion val3 = Object.Instantiate<M_Subregion>(val2.subregionGroups[0].subregions[0]);
				((Object)val3).name = "Subregion_" + transFrom + "_To_" + transTo;
				val3.subregionName = ((Object)val3).name;
				val3.useLevelCount = true;
				val3.subregionMinLength = 1;
				val3.subregionMaxLength = 1;
				val3.subregionOrder = (SubregionOrder)2;
				val3.levelGroups = new List<LevelGroup>
				{
					new LevelGroup
					{
						name = "Transition",
						length = 1,
						endSubregion = true,
						levelReferences = new List<LevelAssetHolder> { newHolderFromLevel }
					}
				};
				val2.subregionGroups = new List<SubregionGroup>
				{
					new SubregionGroup
					{
						name = "Transition",
						subregions = new List<M_Subregion> { val3 }
					}
				};
				EndlessMode.regions.Add(val2);
			}
		}
	}

	private static T GetCachedObject<T>(string name) where T : Object
	{
		if (regionCache.TryGetValue(name, out var value) && value != (Object)null)
		{
			T val = (T)(object)((value is T) ? value : null);
			if (val != null)
			{
				return val;
			}
		}
		T[] array = Resources.FindObjectsOfTypeAll<T>();
		foreach (T val2 in array)
		{
			if ((Object)(object)val2 != (Object)null && ((Object)val2).name == name)
			{
				regionCache[name] = (Object)(object)val2;
				return val2;
			}
		}
		return default(T);
	}
}
[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;
		if ((Object)(object)__instance == (Object)(object)EndlessConfiguration.EndlessMode)
		{
			EndlessConfiguration.UpdateRegions();
		}
	}
}