Decompiled source of KCMLoadouts v1.0.0

KCMLoadouts.dll

Decompiled 6 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using DiskCardGame;
using GBC;
using HarmonyLib;
using InscryptionAPI.Ascension;
using InscryptionAPI.Guid;
using InscryptionAPI.Helpers;
using InscryptionAPI.Helpers.Extensions;
using InscryptionAPI.Regions;
using Microsoft.CodeAnalysis;
using Sirenix.Utilities;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("KCMLoadouts")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Placeholder description")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("KCMLoadouts")]
[assembly: AssemblyTitle("KCMLoadouts")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class IsUnmanagedAttribute : Attribute
	{
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 KCMLoadouts
{
	public class LoadoutInfo
	{
		public string name;

		public string highPriorityItem;

		public string lowPriorityItem;

		public string specialItem;

		public Texture2D icon;

		public int unlockLevel;

		public string currentTotemTop;

		public string currentTotemBottom;

		public List<string> collectedTotemTops;

		public List<string> collectedTotemBottoms;

		public List<string> bonusCards;

		public List<string> penaltyBonusCards;

		public string firstNode;

		public string penaltyFirstNode;

		public int teeth;

		public string startingRegion;

		public List<string> boons;
	}
	public static class LoadoutManager
	{
		private static List<LoadoutInfo> allLoadouts = new List<LoadoutInfo>();

		public static List<LoadoutInfo> AllLoadouts
		{
			get
			{
				List<LoadoutInfo> list = new List<LoadoutInfo>();
				foreach (LoadoutInfo allLoadout in allLoadouts)
				{
					list.Add(allLoadout);
				}
				return list;
			}
		}

		public static LoadoutInfo AddLoadout(string name, Texture2D icon, int unlockLevel = 0, string lowPriorityItem = "", string highPriorityItem = "", string specialItem = "", List<string> bonusCards = null, List<string> penaltyBonusCards = null, string firstNode = "", string penaltyFirstNode = "", string startingRegion = "", List<string> collectedTotemTops = null, List<string> collectedTotemBottoms = null, string currentTotemTop = "", string currentTotemBottom = "", int teeth = 0, List<string> boons = null)
		{
			LoadoutInfo loadoutInfo = new LoadoutInfo();
			loadoutInfo.name = name;
			loadoutInfo.lowPriorityItem = lowPriorityItem;
			loadoutInfo.highPriorityItem = highPriorityItem;
			loadoutInfo.specialItem = specialItem;
			loadoutInfo.icon = icon;
			loadoutInfo.unlockLevel = unlockLevel;
			loadoutInfo.currentTotemTop = currentTotemTop;
			loadoutInfo.currentTotemBottom = currentTotemBottom;
			if (collectedTotemTops != null)
			{
				loadoutInfo.collectedTotemTops = collectedTotemTops;
			}
			else
			{
				loadoutInfo.collectedTotemTops = new List<string>();
			}
			if (collectedTotemBottoms != null)
			{
				loadoutInfo.collectedTotemBottoms = collectedTotemBottoms;
			}
			else
			{
				loadoutInfo.collectedTotemBottoms = new List<string>();
			}
			if (bonusCards != null)
			{
				loadoutInfo.bonusCards = bonusCards;
			}
			else
			{
				loadoutInfo.bonusCards = new List<string>();
			}
			if (penaltyBonusCards != null)
			{
				loadoutInfo.penaltyBonusCards = penaltyBonusCards;
			}
			else
			{
				loadoutInfo.penaltyBonusCards = new List<string>();
			}
			loadoutInfo.firstNode = firstNode;
			loadoutInfo.penaltyFirstNode = penaltyFirstNode;
			loadoutInfo.teeth = teeth;
			loadoutInfo.startingRegion = startingRegion;
			if (boons != null)
			{
				loadoutInfo.boons = boons;
			}
			else
			{
				loadoutInfo.boons = new List<string>();
			}
			allLoadouts.Add(loadoutInfo);
			return loadoutInfo;
		}
	}
	[BepInPlugin("tvflabs.inscryption.KCMLoadouts", "KCMLoadouts", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		[Serializable]
		private class JsonLoadout
		{
			public string loadoutName = "";

			public string iconPath = "";

			public int unlockLevel = 0;

			public string lowPriorityItem = "";

			public string highPriorityItem = "";

			public string specialItem = "";

			public string currentTotemTop = "";

			public string currentTotemBottom = "";

			public List<string> collectedTotemTops = new List<string>();

			public List<string> collectedTotemBottoms = new List<string>();

			public List<string> bonusCards = new List<string>();

			public List<string> penaltyBonusCards = new List<string>();

			public string firstNode = "";

			public string penaltyFirstNode = "";

			public int teeth = 0;

			public string startingRegion = "";

			public List<string> boons = new List<string>();
		}

		[HarmonyPatch(typeof(AscensionSaveData), "NewRun")]
		private class AscensionSaveData_NewRun_Patch
		{
			private static void Postfix(List<CardInfo> starterDeck, AscensionSaveData __instance)
			{
				//IL_030c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0359: Unknown result type (might be due to invalid IL or missing references)
				//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_03bb: Expected O, but got Unknown
				//IL_03c7: 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)
				//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
				//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
				//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
				//IL_0406: Unknown result type (might be due to invalid IL or missing references)
				//IL_0440: Unknown result type (might be due to invalid IL or missing references)
				//IL_0427: Unknown result type (might be due to invalid IL or missing references)
				//IL_0461: Unknown result type (might be due to invalid IL or missing references)
				//IL_05c7: Unknown result type (might be due to invalid IL or missing references)
				if (currentLoadout == null)
				{
					return;
				}
				__instance.currentRun.consumables.Clear();
				if (!Utility.IsNullOrWhiteSpace(currentLoadout.highPriorityItem))
				{
					__instance.currentRun.consumables.Add(currentLoadout.highPriorityItem);
				}
				if (__instance.GetNumChallengesOfTypeActive((AscensionChallenge)4) < 2 && !Utility.IsNullOrWhiteSpace(currentLoadout.lowPriorityItem))
				{
					__instance.currentRun.consumables.Add(currentLoadout.lowPriorityItem);
				}
				if (!__instance.ChallengeIsActive((AscensionChallenge)14) && !Utility.IsNullOrWhiteSpace(currentLoadout.specialItem))
				{
					if (__instance.currentRun.consumables.Count == __instance.currentRun.MaxConsumables)
					{
						__instance.currentRun.consumables.RemoveAt(__instance.currentRun.consumables.Count - 1);
					}
					__instance.currentRun.consumables.Add(currentLoadout.specialItem);
				}
				((CardCollectionInfo)__instance.currentRun.playerDeck).cardIds.Remove(((Object)((CardCollectionInfo)__instance.currentRun.playerDeck).Cards[((CardCollectionInfo)__instance.currentRun.playerDeck).Cards.Count - 1]).name);
				((CardCollectionInfo)__instance.currentRun.playerDeck).cardIds.Remove(((Object)((CardCollectionInfo)__instance.currentRun.playerDeck).Cards[((CardCollectionInfo)__instance.currentRun.playerDeck).Cards.Count - 2]).name);
				((CardCollectionInfo)__instance.currentRun.playerDeck).Cards.RemoveAt(((CardCollectionInfo)__instance.currentRun.playerDeck).Cards.Count - 1);
				((CardCollectionInfo)__instance.currentRun.playerDeck).Cards.RemoveAt(((CardCollectionInfo)__instance.currentRun.playerDeck).Cards.Count - 2);
				List<string> list = new List<string>();
				for (int i = 0; i < currentLoadout.bonusCards.Count; i++)
				{
					list.Add(currentLoadout.bonusCards[i]);
				}
				for (int j = 0; j < currentLoadout.penaltyBonusCards.Count && j < list.Count && j < __instance.numRunsSinceReachedFirstBoss; j++)
				{
					list[j] = currentLoadout.penaltyBonusCards[j];
				}
				foreach (string item2 in list)
				{
					((CardCollectionInfo)__instance.currentRun.playerDeck).AddCard(CardLoader.GetCardByName(item2));
				}
				for (int k = 0; k < currentLoadout.collectedTotemTops.Count; k++)
				{
					__instance.currentRun.totemTops.Add(Plugin.GetEnumValueFromString<Tribe>(currentLoadout.collectedTotemTops[k]));
				}
				for (int l = 0; l < currentLoadout.collectedTotemBottoms.Count; l++)
				{
					__instance.currentRun.totemBottoms.Add(Plugin.GetEnumValueFromString<Ability>(currentLoadout.collectedTotemBottoms[l]));
				}
				if (!Utility.IsNullOrWhiteSpace(currentLoadout.currentTotemTop) && !Utility.IsNullOrWhiteSpace(currentLoadout.currentTotemBottom))
				{
					TotemDefinition val = new TotemDefinition();
					val.tribe = Plugin.GetEnumValueFromString<Tribe>(currentLoadout.currentTotemTop);
					MonoBehaviour.print((object)val.tribe);
					val.ability = Plugin.GetEnumValueFromString<Ability>(currentLoadout.currentTotemBottom);
					if (!__instance.currentRun.totemTops.Contains(val.tribe))
					{
						__instance.currentRun.totemTops.Add(val.tribe);
					}
					if (!__instance.currentRun.totemBottoms.Contains(val.ability))
					{
						__instance.currentRun.totemBottoms.Add(val.ability);
					}
					__instance.currentRun.totems.Add(val);
				}
				__instance.currentRun.currency = currentLoadout.teeth;
				if (!StringExtensions.IsNullOrWhitespace(currentLoadout.startingRegion))
				{
					int num = RegionManager.AllRegionsCopy.FindIndex((RegionData region) => ((Object)region).name == currentLoadout.startingRegion);
					List<int> list2 = new List<int>();
					int[] regionOrder = __instance.currentRun.regionOrder;
					foreach (int item in regionOrder)
					{
						list2.Add(item);
					}
					if (list2.Contains(num))
					{
						list2.Remove(num);
						list2.Add(0);
						list2[2] = list2[1];
						list2[1] = list2[0];
					}
					list2[0] = num;
					__instance.currentRun.regionOrder = new int[3]
					{
						list2[0],
						list2[1],
						list2[2]
					};
				}
				foreach (string boon in currentLoadout.boons)
				{
					__instance.currentRun.playerDeck.AddBoon(Plugin.GetEnumValueFromString<Type>(boon));
				}
			}
		}

		[HarmonyPatch(typeof(MapGenerator), "ForceFirstNodeTraderForAscension")]
		private class MapGenerator_ForceFirstNodeTraderForAscension_Patch
		{
			private static void Postfix(int rowIndex, MapGenerator __instance, ref bool __result)
			{
				if (SaveFile.IsAscension && rowIndex == 1 && RunState.Run.regionTier == 0)
				{
					string text = currentLoadout.firstNode;
					if (AscensionSaveData.Data.numRunsSinceReachedFirstBoss >= 2)
					{
						text = currentLoadout.penaltyFirstNode;
					}
					__result = !Utility.IsNullOrWhiteSpace(text);
				}
			}
		}

		[HarmonyPatch(typeof(MapGenerator), "CreateNode")]
		private class MapGenerator_CreateNode_Patch
		{
			private static void Postfix(int x, int y, List<NodeData> nodesInRow, List<NodeData> previousNodes, int mapLength, MapGenerator __instance, ref NodeData __result)
			{
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0075: Expected O, but got Unknown
				//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b2: Expected O, but got Unknown
				//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ef: Expected O, but got Unknown
				//IL_0107: Unknown result type (might be due to invalid IL or missing references)
				//IL_010d: Expected O, but got Unknown
				//IL_0125: Unknown result type (might be due to invalid IL or missing references)
				//IL_012b: Expected O, but got Unknown
				//IL_0143: Unknown result type (might be due to invalid IL or missing references)
				//IL_0149: Expected O, but got Unknown
				//IL_0150: Unknown result type (might be due to invalid IL or missing references)
				//IL_016d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0173: Expected O, but got Unknown
				//IL_017a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0197: Unknown result type (might be due to invalid IL or missing references)
				//IL_019d: Expected O, but got Unknown
				//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c7: Expected O, but got Unknown
				//IL_01df: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e5: Expected O, but got Unknown
				//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0203: Expected O, but got Unknown
				//IL_0218: Unknown result type (might be due to invalid IL or missing references)
				//IL_021e: Expected O, but got Unknown
				//IL_0233: Unknown result type (might be due to invalid IL or missing references)
				//IL_0239: Expected O, but got Unknown
				//IL_024e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0254: Expected O, but got Unknown
				//IL_0269: Unknown result type (might be due to invalid IL or missing references)
				//IL_026f: Expected O, but got Unknown
				if (!MapGenerator.ForceFirstNodeTraderForAscension(y))
				{
					return;
				}
				string text = currentLoadout.firstNode;
				if (AscensionSaveData.Data.numRunsSinceReachedFirstBoss >= 2)
				{
					text = currentLoadout.penaltyFirstNode;
				}
				NodeData val = null;
				if (text == "TotemBattle" || (text == "CardBattle" && AscensionSaveData.Data.ChallengeIsActive((AscensionChallenge)1)))
				{
					val = (NodeData)new TotemBattleNodeData();
					((CardBattleNodeData)((val is TotemBattleNodeData) ? val : null)).difficulty = RunState.Run.regionTier * 6 + (y + 1) / 3 - 1;
				}
				else
				{
					switch (text)
					{
					case "CardBattle":
						val = (NodeData)new CardBattleNodeData();
						((CardBattleNodeData)((val is CardBattleNodeData) ? val : null)).difficulty = RunState.Run.regionTier * 6 + (y + 1) / 3 - 1;
						break;
					case "BuyPelts":
						val = (NodeData)new BuyPeltsNodeData();
						break;
					case "TradePelts":
						val = (NodeData)new TradePeltsNodeData();
						break;
					case "DeckTrial":
						val = (NodeData)new DeckTrialNodeData();
						break;
					case "RandomCardChoices":
						val = (NodeData)new CardChoicesNodeData();
						((CardChoicesNodeData)((val is CardChoicesNodeData) ? val : null)).choicesType = (CardChoicesType)0;
						break;
					case "CostCardChoices":
						val = (NodeData)new CardChoicesNodeData();
						((CardChoicesNodeData)((val is CardChoicesNodeData) ? val : null)).choicesType = (CardChoicesType)1;
						break;
					case "TribeCardChoices":
						val = (NodeData)new CardChoicesNodeData();
						((CardChoicesNodeData)((val is CardChoicesNodeData) ? val : null)).choicesType = (CardChoicesType)2;
						break;
					case "CardMerge":
						val = (NodeData)new CardMergeNodeData();
						break;
					case "GainConsumables":
						val = (NodeData)new GainConsumablesNodeData();
						break;
					case "BuildTotem":
						val = (NodeData)new BuildTotemNodeData();
						break;
					case "DuplicateMerge":
						val = (NodeData)new DuplicateMergeNodeData();
						break;
					case "CardRemove":
						val = (NodeData)new CardRemoveNodeData();
						break;
					case "CardStatBoost":
						val = (NodeData)new CardStatBoostNodeData();
						break;
					case "CopyCard":
						val = (NodeData)new CopyCardNodeData();
						break;
					}
				}
				val.gridX = __result.gridX;
				val.gridY = __result.gridY;
				((MapElementData)val).id = ((MapElementData)__result).id;
				__result = val;
			}
		}

		[AscensionScreenSort(/*Could not decode attribute arguments.*/)]
		private class SelectLoadoutScreen : AscensionRunSetupScreenBase
		{
			private List<LoadoutIcon> loadoutIcons = new List<LoadoutIcon>();

			private int pageIndex = 0;

			private List<PixelText> footerTexts = new List<PixelText>();

			private bool alreadyEnabled = false;

			public override string headerText => "";

			public override bool showCardDisplayer => false;

			public override bool showCardPanel => false;

			public override void OnEnable()
			{
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_0047: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0126: Unknown result type (might be due to invalid IL or missing references)
				//IL_0144: Unknown result type (might be due to invalid IL or missing references)
				//IL_0149: Unknown result type (might be due to invalid IL or missing references)
				((AscensionRunSetupScreenBase)this).OnEnable();
				currentLoadout = vanillaLoadout;
				if (!alreadyEnabled)
				{
					GameObjectExtensions.FindChild(((Component)this).gameObject, "Footer").GetComponent<ViewportRelativePosition>().viewportAnchor = new Vector2(0.5f, 0f);
					PixelText[] componentsInChildren = GameObjectExtensions.FindChild(((Component)this).gameObject, "Header").GetComponentsInChildren<PixelText>();
					foreach (PixelText val in componentsInChildren)
					{
						if (((Object)((Component)val).gameObject).name.Contains("ChallengeLevel"))
						{
							val.SetText("SELECT LOADOUT", false);
							Transform transform = ((Component)val).transform;
							transform.localPosition += new Vector3(0f, -0.05f, 0f);
							for (int j = 0; j < 5; j++)
							{
								PixelText val2 = Object.Instantiate<PixelText>(val, GameObjectExtensions.FindChild(((Component)this).gameObject, "Footer").transform);
								footerTexts.Add(val2);
								GameObject gameObject = ((Component)val2).gameObject;
								((Object)gameObject).name = ((Object)gameObject).name + "_" + j;
								Transform transform2 = ((Component)val2).transform;
								transform2.position += new Vector3(0f, 0.7f - (float)j * 0.1f, 0f);
								val2.SwitchToSmallFont();
							}
						}
						else if (((Object)((Component)val).gameObject).name.Contains("ChallengePoints"))
						{
							((Component)val).gameObject.SetActive(false);
						}
					}
					PixelText[] componentsInChildren2 = GameObjectExtensions.FindChild(((Component)this).gameObject, "Footer").GetComponentsInChildren<PixelText>();
					foreach (PixelText val3 in componentsInChildren2)
					{
						if (!footerTexts.Contains(val3))
						{
							((Component)val3).gameObject.SetActive(false);
						}
					}
					alreadyEnabled = true;
				}
				pageIndex = 0;
				ShowPage();
				OnCursorEnterLoadoutIcon(loadoutIcons[0]);
			}

			private void ShowPage()
			{
				for (int j = 0; j < loadoutIcons.Count; j++)
				{
					loadoutIcons[j].AssignInfo(null);
				}
				for (int k = 0; k < LoadoutManager.AllLoadouts.Count; k++)
				{
					if (k >= pageIndex * loadoutIcons.Count && k < (pageIndex + 1) * loadoutIcons.Count)
					{
						loadoutIcons[k - pageIndex * loadoutIcons.Count].AssignInfo(LoadoutManager.AllLoadouts[k]);
					}
				}
				for (int l = 0; l < loadoutIcons.Count; l++)
				{
					((MainInputInteractable)loadoutIcons[l]).CursorSelectEnded = (Action<MainInputInteractable>)Delegate.Combine(((MainInputInteractable)loadoutIcons[l]).CursorSelectEnded, (Action<MainInputInteractable>)delegate(MainInputInteractable i)
					{
						OnSelectLoadout(i as LoadoutIcon);
					});
				}
				for (int m = 0; m < loadoutIcons.Count; m++)
				{
					((MainInputInteractable)loadoutIcons[m]).CursorEntered = (Action<MainInputInteractable>)Delegate.Combine(((MainInputInteractable)loadoutIcons[m]).CursorEntered, (Action<MainInputInteractable>)delegate(MainInputInteractable i)
					{
						OnCursorEnterLoadoutIcon(i as LoadoutIcon);
					});
				}
			}

			private void OnSelectLoadout(LoadoutIcon loadout)
			{
				if (loadout.Unlocked)
				{
					currentLoadout = loadout.info;
					((MainInputInteractable)base.continueButton).CursorSelectStart();
				}
			}

			private void OnCursorEnterLoadoutIcon(LoadoutIcon loadout)
			{
				if (loadout.Unlocked)
				{
					for (int i = 0; i < footerTexts.Count; i++)
					{
						List<string> loadoutDescription = GetLoadoutDescription(loadout.info);
						footerTexts[i].SetText(loadoutDescription[i], false);
					}
				}
			}

			private List<string> GetLoadoutDescription(LoadoutInfo info)
			{
				//IL_06cd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0a18: Unknown result type (might be due to invalid IL or missing references)
				//IL_0a82: Unknown result type (might be due to invalid IL or missing references)
				List<string> list = new List<string>(5) { "", "", "", "", "" };
				list[0] += "ITEMS: ";
				if (StringExtensions.IsNullOrWhitespace(info.lowPriorityItem))
				{
					list[0] += "<EMPTY>, ";
				}
				else
				{
					List<string> list2 = list;
					list2[0] = list2[0] + "<color=#eef4c6>" + ItemsUtil.GetConsumableByName(info.lowPriorityItem).rulebookName + "</color>, ";
				}
				if (StringExtensions.IsNullOrWhitespace(info.highPriorityItem))
				{
					list[0] += "<EMPTY>, ";
				}
				else
				{
					List<string> list2 = list;
					list2[0] = list2[0] + "<color=#eef4c6>" + ItemsUtil.GetConsumableByName(info.highPriorityItem).rulebookName + "</color>, ";
				}
				if (StringExtensions.IsNullOrWhitespace(info.specialItem))
				{
					list[0] += "<EMPTY>";
				}
				else
				{
					List<string> list2 = list;
					list2[0] = list2[0] + "<color=#eef4c6>" + ItemsUtil.GetConsumableByName(info.specialItem).rulebookName + "</color>;";
				}
				list[1] += "BONUS CARDS: ";
				if (info.bonusCards.Count == 0)
				{
					list[1] += "<EMPTY>";
				}
				else
				{
					List<string> list2;
					for (int i = 0; i < info.bonusCards.Count - 1; i++)
					{
						list2 = list;
						list2[1] = list2[1] + "<color=#eef4c6>" + CardLoader.GetCardByName(info.bonusCards[i]).DisplayedNameEnglish + "</color>, ";
					}
					list2 = list;
					list2[1] = list2[1] + "<color=#eef4c6>" + CardLoader.GetCardByName(info.bonusCards[info.bonusCards.Count - 1]).DisplayedNameEnglish + "</color>;";
				}
				list[2] += "FIRST NODE: ";
				if (StringExtensions.IsNullOrWhitespace(info.firstNode))
				{
					list[2] += "<EMPTY>;";
				}
				else if (info.firstNode == "TotemBattle")
				{
					list[2] += "<color=#eef4c6>Totem Battle</color>;";
				}
				else if (info.firstNode == "CardBattle")
				{
					list[2] += "<color=#eef4c6>Card Battle</color>;";
				}
				else if (info.firstNode == "BuyPelts")
				{
					list[2] += "<color=#eef4c6>Buy Pelts</color>;";
				}
				else if (info.firstNode == "TradePelts")
				{
					list[2] += "<color=#eef4c6>Trade Pelts</color>;";
				}
				else if (info.firstNode == "DeckTrial")
				{
					list[2] += "<color=#eef4c6>Deck Trial</color>;";
				}
				else if (info.firstNode == "RandomCardChoices")
				{
					list[2] += "<color=#eef4c6>Random Card Choices</color>;";
				}
				else if (info.firstNode == "CostCardChoices")
				{
					list[2] += "<color=#eef4c6>Cost Card Choices</color>;";
				}
				else if (info.firstNode == "TribeCardChoices")
				{
					list[2] += "<color=#eef4c6>Tribe Card Choices</color>;";
				}
				else if (info.firstNode == "CardMerge")
				{
					list[2] += "<color=#eef4c6>Card Merge</color>;";
				}
				else if (info.firstNode == "GainConsumables")
				{
					list[2] += "<color=#eef4c6>Gain Consumables</color>;";
				}
				else if (info.firstNode == "BuildTotem")
				{
					list[2] += "<color=#eef4c6>Build Totem</color>;";
				}
				else if (info.firstNode == "DuplicateMerge")
				{
					list[2] += "<color=#eef4c6>Duplicate Merge</color>;";
				}
				else if (info.firstNode == "CardRemove")
				{
					list[2] += "<color=#eef4c6>Card Remove</color>;";
				}
				else if (info.firstNode == "CardStatBoost")
				{
					list[2] += "<color=#eef4c6>Card Stat Boost</color>;";
				}
				else if (info.firstNode == "CopyCard")
				{
					list[2] += "<color=#eef4c6>Copy Card</color>;";
				}
				int num = 3;
				if ((!StringExtensions.IsNullOrWhitespace(info.currentTotemTop) && !StringExtensions.IsNullOrWhitespace(info.currentTotemBottom)) || info.collectedTotemTops.Count > 0 || info.collectedTotemBottoms.Count > 0)
				{
					list[num] += "TOTEMS: ";
					if (!StringExtensions.IsNullOrWhitespace(info.currentTotemTop) && !StringExtensions.IsNullOrWhitespace(info.currentTotemBottom))
					{
						List<string> list2 = list;
						int index = num;
						list2[index] = list2[index] + "<color=#eef4c6>" + GetNameOfEnumValue(info.currentTotemTop) + "</color> TOP on <color=#eef4c6>" + AbilitiesUtil.GetInfo(Plugin.GetEnumValueFromString<Ability>(info.currentTotemBottom)).rulebookName + "</color> BOTTOM";
						if (info.collectedTotemTops.Count > 0 || info.collectedTotemBottoms.Count > 0)
						{
							list[num] += ", with ";
						}
					}
					if (info.collectedTotemTops.Count > 0 || info.collectedTotemBottoms.Count > 0)
					{
						int num2 = info.collectedTotemTops.Count;
						int num3 = info.collectedTotemBottoms.Count;
						if (info.collectedTotemTops.Contains(info.currentTotemTop))
						{
							num2--;
						}
						if (info.collectedTotemBottoms.Contains(info.currentTotemBottom))
						{
							num3--;
						}
						List<string> list2 = list;
						int index = num;
						list2[index] = list2[index] + "<color=#eef4c6>+" + num2 + "</color> TOPs and <color=#eef4c6>+" + num3 + "</color> BOTTOMs";
					}
					list[num] += ";";
					num++;
				}
				if (info.teeth > 0 || !StringExtensions.IsNullOrWhitespace(info.startingRegion) || info.boons.Count > 0)
				{
					if (info.teeth > 0)
					{
						List<string> list2 = list;
						int index = num;
						list2[index] = list2[index] + "TEETH: <color=#eef4c6>" + info.teeth + "</color>; ";
					}
					if (!StringExtensions.IsNullOrWhitespace(info.startingRegion))
					{
						string text = GetNameOfEnumValue(info.startingRegion);
						if (info.startingRegion == "Forest")
						{
							text = "Woodlands";
						}
						else if (info.startingRegion == "Wetlands")
						{
							text = "Wetlands";
						}
						else if (info.startingRegion == "Alpine")
						{
							text = "Snow Line";
						}
						else if (info.startingRegion == "Midnight")
						{
							text = "Midnight";
						}
						else if (info.startingRegion == "Midnight_Ascension")
						{
							text = "Midnight";
						}
						else if (info.startingRegion == "Pirateville")
						{
							text = "Pirateville";
						}
						List<string> list2 = list;
						int index = num;
						list2[index] = list2[index] + "REGION: <color=#eef4c6>" + text + "</color>; ";
					}
					if (info.boons.Count > 0)
					{
						list[num] += "BOONS: ";
						List<string> list2;
						int index;
						for (int j = 0; j < info.boons.Count - 1; j++)
						{
							list2 = list;
							index = num;
							list2[index] = list2[index] + "<color=#eef4c6>" + BoonsUtil.GetData(Plugin.GetEnumValueFromString<Type>(info.boons[j])).displayedName + "</color>, ";
						}
						list2 = list;
						index = num;
						list2[index] = list2[index] + "<color=#eef4c6>" + BoonsUtil.GetData(Plugin.GetEnumValueFromString<Type>(info.boons[info.boons.Count - 1])).displayedName + "</color>; ";
					}
				}
				return list;
			}

			public override void InitializeScreen(GameObject partialScreen)
			{
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e7: 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_011d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0138: Unknown result type (might be due to invalid IL or missing references)
				//IL_0153: 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_0189: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
				//IL_027b: Unknown result type (might be due to invalid IL or missing references)
				//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
				((AscensionRunSetupScreenBase)this).InitializeScreen(partialScreen);
				GameObject val = Object.Instantiate<GameObject>(GameObjectExtensions.FindChild(Resources.Load<GameObject>("prefabs/ui/ascension/AscensionCardsSummaryScreen"), "PageLeftButton"));
				val.transform.SetParent(partialScreen.transform);
				val.transform.localPosition = new Vector3(-1.75f, 0.15f, 0f);
				((MainInputInteractable)val.GetComponent<AscensionMenuInteractable>()).CursorSelectStarted = delegate
				{
					if (pageIndex > 0)
					{
						pageIndex--;
						ShowPage();
					}
				};
				GameObject val2 = Object.Instantiate<GameObject>(GameObjectExtensions.FindChild(Resources.Load<GameObject>("prefabs/ui/ascension/AscensionCardsSummaryScreen"), "PageRightButton"));
				val2.transform.SetParent(partialScreen.transform);
				val2.transform.localPosition = new Vector3(1.75f, 0.15f, 0f);
				((MainInputInteractable)val2.GetComponent<AscensionMenuInteractable>()).CursorSelectStarted = delegate
				{
					if (pageIndex * 8 < LoadoutManager.AllLoadouts.Count - loadoutIcons.Count)
					{
						pageIndex++;
						ShowPage();
					}
				};
				List<Vector3> list = new List<Vector3>(8)
				{
					new Vector3(-1.29f, 0.47f, 0f),
					new Vector3(-0.43f, 0.47f, 0f),
					new Vector3(0.43f, 0.47f, 0f),
					new Vector3(1.29f, 0.47f, 0f),
					new Vector3(-1.29f, -0.13f, 0f),
					new Vector3(-0.43f, -0.13f, 0f),
					new Vector3(0.43f, -0.13f, 0f),
					new Vector3(1.29f, -0.13f, 0f)
				};
				for (int j = 0; j < 8; j++)
				{
					GameObject val3 = Object.Instantiate<GameObject>(ResourceBank.Get<GameObject>("prefabs/ui/ascension/StarterDeckIcon"));
					val3.transform.SetParent(partialScreen.transform);
					val3.transform.localPosition = list[j];
					GameObjectExtensions.FindChild(val3, "IconBack").GetComponent<PixelSnapSprite>().sprite = TextureHelper.ConvertTexture(TextureHelper.GetImageAsTexture("loadout_background.png", (FilterMode)0), (Vector2?)null);
					GameObjectExtensions.FindChild(val3, "IconBack").GetComponent<SpriteRenderer>().sprite = TextureHelper.ConvertTexture(TextureHelper.GetImageAsTexture("loadout_background.png", (FilterMode)0), (Vector2?)null);
					GameObjectExtensions.FindChild(GameObjectExtensions.FindChild(val3, "IconBack"), "Back").transform.localScale = new Vector3(0.6f, 0.6f, 0.6f);
					GameObjectExtensions.FindChild(GameObjectExtensions.FindChild(val3, "IconBack"), "Icon").transform.localPosition = new Vector3(0f, -0.04f, 0f);
					AscensionStarterDeckIcon component = val3.GetComponent<AscensionStarterDeckIcon>();
					AscensionSpriteBlinkEffect blinkEffect = null;
					SpriteMask iconRenderer = null;
					if ((Object)(object)component != (Object)null)
					{
						blinkEffect = component.blinkEffect;
						iconRenderer = component.iconRenderer;
						Object.Destroy((Object)(object)component);
					}
					LoadoutIcon loadoutIcon = val3.AddComponent<LoadoutIcon>();
					loadoutIcon.info = null;
					loadoutIcon.blinkEffect = blinkEffect;
					loadoutIcon.iconRenderer = iconRenderer;
					loadoutIcons.Add(loadoutIcon);
				}
			}
		}

		private class LoadoutIcon : MainInputInteractable
		{
			public LoadoutInfo info;

			public AscensionSpriteBlinkEffect blinkEffect;

			public SpriteMask iconRenderer;

			public override bool CollisionIs2D => true;

			public bool Unlocked => info != null && AscensionSaveData.Data.challengeLevel >= info.unlockLevel;

			public override CursorType CursorType
			{
				get
				{
					//IL_001f: 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_0022: Unknown result type (might be due to invalid IL or missing references)
					if (((MainInputInteractable)this).CursorSelectEnded == null || !Unlocked)
					{
						return (CursorType)0;
					}
					return (CursorType)4;
				}
			}

			public override void OnCursorEnter()
			{
				((AscensionMenuBlinkEffect)blinkEffect).SetBlinkingEnabled(true);
			}

			public override void OnCursorExit()
			{
				((AscensionMenuBlinkEffect)blinkEffect).SetBlinkingEnabled(false);
			}

			private void Start()
			{
				AssignInfo(info);
			}

			public void AssignInfo(LoadoutInfo loadoutInfo)
			{
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_0111: Unknown result type (might be due to invalid IL or missing references)
				//IL_0116: Unknown result type (might be due to invalid IL or missing references)
				//IL_00be: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
				info = loadoutInfo;
				if (info == null || loadoutInfo == null)
				{
					info = null;
					iconRenderer.sprite = TextureHelper.ConvertTexture(TextureHelper.GetImageAsTexture("loadout_icon_null.png", (FilterMode)0), (Vector2?)null);
					((AscensionMenuBlinkEffect)blinkEffect).blinkOffColor = new Color(16f / 51f, 0.1254902f, 0.24313726f);
					((AscensionMenuBlinkEffect)blinkEffect).SetBlinkingEnabled(false);
				}
				else if (Unlocked)
				{
					iconRenderer.sprite = TextureHelper.ConvertTexture(info.icon, (Vector2?)null);
					((AscensionMenuBlinkEffect)blinkEffect).blinkOffColor = new Color(0.61960787f, 0.14901961f, 16f / 85f);
					((AscensionMenuBlinkEffect)blinkEffect).SetBlinkingEnabled(false);
				}
				else
				{
					iconRenderer.sprite = TextureHelper.ConvertTexture(TextureHelper.GetImageAsTexture("loadout_icon_locked.png", (FilterMode)0), (Vector2?)null);
					((AscensionMenuBlinkEffect)blinkEffect).blinkOffColor = new Color(16f / 51f, 0.1254902f, 0.24313726f);
					((AscensionMenuBlinkEffect)blinkEffect).SetBlinkingEnabled(false);
				}
			}
		}

		private Harmony harmony = new Harmony("tvflabs.inscryption.KCMLoadouts");

		private const string PluginGuid = "tvflabs.inscryption.KCMLoadouts";

		private const string PluginName = "KCMLoadouts";

		private const string PluginVersion = "1.0.0";

		private const string PluginPrefix = "KCMLoadouts";

		public static LoadoutInfo currentLoadout;

		public static LoadoutInfo vanillaLoadout;

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded KCMLoadouts!");
			vanillaLoadout = LoadoutManager.AddLoadout("Vanilla", TextureHelper.GetImageAsTexture("loadout_icon_vanilla.png", (FilterMode)0), 0, "Pliers", "SquirrelBottle", "FishHook", new List<string>(2) { "PeltHare", "PeltHare" }, new List<string>(2) { "Opossum", "RingWorm" }, "TradePelts");
			currentLoadout = vanillaLoadout;
			RegisterJsonLoadouts();
			AscensionScreenManager.RegisterScreen<SelectLoadoutScreen>();
			harmony.PatchAll();
		}

		private void RegisterJsonLoadouts()
		{
			DirectoryInfo directoryInfo = new DirectoryInfo(Paths.PluginPath);
			FileInfo[] files = directoryInfo.GetFiles("*.jldt", SearchOption.AllDirectories);
			FileInfo[] array = files;
			foreach (FileInfo fileInfo in array)
			{
				JsonLoadout jsonLoadout = new JsonLoadout();
				JsonUtility.FromJsonOverwrite(File.ReadAllText(fileInfo.FullName), (object)jsonLoadout);
				if (jsonLoadout != null && !StringExtensions.IsNullOrWhitespace(jsonLoadout.loadoutName) && !StringExtensions.IsNullOrWhitespace(jsonLoadout.iconPath))
				{
					LoadoutManager.AddLoadout(jsonLoadout.loadoutName, TextureHelper.GetImageAsTexture(jsonLoadout.iconPath, (FilterMode)0), jsonLoadout.unlockLevel, jsonLoadout.lowPriorityItem, jsonLoadout.highPriorityItem, jsonLoadout.specialItem, currentTotemTop: jsonLoadout.currentTotemTop, currentTotemBottom: jsonLoadout.currentTotemBottom, collectedTotemTops: jsonLoadout.collectedTotemTops, collectedTotemBottoms: jsonLoadout.collectedTotemBottoms, bonusCards: jsonLoadout.bonusCards, penaltyBonusCards: jsonLoadout.penaltyBonusCards, firstNode: jsonLoadout.firstNode, penaltyFirstNode: jsonLoadout.penaltyFirstNode, teeth: jsonLoadout.teeth, startingRegion: jsonLoadout.startingRegion, boons: jsonLoadout.boons);
				}
			}
		}

		private static T GetEnumValueFromString<T>(string name) where T : unmanaged, Enum
		{
			string[] array = name.Split(new char[1] { '.' });
			string text = "";
			string text2 = array[^1];
			for (int i = 0; i < array.Length - 1; i++)
			{
				text += array[i];
			}
			if (Utility.IsNullOrWhiteSpace(text))
			{
				Array values = Enum.GetValues(typeof(T));
				for (int j = 0; j < values.Length; j++)
				{
					if (Enum.GetValues(typeof(T)).GetValue(j).ToString() == text2)
					{
						return (T)Enum.GetValues(typeof(T)).GetValue(j);
					}
				}
			}
			return GuidManager.GetEnumValue<T>(text, text2);
		}

		private static string GetNameOfEnumValue(string name)
		{
			string[] array = name.Split(new char[1] { '.' });
			string text = "";
			string result = array[^1];
			for (int i = 0; i < array.Length - 1; i++)
			{
				text += array[i];
			}
			return result;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "KCMLoadouts";

		public const string PLUGIN_NAME = "KCMLoadouts";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}