Decompiled source of PeakLevelSelect v1.0.6

PeakLevelSelect.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using Zorro.Core;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace PeakLevelSelect
{
	[BepInPlugin("PeakLevelSelect", "PeakLevelSelect", "1.0.6")]
	public class PeakLevelSelectPlugin : BaseUnityPlugin
	{
		internal static ManualLogSource logger;

		public static ConfigEntry<int> SelectedLevel { get; set; }

		public static ConfigEntry<int> SelectedAscent { get; set; }

		private void Awake()
		{
			logger = ((BaseUnityPlugin)this).Logger;
			SelectedLevel = ((BaseUnityPlugin)this).Config.Bind<int>("General", "SelectedLevel", -2, "-2 = Random,-1 = Daily,0-14=Level_Num");
			SelectedAscent = ((BaseUnityPlugin)this).Config.Bind<int>("General", "SelectedAscent", -2, "-2 = Default,-1-7 = AscentNum");
			Harmony.CreateAndPatchAll(typeof(GUIManagerPatch), (string)null);
		}
	}
	[HarmonyWrapSafe]
	public static class GUIManagerPatch
	{
		private static int todayLevelIndex;

		private static TMP_FontAsset font;

		private static Image image;

		public static TextMeshProUGUI dropDownText;

		public static GameObject dropDown;

		private static TextMeshProUGUI To1;

		private static Image dropdownImage;

		private static Dictionary<string, List<string>> langTable { get; set; }

		public static List<GameObject> buttons { get; set; }

		[HarmonyPatch(typeof(BoardingPass), "UpdateAscent")]
		[HarmonyPostfix]
		public unsafe static void OnEnable()
		{
			bool isCustomRun = RunSettings.IsCustomRun;
			dropDown.gameObject.SetActive(!isCustomRun);
			foreach (GameObject button in buttons)
			{
				button.gameObject.SetActive(!isCustomRun);
			}
			if (!isCustomRun)
			{
				return;
			}
			int level = GetLevel();
			IEnumerable<string> values = SingletonAsset<MapBaker>.Instance.selectedBiomes[level].biomeTypes.Where((BiomeType x) => (int)x > 0).Select(delegate(BiomeType x)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Invalid comparison between Unknown and I4
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: Invalid comparison between Unknown and I4
				string text2 = ((object)(*(BiomeType*)(&x))/*cast due to .constrained prefix*/).ToString();
				if ((int)x == 3)
				{
					text2 = "THE KILN";
				}
				else if ((int)x == 8)
				{
					text2 = "THE CITADEL";
				}
				return LocalizedText.GetText(text2, true);
			});
			string text = string.Join(",", values);
			TMP_Text ascentDesc = GUIManager.instance.boardingPass.ascentDesc;
			ascentDesc.text = ascentDesc.text + "\r\n\r\n" + GetText("Level", level) + "(" + text + ")";
		}

		[HarmonyPatch(typeof(BoardingPass), "UpdateAscent")]
		[HarmonyPostfix]
		public static void UpdateAscent(BoardingPass __instance)
		{
			PeakLevelSelectPlugin.SelectedAscent.Value = __instance.ascentIndex;
		}

		[HarmonyPatch(typeof(MapBaker), "GetLevel")]
		[HarmonyPrefix]
		public static void GetLevel(ref int levelIndex)
		{
			levelIndex = GetLevel();
		}

		public static int GetLevel()
		{
			if (PeakLevelSelectPlugin.SelectedLevel.Value == -2)
			{
				return Random.Range(0, SingletonAsset<MapBaker>.Instance.selectedBiomes.Count);
			}
			if (PeakLevelSelectPlugin.SelectedLevel.Value == -1)
			{
				int num = RefreshTodayLevelIndex();
				return (num != -3) ? num : 0;
			}
			if (PeakLevelSelectPlugin.SelectedLevel.Value < SingletonAsset<MapBaker>.Instance.selectedBiomes.Count)
			{
				return PeakLevelSelectPlugin.SelectedLevel.Value;
			}
			throw new NotImplementedException();
		}

		[HarmonyPatch(typeof(GUIManager), "Start")]
		[HarmonyPostfix]
		public static void Start()
		{
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			langTable = new Dictionary<string, List<string>>();
			langTable.Add("Random", MakeList(((Language)0, "Random"), ((Language)9, "随机地图")));
			langTable.Add("Daily", MakeList(((Language)0, "Daily"), ((Language)9, "当天地图")));
			langTable.Add("Level", MakeList(((Language)0, "Level_{0}"), ((Language)9, "轮换{0}")));
			langTable.Add("Today", MakeList(((Language)0, "Today"), ((Language)9, "今日地图")));
			RefreshTodayLevelIndex();
			buttons = new List<GameObject>();
			GameObject val = GameObject.Find("GAME/GUIManager/Canvas_BoardingPass");
			BoardingPass component = val.GetComponent<BoardingPass>();
			GameObject val2 = GameObject.Find("GAME/GUIManager/Canvas_BoardingPass/BoardingPass/Panel/Ascent/IncrementButton");
			if ((Object)(object)val2 == (Object)null)
			{
				Debug.LogError((object)"find IncrementButton fail!");
				return;
			}
			Transform transform = GameObject.Find("GAME/GUIManager/Canvas_BoardingPass/BoardingPass/Panel").transform;
			if ((Object)(object)transform == (Object)null)
			{
				Debug.LogError((object)"fail Panel fail!");
				return;
			}
			To1 = GameObject.Find("GAME/GUIManager/Canvas_BoardingPass/BoardingPass/Panel/To (1)").GetComponent<TextMeshProUGUI>();
			GameObject val3 = GameObject.Find("GAME/GUIManager/Canvas_BoardingPass/BoardingPass/Panel/BOARDING PASS");
			font = ((TMP_Text)val3.GetComponent<TextMeshProUGUI>()).font;
			GameObject val4 = CreateButton(val2, transform, GetText("Random"), new Vector2(140f, 75f), delegate
			{
				RandomInvoke();
			});
			buttons.Add(val4);
			float x = val4.GetComponent<RectTransform>().sizeDelta.x;
			string text = GetText("Daily");
			if (todayLevelIndex != -3)
			{
				text += $"({todayLevelIndex})";
			}
			GameObject item = CreateButton(val2, transform, text, new Vector2(140f + x + 20f, 75f), delegate
			{
				DailyInvoke();
			});
			buttons.Add(item);
			GameObject val5 = GameObject.Find("GAME/GUIManager/Canvas_BoardingPass/BoardingPass/Panel/Ascent/Reward");
			if ((Object)(object)val5 != (Object)null)
			{
				RectTransform component2 = val5.GetComponent<RectTransform>();
				component2.anchoredPosition = new Vector2(component2.anchoredPosition.x, -10f);
			}
			PeakLevelSelectPlugin.logger.LogInfo((object)"Create Button Sussecs!");
			CreateDropdown(transform);
			if (PeakLevelSelectPlugin.SelectedAscent.Value != -2)
			{
				component.ascentIndex = PeakLevelSelectPlugin.SelectedAscent.Value;
				component.UpdateAscent();
			}
		}

		private static void RandomInvoke()
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			((TMP_Text)dropDownText).text = GetText("Random");
			PeakLevelSelectPlugin.SelectedLevel.Value = -2;
			((Graphic)buttons[0].GetComponent<Image>()).color = new Color(0.9804f, 0.8075f, 0.1922f, 1f);
			((TMP_Text)To1).text = "???";
		}

		private unsafe static void DailyInvoke()
		{
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			RefreshTodayLevelIndex();
			((TMP_Text)dropDownText).text = GetText("Daily");
			MapBaker instance = SingletonAsset<MapBaker>.Instance;
			if (todayLevelIndex != -3 && todayLevelIndex < instance.selectedBiomes.Count)
			{
				((TMP_Text)To1).text = todayLevelIndex.ToString();
				IEnumerable<string> values = SingletonAsset<MapBaker>.Instance.selectedBiomes[todayLevelIndex].biomeTypes.Where((BiomeType x) => (int)x > 0).Select(delegate(BiomeType x)
				{
					//IL_000f: Unknown result type (might be due to invalid IL or missing references)
					//IL_0011: Invalid comparison between Unknown and I4
					//IL_0021: Unknown result type (might be due to invalid IL or missing references)
					//IL_0023: Invalid comparison between Unknown and I4
					string text2 = ((object)(*(BiomeType*)(&x))/*cast due to .constrained prefix*/).ToString();
					if ((int)x == 3)
					{
						text2 = "THE KILN";
					}
					else if ((int)x == 8)
					{
						text2 = "THE CITADEL";
					}
					return LocalizedText.GetText(text2, true);
				});
				string text = string.Join(",", values);
				TextMeshProUGUI obj = dropDownText;
				((TMP_Text)obj).text = ((TMP_Text)obj).text + "(" + text + ")";
			}
			else
			{
				((TMP_Text)To1).text = "0";
			}
			PeakLevelSelectPlugin.SelectedLevel.Value = -1;
			((Graphic)buttons[1].GetComponent<Image>()).color = new Color(0.9804f, 0.8075f, 0.1922f, 1f);
		}

		[HarmonyPatch(typeof(NextLevelService), "NewData")]
		[HarmonyPostfix]
		public static void NewData()
		{
			RefreshTodayLevelIndex();
			if (PeakLevelSelectPlugin.SelectedLevel.Value == -1 && (Object)(object)dropDownText != (Object)null && buttons != null && buttons.Count > 1)
			{
				DailyInvoke();
			}
		}

		private static int RefreshTodayLevelIndex()
		{
			//IL_007a: 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_00b8: 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)
			try
			{
				MapBaker instance = SingletonAsset<MapBaker>.Instance;
				int num = ((instance.ScenePaths != null && instance.ScenePaths.Length != 0) ? instance.ScenePaths.Length : instance.selectedBiomes.Count);
				if (num <= 0)
				{
					todayLevelIndex = -3;
					return todayLevelIndex;
				}
				NextLevelService service = GameHandler.GetService<NextLevelService>();
				if (service != null)
				{
					int num2;
					if (service.Data.IsSome)
					{
						NextLevelData value = service.Data.Value;
						int secondsLeft = ((NextLevelData)(ref value)).SecondsLeft;
						num2 = ((secondsLeft > 0) ? value.CurrentLevelIndex : (value.CurrentLevelIndex + Mathf.FloorToInt((float)(-secondsLeft) / 86400f) + 1));
					}
					else
					{
						num2 = service.OfflineLevelIndex;
					}
					num2 += NextLevelService.debugLevelIndexOffset;
					todayLevelIndex = (num2 % num + num) % num;
					return todayLevelIndex;
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logger = PeakLevelSelectPlugin.logger;
				if (logger != null)
				{
					logger.LogError((object)("RefreshTodayLevelIndex Exception: " + ex));
				}
			}
			todayLevelIndex = -3;
			return todayLevelIndex;
		}

		private static List<string> MakeList(params (Language lang, string text)[] items)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected I4, but got Unknown
			List<string> list = new List<string>(new string[14]);
			for (int i = 0; i < items.Length; i++)
			{
				var (val, value) = items[i];
				list[(int)val] = value;
			}
			for (int j = 0; j < 14; j++)
			{
				if (string.IsNullOrEmpty(list[j]))
				{
					list[j] = list[0];
				}
			}
			return list;
		}

		private unsafe static void CreateDropdown(Transform panel)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_012f: Expected O, but got Unknown
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Expected O, but got Unknown
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Expected O, but got Unknown
			//IL_0312: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c6: Expected O, but got Unknown
			//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0400: Unknown result type (might be due to invalid IL or missing references)
			//IL_0416: Unknown result type (might be due to invalid IL or missing references)
			//IL_042f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0436: Expected O, but got Unknown
			//IL_0460: Unknown result type (might be due to invalid IL or missing references)
			//IL_0477: Unknown result type (might be due to invalid IL or missing references)
			//IL_048e: Unknown result type (might be due to invalid IL or missing references)
			//IL_049b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c9: Expected O, but got Unknown
			//IL_04fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0513: Unknown result type (might be due to invalid IL or missing references)
			//IL_052a: 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_0551: Unknown result type (might be due to invalid IL or missing references)
			//IL_0558: Expected O, but got Unknown
			//IL_0587: Unknown result type (might be due to invalid IL or missing references)
			//IL_059d: Unknown result type (might be due to invalid IL or missing references)
			//IL_05aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b7: 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_05de: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e5: Expected O, but got Unknown
			//IL_0605: Unknown result type (might be due to invalid IL or missing references)
			//IL_0625: Unknown result type (might be due to invalid IL or missing references)
			//IL_063c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0653: 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_0681: Unknown result type (might be due to invalid IL or missing references)
			//IL_069a: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a1: Expected O, but got Unknown
			//IL_06db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0708: Unknown result type (might be due to invalid IL or missing references)
			//IL_071f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0736: Unknown result type (might be due to invalid IL or missing references)
			//IL_074d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0906: Unknown result type (might be due to invalid IL or missing references)
			//IL_0910: Unknown result type (might be due to invalid IL or missing references)
			//IL_094e: Unknown result type (might be due to invalid IL or missing references)
			//IL_09d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_08aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_08db: Expected O, but got Unknown
			//IL_08be: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ab8: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				dropDown = new GameObject("CustomDropdown");
				dropDown.transform.SetParent(panel, false);
				RectTransform val = dropDown.AddComponent<RectTransform>();
				val.anchorMin = new Vector2(0f, 0f);
				val.anchorMax = new Vector2(0f, 0f);
				val.pivot = new Vector2(0f, 0f);
				val.anchoredPosition = new Vector2(520f, 75f);
				val.sizeDelta = new Vector2(0f, 65f);
				Image val2 = dropDown.AddComponent<Image>();
				val2.sprite = image.sprite;
				((Graphic)val2).color = ((Graphic)image).color;
				val2.type = image.type;
				val2.pixelsPerUnitMultiplier = image.pixelsPerUnitMultiplier;
				((Graphic)val2).material = ((Graphic)image).material;
				val2.overrideSprite = image.overrideSprite;
				((Graphic)val2).raycastTarget = ((Graphic)image).raycastTarget;
				dropdownImage = val2;
				GameObject val3 = new GameObject("Label");
				val3.transform.SetParent(dropDown.transform, false);
				TextMeshProUGUI val4 = val3.AddComponent<TextMeshProUGUI>();
				((TMP_Text)val4).fontSize = 14f;
				((TMP_Text)val4).font = font;
				((Graphic)val4).color = Color.white;
				((TMP_Text)val4).text = "";
				((TMP_Text)val4).alignment = (TextAlignmentOptions)513;
				dropDownText = val4;
				RectTransform component = ((Component)val4).GetComponent<RectTransform>();
				component.anchorMin = Vector2.zero;
				component.anchorMax = Vector2.one;
				component.offsetMin = new Vector2(10f, 6f);
				component.offsetMax = new Vector2(-30f, -7f);
				GameObject val5 = new GameObject("Arrow");
				val5.transform.SetParent(dropDown.transform, false);
				TextMeshProUGUI val6 = val5.AddComponent<TextMeshProUGUI>();
				((TMP_Text)val6).font = font;
				((Graphic)val6).color = Color.white;
				((TMP_Text)val6).text = "▼";
				((TMP_Text)val6).fontSize = 24f;
				((TMP_Text)val6).alignment = (TextAlignmentOptions)514;
				RectTransform component2 = ((Component)val6).GetComponent<RectTransform>();
				component2.anchorMin = new Vector2(1f, 0.5f);
				component2.anchorMax = new Vector2(1f, 0.5f);
				component2.pivot = new Vector2(1f, 0.5f);
				component2.sizeDelta = new Vector2(20f, 20f);
				component2.anchoredPosition = new Vector2(-20f, 0f);
				GameObject val7 = new GameObject("Template");
				val7.transform.SetParent(dropDown.transform, false);
				val7.SetActive(false);
				MapBaker instance = SingletonAsset<MapBaker>.Instance;
				RectTransform val8 = val7.AddComponent<RectTransform>();
				val8.anchorMin = new Vector2(0f, 0f);
				val8.anchorMax = new Vector2(1f, 0f);
				val8.pivot = new Vector2(0.5f, 1f);
				PeakLevelSelectPlugin.logger.LogInfo((object)$"ScenePaths: {instance.ScenePaths.Length}");
				val8.sizeDelta = new Vector2(0f, (float)(instance.ScenePaths.Length * 25));
				Image val9 = val7.AddComponent<Image>();
				((Graphic)val9).color = new Color(0.2f, 0.2f, 0.2f);
				val7.AddComponent<RectMask2D>();
				GameObject val10 = new GameObject("Viewport");
				val10.transform.SetParent(val7.transform, false);
				RectTransform val11 = val10.AddComponent<RectTransform>();
				val11.anchorMin = Vector2.zero;
				val11.anchorMax = Vector2.one;
				val11.sizeDelta = Vector2.zero;
				Image val12 = val10.AddComponent<Image>();
				((Graphic)val12).color = Color.clear;
				((Graphic)val12).raycastTarget = false;
				GameObject val13 = new GameObject("Content");
				val13.transform.SetParent(val10.transform, false);
				RectTransform val14 = val13.AddComponent<RectTransform>();
				val14.anchorMin = new Vector2(0f, 1f);
				val14.anchorMax = new Vector2(1f, 1f);
				val14.pivot = new Vector2(0.5f, 1f);
				val14.anchoredPosition = Vector2.zero;
				val14.sizeDelta = new Vector2(0f, 0f);
				GameObject val15 = new GameObject("Item");
				val15.transform.SetParent(val13.transform, false);
				Toggle val16 = val15.AddComponent<Toggle>();
				RectTransform component3 = val15.GetComponent<RectTransform>();
				component3.anchorMin = new Vector2(0f, 1f);
				component3.anchorMax = new Vector2(1f, 1f);
				component3.pivot = new Vector2(0.5f, 1f);
				component3.sizeDelta = new Vector2(0f, 25f);
				GameObject val17 = new GameObject("Item Background");
				val17.transform.SetParent(val15.transform, false);
				Image val18 = val17.AddComponent<Image>();
				((Graphic)val18).color = new Color(0.3f, 0.3f, 0.3f);
				RectTransform component4 = val17.GetComponent<RectTransform>();
				component4.anchorMin = Vector2.zero;
				component4.anchorMax = Vector2.one;
				component4.offsetMin = Vector2.zero;
				component4.offsetMax = Vector2.zero;
				((Selectable)val16).targetGraphic = (Graphic)(object)val18;
				GameObject val19 = new GameObject("Item Checkmark");
				val19.transform.SetParent(val17.transform, false);
				Image val20 = val19.AddComponent<Image>();
				((Graphic)val20).color = Color.white;
				RectTransform component5 = val19.GetComponent<RectTransform>();
				component5.anchorMin = new Vector2(0f, 0.5f);
				component5.anchorMax = new Vector2(0f, 0.5f);
				component5.pivot = new Vector2(0f, 0.5f);
				component5.sizeDelta = new Vector2(20f, 20f);
				component5.anchoredPosition = new Vector2(10f, 0f);
				val16.graphic = (Graphic)(object)val20;
				GameObject val21 = new GameObject("Item Label");
				val21.transform.SetParent(val15.transform, false);
				TextMeshProUGUI val22 = val21.AddComponent<TextMeshProUGUI>();
				((TMP_Text)val22).font = font;
				((TMP_Text)val22).fontSize = 14f;
				((Graphic)val22).color = Color.white;
				((TMP_Text)val22).text = "Option";
				RectTransform component6 = ((Component)val22).GetComponent<RectTransform>();
				component6.anchorMin = new Vector2(0f, 0f);
				component6.anchorMax = new Vector2(1f, 1f);
				component6.offsetMin = new Vector2(30f, 0f);
				component6.offsetMax = new Vector2(-10f, 0f);
				TMP_Dropdown val23 = dropDown.AddComponent<TMP_Dropdown>();
				((Selectable)val23).targetGraphic = (Graphic)(object)val2;
				val23.captionText = (TMP_Text)(object)val4;
				val23.template = val8;
				val23.itemText = (TMP_Text)(object)val22;
				val23.itemImage = val20;
				val23.options.Clear();
				float num = 0f;
				GameObject val24 = GameObject.Find("GAME/GUIManager/Canvas_BoardingPass");
				val24.SetActive(true);
				val24.SetActive(false);
				for (int i = 0; i < instance.selectedBiomes.Count; i++)
				{
					string text = GetText("Level", i);
					IEnumerable<string> values = instance.selectedBiomes[i].biomeTypes.Where((BiomeType x) => (int)x > 0).Select(delegate(BiomeType x)
					{
						//IL_000f: Unknown result type (might be due to invalid IL or missing references)
						//IL_0011: Invalid comparison between Unknown and I4
						//IL_0021: Unknown result type (might be due to invalid IL or missing references)
						//IL_0023: Invalid comparison between Unknown and I4
						string text4 = ((object)(*(BiomeType*)(&x))/*cast due to .constrained prefix*/).ToString();
						if ((int)x == 3)
						{
							text4 = "CALDERA";
						}
						else if ((int)x == 8)
						{
							text4 = "THE CITADEL";
						}
						return LocalizedText.GetText(text4, true);
					});
					string text2 = string.Join(",", values);
					string text3 = text + "(" + text2 + ")";
					if (i == todayLevelIndex)
					{
						text3 = "(" + GetText("Today") + ")" + text3;
					}
					Vector2 preferredValues = ((TMP_Text)dropDownText).GetPreferredValues(text3);
					if (preferredValues.x > num)
					{
						num = preferredValues.x;
					}
					val23.options.Add(new OptionData(text3));
				}
				val.sizeDelta = new Vector2(num + 80f, val.sizeDelta.y);
				float num2 = 25f;
				float num3 = 8f;
				float num4 = Mathf.Min((float)instance.selectedBiomes.Count * num2, num3 * num2);
				val8.sizeDelta = new Vector2(0f, num4);
				ScrollRect val25 = val7.AddComponent<ScrollRect>();
				val25.content = val14;
				val25.viewport = val11;
				val25.horizontal = false;
				val25.vertical = true;
				val25.verticalScrollbar = null;
				val25.verticalScrollbarVisibility = (ScrollbarVisibility)0;
				val25.inertia = true;
				if ((Object)(object)val10.GetComponent<RectMask2D>() == (Object)null)
				{
					val10.AddComponent<RectMask2D>();
				}
				val14.sizeDelta = new Vector2(0f, (float)instance.selectedBiomes.Count * num2);
				((UnityEvent<int>)(object)val23.onValueChanged).AddListener((UnityAction<int>)delegate(int value)
				{
					//IL_0050: Unknown result type (might be due to invalid IL or missing references)
					//IL_008f: Unknown result type (might be due to invalid IL or missing references)
					((TMP_Text)To1).text = value.ToString();
					PeakLevelSelectPlugin.SelectedLevel.Value = value;
					foreach (GameObject button in buttons)
					{
						((Graphic)button.GetComponent<Image>()).color = new Color(0.1922f, 0.2941f, 0.9804f, 1f);
					}
					((Graphic)dropdownImage).color = new Color(0.9804f, 0.8075f, 0.1922f, 1f);
				});
				if (PeakLevelSelectPlugin.SelectedLevel.Value == -1)
				{
					DailyInvoke();
				}
				else if (PeakLevelSelectPlugin.SelectedLevel.Value == -2)
				{
					RandomInvoke();
				}
				else if (PeakLevelSelectPlugin.SelectedLevel.Value < val23.options.Count)
				{
					val23.value = PeakLevelSelectPlugin.SelectedLevel.Value;
					((TMP_Text)To1).text = val23.value.ToString();
					val23.RefreshShownValue();
					((Graphic)dropdownImage).color = new Color(0.9804f, 0.8075f, 0.1922f, 1f);
				}
			}
			catch (Exception ex)
			{
				PeakLevelSelectPlugin.logger.LogError((object)("CreateDropdown Exception: " + ex));
			}
		}

		public static string GetText(string key, params object[] args)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected I4, but got Unknown
			if (!langTable.TryGetValue(key, out List<string> value))
			{
				return (args.Length != 0) ? string.Format(key, args) : key;
			}
			string text = value[(int)LocalizedText.CURRENT_LANGUAGE];
			return (args.Length != 0) ? string.Format(text, args) : text;
		}

		private static GameObject CreateButton(GameObject referenceButton, Transform parent, string buttonText, Vector2 position, UnityAction<GameObject> onClick)
		{
			//IL_00d9: 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_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)referenceButton))
			{
				Debug.LogError((object)"ReferenceButton is null!");
				return null;
			}
			GameObject button = Object.Instantiate<GameObject>(referenceButton);
			((Object)button).name = "Button_" + buttonText;
			button.transform.SetParent(parent, false);
			Transform obj = button.transform.Find("Image");
			Object.Destroy((Object)(object)((obj != null) ? ((Component)obj).gameObject : null));
			Object.Destroy((Object)(object)((Component)button.transform).GetComponent<Animator>());
			if ((Object)(object)image == (Object)null)
			{
				image = button.GetComponent<Image>();
			}
			RectTransform component = button.GetComponent<RectTransform>();
			component.sizeDelta = new Vector2(170f, component.sizeDelta.y);
			component.anchorMin = new Vector2(0f, 0f);
			component.anchorMax = new Vector2(0f, 0f);
			component.pivot = new Vector2(0f, 0f);
			component.anchoredPosition = position;
			CreateButtonText(button, buttonText);
			Button component2 = button.GetComponent<Button>();
			((UnityEventBase)component2.onClick).RemoveAllListeners();
			((UnityEvent)component2.onClick).AddListener((UnityAction)delegate
			{
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_0093: 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)
				foreach (GameObject button2 in buttons)
				{
					((Graphic)dropdownImage).color = new Color(0.1922f, 0.2941f, 0.9804f, 1f);
					if ((Object)(object)button2 == (Object)(object)button)
					{
						((Graphic)button2.GetComponent<Image>()).color = new Color(0.9804f, 0.8075f, 0.1922f, 1f);
					}
					else
					{
						((Graphic)button2.GetComponent<Image>()).color = new Color(0.1922f, 0.2941f, 0.9804f, 1f);
					}
				}
				onClick.Invoke(button);
			});
			return button;
		}

		private static void CreateButtonText(GameObject button, string text)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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)
			GameObject val = new GameObject("Text (TMP)");
			val.transform.SetParent(button.transform, false);
			RectTransform val2 = val.AddComponent<RectTransform>();
			val2.anchorMin = Vector2.zero;
			val2.anchorMax = Vector2.one;
			val2.offsetMin = Vector2.zero;
			val2.offsetMax = Vector2.zero;
			TextMeshProUGUI val3 = val.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val3).text = text;
			((TMP_Text)val3).font = font;
			((Graphic)val3).color = Color.white;
			((TMP_Text)val3).fontStyle = (FontStyles)0;
			((TMP_Text)val3).alignment = (TextAlignmentOptions)514;
			((TMP_Text)val3).autoSizeTextContainer = true;
			((TMP_Text)val3).fontSize = 24f;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}