Decompiled source of Original Card Rendering v0.1.2

Infiniscryption.DefaultRenderers.dll

Decompiled a year ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using DiskCardGame;
using HarmonyLib;
using InscryptionAPI.Card;
using InscryptionAPI.Encounters;
using InscryptionCommunityPatch.Card;
using Pixelplacement;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("Infiniscryption.DefaultRenderers")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Infinite Inscryption - Default Renderers")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("Infiniscryption.DefaultRenderers")]
[assembly: AssemblyTitle("Infiniscryption.DefaultRenderers")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
namespace Infiniscryption.DefaultRenderers;

[HarmonyPatch]
public class DefaultCardRenderer : MonoBehaviour
{
	private static readonly Texture MAGNIFICUS_CARD_BACK_TEXTURE = (Texture)(object)Resources.Load<Texture2D>("art/cards/card_back_magnificus");

	private static readonly Dictionary<CardTemple, GameObject> CardPrefabs = new Dictionary<CardTemple, GameObject>
	{
		{
			(CardTemple)1,
			ResourceBank.Get<GameObject>("Prefabs/Cards/PlayableCard_Grimora")
		},
		{
			(CardTemple)3,
			ResourceBank.Get<GameObject>("Prefabs/Cards/PlayableCard_Magnificus")
		},
		{
			(CardTemple)0,
			ResourceBank.Get<GameObject>("Prefabs/Cards/PlayableCard")
		},
		{
			(CardTemple)2,
			ResourceBank.Get<GameObject>("Prefabs/Cards/PlayableCard_Part3")
		}
	};

	private static readonly Dictionary<CardTemple, GameObject> SelectableCardPrefabs = new Dictionary<CardTemple, GameObject>
	{
		{
			(CardTemple)1,
			ResourceBank.Get<GameObject>("Prefabs/Cards/SelectableCard_Grimora")
		},
		{
			(CardTemple)3,
			ResourceBank.Get<GameObject>("Prefabs/Cards/SelectableCard")
		},
		{
			(CardTemple)0,
			ResourceBank.Get<GameObject>("Prefabs/Cards/SelectableCard")
		},
		{
			(CardTemple)2,
			ResourceBank.Get<GameObject>("Prefabs/Cards/SelectableCard_Part3")
		}
	};

	private static readonly Dictionary<CardTemple, GameObject> CardRenderCameraPrefabs = new Dictionary<CardTemple, GameObject>
	{
		{
			(CardTemple)1,
			ResourceBank.Get<GameObject>("Prefabs/Cards/CardRenderCamera_Grimora")
		},
		{
			(CardTemple)3,
			ResourceBank.Get<GameObject>("Prefabs/Cards/CardRenderCamera_Magnificus")
		},
		{
			(CardTemple)0,
			ResourceBank.Get<GameObject>("Prefabs/Cards/CardRenderCamera")
		},
		{
			(CardTemple)2,
			ResourceBank.Get<GameObject>("Prefabs/Cards/CardRenderCamera_Part3")
		}
	};

	internal readonly List<string> ActiveZoneOverrides = new List<string>();

	private static bool _enabledForAllCards = false;

	private Dictionary<CardTemple, CardRenderCamera> CardRenderCameras = null;

	private CardTemple? SaveFileOverride = null;

	private static DefaultCardRenderer m_instance = null;

	private static ConditionalWeakTable<SelectableCard, GameObject> InnerCardTable = new ConditionalWeakTable<SelectableCard, GameObject>();

	private static ConditionalWeakTable<CardAnimationController, Card> OuterCardAnimatorTable = new ConditionalWeakTable<CardAnimationController, Card>();

	public static bool EnabledForAllCards
	{
		get
		{
			return DefaultRenderersPlugin.Instance.RendererAlwaysActive || _enabledForAllCards || ((Object)(object)Instance != (Object)null && Instance.ActiveZoneOverrides.Count > 0);
		}
		set
		{
			_enabledForAllCards = value;
		}
	}

	public static CardTemple? ActiveTemple
	{
		get
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			CardTemple? result;
			if (!((Scene)(ref activeScene)).name.ToLowerInvariant().Contains("part1"))
			{
				activeScene = SceneManager.GetActiveScene();
				if (!((Scene)(ref activeScene)).name.ToLowerInvariant().Contains("part3"))
				{
					activeScene = SceneManager.GetActiveScene();
					if (!((Scene)(ref activeScene)).name.ToLowerInvariant().Contains("grimora"))
					{
						activeScene = SceneManager.GetActiveScene();
						result = (((Scene)(ref activeScene)).name.ToLowerInvariant().Contains("magnificus") ? new CardTemple?((CardTemple)3) : null);
					}
					else
					{
						result = (CardTemple)1;
					}
				}
				else
				{
					result = (CardTemple)2;
				}
			}
			else
			{
				result = (CardTemple)0;
			}
			return result;
		}
	}

	public static DefaultCardRenderer Instance
	{
		get
		{
			if ((Object)(object)m_instance != (Object)null)
			{
				return m_instance;
			}
			Instantiate();
			return m_instance;
		}
		private set
		{
			m_instance = value;
		}
	}

	public void EnableGlobalRenderer(string pluginGuid)
	{
		if (!ActiveZoneOverrides.Contains(pluginGuid))
		{
			ActiveZoneOverrides.Add(pluginGuid);
		}
	}

	public void CancelGlobalRenderer(string pluginGuid, bool force = false)
	{
		if (force)
		{
			ActiveZoneOverrides.Clear();
		}
		else
		{
			ActiveZoneOverrides.Remove(pluginGuid);
		}
	}

	public static void Instantiate()
	{
		//IL_000c: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Expected O, but got Unknown
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f2: Expected O, but got Unknown
		//IL_0225: Unknown result type (might be due to invalid IL or missing references)
		//IL_022a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0231: Expected O, but got Unknown
		//IL_0307: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			ManualLogSource log = DefaultRenderersPlugin.Log;
			Scene activeScene = SceneManager.GetActiveScene();
			log.LogInfo((object)("Trying to create default renderers plugin for " + ((Scene)(ref activeScene)).name.ToLowerInvariant()));
			if (!ActiveTemple.HasValue)
			{
				DefaultRenderersPlugin.Log.LogInfo((object)"Cannot create default renderers plugin for this scene because it's not a main game scene");
				return;
			}
			if ((Object)(object)m_instance != (Object)null)
			{
				return;
			}
			if ((Object)(object)Singleton<CardRenderCamera>.Instance == (Object)null)
			{
				DefaultRenderersPlugin.Log.LogInfo((object)"Cannot create default renderers plugin for this scene because there is not a CardRenderCamera");
				return;
			}
		}
		catch
		{
			return;
		}
		GameObject val = new GameObject("DefaultCardRenderers");
		val.transform.SetParent(((Component)Singleton<CardRenderCamera>.Instance).transform.parent);
		Instance = val.AddComponent<DefaultCardRenderer>();
		Instance.CardRenderCameras = new Dictionary<CardTemple, CardRenderCamera>();
		Instance.CardRenderCameras[ActiveTemple.Value] = Singleton<CardRenderCamera>.Instance;
		int num = 2;
		foreach (KeyValuePair<CardTemple, GameObject> cardRenderCameraPrefab in CardRenderCameraPrefabs)
		{
			if (cardRenderCameraPrefab.Key == ActiveTemple.Value)
			{
				continue;
			}
			GameObject val2 = Object.Instantiate<GameObject>(cardRenderCameraPrefab.Value, ((Component)Singleton<GameFlowManager>.Instance).transform);
			val2.transform.position = val2.transform.position + Vector3.down * 10f * (float)num++;
			CardRenderCamera componentInChildren = val2.GetComponentInChildren<CardRenderCamera>();
			((Object)((Component)componentInChildren).gameObject).name = $"SpecialRenderCamera{cardRenderCameraPrefab.Key}";
			RenderTexture val3 = new RenderTexture(((Texture)componentInChildren.snapshotRenderTexture).width, ((Texture)componentInChildren.snapshotRenderTexture).height, componentInChildren.snapshotRenderTexture.depth, componentInChildren.snapshotRenderTexture.format);
			val3.Create();
			RenderTexture val4 = new RenderTexture(((Texture)componentInChildren.snapshotEmissionRenderTexture).width, ((Texture)componentInChildren.snapshotEmissionRenderTexture).height, componentInChildren.snapshotEmissionRenderTexture.depth, componentInChildren.snapshotEmissionRenderTexture.format);
			val4.Create();
			Camera[] componentsInChildren = ((Component)componentInChildren).GetComponentsInChildren<Camera>();
			foreach (Camera val5 in componentsInChildren)
			{
				if ((Object)(object)val5.targetTexture == (Object)(object)componentInChildren.snapshotRenderTexture)
				{
					val5.targetTexture = (componentInChildren.snapshotRenderTexture = val3);
				}
				if ((Object)(object)val5.targetTexture == (Object)(object)componentInChildren.snapshotEmissionRenderTexture)
				{
					val5.targetTexture = (componentInChildren.snapshotEmissionRenderTexture = val4);
				}
			}
			Instance.CardRenderCameras[cardRenderCameraPrefab.Key] = componentInChildren;
		}
		Singleton<CardRenderCamera>.m_Instance = Instance.CardRenderCameras[ActiveTemple.Value];
		Singleton<PlayerHand>.Instance.cardZSpacing = 0.05f;
	}

	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	[HarmonyPrefix]
	private static bool HackPart1(ref bool __result)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Invalid comparison between Unknown and I4
		if ((Object)(object)Instance != (Object)null && Instance.SaveFileOverride.HasValue && (int)Instance.SaveFileOverride.Value == 0)
		{
			__result = true;
			return false;
		}
		return true;
	}

	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	[HarmonyPrefix]
	private static bool HackPart3(ref bool __result)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Invalid comparison between Unknown and I4
		if ((Object)(object)Instance != (Object)null && Instance.SaveFileOverride.HasValue && (int)Instance.SaveFileOverride.Value == 2)
		{
			__result = true;
			return false;
		}
		return true;
	}

	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	[HarmonyPrefix]
	private static bool HackGrimora(ref bool __result)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Invalid comparison between Unknown and I4
		if ((Object)(object)Instance != (Object)null && Instance.SaveFileOverride.HasValue && (int)Instance.SaveFileOverride.Value == 1)
		{
			__result = true;
			return false;
		}
		return true;
	}

	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	[HarmonyPrefix]
	private static bool HackMagnificus(ref bool __result)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Invalid comparison between Unknown and I4
		if ((Object)(object)Instance != (Object)null && Instance.SaveFileOverride.HasValue && (int)Instance.SaveFileOverride.Value == 3)
		{
			__result = true;
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(RenderStatsLayer), "RenderCard")]
	[HarmonyPrefix]
	[HarmonyPriority(700)]
	private static bool OverrideRender(RenderStatsLayer __instance, CardRenderInfo info)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: 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_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Invalid comparison between Unknown and I4
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)Instance != (Object)null)
		{
			CardTemple rendererTemple = info.baseInfo.GetRendererTemple();
			if ((CardTemple?)rendererTemple == ActiveTemple)
			{
				return true;
			}
			if (__instance is PaperRenderStatsLayer && (int)info.baseInfo.GetRendererTemple() == 3)
			{
				info.portraitColor = new Color(1f, 1f, 1f, 0.9f);
			}
			Instance.SaveFileOverride = rendererTemple;
			bool flag = CardDisplayer3D.EmissionEnabledForCard(info, __instance.PlayableCard);
			if (!flag)
			{
				__instance.DisableEmission();
			}
			DefaultRenderersPlugin.Log.LogInfo((object)$"Rendering {((Object)info.baseInfo).name} {rendererTemple} {((Object)((Component)Instance.CardRenderCameras[rendererTemple]).gameObject).name}");
			Instance.CardRenderCameras[rendererTemple].QueueStatsLayerForRender(info, __instance, __instance.PlayableCard, __instance.RenderToMainTexture, flag);
			Instance.SaveFileOverride = null;
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(GravestoneCardAnimationController), "SetCardRendererFlipped")]
	[HarmonyPrefix]
	[HarmonyPriority(700)]
	private static bool HackForGrimAnim(GravestoneCardAnimationController __instance, bool flipped)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		if (ActiveTemple == (CardTemple?)2 && (Object)(object)((CardAnimationController)__instance).PlayableCard != (Object)null && ((CardAnimationController)__instance).PlayableCard.OnBoard)
		{
			((Component)__instance.armAnim).transform.localEulerAngles = ((!flipped) ? new Vector3(-270f, 90f, -90f) : new Vector3(-90f, 0f, 0f));
			((Component)__instance.armAnim).transform.localPosition = ((!flipped) ? new Vector3(0f, -0.1f, -0.1f) : new Vector3(0f, 0.24f, -0.1f));
			((Component)__instance.damageMarks).transform.localPosition = ((!flipped) ? new Vector3(0.19f, -0.37f, -0.01f) : new Vector3(-0.21f, -0.1f, -0.01f));
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(CardSpawner), "SpawnPlayableCard")]
	[HarmonyPrefix]
	[HarmonyPriority(700)]
	private static bool MakeCardWithAppropriatePrefab(CardInfo info, ref PlayableCard __result)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Invalid comparison between Unknown and I4
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Invalid comparison between Unknown and I4
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Expected O, but got Unknown
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)Instance != (Object)null)
		{
			CardTemple rendererTemple = info.GetRendererTemple();
			if ((CardTemple?)rendererTemple == ActiveTemple)
			{
				return true;
			}
			DefaultRenderersPlugin.Log.LogInfo((object)"In Custom Make Card");
			Instance.SaveFileOverride = rendererTemple;
			GameObject val = Object.Instantiate<GameObject>(CardPrefabs[rendererTemple]);
			if ((int)rendererTemple == 3 && ActiveTemple != (CardTemple?)3)
			{
				info.appearanceBehaviour = new List<Appearance>(info.appearanceBehaviour) { OnboardWizardCardModel.ID };
			}
			PlayableCard component = val.GetComponent<PlayableCard>();
			((Card)component).SetInfo(info);
			__result = component;
			if ((int)rendererTemple == 1 && ActiveTemple == (CardTemple?)2 && component.OnBoard)
			{
				GameObject val2 = new GameObject("Part3Parent");
				val2.transform.SetParent(val.transform);
				val.transform.Find("RotatingParent").SetParent(val2.transform);
				val2.transform.localPosition = Vector3.zero;
				val2.transform.localScale = Vector3.one;
				val2.transform.localEulerAngles = new Vector3(90f, 180f, 0f);
			}
			Instance.SaveFileOverride = null;
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(CardAnimationController3D), "Awake")]
	[HarmonyPrefix]
	[HarmonyPriority(700)]
	private static bool DontFireAwakeDuringCustomRebuild(CardAnimationController3D __instance)
	{
		if ((Object)(object)((CardAnimationController)__instance).cardRenderer == (Object)null)
		{
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(CardDisplayer3D), "GetEmissivePortrait")]
	[HarmonyFinalizer]
	private static Exception PreventErrorForMissingArt(Exception __exception, ref Sprite __result)
	{
		if (__exception != null)
		{
			__result = null;
		}
		return null;
	}

	private static GameObject GetInnerCard(SelectableCard card)
	{
		if (InnerCardTable.TryGetValue(card, out var value))
		{
			return value;
		}
		return null;
	}

	private static void SetInnerCard(SelectableCard card, GameObject innerCard)
	{
		InnerCardTable.Remove(card);
		InnerCardTable.Add(card, innerCard);
	}

	private static Card GetOuterCard(CardAnimationController card)
	{
		if (OuterCardAnimatorTable.TryGetValue(card, out var value))
		{
			return value;
		}
		return null;
	}

	private static void SetOuterCard(CardAnimationController card, Card innerCard)
	{
		OuterCardAnimatorTable.Remove(card);
		OuterCardAnimatorTable.Add(card, innerCard);
	}

	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	[HarmonyPrefix]
	private static bool GetAnimFromChild(Card __instance, ref CardAnimationController __result)
	{
		SelectableCard val = (SelectableCard)(object)((__instance is SelectableCard) ? __instance : null);
		if (val != null && (Object)(object)Instance != (Object)null)
		{
			GameObject innerCard = GetInnerCard(val);
			if ((Object)(object)innerCard != (Object)null)
			{
				__result = innerCard.GetComponent<CardAnimationController>();
				return false;
			}
		}
		return true;
	}

	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	[HarmonyPrefix]
	private static bool GetCardFromAnim(CardAnimationController __instance, ref Card __result)
	{
		if ((Object)(object)Instance != (Object)null)
		{
			Card outerCard = GetOuterCard(__instance);
			if ((Object)(object)outerCard != (Object)null)
			{
				__result = outerCard;
				return false;
			}
		}
		return true;
	}

	private static void ReplaceGutsOfSelectableCard(SelectableCard __instance, CardInfo info, Action<SelectableCard> cardSelected = null, Action<SelectableCard> cardFlipped = null, bool? startFlipped = null, Action<SelectableCard> cardInspected = null)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Expected O, but got Unknown
		//IL_024b: Unknown result type (might be due to invalid IL or missing references)
		//IL_025c: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		//IL_028e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0294: Invalid comparison between Unknown and I4
		Instance.SaveFileOverride = info.GetRendererTemple();
		GameObject val = Object.Instantiate<GameObject>(SelectableCardPrefabs[info.GetRendererTemple()], ((Component)__instance).transform.parent);
		val.transform.localPosition = ((Component)__instance).transform.localPosition;
		val.transform.localScale = ((Component)__instance).transform.localScale;
		val.transform.localEulerAngles = ((Component)__instance).transform.localEulerAngles;
		Object.Destroy((Object)(object)val.GetComponent<Collider>());
		SelectableCard component = val.GetComponent<SelectableCard>();
		((Card)component).SetInfo(info);
		FieldInfo[] fields = typeof(SelectableCard).GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
		foreach (FieldInfo fieldInfo in fields)
		{
			if (!(fieldInfo.FieldType == typeof(CardChoice)))
			{
				DefaultRenderersPlugin.Log.LogInfo((object)$"Setting {fieldInfo} on new card");
				fieldInfo.SetValue(__instance, fieldInfo.GetValue(component));
			}
		}
		FieldInfo[] fields2 = typeof(Card).GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
		foreach (FieldInfo fieldInfo2 in fields2)
		{
			DefaultRenderersPlugin.Log.LogInfo((object)$"Setting {fieldInfo2} on new card");
			fieldInfo2.SetValue(__instance, fieldInfo2.GetValue(component));
		}
		Object.Destroy((Object)(object)component);
		List<Transform> list = new List<Transform>();
		foreach (Transform item2 in ((Component)__instance).gameObject.transform)
		{
			Transform item = item2;
			list.Add(item);
		}
		foreach (Transform item3 in list)
		{
			Object.Destroy((Object)(object)((Component)item3).gameObject);
		}
		Animator component2 = ((Component)__instance).GetComponent<Animator>();
		if ((Object)(object)component2 != (Object)null)
		{
			Object.Destroy((Object)(object)component2);
		}
		CardAnimationController component3 = ((Component)__instance).GetComponent<CardAnimationController>();
		if ((Object)(object)component3 != (Object)null)
		{
			Object.Destroy((Object)(object)component3);
		}
		val.transform.SetParent(((Component)__instance).transform);
		val.transform.localPosition = Vector3.zero;
		val.transform.localScale = Vector3.one;
		val.transform.localEulerAngles = Vector3.zero;
		SetInnerCard(__instance, val);
		SetOuterCard(val.GetComponent<CardAnimationController>(), (Card)(object)__instance);
		if ((int)info.GetRendererTemple() != 3)
		{
			return;
		}
		RenderStatsLayer statsLayer = ((Card)__instance).StatsLayer;
		PaperRenderStatsLayer val2 = (PaperRenderStatsLayer)(object)((statsLayer is PaperRenderStatsLayer) ? statsLayer : null);
		if (val2 != null)
		{
			((Card)__instance).defaultCardback = MAGNIFICUS_CARD_BACK_TEXTURE;
			if ((Object)(object)((RenderStatsLayer)val2).RigidRenderer != (Object)null && ((RenderStatsLayer)val2).RigidRenderer.materials.Length > 1)
			{
				((RenderStatsLayer)val2).RigidRenderer.materials[1].SetTexture("_MainTex", MAGNIFICUS_CARD_BACK_TEXTURE);
			}
			if ((Object)(object)val2.bendableCardRenderer != (Object)null && val2.bendableCardRenderer.materials.Length > 1)
			{
				val2.bendableCardRenderer.materials[1].SetTexture("_MainTex", MAGNIFICUS_CARD_BACK_TEXTURE);
			}
		}
	}

	[HarmonyPatch(typeof(SelectableCard), "Initialize", new Type[]
	{
		typeof(CardInfo),
		typeof(Action<SelectableCard>),
		typeof(Action<SelectableCard>),
		typeof(bool),
		typeof(Action<SelectableCard>)
	})]
	[HarmonyPrefix]
	[HarmonyPriority(700)]
	private static bool ReplacingGutsIsTheOnlyScalableWayButItsAHugeFuggingPain(CardInfo info, SelectableCard __instance, Action<SelectableCard> cardSelected = null, Action<SelectableCard> cardFlipped = null, bool startFlipped = false, Action<SelectableCard> cardInspected = null)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)Instance != (Object)null && (CardTemple?)info.GetRendererTemple() != ActiveTemple)
		{
			ReplaceGutsOfSelectableCard(__instance, info);
		}
		return true;
	}

	[HarmonyPatch(typeof(Card), "SetInfo")]
	[HarmonyPrefix]
	private static void SwapOutGutsHereTooFFS(Card __instance, CardInfo info)
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Invalid comparison between Unknown and I4
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Invalid comparison between Unknown and I4
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Invalid comparison between Unknown and I4
		if ((Object)(object)Instance == (Object)null)
		{
			return;
		}
		SelectableCard val = (SelectableCard)(object)((__instance is SelectableCard) ? __instance : null);
		if (!((Object)(object)val == (Object)null) && !((Object)(object)info == (Object)null))
		{
			CardTemple rendererTemple = info.GetRendererTemple();
			if (((int)rendererTemple != 0 || !(((Card)val).Anim is PaperCardAnimationController)) && ((int)rendererTemple != 2 || !(((Card)val).Anim is DiskCardAnimationController)) && ((int)rendererTemple != 1 || !(((Card)val).Anim is GravestoneCardAnimationController)) && ((int)rendererTemple != 3 || !(((Card)val).Anim is PaperCardAnimationController)))
			{
				ReplaceGutsOfSelectableCard(val, info);
			}
		}
	}

	[HarmonyPatch(typeof(Card), "SetFaceDown")]
	[HarmonyPrefix]
	private static bool DifferentAnimationWhenChangingTempleOfCard(Card __instance, bool faceDown, bool immediate = false)
	{
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Invalid comparison between Unknown and I4
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Invalid comparison between Unknown and I4
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Invalid comparison between Unknown and I4
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Invalid comparison between Unknown and I4
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: 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)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)Instance == (Object)null)
		{
			return true;
		}
		SelectableCard card = (SelectableCard)(object)((__instance is SelectableCard) ? __instance : null);
		if ((Object)(object)card == (Object)null || (Object)(object)((Card)card).Info == (Object)null)
		{
			return true;
		}
		CardTemple rendererTemple = ((Card)card).Info.GetRendererTemple();
		if (faceDown && (int)rendererTemple == 3 && ((Card)card).Anim is PaperCardAnimationController)
		{
			CustomCoroutine.WaitThenExecute(0.084f, (Action)delegate
			{
				((Card)card).SetCardback(MAGNIFICUS_CARD_BACK_TEXTURE);
			}, false);
		}
		if (!((Card)card).FaceDown || faceDown || (Object)(object)Instance == (Object)null)
		{
			return true;
		}
		if ((int)rendererTemple == 0 && ((Card)card).Anim is PaperCardAnimationController)
		{
			return true;
		}
		if ((int)rendererTemple == 2 && ((Card)card).Anim is DiskCardAnimationController)
		{
			return true;
		}
		if ((int)rendererTemple == 1 && ((Card)card).Anim is GravestoneCardAnimationController)
		{
			return true;
		}
		if ((int)rendererTemple == 3 && ((Card)card).Anim is PaperCardAnimationController)
		{
			return true;
		}
		Vector3 currentPos = ((Component)card).gameObject.transform.localPosition;
		Tween.LocalPosition(((Component)card).transform, currentPos + Vector3.forward * 3f, 0.25f, 0f, (AnimationCurve)null, (LoopType)0, (Action)null, (Action)delegate
		{
			//IL_0049: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			CardInfo info = ((Card)card).Info;
			ReplaceGutsOfSelectableCard(card, ((Card)card).Info);
			((Card)card).SetInfo(info);
			((Component)card).transform.localPosition = currentPos - Vector3.forward * 3f;
		}, true);
		Tween.LocalPosition(((Component)card).transform, currentPos, 0.25f, 0.35f, (AnimationCurve)null, (LoopType)0, (Action)null, (Action)null, true);
		return false;
	}

	[HarmonyPatch(typeof(GravestoneCardAnimationController), "PlayDeathAnimation")]
	[HarmonyPrefix]
	[HarmonyPriority(700)]
	private static bool PreventDefectWithGravestoneCards(GravestoneCardAnimationController __instance, bool playSound = true)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//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_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Expected O, but got Unknown
		//IL_0120: Expected O, but got Unknown
		if ((Object)(object)Instance == (Object)null || ActiveTemple == (CardTemple?)1)
		{
			return true;
		}
		if (Random.value < 0.33f)
		{
			__instance.PlayGlitchOutAnimation();
			return false;
		}
		Tween.ShaderColor(((CardAnimationController)__instance).Card.StatsLayer.Material, "_FadeColor", Color.black, 0.35f, 0f, Tween.EaseIn, (LoopType)0, (Action)null, (Action)delegate
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			((CardAnimationController)__instance).Card.StatsLayer.Material = __instance.fadeMaterial;
			Tween.ShaderColor(((CardAnimationController)__instance).Card.StatsLayer.Material, "_Color", new Color(0f, 0f, 0f, 0f), 0.35f, 0f, Tween.EaseLinear, (LoopType)0, (Action)null, (Action)null, true);
		}, true);
		((CardAnimationController)__instance).Anim.Play("die", 0, 0f);
		__instance.PlayDeathParticles();
		if (playSound)
		{
			AudioController.Instance.PlaySound3D("card_death", (MixerGroup)4, ((Component)__instance).transform.position, 1f, 0f, new Pitch((Variation)3), new Repetition(0.05f, ""), (Randomization)null, (Distortion)null, false);
		}
		return false;
	}

	[HarmonyPatch(typeof(SelectableCardArray), "GetCardYPos")]
	[HarmonyPostfix]
	private static void MakeCardArraysHigherWhenCardPoolIsMixed(ref float __result)
	{
		if ((Object)(object)Instance != (Object)null)
		{
			__result += 0.007f;
		}
	}

	[HarmonyPatch(typeof(SelectableCardArray), "TweenInCard")]
	[HarmonyPrefix]
	private static bool TweenWithAppropriateRotation(SelectableCardArray __instance, Transform cardTransform, Vector3 cardPos, float zRot, bool tiltCard = false)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: 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_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: 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)
		if (!tiltCard || (Object)(object)Instance == (Object)null)
		{
			return true;
		}
		float num = 2f;
		cardTransform.localPosition = cardPos;
		cardTransform.eulerAngles = new Vector3(90f + num, 90f, 90f);
		Vector3 position = cardTransform.position;
		Vector3 position2 = position + __instance.offscreenPositionOffset;
		cardTransform.position = position2;
		Tween.Position(cardTransform, position, 0.15f, 0f, Tween.EaseOut, (LoopType)0, (Action)null, (Action)null, true);
		return false;
	}

	[HarmonyPatch(typeof(Part3CardCostRender), "GetPiece")]
	[HarmonyPostfix]
	private static void FixTheApiAndGetPieceForPatchedCard(Card card, string key, ref GameObject __result)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)Instance == (Object)null) && ActiveTemple != (CardTemple?)2 && !((Object)(object)__result != (Object)null) && ((Component)card).transform.childCount != 0)
		{
			Transform child = ((Component)card).transform.GetChild(0);
			Transform val = child.Find(key);
			__result = ((val != null) ? ((Component)val).gameObject : null);
		}
	}

	[HarmonyPatch(typeof(FishHookGrab), "SetHookTargetSlot")]
	[HarmonyPrefix]
	private static bool FixHookAnimation(FishHookGrab __instance, CardSlot slot)
	{
		if ((Object)(object)__instance.hookTargetCard != (Object)null)
		{
			CardAnimationController anim = ((Card)__instance.hookTargetCard).Anim;
			PaperCardAnimationController val = (PaperCardAnimationController)(object)((anim is PaperCardAnimationController) ? anim : null);
			if (val != null && (Object)(object)val.fishHookMarker != (Object)null)
			{
				val.SetMarkedForFishHook(false);
			}
		}
		__instance.hookTargetSlot = slot;
		__instance.hookTargetCard = null;
		if ((Object)(object)__instance.hookTargetSlot != (Object)null && (Object)(object)__instance.hookTargetSlot.Card != (Object)null)
		{
			__instance.hookTargetCard = __instance.hookTargetSlot.Card;
			CardAnimationController anim2 = ((Card)__instance.hookTargetCard).Anim;
			PaperCardAnimationController val2 = (PaperCardAnimationController)(object)((anim2 is PaperCardAnimationController) ? anim2 : null);
			if (val2 != null && (Object)(object)val2.fishHookMarker != (Object)null)
			{
				val2.SetMarkedForFishHook(true);
			}
		}
		return false;
	}

	[HarmonyPatch(typeof(DiskTalkingCard), "SetAbilityIconsShown")]
	[HarmonyPrefix]
	private static bool PreventNREsOnDiskCards(DiskTalkingCard __instance, bool shown)
	{
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: 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)
		if ((Object)(object)((TalkingCard)__instance).CardCameraParent != (Object)null)
		{
			if ((Object)(object)__instance.abilityIcons == (Object)(object)__instance)
			{
				__instance.abilityIcons = ((Component)((TalkingCard)__instance).CardCameraParent).GetComponentInChildren<CardAbilityIcons>();
			}
			CardAbilityIcons abilityIcons = __instance.abilityIcons;
			if (abilityIcons != null)
			{
				abilityIcons.SetColorOfDefaultIcons((!shown) ? __instance.fadedAbilitiesColor : ((((SpecialCardBehaviour)__instance).Card.RenderInfo != null) ? ((SpecialCardBehaviour)__instance).Card.RenderInfo.defaultAbilityColor : GameColors.Instance.blue), false);
			}
		}
		return false;
	}
}
[BepInPlugin("zorro.inscryption.infiniscryption.defaultrenderers", "Infiniscryption Default Renderers", "1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class DefaultRenderersPlugin : BaseUnityPlugin
{
	internal const string PluginGuid = "zorro.inscryption.infiniscryption.defaultrenderers";

	internal const string PluginName = "Infiniscryption Default Renderers";

	internal const string PluginVersion = "1.0";

	internal const string CardPrefix = "DEFREN";

	internal static DefaultRenderersPlugin Instance;

	internal static ManualLogSource Log;

	internal bool RendererAlwaysActive => ((BaseUnityPlugin)this).Config.Bind<bool>("DefaultRenderersPlugin", "RendererAlwaysActive", false, new ConfigDescription("Set this to true to make cards always render according to their temple.", (AcceptableValueBase)null, Array.Empty<object>())).Value;

	private void Awake()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Expected O, but got Unknown
		try
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony val = new Harmony("zorro.inscryption.infiniscryption.defaultrenderers");
			val.PatchAll();
			CardManager.ModifyCardList += delegate(List<CardInfo> cards)
			{
				foreach (CardInfo card in cards)
				{
					CardInfo val2 = card;
					if (val2.traits == null)
					{
						val2.traits = new List<Trait>();
					}
				}
				return cards;
			};
			SceneManager.sceneLoaded += OnSceneLoaded;
			Instance = this;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Infiniscryption Default Renderers is loaded!");
		}
		catch (Exception ex)
		{
			Log.LogError((object)ex);
			throw;
		}
	}

	public void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		CardManager.SyncCardList();
		AbilityManager.SyncAbilityList();
		EncounterManager.SyncEncounterList();
		try
		{
			DefaultCardRenderer.Instantiate();
		}
		catch (Exception ex)
		{
			Log.LogWarning((object)ex);
		}
	}
}
public static class DefaultRenderersExtensions
{
	public static CardTemple GetRendererTemple(this CardInfo info)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		if (info.HasTrait((Trait)16))
		{
			return info.temple;
		}
		string extendedProperty = CardExtensions.GetExtendedProperty(info, "Renderer.OverrideTemple");
		if (!string.IsNullOrEmpty(extendedProperty) && Enum.TryParse<CardTemple>(extendedProperty, out CardTemple result))
		{
			return result;
		}
		if (!DefaultCardRenderer.EnabledForAllCards)
		{
			return DefaultCardRenderer.ActiveTemple.GetValueOrDefault(info.temple);
		}
		string extendedProperty2 = CardExtensions.GetExtendedProperty(info, "PackManager.OriginalTemple");
		if (!string.IsNullOrEmpty(extendedProperty2) && Enum.TryParse<CardTemple>(extendedProperty2, out CardTemple result2))
		{
			return result2;
		}
		return info.temple;
	}
}
[HarmonyPatch]
public class OnboardWizardCardModel : CardAppearanceBehaviour
{
	private readonly bool portraitSpawned = false;

