Decompiled source of Mission list v1.0.1

BepInEx/plugins/Mission_List.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Pigeon.Movement;
using Pigeon.UI;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MiniPrince123")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.0.0.0")]
[assembly: AssemblyInformationalVersion("0.0.0-alpha.0.23+a5c36234132c9334d22749b6886ac28a443c4e9d")]
[assembly: AssemblyProduct("Mission_List")]
[assembly: AssemblyTitle("Mission_List")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MyMycoModRoot
{
	internal static class Configs
	{
		internal enum SortMethod
		{
			Biome,
			ModifierCount,
			MissionType
		}

		internal enum WeekliesEnum
		{
			Vanilla,
			HideAll,
			HideNone
		}

		public static ConfigEntry<SortMethod> SortBy { get; private set; }

		public static ConfigEntry<bool> IsOpenByDefault { get; private set; }

		public static ConfigEntry<bool> BiomeIconsColor { get; private set; }

		public static ConfigEntry<bool> OxybreachE { get; private set; }

		public static ConfigEntry<bool> Freeroam { get; private set; }

		public static ConfigEntry<bool> Incursion { get; private set; }

		public static ConfigEntry<bool> Ouroboros { get; private set; }

		public static ConfigEntry<bool> Ouroblitz { get; private set; }

		public static ConfigEntry<WeekliesEnum> WeekliesVisibility { get; private set; }

		public static ConfigEntry<bool> LegacyMissions { get; private set; }

		public static ConfigEntry<bool> ReplayMissions { get; private set; }

		internal static void Initialize(ConfigFile configFile)
		{
			SortBy = configFile.Bind<SortMethod>("Preferences", "Sorting Method", SortMethod.MissionType, "Determines how missions are sorted in the Mission List.");
			IsOpenByDefault = configFile.Bind<bool>("Preferences", "Is Open By Default", false, "Automatically opens the Mission List when interacting with the terminal.");
			BiomeIconsColor = configFile.Bind<bool>("Preferences", "Biome-Based Outline Color", false, "Colors mission's outlines based on their biome's color.");
			Freeroam = configFile.Bind<bool>("Missions Visibility", "Paid Time Off", true, "Includes Paid Time Off in the Mission List.");
			Incursion = configFile.Bind<bool>("Missions Visibility", "Incursion", true, "Includes Incursion in the Mission List.");
			Ouroboros = configFile.Bind<bool>("Missions Visibility", "Ouroboros", false, "Includes Ouroboros in the Mission List.");
			Ouroblitz = configFile.Bind<bool>("Missions Visibility", "Ouroboros Blitz", false, "Includes Ouroboros Blitz in the Mission List.");
			OxybreachE = configFile.Bind<bool>("Missions Visibility", "Oxythane Breach: Escalation", false, "Includes Oxythane Breach: Escalation in the Mission List.");
			WeekliesVisibility = configFile.Bind<WeekliesEnum>("Missions Visibility", "Completed Weeklies", WeekliesEnum.Vanilla, "How the completed weekly missions are shown.");
			LegacyMissions = configFile.Bind<bool>("Missions Visibility", "Include Extra Permanent Locations", false, "Includes the \"Permanent Locations\" missions to the Mission List.");
			ReplayMissions = configFile.Bind<bool>("Missions Visibility", "Include Replay Missions", false, "Includes the \"Replay Missions\" missions to the Mission List.");
		}
	}
	[HarmonyPatch(typeof(MissionSelectWindow), "OnOpen")]
	internal static class MissionList
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__CloseCustomWindow;

			public static Func<MissionData, int> <1>__GetBiomeOrder;

			public static Func<MissionData, int> <2>__GetMissionTypeOrder;
		}

		private static readonly string[] BiomeOrder = new string[7] { "GravityFarm", "City", "Desert", "IceFloes", "Tundra", "Sewer", "Moon" };

		private static readonly string[] MissionTypeOrder = new string[20]
		{
			"groundzero", "abomrush", "ge_amalgamation", "sat_salvage", "planet_def", "prized_pos", "rampage", "cleanup_detail", "sax_transport", "pop_ctrl",
			"freeroam", "incursion", "ouroboros", "ouroblitz", "oxybreach_e", "perfectfit", "containment", "exp_alpha", "oxybreach", "intro"
		};

		private static ScrollArea _customScrollArea;

		private static GameObject _customButton;

		private static GameObject _customWindow;

		private static GameObject _customScrollBar;

		private static readonly HashSet<MissionSelectButton> OtButtons = new HashSet<MissionSelectButton>();

		private static void Postfix(MissionSelectWindow __instance)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			GameObject val = (GameObject)AccessTools.Field(typeof(MissionSelectWindow), "replayButton").GetValue(__instance);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Logger.LogError((object)"Could not find replayButton.");
			}
			else if (!val.activeSelf)
			{
				Plugin.Logger.LogError((object)"replayButton.activeSelf == false.");
			}
			else
			{
				if (!((Object)(object)_customButton == (Object)null))
				{
					return;
				}
				_customButton = Object.Instantiate<GameObject>(val, val.transform.parent);
				((Object)_customButton).name = "MyCustomButton";
				((TMP_Text)_customButton.GetComponentInChildren<TextMeshProUGUI>(true)).text = "Mission List";
				_customButton.transform.SetSiblingIndex(val.transform.GetSiblingIndex() + 2);
				_customButton.transform.localPosition = Vector3.zero;
				DefaultButton component = _customButton.GetComponent<DefaultButton>();
				if ((Object)(object)component != (Object)null)
				{
					ClearPersistentListeners((UnityEventBase)(object)((Button)component).OnClickUp);
					((Button)component).OnClickUp.AddListener((UnityAction)delegate
					{
						OnCustomButtonClicked(__instance);
					});
				}
				CreateCustomWindow(__instance);
			}
		}

		private static void CreateCustomWindow(MissionSelectWindow missionWindow)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Expected O, but got Unknown
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: 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_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
			FieldInfo fieldInfo = AccessTools.Field(typeof(MissionSelectWindow), "legacyWindow");
			if (fieldInfo == null)
			{
				Plugin.Logger.LogError((object)"Could not find MissionSelectWindow.legacyWindow.");
				return;
			}
			GameObject val = (GameObject)fieldInfo.GetValue(missionWindow);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Logger.LogError((object)"MissionSelectWindow.legacyWindow is null.");
				return;
			}
			_customWindow = Object.Instantiate<GameObject>(val, val.transform.parent);
			((Object)_customWindow).name = "_customWindow";
			((TMP_Text)_customWindow.GetComponentInChildren<TextMeshProUGUI>(true)).text = "Mission List";
			_customWindow.SetActive(false);
			WireCloseButton(_customWindow);
			RectTransform val2 = FindClone((RectTransform)AccessTools.Field(typeof(MissionSelectWindow), "legacyMissionContainer").GetValue(missionWindow), val, _customWindow);
			((Object)val2).name = "_customContainer";
			ScrollArea componentInChildren = ((Component)missionWindow).GetComponentInChildren<ScrollArea>(true);
			if ((Object)(object)componentInChildren == (Object)null)
			{
				Plugin.Logger.LogError((object)"No originalScrollArea.");
				return;
			}
			_customScrollArea = Object.Instantiate<ScrollArea>(componentInChildren, _customWindow.transform);
			((Object)_customScrollArea).SetName("_customScrollArea");
			RectTransform component = ((Component)val2).GetComponent<RectTransform>();
			((Component)_customScrollArea).GetComponent<RectTransform>().anchoredPosition = component.anchoredPosition;
			((Component)_customScrollArea).GetComponent<RectTransform>().anchorMax = component.anchorMax;
			((Component)_customScrollArea).GetComponent<RectTransform>().anchorMin = component.anchorMin;
			((Component)_customScrollArea).GetComponent<RectTransform>().offsetMax = component.offsetMax;
			((Component)_customScrollArea).GetComponent<RectTransform>().offsetMin = component.offsetMin;
			((Component)_customScrollArea).GetComponent<RectTransform>().pivot = component.pivot * 2f;
			((Component)_customScrollArea).GetComponent<RectTransform>().sizeDelta = component.sizeDelta;
			ClearPersistentListeners((UnityEventBase)(object)_customScrollArea.onScroll);
			Transform val3 = ((Component)componentInChildren).transform.parent.Find("Scroll R");
			if ((Object)(object)val3 == (Object)null)
			{
				Plugin.Logger.LogError((object)("Could not find 'Scroll R' beside '" + GetPath(((Component)componentInChildren).transform, ((Component)missionWindow).transform) + "' in the original mission info window."));
				DestroyCustomWindow();
				return;
			}
			_customScrollBar = Object.Instantiate<GameObject>(((Component)val3).gameObject, _customWindow.transform, false);
			((Object)_customScrollBar).name = "_customScrollBar";
			_customScrollBar.SetActive(true);
			Transform obj = _customScrollBar.transform.Find("ScrollRect/ScrollBar");
			ScrollBar val4 = ((obj != null) ? ((Component)obj).GetComponent<ScrollBar>() : null);
			FieldInfo fieldInfo2 = AccessTools.Field(typeof(ScrollArea), "scrollBar");
			if ((Object)(object)val4 == (Object)null || fieldInfo2 == null)
			{
				Plugin.Logger.LogError((object)"Could not wire the cloned 'Scroll R/ScrollRect/ScrollBar' to the custom ScrollArea.");
				DestroyCustomWindow();
				return;
			}
			_customScrollBar.GetComponent<RectTransform>().sizeDelta = new Vector2(20f, 775f);
			_customScrollBar.GetComponent<RectTransform>().anchoredPosition = new Vector2(-2f, 20f);
			ClearPersistentListeners((UnityEventBase)(object)val4.OnDrag);
			fieldInfo2.SetValue(_customScrollArea, val4);
			Plugin.Logger.LogInfo((object)("Cloned 'Scroll R/ScrollRect/ScrollBar' under '" + ((Object)_customWindow).name + "' and assigned it to the ScrollArea."));
			Transform obj2 = ((Component)_customScrollArea).transform.Find("ScrollContent");
			RectTransform val5 = (RectTransform)(object)((obj2 is RectTransform) ? obj2 : null);
			if ((Object)(object)val5 == (Object)null)
			{
				Plugin.Logger.LogError((object)"Could not find ScrollContent.");
				return;
			}
			_customScrollArea.ItemContainer = val5;
			GridLayoutGroup component2 = ((Component)val2).GetComponent<GridLayoutGroup>();
			GridLayoutGroup val6 = ((Component)val5).GetComponent<GridLayoutGroup>();
			if ((Object)(object)val6 == (Object)null)
			{
				val6 = ((Component)val5).gameObject.AddComponent<GridLayoutGroup>();
			}
			((LayoutGroup)val6).padding = ((LayoutGroup)component2).padding;
			val6.cellSize = component2.cellSize;
			val6.spacing = new Vector2(75f, 75f);
			missionWindow.ToggleReplayWindow();
			missionWindow.ToggleReplayWindow();
			missionWindow.ToggleLegacyWindow();
			missionWindow.ToggleLegacyWindow();
			PopulateCustomWindow(missionWindow, val5);
			if (Configs.IsOpenByDefault.Value)
			{
				OpenCustomWindow();
			}
		}

		private static void OnCustomButtonClicked(MissionSelectWindow instance)
		{
			if (!((Object)(object)_customWindow == (Object)null))
			{
				instance.legacyWindow.SetActive(false);
				instance.replayWindow.SetActive(false);
				if (_customWindow.activeSelf)
				{
					CloseCustomWindow();
					return;
				}
				Transform obj = ((Component)_customScrollArea).transform.Find("ScrollContent");
				PopulateCustomWindow(instance, (RectTransform)(object)((obj is RectTransform) ? obj : null));
				OpenCustomWindow();
			}
		}

		private static void CloseCustomWindow()
		{
			if ((Object)(object)_customWindow != (Object)null)
			{
				_customWindow.SetActive(false);
			}
		}

		private static void OpenCustomWindow()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_004c: 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)
			if (!((Object)(object)_customWindow == (Object)null))
			{
				_customWindow.SetActive(true);
				RefreshCustomScroll();
				PlayerLook.Instance.DotTransition.Enable((RectTransform)_customWindow.transform, Global.UIColor, true);
				((Graphic)_customScrollBar.GetComponent<BevelRectOutline>()).color = Global.UIColor;
				((Graphic)((Component)_customScrollBar.transform.GetChild(0).GetChild(0)).GetComponent<BevelRect>()).color = Global.UIColor;
			}
		}

		private static void RefreshCustomScroll()
		{
			//IL_00ac: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_customScrollArea == (Object)null)
			{
				return;
			}
			RectTransform itemContainer = _customScrollArea.ItemContainer;
			ScrollBar scrollBar = _customScrollArea.ScrollBar;
			if (!((Object)(object)itemContainer == (Object)null) && !((Object)(object)scrollBar == (Object)null))
			{
				LayoutRebuilder.ForceRebuildLayoutImmediate(itemContainer);
				_customScrollArea.UpdateScrollSpeed();
				float maxScrollPos = _customScrollArea.GetMaxScrollPos((RectTransform)null);
				if ((Object)(object)_customScrollBar != (Object)null)
				{
					_customScrollBar.SetActive(maxScrollPos > 0f);
				}
				scrollBar.SetScrollY(1f);
				ManualLogSource logger = Plugin.Logger;
				string text = $"scroll: persistent={((UnityEventBase)_customScrollArea.onScroll).GetPersistentEventCount()} ";
				object arg = maxScrollPos;
				Rect rect = itemContainer.rect;
				string text2 = $"max={arg} contentH={((Rect)(ref rect)).height} ";
				rect = ((RectTransform)((Component)_customScrollArea).transform).rect;
				logger.LogInfo((object)(text + text2 + $"areaH={((Rect)(ref rect)).height} " + $"speed={scrollBar.ScrollSpeed}"));
			}
		}

		private static void DestroyCustomWindow()
		{
			if ((Object)(object)_customWindow != (Object)null)
			{
				Object.Destroy((Object)(object)_customWindow);
			}
			_customWindow = null;
			_customScrollArea = null;
			_customScrollBar = null;
		}

		private static void WireCloseButton(GameObject window)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			DefaultButton componentInChildren = window.GetComponentInChildren<DefaultButton>();
			ClearPersistentListeners((UnityEventBase)(object)((Button)componentInChildren).OnClickUp);
			UnityEvent onClickUp = ((Button)componentInChildren).OnClickUp;
			object obj = <>O.<0>__CloseCustomWindow;
			if (obj == null)
			{
				UnityAction val = CloseCustomWindow;
				<>O.<0>__CloseCustomWindow = val;
				obj = (object)val;
			}
			onClickUp.AddListener((UnityAction)obj);
		}

		private static RectTransform FindClone(RectTransform original, GameObject originalWindow, GameObject clonedWindow)
		{
			string path = GetPath((Transform)(object)original, originalWindow.transform);
			Transform obj = clonedWindow.transform.Find(path);
			return (RectTransform)(object)((obj is RectTransform) ? obj : null);
		}

		private static string GetPath(Transform child, Transform root)
		{
			Transform val = child;
			string text = ((Object)val).name;
			while ((Object)(object)val.parent != (Object)null && (Object)(object)val.parent != (Object)(object)root)
			{
				val = val.parent;
				text = ((Object)val).name + "/" + text;
			}
			Plugin.Logger.LogInfo((object)("path : " + text));
			return text;
		}

		private static void PopulateCustomWindow(MissionSelectWindow missionWindow, RectTransform container)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0093: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0437: Unknown result type (might be due to invalid IL or missing references)
			//IL_043c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_047c: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d8: Unknown result type (might be due to invalid IL or missing references)
			MissionSelectButton val = (MissionSelectButton)AccessTools.Field(typeof(MissionSelectWindow), "missionButtonPrefab").GetValue(missionWindow);
			List<MissionData> list = new List<MissionData>();
			PlanetData[] planets = missionWindow.planets;
			foreach (PlanetData val2 in planets)
			{
				if (val2.planetReference.IsLocked())
				{
					continue;
				}
				ActiveMission[] data = val2.activeMissions.Data;
				foreach (ActiveMission val3 in data)
				{
					if (!((Object)(object)val3.Button == (Object)null) && ((Component)val3.Button).gameObject.activeSelf)
					{
						MissionData mission = val3.Button.Mission;
						if (FilterMission(((MissionData)(ref mission)).Mission, val3.Source))
						{
							list.Add(mission);
						}
					}
				}
			}
			object? obj = AccessTools.Field(typeof(MissionSelectWindow), "replayMissionContainer")?.GetValue(missionWindow);
			Transform val4 = (Transform)((obj is Transform) ? obj : null);
			if ((Object)(object)val4 == (Object)null)
			{
				Plugin.Logger.LogError((object)"Could not find MissionSelectWindow.replayMissionContainer.");
			}
			else
			{
				MissionSelectButton[] componentsInChildren = ((Component)val4).GetComponentsInChildren<MissionSelectButton>(true);
				foreach (MissionSelectButton val5 in componentsInChildren)
				{
					if (!((Component)val5).gameObject.activeSelf)
					{
						continue;
					}
					MissionData mission2 = val5.Mission;
					if (FilterMission(((MissionData)(ref mission2)).Mission, val5) && !list.Contains(mission2))
					{
						bool flag = ((MissionData)(ref mission2)).Mission._missionName == "groundzero";
						bool flag2 = Configs.WeekliesVisibility.Value == Configs.WeekliesEnum.HideNone || (Configs.WeekliesVisibility.Value == Configs.WeekliesEnum.Vanilla && !((MissionData)(ref mission2)).Mission.HasCompletedThisWeek());
						if (((MissionData)(ref mission2)).Mission._missionName != "ge_amalgamation" && (flag ? flag2 : Configs.ReplayMissions.Value))
						{
							list.Add(mission2);
						}
					}
				}
			}
			if (Configs.LegacyMissions.Value)
			{
				object? obj2 = AccessTools.Field(typeof(MissionSelectWindow), "legacyMissionContainer")?.GetValue(missionWindow);
				Transform val6 = (Transform)((obj2 is Transform) ? obj2 : null);
				if ((Object)(object)val6 == (Object)null)
				{
					Plugin.Logger.LogError((object)"Could not find MissionSelectWindow.legacyMissionContainer.");
				}
				else
				{
					MissionSelectButton[] componentsInChildren = ((Component)val6).GetComponentsInChildren<MissionSelectButton>(true);
					foreach (MissionSelectButton val7 in componentsInChildren)
					{
						if (((Component)val7).gameObject.activeSelf)
						{
							MissionData mission3 = val7.Mission;
							if (FilterMission(((MissionData)(ref mission3)).Mission, val7) && !list.Contains(mission3))
							{
								list.Add(mission3);
							}
						}
					}
				}
			}
			list = Configs.SortBy.Value switch
			{
				Configs.SortMethod.Biome => list.OrderBy(GetBiomeOrder).ThenByDescending((MissionData val9) => ((MissionData)(ref val9)).GetModifierCount()).ThenBy(GetMissionTypeOrder)
					.ToList(), 
				Configs.SortMethod.ModifierCount => list.OrderByDescending((MissionData val9) => ((MissionData)(ref val9)).GetModifierCount()).ThenBy(GetMissionTypeOrder).ThenBy(GetBiomeOrder)
					.ToList(), 
				Configs.SortMethod.MissionType => list.OrderBy(GetMissionTypeOrder).ThenByDescending((MissionData val9) => ((MissionData)(ref val9)).GetModifierCount()).ThenBy(GetBiomeOrder)
					.ToList(), 
				_ => list, 
			};
			int num = 0;
			foreach (MissionData item in list)
			{
				MissionData current = item;
				MissionSelectButton val8 = ((num >= ((Transform)container).childCount) ? Object.Instantiate<MissionSelectButton>(val, (Transform)(object)container) : ((Component)((Transform)container).GetChild(num)).GetComponent<MissionSelectButton>());
				((Component)val8).gameObject.SetActive(true);
				((MaskableGraphic)((Component)val8).GetComponent<Image>()).maskable = true;
				val8.Setup(current, missionWindow, true, false, false);
				Image[] componentsInChildren2 = ((Component)val8).GetComponentsInChildren<Image>(true);
				for (int i = 0; i < componentsInChildren2.Length; i++)
				{
					((MaskableGraphic)componentsInChildren2[i]).maskable = true;
				}
				if (Configs.BiomeIconsColor.Value)
				{
					((Graphic)((Component)((Component)val8).transform.Find("Outline")).GetComponent<Image>()).color = ((MissionData)(ref current)).Region.Color;
				}
				num++;
			}
			for (int num2 = num; num2 < ((Transform)container).childCount; num2++)
			{
				((Component)((Transform)container).GetChild(num2)).gameObject.SetActive(false);
			}
		}

		private static bool FilterMission(Mission mission, object source)
		{
			if (!Configs.Freeroam.Value && mission._missionName == "freeroam")
			{
				return false;
			}
			if (!Configs.Incursion.Value && mission._missionName == "incursion")
			{
				return false;
			}
			if (!Configs.Ouroboros.Value && mission._missionName == "ouroboros")
			{
				return false;
			}
			if (!Configs.Ouroblitz.Value && mission._missionName == "ouroblitz")
			{
				return false;
			}
			if (!Configs.OxybreachE.Value && mission._missionName == "oxybreach_e")
			{
				return false;
			}
			if (Configs.WeekliesVisibility.Value == Configs.WeekliesEnum.HideAll && mission.HasCompletedThisWeek())
			{
				if (source is MissionSelectButton && Enumerable.Contains(OtButtons, source))
				{
					return false;
				}
				if (mission.ResetWeekly)
				{
					return false;
				}
			}
			return true;
		}

		private static int GetBiomeOrder(MissionData mission)
		{
			for (int i = 0; i < BiomeOrder.Length; i++)
			{
				if (string.Equals(BiomeOrder[i], ((Object)((MissionData)(ref mission)).Region).GetName(), StringComparison.OrdinalIgnoreCase))
				{
					return i;
				}
			}
			return BiomeOrder.Length;
		}

		private static int GetMissionTypeOrder(MissionData mission)
		{
			for (int i = 0; i < MissionTypeOrder.Length; i++)
			{
				if (string.Equals(MissionTypeOrder[i], ((MissionData)(ref mission)).Mission._missionName, StringComparison.OrdinalIgnoreCase))
				{
					return i;
				}
			}
			return MissionTypeOrder.Length;
		}

		private static void ClearPersistentListeners(UnityEventBase unityEvent)
		{
			object value = AccessTools.Field(typeof(UnityEventBase), "m_PersistentCalls").GetValue(unityEvent);
			AccessTools.Method(value.GetType(), "Clear", (Type[])null, (Type[])null).Invoke(value, null);
			AccessTools.Method(typeof(UnityEventBase), "DirtyPersistentCalls", (Type[])null, (Type[])null).Invoke(unityEvent, null);
		}

		[HarmonyPatch(typeof(MissionSelectWindow), "ToggleLegacyWindow")]
		[HarmonyPrefix]
		private static void ToggleLegacyWindowPrefix()
		{
			CloseCustomWindow();
		}

		[HarmonyPatch(typeof(MissionSelectWindow), "ToggleReplayWindow")]
		[HarmonyPostfix]
		private static void ToggleReplayWindowPostfix()
		{
			CloseCustomWindow();
		}

		[HarmonyPatch(typeof(MissionSelectWindow), "OnEscape")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> OnEscapeTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Expected O, but got Unknown
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Expected O, but got Unknown
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Expected O, but got Unknown
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			FieldInfo fieldInfo = AccessTools.Field(typeof(MissionSelectWindow), "replayWindow");
			if (fieldInfo == null)
			{
				Plugin.Logger.LogError((object)"Could not find MissionSelectWindow.replayWindow for OnEscape transpiler.");
				return list;
			}
			for (int i = 1; i < list.Count; i++)
			{
				if (!(list[i].opcode != OpCodes.Ldfld) && object.Equals(list[i].operand, fieldInfo) && !(list[i - 1].opcode != OpCodes.Ldarg_0))
				{
					Label label = generator.DefineLabel();
					CodeInstruction obj = list[i - 1];
					Label[] collection = obj.labels.ToArray();
					obj.labels.Clear();
					List<CodeInstruction> list2 = new List<CodeInstruction>
					{
						new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(MissionList), "HandleEscapeKey", (Type[])null, (Type[])null)),
						new CodeInstruction(OpCodes.Brfalse, (object)label),
						new CodeInstruction(OpCodes.Ldc_I4_1, (object)null),
						new CodeInstruction(OpCodes.Ret, (object)null)
					};
					list2[0].labels.AddRange(collection);
					obj.labels.Add(label);
					list.InsertRange(i - 1, list2);
					return list;
				}
			}
			Plugin.Logger.LogError((object)"Could not find the replayWindow check in MissionSelectWindow.OnEscape.");
			return list;
		}

		private static bool HandleEscapeKey()
		{
			if ((Object)(object)_customWindow == (Object)null || !_customWindow.activeSelf)
			{
				return false;
			}
			CloseCustomWindow();
			return true;
		}

		internal static void TrackOtButton(MissionContainer missionContainer, MissionSelectButton button)
		{
			if ((Object)(object)missionContainer == (Object)(object)Global.Instance.OvertimeAssignment)
			{
				OtButtons.Add(button);
			}
		}
	}
	[HarmonyPatch]
	internal static class OtTrackingPatches
	{
		[HarmonyPatch(typeof(MissionSelectWindow), "SetupMission")]
		[HarmonyPostfix]
		private static void SetupMissionPostfix(MissionContainer __0, MissionSelectButton __2)
		{
			MissionList.TrackOtButton(__0, __2);
		}
	}
	[MycoMod(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("miniprince123.mission_list", "Mission_List", "0.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private Harmony _harmony;

		internal static ManualLogSource Logger;

		private void Awake()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin Mission_List (miniprince123.mission_list 0.0.0) is loaded!");
			Configs.Initialize(((BaseUnityPlugin)this).Config);
			Logger.LogInfo((object)"Config initialized");
			_harmony = new Harmony("miniprince123.mission_list");
			_harmony.PatchAll();
			Logger.LogInfo((object)"Harmony patches applied");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "miniprince123.mission_list";

		public const string PLUGIN_NAME = "Mission_List";

		public const string PLUGIN_VERSION = "0.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}