Decompiled source of ThreeDRenderer v0.3.4

plugins/3DRenderer.dll

Decompiled 4 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using DiskCardGame.Patches;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Pixelplacement;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("3DRenderer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("3DRenderer")]
[assembly: AssemblyTitle("3DRenderer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class IsReadOnlyAttribute : Attribute
	{
	}
	[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;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class ExtensionMarkerAttribute : Attribute
	{
		private readonly string <Name>k__BackingField;

		public string Name => <Name>k__BackingField;

		public ExtensionMarkerAttribute(string name)
		{
			<Name>k__BackingField = name;
		}
	}
}
namespace DiskCardGame
{
	[BepInPlugin("chytridi05.inscryption.3drenderer", "3DRenderer", "0.3.4")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[HarmonyPatch]
	public class Plugin : BaseUnityPlugin
	{
		public static class Config
		{
			public static bool UsingPaperMergeAbilities;

			public static bool UsingPaperTotemAbilities;

			public static bool UsingPaperDustParticles;

			public static bool UsingPaperSacrificeParticles;

			public static bool UsingDiskShielded;

			public static bool UsingDiskOverclocked;

			public static bool UsingDiskExplosive;

			public static bool UsingDiskLatchAbility;

			public static bool UsingWizard3DPortraits;
		}

		public const string GUID = "chytridi05.inscryption.3drenderer";

		public const string NAME = "3DRenderer";

		public const string VERSION = "0.3.4";

		private readonly Dictionary<Scene, SceneSnapshotTextures> snapshotTexturesByScene = new Dictionary<Scene, SceneSnapshotTextures>();

		private static readonly Harmony harmony = new Harmony("chytridi05.inscryption.3drenderer");

		public static CardRenderCamera[] CardRenderCameras { get; private set; }

		private void Awake()
		{
			Config.UsingPaperMergeAbilities = ((BaseUnityPlugin)this).Config.Bind<bool>("Renderer", "Using Paper Merge Abilities", true, "Toggle whether to use paper renderer for merge abilities.").Value;
			Config.UsingPaperTotemAbilities = ((BaseUnityPlugin)this).Config.Bind<bool>("Renderer", "Using Paper Totem Abilities", true, "Toggle whether to use paper renderer for totem abilities.").Value;
			Config.UsingPaperDustParticles = ((BaseUnityPlugin)this).Config.Bind<bool>("Renderer", "Using Paper Dust Particles", true, "Toggle whether to use paper renderer for dust particles.").Value;
			Config.UsingPaperSacrificeParticles = ((BaseUnityPlugin)this).Config.Bind<bool>("Renderer", "Using Paper Sacrifice Particles", true, "Toggle whether to use paper renderer for sacrifice particles.").Value;
			Config.UsingDiskShielded = ((BaseUnityPlugin)this).Config.Bind<bool>("Renderer", "Using Disk Shielded", true, "Toggle whether to use disk renderer for shielded.").Value;
			Config.UsingDiskOverclocked = ((BaseUnityPlugin)this).Config.Bind<bool>("Renderer", "Using Disk Overclocked", true, "Toggle whether to use disk renderer for overclocked.").Value;
			Config.UsingDiskExplosive = ((BaseUnityPlugin)this).Config.Bind<bool>("Renderer", "Using Disk Explosive", true, "Toggle whether to use disk renderer for explosive.").Value;
			Config.UsingDiskLatchAbility = ((BaseUnityPlugin)this).Config.Bind<bool>("Renderer", "Using Disk Latch Ability", true, "Toggle whether to use disk renderer for latch ability.").Value;
			Config.UsingWizard3DPortraits = ((BaseUnityPlugin)this).Config.Bind<bool>("Renderer", "Using Wizard 3D Portraits", true, "Use Wizard portraits and slot stats on both sides of non-Magnificus boards.").Value;
			AppDomain.CurrentDomain.AssemblyResolve += ResolveEmitAssembly;
			try
			{
				harmony.PatchAll(typeof(Plugin).Assembly);
			}
			finally
			{
				AppDomain.CurrentDomain.AssemblyResolve -= ResolveEmitAssembly;
			}
			SceneManager.sceneLoaded += OnSceneLoaded;
			SceneManager.sceneUnloaded += OnSceneUnloaded;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded 3DRenderer 0.3.4");
		}

		private static void ApplyPatches()
		{
			AppDomain.CurrentDomain.AssemblyResolve += ResolveEmitAssembly;
			try
			{
				harmony.PatchAll(typeof(Plugin).Assembly);
			}
			finally
			{
				AppDomain.CurrentDomain.AssemblyResolve -= ResolveEmitAssembly;
			}
		}

		private static Assembly ResolveEmitAssembly(object sender, ResolveEventArgs args)
		{
			if (!(args.RequestingAssembly == typeof(Plugin).Assembly) || !(new AssemblyName(args.Name).Name == "System.Reflection.Emit.ILGeneration") || !(typeof(object).Assembly.GetName().Name == "mscorlib"))
			{
				return null;
			}
			return typeof(object).Assembly;
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04de: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0507: Unknown result type (might be due to invalid IL or missing references)
			//IL_0534: Unknown result type (might be due to invalid IL or missing references)
			//IL_053b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0542: Unknown result type (might be due to invalid IL or missing references)
			//IL_0547: Unknown result type (might be due to invalid IL or missing references)
			//IL_054c: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_06fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0704: Unknown result type (might be due to invalid IL or missing references)
			//IL_0709: Unknown result type (might be due to invalid IL or missing references)
			//IL_070e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0719: Unknown result type (might be due to invalid IL or missing references)
			//IL_071e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0723: Unknown result type (might be due to invalid IL or missing references)
			//IL_072d: Unknown result type (might be due to invalid IL or missing references)
			//IL_075a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0761: Unknown result type (might be due to invalid IL or missing references)
			//IL_0768: Unknown result type (might be due to invalid IL or missing references)
			//IL_076d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0772: Unknown result type (might be due to invalid IL or missing references)
			//IL_090a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0916: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_09af: Unknown result type (might be due to invalid IL or missing references)
			//IL_09b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_09c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ca: Unknown result type (might be due to invalid IL or missing references)
			if ((int)mode == 1)
			{
				return;
			}
			CardRenderCameras = Enumerable.Repeat<CardRenderCamera>(Singleton<CardRenderCamera>.Instance, 4).ToArray();
			if ((Object)(object)Singleton<CardRenderCamera>.Instance != (Object)null)
			{
				SceneSnapshotTextures sceneSnapshotTextures = new SceneSnapshotTextures();
				snapshotTexturesByScene.Add(scene, sceneSnapshotTextures);
				Transform parent = ((Component)Singleton<CardRenderCamera>.Instance).transform.parent;
				string name = ((Object)((Component)Singleton<CardRenderCamera>.Instance).gameObject).name;
				bool flag = name.ToLowerInvariant().Contains("grimora");
				bool flag2 = name.ToLowerInvariant().Contains("part3");
				bool flag3 = name.ToLowerInvariant().Contains("magnificus");
				if (flag || flag2 || flag3)
				{
					CardRenderCameras[0] = Object.Instantiate<CardRenderCamera>(Resources.Load<GameObject>("Prefabs/Cards/CardRenderCamera").GetComponent<CardRenderCamera>(), parent);
				}
				if (!flag)
				{
					CardRenderCameras[1] = Object.Instantiate<CardRenderCamera>(Resources.Load<GameObject>("Prefabs/Cards/CardRenderCamera_Grimora").GetComponent<CardRenderCamera>(), parent);
				}
				if (!flag2)
				{
					CardRenderCameras[2] = Object.Instantiate<CardRenderCamera>(Resources.Load<GameObject>("Prefabs/Cards/CardRenderCamera_Part3").GetComponent<CardRenderCamera>(), parent);
				}
				if (!flag3)
				{
					CardRenderCameras[3] = Object.Instantiate<CardRenderCamera>(Resources.Load<GameObject>("Prefabs/Cards/CardRenderCamera_Magnificus").GetComponent<CardRenderCamera>(), parent);
				}
				for (int i = 0; i < 4; i++)
				{
					CardRenderCamera val = CardRenderCameras[i];
					Transform transform = ((Component)val).transform;
					transform.localPosition += Vector3.up * 20f * (float)i;
					CardDisplayer cardDisplayer = val.cardDisplayer;
					switch (i)
					{
					case 0:
						cardDisplayer.gemCostTextures = CardRenderCameras[3].cardDisplayer.gemCostTextures;
						break;
					case 3:
					{
						CardAbilityIcons componentInChildren = ((Component)cardDisplayer).GetComponentInChildren<CardAbilityIcons>(true);
						CardAbilityIcons val2 = Object.Instantiate<CardAbilityIcons>(((Component)CardRenderCameras[0].cardDisplayer).GetComponentInChildren<CardAbilityIcons>(true), ((Component)cardDisplayer).transform);
						foreach (GameObject defaultIconGroup in val2.defaultIconGroups)
						{
							defaultIconGroup.transform.SetParent((Transform)null);
							Object.Destroy((Object)(object)defaultIconGroup);
						}
						componentInChildren.mergeIcons = val2.mergeIcons;
						componentInChildren.totemIcons = val2.totemIcons;
						componentInChildren.emissiveTotemIcons = val2.emissiveTotemIcons;
						componentInChildren.boonIcon = val2.boonIcon;
						componentInChildren.emissiveIconMat = val2.emissiveIconMat;
						componentInChildren.totemIconMat = val2.totemIconMat;
						while (((Component)val2).transform.childCount > 0)
						{
							Transform child = ((Component)val2).transform.GetChild(0);
							child.SetParent(((Component)componentInChildren).transform, true);
							AbilityIconInteractable[] componentsInChildren = ((Component)child).GetComponentsInChildren<AbilityIconInteractable>(true);
							foreach (AbilityIconInteractable obj in componentsInChildren)
							{
								obj.OriginalLocalPosition = ((Component)obj).transform.localPosition;
							}
						}
						Object.Destroy((Object)(object)((Component)val2).gameObject);
						cardDisplayer.costTextures = CardRenderCameras[0].cardDisplayer.costTextures;
						cardDisplayer.boneCostTextures = CardRenderCameras[0].cardDisplayer.boneCostTextures;
						break;
					}
					}
					sceneSnapshotTextures.Bind(val);
				}
				((BaseUnityPlugin)this).Logger.LogDebug((object)"Instantiated card render cameras");
			}
			if (!Config.UsingWizard3DPortraits || !((Object)(object)Singleton<BoardManager3D>.Instance != (Object)null))
			{
				return;
			}
			Transform root = ((Component)Singleton<BoardManager3D>.Instance).transform.root;
			if ((Object)(object)((Component)root).GetComponentInChildren<WizardPortraitSlotManager>() != (Object)null)
			{
				return;
			}
			WizardPortraitSlotManager portraitSlots = Object.Instantiate<WizardPortraitSlotManager>(Resources.Load<GameObject>("Prefabs/FinaleMagnificus/3DPortraitSlots").GetComponent<WizardPortraitSlotManager>(), root);
			int k;
			Vector3 val4;
			for (k = 0; k < ((BoardManager)Singleton<BoardManager3D>.Instance).playerSlots.Count; k++)
			{
				while (k >= portraitSlots.playerSlots.Count)
				{
					WizardBattlePortraitSlot val3 = Object.Instantiate<WizardBattlePortraitSlot>(portraitSlots.playerSlots[0], ((Component)portraitSlots.playerSlots[0]).transform.parent);
					portraitSlots.playerSlots.Add(val3);
					portraitSlots.slotBorderRenderers.Add(((Component)((Component)val3).transform.Find("Border")).GetComponent<Renderer>());
				}
				portraitSlots.playerSlots[k].cardSlot = ((BoardManager)Singleton<BoardManager3D>.Instance).playerSlots[k];
				Transform transform2 = ((Component)portraitSlots.slotBorderRenderers.Single((Renderer x) => ((Component)x).transform.IsChildOf(((Component)portraitSlots.playerSlots[k]).transform))).transform;
				Transform transform3 = ((Component)((Component)((Component)((BoardManager)Singleton<BoardManager3D>.Instance).playerSlots[k]).transform.Find("Quad")).GetComponent<Renderer>()).transform;
				Transform transform4 = ((Component)portraitSlots.playerSlots[k]).transform;
				Vector3 localScale = transform4.localScale;
				val4 = transform3.TransformVector(Vector3.right);
				float magnitude = ((Vector3)(ref val4)).magnitude;
				val4 = transform2.TransformVector(Vector3.right);
				transform4.localScale = localScale * (magnitude / ((Vector3)(ref val4)).magnitude);
				Transform transform5 = ((Component)portraitSlots.playerSlots[k]).transform;
				transform5.position += transform3.position - transform2.position;
			}
			int i2;
			for (i2 = 0; i2 < ((BoardManager)Singleton<BoardManager3D>.Instance).opponentSlots.Count; i2++)
			{
				while (i2 >= portraitSlots.opponentSlots.Count)
				{
					WizardBattlePortraitSlot val5 = Object.Instantiate<WizardBattlePortraitSlot>(portraitSlots.opponentSlots[0], ((Component)portraitSlots.opponentSlots[0]).transform.parent);
					portraitSlots.opponentSlots.Add(val5);
					portraitSlots.slotBorderRenderers.Add(((Component)((Component)val5).transform.Find("Border")).GetComponent<Renderer>());
				}
				portraitSlots.opponentSlots[i2].cardSlot = ((BoardManager)Singleton<BoardManager3D>.Instance).opponentSlots[i2];
				Transform transform6 = ((Component)portraitSlots.slotBorderRenderers.Single((Renderer x) => ((Component)x).transform.IsChildOf(((Component)portraitSlots.opponentSlots[i2]).transform))).transform;
				Transform transform7 = ((Component)((Component)((Component)((BoardManager)Singleton<BoardManager3D>.Instance).opponentSlots[i2]).transform.Find("Quad")).GetComponent<Renderer>()).transform;
				Transform transform8 = ((Component)portraitSlots.opponentSlots[i2]).transform;
				Vector3 localScale2 = transform8.localScale;
				val4 = transform7.TransformVector(Vector3.right);
				float magnitude2 = ((Vector3)(ref val4)).magnitude;
				val4 = transform6.TransformVector(Vector3.right);
				transform8.localScale = localScale2 * (magnitude2 / ((Vector3)(ref val4)).magnitude);
				Transform transform9 = ((Component)portraitSlots.opponentSlots[i2]).transform;
				transform9.position += transform7.position - transform6.position;
			}
			for (int num = 0; num < ((BoardManager)Singleton<BoardManager3D>.Instance).playerSlots.Count; num++)
			{
				portraitSlots.playerSlots[num].numberMeshes.AddRange((IEnumerable<Mesh>)(object)new Mesh[6]
				{
					Resources.Load<Mesh>("Art/Assets3D/AbilityIcons3d/Font_11"),
					Resources.Load<Mesh>("Art/Assets3D/AbilityIcons3d/Font_14"),
					Resources.Load<Mesh>("Art/Assets3D/AbilityIcons3d/Font_9"),
					Resources.Load<Mesh>("Art/Assets3D/AbilityIcons3d/Font"),
					Resources.Load<Mesh>("Art/Assets3D/AbilityIcons3d/Font_4"),
					Resources.Load<Mesh>("Art/Assets3D/AbilityIcons3d/Font_16")
				});
			}
			for (int num2 = 0; num2 < ((BoardManager)Singleton<BoardManager3D>.Instance).opponentSlots.Count; num2++)
			{
				portraitSlots.opponentSlots[num2].numberMeshes.AddRange((IEnumerable<Mesh>)(object)new Mesh[6]
				{
					Resources.Load<Mesh>("Art/Assets3D/AbilityIcons3d/Font_11"),
					Resources.Load<Mesh>("Art/Assets3D/AbilityIcons3d/Font_14"),
					Resources.Load<Mesh>("Art/Assets3D/AbilityIcons3d/Font_9"),
					Resources.Load<Mesh>("Art/Assets3D/AbilityIcons3d/Font"),
					Resources.Load<Mesh>("Art/Assets3D/AbilityIcons3d/Font_4"),
					Resources.Load<Mesh>("Art/Assets3D/AbilityIcons3d/Font_16")
				});
			}
			if (!(Singleton<BoardManager3D>.Instance is MagnificusBoardManager))
			{
				foreach (WizardBattlePortraitSlot playerSlot in portraitSlots.playerSlots)
				{
					playerSlot.statsPanelParent.RotateAround(((Component)playerSlot).transform.position, ((Component)playerSlot).transform.up, 180f);
				}
				foreach (Renderer slotBorderRenderer in portraitSlots.slotBorderRenderers)
				{
					slotBorderRenderer.forceRenderingOff = true;
				}
				foreach (WizardBattlePortraitSlot item in portraitSlots.playerSlots.Concat(portraitSlots.opponentSlots))
				{
					MainModule main = item.projectileSmoke.main;
					((MainModule)(ref main)).scalingMode = (ParticleSystemScalingMode)0;
					MainModule main2 = item.projectileDust.main;
					((MainModule)(ref main2)).scalingMode = (ParticleSystemScalingMode)0;
					((Component)item).gameObject.AddComponent<WizardSlotAbilityIcons>().Initialize(item);
					foreach (Renderer glowEdgeRenderer in item.glowEdgeRenderers)
					{
						glowEdgeRenderer.forceRenderingOff = true;
					}
				}
			}
			((BaseUnityPlugin)this).Logger.LogDebug((object)"Instantiated wizard portrait slot manager");
		}

		private void OnSceneUnloaded(Scene scene)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (snapshotTexturesByScene.TryGetValue(scene, out var value))
			{
				value.Release(scene, ((BaseUnityPlugin)this).Logger);
				snapshotTexturesByScene.Remove(scene);
			}
		}
	}
}
namespace DiskCardGame.Patches
{
	[HarmonyPatch(typeof(BoardManager))]
	internal static class BoardManagerPatches
	{
		private readonly struct SlotAssignment
		{
			internal readonly PlayableCard Card;

			internal readonly CardSlot Slot;

			internal readonly CardSlot Previous;

			internal readonly PlayableCard Displaced;

			public SlotAssignment(PlayableCard card, CardSlot slot, CardSlot previous, PlayableCard displaced)
			{
				Card = card;
				Slot = slot;
				Previous = previous;
				Displaced = displaced;
			}
		}

		private static readonly Dictionary<PlayableCard, int> temporaryMoveCounts = new Dictionary<PlayableCard, int>();

		[HarmonyPostfix]
		[HarmonyPatch(typeof(BoardManager3D), "CleanUp")]
		private static IEnumerator CleanUp(IEnumerator original, BoardManager3D __instance)
		{
			yield return original;
			WizardPortraitSlotManager instance = Singleton<WizardPortraitSlotManager>.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				yield break;
			}
			foreach (WizardBattlePortraitSlot item in instance.playerSlots.Concat(instance.opponentSlots))
			{
				WizardBattlePortraitSlotPatches.ReleasePortrait(item);
				((Component)item.statsPanelParent).gameObject.SetActive(false);
				((Component)item.queueCardParent).gameObject.SetActive(false);
				((Component)item.glowSlotParent).gameObject.SetActive(false);
			}
			instance.SetSlotsShown(false, false);
		}

		[HarmonyTranspiler]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		private static IEnumerable<CodeInstruction> AssignCardRotation(IEnumerable<CodeInstruction> instructions)
		{
			return Transpilers.MethodReplacer(instructions, (MethodBase)AccessTools.PropertyGetter(typeof(Transform), "rotation"), (MethodBase)AccessTools.Method(typeof(BoardManagerPatches), "GetCardSlotRotation", (Type[])null, (Type[])null));
		}

		private static Quaternion GetCardSlotRotation(Transform target)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			Quaternion val = target.rotation;
			CardSlot componentInParent = ((Component)target).GetComponentInParent<CardSlot>();
			if ((Object)(object)componentInParent != (Object)null && !componentInParent.IsPlayerSlot && (Object)(object)componentInParent.Card != (Object)null && ((Card)componentInParent.Card).Anim is GravestoneCardAnimationController && (Object)(object)componentInParent.opposingSlot != (Object)null && Vector3.Dot(target.up, ((Component)componentInParent.opposingSlot).transform.GetChild(0).up) < 0f)
			{
				val *= Quaternion.Euler(0f, 0f, 180f);
			}
			return val;
		}

		[HarmonyTranspiler]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		private static IEnumerable<CodeInstruction> PullHookRotation(IEnumerable<CodeInstruction> instructions)
		{
			return Transpilers.MethodReplacer(instructions, (MethodBase)AccessTools.PropertySetter(typeof(Transform), "eulerAngles"), (MethodBase)AccessTools.Method(typeof(BoardManagerPatches), "SetHookedCardRotation", (Type[])null, (Type[])null));
		}

		private static void SetHookedCardRotation(Transform target, Vector3 angles)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			PlayableCard component = ((Component)target).GetComponent<PlayableCard>();
			if (!(((component != null) ? ((Card)component).Anim : null) is GravestoneCardAnimationController))
			{
				target.eulerAngles = angles;
			}
		}

		[HarmonyTranspiler]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		private static IEnumerable<CodeInstruction> SyncPortraitAtSlotAssignment(IEnumerable<CodeInstruction> instructions, ILGenerator generator, MethodBase __originalMethod)
		{
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Expected O, but got Unknown
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Expected O, but got Unknown
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Expected O, but got Unknown
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Expected O, but got Unknown
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Expected O, but got Unknown
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Expected O, but got Unknown
			List<CodeInstruction> code = instructions.ToList();
			FieldInfo slot = AccessTools.Field(__originalMethod.DeclaringType, "slot");
			FieldInfo fieldInfo = AccessTools.Field(__originalMethod.DeclaringType, "transitionDuration");
			FieldInfo resolve = AccessTools.Field(__originalMethod.DeclaringType, "resolveTriggers");
			MethodInfo setCard = AccessTools.PropertySetter(typeof(CardSlot), "Card");
			MethodInfo setSlot = AccessTools.PropertySetter(typeof(PlayableCard), "Slot");
			int[] array = (from i in Enumerable.Range(3, Math.Max(0, code.Count - 8))
				where slot != null && CodeInstructionExtensions.Calls(code[i], setCard) && CodeInstructionExtensions.LoadsField(code[i - 3], slot, false) && code[i - 2].opcode == code[i + 1].opcode && object.Equals(code[i - 2].operand, code[i + 1].operand) && code[i - 1].opcode == OpCodes.Ldfld && object.Equals(code[i - 1].operand, code[i + 2].operand) && code[i + 3].opcode == OpCodes.Ldarg_0 && CodeInstructionExtensions.LoadsField(code[i + 4], slot, false) && CodeInstructionExtensions.Calls(code[i + 5], setSlot)
				select i).ToArray();
			int[] array2 = (from i in Enumerable.Range(1, Math.Max(0, code.Count - 1))
				where resolve != null && CodeInstructionExtensions.LoadsField(code[i], resolve, false) && code[i - 1].opcode == OpCodes.Ldarg_0
				select i).ToArray();
			if (slot?.FieldType != typeof(CardSlot) || fieldInfo?.FieldType != typeof(float) || resolve?.FieldType != typeof(bool) || array.Length != 1 || array2.Length != 1 || array2[0] <= array[0] + 5)
			{
				Debug.LogWarning((object)"3DRenderer: could not locate the paired slot assignments for Wizard portraits.");
				return code;
			}
			int num = array[0];
			int index = array2[0] - 1;
			LocalBuilder localBuilder = generator.DeclareLocal(typeof(SlotAssignment));
			code.InsertRange(index, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[6]
			{
				CodeInstructionExtensions.MoveLabelsFrom(new CodeInstruction(OpCodes.Ldloc, (object)localBuilder), code[index]),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)fieldInfo),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)resolve),
				CodeInstruction.Call(typeof(BoardManagerPatches), "SyncCommittedPortrait", (Type[])null, (Type[])null)
			});
			code[num].opcode = OpCodes.Call;
			code[num].operand = AccessTools.Method(typeof(BoardManagerPatches), "SetDestinationCard", (Type[])null, (Type[])null);
			code.Insert(num + 1, new CodeInstruction(OpCodes.Stloc, (object)localBuilder));
			return code;
		}

		private static SlotAssignment SetDestinationCard(CardSlot slot, PlayableCard card)
		{
			SlotAssignment result = new SlotAssignment(card, slot, card.Slot, slot.Card);
			slot.Card = card;
			return result;
		}

		private static void SyncCommittedPortrait(SlotAssignment assignment, float transitionDuration, bool resolveTriggers)
		{
			PlayableCard card = assignment.Card;
			CardSlot slot = assignment.Slot;
			WizardPortraitSlotManager instance = Singleton<WizardPortraitSlotManager>.Instance;
			if ((Object)(object)instance != (Object)null && (Object)(object)card != (Object)null && (Object)(object)slot != (Object)null && !card.Dead && (Object)(object)card.Slot == (Object)(object)slot && (Object)(object)slot.Card == (Object)(object)card)
			{
				SynchronizeAssignedPortrait(instance.GetPortraitSlotForCardSlot(slot), spawnImmediately: (Object)(object)assignment.Previous != (Object)(object)slot && ((Object)(object)assignment.Previous != (Object)null || !resolveTriggers || temporaryMoveCounts.ContainsKey(card)), card: card, displacedCard: assignment.Displaced, transitionDuration: transitionDuration);
			}
		}

		private static void SynchronizeAssignedPortrait(WizardBattlePortraitSlot destination, PlayableCard card, PlayableCard displacedCard, float transitionDuration, bool spawnImmediately)
		{
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			CardAnimationController anim = ((Card)card).Anim;
			WizardCardAnimationController val = (WizardCardAnimationController)(object)((anim is WizardCardAnimationController) ? anim : null);
			WizardBattle3DPortrait val2 = (((Object)(object)val != (Object)null) ? val.WizardPortrait : null);
			WizardBattlePortraitSlot val3 = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponentInParent<WizardBattlePortraitSlot>() : null);
			if ((Object)(object)destination == (Object)null)
			{
				if ((Object)(object)val3 != (Object)null && (Object)(object)val3.WizardPortrait == (Object)(object)val2)
				{
					WizardBattlePortraitSlotPatches.ReleasePortrait(val3);
				}
				else if ((Object)(object)val2 != (Object)null)
				{
					WizardBattlePortraitSlotPatches.DestroyPortrait(val2);
				}
				return;
			}
			if ((Object)(object)destination.WizardPortrait != (Object)(object)val2)
			{
				if ((Object)(object)displacedCard != (Object)null && temporaryMoveCounts.ContainsKey(displacedCard))
				{
					CardAnimationController anim2 = ((Card)displacedCard).Anim;
					WizardCardAnimationController val4 = (WizardCardAnimationController)(object)((anim2 is WizardCardAnimationController) ? anim2 : null);
					if (val4 != null && (Object)(object)val4.WizardPortrait != (Object)null && (Object)(object)destination.WizardPortrait == (Object)(object)val4.WizardPortrait)
					{
						SuspendPortrait(destination);
						goto IL_00cb;
					}
				}
				WizardBattlePortraitSlotPatches.ReleasePortrait(destination);
			}
			goto IL_00cb;
			IL_00cb:
			if ((Object)(object)val2 == (Object)null)
			{
				if (!spawnImmediately || (Object)(object)val == (Object)null)
				{
					return;
				}
				WizardBattlePortraitSlotPatches.SpawnPortraitImmediately(destination, card, ((Card)card).Info);
			}
			else
			{
				if ((Object)(object)destination.WizardPortrait == (Object)(object)val2 && (Object)(object)((Component)val2).transform.parent == (Object)(object)((Component)destination).transform)
				{
					return;
				}
				if ((Object)(object)val3 != (Object)null && (Object)(object)val3 != (Object)(object)destination && (Object)(object)val3.WizardPortrait == (Object)(object)val2)
				{
					WizardBattlePortraitSlotPatches.UnbindPortrait(val3);
				}
				destination.WizardPortrait = val2;
				Transform transform = ((Component)val2).transform;
				Quaternion localRotation = transform.localRotation;
				Vector3 localScale = transform.localScale;
				transform.SetParent(((Component)destination).transform);
				transform.localScale = localScale;
				((Component)val2).gameObject.SetActive(true);
				Tween.LocalPosition(transform, Vector3.zero, transitionDuration, 0.05f, Tween.EaseOut, (LoopType)0, (Action)null, (Action)null, true);
				Tween.Rotation(transform, ((Component)destination).transform.rotation * localRotation, transitionDuration, 0f, Tween.EaseOut, (LoopType)0, (Action)null, (Action)null, true);
				if ((Object)(object)val2.anim != (Object)null && !((Component)val2.anim).gameObject.activeSelf)
				{
					val2.PlaySpawnAnimation(true);
				}
			}
			WizardBattlePortraitSlotPatches.ShowStatsPanelForCurrentCard(destination);
		}

		[HarmonyPostfix]
		[HarmonyPatch("MoveAllCardsClockwise")]
		private static IEnumerator MoveAllCardsClockwise(IEnumerator original, BoardManager __instance)
		{
			if ((Object)(object)Singleton<WizardPortraitSlotManager>.Instance == (Object)null)
			{
				yield return original;
				yield break;
			}
			PlayableCard[] cards = __instance.AllSlots.Select((CardSlot slot) => slot.Card).ToArray();
			using (original as IDisposable)
			{
				if (original.MoveNext())
				{
					yield return FollowTemporaryMoves(original, cards, slotsCleared: true);
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StrafeSwap), "DoStrafe")]
		private static IEnumerator PreserveSwapPortrait(IEnumerator original, StrafeSwap __instance, CardSlot toLeft, CardSlot toRight)
		{
			if ((Object)(object)Singleton<WizardPortraitSlotManager>.Instance == (Object)null)
			{
				yield return original;
				yield break;
			}
			using (original as IDisposable)
			{
				if (original.MoveNext())
				{
					CardSlot val = (((Strafe)__instance).movingLeft ? toLeft : toRight);
					PlayableCard val2 = (((Object)(object)val != (Object)null) ? val.Card : null);
					yield return FollowTemporaryMoves(original, (IEnumerable<PlayableCard>)(object)new PlayableCard[1] { val2 });
				}
			}
		}

		private static IEnumerator FollowTemporaryMoves(IEnumerator original, IEnumerable<PlayableCard> cards, bool slotsCleared = false)
		{
			List<(PlayableCard Card, WizardBattle3DPortrait Portrait)> moves = new List<(PlayableCard, WizardBattle3DPortrait)>();
			try
			{
				foreach (PlayableCard item2 in cards.Distinct())
				{
					if ((Object)(object)item2 != (Object)null)
					{
						CardAnimationController anim = ((Card)item2).Anim;
						WizardCardAnimationController val = (WizardCardAnimationController)(object)((anim is WizardCardAnimationController) ? anim : null);
						if (val != null)
						{
							temporaryMoveCounts.TryGetValue(item2, out var value);
							temporaryMoveCounts[item2] = value + 1;
							moves.Add((item2, val.WizardPortrait));
						}
					}
				}
				if (slotsCleared)
				{
					foreach (var item3 in moves)
					{
						WizardBattle3DPortrait item = item3.Portrait;
						WizardBattlePortraitSlot val2 = (((Object)(object)item != (Object)null) ? ((Component)item).GetComponentInParent<WizardBattlePortraitSlot>() : null);
						if ((Object)(object)val2 != (Object)null && (Object)(object)val2.WizardPortrait == (Object)(object)item && (Object)(object)val2.CardSlot != (Object)null && (Object)(object)val2.CardSlot.Card == (Object)null)
						{
							SuspendPortrait(val2);
						}
					}
				}
				do
				{
					yield return original.Current;
				}
				while (original.MoveNext());
			}
			finally
			{
				foreach (var (key, portrait) in moves)
				{
					if (temporaryMoveCounts[key] == 1)
					{
						temporaryMoveCounts.Remove(key);
						WizardBattlePortraitSlotPatches.ReleaseDetachedPortrait(portrait);
					}
					else
					{
						temporaryMoveCounts[key]--;
					}
				}
			}
		}

		private static void SuspendPortrait(WizardBattlePortraitSlot slot)
		{
			((Component)WizardBattlePortraitSlotPatches.UnbindPortrait(slot)).gameObject.SetActive(false);
		}
	}
	[HarmonyPatch]
	internal static class BuildTotemSequencerPatches
	{
		[HarmonyTargetMethod]
		private static MethodBase TargetMethod()
		{
			return AccessTools.Method(AccessTools.Inner(typeof(BuildTotemSequencer), "<>c"), "<GenerateTotemChoices>b__26_0", (Type[])null, (Type[])null);
		}

		[HarmonyPrefix]
		private static bool SkipUnregisteredAbility(Ability x, ref bool __result)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)AbilitiesUtil.GetInfo(x) != (Object)null)
			{
				return true;
			}
			__result = true;
			return false;
		}
	}
	[HarmonyPatch(typeof(CardAbilityIcons))]
	internal static class CardAbilityIconsPatches
	{
		private sealed class IconLists
		{
			private readonly List<AbilityIconInteractable> merge;

			private readonly List<AbilityIconInteractable> totem;

			private readonly List<AbilityIconInteractable> emissiveTotem;

			private readonly Material emissiveMaterial;

			private readonly Material totemMaterial;

			private readonly CardAbilityIcons source;

			internal readonly CardAnimationControllerManager Manager;

			internal IconLists(CardAbilityIcons target, CardAbilityIcons source, CardAnimationControllerManager manager, bool useMerge, bool useTotem)
			{
				this.source = source;
				Manager = manager;
				merge = target.mergeIcons;
				totem = target.totemIcons;
				emissiveTotem = target.emissiveTotemIcons;
				emissiveMaterial = target.emissiveIconMat;
				totemMaterial = target.totemIconMat;
				if (useMerge)
				{
					target.mergeIcons = source.mergeIcons;
				}
				CardAbilityIcons val;
				if (useTotem)
				{
					target.totemIcons = source.totemIcons;
					target.emissiveTotemIcons = source.emissiveTotemIcons;
					val = target;
					if (val.totemIconMat == null)
					{
						val.totemIconMat = source.totemIconMat;
					}
				}
				val = target;
				if (val.emissiveIconMat == null)
				{
					val.emissiveIconMat = source.emissiveIconMat;
				}
			}

			internal void Restore(CardAbilityIcons target)
			{
				if (target.mergeIcons == source.mergeIcons)
				{
					target.mergeIcons = merge;
				}
				if (target.totemIcons == source.totemIcons)
				{
					target.totemIcons = totem;
				}
				if (target.emissiveTotemIcons == source.emissiveTotemIcons)
				{
					target.emissiveTotemIcons = emissiveTotem;
				}
				if (target.emissiveIconMat == source.emissiveIconMat)
				{
					target.emissiveIconMat = emissiveMaterial;
				}
				if (target.totemIconMat == source.totemIconMat)
				{
					target.totemIconMat = totemMaterial;
				}
			}
		}

		[HarmonyTranspiler]
		[HarmonyPatch("UpdateAbilityIcons")]
		private static IEnumerable<CodeInstruction> UpdateAbilityIcons(IEnumerable<CodeInstruction> instructions)
		{
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Expected O, but got Unknown
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Expected O, but got Unknown
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Expected O, but got Unknown
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Expected O, but got Unknown
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Expected O, but got Unknown
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Expected O, but got Unknown
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Expected O, but got Unknown
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			FieldInfo fieldInfo = AccessTools.Field(typeof(CardModificationInfo), "fromCardMerge");
			FieldInfo fieldInfo2 = AccessTools.Field(typeof(CardModificationInfo), "fromTotem");
			FieldInfo fieldInfo3 = AccessTools.Field(typeof(CardModificationInfo), "fromLatch");
			CodeInstruction val = CodeInstruction.CallClosure<Func<bool, CardAbilityIcons, CardInfo, bool>>((Func<bool, CardAbilityIcons, CardInfo, bool>)((bool flag, CardAbilityIcons instance, CardInfo info) => flag && (Plugin.Config.UsingPaperMergeAbilities || !UsesPaperModificationIcons(instance, info))));
			CodeInstruction val2 = CodeInstruction.CallClosure<Func<bool, CardAbilityIcons, CardInfo, bool>>((Func<bool, CardAbilityIcons, CardInfo, bool>)((bool flag, CardAbilityIcons instance, CardInfo info) => flag && (Plugin.Config.UsingPaperTotemAbilities || !UsesPaperModificationIcons(instance, info))));
			CodeInstruction val3 = CodeInstruction.CallClosure<Func<bool, CardAbilityIcons, CardInfo, bool>>((Func<bool, CardAbilityIcons, CardInfo, bool>)delegate(bool flag, CardAbilityIcons instance, CardInfo info)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Invalid comparison between Unknown and I4
				if ((int)info.temple != 2 && (flag &= Plugin.Config.UsingDiskLatchAbility))
				{
					CardAnimationControllerManager componentInParent = ((Component)instance).GetComponentInParent<CardAnimationControllerManager>();
					if ((Object)(object)componentInParent != (Object)null)
					{
						DiskCardAnimationController val4 = componentInParent.AddAnim<DiskCardAnimationController>(includeDerivedTypes: true, (Action<DiskCardAnimationController>)null);
						DiskRenderStatsLayer val5 = default(DiskRenderStatsLayer);
						if ((Object)(object)val4 != (Object)null && ((Component)((CardAnimationController)val4).cardRenderer).TryGetComponent<DiskRenderStatsLayer>(ref val5))
						{
							((Behaviour)val5).enabled = true;
						}
						if ((Object)(object)val4 != (Object)null && (Object)(object)instance.latchIcon == (Object)null)
						{
							instance.latchIcon = ((Component)((CardAnimationController)val4).cardRenderer).GetComponentInChildren<CardAbilityIcons>(true)?.latchIcon;
						}
					}
				}
				return flag;
			});
			for (int num = 0; num < list.Count; num++)
			{
				if (CodeInstructionExtensions.LoadsField(list[num], fieldInfo, false))
				{
					list.InsertRange(num + 1, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[3]
					{
						new CodeInstruction(OpCodes.Ldarg_0, (object)null),
						new CodeInstruction(OpCodes.Ldarg_1, (object)null),
						new CodeInstruction(val)
					});
					num += 3;
				}
				else if (CodeInstructionExtensions.LoadsField(list[num], fieldInfo2, false))
				{
					list.InsertRange(num + 1, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[3]
					{
						new CodeInstruction(OpCodes.Ldarg_0, (object)null),
						new CodeInstruction(OpCodes.Ldarg_1, (object)null),
						new CodeInstruction(val2)
					});
					num += 3;
				}
				else if (CodeInstructionExtensions.LoadsField(list[num], fieldInfo3, false))
				{
					list.InsertRange(num + 1, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[3]
					{
						new CodeInstruction(OpCodes.Ldarg_0, (object)null),
						new CodeInstruction(OpCodes.Ldarg_1, (object)null),
						new CodeInstruction(val3)
					});
					num += 3;
				}
			}
			return list;
		}

		[HarmonyPrefix]
		[HarmonyPatch("UpdateAbilityIcons")]
		private static void PrepareBorrowedIcons(CardAbilityIcons __instance, CardInfo info, List<CardModificationInfo> mods, out IconLists __state)
		{
			__state = null;
			CardAnimationControllerManager componentInParent = ((Component)__instance).GetComponentInParent<CardAnimationControllerManager>();
			if (!((Object)(object)componentInParent == (Object)null) && !((Object)(object)componentInParent.Card == (Object)null) && !((Object)(object)componentInParent.Card.AbilityIcons != (Object)(object)__instance) && componentInParent.UsesBorrowedPaperIcons && !((Object)(object)info == (Object)null))
			{
				List<CardModificationInfo> source = info.Mods.Concat(mods ?? Enumerable.Empty<CardModificationInfo>()).ToList();
				bool flag = Plugin.Config.UsingPaperMergeAbilities && source.Any((CardModificationInfo mod) => mod.fromCardMerge);
				bool flag2 = Plugin.Config.UsingPaperTotemAbilities && source.Any((CardModificationInfo mod) => mod.fromTotem);
				componentInParent.SetBorrowedAbilityUsage(flag, flag2);
				if (componentInParent.TryGetBorrowedAbilityIcons(out var _, out var icons))
				{
					__state = new IconLists(__instance, icons, componentInParent, flag, flag2);
				}
			}
		}

		[HarmonyFinalizer]
		[HarmonyPatch("UpdateAbilityIcons")]
		private static void RestoreBorrowedIcons(CardAbilityIcons __instance, IconLists __state)
		{
			if (__state != null)
			{
				__state.Restore(__instance);
				__state.Manager.ApplyBorrowedInteraction();
			}
		}

		private static bool UsesPaperModificationIcons(CardAbilityIcons instance, CardInfo info)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Invalid comparison between Unknown and I4
			CardAnimationControllerManager componentInParent = ((Component)instance).GetComponentInParent<CardAnimationControllerManager>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				return componentInParent.UsesBorrowedPaperIcons;
			}
			bool flag = (Object)(object)info != (Object)null;
			if (flag)
			{
				CardTemple temple = info.temple;
				bool flag2 = (((int)temple == 0 || (int)temple == 3) ? true : false);
				flag = !flag2;
			}
			return flag;
		}

		[HarmonyPostfix]
		[HarmonyPatch("SetInteractionEnabled")]
		private static void SetInteractionEnabled(CardAbilityIcons __instance, bool interactionEnabled)
		{
			((Component)__instance).GetComponentInParent<CardAnimationControllerManager>()?.SetBorrowedInteraction(__instance, interactionEnabled);
		}
	}
	[HarmonyPatch(typeof(CardAnimationController))]
	public static class CardAnimationControllerExtension
	{
		[SpecialName]
		public sealed class <G>$649D48BAA6F19C7ADA8F4F9C54F8EA09
		{
			[SpecialName]
			public static class <M>$011FD489D441D5E3F95518CBAAA9EE67
			{
			}

			[ExtensionMarker("<M>$011FD489D441D5E3F95518CBAAA9EE67")]
			public Transform WeaponParent
			{
				[ExtensionMarker("<M>$011FD489D441D5E3F95518CBAAA9EE67")]
				get
				{
					throw new NotSupportedException();
				}
			}

			[ExtensionMarker("<M>$011FD489D441D5E3F95518CBAAA9EE67")]
			public WizardBattle3DPortrait WizardPortrait
			{
				[ExtensionMarker("<M>$011FD489D441D5E3F95518CBAAA9EE67")]
				get
				{
					throw new NotSupportedException();
				}
				[ExtensionMarker("<M>$011FD489D441D5E3F95518CBAAA9EE67")]
				set
				{
					throw new NotSupportedException();
				}
			}

			[ExtensionMarker("<M>$011FD489D441D5E3F95518CBAAA9EE67")]
			public RenderStatsLayer StatsLayer
			{
				[ExtensionMarker("<M>$011FD489D441D5E3F95518CBAAA9EE67")]
				get
				{
					throw new NotSupportedException();
				}
			}
		}

		public static T ValidateComponent<T>(this Component __instance) where T : Component
		{
			return __instance.GetComponent<T>() ?? __instance.gameObject.AddComponent<T>();
		}

		public static Transform get_WeaponParent(CardAnimationController __instance)
		{
			object obj = ((object)((__instance is DiskCardAnimationController) ? __instance : null)) ?? ((object)((Component)__instance).GetComponent<CardAnimationControllerManager>()?.AddAnim<DiskCardAnimationController>(includeDerivedTypes: true, (Action<DiskCardAnimationController>)null));
			if (obj == null)
			{
				return null;
			}
			return ((DiskCardAnimationController)obj).WeaponParent;
		}

		public static WizardBattle3DPortrait get_WizardPortrait(CardAnimationController __instance)
		{
			object obj = ((object)((__instance is WizardCardAnimationController) ? __instance : null)) ?? ((object)((Component)__instance).GetComponent<CardAnimationControllerManager>()?.AddAnim<WizardCardAnimationController>(includeDerivedTypes: true, (Action<WizardCardAnimationController>)null));
			if (obj == null)
			{
				return null;
			}
			return ((WizardCardAnimationController)obj).WizardPortrait;
		}

		public static void set_WizardPortrait(CardAnimationController __instance, WizardBattle3DPortrait value)
		{
			object obj = ((object)((__instance is WizardCardAnimationController) ? __instance : null)) ?? ((object)((Component)__instance).GetComponent<CardAnimationControllerManager>()?.AddAnim<WizardCardAnimationController>(includeDerivedTypes: true, (Action<WizardCardAnimationController>)null));
			if (obj != null)
			{
				((WizardCardAnimationController)obj).WizardPortrait = value;
			}
		}

		public static RenderStatsLayer get_StatsLayer(CardAnimationController __instance)
		{
			if (__instance is PaperCardAnimationController)
			{
				return (RenderStatsLayer)(object)((IEnumerable<PaperRenderStatsLayer>)((Component)__instance).GetComponentsInChildren<PaperRenderStatsLayer>(true)).FirstOrDefault((Func<PaperRenderStatsLayer, bool>)((PaperRenderStatsLayer x) => !(x is CanvasRenderStatsLayer)));
			}
			if (__instance is GravestoneCardAnimationController)
			{
				return (RenderStatsLayer)(object)((Component)__instance).GetComponentInChildren<GravestoneRenderStatsLayer>(true);
			}
			if (__instance is DiskCardAnimationController)
			{
				return (RenderStatsLayer)(object)((Component)__instance).GetComponentInChildren<DiskRenderStatsLayer>(true);
			}
			if (__instance is WizardCardAnimationController)
			{
				return (RenderStatsLayer)(object)((Component)__instance).GetComponentInChildren<CanvasRenderStatsLayer>(true);
			}
			return ((Component)__instance).GetComponentInChildren<RenderStatsLayer>(true);
		}

		public static void PlayGlitchOutAnimation(this CardAnimationController __instance)
		{
			if (__instance is PaperCardAnimationController)
			{
				CardAnimationController obj = __instance;
				((PaperCardAnimationController)((obj is PaperCardAnimationController) ? obj : null)).PlayGlitchOutAnimation();
				return;
			}
			if (__instance is GravestoneCardAnimationController)
			{
				CardAnimationController obj2 = __instance;
				((GravestoneCardAnimationController)((obj2 is GravestoneCardAnimationController) ? obj2 : null)).PlayGlitchOutAnimation();
				return;
			}
			if (__instance is WizardCardAnimationController)
			{
				CustomCoroutine.WaitThenExecute(0.2f, (Action)delegate
				{
					CardAnimationController obj3 = __instance;
					WizardBattle3DPortrait wizardPortrait = ((WizardCardAnimationController)((obj3 is WizardCardAnimationController) ? obj3 : null)).WizardPortrait;
					if ((Object)(object)wizardPortrait != (Object)null)
					{
						Object.Destroy((Object)(object)((Component)wizardPortrait).gameObject);
					}
				}, true);
			}
			GlitchOutAssetEffect.GlitchModel(((Component)__instance.Card.StatsLayer.Renderer).transform, false, true);
		}

		public static void PlayBloodCostParticles(this CardAnimationController __instance)
		{
			if (__instance is CardAnimationController3D)
			{
				object obj = ((object)((__instance is PaperCardAnimationController) ? __instance : null)) ?? ((object)((Component)__instance).GetComponent<CardAnimationControllerManager>()?.AddAnim<PaperCardAnimationController>(includeDerivedTypes: true, (Action<PaperCardAnimationController>)null));
				if (obj != null)
				{
					((PaperCardAnimationController)obj).PlayBloodCostParticles();
				}
			}
		}

		public static void SetMarkedForFishHook(this CardAnimationController __instance, bool marked)
		{
			object obj = ((object)((__instance is PaperCardAnimationController) ? __instance : null)) ?? ((object)((Component)__instance).GetComponent<CardAnimationControllerManager>()?.AddAnim<PaperCardAnimationController>(includeDerivedTypes: true, (Action<PaperCardAnimationController>)null));
			if (obj != null)
			{
				((PaperCardAnimationController)obj).SetMarkedForFishHook(marked);
			}
		}

		public static void SpawnHoloPortrait(this CardAnimationController __instance, GameObject prefab)
		{
			object obj = ((object)((__instance is DiskCardAnimationController) ? __instance : null)) ?? ((object)((Component)__instance).GetComponent<CardAnimationControllerManager>()?.AddAnim<DiskCardAnimationController>(includeDerivedTypes: true, (Action<DiskCardAnimationController>)null));
			if (obj != null)
			{
				((DiskCardAnimationController)obj).SpawnHoloPortrait(prefab);
			}
		}

		public static void SetWeaponMesh(this CardAnimationController __instance, DiskCardWeapon weapon)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			object obj = ((object)((__instance is DiskCardAnimationController) ? __instance : null)) ?? ((object)((Component)__instance).GetComponent<CardAnimationControllerManager>()?.AddAnim<DiskCardAnimationController>(includeDerivedTypes: true, (Action<DiskCardAnimationController>)null));
			if (obj != null)
			{
				((DiskCardAnimationController)obj).SetWeaponMesh(weapon);
			}
		}

		public static void ShowWeaponAnim(this CardAnimationController __instance)
		{
			object obj = ((object)((__instance is DiskCardAnimationController) ? __instance : null)) ?? ((object)((Component)__instance).GetComponent<CardAnimationControllerManager>()?.AddAnim<DiskCardAnimationController>(includeDerivedTypes: true, (Action<DiskCardAnimationController>)null));
			if (obj != null)
			{
				((DiskCardAnimationController)obj).ShowWeaponAnim();
			}
		}

		public static void HideWeaponAnim(this CardAnimationController __instance)
		{
			object obj = ((object)((__instance is DiskCardAnimationController) ? __instance : null)) ?? ((object)((Component)__instance).GetComponent<CardAnimationControllerManager>()?.AddAnim<DiskCardAnimationController>(includeDerivedTypes: true, (Action<DiskCardAnimationController>)null));
			if (obj != null)
			{
				((DiskCardAnimationController)obj).HideWeaponAnim();
			}
		}

		public static void AimWeaponAnim(this CardAnimationController __instance, Vector3 target)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			object obj = ((object)((__instance is DiskCardAnimationController) ? __instance : null)) ?? ((object)((Component)__instance).GetComponent<CardAnimationControllerManager>()?.AddAnim<DiskCardAnimationController>(includeDerivedTypes: true, (Action<DiskCardAnimationController>)null));
			if (obj != null)
			{
				((DiskCardAnimationController)obj).AimWeaponAnim(target);
			}
		}

		public static void Expand(this CardAnimationController __instance, bool immediate = false)
		{
			CardAnimationController obj = ((__instance is DiskCardAnimationController) ? __instance : null);
			if (obj != null)
			{
				((DiskCardAnimationController)obj).Expand(immediate);
			}
		}

		public static void Contract(this CardAnimationController __instance)
		{
			CardAnimationController obj = ((__instance is DiskCardAnimationController) ? __instance : null);
			if (obj != null)
			{
				((DiskCardAnimationController)obj).Contract();
			}
		}

		public static void SetHologramShown(this CardAnimationController __instance, bool shown, Material hologramMaterial = null)
		{
			object obj = ((object)((__instance is DiskCardAnimationController) ? __instance : null)) ?? ((object)((Component)__instance).GetComponent<CardAnimationControllerManager>()?.AddAnim<DiskCardAnimationController>(includeDerivedTypes: true, (Action<DiskCardAnimationController>)null));
			if (obj != null)
			{
				((DiskCardAnimationController)obj).SetHologramShown(shown, hologramMaterial);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(CardAnimationController3D), "SetRendererYPos")]
		private static void SetRendererYPos(CardAnimationController3D __instance, float yPos)
		{
			if (((Behaviour)__instance).enabled)
			{
				CardAnimationControllerManager component = ((Component)__instance).GetComponent<CardAnimationControllerManager>();
				if (component != null)
				{
					component.intendedRendererYPos = yPos - CardAnimationControllerManager.GetGiantRendererYOffset((CardAnimationController)(object)__instance);
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPriority(0)]
		[HarmonyPatch(typeof(PaperCardAnimationController), "PlayGlitchOutAnimation")]
		private static bool PlayGlitchOutAnimation(CardAnimationController __instance, bool __runOriginal)
		{
			if (__runOriginal)
			{
				if ((Object)(object)__instance.PlayableCard != (Object)null)
				{
					return true;
				}
				if ((Object)(object)__instance.Card != (Object)null && (Object)(object)__instance.Card.StatsLayer != (Object)null && (Object)(object)__instance.Card.StatsLayer.Renderer != (Object)null)
				{
					GlitchOutAssetEffect.GlitchModel(((Component)__instance.Card.StatsLayer.Renderer).transform, false, true);
				}
			}
			return false;
		}
	}
	[HarmonyPatch]
	internal static class CardAnimationControllerExtensionPatches
	{
		[HarmonyTargetMethods]
		private static IEnumerable<MethodBase> TargetMethods()
		{
			yield return AccessTools.Method(typeof(BountyHunter), "Awake", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(ChessboardEnemyBattleSequencer), "GlitchOutCard", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(DiskTalkingCard), "SetWeaponMesh", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(FishHookGrab), "SetHookTargetSlot", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(HologramPortrait), "ApplyAppearance", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(Part3CombatPhaseManager), "VisualizeStartSniperAbility", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(Part3CombatPhaseManager), "VisualizeAimSniperAbility", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(PlayerHand), "OnCardSelected", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(Sentry), "Awake", (Type[])null, (Type[])null);
			yield return AccessTools.Method(AccessTools.Inner(typeof(CardSingleChoicesSequencer), "<>c__DisplayClass13_0"), "<CardSelectionSequence>b__2", (Type[])null, (Type[])null);
			yield return AccessTools.Method(AccessTools.Inner(typeof(TelegrapherBossOpponent), "<>c__DisplayClass20_0"), "<SendCardSequence>b__5", (Type[])null, (Type[])null);
			yield return AccessTools.Method(AccessTools.Inner(typeof(TelegrapherBossOpponent), "<>c__DisplayClass20_0"), "<SendCardSequence>b__6", (Type[])null, (Type[])null);
			yield return AccessTools.EnumeratorMoveNext((MethodBase)AccessTools.Method(typeof(DiskDriveModSequencer), "ModifyCardSequence", (Type[])null, (Type[])null));
			yield return AccessTools.EnumeratorMoveNext((MethodBase)AccessTools.Method(typeof(Latch), "OnPreDeathAnimation", (Type[])null, (Type[])null));
			yield return AccessTools.EnumeratorMoveNext((MethodBase)AccessTools.Method(typeof(LeshyGoodbyeBattleSequencer), "EndSceneSequence", (Type[])null, (Type[])null));
			yield return AccessTools.EnumeratorMoveNext((MethodBase)AccessTools.Method(typeof(ModifySideDeckSequencer), "CreateAndInsertCard", (Type[])null, (Type[])null));
			yield return AccessTools.EnumeratorMoveNext((MethodBase)AccessTools.Method(typeof(Part3CombatPhaseManager), "ShowCardBlocked", (Type[])null, (Type[])null));
			yield return AccessTools.EnumeratorMoveNext((MethodBase)AccessTools.Method(typeof(PhotographerSnapshotManager), "ApplySlotState", (Type[])null, (Type[])null));
			yield return AccessTools.EnumeratorMoveNext((MethodBase)AccessTools.Method(typeof(Sentry), "FireAtOpposingSlot", (Type[])null, (Type[])null));
			yield return AccessTools.EnumeratorMoveNext((MethodBase)AccessTools.Method(typeof(Tutorial1BattleSequencer), "WaitForViewChange", (Type[])null, (Type[])null));
		}

		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, MethodBase __originalMethod)
		{
			List<CodeInstruction> list = instructions.ToList();
			if (__originalMethod.DeclaringType.DeclaringType == typeof(Latch))
			{
				MethodInfo operand = AccessTools.Method(typeof(CardAnimationControllerExtensionPatches), "ResolveLatchAnim", (Type[])null, (Type[])null);
				{
					foreach (CodeInstruction item in list)
					{
						if (CodeInstructionExtensions.Is(item, OpCodes.Isinst, (MemberInfo)typeof(DiskCardAnimationController)))
						{
							item.opcode = OpCodes.Call;
							item.operand = operand;
						}
					}
					return list;
				}
			}
			for (int i = 0; i < list.Count; i++)
			{
				if ((list[i].opcode != OpCodes.Call && list[i].opcode != OpCodes.Callvirt) || !(list[i].operand is MethodInfo { IsStatic: false, IsPublic: not false } methodInfo))
				{
					continue;
				}
				Type declaringType = methodInfo.DeclaringType;
				if ((object)declaringType == null || !declaringType.IsSubclassOf(typeof(CardAnimationController3D)) || !methodInfo.Equals(methodInfo.GetBaseDefinition()) || (methodInfo.CallingConvention & CallingConventions.VarArgs) != 0)
				{
					continue;
				}
				MethodInfo method = typeof(CardAnimationControllerExtension).GetMethod(methodInfo.Name, BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public);
				if (method == null)
				{
					continue;
				}
				bool flag = false;
				int num = i - 1;
				while (num >= 0 && list[num].opcode.OpCodeType == OpCodeType.Prefix)
				{
					if (list[num].opcode == OpCodes.Constrained)
					{
						flag = true;
						break;
					}
					num--;
				}
				if (flag)
				{
					continue;
				}
				int num2 = methodInfo.GetParameters().Length;
				bool flag2 = list[i].labels.Count == 0 && list[i].blocks.Count == 0;
				int num3 = i - 1;
				while (flag2 && num3 >= 0 && list[num3].labels.Count <= 0 && list[num3].blocks.Count <= 0)
				{
					int num4;
					int num5;
					if (list[num3].opcode == OpCodes.Call || list[num3].opcode == OpCodes.Callvirt || list[num3].opcode == OpCodes.Newobj)
					{
						if (!(list[num3].operand is MethodBase methodBase) || (methodBase.CallingConvention & CallingConventions.VarArgs) != 0)
						{
							break;
						}
						num4 = methodBase.GetParameters().Length;
						if (list[num3].opcode != OpCodes.Newobj && !methodBase.IsStatic)
						{
							num4++;
						}
						num5 = ((list[num3].opcode == OpCodes.Newobj || (methodBase is MethodInfo methodInfo2 && methodInfo2.ReturnType != typeof(void))) ? 1 : 0);
					}
					else
					{
						if (list[num3].opcode.FlowControl != FlowControl.Next)
						{
							break;
						}
						num4 = list[num3].opcode.StackBehaviourPop switch
						{
							StackBehaviour.Pop0 => 0, 
							StackBehaviour.Pop1 => 1, 
							StackBehaviour.Popi => 1, 
							StackBehaviour.Popref => 1, 
							StackBehaviour.Pop1_pop1 => 2, 
							StackBehaviour.Popi_pop1 => 2, 
							StackBehaviour.Popi_popi => 2, 
							StackBehaviour.Popi_popi8 => 2, 
							StackBehaviour.Popi_popr4 => 2, 
							StackBehaviour.Popi_popr8 => 2, 
							StackBehaviour.Popref_pop1 => 2, 
							StackBehaviour.Popref_popi => 2, 
							StackBehaviour.Popi_popi_popi => 3, 
							StackBehaviour.Popref_popi_pop1 => 3, 
							StackBehaviour.Popref_popi_popi => 3, 
							StackBehaviour.Popref_popi_popi8 => 3, 
							StackBehaviour.Popref_popi_popr4 => 3, 
							StackBehaviour.Popref_popi_popr8 => 3, 
							StackBehaviour.Popref_popi_popref => 3, 
							_ => -1, 
						};
						num5 = list[num3].opcode.StackBehaviourPush switch
						{
							StackBehaviour.Push0 => 0, 
							StackBehaviour.Push1_push1 => 2, 
							StackBehaviour.Push1 => 1, 
							StackBehaviour.Pushi => 1, 
							StackBehaviour.Pushi8 => 1, 
							StackBehaviour.Pushr4 => 1, 
							StackBehaviour.Pushr8 => 1, 
							StackBehaviour.Pushref => 1, 
							_ => -1, 
						};
						if (num4 < 0 || num5 < 0)
						{
							break;
						}
					}
					if (num2 < num5)
					{
						if (list[num3].opcode == OpCodes.Isinst && list[num3].operand is Type c && declaringType.IsAssignableFrom(c))
						{
							list[num3].operand = typeof(CardAnimationController);
						}
						break;
					}
					num2 += num4 - num5;
					num3--;
				}
				list[i].opcode = OpCodes.Call;
				list[i].operand = method;
			}
			return list;
		}

		private static DiskCardAnimationController ResolveLatchAnim(CardAnimationController anim)
		{
			object obj = ((anim is DiskCardAnimationController) ? anim : null);
			if (obj == null)
			{
				CardAnimationControllerManager component = ((Component)anim).GetComponent<CardAnimationControllerManager>();
				if (component == null)
				{
					return null;
				}
				obj = component.AddAnim<DiskCardAnimationController>(includeDerivedTypes: true, (Action<DiskCardAnimationController>)null);
			}
			return (DiskCardAnimationController)obj;
		}
	}
	public class CardAnimationControllerManager : ManagedBehaviour
	{
		internal List<CardAnimationController> anims = new List<CardAnimationController>();

		private bool paperEffectsNeedRebind;

		private PaperRenderStatsLayer renderedPaperAbilityLayer;

		private PaperRenderStatsLayer borrowedAbilityLayer;

		private CardAbilityIcons borrowedAbilityIcons;

		private Transform borrowedAbilityModel;

		private bool borrowingMergeIcons;

		private bool borrowingTotemIcons;

		private bool abilityInteractionEnabled = true;

		private bool wizardCardHiddenBySlot;

		private readonly Dictionary<GameObject, uint> paperSurfaceRevisions = new Dictionary<GameObject, uint>();

		private CardAnimationController activeAnim;

		private RenderStatsLayer activeLayer;

		private bool bindingSuspended;

		private static readonly Vector3 GIANT_RENDERER_POSITION = new Vector3(-1.67f, -0.52f, 0f);

		private static readonly Vector3 GIANT_RENDERER_SCALE = new Vector3(4.4f, 2.1f, 1f);

		private const float GRAVESTONE_PIVOT_HEIGHT = 0.36f;

		private static readonly Vector3 GRAVESTONE_RENDERER_SCALE = new Vector3(0.635f, 0.6350002f, 0.2000001f);

		private static readonly Vector3 DISK_RENDERER_SCALE = new Vector3(0.5263159f, 0.8000001f, 1f);

		private static readonly string[] DISK_SPECIFIC_RENDERERS = new string[5] { "Rails", "ScreenFront", "ScreenBack", "Bottom", "Top" };

		public Card Card => ((Component)this).GetComponent<Card>();

		public PlayableCard PlayableCard => ((Component)this).GetComponent<PlayableCard>();

		public SelectableCard SelectableCard => ((Component)this).GetComponent<SelectableCard>();

		internal uint RenderBindingRevision { get; private set; }

		public CardAnimationController Anim => activeAnim;

		public RenderStatsLayer StatsLayer => FindStatsLayer(activeAnim);

		internal bool flipped
		{
			get
			{
				//IL_004b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				CardAnimationController anim = Anim;
				if (anim is GravestoneCardAnimationController)
				{
					return false;
				}
				if (anim is DiskCardAnimationController)
				{
					return (((Component)anim.cardRenderer).transform.localRotation * Vector3.right).y < 0f;
				}
				return ((Component)anim.cardRenderer).transform.localRotation.z != 0f;
			}
			set
			{
				CardAnimationController anim = Anim;
				bool cardRendererFlipped = value && !(anim is GravestoneCardAnimationController);
				foreach (CardAnimationController anim2 in anims)
				{
					if (!((Behaviour)anim2).enabled && (Object)(object)anim2.cardRenderer != (Object)(object)anim.cardRenderer)
					{
						anim2.SetCardRendererFlipped(cardRendererFlipped);
					}
				}
			}
		}

		internal bool faceDown
		{
			get
			{
				return Anim.FaceDown;
			}
			set
			{
				foreach (CardAnimationController anim in anims)
				{
					anim.FaceDown = value;
				}
				if ((Object)(object)renderedPaperAbilityLayer != (Object)null)
				{
					UpdateAnim(Anim);
				}
				ApplyBorrowedInteraction();
			}
		}

		internal float intendedRendererYPos
		{
			get
			{
				CardAnimationController anim = Anim;
				CardAnimationController3D val = (CardAnimationController3D)(((object)((anim is CardAnimationController3D) ? anim : null)) ?? ((object)this.GetAnim<CardAnimationController3D>(includeDerivedTypes: true)));
				if (!((Object)(object)val != (Object)null))
				{
					return 0f;
				}
				return val.intendedRendererYPos - GetGiantRendererYOffset((CardAnimationController)(object)val);
			}
			set
			{
				foreach (CardAnimationController anim in anims)
				{
					if (!((Behaviour)anim).enabled)
					{
						CardAnimationController3D val = (CardAnimationController3D)(object)((anim is CardAnimationController3D) ? anim : null);
						if (val != null)
						{
							val.SetRendererYPos(value + GetGiantRendererYOffset((CardAnimationController)(object)val));
						}
					}
				}
			}
		}

		internal bool UsesBorrowedPaperIcons
		{
			get
			{
				bool flag = !bindingSuspended;
				if (flag)
				{
					CardAnimationController val = activeAnim;
					bool flag2 = ((val is GravestoneCardAnimationController || val is DiskCardAnimationController) ? true : false);
					flag = flag2;
				}
				return flag;
			}
		}

		internal uint GetSurfaceRevision(RenderStatsLayer layer)
		{
			if (!(layer is PaperRenderStatsLayer) || !paperSurfaceRevisions.TryGetValue(((Component)layer).gameObject, out var value))
			{
				return 0u;
			}
			return value;
		}

		internal static CardAnimationControllerManager GetOrCreate(Card card, CardInfo info)
		{
			CardAnimationControllerManager component = ((Component)card).GetComponent<CardAnimationControllerManager>();
			if ((Object)(object)component != (Object)null)
			{
				return component;
			}
			CardAnimationController val = ((IEnumerable<CardAnimationController>)((Component)card).GetComponents<CardAnimationController>()).FirstOrDefault((Func<CardAnimationController, bool>)((CardAnimationController item) => ((Behaviour)item).enabled));
			if (!CardModelSelection.TryResolve(info, card is PlayableCard, out var _, out var _) || (Object)(object)val == (Object)null || !CardModelSelection.IsKnownController(((object)val).GetType()) || (Object)(object)FindStatsLayer(val) == (Object)null || !HasSupportedLayout(card))
			{
				return null;
			}
			return ((Component)card).gameObject.AddComponent<CardAnimationControllerManager>();
		}

		internal bool TryGetMainRenderBinding(out CardAnimationController anim, out RenderStatsLayer layer)
		{
			anim = activeAnim;
			layer = null;
			if (bindingSuspended || (Object)(object)anim == (Object)null || !((Behaviour)anim).enabled)
			{
				return false;
			}
			layer = FindStatsLayer(anim);
			if (activeLayer != layer)
			{
				activeLayer = layer;
				InvalidateRenderBinding();
			}
			if ((Object)(object)layer != (Object)null)
			{
				return ((Behaviour)layer).enabled;
			}
			return false;
		}

		private static RenderStatsLayer FindStatsLayer(CardAnimationController anim)
		{
			if ((Object)(object)anim == (Object)null || (Object)(object)anim.cardRenderer == (Object)null)
			{
				return null;
			}
			Type type = ((anim is WizardCardAnimationController) ? typeof(CanvasRenderStatsLayer) : ((anim is DiskCardAnimationController) ? typeof(DiskRenderStatsLayer) : ((anim is GravestoneCardAnimationController) ? typeof(GravestoneRenderStatsLayer) : ((!(anim is PaperCardAnimationController)) ? null : typeof(PaperRenderStatsLayer)))));
			Type type2 = type;
			if (!(type2 == null))
			{
				return ((IEnumerable<RenderStatsLayer>)((Component)anim).GetComponentsInChildren<RenderStatsLayer>(true)).FirstOrDefault((Func<RenderStatsLayer, bool>)((RenderStatsLayer layer) => (((object)layer).GetType() == type2 || (type2 == typeof(PaperRenderStatsLayer) && ((object)layer).GetType() == typeof(RenderLiveStatsLayer))) && (Object)(object)layer.Renderer != (Object)null));
			}
			return null;
		}

		private static bool HasSupportedLayout(Card card)
		{
			if ((Object)(object)card == (Object)null)
			{
				return false;
			}
			CardAnimationController[] componentsInChildren = ((Component)card).GetComponentsInChildren<CardAnimationController>(true);
			RenderStatsLayer[] componentsInChildren2 = ((Component)card).GetComponentsInChildren<RenderStatsLayer>(true);
			if (componentsInChildren.Count((CardAnimationController anim) => ((Behaviour)anim).enabled) == 1 && !(from anim in componentsInChildren
				group anim by ((object)anim).GetType()).Any((IGrouping<Type, CardAnimationController> group) => group.Count() > 1) && componentsInChildren2.Length <= 4 && !(from layer in componentsInChildren2
				group layer by ((object)layer).GetType()).Any((IGrouping<Type, RenderStatsLayer> group) => group.Count() > 1))
			{
				return !(from layer in componentsInChildren2
					where ((Behaviour)layer).enabled && (Object)(object)layer.Renderer != (Object)null
					group layer by layer.Renderer).Any((IGrouping<Renderer, RenderStatsLayer> group) => group.Count() > 1);
			}
			return false;
		}

		private bool CanChangeBinding()
		{
			if (bindingSuspended)
			{
				return false;
			}
			if (!TryGetMainRenderBinding(out var _, out var _) || !HasSupportedLayout(Card))
			{
				bindingSuspended = true;
				ClearBorrowedAbilityIcons();
				InvalidateRenderBinding();
				return false;
			}
			return true;
		}

		private static bool IsNativePaperLayer(RenderStatsLayer layer)
		{
			Type type = ((object)layer).GetType();
			if (!(type == typeof(PaperRenderStatsLayer)) && !(type == typeof(CanvasRenderStatsLayer)))
			{
				return type == typeof(RenderLiveStatsLayer);
			}
			return true;
		}

		private bool CanEnableStatsLayer(RenderStatsLayer layer)
		{
			if ((Object)(object)layer != (Object)null)
			{
				return !((Component)this).GetComponentsInChildren<RenderStatsLayer>(true).Any((RenderStatsLayer other) => (Object)(object)other != (Object)(object)layer && ((Behaviour)other).enabled && (Object)(object)other.Renderer == (Object)(object)layer.Renderer && (!((Object)(object)((Component)other).gameObject == (Object)(object)((Component)layer).gameObject) || !IsNativePaperLayer(other) || !IsNativePaperLayer(layer)));
			}
			return false;
		}

		private void Awake()
		{
			if (anims.Count == 0)
			{
				anims.AddRange(from item in ((Component)this).GetComponents<CardAnimationController>()
					where CardModelSelection.IsKnownController(((object)item).GetType())
					select item);
				activeAnim = ((IEnumerable<CardAnimationController>)anims).FirstOrDefault((Func<CardAnimationController, bool>)((CardAnimationController item) => ((Behaviour)item).enabled));
				activeLayer = FindStatsLayer(activeAnim);
			}
		}

		public void SetInfo(CardInfo info)
		{
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			Awake();
			if (!CanChangeBinding())
			{
				return;
			}
			CardAnimationController val = activeAnim;
			if (CardModelSelection.TryResolve(info, (Object)(object)PlayableCard != (Object)null, out var animType, out var _))
			{
				CardAnimationController val2 = AddAnim(animType);
				if (CanEnableStatsLayer(FindStatsLayer(val2)))
				{
					val = val2;
				}
			}
			WizardBattlePortraitSlot portraitSlot = null;
			PlayableCard playableCard = PlayableCard;
			if (playableCard != null && playableCard.OnBoard && (Object)(object)playableCard.Slot.Card == (Object)(object)playableCard)
			{
				WizardPortraitSlotManager instance = Singleton<WizardPortraitSlotManager>.Instance;
				portraitSlot = ((instance != null) ? instance.GetPortraitSlotForCardSlot(playableCard.Slot) : null);
				CardAnimationController anim = Anim;
				WizardCardAnimationController val3 = (WizardCardAnimationController)(object)((anim is WizardCardAnimationController) ? anim : null);
				if (val3 != null && (Object)(object)val3.WizardPortrait != (Object)null)
				{
					if (!((Object)(object)val3 != (Object)(object)val))
					{
						CardInfo info2 = Card.Info;
						if (!(((info2 != null) ? ((Object)info2).name : null) != ((Object)info).name) && WizardBattlePortraitSlotPatches.HasPortraitFor(portraitSlot, playableCard))
						{
							goto IL_0165;
						}
					}
					if ((Object)(object)portraitSlot != (Object)null && (Object)(object)portraitSlot.WizardPortrait == (Object)(object)val3.WizardPortrait)
					{
						WizardBattlePortraitSlotPatches.ReleasePortrait(portraitSlot);
					}
					else
					{
						WizardBattlePortraitSlotPatches.DestroyPortrait(val3.WizardPortrait);
					}
					val3.WizardPortrait = null;
				}
			}
			goto IL_0165;
			IL_0165:
			if (Anim is PaperCardAnimationController)
			{
				RenderStatsLayer statsLayer = StatsLayer;
				RenderLiveStatsLayer val4 = (RenderLiveStatsLayer)(object)((statsLayer is RenderLiveStatsLayer) ? statsLayer : null);
				if (val4 != null)
				{
					CardInfo info3 = Card.Info;
					if (!(val is PaperCardAnimationController) || !info.appearanceBehaviour.Contains((Appearance)(val4.Giant ? 11 : 5)) || (Object)(object)((info3 != null) ? info3.AnimatedPortrait : null) != (Object)(object)info.AnimatedPortrait)
					{
						GameObject gameObject = ((Component)val4).gameObject;
						Renderer bendableCardRenderer = ((PaperRenderStatsLayer)val4).bendableCardRenderer;
						bool bendable = ((PaperRenderStatsLayer)val4).bendable;
						bool enabled = ((Behaviour)val4).enabled;
						((Behaviour)val4).enabled = false;
						((RenderStatsLayer)val4).PreserveMaterialOnDestroy = true;
						SetMaterialTiling[] componentsInChildren = ((Component)val4).GetComponentsInChildren<SetMaterialTiling>(true);
						foreach (SetMaterialTiling val5 in componentsInChildren)
						{
							if (val5.MaterialIndex == 0)
							{
								val5.AdjustOffset(Vector2.zero);
							}
						}
						Type appearanceType = (val4.Giant ? typeof(GiantAnimatedPortrait) : typeof(AnimatedPortrait));
						AnimatedPortrait val6 = ((IEnumerable<AnimatedPortrait>)((Component)this).GetComponents<AnimatedPortrait>()).FirstOrDefault((Func<AnimatedPortrait, bool>)((AnimatedPortrait item) => ((object)item).GetType() == appearanceType));
						if ((Object)(object)val6 != (Object)null)
						{
							Object.DestroyImmediate((Object)(object)val6);
						}
						CardRenderInfo renderInfo = Card.RenderInfo;
						if ((Object)(object)info3 != (Object)null && (Object)(object)renderInfo.prefabPortrait == (Object)(object)info3.AnimatedPortrait)
						{
							renderInfo.prefabPortrait = null;
							renderInfo.hidePortrait = false;
						}
						if (val4.Giant)
						{
							if ((Object)(object)renderInfo.baseTextureOverride == (Object)(object)ResourceBank.Get<Texture>("Art/Cards/card_empty_giant"))
							{
								renderInfo.baseTextureOverride = null;
							}
							if (renderInfo.defaultAbilitiesOffset == new Vector2(0f, -0.034f))
							{
								renderInfo.defaultAbilitiesOffset = Vector2.zero;
							}
						}
						Object.DestroyImmediate((Object)(object)val4);
						PaperRenderStatsLayer obj = gameObject.AddComponent<PaperRenderStatsLayer>();
						obj.bendableCardRenderer = bendableCardRenderer;
						obj.bendable = bendable;
						((Behaviour)obj).enabled = enabled;
					}
				}
			}
			ActivateAnim(val, delegate(CardAnimationController x)
			{
				if ((Object)(object)portraitSlot != (Object)null)
				{
					WizardCardAnimationController val7 = (WizardCardAnimationController)(object)((x is WizardCardAnimationController) ? x : null);
					if (val7 != null && (Object)(object)val7.WizardPortrait == (Object)null)
					{
						PlayableCard playableCard2 = PlayableCard;
						if (playableCard2 != null && !playableCard2.Dead)
						{
							WizardBattlePortraitSlotPatches.SpawnPortraitImmediately(portraitSlot, playableCard2, info);
						}
					}
				}
			});
		}

		public T SetAnim<T>(Action<T> action = null, bool includeDerivedTypes = false) where T : CardAnimationController3D
		{
			CardAnimationController obj = SetAnim(typeof(T), delegate(CardAnimationController x)
			{
				action?.Invoke((T)(object)((x is T) ? x : null));
			}, includeDerivedTypes);
			return (T)(object)((obj is T) ? obj : null);
		}

		public CardAnimationController SetAnim(Type type, Action<CardAnimationController> action = null, bool includeDerivedTypes = false)
		{
			return ActivateAnim(AddAnim(type, null, includeDerivedTypes), action);
		}

		private CardAnimationController ActivateAnim(CardAnimationController target, Action<CardAnimationController> action)
		{
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: 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_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: Unknown result type (might be due to invalid IL or missing references)
			//IL_053a: Unknown result type (might be due to invalid IL or missing references)
			//IL_053f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0544: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_080d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0812: Unknown result type (might be due to invalid IL or missing references)
			//IL_0817: Unknown result type (might be due to invalid IL or missing references)
			//IL_0839: Unknown result type (might be due to invalid IL or missing references)
			//IL_083e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0843: Unknown result type (might be due to invalid IL or missing references)
			//IL_088d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0892: Unknown result type (might be due to invalid IL or missing references)
			//IL_0476: Unknown result type (might be due to invalid IL or missing references)
			//IL_047b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0480: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0695: Unknown result type (might be due to invalid IL or missing references)
			//IL_069a: Unknown result type (might be due to invalid IL or missing references)
			//IL_069f: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_06cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0703: Unknown result type (might be due to invalid IL or missing references)
			//IL_070d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0712: Unknown result type (might be due to invalid IL or missing references)
			//IL_071c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0721: Unknown result type (might be due to invalid IL or missing references)
			//IL_0726: Unknown result type (might be due to invalid IL or missing references)
			if (!CanEnableStatsLayer(FindStatsLayer(target)))
			{
				return activeAnim;
			}
			if (((Behaviour)target).enabled)
			{
				action?.Invoke(target);
				return target;
			}
			CardAnimationController val = activeAnim;
			if (val is DiskCardAnimationController)
			{
				RenderStatsLayer componentInChildren = (RenderStatsLayer)(object)((Component)this).GetComponentInChildren<DiskRenderStatsLayer>(true);
				for (int i = 0; i < ((Component)componentInChildren).transform.childCount; i++)
				{
					Transform child = ((Component)componentInChildren).transform.GetChild(i);
					if (DISK_SPECIFIC_RENDERERS.Contains(((Object)child).name))
					{
						Renderer[] componentsInChildren = ((Component)child).GetComponentsInChildren<Renderer>(true);
						for (int j = 0; j < componentsInChildren.Length; j++)
						{
							componentsInChildren[j].forceRenderingOff = true;
						}
					}
				}
			}
			float intendedRendererYPos = this.intendedRendererYPos + GetGiantRendererYOffset(target);
			Vector3 val2 = (((Object)(object)val != (Object)null) ? ((Component)val.cardRenderer).transform.localPosition : Vector3.zero);
			if ((val is GiantCardAnimationController || val is GiantGravestoneCardAnimationController || val is GiantDiskCardAnimationController || val is GiantWizardCardAnimationController) ? true : false)
			{
				val2 -= GIANT_RENDERER_POSITION;
			}
			((Component)target.cardRenderer).transform.localPosition = val2;
			((Component)target.cardRenderer).transform.localScale = Vector3.one;
			PaperCardAnimationController val3 = (PaperCardAnimationController)(object)((target is PaperCardAnimationController) ? target : null);
			if (val3 != null)
			{
				RenderStatsLayer obj = FindStatsLayer(target);
				PaperRenderStatsLayer layer = (PaperRenderStatsLayer)(object)((obj is PaperRenderStatsLayer) ? obj : null);
				EnablePaperStatsLayer(layer);
				Card.abilityIcons = ((Component)((CardAnimationController)val3).cardRenderer).GetComponentInChildren<CardAbilityIcons>(true);
				Card.statIcons = ((Component)((CardAnimationController)val3).cardRenderer).GetComponentInChildren<CardStatIcons>(true);
				Card.defaultCardback = Resources.Load<Texture>("Art/Cards/card_back");
				((Component)this).GetComponent<Animator>().runtimeAnimatorController = Resources.Load<RuntimeAnimatorController>("Animation/Cards/PaperCards/Card");
				((Behaviour)((Component)this).GetComponent<Animator>()).enabled = true;
				((Behaviour)((Component)this).GetComponent<AudioKeyframeEvents>()).enabled = true;
				TableAnimationKeyframeEvents component = ((Component)this).GetComponent<TableAnimationKeyframeEvents>();
				if (component != null)
				{
					((Behaviour)component).enabled = val3 is GiantCardAnimationController;
				}
				if (val3 is GiantCardAnimationController)
				{
					Transform transform = ((Component)((CardAnimationController)val3).cardRenderer).transform;
					transform.localPosition += GIANT_RENDERER_POSITION;
					((Component)((CardAnimationController)val3).cardRenderer).transform.localScale = Vector3.Scale(((Component)((CardAnimationController)val3).cardRenderer).transform.localScale, GIANT_RENDERER_SCALE);
					((Component)this).GetComponent<Animator>().runtimeAnimatorController = Resources.Load<RuntimeAnimatorController>("Animation/Cards/PaperCards/Card_Giant");
				}
				if (paperEffectsNeedRebind)
				{
					paperEffectsNeedRebind = false;
					Animator component2 = ((Component)this).GetComponent<Animator>();
					if (((Behaviour)component2).isActiveAndEnabled)
					{
						Transform transform2 = ((Component)((CardAnimationController)val3).cardRenderer).transform;
						Vector3 localPosition = transform2.localPosition;
						Quaternion localRotation = transform2.localRotation;
						Vector3 localScale = transform2.localScale;
						component2.Rebind();
						transform2.localPosition = localPosition;
						transform2.localRotation = localRotation;
						transform2.localScale = localScale;
					}
				}
				if ((Object)(object)SelectableCard != (Object)null)
				{
					SelectableCard.animationParent = ((Component)((CardAnimationController)val3).cardRenderer).transform;
					SelectableCard.localRotationOffset = Vector3.zero;
					for (int k = 0; k < ((Component)this).transform.childCount; k++)
					{
						if (!((Object)(object)SelectableCard.dustParticles == (Object)null))
						{
							break;
						}
						Transform child2 = ((Component)this).transform.GetChild(k);
						SelectableCard.dustParticles = ((Component)child2).GetComponent<ParticleSystem>();
					}
				}
			}
			else
			{
				GravestoneCardAnimationController val4 = (GravestoneCardAnimationController)(object)((target is GravestoneCardAnimationController) ? target : null);
				if (val4 != null)
				{
					((Component)((CardAnimationController)val4).cardRenderer).transform.localScale = Vector3.Scale(((Component)((CardAnimationController)val4).cardRenderer).transform.localScale, GRAVESTONE_RENDERER_SCALE);
					RenderStatsLayer val5 = FindStatsLayer(target);
					RenderStatsLayer[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<RenderStatsLayer>(true);
					foreach (RenderStatsLayer val6 in componentsInChildren2)
					{
						if ((Object)(object)val6.Renderer == (Object)(object)val5.Renderer)
						{
							((Behaviour)val6).enabled = (Object)(object)val6 == (Object)(object)val5;
						}
					}
					Card.abilityIcons = ((Component)((Component)((CardAnimationController)val4).cardRenderer).transform.parent).GetComponentInChildren<CardAbilityIcons>(true);
					Card.statIcons = null;
					Card.defaultCardback = null;
					((Component)this).GetComponent<Animator>().runtimeAnimatorController = Resources.Load<RuntimeAnimatorController>("Animation/Cards/GravestoneCard/GravestoneCardAnim");
					((Behaviour)((Component)this).GetComponent<Animator>()).enabled = true;
					AudioKeyframeEvents component3 = ((Component)this).GetComponent<AudioKeyframeEvents>();
					if (component3 != null)
					{
						((Behaviour)component3).enabled = false;
					}
					TableAnimationKeyframeEvents component4 = ((Component)this).GetComponent<TableAnimationKeyframeEvents>();
					if (component4 != null)
					{
						((Behaviour)component4).enabled = val4 is GiantGravestoneCardAnimationController;
					}
					if (val4 is GiantGravestoneCardAnimationController)
					{
						Transform transform3 = ((Component)((CardAnimationController)val4).cardRenderer).transform;
						transform3.localPosition += GIANT_RENDERER_POSITION;
						((Component)((CardAnimationController)val4).cardRenderer).transform.localScale = Vector3.Scale(((Component)((CardAnimationController)val4).cardRenderer).transform.localScale, GIANT_RENDERER_SCALE);
					}
					if ((Object)(object)SelectableCard != (Object)null)
					{
						SelectableCard.animationParent = ((Component)((CardAnimationController)val4).cardRenderer).transform.parent.parent;
						SelectableCard.localRotationOffset = Vector3.zero;
						if (!Plugin.Config.UsingPaperDustParticles)
						{
							SelectableCard.dustParticles = null;
						}
					}
				}
				else
				{
					DiskCardAnimationController val7 = (DiskCardAnimationController)(object)((target is DiskCardAnimationController) ? target : null);
					if (val7 != null)
					{
						((Component)((CardAnimationController)val7).cardRenderer).transform.localScale = Vector3.Scale(((Component)((CardAnimationController)val7).cardRenderer).transform.localScale, DISK_RENDERER_SCALE);
						RenderStatsLayer val8 = FindStatsLayer(target);
						RenderStatsLayer[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<RenderStatsLayer>(true);
						foreach (RenderStatsLayer val9 in componentsInChildren2)
						{
							if ((Object)(object)val9.Renderer == (Object)(object)val8.Renderer)
							{
								((Behaviour)val9).enabled = (Object)(object)val9 == (Object)(object)val8;
							}
						}
						for (int l = 0; l < ((Component)val8).transform.childCount; l++)
						{
							Transform child3 = ((Component)val8).transform.GetChild(l);
							if (DISK_SPECIFIC_RENDERERS.Contains(((Object)child3).name))
							{
								Renderer[] componentsInChildren = ((Component)child3).GetComponentsInChildren<Renderer>(true);
								for (int j = 0; j < componentsInChildren.Length; j++)
								{
									componentsInChildren[j].forceRenderingOff = false;
								}
							}
						}
						Card.abilityIcons = ((Component)((CardAnimationController)val7).cardRenderer).GetComponentInChildren<CardAbilityIcons>(true);
						Card.statIcons = ((Component)((CardAnimationController)val7).cardRenderer).GetComponentInChildren<CardStatIcons>(true);
						Card.defaultCardback = null;
						Animator component5 = ((Component)this).GetComponent<Animator>();
						if (component5 != null)
						{
							((Behaviour)component5).enabled = false;
						}
						AudioKeyframeEvents component6 = ((Component)this).GetComponent<AudioKeyframeEvents>();
						if (component6 != null)
						{
							((Behaviour)component6).enabled = false;
						}
						TableAnimationKeyframeEvents component7 = ((Component)this).GetComponent<TableAnimationKeyframeEvents>();
						if (component7 != null)
						{
							((Behaviour)component7).enabled = val7 is GiantDiskCardAnimationController;
						}
						if (val7 is GiantDiskCardAnimationController)
						{
							Transform transform4 = ((Component)((CardAnimationController)val7).cardRenderer).transform;
							transform4.localPosition += GIANT_RENDERER_POSITION;
							((Component)((CardAnimationController)val7).cardRenderer).transform.localScale = Vector3.Scale(((Component)((CardAnimationController)val7).cardRenderer).transform.localScale, GIANT_RENDERER_SCALE);
						}
						if ((Object)(object)SelectableCard != (Object)null)
						{
							SelectableCard.animationParent = ((Component)((CardAnimationController)val7).cardRenderer).transform;
							SelectableCard.localRotationOffset = Vector3.down * 180f + Vector3.forward * 90f;
							if (!Plugin.Config.UsingPaperDustParticles)
							{
								SelectableCard.dustParticles = null;
							}
						}
					}
					else
					{
						WizardCardAnimationController val10 = (WizardCardAnimationController)(object)((target is WizardCardAnimationController) ? target : null);
						if (val10 != null)
						{
							RenderStatsLayer obj2 = FindStatsLayer(target);
							PaperRenderStatsLayer layer2 = (PaperRenderStatsLayer)(object)((obj2 is PaperRenderStatsLayer) ? obj2 : null);
							EnablePaperStatsLayer(layer2);
							Card.abilityIcons = ((Component)((CardAnimationController)val10).cardRenderer).GetComponentInChildren<CardAbilityIcons>(true);
							Card.statIcons = ((Component)((CardAnimationController)val10).cardRenderer).GetComponentInChildren<CardStatIcons>(true);
							Card.defaultCardback = Resources.Load<Texture>("Art/Cards/card_back");
							((Component)this).GetComponent<Animator>().runtimeAnimatorController = Resources.Load<RuntimeAnimatorController>("Animation/Cards/PaperCards/Card");
							((Behaviour)((Component)this).GetComponent<Animator>()).enabled = true;
							((Behaviour)((Component)this).GetComponent<AudioKeyframeEvents>()).enabled = true;
							TableAnimationKeyframeEvents component8 = ((Component)this).GetComponent<TableAnimationKeyframeEvents>();
							if (component8 != null)
							{
								((Behaviour)component8).enabled = val10 is GiantWizardCardAnimationController;
							}
							if (val10 is GiantWizardCardAnimationController)
							{
								Transform transform5 = ((Component)((CardAnimationController)val10).cardRenderer).transform;
								transform5.localPosition += GIANT_RENDERER_POSITION;
								((Component)((CardAnimationController)val10).cardRenderer).transform.localScale = Vector3.Scale(((Component)((CardAnimationController)val10).cardRenderer).transform.localScale, GIANT_RENDERER_SCALE);
								((Component)this).GetComponent<Animator>().runtimeAnimatorController = Resources.Load<RuntimeAnimatorController>("Animation/Cards/PaperCards/Card_Giant");
							}
							if ((Object)(object)SelectableCard != (Object)null)
							{
								SelectableCard.animationParent = ((Component)((CardAnimationController)val10).cardRenderer).transform;
								SelectableCard.localRotationOffset = Vector3.zero;
								for (int m = 0; m < ((Component)this).transform.childCount; m++)
								{
									if (!((Object)(object)SelectableCard.dustParticles == (Object)null))
									{
										break;
									}
									Transform child4 = ((Component)this).transform.GetChild(m);
									SelectableCard.dustParticles = ((Component)child4).GetComponent<ParticleSystem>();
								}
							}
						}
					}
				}
			}
			if ((Object)(object)activeAnim != (Object)null)
			{
				ClearBorrowedAbilityIcons();
				((Behaviour)activeAnim).enabled = false;
			}
			activeAnim = target;
			((Behaviour)target).enabled = true;
			activeLayer = FindStatsLayer(target);
			InvalidateRenderBinding();
			renderedPaperAbilityLayer = null;
			UpdateAnim(target);
			action = (Action<CardAnimationController>)Delegate.Combine(action, (Action<CardAnimationController>)delegate(CardAnimationController x)
			{
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_0054: Unknown result type (might be due to invalid IL or missing references)
				//IL_005e: Unknown result type (might be due to invalid IL or missing references)
				x.PlayFaceDownAnimation(x.FaceDown, true);
				CardAnimationController3D val11 = (CardAnimationController3D)(object)((x is CardAnimationController3D) ? x : null);
				if (val11 != null)
				{
					val11.SetRendererYPos(intendedRendererYPos);
					((Component)((CardAnimationController)val11).cardRenderer).transform.localPosition = new Vector3(((Component)((CardAnimationController)val11).cardRenderer).transform.localPosition.x, intendedRendererYPos, ((Component)((CardAnimationController)val11).cardRenderer).transform.localPosition.z);
				}
			});
			action(target);
			return target;
		}

		public T AddAnim<T>(bool includeDerivedTypes = false, Action<T> action = null) where T : CardAnimationController3D
		{
			CardAnimationController obj = AddAnim(typeof(T), delegate(CardAnimationController x)
			{
				action?.Invoke((T)(object)((x is T) ? x : null));
			}, includeDerivedTypes);
			return (T)(object)((obj is T) ? obj : null);
		}

		public CardAnimationController AddAnim(Type type, Action<CardAnimationController> action = null, bool includeDerivedTypes = false)
		{
			if (!CardModelSelection.IsKnownController(type) || !CanChangeBinding())
			{
				return null;
			}
			CardAnimationController val = GetAnim(type, includeDerivedTypes);
			if ((Object)(object)val != (Object)null)
			{
				action?.Invoke(val);
				return val;
			}
			if (!CanPrepareBranch(type))
			{
				return null;
			}
			Component obj = ((Component)this).gameObject.AddComponent(type);
			CardAnimationController val2 = (CardAnimationController)(object)((obj is CardAnimationController) ? obj : null);
			((Behaviour)val2).enabled = false;
			PaperCardAnimationController val3 = (PaperCardAnimationController)(object)((val2 is PaperCardAnimationController) ? val2 : null);
			if (val3 != null)
			{
				if (anims.Exists((CardAnimationController x) => x is PaperCardAnimationController) || type != typeof(PaperCardAnimationController))
				{
					val = (CardAnimationController)(((object)((IEnumerable<CardAnimationController>)anims).FirstOrDefault((Func<CardAnimationController, bool>)((CardAnimationController x) => x is PaperCardAnimationController))) ?? ((object)this.AddAnim<PaperCardAnimationController>(includeDerivedTypes: false, (Action<PaperCardAnimationController>)null)));
					if (val2 is GiantCardAnimationController && (Object)(object)((Component)this).GetComponent<TableAnimationKeyframeEvents>() == (Object)null)
					{
						((Component)this).gameObject.AddComponent<TableAnimationKeyframeEvents>();
					}
				}
				else
				{
					if ((Object)(object)PlayableCard !=