	private static readonly Dictionary<GemType, string> DefaultWizardModels;

	private static readonly ConditionalWeakTable<WizardBattle3DPortrait, Transform> LastTargetSlot;

	public static Appearance ID { get; private set; }

	private static GameObject GetDefaultPrefab(PlayableCard card)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		if (((Card)card).Info.GemsCost.Count > 0)
		{
			return ResourceBank.Get<GameObject>(DefaultWizardModels[((Card)card).Info.GemsCost[0]]);
		}
		if (((Card)card).Info.Attack == 0)
		{
			return ResourceBank.Get<GameObject>("prefabs/finalemagnificus/Wizard3DPortrait_PracticeMage");
		}
		return ResourceBank.Get<GameObject>(DefaultWizardModels[(GemType)0]);
	}

	private GameObject GetPrefab(PlayableCard card)
	{
		string text = CardExtensions.GetExtendedProperty(((Card)card).Info, "Wizard3DPortrait");
		if (string.IsNullOrEmpty(text))
		{
			text = "prefabs/finalemagnificus/Wizard3DPortrait_" + ((Object)((CardAppearanceBehaviour)this).Card.Info).name;
		}
		try
		{
			return ResourceBank.Get<GameObject>(text) ?? GetDefaultPrefab(card);
		}
		catch
		{
			return GetDefaultPrefab(card);
		}
	}

	public override void ApplyAppearance()
	{
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Expected O, but got Unknown
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		CardAnimationController anim = ((CardAppearanceBehaviour)this).Card.Anim;
		WizardCardAnimationController val = (WizardCardAnimationController)(object)((anim is WizardCardAnimationController) ? anim : null);
		if (val == null)
		{
			return;
		}
		Card card = ((CardAppearanceBehaviour)this).Card;
		PlayableCard val2 = (PlayableCard)(object)((card is PlayableCard) ? card : null);
		if (val2 == null || !val2.OnBoard)
		{
			return;
		}
		GameObject prefab = GetPrefab(val2);
		if ((Object)(object)prefab == (Object)null)
		{
			return;
		}
		Transform val3 = ((Component)val2).transform.Find("CustomAnimationParent");
		if ((Object)(object)val3 == (Object)null)
		{
			GameObject val4 = new GameObject("CustomAnimationParent");
			val4.transform.SetParent(((Component)val2).transform);
			val4.transform.localPosition = Vector3.zero;
			val4.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
			GameObject val5 = Object.Instantiate<GameObject>(prefab, val4.transform);
			Transform obj = val5.transform.Find("Anim");
			if (obj != null)
			{
				((Component)obj).gameObject.SetActive(true);
			}
			val.WizardPortrait = val5.GetComponent<WizardBattle3DPortrait>();
			val5.SetActive(false);
		}
	}

	public override void OnPreRenderCard()
	{
		((CardAppearanceBehaviour)this).ApplyAppearance();
	}

	static OnboardWizardCardModel()
	{
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		DefaultWizardModels = new Dictionary<GemType, string>
		{
			{
				(GemType)2,
				"prefabs/finalemagnificus/Wizard3DPortrait_BlueMage"
			},
			{
				(GemType)1,
				"prefabs/finalemagnificus/Wizard3DPortrait_OrangeMage"
			},
			{
				(GemType)0,
				"prefabs/finalemagnificus/Wizard3DPortrait_JuniorSage"
			}
		};
		LastTargetSlot = new ConditionalWeakTable<WizardBattle3DPortrait, Transform>();
		ID = CardAppearanceBehaviourManager.Add("zorro.inscryption.infiniscryption.defaultrenderers", "OnboardWizardCardModel", typeof(OnboardWizardCardModel)).Id;
	}

	private static void FaceCorrectWay(WizardCardAnimationController anim)
	{
		//IL_0051: 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)
		if (((CardAnimationController)anim).PlayableCard.OpponentCard)
		{
			((Component)anim.WizardPortrait).transform.localEulerAngles = new Vector3(0f, 180f, 0f);
		}
		else
		{
			((Component)anim.WizardPortrait).transform.localEulerAngles = new Vector3(0f, 0f, 0f);
		}
	}

	[HarmonyPatch(typeof(WizardCardAnimationController), "PlayAttackAnimation", new Type[]
	{
		typeof(bool),
		typeof(CardSlot)
	})]
	[HarmonyPrefix]
	private static bool SpecialWizardAttack(WizardCardAnimationController __instance, bool attackPlayer, CardSlot targetSlot)
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)((CardAnimationController)__instance).PlayableCard != (Object)null && ((Card)((CardAnimationController)__instance).PlayableCard).Info.appearanceBehaviour.Contains(ID) && (Object)(object)__instance.WizardPortrait != (Object)null)
		{
			if ((Object)(object)targetSlot == (Object)null)
			{
				targetSlot = ((CardAnimationController)__instance).PlayableCard.Slot.opposingSlot;
			}
			FaceCorrectWay(__instance);
			((Component)__instance.WizardPortrait).gameObject.SetActive(true);
			SpecialPortraitAttack(__instance.WizardPortrait, delegate
			{
				((CardAnimationController)__instance).OnAttackImpact();
			}, attackPlayer, targetSlot);
			CustomCoroutine.WaitThenExecute(0.5f, (Action)delegate
			{
				((Component)__instance.WizardPortrait).gameObject.SetActive(false);
				Traverse.Create((object)__instance).Field("<DoingAttackAnimation>k__BackingField").SetValue((object)false);
			}, false);
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(WizardCardAnimationController), "PlayHitAnimation")]
	[HarmonyPrefix]
	private static bool SpecialWizardHit(WizardCardAnimationController __instance)
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)((CardAnimationController)__instance).PlayableCard != (Object)null && ((Card)((CardAnimationController)__instance).PlayableCard).Info.appearanceBehaviour.Contains(ID) && (Object)(object)__instance.WizardPortrait != (Object)null)
		{
			((Component)__instance.WizardPortrait).gameObject.SetActive(true);
			FaceCorrectWay(__instance);
			__instance.WizardPortrait.PlayHitAnimation();
			CustomCoroutine.WaitThenExecute(0.5f, (Action)delegate
			{
				((Component)__instance.WizardPortrait).gameObject.SetActive(false);
			}, false);
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(WizardBattle3DPortrait), "PlayHitAnimation")]
	[HarmonyPrefix]
	private static bool MissingHitAnimation(WizardBattle3DPortrait __instance)
	{
		if (!__instance.anim.parameters.Any((AnimatorControllerParameter p) => p.name.Equals("hit")) && __instance.anim.parameters.Any((AnimatorControllerParameter p) => p.name.Equals("die")))
		{
			__instance.anim.SetTrigger("die");
			CustomCoroutine.WaitThenExecute(0.5f, (Action)delegate
			{
				__instance.anim.Rebind();
			}, false);
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(WizardCardAnimationController), "PlayDeathAnimation")]
	[HarmonyPrefix]
	private static bool SpecialWizardDie(WizardCardAnimationController __instance, bool playSound)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Expected O, but got Unknown
		//IL_00c7: Expected O, but got Unknown
		if ((Object)(object)((CardAnimationController)__instance).PlayableCard != (Object)null && ((Card)((CardAnimationController)__instance).PlayableCard).Info.appearanceBehaviour.Contains(ID) && (Object)(object)__instance.WizardPortrait != (Object)null)
		{
			((Component)__instance.WizardPortrait).gameObject.SetActive(true);
			FaceCorrectWay(__instance);
			((CardAnimationController)__instance).Anim.SetBool("dying", true);
			((CardAnimationController)__instance).Anim.Play("death", 0, 0f);
			if (playSound)
			{
				AudioController.Instance.PlaySound3D("card_death", (MixerGroup)4, ((Component)__instance).transform.position, 1f, 0f, new Pitch((Variation)3), new Repetition(0.05f, ""), (Randomization)null, (Distortion)null, false);
			}
			__instance.WizardPortrait.PlayDeathAnimation(0.15f);
			return false;
		}
		return true;
	}

	private static void SetLastTargetSlot(WizardBattle3DPortrait portrait, Transform target)
	{
		LastTargetSlot.Remove(portrait);
		LastTargetSlot.Add(portrait, target);
	}

	private static Transform GetLastTargetSlot(WizardBattle3DPortrait portrait)
	{
		Transform value;
		return LastTargetSlot.TryGetValue(portrait, out value) ? value : null;
	}

	private static void SpecialPortraitAttack(WizardBattle3DPortrait portrait, Action impactCallback, bool attackPlayer, CardSlot target)
	{
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		portrait.projectileImpactCallback = impactCallback;
		SetLastTargetSlot(portrait, ((Component)target).transform);
		string animTrigger = "attack";
		if (!portrait.anim.parameters.Any((AnimatorControllerParameter p) => p.name.Equals("attack")))
		{
			animTrigger = "ability";
		}
		if (portrait.anim.parameters.Any((AnimatorControllerParameter p) => p.name.Equals(animTrigger)))
		{
			portrait.projectileDestination = ((Component)target).transform.position + Vector3.down * 30f;
			portrait.anim.SetTrigger(animTrigger);
		}
		else
		{
			Tween.Rotate(((Component)portrait).transform, new Vector3(0f, -200f, 0f), (Space)1, 0.6f, 0f, (AnimationCurve)null, (LoopType)0, (Action)null, (Action)delegate
			{
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				((Component)portrait).transform.localEulerAngles = Vector3.zero;
			}, true);
		}
	}

	[HarmonyPatch(typeof(WizardBattle3DPortrait), "OnFireProjectileKeyframe")]
	[HarmonyPrefix]
	private static bool SpecialProjectileKeyFrame(WizardBattle3DPortrait __instance)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Expected O, but got Unknown
		if (DefaultCardRenderer.ActiveTemple == (CardTemple?)3)
		{
			return true;
		}
		AudioController.Instance.PlaySound3D("wizard_cast", (MixerGroup)4, ((Component)__instance).transform.position, 1f, 0f, new Pitch((Variation)1), (Repetition)null, (Randomization)null, (Distortion)null, false).spatialBlend = 0.5f;
		return false;
	}
}