Decompiled source of LostBranchCompanion v0.0.5

Companion.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 AddWatermark;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Companion.Config;
using Companion.Patches;
using Companion.Utils;
using Cysharp.Threading.Tasks;
using HarmonyLib;
using LBoL.Base.Extensions;
using LBoL.ConfigData;
using LBoL.Core;
using LBoL.Core.Adventures;
using LBoL.Core.Battle;
using LBoL.Core.Cards;
using LBoL.Core.SaveData;
using LBoL.Core.Stations;
using LBoL.Core.Units;
using LBoL.Presentation;
using LBoL.Presentation.Environments;
using LBoL.Presentation.I10N;
using LBoL.Presentation.UI;
using LBoL.Presentation.UI.Dialogs;
using LBoL.Presentation.UI.ExtraWidgets;
using LBoL.Presentation.UI.Panels;
using LBoL.Presentation.UI.Widgets;
using LBoL.Presentation.Units;
using LBoLEntitySideloader;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Experimental.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("LBoL.Base")]
[assembly: IgnoresAccessChecksTo("LBoL.ConfigData")]
[assembly: IgnoresAccessChecksTo("LBoL.Core")]
[assembly: IgnoresAccessChecksTo("LBoL.EntityLib")]
[assembly: IgnoresAccessChecksTo("LBoL.Presentation")]
[assembly: IgnoresAccessChecksTo("Untitled.ConfigDataBuilder.Base")]
[assembly: AssemblyCompany("Companion")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Companion")]
[assembly: AssemblyTitle("Companion")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Companion
{
	[BepInPlugin("cyaneko.lbol.mods.companion", "Lost Branch Companion", "0.0.5")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("LBoL.exe")]
	public class BepinexPlugin : BaseUnityPlugin
	{
		private static readonly Harmony harmony = PInfo.harmony;

		internal static ManualLogSource log;

		internal static ConfigEntry<bool> AutoCollectMoney;

		internal static ConfigEntry<bool> AutoCollectExhibits;

		internal static ConfigEntry<string> AutoCollectWhitelist;

		internal static ConfigEntry<string> AutoCollectBlacklist;

		internal static ConfigEntry<bool> AutoCollectTools;

		internal static ConfigEntry<bool> AutoOpenMap;

		internal static ConfigEntry<bool> AutoAdvance;

		internal static ConfigEntry<QuickStartMode> QuickStartBehaviour;

		internal static bool SideloaderAvailable = false;

		private void Awake()
		{
			log = ((BaseUnityPlugin)this).Logger;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			AutoCollectMoney = ((BaseUnityPlugin)this).Config.Bind<bool>("Quality of Life", "Auto-collect money", true, "Automatically collect reward money.");
			AutoCollectExhibits = ((BaseUnityPlugin)this).Config.Bind<bool>("Quality of Life", "Auto-collect exhibits", true, "Automatically collect most exhibits. Further configurable through white/black lists.");
			AutoCollectWhitelist = ((BaseUnityPlugin)this).Config.Bind<string>("Quality of Life", "Exhibit white list", "", "Comma-separated list of exhibit IDs to ALWAYS pick up by auto-collection. If you do not know what is an exhibit ID, ask a modder.");
			AutoCollectBlacklist = ((BaseUnityPlugin)this).Config.Bind<string>("Quality of Life", "Exhibit black list", "", "Comma-separated list of exhibit IDs to NEVER pick up by auto-collection. If you do not know what is an exhibit ID, ask a modder.");
			AutoCollectTools = ((BaseUnityPlugin)this).Config.Bind<bool>("Quality of Life", "Auto-collect tools", true, "Automatically collect tool cards (from Ringo or Toolbox)");
			AutoOpenMap = ((BaseUnityPlugin)this).Config.Bind<bool>("Quality of Life", "Auto-open map", true, "Automatically open the map when an event is finished or all rewards are collected.");
			AutoAdvance = ((BaseUnityPlugin)this).Config.Bind<bool>("Quality of Life", "Auto-advance path", false, "Automatically advance to next node if there is only one available path.");
			QuickStartBehaviour = ((BaseUnityPlugin)this).Config.Bind<QuickStartMode>("Quick Start", "Mode", QuickStartMode.LastRun, "Determines behaviour of the Quick Start button");
			foreach (string item in from id in AutoCollectWhitelist.Value.Split(',', StringSplitOptions.RemoveEmptyEntries)
				select id.Trim().ToLowerInvariant())
			{
				Automation.ExhibitWhitelist.Add(item);
			}
			foreach (string item2 in from id in AutoCollectBlacklist.Value.Split(',', StringSplitOptions.RemoveEmptyEntries)
				select id.Trim().ToLowerInvariant())
			{
				Automation.ExhibitBlacklist.Add(item2);
			}
			CompanionConfigUI.lily = Texture.LoadTextureFromAssembly(Assembly.GetExecutingAssembly(), "lily.png");
			SideloaderAvailable = Chainloader.PluginInfos.ContainsKey("neo.lbol.frameworks.entitySideloader");
			harmony.PatchAll();
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			if ((Object)null != (Object)(object)RunQuickstart.MainMenuPanel_Patches.ResetGameObj)
			{
				Object.Destroy((Object)(object)RunQuickstart.MainMenuPanel_Patches.ResetGameObj);
				RunQuickstart.MainMenuPanel_Patches.ResetGameObj = null;
			}
			if ((Object)null != (Object)(object)RunQuickstart.MainMenuPanel_Patches.QuickStartGameObj)
			{
				Object.Destroy((Object)(object)RunQuickstart.MainMenuPanel_Patches.QuickStartGameObj);
				RunQuickstart.MainMenuPanel_Patches.QuickStartGameObj = null;
			}
			if ((Object)null != (Object)(object)RunQuickstart.SettingPanel_Patches.ResetGameBtn)
			{
				Object.Destroy((Object)(object)((Component)RunQuickstart.SettingPanel_Patches.ResetGameBtn).gameObject);
				RunQuickstart.SettingPanel_Patches.ResetGameBtn = null;
			}
			if ((Object)null != (Object)(object)CompanionConfigUI.lily)
			{
				Object.Destroy((Object)(object)CompanionConfigUI.lily.texture);
				Object.Destroy((Object)(object)CompanionConfigUI.lily);
				CompanionConfigUI.lily = null;
			}
			Automation.ExhibitBlacklist.Clear();
			Automation.ExhibitWhitelist.Clear();
		}
	}
	public static class PInfo
	{
		public const string GUID = "cyaneko.lbol.mods.companion";

		public const string Name = "Lost Branch Companion";

		public const string version = "0.0.5";

		public static readonly Harmony harmony = new Harmony("cyaneko.lbol.mods.companion");
	}
	internal class SideloaderWrapper
	{
		[CompilerGenerated]
		private sealed class <EnumerateLoadouts>d__1 : IEnumerable<(string, string)>, IEnumerable, IEnumerator<(string, string)>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private (string, string) <>2__current;

			private int <>l__initialThreadId;

			private Dictionary<string, List<CharLoadoutInfo>>.Enumerator <>7__wrap1;

			private KeyValuePair<string, List<CharLoadoutInfo>> <chara>5__3;

			private List<CharLoadoutInfo>.Enumerator <>7__wrap3;

			(string, string) IEnumerator<(string, string)>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <EnumerateLoadouts>d__1(int <>1__state)
			{
				this.<>1__state = <>1__state;
				<>l__initialThreadId = Environment.CurrentManagedThreadId;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if ((uint)(num - -4) <= 1u || num == 1)
				{
					try
					{
						if (num == -4 || num == 1)
						{
							try
							{
							}
							finally
							{
								<>m__Finally2();
							}
						}
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<>7__wrap1 = default(Dictionary<string, List<CharLoadoutInfo>>.Enumerator);
				<chara>5__3 = default(KeyValuePair<string, List<CharLoadoutInfo>>);
				<>7__wrap3 = default(List<CharLoadoutInfo>.Enumerator);
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				try
				{
					int num = <>1__state;
					if (num != 0)
					{
						if (num != 1)
						{
							return false;
						}
						<>1__state = -4;
						goto IL_00ad;
					}
					<>1__state = -1;
					<>7__wrap1 = UniqueTracker.Instance.loadoutInfos.GetEnumerator();
					<>1__state = -3;
					goto IL_00d8;
					IL_00ad:
					if (<>7__wrap3.MoveNext())
					{
						CharLoadoutInfo current = <>7__wrap3.Current;
						<>2__current = (<chara>5__3.Key, current.ultimateSkill);
						<>1__state = 1;
						return true;
					}
					<>m__Finally2();
					<>7__wrap3 = default(List<CharLoadoutInfo>.Enumerator);
					<chara>5__3 = default(KeyValuePair<string, List<CharLoadoutInfo>>);
					goto IL_00d8;
					IL_00d8:
					if (<>7__wrap1.MoveNext())
					{
						<chara>5__3 = <>7__wrap1.Current;
						<>7__wrap3 = <chara>5__3.Value.GetEnumerator();
						<>1__state = -4;
						goto IL_00ad;
					}
					<>m__Finally1();
					<>7__wrap1 = default(Dictionary<string, List<CharLoadoutInfo>>.Enumerator);
					return false;
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				((IDisposable)<>7__wrap1).Dispose();
			}

			private void <>m__Finally2()
			{
				<>1__state = -3;
				((IDisposable)<>7__wrap3).Dispose();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}

			[DebuggerHidden]
			IEnumerator<(string, string)> IEnumerable<(string, string)>.GetEnumerator()
			{
				if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
				{
					<>1__state = 0;
					return this;
				}
				return new <EnumerateLoadouts>d__1(0);
			}

			[DebuggerHidden]
			IEnumerator IEnumerable.GetEnumerator()
			{
				return ((IEnumerable<(string, string)>)this).GetEnumerator();
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal static bool TryGetLoadout(string playerName, string usId, out UltimateSkill ultimateSkill, out Exhibit startingExhibit, out IEnumerable<Card> startingLibrary)
		{
			ultimateSkill = null;
			startingExhibit = null;
			startingLibrary = null;
			if (UniqueTracker.Instance.loadoutInfos.TryGetValue(playerName, out var value))
			{
				CharLoadoutInfo val = value.Find((CharLoadoutInfo loadout) => loadout.ultimateSkill == usId);
				if (val != null)
				{
					try
					{
						ultimateSkill = Library.CreateUs(val.ultimateSkill);
						startingExhibit = Library.CreateExhibit(val.exhibit);
						startingLibrary = val.deck.Select((string c) => Library.CreateCard(c));
						return true;
					}
					catch (Exception arg)
					{
						BepinexPlugin.log.LogError((object)$"(SideloaderWrapper.TryGetLoadout) error while trying to create loadout:\n{arg}");
					}
				}
			}
			return false;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[IteratorStateMachine(typeof(<EnumerateLoadouts>d__1))]
		internal static IEnumerable<(string, string)> EnumerateLoadouts()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <EnumerateLoadouts>d__1(-2);
		}
	}
	internal class WatermarkWrapper
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		internal static void ActivateWatermark()
		{
			API.ActivateWatermark();
		}
	}
}
namespace Companion.Utils
{
	public static class Extensions
	{
		public static T GenericMin<T>(T a, T b) where T : IComparable
		{
			if (a.CompareTo(b) > 0)
			{
				return b;
			}
			return a;
		}

		public static T GenericMax<T>(T a, T b) where T : IComparable
		{
			if (a.CompareTo(b) < 0)
			{
				return b;
			}
			return a;
		}

		public static bool IsOverride(this MethodInfo m)
		{
			return m.GetBaseDefinition().DeclaringType != m.DeclaringType;
		}
	}
	public static class Profile
	{
		public static void UnlockAllForProfile(ProfileSaveData prof)
		{
			if (prof != null)
			{
				if (prof.Exp < ExpHelper.MaxExp)
				{
					int num = ExpHelper.MaxExp - prof.Exp;
					prof.BluePoint += num;
					prof.Exp += num;
				}
				prof.CardsRevealed = (from cfg in CardConfig.AllConfig()
					where !cfg.HideMesuem && cfg.DebugLevel == 0
					select cfg.Id).ToList();
				prof.CardsRevealed.Sort();
				prof.ExhibitsRevealed = (from cfg in ExhibitConfig.AllConfig()
					where cfg.Revealable && !cfg.IsDebug
					select cfg.Id).ToList();
				prof.ExhibitsRevealed.Sort();
			}
		}

		public static bool TryGetLastRunInHistory(out GameRunRecordSaveData record)
		{
			record = null;
			GameMaster instance = Singleton<GameMaster>.Instance;
			if (instance.CurrentSaveIndex.HasValue)
			{
				int value = instance.CurrentSaveIndex.Value;
				string path = Path.Combine(GameMaster.PlatformHandler.GetSaveDataFolder(), GameMaster.GetHistoryFileName(value));
				List<GameRunRecordSaveData> list;
				try
				{
					if (!File.Exists(path))
					{
						BepinexPlugin.log.LogInfo((object)"(RunQuickstart.TryGetLastRunInHistory) Run history file does not exist");
						return false;
					}
					list = SaveDataHelper.DeserializeGameRunHistory(File.ReadAllBytes(path));
				}
				catch (Exception arg)
				{
					BepinexPlugin.log.LogError((object)$"(RunQuickstart.TryGetLastRunInHistory) Could not read run history file: {arg}");
					return false;
				}
				if (list.Count == 0)
				{
					BepinexPlugin.log.LogInfo((object)"(RunQuickstart.TryGetLastRunInHistory) Run history is empty");
					return false;
				}
				record = list.Last();
				return true;
			}
			return false;
		}
	}
	public static class Texture
	{
		public static Sprite LoadTextureFromAssembly(Assembly assembly, string id)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			string text = assembly.GetManifestResourceNames().FirstOrDefault((string p) => p.EndsWith("." + id));
			if (text == null)
			{
				return null;
			}
			using Stream stream = assembly.GetManifestResourceStream(text);
			if (stream == null)
			{
				return null;
			}
			using MemoryStream memoryStream = new MemoryStream();
			byte[] array = new byte[32768];
			int count;
			while ((count = stream.Read(array, 0, array.Length)) > 0)
			{
				memoryStream.Write(array, 0, count);
			}
			Texture2D val = new Texture2D(0, 0, (GraphicsFormat)4, (TextureCreationFlags)0)
			{
				anisoLevel = 1,
				filterMode = (FilterMode)1
			};
			ImageConversion.LoadImage(val, memoryStream.ToArray());
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 1f);
		}
	}
	public static class UI
	{
		public static void ConfirmationPopup(string key, Action confirmAction)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			((UiDialog<MessageContent>)(object)UiManager.GetDialog<MessageDialog>()).Show(new MessageContent
			{
				TextKey = key,
				Icon = (MessageIcon)1,
				Buttons = (DialogButtons)1,
				OnConfirm = confirmAction
			});
		}
	}
}
namespace Companion.Patches
{
	[HarmonyPatch]
	public static class Automation
	{
		[CompilerGenerated]
		private sealed class <EndStationFlowWrapper>d__5 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public Station station;

			public IEnumerator result;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <EndStationFlowWrapper>d__5(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_006b: Invalid comparison between I4 and Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					BepinexPlugin.log.LogDebug((object)"EndStationFlow...");
					if (((Unit)station.GameRun.Player).IsDead || station.IsStageEnd || (!station.IsStageEnd && 2 != (int)station.GameRun.MapMode))
					{
						BepinexPlugin.log.LogDebug((object)"Trying to skip next click");
						skipNextButtonClick = true;
					}
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (result.MoveNext())
				{
					<>2__current = result.Current;
					<>1__state = 1;
					return true;
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public static readonly HashSet<string> ExhibitWhitelist = new HashSet<string>();

		public static readonly HashSet<string> ExhibitBlacklist = new HashSet<string>();

		private static bool skipNextButtonClick = false;

		[HarmonyPatch(typeof(RewardPanel), "OnShowing", new Type[] { typeof(ShowRewardContent) })]
		[HarmonyPostfix]
		public static void AfterShow(RewardPanel __instance, ShowRewardContent showRewardContent)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_0043: Expected I4, but got Unknown
			List<RewardWidget> rewardWidgets = __instance._rewardWidgets;
			List<RewardWidget> list = new List<RewardWidget>();
			for (int i = 0; i < rewardWidgets.Count; i++)
			{
				RewardWidget val = rewardWidgets[i];
				bool flag = false;
				StationRewardType type = val.StationReward.Type;
				switch ((int)type)
				{
				case 2:
				{
					if (!BepinexPlugin.AutoCollectExhibits.Value)
					{
						break;
					}
					Exhibit exhibit = val.StationReward.Exhibit;
					if (exhibit == null)
					{
						break;
					}
					if (ExhibitWhitelist.Contains(((GameEntity)exhibit).Id.ToLowerInvariant()))
					{
						flag = true;
					}
					else if (!ExhibitBlacklist.Contains(((GameEntity)exhibit).Id.ToLowerInvariant()))
					{
						MethodInfo? method = ((object)exhibit).GetType().GetMethod("OnGain", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
						MethodInfo method2 = ((object)exhibit).GetType().GetMethod("SpecialGain", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
						if (!method.IsOverride() && !method2.IsOverride())
						{
							flag = true;
						}
					}
					break;
				}
				case 0:
					if (BepinexPlugin.AutoCollectMoney.Value)
					{
						flag = true;
					}
					break;
				case 3:
					if (BepinexPlugin.AutoCollectTools.Value)
					{
						flag = true;
					}
					break;
				}
				if (flag)
				{
					list.Add(val);
				}
			}
			foreach (RewardWidget item in list)
			{
				((UnityEvent)item.button.onClick).Invoke();
			}
		}

		[HarmonyPatch(typeof(GameMaster), "EndGameProcedure", new Type[] { typeof(GameRunController) })]
		[HarmonyPrefix]
		public static void PreGameEnd(GameMaster __instance)
		{
			BepinexPlugin.log.LogDebug((object)"EndGameProcedure...");
			BepinexPlugin.log.LogDebug((object)"Trying to skip next click");
			skipNextButtonClick = true;
		}

		[IteratorStateMachine(typeof(<EndStationFlowWrapper>d__5))]
		[HarmonyPatch(typeof(GameMaster), "EndStationFlow", new Type[]
		{
			typeof(Station),
			typeof(bool)
		})]
		[HarmonyPostfix]
		public static IEnumerator EndStationFlowWrapper(IEnumerator result, GameMaster __instance, Station station, bool skipBossReward)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <EndStationFlowWrapper>d__5(0)
			{
				result = result,
				station = station
			};
		}

		[HarmonyPatch(typeof(VnPanel), "SetNextButton", new Type[]
		{
			typeof(bool),
			typeof(int?),
			typeof(Action)
		})]
		[HarmonyPostfix]
		public static void ClickNextButton(VnPanel __instance, bool active, int? index, Action call)
		{
			BepinexPlugin.log.LogDebug((object)"SetNextButton...");
			if (skipNextButtonClick)
			{
				BepinexPlugin.log.LogDebug((object)"Click skipped...");
				skipNextButtonClick = false;
			}
			else if (BepinexPlugin.AutoOpenMap.Value && active && index.HasValue && 0 == index)
			{
				BepinexPlugin.log.LogDebug((object)"Conditions valid, clicking...");
				((UnityEvent)__instance.nextButton.onClick).Invoke();
			}
		}

		[HarmonyPatch(typeof(VnPanel), "End")]
		[HarmonyPostfix]
		public static void EndEvent(VnPanel __instance)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Invalid comparison between I4 and Unknown
			BepinexPlugin.log.LogDebug((object)"End...");
			if (skipNextButtonClick)
			{
				BepinexPlugin.log.LogDebug((object)"Click skipped...");
				skipNextButtonClick = false;
			}
			else if (BepinexPlugin.AutoOpenMap.Value)
			{
				MapNode val = ((UiPanelBase)__instance).GameRun.CurrentMap.Path.LastOrDefault();
				if (val == null || 10 != (int)val.StationType)
				{
					BepinexPlugin.log.LogDebug((object)"Event finished, clicking...");
					((UnityEvent)__instance.nextButton.onClick).Invoke();
				}
			}
		}

		[HarmonyPatch(typeof(MapPanel), "OnShown")]
		[HarmonyPostfix]
		public static void AfterMapOpenClickNode(MapPanel __instance)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Invalid comparison between I4 and Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Invalid comparison between I4 and Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Invalid comparison between I4 and Unknown
			if (!BepinexPlugin.AutoAdvance.Value || ((UiPanelBase)__instance).Battle != null)
			{
				return;
			}
			RewardPanel panel = UiManager.GetPanel<RewardPanel>();
			if (0 < panel._rewardWidgets.Count)
			{
				return;
			}
			IReadOnlyList<MapNode> path = __instance._map.Path;
			if (0 < path.Count)
			{
				MapNode val = path.Last();
				int count = path.Count;
				if (5 != (int)val.StationType && 3 != (int)((UiPanelBase)__instance).GameRun.MapMode && 1 != (int)((UiPanelBase)__instance).GameRun.MapMode && 1 == val.FollowerList.Count)
				{
					((UnityEvent)__instance._mapNodeWidgets[count, val.FollowerList[0]].button.onClick).Invoke();
				}
			}
		}
	}
	[HarmonyPatch]
	public static class CompanionConfigUI
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction<bool> <>9__13_0;

			public static UnityAction<bool> <>9__13_1;

			public static UnityAction<bool> <>9__13_2;

			public static UnityAction<bool> <>9__13_3;

			public static UnityAction<bool> <>9__13_4;

			public static UnityAction<int> <>9__13_5;

			public static Action <>9__13_7;

			public static UnityAction <>9__13_6;

			internal void <InitConfigTab>b__13_0(bool s)
			{
				BepinexPlugin.AutoCollectMoney.Value = s;
			}

			internal void <InitConfigTab>b__13_1(bool s)
			{
				BepinexPlugin.AutoCollectExhibits.Value = s;
			}

			internal void <InitConfigTab>b__13_2(bool s)
			{
				BepinexPlugin.AutoCollectTools.Value = s;
			}

			internal void <InitConfigTab>b__13_3(bool s)
			{
				BepinexPlugin.AutoOpenMap.Value = s;
			}

			internal void <InitConfigTab>b__13_4(bool s)
			{
				BepinexPlugin.AutoAdvance.Value = s;
			}

			internal void <InitConfigTab>b__13_5(int idx)
			{
				BepinexPlugin.QuickStartBehaviour.Value = (QuickStartMode)idx;
			}

			internal void <InitConfigTab>b__13_6()
			{
				UI.ConfirmationPopup("ProfileUnlockWarning", delegate
				{
					Profile.UnlockAllForProfile(Singleton<GameMaster>.Instance.CurrentProfile);
					UiManager.GetPanel<MainMenuPanel>().RefreshProfile();
				});
			}

			internal void <InitConfigTab>b__13_7()
			{
				Profile.UnlockAllForProfile(Singleton<GameMaster>.Instance.CurrentProfile);
				UiManager.GetPanel<MainMenuPanel>().RefreshProfile();
			}
		}

		private static int tabIndex = -1;

		public static Sprite lily = null;

		public static GameObject dropdownTemplate = null;

		public static GameObject smallDropdownTemplate = null;

		public static GameObject switchTemplate = null;

		public static GameObject sliderTemplate = null;

		public static GameObject buttonTemplate = null;

		private static GameObject CreateDropdown(Transform panelParent, string internalName, string tooltipKey, IEnumerable<string> options, int currentValue, UnityAction<int> callback, bool small = false)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			GameObject obj = Object.Instantiate<GameObject>(small ? smallDropdownTemplate : dropdownTemplate, panelParent);
			((Object)obj).name = internalName;
			TMP_Dropdown componentInChildren = obj.GetComponentInChildren<TMP_Dropdown>();
			componentInChildren.onValueChanged = new DropdownEvent();
			((UnityEvent<int>)(object)componentInChildren.onValueChanged).AddListener(callback);
			componentInChildren.ClearOptions();
			componentInChildren.AddOptions(options.ToList());
			componentInChildren.SetValueWithoutNotify(currentValue);
			string text = "Setting." + internalName;
			string text2 = "Setting." + tooltipKey;
			SimpleTooltipSource.CreateWithGeneralKey(obj, text, text2).WithPosition((TooltipDirection)3, (TooltipAlignment)0);
			LocalizedText component = ((Component)obj.transform.Find("KeyTmp")).GetComponent<LocalizedText>();
			component.key = text;
			component.OnLocaleChanged();
			return obj;
		}

		private static GameObject CreateSwitch(Transform panelParent, string internalName, string tooltipKey, bool currentValue, UnityAction<bool> callback)
		{
			GameObject obj = Object.Instantiate<GameObject>(switchTemplate, panelParent);
			((Object)obj).name = internalName;
			SwitchWidget componentInChildren = obj.GetComponentInChildren<SwitchWidget>();
			componentInChildren.onToggleChanged = new UnityEvent<bool>();
			componentInChildren.onToggleChanged.AddListener(callback);
			componentInChildren.SetValueWithoutNotifier(currentValue, true);
			string text = "Setting." + internalName;
			string text2 = "Setting." + tooltipKey;
			SimpleTooltipSource.CreateWithGeneralKey(obj, text, text2).WithPosition((TooltipDirection)3, (TooltipAlignment)0);
			LocalizedText component = ((Component)obj.transform.Find("KeyTmp")).GetComponent<LocalizedText>();
			component.key = text;
			component.OnLocaleChanged();
			return obj;
		}

		private static GameObject CreateSlider(Transform panelParent, string internalName, string tooltipKey, UnityAction<float> callback)
		{
			return null;
		}

		private static GameObject CreateButton(Transform panelParent, string internalName, string tooltipKey, UnityAction callback, bool interactable)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			GameObject obj = Object.Instantiate<GameObject>(buttonTemplate, panelParent);
			((Object)obj).name = internalName;
			Transform val = obj.transform.Find("ResetHint");
			((Object)val).name = internalName;
			CommonButtonWidget component = ((Component)val).GetComponent<CommonButtonWidget>();
			component.button.onClick = new ButtonClickedEvent();
			((UnityEvent)component.button.onClick).AddListener(callback);
			((Selectable)component.button).interactable = interactable;
			string text = "UI." + internalName;
			string text2 = "UI." + tooltipKey;
			SimpleTooltipSource.CreateWithGeneralKey(obj, text, text2).WithPosition((TooltipDirection)3, (TooltipAlignment)0);
			LocalizedText component2 = ((Component)val.Find("Text (TMP)")).GetComponent<LocalizedText>();
			component2.key = text;
			component2.OnLocaleChanged();
			return obj;
		}

		private static bool TryGetChild(this Transform t, string childName, out Transform child)
		{
			child = t.Find(childName);
			if ((Object)null == (Object)(object)child)
			{
				BepinexPlugin.log.LogWarning((object)("Could not find " + childName + " Transform, the config UI will not be initialised"));
				return false;
			}
			return true;
		}

		private static bool TryGetOptionTab(this SettingPanel panel, string name, out CanvasGroup tab)
		{
			tab = panel.tabs.Where((CanvasGroup t) => ((Object)t).name == name).FirstOrDefault();
			if ((Object)null == (Object)(object)tab)
			{
				BepinexPlugin.log.LogWarning((object)("Could not find " + name + " tab, the config UI will not be initialised"));
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(SettingPanel), "Awake")]
		[HarmonyPrefix]
		public static void InitConfigTab(SettingPanel __instance)
		{
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b2: Expected O, but got Unknown
			if (!((Component)__instance).transform.TryGetChild("Root", out var child) || !child.TryGetChild("Tabs", out var child2) || !child2.TryGetChild("Main", out var child3) || !__instance.TryGetOptionTab("Main", out var tab) || !__instance.TryGetOptionTab("Preference", out var tab2))
			{
				return;
			}
			Transform val = ((Component)tab).transform.Find("LeftPanel");
			Transform val2 = ((Component)tab).transform.Find("RightPanel");
			Transform obj = ((Component)tab2).transform.Find("RightPanel");
			dropdownTemplate = ((Component)val.Find("Resolution")).gameObject;
			smallDropdownTemplate = ((Component)obj.Find("HintLevel")).gameObject;
			switchTemplate = ((Component)val.Find("FullScreen")).gameObject;
			sliderTemplate = ((Component)val2.Find("Master")).gameObject;
			buttonTemplate = ((Component)obj.Find("ResetHint")).gameObject;
			GameObject val3 = Object.Instantiate<GameObject>(((Component)child3).gameObject, child2);
			((Object)val3).name = "CompanionConfig";
			LocalizedText componentInChildren = val3.GetComponentInChildren<LocalizedText>();
			componentInChildren.key = "UI.CompanionConfig";
			componentInChildren.OnLocaleChanged();
			if ((Object)null != (Object)(object)lily)
			{
				Transform val4 = val3.transform.Find("Icon");
				if ((Object)null != (Object)(object)val4)
				{
					((Component)val4).GetComponent<Image>().sprite = lily;
				}
			}
			CanvasGroup val5 = Object.Instantiate<CanvasGroup>(tab, new InstantiateParameters
			{
				parent = ((Component)tab).transform.parent
			});
			((Object)val5).name = "CompanionConfig";
			((Component)val5).transform.SetSiblingIndex(((Component)child).transform.childCount - 2);
			Transform val6 = ((Component)val5).transform.Find("LeftPanel");
			Transform obj2 = ((Component)val5).transform.Find("RightPanel");
			TransformExtensions.DestroyChildren(val6);
			TransformExtensions.DestroyChildren(obj2);
			CreateSwitch(((Component)val6).transform, "AutoCollectMoney", "AutoCollectMoneyDesc", BepinexPlugin.AutoCollectMoney.Value, delegate(bool s)
			{
				BepinexPlugin.AutoCollectMoney.Value = s;
			});
			CreateSwitch(((Component)val6).transform, "AutoCollectExhibits", "AutoCollectExhibitsDesc", BepinexPlugin.AutoCollectExhibits.Value, delegate(bool s)
			{
				BepinexPlugin.AutoCollectExhibits.Value = s;
			});
			CreateSwitch(((Component)val6).transform, "AutoCollectTools", "AutoCollectToolsDesc", BepinexPlugin.AutoCollectTools.Value, delegate(bool s)
			{
				BepinexPlugin.AutoCollectTools.Value = s;
			});
			CreateSwitch(((Component)val6).transform, "AutoOpenMap", "AutoOpenMapDesc", BepinexPlugin.AutoOpenMap.Value, delegate(bool s)
			{
				BepinexPlugin.AutoOpenMap.Value = s;
			});
			CreateSwitch(((Component)val6).transform, "AutoAdvance", "AutoAdvanceDesc", BepinexPlugin.AutoAdvance.Value, delegate(bool s)
			{
				BepinexPlugin.AutoAdvance.Value = s;
			});
			CreateDropdown(((Component)val6).transform, "QuickStartType", "QuickStartTypeDesc", Enum.GetNames(typeof(QuickStartMode)), CollectionsExtensions.IndexOf<QuickStartMode>((IReadOnlyList<QuickStartMode>)(QuickStartMode[])Enum.GetValues(typeof(QuickStartMode)), BepinexPlugin.QuickStartBehaviour.Value), delegate(int idx)
			{
				BepinexPlugin.QuickStartBehaviour.Value = (QuickStartMode)idx;
			}, small: true);
			Transform transform = ((Component)obj2).transform;
			object obj3 = <>c.<>9__13_6;
			if (obj3 == null)
			{
				UnityAction val7 = delegate
				{
					UI.ConfirmationPopup("ProfileUnlockWarning", delegate
					{
						Profile.UnlockAllForProfile(Singleton<GameMaster>.Instance.CurrentProfile);
						UiManager.GetPanel<MainMenuPanel>().RefreshProfile();
					});
				};
				<>c.<>9__13_6 = val7;
				obj3 = (object)val7;
			}
			CreateButton(transform, "UnlockProfile", "UnlockProfileDesc", (UnityAction)obj3, Singleton<GameMaster>.Instance.CurrentGameRun == null);
			__instance.tabs.Add(val5);
			tabIndex = __instance.tabs.IndexOf(val5);
			dropdownTemplate = null;
			smallDropdownTemplate = null;
			switchTemplate = null;
			sliderTemplate = null;
			buttonTemplate = null;
		}

		[HarmonyPatch(typeof(SettingPanel), "UI_OnTabToggleChanged", new Type[] { typeof(Toggle) })]
		[HarmonyPrefix]
		public static bool OnTabChanged(SettingPanel __instance, Toggle item)
		{
			if ("CompanionConfig" == ((Object)item).name)
			{
				__instance.SwitchToTab(tabIndex);
				return false;
			}
			return true;
		}
	}
	public static class LocalisationKeys
	{
		public const string UIPrefix = "UI.";

		public const string SettingsPrefix = "Setting.";

		public const string MessageDialogPrefix = "MessageDialog.";

		public const string ResetGameButton = "ResetGame";

		public const string QuickStartButton = "QuickStartGame";

		public const string ProfileUnlockButton = "UnlockProfile";

		public const string ProfileUnlockDesc = "UnlockProfileDesc";

		public const string ConfigTabHeader = "CompanionConfig";

		public const string AutoCollectMoney = "AutoCollectMoney";

		public const string AutoCollectMoneyDesc = "AutoCollectMoneyDesc";

		public const string AutoCollectExhibits = "AutoCollectExhibits";

		public const string AutoCollectExhibitsDesc = "AutoCollectExhibitsDesc";

		public const string AutoCollectTools = "AutoCollectTools";

		public const string AutoCollectToolsDesc = "AutoCollectToolsDesc";

		public const string AutoOpenMap = "AutoOpenMap";

		public const string AutoOpenMapDesc = "AutoOpenMapDesc";

		public const string AutoAdvance = "AutoAdvance";

		public const string AutoAdvanceDesc = "AutoAdvanceDesc";

		public const string QuickStartType = "QuickStartType";

		public const string QuickStartTypeDesc = "QuickStartTypeDesc";

		public const string GameResetWarning = "ResetGameWarning";

		public const string ProfileUnlockWarning = "ProfileUnlockWarning";

		public static readonly Dictionary<(Locale, string), string> LocTable = new Dictionary<(Locale, string), string>
		{
			[((Locale)0, "UI.ResetGame")] = "Reset Run",
			[((Locale)0, "UI.QuickStartGame")] = "Quick Start",
			[((Locale)0, "UI.UnlockProfile")] = "Unlock profile",
			[((Locale)0, "UI.CompanionConfig")] = "Companion",
			[((Locale)0, "Setting.AutoCollectMoney")] = "Auto-collect money",
			[((Locale)0, "Setting.AutoCollectExhibits")] = "Auto-collect exhibits",
			[((Locale)0, "Setting.AutoCollectTools")] = "Auto-collect tools",
			[((Locale)0, "Setting.AutoOpenMap")] = "Auto-open map",
			[((Locale)0, "Setting.AutoAdvance")] = "Auto-advance path",
			[((Locale)0, "Setting.QuickStartType")] = "Quick Start mode",
			[((Locale)0, "UI.UnlockProfileDesc")] = "Sets the current profile to unlock level 10, reveals all cards and |Exhibits|.",
			[((Locale)0, "Setting.AutoCollectMoneyDesc")] = "Automatically collect reward money.",
			[((Locale)0, "Setting.AutoCollectExhibitsDesc")] = "Automatically collect most |Exhibits|.\nFurther configurable through white/black lists in the configuration file.",
			[((Locale)0, "Setting.AutoCollectToolsDesc")] = "Automatically collect |Tool| cards (from Ringo or Toolbox).",
			[((Locale)0, "Setting.AutoOpenMapDesc")] = "Automatically open the map when all rewards are collected or an event is finished.",
			[((Locale)0, "Setting.AutoAdvanceDesc")] = "Automatically advance to next node if there is only one available path.",
			[((Locale)0, "Setting.QuickStartTypeDesc")] = "Determines behaviour of the Quick Start button.\n|LastRun| - Quick Start will choose the last picked character and deck.\n|Random| - Quick Start will randomly choose the character and deck.",
			[((Locale)0, "MessageDialog.ResetGameWarning")] = "Reset your current run?",
			[((Locale)0, "MessageDialog.ProfileUnlockWarning")] = "Unlock everything on this profile?",
			[((Locale)1, "UI.ResetGame")] = "rosl",
			[((Locale)1, "UI.QuickStartGame")] = "快速开局",
			[((Locale)1, "UI.UnlockProfile")] = "破解版帐号",
			[((Locale)1, "UI.CompanionConfig")] = "伙伴",
			[((Locale)1, "Setting.AutoCollectMoney")] = "自动抓钱",
			[((Locale)1, "Setting.AutoCollectExhibits")] = "自动抓展品",
			[((Locale)1, "Setting.AutoCollectTools")] = "自动抓道具",
			[((Locale)1, "Setting.AutoOpenMap")] = "自动开启地图",
			[((Locale)1, "Setting.AutoAdvance")] = "自动前进",
			[((Locale)1, "Setting.QuickStartType")] = "快速开局模式",
			[((Locale)1, "UI.UnlockProfileDesc")] = "将帐号等级提升到10,显示所有卡牌和展品。",
			[((Locale)1, "Setting.AutoCollectMoneyDesc")] = "自动拾取金钱",
			[((Locale)1, "Setting.AutoCollectExhibitsDesc")] = "自动拾取大部份|展品|。\n能在设定档添加黑/白名单。",
			[((Locale)1, "Setting.AutoCollectToolsDesc")] = "自动拾取|道具|牌(铃瑚或工具箱)。",
			[((Locale)1, "Setting.AutoOpenMapDesc")] = "当所有奖励或事件结束后自动开启地图",
			[((Locale)1, "Setting.AutoAdvanceDesc")] = "当只有一条能走的路时自动前进。",
			[((Locale)1, "Setting.QuickStartTypeDesc")] = "控制快速开局的模式。\n|上一局| - 快速开局会选择上一局的角色机体。\n|随机| - 快速开局会选择随机角色机体。",
			[((Locale)1, "MessageDialog.ResetGameWarning")] = "确定rosl?",
			[((Locale)1, "MessageDialog.ProfileUnlockWarning")] = "确定破解帐号?",
			[((Locale)2, "UI.ResetGame")] = "rosl",
			[((Locale)2, "UI.QuickStartGame")] = "快速開局",
			[((Locale)2, "UI.UnlockProfile")] = "破解版帳號",
			[((Locale)2, "UI.CompanionConfig")] = "夥伴",
			[((Locale)2, "Setting.AutoCollectMoney")] = "自動抓錢",
			[((Locale)2, "Setting.AutoCollectExhibits")] = "自動抓展品",
			[((Locale)2, "Setting.AutoCollectTools")] = "自動抓道具",
			[((Locale)2, "Setting.AutoOpenMap")] = "自動開啟地圖",
			[((Locale)2, "Setting.AutoAdvance")] = "自動前進",
			[((Locale)2, "Setting.QuickStartType")] = "快速開局模式",
			[((Locale)2, "UI.UnlockProfileDesc")] = "將帳號等級提升到10,顯示所有卡牌和展品。",
			[((Locale)2, "Setting.AutoCollectMoneyDesc")] = "自動拾取金錢",
			[((Locale)2, "Setting.AutoCollectExhibitsDesc")] = "自動拾取大部份|展品|。\n能在設定檔添加黑/白名單。",
			[((Locale)2, "Setting.AutoCollectToolsDesc")] = "自動拾取|道具|牌(鈴瑚或工具箱)。",
			[((Locale)2, "Setting.AutoOpenMapDesc")] = "當所有獎勵或事件結束後自動開啟地圖",
			[((Locale)2, "Setting.AutoAdvanceDesc")] = "當只有一條能走的路時自動前進。",
			[((Locale)2, "Setting.QuickStartTypeDesc")] = "控制快速開局的模式。\n|上一局| - 快速開局會選擇上一局的角色機體。\n|隨機| - 快速開局會選擇隨機角色機    體。",
			[((Locale)2, "MessageDialog.ResetGameWarning")] = "確定rosl?",
			[((Locale)2, "MessageDialog.ProfileUnlockWarning")] = "確定破解帳號?",
			[((Locale)3, "UI.ResetGame")] = "攻略リセット",
			[((Locale)3, "UI.QuickStartGame")] = "クイックスタート",
			[((Locale)3, "UI.UnlockProfile")] = "セーブデータのアンロック",
			[((Locale)3, "UI.CompanionConfig")] = "コンパニオン",
			[((Locale)3, "Setting.AutoCollectMoney")] = "資金力の自動取得",
			[((Locale)3, "Setting.AutoCollectExhibits")] = "展示品の自動取得",
			[((Locale)3, "Setting.AutoCollectTools")] = "道具の自動取得",
			[((Locale)3, "Setting.AutoOpenMap")] = "マップの自動表示",
			[((Locale)3, "Setting.AutoAdvance")] = "自動で進む",
			[((Locale)3, "Setting.QuickStartType")] = "クイックスタートモード",
			[((Locale)3, "UI.UnlockProfileDesc")] = "現在のセーブデータのアンロックレベルを10にし、すべてのカードを|展示品|を収拾済みにします。",
			[((Locale)3, "Setting.AutoCollectMoneyDesc")] = "報酬の資金力を自動で取得します。",
			[((Locale)3, "Setting.AutoCollectExhibitsDesc")] = "ほとんどの|展示品|を自動で取得します。\n設定ファイルのホワイト/ブラックリストでより詳細に設定できます。",
			[((Locale)3, "Setting.AutoCollectToolsDesc")] = "|道具|カードを自動で取得します(鈴瑚または工具箱から)。",
			[((Locale)3, "Setting.AutoOpenMapDesc")] = "すべての報酬を取得したりイベントが終了したりした時、自動でマップを表示します。",
			[((Locale)3, "Setting.AutoAdvanceDesc")] = "一本道の時、自動で次へ進みます。",
			[((Locale)3, "Setting.QuickStartTypeDesc")] = "クイックスタートボタンの挙動を決めます。\n|LastRun|――直前の攻略で選択した主人公とデッキでクイックスタート。\n|Random|――――ランダムな主人公とデッキでクイックスタート。",
			[((Locale)3, "MessageDialog.ResetGameWarning")] = "現在の攻略をリセットしますか?",
			[((Locale)3, "MessageDialog.ProfileUnlockWarning")] = "現在のセーブデータのすべてをアンロックしますか?",
			[((Locale)6, "UI.ResetGame")] = "Resetuj Przejście",
			[((Locale)6, "UI.QuickStartGame")] = "Szybka Gra",
			[((Locale)6, "UI.UnlockProfile")] = "Odblokuj profil",
			[((Locale)6, "UI.CompanionConfig")] = "Towarzysz",
			[((Locale)6, "Setting.AutoCollectMoney")] = "Zbieraj pieniądze",
			[((Locale)6, "Setting.AutoCollectExhibits")] = "Zbieraj eksponaty",
			[((Locale)6, "Setting.AutoCollectTools")] = "Zbieraj narzędzia",
			[((Locale)6, "Setting.AutoOpenMap")] = "Auto-otwieranie mapy",
			[((Locale)6, "Setting.AutoAdvance")] = "Auto-podróż",
			[((Locale)6, "Setting.QuickStartType")] = "Tryb Szybkiej Gry",
			[((Locale)6, "UI.UnlockProfileDesc")] = "Ustawia obecny profil na poziom odblokowania 10, ujawnia wszystkie karty oraz eksponaty.",
			[((Locale)6, "Setting.AutoCollectMoneyDesc")] = "Automatycznie zbieraj pieniądze za walki.",
			[((Locale)6, "Setting.AutoCollectExhibitsDesc")] = "Automatycznie zbieraj większość |Eksponatów| za walki.\nMożliwa konfiguracja białej i czarnej listy eksponatów za pomocą pliku konfiguracyjnego.",
			[((Locale)6, "Setting.AutoCollectToolsDesc")] = "Automatycznie zbieraj karty |Narzędzi| (Ringo, Skrzynka na Narzędzia).",
			[((Locale)6, "Setting.AutoOpenMapDesc")] = "Automatycznie otwieraj mapę kiedy wszystkie nagrody zostaną zebrane lub po zakończeniu wydarzeń.",
			[((Locale)6, "Setting.AutoAdvanceDesc")] = "Automatycznie przechodź do następnego węzła mapy kiedy istnieje tylko jedna ścieżka.",
			[((Locale)6, "Setting.QuickStartTypeDesc")] = "Zmienia zachowanie przycisku Szybkiej Gry.\n|LastRun| - Szybka Gra wybierze postać i talię z ostatniej gry.\n|Random| - Szybka Gra wybierze losową postać i jej talię.",
			[((Locale)6, "MessageDialog.ResetGameWarning")] = "Czy na pewno chcesz zresetować to przejście?",
			[((Locale)6, "MessageDialog.ProfileUnlockWarning")] = "Czy na pewno odblokować wszystko na tym profilu?"
		};
	}
	[HarmonyPatch]
	public class LocalisationPatch
	{
		public static MethodBase TargetMethod()
		{
			return AccessTools.Method((from t in typeof(Localization).GetNestedTypes(AccessTools.allDeclared)
				where t.Name.Contains("<ReloadCommonAsync>")
				select t).Single(), "MoveNext", (Type[])null, (Type[])null);
		}

		public static void PostReloadCommon()
		{
			foreach (var (tuple2, value) in LocalisationKeys.LocTable.Where((KeyValuePair<(Locale, string), string> kvp) => kvp.Key.Item1 == Localization.CurrentLocale))
			{
				Localization.LocalizationTable.Add(tuple2.Item2, value);
			}
		}

		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> AsyncPostfix(IEnumerable<CodeInstruction> instructions, ILGenerator gen)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Expected O, but got Unknown
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Expected O, but got Unknown
			return new CodeMatcher(instructions, gen).End().MatchBack(true, (CodeMatch[])(object)new CodeMatch[8]
			{
				CodeMatch.op_Implicit(new CodeInstruction(OpCodes.Ldarg_0, (object)null)),
				CodeMatch.op_Implicit(new CodeInstruction(OpCodes.Ldc_I4_M1, (object)null)),
				CodeMatch.op_Implicit(new CodeInstruction(OpCodes.Dup, (object)null)),
				CodeMatch.op_Implicit(new CodeInstruction(OpCodes.Stloc_0, (object)null)),
				CodeMatch.op_Implicit(new CodeInstruction(OpCodes.Stfld, (object)null)),
				CodeMatch.op_Implicit(new CodeInstruction(OpCodes.Ldloca_S, (object)null)),
				CodeMatch.op_Implicit(new CodeInstruction(OpCodes.Call, (object)null)),
				CodeMatch.op_Implicit(new CodeInstruction(OpCodes.Leave, (object)null))
			}).Advance(-1)
				.Insert((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(LocalisationPatch), "PostReloadCommon", (Type[])null, (Type[])null))
				})
				.InstructionEnumeration();
		}
	}
	[HarmonyPatch]
	public static class RunQuickstart
	{
		[HarmonyPatch(typeof(GameMaster))]
		public class GameMaster_Patches
		{
			[CompilerGenerated]
			private sealed class <CoPostResetGameRun>d__0 : IEnumerator<object>, IEnumerator, IDisposable
			{
				private int <>1__state;

				private object <>2__current;

				public GameMaster gm;

				object IEnumerator<object>.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				object IEnumerator.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				[DebuggerHidden]
				public <CoPostResetGameRun>d__0(int <>1__state)
				{
					this.<>1__state = <>1__state;
				}

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					//IL_0040: Unknown result type (might be due to invalid IL or missing references)
					//IL_012c: Unknown result type (might be due to invalid IL or missing references)
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						if (gm.CurrentGameRun == null)
						{
							throw new InvalidOperationException("Not in game-run");
						}
						<>2__current = UniTaskExtensions.ToCoroutine(UiManager.ShowLoading(0.5f), (Action<Exception>)null);
						<>1__state = 1;
						return true;
					case 1:
					{
						<>1__state = -1;
						if (gm.CurrentGameRun.Battle != null)
						{
							UiManager.LeaveBattle();
						}
						UiManager.LeaveGameRun();
						gm.CurrentGameRun = null;
						Environment instance = Environment.Instance;
						if ((Object)null != (Object)(object)Environment.CurrentEnvironment)
						{
							instance.ClearEnvironment();
						}
						GameDirector.ClearAll();
						GameMaster.UnloadGameRunUi();
						GC.Collect();
						Resources.UnloadUnusedAssets();
						GameRunSaveData gameSave = GameSave;
						GameSave = null;
						GameRunController val = NewRunFromSave(gameSave);
						if (val != null)
						{
							<>2__current = gm.CoNewGameRun(val);
							<>1__state = 2;
							return true;
						}
						break;
					}
					case 2:
						<>1__state = -1;
						if (gm.CurrentGameRun != null)
						{
							BepinexPlugin.log.LogDebug((object)"gm.CurrentGameRun is not null");
							GameRunController currentGameRun = gm.CurrentGameRun;
							MapNode startNode = currentGameRun.CurrentMap.StartNode;
							gm.PlayMusic(startNode.StationType, currentGameRun.CurrentStage.Level, (string)null, true);
						}
						else
						{
							BepinexPlugin.log.LogDebug((object)"gm.CurrentGameRun is null");
						}
						break;
					}
					return false;
				}

				bool IEnumerator.MoveNext()
				{
					//ILSpy generated this explicit interface implementation from .override directive in MoveNext
					return this.MoveNext();
				}

				[DebuggerHidden]
				void IEnumerator.Reset()
				{
					throw new NotSupportedException();
				}
			}

			[IteratorStateMachine(typeof(<CoPostResetGameRun>d__0))]
			public static IEnumerator CoPostResetGameRun(GameMaster gm)
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <CoPostResetGameRun>d__0(0)
				{
					gm = gm
				};
			}

			[HarmonyPatch("EndGameProcedure")]
			[HarmonyPrefix]
			public static void OnGameEnd()
			{
				if ((Object)null != (Object)(object)SettingPanel_Patches.ResetGameBtn)
				{
					((Selectable)SettingPanel_Patches.ResetGameBtn).interactable = false;
				}
			}

			[HarmonyPatch("LeaveGameRun")]
			[HarmonyPrefix]
			public static bool OnLeaveRun()
			{
				if (HookCoLeave)
				{
					HookCoLeave = false;
					GameMaster instance = Singleton<GameMaster>.Instance;
					GameDirector.StopLoreChat();
					((MonoBehaviour)instance).StopAllCoroutines();
					((MonoBehaviour)instance).StartCoroutine(CoPostResetGameRun(instance));
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(MainMenuPanel))]
		public class MainMenuPanel_Patches
		{
			[Serializable]
			[CompilerGenerated]
			private sealed class <>c
			{
				public static readonly <>c <>9 = new <>c();

				public static Action <>9__4_1;

				public static UnityAction <>9__4_0;

				internal void <PanelAwake>b__4_0()
				{
					UI.ConfirmationPopup("ResetGameWarning", delegate
					{
						ResetGameRun(CoMenuResetGameRun);
					});
				}

				internal void <PanelAwake>b__4_1()
				{
					ResetGameRun(CoMenuResetGameRun);
				}
			}

			[CompilerGenerated]
			private sealed class <>c__DisplayClass3_0
			{
				public GameResultPanel grPanel;

				internal bool <CoMenuResetGameRun>b__0()
				{
					return ((UiBase)grPanel).IsVisible;
				}
			}

			[CompilerGenerated]
			private sealed class <CoMenuResetGameRun>d__3 : IEnumerator<object>, IEnumerator, IDisposable
			{
				private int <>1__state;

				private object <>2__current;

				public GameRunSaveData save;

				object IEnumerator<object>.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				object IEnumerator.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				[DebuggerHidden]
				public <CoMenuResetGameRun>d__3(int <>1__state)
				{
					this.<>1__state = <>1__state;
				}

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					//IL_0046: Unknown result type (might be due to invalid IL or missing references)
					//IL_0050: Expected O, but got Unknown
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
					{
						<>1__state = -1;
						<>c__DisplayClass3_0 CS$<>8__locals0 = new <>c__DisplayClass3_0
						{
							grPanel = UiManager.GetPanel<GameResultPanel>()
						};
						GameMaster.RequestAbandonGameRun(false);
						<>2__current = (object)new WaitWhile((Func<bool>)(() => ((UiBase)CS$<>8__locals0.grPanel).IsVisible));
						<>1__state = 1;
						return true;
					}
					case 1:
					{
						<>1__state = -1;
						GameRunController val = NewRunFromSave(save);
						if (val != null)
						{
							<>2__current = Singleton<GameMaster>.Instance.CoNewGameRun(val);
							<>1__state = 2;
							return true;
						}
						break;
					}
					case 2:
						<>1__state = -1;
						break;
					}
					return false;
				}

				bool IEnumerator.MoveNext()
				{
					//ILSpy generated this explicit interface implementation from .override directive in MoveNext
					return this.MoveNext();
				}

				[DebuggerHidden]
				void IEnumerator.Reset()
				{
					throw new NotSupportedException();
				}
			}

			public static GameObject ResetGameObj;

			public static GameObject QuickStartGameObj;

			private static void QuickStartGameRun()
			{
				GameMaster instance = Singleton<GameMaster>.Instance;
				if (instance.CurrentGameRun != null)
				{
					BepinexPlugin.log.LogError((object)"(QuickStartGameRun) Already in game-run");
					return;
				}
				GameRunController val = NewQuickStartRun();
				if (val != null)
				{
					((MonoBehaviour)instance).StartCoroutine(instance.CoNewGameRun(val));
				}
				else
				{
					GameMaster.ShowErrorDialogWithKey("CorruptedGameRunSaveData");
				}
			}

			[IteratorStateMachine(typeof(<CoMenuResetGameRun>d__3))]
			private static IEnumerator CoMenuResetGameRun(GameRunSaveData save)
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <CoMenuResetGameRun>d__3(0)
				{
					save = save
				};
			}

			[HarmonyPatch("Awake")]
			[HarmonyPostfix]
			public static void PanelAwake(MainMenuPanel __instance)
			{
				//IL_013c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0141: Unknown result type (might be due to invalid IL or missing references)
				//IL_014b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0150: Unknown result type (might be due to invalid IL or missing references)
				//IL_0157: Unknown result type (might be due to invalid IL or missing references)
				//IL_015c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0166: Unknown result type (might be due to invalid IL or missing references)
				//IL_016b: Unknown result type (might be due to invalid IL or missing references)
				//IL_017d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0187: Expected O, but got Unknown
				//IL_005a: Unknown result type (might be due to invalid IL or missing references)
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				//IL_0068: Unknown result type (might be due to invalid IL or missing references)
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_007c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0081: Unknown result type (might be due to invalid IL or missing references)
				//IL_008e: 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_009d: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00eb: Expected O, but got Unknown
				Transform transform = ((Component)__instance.mainMenuButtonGroup).transform;
				if ((Object)null == (Object)(object)transform.Find("ResetGame"))
				{
					GameObject gameObject = ((Component)__instance.restoreGameButton).gameObject;
					Transform[] componentsInChildren = ((Component)transform).GetComponentsInChildren<Transform>(true);
					foreach (Transform val in componentsInChildren)
					{
						RectTransform component = ((Component)val).GetComponent<RectTransform>();
						if (!((Object)null != (Object)(object)component))
						{
							continue;
						}
						Vector2 offsetMin = component.offsetMin;
						Vector2 offsetMax = component.offsetMax;
						component.offsetMin += Vector2.up * 120f;
						component.offsetMax += Vector2.up * 120f;
						if (!(((Object)val).name == ((Object)gameObject).name))
						{
							continue;
						}
						object obj = <>c.<>9__4_0;
						if (obj == null)
						{
							UnityAction val2 = delegate
							{
								UI.ConfirmationPopup("ResetGameWarning", delegate
								{
									ResetGameRun(CoMenuResetGameRun);
								});
							};
							<>c.<>9__4_0 = val2;
							obj = (object)val2;
						}
						ResetGameObj = CreateButton(gameObject, transform, offsetMin, offsetMax, "ResetGame", positionBeforeOrig: false, (UnityAction)obj);
						break;
					}
				}
				if ((Object)null == (Object)(object)transform.Find("QuickStartGame"))
				{
					GameObject gameObject2 = ((Component)__instance.newGameButton).gameObject;
					RectTransform component2 = gameObject2.GetComponent<RectTransform>();
					if ((Object)null != (Object)(object)component2)
					{
						QuickStartGameObj = CreateButton(gameObject2, transform, component2.offsetMin + Vector2.up * 120f, component2.offsetMax + Vector2.up * 120f, "QuickStartGame", positionBeforeOrig: true, new UnityAction(QuickStartGameRun));
					}
				}
			}

			[HarmonyPatch("RefreshProfile")]
			[HarmonyPostfix]
			public static void PanelShow(MainMenuPanel __instance)
			{
				bool flag = Singleton<GameMaster>.Instance.GameRunSaveData != null;
				GameObject resetGameObj = ResetGameObj;
				if (resetGameObj != null)
				{
					resetGameObj.SetActive(flag);
				}
				GameObject quickStartGameObj = QuickStartGameObj;
				if (quickStartGameObj != null)
				{
					quickStartGameObj.SetActive(!flag);
				}
			}
		}

		[HarmonyPatch(typeof(SettingPanel))]
		public class SettingPanel_Patches
		{
			[Serializable]
			[CompilerGenerated]
			private sealed class <>c
			{
				public static readonly <>c <>9 = new <>c();

				public static Action <>9__2_1;

				public static UnityAction <>9__2_0;

				internal void <PanelAwake>b__2_0()
				{
					UI.ConfirmationPopup("ResetGameWarning", delegate
					{
						ResetGameRun(CoMidRunResetGameRun);
					});
				}

				internal void <PanelAwake>b__2_1()
				{
					ResetGameRun(CoMidRunResetGameRun);
				}
			}

			[CompilerGenerated]
			private sealed class <>c__DisplayClass1_0
			{
				public GameResultPanel grPanel;

				internal bool <CoMidRunResetGameRun>b__0()
				{
					return ((UiBase)grPanel).IsVisible;
				}
			}

			[CompilerGenerated]
			private sealed class <CoMidRunResetGameRun>d__1 : IEnumerator<object>, IEnumerator, IDisposable
			{
				private int <>1__state;

				private object <>2__current;

				public GameRunSaveData save;

				object IEnumerator<object>.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				object IEnumerator.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				[DebuggerHidden]
				public <CoMidRunResetGameRun>d__1(int <>1__state)
				{
					this.<>1__state = <>1__state;
				}

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
					//IL_01f4: Expected O, but got Unknown
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
					{
						<>1__state = -1;
						<>c__DisplayClass1_0 CS$<>8__locals0 = new <>c__DisplayClass1_0
						{
							grPanel = UiManager.GetPanel<GameResultPanel>()
						};
						GameMaster instance = Singleton<GameMaster>.Instance;
						GameDirector instance2 = Singleton<GameDirector>.Instance;
						GameRunController currentGameRun = instance.CurrentGameRun;
						GameSave = save;
						HookCoLeave = true;
						((MonoBehaviour)instance).StopAllCoroutines();
						((Unit)currentGameRun.Player).Hp = 0;
						((Unit)currentGameRun.Player).Status = (UnitStatus)2;
						currentGameRun.Status = (GameRunStatus)3;
						currentGameRun.GenerateRecords(false, (EnemyGroup)null, (Adventure)null);
						BattleController battle = currentGameRun.Battle;
						if (battle != null)
						{
							currentGameRun.LeaveBattle(battle.EnemyGroup);
							UiManager.LeaveBattle();
							instance2.LeaveBattle(battle);
						}
						GameDirector.ClearDoremyEnvironment();
						((Component)UiManager.GetPanel<BattleManaPanel>()).gameObject.SetActive(false);
						((Component)UiManager.GetPanel<BossExhibitPanel>()).gameObject.SetActive(false);
						((Component)UiManager.GetPanel<CardDetailPanel>()).gameObject.SetActive(false);
						((Component)UiManager.GetPanel<ExhibitInfoPanel>()).gameObject.SetActive(false);
						((Component)UiManager.GetPanel<GapOptionsPanel>()).gameObject.SetActive(false);
						((Component)UiManager.GetPanel<HintPanel>()).gameObject.SetActive(false);
						((Component)UiManager.GetPanel<MapPanel>()).gameObject.SetActive(false);
						((Component)UiManager.GetPanel<NazrinDetectPanel>()).gameObject.SetActive(false);
						((Component)UiManager.GetPanel<PlayBoard>()).gameObject.SetActive(false);
						((Component)UiManager.GetPanel<PopupHud>()).gameObject.SetActive(false);
						((Component)UiManager.GetPanel<RewardPanel>()).gameObject.SetActive(false);
						((Component)UiManager.GetPanel<SelectCardPanel>()).gameObject.SetActive(false);
						((Component)UiManager.GetPanel<ShopPanel>()).gameObject.SetActive(false);
						((Component)UiManager.GetPanel<ShowCardsPanel>()).gameObject.SetActive(false);
						((Component)UiManager.GetPanel<SettingPanel>()).gameObject.SetActive(false);
						((Behaviour)UiManager.GetPanel<SystemBoard>().mapButton).enabled = false;
						((Component)UiManager.GetPanel<SpellPanel>()).gameObject.SetActive(false);
						((Component)UiManager.GetPanel<UltimateSkillPanel>()).gameObject.SetActive(false);
						((Component)UiManager.GetPanel<VnPanel>()).gameObject.SetActive(false);
						GameMaster.EndGameProcedure(currentGameRun);
						<>2__current = (object)new WaitWhile((Func<bool>)(() => ((UiBase)CS$<>8__locals0.grPanel).IsVisible));
						<>1__state = 1;
						return true;
					}
					case 1:
						<>1__state = -1;
						return false;
					}
				}

				bool IEnumerator.MoveNext()
				{
					//ILSpy generated this explicit interface implementation from .override directive in MoveNext
					return this.MoveNext();
				}

				[DebuggerHidden]
				void IEnumerator.Reset()
				{
					throw new NotSupportedException();
				}
			}

			public static Button ResetGameBtn;

			[IteratorStateMachine(typeof(<CoMidRunResetGameRun>d__1))]
			private static IEnumerator CoMidRunResetGameRun(GameRunSaveData save)
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <CoMidRunResetGameRun>d__1(0)
				{
					save = save
				};
			}

			[HarmonyPatch("Awake")]
			[HarmonyPostfix]
			public static void PanelAwake(SettingPanel __instance)
			{
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_006b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0071: Expected O, but got Unknown
				Transform transform = __instance.inGameGroup.gameObject.transform;
				if (!((Object)null == (Object)(object)transform.Find("ResetGame")))
				{
					return;
				}
				GameObject obj = Object.Instantiate<GameObject>(((Component)__instance.reenterStationButton).gameObject, transform);
				((Object)obj).name = "ResetGame";
				obj.transform.SetSiblingIndex(2);
				object obj2 = <>c.<>9__2_0;
				if (obj2 == null)
				{
					UnityAction val = delegate
					{
						UI.ConfirmationPopup("ResetGameWarning", delegate
						{
							ResetGameRun(CoMidRunResetGameRun);
						});
					};
					<>c.<>9__2_0 = val;
					obj2 = (object)val;
				}
				PostCreateButton(obj, "ResetGame", (UnityAction)obj2);
				ResetGameBtn = obj.GetComponent<Button>();
			}
		}

		private static bool HookCoLeave;

		private static GameRunSaveData GameSave;

		private static GameObject CreateButton(GameObject orig, Transform parent, Vector2 rtfOffMin, Vector2 rtfOffMax, string key, bool positionBeforeOrig, UnityAction call)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = Object.Instantiate<GameObject>(orig, parent);
			((Object)obj).name = key;
			obj.transform.SetSiblingIndex(orig.transform.GetSiblingIndex() + ((!positionBeforeOrig) ? 1 : 0));
			RectTransform component = ((Component)obj.transform).GetComponent<RectTransform>();
			if ((Object)null != (Object)(object)component)
			{
				component.offsetMin = rtfOffMin;
				component.offsetMax = rtfOffMax;
			}
			PostCreateButton(obj, key, call);
			return obj;
		}

		private static void PostCreateButton(GameObject btnObj, string key, UnityAction call)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			Button component = btnObj.GetComponent<Button>();
			component.onClick = new ButtonClickedEvent();
			((UnityEvent)component.onClick).AddListener(call);
			LocalizedText componentInChildren = btnObj.GetComponentInChildren<LocalizedText>();
			componentInChildren.key = "UI." + key;
			componentInChildren.OnLocaleChanged();
		}

		private static IEnumerable<(string, string)> EnumerateLoadouts()
		{
			HashSet<(string, string)> hashSet = (from ply in Library.GetSelectablePlayers()
				where ply.Config.UnlockLevel.HasValue
				select ply).SelectMany((PlayerUnit ply) => new HashSet<(string, string)>
			{
				(((GameEntity)ply).Id, ply.Config.UltimateSkillA),
				(((GameEntity)ply).Id, ply.Config.UltimateSkillB)
			}).ToHashSet();
			if (BepinexPlugin.SideloaderAvailable)
			{
				hashSet.UnionWith(SideloaderWrapper.EnumerateLoadouts());
			}
			return hashSet;
		}

		private static bool TryCreateLoadout(string playerName, string usId, out PlayerUnit ply, out PlayerType plyType, out Exhibit startingExhibit, out IEnumerable<Card> startingDeck)
		{
			ply = null;
			plyType = (PlayerType)0;
			startingExhibit = null;
			startingDeck = null;
			PlayerUnit val = (from p in Library.GetSelectablePlayers()
				where ((GameEntity)p).Id == playerName
				select p).FirstOrDefault();
			if (val == null)
			{
				BepinexPlugin.log.LogError((object)("(RunQuickstart.TryCreateLoadout) could not create loadout: unknown player " + playerName));
				return false;
			}
			PlayerUnitConfig config = val.Config;
			ply = Library.CreatePlayerUnit(((object)val).GetType());
			UltimateSkill ultimateSkill = null;
			bool flag = config.UltimateSkillA == usId;
			bool flag2 = config.UltimateSkillB == usId;
			if (!flag && !flag2)
			{
				if (!BepinexPlugin.SideloaderAvailable || !SideloaderWrapper.TryGetLoadout(playerName, usId, out ultimateSkill, out startingExhibit, out startingDeck))
				{
					BepinexPlugin.log.LogError((object)("(RunQuickstart.TryCreateLoadout) loadout for " + playerName + " with Us " + usId + " not found"));
					return false;
				}
			}
			else
			{
				plyType = (PlayerType)((!flag) ? 1 : 0);
				ultimateSkill = Library.CreateUs(flag ? config.UltimateSkillA : config.UltimateSkillB);
				startingExhibit = Library.CreateExhibit(flag ? config.ExhibitA : config.ExhibitB);
				startingDeck = (flag ? config.DeckA : config.DeckB).Select((string c) => Library.CreateCard(c));
			}
			ply.SetUs(ultimateSkill);
			return true;
		}

		private static GameRunController NewQuickStartRun()
		{
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Expected O, but got Unknown
			if (!Profile.TryGetLastRunInHistory(out var record))
			{
				BepinexPlugin.log.LogError((object)"(RunQuickstart.NewQuickStartRun) could not start game run - could not get last run from profile");
				UiManager.GetPanel<MainMenuPanel>().RefreshProfile();
				return null;
			}
			try
			{
				string playerName = record.Player;
				string usId = record.Us;
				QuickStartMode value = BepinexPlugin.QuickStartBehaviour.Value;
				if (value != 0 && value == QuickStartMode.Random)
				{
					List<(string, string)> list = EnumerateLoadouts().ToList();
					Random random = new Random();
					(playerName, usId) = list[random.Next(0, list.Count)];
				}
				if (!TryCreateLoadout(playerName, usId, out var ply, out var plyType, out var startingExhibit, out var startingDeck))
				{
					BepinexPlugin.log.LogError((object)"(RunQuickstart.NewQuickStartRun) could not start game run - loadout creation failed");
					UiManager.GetPanel<MainMenuPanel>().RefreshProfile();
					return null;
				}
				GameMaster instance = Singleton<GameMaster>.Instance;
				ProfileSaveData currentProfile = instance.CurrentProfile;
				if (currentProfile == null)
				{
					BepinexPlugin.log.LogError((object)"(RunQuickstart.NewQuickStartRun) could not start game run - no profile selected");
					UiManager.GetPanel<MainMenuPanel>().RefreshProfile();
					return null;
				}
				StartGameData defaultMode = MainMenuPanel.DefaultMode;
				return GameRunController.Create(new GameRunStartupParameters
				{
					Mode = (GameMode)1,
					ShowRandomResult = GameMaster.DefaultShowRandomResult,
					Seed = null,
					Difficulty = record.Difficulty,
					Puzzles = record.Puzzles,
					Player = ply,
					PlayerType = plyType,
					InitExhibit = startingExhibit,
					InitMoneyOverride = null,
					Deck = startingDeck,
					Stages = defaultMode.StagesCreateFunc(),
					DebutAdventureType = defaultMode.DebutAdventure,
					UserProfile = currentProfile,
					UnlockLevel = instance.CurrentProfileLevel,
					JadeBoxes = new List<JadeBox>()
				});
			}
			catch (Exception arg)
			{
				BepinexPlugin.log.LogError((object)$"(RunQuickstart.NewQuickStartRun) could not start game run:\n{arg}");
				UiManager.GetPanel<MainMenuPanel>().RefreshProfile();
				return null;
			}
		}

		private static GameRunController NewRunFromSave(GameRunSaveData save)
		{
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Expected O, but got Unknown
			string name = save.Player.Name;
			string us = save.Player.Us;
			try
			{
				if (!TryCreateLoadout(name, us, out var ply, out var plyType, out var startingExhibit, out var startingDeck))
				{
					BepinexPlugin.log.LogError((object)"(RunQuickstart.NewRunFromSave) could not start game run - loadout creation failed");
					UiManager.GetPanel<MainMenuPanel>().RefreshProfile();
					return null;
				}
				IEnumerable<JadeBox> jadeBoxes = save.JadeBoxes.Select((JadeBoxSaveData j) => Library.CreateJadeBox(j.Name));
				ulong? seed = null;
				if (!save.IsAutoSeed)
				{
					seed = save.RootSeed;
				}
				StartGameData defaultMode = MainMenuPanel.DefaultMode;
				GameMaster instance = Singleton<GameMaster>.Instance;
				ProfileSaveData currentProfile = instance.CurrentProfile;
				if (currentProfile == null)
				{
					BepinexPlugin.log.LogError((object)"(RunQuickstart.NewRunFromSave) could not start game run - no profile selected");
					UiManager.GetPanel<MainMenuPanel>().RefreshProfile();
					return null;
				}
				return GameRunController.Create(new GameRunStartupParameters
				{
					Mode = save.Mode,
					ShowRandomResult = save.ShowRandomResult,
					Seed = seed,
					Difficulty = save.Difficulty,
					Puzzles = save.Puzzles,
					Player = ply,
					PlayerType = plyType,
					InitExhibit = startingExhibit,
					InitMoneyOverride = null,
					Deck = startingDeck,
					Stages = defaultMode.StagesCreateFunc(),
					DebutAdventureType = defaultMode.DebutAdventure,
					UserProfile = currentProfile,
					UnlockLevel = instance.CurrentProfileLevel,
					JadeBoxes = jadeBoxes
				});
			}
			catch (Exception arg)
			{
				BepinexPlugin.log.LogError((object)$"(RunQuickstart.NewRunFromSave) could not start game run:\n{arg}");
				UiManager.GetPanel<MainMenuPanel>().RefreshProfile();
				return null;
			}
		}

		private static void ResetGameRun(Func<GameRunSaveData, IEnumerator> coro)
		{
			GameMaster instance = Singleton<GameMaster>.Instance;
			GameRunSaveData gameRunSaveData = instance.GameRunSaveData;
			if (gameRunSaveData != null)
			{
				((MonoBehaviour)instance).StartCoroutine(coro(gameRunSaveData));
			}
			else
			{
				GameMaster.ShowErrorDialogWithKey("CorruptedGameRunSaveData");
			}
		}
	}
	[HarmonyPatch(typeof(StartGamePanel))]
	public static class StartGameUI
	{
		[HarmonyPatch("RefreshConfirm")]
		[HarmonyPostfix]
		public static void UnlockCharacter(StartGamePanel __instance)
		{
			if (__instance._playerIndex >= 0 && __instance._playerIndex <= __instance._players.Count && __instance._players[__instance._playerIndex].Config.UnlockLevel.HasValue)
			{
				__instance.characterHintRoot.gameObject.SetActive(false);
				((TMP_Text)__instance.characterHint).text = "";
				((Selectable)__instance.characterConfirmButton).interactable = true;
			}
		}

		[HarmonyPatch("RefreshDifficultyConfirm")]
		[HarmonyPostfix]
		public static void UnlockDifficulty(StartGamePanel __instance)
		{
			if (!__instance.gameModeSwitch.IsOn)
			{
				__instance.difficultyGroups[__instance._difficultyIndex].SetLocked(false);
				__instance._isDifficultyLock = false;
				((Selectable)__instance.difficultyConfirmButton).interactable = true;
				__instance._confirmTooltip.SetDirect("", (string)null);
			}
		}

		[HarmonyPatch("SetPuzzleStatus")]
		[HarmonyPostfix]
		public static void UnlockRequests(StartGamePanel __instance)
		{
			for (int i = 0; i < PuzzleFlags.AllPuzzleFlags.Count; i++)
			{
				foreach (PuzzleToggleWidget value in __instance._puzzleToggles.Values)
				{
					value.IsLock = false;
				}
			}
			__instance.puzzleSelectAllGroup.SetActive(true);
		}

		[HarmonyPatch("SetJadeBoxStatus")]
		[HarmonyPostfix]
		public static void UnlockJadeboxes(StartGamePanel __instance)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			((Selectable)__instance.jadeBoxButton).interactable = true;
			((Behaviour)__instance._jadeBoxTooltip).enabled = false;
			((Component)__instance.jadeBoxLockImage).gameObject.SetActive(false);
			((Graphic)__instance.jadeBoxText).color = Color.white;
		}
	}
}
namespace Companion.Config
{
	public enum QuickStartMode
	{
		LastRun,
		Random
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}