Decompiled source of CustomSideDeck v2.3.2

CustomSideDeck.dll

Decompiled 6 hours ago
using System;
using System.Collections;
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 BepInEx.Bootstrap;
using BepInEx.Configuration;
using CustomSideDeck.Info;
using DiskCardGame;
using GBC;
using HarmonyLib;
using InscryptionAPI.Ascension;
using InscryptionAPI.Card;
using InscryptionAPI.Guid;
using InscryptionAPI.Helpers;
using InscryptionAPI.Helpers.Extensions;
using InscryptionAPI.Nodes;
using InscryptionAPI.Saves;
using Microsoft.CodeAnalysis;
using Pixelplacement;
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("CustomSideDeck")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Placeholder description")]
[assembly: AssemblyFileVersion("2.3.2.0")]
[assembly: AssemblyInformationalVersion("2.3.2")]
[assembly: AssemblyProduct("CustomSideDeck")]
[assembly: AssemblyTitle("CustomSideDeck")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.3.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ExampleMod
{
	public class ExampleSequencer : CustomNodeSequencer, ICustomNodeSequencer
	{
		public SelectCardFromDeckSlot selectionSlot = Singleton<SpecialNodeHandler>.Instance.cardStatBoostSequencer.selectionSlot;

		public override bool ShouldNotReturnToMapOnEnd(CustomSpecialNodeData exampleNode)
		{
			return true;
		}

		public override IEnumerator DoCustomSequence(CustomSpecialNodeData exampleNode)
		{
			Singleton<ViewManager>.Instance.SwitchToView((View)1, false, true);
			yield return (object)new WaitForSeconds(0.5f);
			Singleton<ViewManager>.Instance.SwitchToView((View)38, false, true);
			Singleton<TableRuleBook>.Instance.SetOnBoard(true);
			Singleton<InteractionCursor>.Instance.SetEnabled(true);
			((InteractableBase)selectionSlot).ClearDelegates();
			Component[] componentsInChildren = ((Component)selectionSlot).GetComponentsInChildren<Component>();
			foreach (Component child in componentsInChildren)
			{
				if (Object.op_Implicit((Object)(object)child) && ((object)child).ToString().Contains("FireAnim"))
				{
					Object.Destroy((Object)(object)child.gameObject);
				}
			}
			if (((HighlightedInteractable)selectionSlot).specificRenderers.Count > 1)
			{
				((HighlightedInteractable)selectionSlot).specificRenderers.RemoveAt(1);
			}
			((HighlightedInteractable)selectionSlot).specificRenderers[0].material.mainTexture = (Texture)(object)TextureHelper.GetImageAsTexture("slot_example_sequence.png", (FilterMode)0);
			SelectCardFromDeckSlot selectCardFromDeckSlot = selectionSlot;
			((MainInputInteractable)selectCardFromDeckSlot).CursorSelectStarted = (Action<MainInputInteractable>)Delegate.Combine(((MainInputInteractable)selectCardFromDeckSlot).CursorSelectStarted, (Action<MainInputInteractable>)delegate(MainInputInteractable slot)
			{
				OnSlotSelected(slot);
			});
			yield return (object)new WaitForSeconds(0.3f);
			((Component)Singleton<ExplorableAreaManager>.Instance.HangingLight).gameObject.SetActive(false);
			((Component)Singleton<ExplorableAreaManager>.Instance.HandLight).gameObject.SetActive(false);
			yield return Singleton<TextDisplayer>.Instance.ShowUntilInput("There is nothing here yet...", -0.65f, 0.5f, (Emotion)1, (LetterAnimation)0, (Speaker)0, (string[])null, true);
			yield return Singleton<TextDisplayer>.Instance.ShowUntilInput("Pity.", -0.45f, 0.5f, (Emotion)2, (LetterAnimation)0, (Speaker)1, (string[])null, true);
			((Component)selectionSlot).gameObject.SetActive(true);
			selectionSlot.RevealAndEnable();
			yield return (object)new WaitForSeconds(0.3f);
			((Component)Singleton<ExplorableAreaManager>.Instance.HangingLight).gameObject.SetActive(true);
			((Component)Singleton<ExplorableAreaManager>.Instance.HandLight).gameObject.SetActive(true);
			yield return (object)new WaitForSeconds(0.5f);
			yield return Singleton<TextDisplayer>.Instance.ShowUntilInput("Oh..?", -0.45f, 0.5f, (Emotion)5, (LetterAnimation)0, (Speaker)1, (string[])null, true);
		}

		private void OnSlotSelected(MainInputInteractable slot)
		{
			List<CardInfo> validCards = GetValidCards();
			((InteractableBase)selectionSlot).SetEnabled(false);
			((HighlightedInteractable)selectionSlot).ShowState((State)1, false, 0.15f);
			if (validCards == null)
			{
				((MonoBehaviour)this).StartCoroutine(ApplyCardCostSequence(validCards: false));
			}
			else if (validCards != null)
			{
				((SelectCardFromDeckSlot)((slot is SelectCardFromDeckSlot) ? slot : null)).SelectFromCards(validCards, (Action)OnSlotSelectionEnded, false);
			}
		}

		private IEnumerator ApplyCardCostSequence(bool validCards)
		{
			if (!validCards)
			{
				((InteractableBase)selectionSlot).SetEnabled(false);
				selectionSlot.FlyOffCard();
				selectionSlot.Disable();
				((HighlightedInteractable)selectionSlot).SetShown(false, false);
				Singleton<SpecialNodeHandler>.Instance.cardStatBoostSequencer.selectionSlot.pile.Draw();
				Singleton<SpecialNodeHandler>.Instance.cardStatBoostSequencer.selectionSlot.pile.DestroyCardsImmediate();
				yield return (object)new WaitForSeconds(0.5f);
				if ((Object)(object)Singleton<GameFlowManager>.Instance != (Object)null)
				{
					Singleton<GameFlowManager>.Instance.TransitionToGameState((GameState)1, (NodeData)null);
				}
				yield break;
			}
			((InteractableBase)selectionSlot).SetEnabled(false);
			yield return Singleton<TextDisplayer>.Instance.ShowUntilInput("That's a fine " + ((Card)selectionSlot.Card).Info.displayedName + "...", -2.5f, 0.5f, (Emotion)0, (LetterAnimation)0, (Speaker)0, (string[])null, true);
			ScriptableObject.CreateInstance<CardInfo>();
			CardInfo modifiedCard = ((Card)selectionSlot.Card).Info;
			modifiedCard.cost = ((Card)selectionSlot.Card).Info.cost - 1;
			((Card)selectionSlot.Card).SetFaceDown(true, false);
			((Card)selectionSlot.Card).Info.cost = modifiedCard.cost;
			((Card)selectionSlot.Card).SetInfo(modifiedCard);
			((Card)selectionSlot.Card).RenderCard();
			yield return (object)new WaitForSeconds(0.6f);
			((Card)selectionSlot.Card).SetFaceDown(false, false);
			((CardCollectionInfo)RunState.Run.playerDeck).RemoveCard(((Card)selectionSlot.Card).Info);
			((CardCollectionInfo)RunState.Run.playerDeck).AddCard(modifiedCard);
			SaveManager.SaveToFile(false);
			Singleton<ViewManager>.Instance.SwitchToView((View)38, false, true);
			yield return (object)new WaitForSeconds(1.2f);
			selectionSlot.FlyOffCard();
			selectionSlot.Disable();
			((HighlightedInteractable)selectionSlot).SetShown(false, false);
			Singleton<SpecialNodeHandler>.Instance.cardStatBoostSequencer.selectionSlot.pile.Draw();
			Singleton<SpecialNodeHandler>.Instance.cardStatBoostSequencer.selectionSlot.pile.DestroyCardsImmediate();
			yield return (object)new WaitForSeconds(0.5f);
			if ((Object)(object)Singleton<GameFlowManager>.Instance != (Object)null)
			{
				Singleton<GameFlowManager>.Instance.TransitionToGameState((GameState)1, (NodeData)null);
			}
		}

		private void OnSlotSelectionEnded()
		{
			if ((Object)(object)selectionSlot.Card != (Object)null)
			{
				Debug.Log((object)"SlotSelectionEnded");
				((HighlightedInteractable)selectionSlot).SetShown(true, false);
				((HighlightedInteractable)selectionSlot).ShowState((State)2, false, 0.15f);
				Singleton<ViewManager>.Instance.SwitchToView((View)38, false, true);
				((MonoBehaviour)this).StartCoroutine(ApplyCardCostSequence(validCards: true));
			}
		}

		private List<CardInfo> GetValidCards()
		{
			List<CardInfo> list = new List<CardInfo>();
			list.Clear();
			list.AddRange(RunState.DeckList);
			list.RemoveAll((CardInfo x) => x.cost == 0);
			return list;
		}
	}
}
namespace CustomSideDeck
{
	[BepInPlugin("tvflabs.inscryption.CustomSideDeck", "CustomSideDeck", "2.3.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		public class Part1CardDrawPiles_SideDeckData_Patch
		{
			public static void Postfix(ref List<CardInfo> __result, Part1CardDrawPiles __instance)
			{
				List<CardInfo> sideDeckCards = SideDeckCards;
				__result = sideDeckCards;
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		public class Part3CardDrawPiles_SideDeckData_Patch
		{
			public static void Postfix(ref List<CardInfo> __result, Part3CardDrawPiles __instance)
			{
				List<CardInfo> list = new List<CardInfo>();
				for (int i = 1; i < SideDeckCards.Count; i++)
				{
					object obj = SideDeckCards[i].Clone();
					CardInfo val = (CardInfo)((obj is CardInfo) ? obj : null);
					Part3CardDrawPiles.AddModsToVessel(val);
					list.Add(val);
				}
				__result = list;
			}
		}

		[HarmonyPatch(typeof(AscensionSaveData), "GetActiveChallengePoints")]
		public class AscensionSaveData_GetActiveChallengePoints_Patch
		{
			public static void Postfix(ref int __result, AscensionSaveData __instance)
			{
				if (CurrentSideDeck != null)
				{
					__result += CurrentSideDeck.challengePoints;
				}
			}
		}

		[HarmonyPatch(typeof(LoadingScreenManager), "LoadGameData")]
		public class LoadingScreenManager_LoadGameData_Patch
		{
			public static IEnumerator Postfix(IEnumerator values, LoadingScreenManager __instance)
			{
				yield return values;
				InitializeSideDecks();
			}
		}

		[HarmonyPatch(typeof(Part1CardDrawPiles), "Start")]
		public class Part1CardDrawPiles_Start_Patch
		{
			public static void Postfix(Part1CardDrawPiles __instance)
			{
				//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_03ae: Expected O, but got Unknown
				//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
				//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
				//IL_02da: Unknown result type (might be due to invalid IL or missing references)
				//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
				//IL_0304: Unknown result type (might be due to invalid IL or missing references)
				//IL_0320: Unknown result type (might be due to invalid IL or missing references)
				//IL_0327: Unknown result type (might be due to invalid IL or missing references)
				//IL_032e: Unknown result type (might be due to invalid IL or missing references)
				//IL_033a: Unknown result type (might be due to invalid IL or missing references)
				//IL_033f: Unknown result type (might be due to invalid IL or missing references)
				bool flag = false;
				Texture2D imageAsTexture = TextureHelper.GetImageAsTexture("CSD_squirrel_back.png", (FilterMode)0);
				if (CurrentSideDeck.cardBack != null)
				{
					if (CurrentSideDeck.cardBack == "squirrel")
					{
						imageAsTexture = TextureHelper.GetImageAsTexture("CSD_squirrel_back.png", (FilterMode)0);
						flag = true;
					}
					else if (CurrentSideDeck.cardBack == "bee")
					{
						imageAsTexture = TextureHelper.GetImageAsTexture("CSD_bee_back.png", (FilterMode)0);
						flag = true;
					}
					else if (CurrentSideDeck.cardBack == "waterborne" || CurrentSideDeck.cardBack == "aquasquirrel" || CurrentSideDeck.cardBack == "aqua" || CurrentSideDeck.cardBack == "submerge")
					{
						imageAsTexture = TextureHelper.GetImageAsTexture("CSD_aquasquirrel_back.png", (FilterMode)0);
						flag = true;
					}
					else if (CurrentSideDeck.cardBack == "blank")
					{
						imageAsTexture = TextureHelper.GetImageAsTexture("CSD_card_back_template.png", (FilterMode)0);
						flag = true;
					}
					if (!flag && !(CurrentSideDeck.cardBack == "generated") && !(CurrentSideDeck.cardBack == "gen"))
					{
						DirectoryInfo directoryInfo = new DirectoryInfo(Paths.PluginPath);
						FileInfo[] files = directoryInfo.GetFiles(CurrentSideDeck.cardBack, SearchOption.AllDirectories);
						if (files.Length != 0)
						{
							string fullName = files[0].FullName;
							if ((Object)(object)TextureHelper.GetImageAsTexture(fullName, (FilterMode)0) != (Object)null)
							{
								imageAsTexture = TextureHelper.GetImageAsTexture(fullName, (FilterMode)0);
								flag = true;
							}
						}
					}
				}
				if ((plugin.generateCardBacks.Value || (CurrentSideDeck.cardBack != null && (CurrentSideDeck.cardBack == "generated" || CurrentSideDeck.cardBack == "gen"))) && !flag)
				{
					imageAsTexture = TextureHelper.GetImageAsTexture("CSD_card_back_template.png", (FilterMode)0);
					Texture2D texture = CardLoader.GetCardByName(CurrentSideDeck.defaultCard).portraitTex.texture;
					if ((Object)(object)texture != (Object)null)
					{
						Color32[] pixels = texture.GetPixels32();
						Color32[] pixels2 = imageAsTexture.GetPixels32();
						for (int i = 0; i < pixels.Length; i++)
						{
							if (pixels[i].a > 0)
							{
								Color32 val = Color32.op_Implicit(Color.Lerp(Color32.op_Implicit(pixels2[(i % ((Texture)texture).width + 5) * (i / ((Texture)texture).width + 49)]), Color32.op_Implicit(pixels[i]), ((float)(int)pixels[i].a - 8f) / 255f));
								imageAsTexture.SetPixel(i % ((Texture)texture).width + 5, i / ((Texture)texture).width + 49, Color32.op_Implicit(new Color32(val.r, val.g, val.b, byte.MaxValue)));
							}
						}
						imageAsTexture.Apply();
					}
				}
				Transform val2 = ((CardDrawPiles3D)__instance).SidePile.cardbackPrefab.transform.Find("BendableCard");
				GameObject gameObject = ((Component)val2.Find("Mesh")).gameObject;
				SkinnedMeshRenderer val3 = (SkinnedMeshRenderer)gameObject.GetComponentByName("SkinnedMeshRenderer");
				((Renderer)val3).materials[1].mainTexture = (Texture)(object)imageAsTexture;
			}
		}

		[HarmonyPatch(typeof(AscensionStartScreen), "ContinueGameSequence")]
		public class AscensionStartScreen_ContinueGameSequence_Patch
		{
			public static void Postfix()
			{
				InitializeSideDecks();
			}
		}

		[HarmonyPatch(typeof(DeckReviewSequencer), "OnEnterDeckView")]
		public class DeckReviewSequencer_OnEnterDeckView_Patch
		{
			public static bool Prefix(DeckReviewSequencer __instance)
			{
				//IL_009c: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a6: Expected O, but got Unknown
				//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b2: Expected O, but got Unknown
				//IL_0107: Unknown result type (might be due to invalid IL or missing references)
				//IL_0111: Expected O, but got Unknown
				//IL_0116: Unknown result type (might be due to invalid IL or missing references)
				//IL_011d: Expected O, but got Unknown
				//IL_0253: Unknown result type (might be due to invalid IL or missing references)
				//IL_025e: Unknown result type (might be due to invalid IL or missing references)
				//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_030c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0335: Unknown result type (might be due to invalid IL or missing references)
				//IL_035e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0387: Unknown result type (might be due to invalid IL or missing references)
				//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
				if (CurrentSideDeck.canEditDuringRun && (CurrentSideDeck.csdType == "Configurable" || CurrentSideDeck.csdType == "Advanced"))
				{
					if ((Object)(object)mainDeckPile == (Object)null || (Object)(object)sideDeckPile == (Object)null || (Object)(object)mainDeckInteractable == (Object)null || (Object)(object)sideDeckInteractable == (Object)null)
					{
						mainDeckObject = new GameObject("MainDeck");
						GameObject val = new GameObject("SelectionInteractable");
						val.transform.parent = mainDeckObject.transform;
						Component obj = mainDeckObject.AddComponent(typeof(CardPile));
						mainDeckPile = (CardPile)(object)((obj is CardPile) ? obj : null);
						Component obj2 = val.AddComponent(typeof(GenericMainInputInteractable));
						mainDeckInteractable = (GenericMainInputInteractable)(object)((obj2 is GenericMainInputInteractable) ? obj2 : null);
						sideDeckObject = new GameObject("SideDeck");
						GameObject val2 = new GameObject("SelectionInteractable");
						val2.transform.parent = sideDeckObject.transform;
						Component obj3 = sideDeckObject.AddComponent(typeof(CardPile));
						sideDeckPile = (CardPile)(object)((obj3 is CardPile) ? obj3 : null);
						Component obj4 = val2.AddComponent(typeof(GenericMainInputInteractable));
						sideDeckInteractable = (GenericMainInputInteractable)(object)((obj4 is GenericMainInputInteractable) ? obj4 : null);
						CardPile component = GameObject.Find("PlayerDeckPile").GetComponent<CardPile>();
						CardPile component2 = GameObject.Find("SquirrelPile").GetComponent<CardPile>();
						mainDeckPile.CardBackPrefab = component.cardbackPrefab;
						sideDeckPile.CardBackPrefab = component2.cardbackPrefab;
						mainDeckPile.tapSoundEvent = component.tapSoundEvent;
						sideDeckPile.tapSoundEvent = component2.tapSoundEvent;
						mainDeckPile.shadow = component.shadow;
						sideDeckPile.shadow = component2.shadow;
						((MainInputInteractable)mainDeckInteractable).CursorSelectStarted = (Action<MainInputInteractable>)Delegate.Combine(((MainInputInteractable)mainDeckInteractable).CursorSelectStarted, (Action<MainInputInteractable>)delegate
						{
							OnMainDeckSelected(__instance);
						});
						((MainInputInteractable)sideDeckInteractable).CursorSelectStarted = (Action<MainInputInteractable>)Delegate.Combine(((MainInputInteractable)sideDeckInteractable).CursorSelectStarted, (Action<MainInputInteractable>)delegate
						{
							OnSideDeckSelected(__instance);
						});
						mainDeckInteractable.cursorType = (CursorType)4;
						sideDeckInteractable.cursorType = (CursorType)4;
						mainDeckInteractable.is2D = false;
						sideDeckInteractable.is2D = false;
						((MainInputInteractable)mainDeckInteractable).ParentInteractables.Add((MainInputInteractable)(object)mainDeckPile);
						((MainInputInteractable)sideDeckInteractable).ParentInteractables.Add((MainInputInteractable)(object)sideDeckPile);
						((InteractableBase)mainDeckInteractable).coll = (Collider)(object)val.AddComponent<BoxCollider>();
						((InteractableBase)sideDeckInteractable).coll = (Collider)(object)val2.AddComponent<BoxCollider>();
						Collider coll = ((InteractableBase)mainDeckInteractable).coll;
						((BoxCollider)((coll is BoxCollider) ? coll : null)).center = new Vector3(0f, 0.5f, 0f);
						Collider coll2 = ((InteractableBase)sideDeckInteractable).coll;
						((BoxCollider)((coll2 is BoxCollider) ? coll2 : null)).center = new Vector3(0f, 0.5f, 0f);
						Collider coll3 = ((InteractableBase)mainDeckInteractable).coll;
						((BoxCollider)((coll3 is BoxCollider) ? coll3 : null)).extents = new Vector3(0.7f, 0.5f, 1f);
						Collider coll4 = ((InteractableBase)sideDeckInteractable).coll;
						((BoxCollider)((coll4 is BoxCollider) ? coll4 : null)).extents = new Vector3(0.7f, 0.5f, 1f);
						Collider coll5 = ((InteractableBase)mainDeckInteractable).coll;
						((BoxCollider)((coll5 is BoxCollider) ? coll5 : null)).size = new Vector3(1.4f, 1f, 2f);
						Collider coll6 = ((InteractableBase)sideDeckInteractable).coll;
						((BoxCollider)((coll6 is BoxCollider) ? coll6 : null)).size = new Vector3(1.4f, 1f, 2f);
						((InteractableBase)mainDeckInteractable).SetEnabled(false);
						((InteractableBase)sideDeckInteractable).SetEnabled(false);
					}
					deckReviewState = "ChoosePile";
					entering = true;
					((MonoBehaviour)__instance).StartCoroutine(SpawnDeckPiles(__instance));
					return false;
				}
				deckReviewState = "";
				return true;
			}
		}

		[HarmonyPatch(typeof(DeckReviewSequencer), "OnExitDeckView")]
		public class DeckReviewSequencer_OnExitDeckView_Patch
		{
			public static bool Prefix(DeckReviewSequencer __instance)
			{
				if (CurrentSideDeck.canEditDuringRun && (CurrentSideDeck.csdType == "Configurable" || CurrentSideDeck.csdType == "Advanced"))
				{
					((InteractableBase)mainDeckInteractable).SetEnabled(false);
					((InteractableBase)sideDeckInteractable).SetEnabled(false);
					if (deckReviewState == "ChoosePile" && !exiting)
					{
						exiting = true;
						((MonoBehaviour)__instance).StartCoroutine(CleanUpDeckPiles(selectedMainPile: true, selectedSidePile: true, __instance));
					}
					return false;
				}
				return true;
			}
		}

		[AscensionScreenSort(/*Could not decode attribute arguments.*/)]
		public class SideDeckSelectionScreen : AscensionRunSetupScreenBase
		{
			private int numCardsToShow = 7;

			private List<SideDeckInfo> validSideDecks = new List<SideDeckInfo>();

			private GameObject selectedBorder;

			public static SideDeckSelectionScreen Instance;

			public int scrollIndex = 0;

			public override string headerText => "Select Side Deck";

			public override bool showCardDisplayer => true;

			public override bool showCardPanel => true;

			public override void InitializeScreen(GameObject partialScreen)
			{
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				GameObject val = Resources.Load<GameObject>("prefabs/gbcui/pixelselectionborder");
				GameObject val2 = Object.Instantiate<GameObject>(val, ((Component)base.cards[0]).gameObject.transform);
				val2.GetComponent<SpriteRenderer>().color = GameColors.Instance.brightNearWhite;
				val2.AddComponent<PixelSnapElement>();
				selectedBorder = val2;
				Instance = this;
			}

			public override void CardClicked(PixelSelectableCard card)
			{
				if ((Object)(object)card != (Object)null && (Object)(object)((Card)card).Info != (Object)null)
				{
					CurrentSideDeck = SideDeckManager.GetSideDeckByName(CardExtensions.GetExtendedProperty(((Card)card).Info, "CSDAssociatedSideDeck"));
					ShowPage();
				}
			}

			public override void OnEnable()
			{
				((AscensionRunSetupScreenBase)this).OnEnable();
				InitializeSideDecks();
				validSideDecks.Clear();
				if (!AscensionSaveData.Data.ChallengeIsActive((AscensionChallenge)12))
				{
					validSideDecks.Add(SideDeckManager.GetSideDeckByName(CardExtensions.GetExtendedProperty(CardLoader.GetCardByName("Squirrel"), "CSDAssociatedSideDeck")));
					validSideDecks.Add(SideDeckManager.GetSideDeckByName(CardExtensions.GetExtendedProperty(CardLoader.GetCardByName("Bee"), "CSDAssociatedSideDeck")));
				}
				if (AscensionSaveData.Data.ChallengeIsActive((AscensionChallenge)12) || plugin.showAquasquirrelsWhenChallengeDisabled.Value)
				{
					validSideDecks.Add(SideDeckManager.GetSideDeckByName(CardExtensions.GetExtendedProperty(CardLoader.GetCardByName("AquaSquirrel"), "CSDAssociatedSideDeck")));
				}
				foreach (SideDeckInfo sideDecks in SideDeckManager.sideDecksList)
				{
					if (sideDecks.kayceesMod && !validSideDecks.Contains(sideDecks))
					{
						if (!AscensionSaveData.Data.ChallengeIsActive((AscensionChallenge)12) && !sideDecks.isAqua)
						{
							validSideDecks.Add(sideDecks);
						}
						if ((AscensionSaveData.Data.ChallengeIsActive((AscensionChallenge)12) || plugin.showAquasquirrelsWhenChallengeDisabled.Value) && sideDecks.isAqua)
						{
							validSideDecks.Add(sideDecks);
						}
					}
				}
				if (AscensionSaveData.Data.ChallengeIsActive((AscensionChallenge)12) && plugin.generateAquaVersions.Value)
				{
					foreach (SideDeckInfo sideDecks2 in SideDeckManager.sideDecksList)
					{
						if (validSideDecks.Contains(sideDecks2))
						{
							continue;
						}
						bool flag = false;
						if ((Object)(object)CardLoader.GetCardByName(sideDecks2.defaultCard) != (Object)null && !CardLoader.GetCardByName(sideDecks2.defaultCard).HasAbility((Ability)13))
						{
							flag = true;
						}
						if (!flag)
						{
							foreach (string card in sideDecks2.cards)
							{
								if ((Object)(object)CardLoader.GetCardByName(card) != (Object)null && !CardLoader.GetCardByName(card).HasAbility((Ability)13))
								{
									flag = true;
									break;
								}
							}
						}
						if (!flag)
						{
							foreach (string card2 in sideDecks2.cards)
							{
								if ((Object)(object)CardLoader.GetCardByName(card2) != (Object)null && !CardLoader.GetCardByName(card2).HasAbility((Ability)13))
								{
									flag = true;
									break;
								}
							}
						}
						if (flag)
						{
							validSideDecks.Add(sideDecks2);
						}
					}
				}
				CurrentSideDeck = validSideDecks[0];
				scrollIndex = 0;
				ShowPage();
				((AscensionRunSetupScreenBase)this).CardClicked(base.cards[0]);
			}

			public void ShowPage()
			{
				List<CardInfo> list = new List<CardInfo>();
				foreach (SideDeckInfo validSideDeck in validSideDecks)
				{
					CardInfo cardByName = CardLoader.GetCardByName(validSideDeck.defaultCard);
					if (AscensionSaveData.Data.ChallengeIsActive((AscensionChallenge)12) && plugin.generateAquaVersions.Value && !validSideDeck.isAqua)
					{
						string text = cardByName.DisplayedNameLocalized;
						if (char.IsUpper(text[0]))
						{
							text = ((text.Length <= 1) ? text.ToLower() : (char.ToLower(text[0]) + text.Substring(1)));
						}
						CardExtensions.SetDisplayedName(cardByName, "Aqua" + text);
						if (!cardByName.HasAbility((Ability)13))
						{
							CardExtensions.AddAbilities(cardByName, (Ability[])(object)new Ability[1] { (Ability)13 });
						}
					}
					list.Add(cardByName);
				}
				((AscensionRunSetupScreenBase)this).ShowCards(list.GetRange(scrollIndex, Math.Min(list.Count - scrollIndex, numCardsToShow)));
				selectedBorder.SetActive(false);
				foreach (PixelSelectableCard card in base.cards)
				{
					if ((Object)(object)card != (Object)null && ((Behaviour)card).enabled && (Object)(object)((Card)card).Info != (Object)null && CardExtensions.GetExtendedProperty(((Card)card).Info, "CSDAssociatedSideDeck") != null && CardExtensions.GetExtendedProperty(((Card)card).Info, "CSDAssociatedSideDeck") == CurrentSideDeck.internalName)
					{
						selectedBorder.transform.SetParent(((Component)card).transform.Find("Base/PixelSnap"), false);
						selectedBorder.SetActive(true);
						break;
					}
				}
				string text2 = "<color=#eef4c6>0</color> Challenge Points";
				if (CurrentSideDeck.challengePoints != 0)
				{
					text2 = ((CurrentSideDeck.challengePoints <= 0) ? ("<color=#eef4c6>" + CurrentSideDeck.challengePoints + "</color> Challenge Points") : ("<color=#eef4c6>+" + CurrentSideDeck.challengePoints + "</color> Challenge Points"));
				}
				SequentialPixelTextLines component = GameObjectExtensions.FindChild(((Component)this).gameObject, "Header").GetComponent<SequentialPixelTextLines>();
				component.ShowText(0.1f, new string[2]
				{
					"CURRENT SIDE DECK: " + text2,
					"Total Challenge Points: <color=#eef4c6>" + AscensionSaveData.Data.GetActiveChallengePoints() + "</color>"
				}, true);
			}

			public override void LeftButtonClicked(MainInputInteractable button)
			{
				if (scrollIndex > 0)
				{
					scrollIndex = Math.Max(0, scrollIndex - numCardsToShow);
					ShowPage();
				}
			}

			public override void RightButtonClicked(MainInputInteractable button)
			{
				if (scrollIndex < validSideDecks.Count - numCardsToShow)
				{
					scrollIndex += numCardsToShow;
					ShowPage();
				}
			}
		}

		[AscensionScreenSort(/*Could not decode attribute arguments.*/)]
		public class SideDeckConfigurationScreen : AscensionRunSetupScreenBase
		{
			private int numCardsToShow = 5;

			public static SideDeckConfigurationScreen Instance;

			public bool isAdvanced = false;

			public List<CardInfo> confCards;

			public int scrollIndex = 0;

			public override string headerText => "Configure Side Deck";

			public override bool showCardDisplayer => true;

			public override bool showCardPanel => true;

			public override void InitializeScreen(GameObject partialScreen)
			{
				Instance = this;
			}

			public override void CardClicked(PixelSelectableCard card)
			{
				if (!((Object)(object)card != (Object)null) || !((Object)(object)((Card)card).Info != (Object)null))
				{
					return;
				}
				int index = confCards.IndexOf(((Card)card).Info);
				string extendedProperty = CardExtensions.GetExtendedProperty(((Card)card).Info, "ConfIndex");
				confCards.RemoveAt(index);
				for (int i = 0; i <= CurrentSideDeck.options.Count; i++)
				{
					if (((Object)((Card)card).Info).name == CurrentSideDeck.options[i])
					{
						if (i == CurrentSideDeck.options.Count - 1)
						{
							((Card)card).SetInfo(CardExtensions.SetExtendedProperty(CardLoader.GetCardByName(CurrentSideDeck.options[0]), "ConfIndex", (object)extendedProperty));
						}
						else
						{
							((Card)card).SetInfo(CardExtensions.SetExtendedProperty(CardLoader.GetCardByName(CurrentSideDeck.options[i + 1]), "ConfIndex", (object)extendedProperty));
						}
						break;
					}
				}
				confCards.Insert(index, ((Card)card).Info);
				int num = 0;
				foreach (CardInfo confCard in confCards)
				{
					SetConfCard(((Object)confCard).name, num);
					num++;
				}
				ShowPage();
			}

			public override void OnEnable()
			{
				int num = 0;
				if (CurrentSideDeck.csdType == "Advanced")
				{
					isAdvanced = true;
					for (int i = 1; i <= CurrentSideDeck.cards.Count; i++)
					{
						if (!Utility.IsNullOrWhiteSpace(CurrentSideDeck.cards[i - 1]) && (CurrentSideDeck.cards[i - 1] == "conf" || CurrentSideDeck.cards[i - 1] == "c"))
						{
							num++;
						}
					}
				}
				else if (CurrentSideDeck.options.Count > 0)
				{
					num = CurrentSideDeck.numCards;
				}
				if (CurrentSideDeck.options.Count == 0 || num == 0)
				{
					((MainInputInteractable)base.continueButton).CursorSelectStart();
					((MainInputInteractable)base.continueButton).CursorSelectEnd();
					return;
				}
				((AscensionRunSetupScreenBase)this).OnEnable();
				confCards = new List<CardInfo>();
				if (isAdvanced)
				{
					for (int j = 1; j <= num; j++)
					{
						confCards.Add(CardLoader.GetCardByName(CurrentSideDeck.options[0]));
					}
				}
				else
				{
					for (int k = 1; k <= CurrentSideDeck.numCards; k++)
					{
						confCards.Add(CardLoader.GetCardByName(CurrentSideDeck.options[0]));
					}
				}
				int num2 = 0;
				foreach (CardInfo confCard in confCards)
				{
					SetConfCard(((Object)confCard).name, num2);
					num2++;
				}
				ShowPage();
			}

			public void ShowPage()
			{
				((AscensionRunSetupScreenBase)this).ShowCards(confCards.GetRange(scrollIndex, Math.Min(confCards.Count - scrollIndex, numCardsToShow)));
				string text = "<color=#eef4c6>0</color> Challenge Points";
				if (CurrentSideDeck.challengePoints != 0)
				{
					text = ((CurrentSideDeck.challengePoints <= 0) ? ("<color=#eef4c6>" + CurrentSideDeck.challengePoints + "</color> Challenge Points") : ("<color=#eef4c6>+" + CurrentSideDeck.challengePoints + "</color> Challenge Points"));
				}
				SequentialPixelTextLines component = GameObjectExtensions.FindChild(((Component)this).gameObject, "Header").GetComponent<SequentialPixelTextLines>();
				component.ShowText(0.1f, new string[2]
				{
					"CURRENT SIDE DECK: " + text,
					"Total Challenge Points: <color=#eef4c6>" + AscensionSaveData.Data.GetActiveChallengePoints() + "</color>"
				}, true);
			}

			public override void LeftButtonClicked(MainInputInteractable button)
			{
				if (scrollIndex > 0)
				{
					scrollIndex = Math.Max(0, scrollIndex - numCardsToShow);
					ShowPage();
				}
			}

			public override void RightButtonClicked(MainInputInteractable button)
			{
				if (scrollIndex < confCards.Count - numCardsToShow)
				{
					scrollIndex += numCardsToShow;
					ShowPage();
				}
			}
		}

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

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

		private const string PluginName = "CustomSideDeck";

		private const string PluginVersion = "2.3.0";

		private const string PluginPrefix = "CustomSideDeck";

		private static Plugin plugin;

		private static bool alreadyInitialized;

		private ConfigEntry<bool> generateCardBacks;

		private ConfigEntry<bool> generateAquaVersions;

		private ConfigEntry<bool> showAquasquirrelsWhenChallengeDisabled;

		private static string deckReviewState = "";

		private static CardPile mainDeckPile = null;

		private static CardPile sideDeckPile = null;

		private static GenericMainInputInteractable mainDeckInteractable = null;

		private static GenericMainInputInteractable sideDeckInteractable = null;

		private static GameObject mainDeckObject = null;

		private static GameObject sideDeckObject = null;

		private static Vector3 defaultMainPilePos = new Vector3(-1.09f, 5.0196f, 1.36f);

		private static Vector3 defaultSidePilePos = new Vector3(1.71f, 5.0199f, 1.36f);

		private static bool entering = false;

		private static bool exiting = false;

		private static List<CardInfo> sideDeckCards = new List<CardInfo>();

		public static List<CardInfo> SideDeckCards
		{
			get
			{
				List<CardInfo> list = new List<CardInfo>();
				if (CurrentSideDeck.csdType != "Advanced")
				{
					for (int i = 0; i < CurrentSideDeck.numCards; i++)
					{
						if (CurrentSideDeck.options.Count > 0)
						{
							list.Add(CardLoader.GetCardByName(GetConfCards()[i]));
						}
						else
						{
							list.Add(CardLoader.GetCardByName(CurrentSideDeck.defaultCard));
						}
					}
				}
				else
				{
					int num = 0;
					foreach (string card in CurrentSideDeck.cards)
					{
						if (card == "conf")
						{
							list.Add(CardLoader.GetCardByName(GetConfCards()[num]));
							num++;
						}
						else if (card == "def" || card == "self")
						{
							CardLoader.GetCardByName(CurrentSideDeck.defaultCard);
						}
						else
						{
							list.Add(CardLoader.GetCardByName(card));
						}
					}
				}
				if (AscensionSaveData.Data.ChallengeIsActive((AscensionChallenge)12) && !CurrentSideDeck.isAqua)
				{
					foreach (CardInfo item in list)
					{
						string text = item.DisplayedNameLocalized;
						if (char.IsUpper(text[0]))
						{
							text = ((text.Length <= 1) ? text.ToLower() : (char.ToLower(text[0]) + text.Substring(1)));
						}
						CardExtensions.SetDisplayedName(item, "Aqua" + text);
						if (!item.HasAbility((Ability)13))
						{
							CardExtensions.AddAbilities(item, (Ability[])(object)new Ability[1] { (Ability)13 });
						}
					}
				}
				return list;
			}
		}

		public static SideDeckInfo CurrentSideDeck
		{
			get
			{
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_0078: Invalid comparison between Unknown and I4
				//IL_0098: Unknown result type (might be due to invalid IL or missing references)
				//IL_009e: Invalid comparison between Unknown and I4
				if (SaveFile.IsAscension)
				{
					string value = ModdedSaveManager.SaveData.GetValue("tvflabs.inscryption.CustomSideDeck", "CurrentSideDeck");
					return (!string.IsNullOrEmpty(value)) ? SideDeckManager.GetSideDeckByName(value) : SideDeckManager.GetSideDeckByName("_Squirrel");
				}
				if (SaveManager.SaveFile.IsPart1)
				{
					CardDrawPiles instance = Singleton<CardDrawPiles>.Instance;
					if ((int)((Part1CardDrawPiles)((instance is Part1CardDrawPiles) ? instance : null)).sidePileFigurine == 1)
					{
						return SideDeckManager.GetSideDeckByName("_Bee");
					}
					CardDrawPiles instance2 = Singleton<CardDrawPiles>.Instance;
					if ((int)((Part1CardDrawPiles)((instance2 is Part1CardDrawPiles) ? instance2 : null)).sidePileFigurine == 2)
					{
						return SideDeckManager.GetSideDeckByName("_AquaSquirrel");
					}
					return SideDeckManager.GetSideDeckByName("_Squirrel");
				}
				if (SaveManager.SaveFile.IsPart3)
				{
					if (StoryEventsData.EventCompleted((StoryEvent)54))
					{
						return SideDeckManager.GetSideDeckByName("_EmptyVessel_GreenGem");
					}
					return SideDeckManager.GetSideDeckByName("_EmptyVessel");
				}
				return SideDeckManager.GetSideDeckByName("_Squirrel");
			}
			set
			{
				ModdedSaveManager.SaveData.SetValue("tvflabs.inscryption.CustomSideDeck", "CurrentSideDeck", (object)value.internalName);
			}
		}

		private void Awake()
		{
			plugin = this;
			generateCardBacks = ((BaseUnityPlugin)this).Config.Bind<bool>("CSDConfig", "GenerateDefaultCardBacks", false, "How the mod should handle side deck card backs for side decks that don't add their own custom card back. If enabled, automatically generates a unique card back based on the side deck's main card's portrait. Otherwise, the default squirrel back will be used.");
			generateAquaVersions = ((BaseUnityPlugin)this).Config.Bind<bool>("CSDConfig", "GenerateAquaVersions", false, "Whether to automatically add an Aqua version of all custom side decks. Buggy, not recommended.");
			showAquasquirrelsWhenChallengeDisabled = ((BaseUnityPlugin)this).Config.Bind<bool>("CSDConfig", "ShowAquaSideDecksWhenSquirrelFishChallengeDisabled", false, "Whether or not Aquasquirrels and custom side decks marked as `CSDIsAqua` should be shown as options even when the Squirrel Fish challenge isn't on.");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded CustomSideDeck!");
			harmony.PatchAll();
			AscensionScreenManager.RegisterScreen<SideDeckSelectionScreen>();
			AscensionScreenManager.RegisterScreen<SideDeckConfigurationScreen>();
			RegisterSideDecks();
		}

		private void RegisterSideDecks()
		{
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("Squirrel"), "CSDIsSideDeck", (object)"true");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("Squirrel"), "CSDSideDeckType", (object)"Basic");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("Squirrel"), "CSDCardBack", (object)"squirrel");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("Squirrel"), "CSDChallengePoints", (object)"0");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("Squirrel"), "CSDAct1", (object)"true");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("Squirrel"), "CSDKayceesMod", (object)"true");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("Bee"), "CSDIsSideDeck", (object)"true");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("Bee"), "CSDSideDeckType", (object)"Basic");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("Bee"), "CSDCardBack", (object)"bee");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("Bee"), "CSDChallengePoints", (object)"-20");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("Bee"), "CSDAct1", (object)"true");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("Bee"), "CSDKayceesMod", (object)"true");
			CardExtensions.SetPixelPortrait(CardLoader.GetCardByName("Bee"), TextureHelper.GetImageAsSprite("pixelportrait_bee.png", (SpriteType)1, (FilterMode)0));
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("AquaSquirrel"), "CSDIsSideDeck", (object)"true");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("AquaSquirrel"), "CSDSideDeckType", (object)"Basic");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("AquaSquirrel"), "CSDCardBack", (object)"aquasquirrel");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("AquaSquirrel"), "CSDIsAqua", (object)"true");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("AquaSquirrel"), "CSDChallengePoints", (object)"0");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("AquaSquirrel"), "CSDKayceesMod", (object)"true");
			CardExtensions.SetPixelPortrait(CardLoader.GetCardByName("AquaSquirrel"), TextureHelper.GetImageAsSprite("pixelportrait_aquasquirrel.png", (SpriteType)1, (FilterMode)0));
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("EmptyVessel"), "CSDIsSideDeck", (object)"true");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("EmptyVessel"), "CSDSideDeckType", (object)"Basic");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("EmptyVessel"), "CSDCardBack", (object)"blank");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("EmptyVessel"), "CSDChallengePoints", (object)"5");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("EmptyVessel"), "CSDAct3", (object)"true");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("EmptyVessel_GreenGem"), "CSDIsSideDeck", (object)"true");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("EmptyVessel_GreenGem"), "CSDSideDeckType", (object)"Configurable");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("EmptyVessel_GreenGem"), "CSDNumCards", (object)"10");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("EmptyVessel_GreenGem"), "CSDNumOptions", (object)"3");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("EmptyVessel_GreenGem"), "CSDOption1", (object)"EmptyVessel_GreenGem");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("EmptyVessel_GreenGem"), "CSDOption2", (object)"EmptyVessel_OrangeGem");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("EmptyVessel_GreenGem"), "CSDOption3", (object)"EmptyVessel_BlueGem");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("EmptyVessel_GreenGem"), "CSDCardBack", (object)"blank");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("EmptyVessel_GreenGem"), "CSDChallengePoints", (object)"0");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("EmptyVessel_GreenGem"), "CSDCanEditDuringRun", (object)"true");
			CardExtensions.SetExtendedProperty(CardLoader.GetCardByName("EmptyVessel_GreenGem"), "CSDAct3", (object)"true");
		}

		public static List<string> GetConfCards()
		{
			List<string> list = new List<string>();
			if (CurrentSideDeck.csdType != "Advanced")
			{
				if (CurrentSideDeck.options.Count > 0)
				{
					for (int i = 0; i < CurrentSideDeck.numCards; i++)
					{
						list.Add(ModdedSaveManager.SaveData.GetValue("tvflabs.inscryption.CustomSideDeck", $"ConfCard{i}"));
					}
				}
			}
			else
			{
				int num = 0;
				foreach (string card in CurrentSideDeck.cards)
				{
					if (card == "conf")
					{
						list.Add(ModdedSaveManager.SaveData.GetValue("tvflabs.inscryption.CustomSideDeck", $"ConfCard{num}"));
						num++;
					}
				}
			}
			return list;
		}

		public static void SetConfCard(string card, int cardNum)
		{
			ModdedSaveManager.SaveData.SetValue("tvflabs.inscryption.CustomSideDeck", $"ConfCard{cardNum}", (object)card);
		}

		private static void InitializeSideDecks()
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Invalid comparison between Unknown and I4
			if (alreadyInitialized)
			{
				return;
			}
			if (Chainloader.PluginInfos.ContainsKey("zorro.inscryption.infiniscryption.sidedecks"))
			{
				foreach (CardInfo item in CardManager.AllCardsCopy)
				{
					if (CardExtensions.HasCardMetaCategory(item, GuidManager.GetEnumValue<CardMetaCategory>("zorro.inscryption.infiniscryption.sidedecks", "SideDeck")) && (!CardExtensions.GetExtendedPropertyAsBool(item, "CSDIsSideDeck").HasValue || !CardExtensions.GetExtendedPropertyAsBool(item, "CSDIsSideDeck").Value) && (int)item.temple == 0)
					{
						CardExtensions.SetExtendedProperty(item, "CSDIsSideDeck", (object)"true");
						CardExtensions.SetExtendedProperty(item, "CSDSideDeckType", (object)"Basic");
						if (CardExtensions.GetExtendedPropertyAsInt(item, "SideDeckValue").HasValue)
						{
							CardExtensions.SetExtendedProperty(item, "CSDChallengePoints", (object)(-CardExtensions.GetExtendedPropertyAsInt(item, "SideDeckValue")));
						}
					}
				}
			}
			foreach (CardInfo item2 in CardManager.AllCardsCopy)
			{
				if (!CardExtensions.GetExtendedPropertyAsBool(item2, "CSDIsSideDeck").HasValue || !CardExtensions.GetExtendedPropertyAsBool(item2, "CSDIsSideDeck").Value)
				{
					continue;
				}
				SideDeckInfo sideDeckInfo;
				if (CardExtensions.GetExtendedProperty(item2, "CSDSideDeckType").ToLower() == "basic")
				{
					sideDeckInfo = SideDeckManager.New(CardExtensions.GetModPrefix(item2), ((Object)item2).name, "Basic", new List<string>(), new List<string>(), ((Object)item2).name);
				}
				else if (CardExtensions.GetExtendedProperty(item2, "CSDSideDeckType").ToLower() == "setcount")
				{
					sideDeckInfo = SideDeckManager.New(CardExtensions.GetModPrefix(item2), ((Object)item2).name, "SetCount", new List<string>(), new List<string>(), ((Object)item2).name, CardExtensions.GetExtendedPropertyAsInt(item2, "CSDNumCards") ?? 10);
				}
				else if (CardExtensions.GetExtendedProperty(item2, "CSDSideDeckType").ToLower() == "configurable")
				{
					List<string> list = new List<string>();
					for (int i = 0; i < CardExtensions.GetExtendedPropertyAsInt(item2, "CSDNumOptions").GetValueOrDefault(); i++)
					{
						list.Add(CardExtensions.GetExtendedProperty(item2, $"CSDOption{i + 1}"));
					}
					sideDeckInfo = SideDeckManager.New(CardExtensions.GetModPrefix(item2), ((Object)item2).name, "Configurable", new List<string>(), list, ((Object)item2).name, CardExtensions.GetExtendedPropertyAsInt(item2, "CSDNumCards") ?? 10);
				}
				else if (CardExtensions.GetExtendedProperty(item2, "CSDSideDeckType").ToLower() == "advanced")
				{
					List<string> list2 = new List<string>();
					for (int j = 0; j < CardExtensions.GetExtendedPropertyAsInt(item2, "CSDNumOptions").GetValueOrDefault(); j++)
					{
						list2.Add(CardExtensions.GetExtendedProperty(item2, $"CSDOption{j + 1}"));
					}
					List<string> list3 = new List<string>();
					for (int k = 0; k < (CardExtensions.GetExtendedPropertyAsInt(item2, "CSDNumCards") ?? 1); k++)
					{
						list3.Add(CardExtensions.GetExtendedProperty(item2, $"CSDCard{k + 1}"));
					}
					sideDeckInfo = SideDeckManager.New(CardExtensions.GetModPrefix(item2), ((Object)item2).name, "Advanced", list3, list2, ((Object)item2).name, CardExtensions.GetExtendedPropertyAsInt(item2, "CSDNumCards") ?? 10);
				}
				else
				{
					sideDeckInfo = SideDeckManager.New(CardExtensions.GetModPrefix(item2), ((Object)item2).name, "Basic", new List<string>(), new List<string>(), ((Object)item2).name);
				}
				if (CardExtensions.GetExtendedPropertyAsBool(item2, "CSDAct1").HasValue || CardExtensions.GetExtendedPropertyAsBool(item2, "CSDAct3").HasValue || CardExtensions.GetExtendedPropertyAsBool(item2, "CSDKayceesMod").HasValue)
				{
					sideDeckInfo.act1 = CardExtensions.GetExtendedPropertyAsBool(item2, "CSDAct1").HasValue && CardExtensions.GetExtendedPropertyAsBool(item2, "CSDAct1").Value;
					sideDeckInfo.act3 = CardExtensions.GetExtendedPropertyAsBool(item2, "CSDAct3").HasValue && CardExtensions.GetExtendedPropertyAsBool(item2, "CSDAct3").Value;
					sideDeckInfo.kayceesMod = CardExtensions.GetExtendedPropertyAsBool(item2, "KayceesMod").HasValue && CardExtensions.GetExtendedPropertyAsBool(item2, "KayceesMod").Value;
				}
				sideDeckInfo.cardBack = CardExtensions.GetExtendedProperty(item2, "CSDCardBack");
				sideDeckInfo.isAqua = CardExtensions.GetExtendedPropertyAsBool(item2, "CSDIsAqua").HasValue && CardExtensions.GetExtendedPropertyAsBool(item2, "CSDIsAqua").Value;
				sideDeckInfo.challengePoints = (CardExtensions.GetExtendedPropertyAsInt(item2, "CSDChallengePoints").HasValue ? CardExtensions.GetExtendedPropertyAsInt(item2, "CSDChallengePoints").Value : 0);
				sideDeckInfo.canEditDuringRun = CardExtensions.GetExtendedPropertyAsBool(item2, "CSDCanEditDuringRun").HasValue && CardExtensions.GetExtendedPropertyAsBool(item2, "CSDCanEditDuringRun").Value;
				CardExtensions.SetExtendedProperty(item2, "CSDAssociatedSideDeck", (object)sideDeckInfo.internalName);
			}
			alreadyInitialized = true;
		}

		private static void OnMainDeckSelected(DeckReviewSequencer deckReviewSequencer)
		{
			deckReviewState = "MainDeck";
			((InteractableBase)mainDeckInteractable).SetEnabled(false);
			((InteractableBase)sideDeckInteractable).SetEnabled(false);
			((MonoBehaviour)deckReviewSequencer).StartCoroutine(CleanUpDeckPiles(selectedMainPile: true, selectedSidePile: false, deckReviewSequencer));
			Singleton<ViewManager>.Instance.Controller.LockState = (ViewLockState)1;
			CustomCoroutine.WaitThenExecute(0.2f, (Action)delegate
			{
				deckReviewSequencer.ArrayDeck(((CardCollectionInfo)SaveManager.SaveFile.CurrentDeck).Cards, (Action<SelectableCard>)null, false);
			}, false);
		}

		private static void OnSideDeckSelected(DeckReviewSequencer deckReviewSequencer)
		{
			deckReviewState = "EditSideDeck";
			((MonoBehaviour)deckReviewSequencer).StartCoroutine(CleanUpDeckPiles(selectedMainPile: false, selectedSidePile: true, deckReviewSequencer));
			((InteractableBase)mainDeckInteractable).SetEnabled(false);
			((InteractableBase)sideDeckInteractable).SetEnabled(false);
			Singleton<ViewManager>.Instance.Controller.LockState = (ViewLockState)1;
			sideDeckCards.Clear();
			foreach (string confCard in GetConfCards())
			{
				sideDeckCards.Add(CardLoader.GetCardByName(confCard));
			}
			CustomCoroutine.WaitThenExecute(0.2f, (Action)delegate
			{
				deckReviewSequencer.ArrayDeck(sideDeckCards, (Action<SelectableCard>)OnSideDeckCardSelected, false);
			}, false);
		}

		private static void OnSideDeckCardSelected(SelectableCard card)
		{
			string name = ((Object)((Card)card).Info).name;
			if ((Object)(object)card != (Object)null && (Object)(object)((Card)card).Info != (Object)null)
			{
				int index = sideDeckCards.IndexOf(((Card)card).Info);
				string extendedProperty = CardExtensions.GetExtendedProperty(((Card)card).Info, "ConfIndex");
				sideDeckCards.RemoveAt(index);
				for (int i = 0; i <= CurrentSideDeck.options.Count; i++)
				{
					if (((Object)((Card)card).Info).name == CurrentSideDeck.options[i])
					{
						if (i == CurrentSideDeck.options.Count - 1)
						{
							((Card)card).SetInfo(CardExtensions.SetExtendedProperty(CardLoader.GetCardByName(CurrentSideDeck.options[0]), "ConfIndex", (object)extendedProperty));
						}
						else
						{
							((Card)card).SetInfo(CardExtensions.SetExtendedProperty(CardLoader.GetCardByName(CurrentSideDeck.options[i + 1]), "ConfIndex", (object)extendedProperty));
						}
						break;
					}
				}
				sideDeckCards.Insert(index, ((Card)card).Info);
				int num = 0;
				foreach (CardInfo sideDeckCard in sideDeckCards)
				{
					SetConfCard(((Object)sideDeckCard).name, num);
					num++;
				}
				((Card)card).SetInfo(sideDeckCards[index]);
			}
			((Card)card).Anim.LightNegationEffect();
		}

		private static IEnumerator SpawnDeckPiles(DeckReviewSequencer deckReviewSequencer)
		{
			Singleton<ViewManager>.Instance.Controller.LockState = (ViewLockState)1;
			((Component)mainDeckPile).transform.position = defaultMainPilePos;
			((Component)sideDeckPile).transform.position = defaultSidePilePos;
			((MonoBehaviour)deckReviewSequencer).StartCoroutine(mainDeckPile.SpawnCards(((CardCollectionInfo)SaveManager.SaveFile.CurrentDeck).Cards.Count, 0.5f));
			((MonoBehaviour)deckReviewSequencer).StartCoroutine(sideDeckPile.SpawnCards(GetNumConfCards(), 0.5f));
			yield return (object)new WaitUntil((Func<bool>)(() => !mainDeckPile.DoingCardOperation && !sideDeckPile.DoingCardOperation));
			yield return (object)new WaitForSeconds(0.5f);
			Singleton<ViewManager>.Instance.Controller.LockState = (ViewLockState)0;
			((InteractableBase)mainDeckInteractable).SetEnabled(true);
			((InteractableBase)sideDeckInteractable).SetEnabled(true);
			entering = false;
		}

		private static IEnumerator CleanUpDeckPiles(bool selectedMainPile, bool selectedSidePile, DeckReviewSequencer deckReviewSequencer)
		{
			Singleton<ViewManager>.Instance.Controller.LockState = (ViewLockState)1;
			Tween.Position(((Component)mainDeckPile).transform, defaultMainPilePos + Vector3.back * 3.5f, selectedMainPile ? 0.15f : 0.2f, selectedMainPile ? 0.15f : 0f, Tween.EaseLinear, (LoopType)0, (Action)null, (Action)delegate
			{
				if (!selectedMainPile)
				{
					mainDeckPile.DestroyCardsImmediate();
				}
			}, true);
			Tween.Position(((Component)sideDeckPile).transform, defaultSidePilePos + Vector3.back * 3.5f, selectedSidePile ? 0.15f : 0.2f, selectedSidePile ? 0.15f : 0f, Tween.EaseLinear, (LoopType)0, (Action)null, (Action)delegate
			{
				if (!selectedSidePile)
				{
					sideDeckPile.DestroyCardsImmediate();
				}
			}, true);
			if (selectedMainPile)
			{
				((MonoBehaviour)deckReviewSequencer).StartCoroutine(mainDeckPile.DestroyCards(0.2f));
			}
			if (selectedSidePile)
			{
				((MonoBehaviour)deckReviewSequencer).StartCoroutine(sideDeckPile.DestroyCards(0.2f));
			}
			yield return (object)new WaitUntil((Func<bool>)(() => !mainDeckPile.DoingCardOperation && !sideDeckPile.DoingCardOperation));
			Singleton<ViewManager>.Instance.Controller.LockState = (ViewLockState)0;
			exiting = false;
		}

		private static int GetNumConfCards()
		{
			int num = 0;
			if (CurrentSideDeck.csdType == "Advanced")
			{
				for (int i = 1; i <= CurrentSideDeck.cards.Count; i++)
				{
					if (!Utility.IsNullOrWhiteSpace(CurrentSideDeck.cards[i - 1]) && (CurrentSideDeck.cards[i - 1] == "conf" || CurrentSideDeck.cards[i - 1] == "c"))
					{
						num++;
					}
				}
			}
			else if (CurrentSideDeck.options.Count > 0)
			{
				num = CurrentSideDeck.numCards;
			}
			return num;
		}
	}
	internal class SideDeckIcon : MainInputInteractable
	{
		public SideDeckInfo Info;

		private Plugin.SideDeckSelectionScreen ScreenParent => ((Component)this).GetComponentInParent<Plugin.SideDeckSelectionScreen>();

		public override bool CollisionIs2D => true;

		public override void OnCursorEnter()
		{
			((AscensionRunSetupScreenBase)ScreenParent).DisplayCardInfo((CardInfo)null, Localization.Translate(Info.displayName), Info.description + $"\nContains {Info.cards.Count} cards", false);
		}

		public override void OnCursorExit()
		{
			((AscensionRunSetupScreenBase)ScreenParent).ClearMessage();
		}
	}
	public static class SideDeckManager
	{
		public static List<SideDeckInfo> sideDecksList = new List<SideDeckInfo>();

		public static SideDeckInfo New(string modPrefix, string name, string csdType, List<string> cards, List<string> options, string defaultCard, int numCards = 10, string cardBack = null, string pixelCardBack = null, bool isAqua = false, int challengePoints = 0, bool canEditDuringRun = false, bool act1 = false, bool act3 = false, bool kayceesMod = true)
		{
			SideDeckInfo sideDeckInfo = new SideDeckInfo();
			sideDeckInfo.internalName = modPrefix + "_" + name;
			sideDeckInfo.numCards = numCards;
			sideDeckInfo.defaultCard = defaultCard;
			sideDeckInfo.cards = new List<string>();
			sideDeckInfo.options = new List<string>();
			sideDeckInfo.csdType = csdType;
			sideDeckInfo.isAqua = isAqua;
			sideDeckInfo.challengePoints = challengePoints;
			sideDeckInfo.canEditDuringRun = canEditDuringRun;
			sideDeckInfo.act1 = act1;
			sideDeckInfo.act3 = act3;
			sideDeckInfo.kayceesMod = kayceesMod;
			foreach (string card in cards)
			{
				sideDeckInfo.cards.Add(card);
			}
			foreach (string option in options)
			{
				sideDeckInfo.options.Add(option);
			}
			sideDecksList.Add(sideDeckInfo);
			return sideDeckInfo;
		}

		public static SideDeckInfo GetSideDeckByName(string name)
		{
			return sideDecksList.Find((SideDeckInfo sideDeck) => sideDeck.internalName == name);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "CustomSideDeck";

		public const string PLUGIN_NAME = "CustomSideDeck";

		public const string PLUGIN_VERSION = "2.3.2";
	}
}
namespace CustomSideDeck.Info
{
	public class SideDeckInfo
	{
		public string internalName;

		public string displayName;

		public string description;

		public string csdType;

		public int numCards;

		public string defaultCard;

		public List<string> cards;

		public List<string> options;

		public string cardBack;

		public string pixelCardBack;

		public bool isAqua;

		public bool act1;

		public bool act3;

		public bool kayceesMod;

		public int challengePoints;

		public bool canEditDuringRun;
	}
}