Decompiled source of TCGShopExpansionMod 0703 Patch v1.2.4

BepInEx/plugins/TCGShopExpansionMod0703Patch/TCGShopExpansionMod0703Patch.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using I2.Loc;
using Microsoft.CodeAnalysis;
using TCGShopExpansionMod.Handlers;
using TCGShopExpansionMod0703Patch.Patches;
using TMPro;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("TCGShopExpansionMod0703Patch")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+89938e8139244489dbcd9d0ac79611e738764844")]
[assembly: AssemblyProduct("TCGShopExpansionMod 0.70.3 Compatibility Patch")]
[assembly: AssemblyTitle("TCGShopExpansionMod0703Patch")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace TCGShopExpansionMod0703Patch
{
	[DefaultExecutionOrder(32760)]
	internal sealed class AlbumHoFoilRepairBehaviour : MonoBehaviour
	{
		private CardUI? _cardUi;

		private Coroutine? _endOfFrameLoop;

		public static void EnsureOn(CardUI cardUi)
		{
			if (!((Object)(object)cardUi == (Object)null))
			{
				AlbumHoFoilRepairBehaviour albumHoFoilRepairBehaviour = ((Component)cardUi).GetComponent<AlbumHoFoilRepairBehaviour>();
				if ((Object)(object)albumHoFoilRepairBehaviour == (Object)null)
				{
					albumHoFoilRepairBehaviour = ((Component)cardUi).gameObject.AddComponent<AlbumHoFoilRepairBehaviour>();
				}
				albumHoFoilRepairBehaviour._cardUi = cardUi;
				((Behaviour)albumHoFoilRepairBehaviour).enabled = true;
				if (albumHoFoilRepairBehaviour._endOfFrameLoop == null && ((Behaviour)albumHoFoilRepairBehaviour).isActiveAndEnabled)
				{
					albumHoFoilRepairBehaviour._endOfFrameLoop = ((MonoBehaviour)albumHoFoilRepairBehaviour).StartCoroutine(albumHoFoilRepairBehaviour.EndOfFrameRepairLoop());
				}
			}
		}

		public static void DisableOn(CardUI cardUi)
		{
			if (!((Object)(object)cardUi == (Object)null))
			{
				AlbumHoFoilRepairBehaviour component = ((Component)cardUi).GetComponent<AlbumHoFoilRepairBehaviour>();
				if ((Object)(object)component != (Object)null)
				{
					((Behaviour)component).enabled = false;
				}
			}
		}

		private void OnEnable()
		{
			if ((Object)(object)_cardUi != (Object)null && _endOfFrameLoop == null)
			{
				_endOfFrameLoop = ((MonoBehaviour)this).StartCoroutine(EndOfFrameRepairLoop());
			}
		}

		private void OnDisable()
		{
			if (_endOfFrameLoop != null)
			{
				((MonoBehaviour)this).StopCoroutine(_endOfFrameLoop);
				_endOfFrameLoop = null;
			}
		}

		private void LateUpdate()
		{
			if ((Object)(object)_cardUi == (Object)null)
			{
				((Behaviour)this).enabled = false;
			}
			else
			{
				TetramonOverlay0703Patches.RepairAlbumHoFoilMainTex(_cardUi);
			}
		}

		private IEnumerator EndOfFrameRepairLoop()
		{
			WaitForEndOfFrame wait = new WaitForEndOfFrame();
			while (((Behaviour)this).enabled && (Object)(object)_cardUi != (Object)null)
			{
				yield return wait;
				if ((Object)(object)_cardUi == (Object)null)
				{
					yield break;
				}
				TetramonOverlay0703Patches.RepairAlbumHoFoilMainTex(_cardUi);
			}
			_endOfFrameLoop = null;
		}
	}
	internal static class ArtExpanderBridge
	{
		private const BindingFlags StaticAny = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		private const BindingFlags InstanceAny = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

		private static bool _initialized;

		private static bool _available;

		private static readonly List<object> ArtCaches = new List<object>();

		private static MethodInfo? _resolveArtPath;

		private static MethodInfo? _loadSprite;

		private static bool _loggedAssetNameDump;

		private static readonly ECardBorderType[] BorderFallbackOrder;

		public static void TryInitialize()
		{
			EnsureInitialized();
		}

		public static void DumpBackAssetNames()
		{
			if (_loggedAssetNameDump || !EnsureInitialized())
			{
				return;
			}
			_loggedAssetNameDump = true;
			try
			{
				int num = 0;
				foreach (object artCache in ArtCaches)
				{
					string[] allAssetNames = GetAllAssetNames(artCache);
					if (allAssetNames == null)
					{
						continue;
					}
					num++;
					int num2 = 0;
					for (int i = 0; i < allAssetNames.Length; i++)
					{
						string text = allAssetNames[i].ToLowerInvariant();
						if (text.Contains("back") || text.Contains("pokemon") || text.Contains("sleeve") || text.Contains("reverse"))
						{
							Plugin.Log.LogWarning((object)$"BundleBackAsset[{num}]: {allAssetNames[i]}");
							num2++;
						}
					}
					Plugin.Log.LogWarning((object)$"ArtExpander bundle cache #{num}: {allAssetNames.Length} assets, {num2} back-like names.");
				}
				if (num == 0)
				{
					Plugin.Log.LogWarning((object)"DumpBackAssetNames: no enumerable bundle caches found.");
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("DumpBackAssetNames failed: " + ex.Message));
			}
		}

		public static Sprite? LoadSpriteByBundlePath(string assetPath)
		{
			if (string.IsNullOrEmpty(assetPath) || !EnsureInitialized() || _loadSprite == null)
			{
				return null;
			}
			for (int i = 0; i < ArtCaches.Count; i++)
			{
				object? obj = _loadSprite.Invoke(ArtCaches[i], new object[1] { assetPath });
				Sprite val = (Sprite)((obj is Sprite) ? obj : null);
				if (val != null && (Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			return null;
		}

		private static string[]? GetAllAssetNames(object cache)
		{
			object obj = cache.GetType().GetField("_bundleLoader", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(cache);
			if (obj == null)
			{
				return null;
			}
			return obj.GetType().GetMethod("GetAllAssetNames", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.Invoke(obj, Array.Empty<object>()) as string[];
		}

		public static Sprite? LoadCardArt(CardData cardData)
		{
			//IL_0056: 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_0059: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			if (cardData == null || !EnsureInitialized() || !_available)
			{
				return null;
			}
			Sprite val = TryLoadFromCaches(cardData);
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			if (cardData.isFoil)
			{
				CardData obj = CloneCardData(cardData);
				obj.isFoil = false;
				val = TryLoadFromCaches(obj);
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			for (int i = 0; i < BorderFallbackOrder.Length; i++)
			{
				ECardBorderType val2 = BorderFallbackOrder[i];
				if (val2 != cardData.borderType)
				{
					CardData obj2 = CloneCardData(cardData);
					obj2.borderType = val2;
					val = TryLoadFromCaches(obj2);
					if ((Object)(object)val != (Object)null)
					{
						return val;
					}
				}
			}
			return null;
		}

		private static Sprite? TryLoadFromCaches(CardData cardData)
		{
			for (int i = 0; i < ArtCaches.Count; i++)
			{
				Sprite val = LoadFromCache(ArtCaches[i], cardData);
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			return null;
		}

		private static CardData CloneCardData(CardData source)
		{
			//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_000d: Expected O, but got Unknown
			CardData val = new CardData();
			val.CopyData(source);
			return val;
		}

		private static Sprite? LoadFromCache(object cache, CardData cardData)
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			if (_resolveArtPath == null || _loadSprite == null)
			{
				return null;
			}
			object[] array = _resolveArtPath.GetParameters().Length switch
			{
				5 => new object[5] { cardData.monsterType, cardData.borderType, cardData.expansionType, cardData.isDestiny, cardData.isFoil }, 
				4 => new object[4] { cardData.monsterType, cardData.borderType, cardData.expansionType, cardData.isDestiny }, 
				_ => null, 
			};
			if (array == null)
			{
				return null;
			}
			if (!(_resolveArtPath.Invoke(cache, array) is string text) || string.IsNullOrEmpty(text))
			{
				return null;
			}
			object? obj = _loadSprite.Invoke(cache, new object[1] { text });
			return (Sprite?)((obj is Sprite) ? obj : null);
		}

		private static bool EnsureInitialized()
		{
			if (_initialized)
			{
				return _available;
			}
			_initialized = true;
			try
			{
				Type type = FindArtExpanderPluginType();
				if (type == null)
				{
					Plugin.Log.LogWarning((object)"ArtExpander bridge: Plugin type not found.");
					return false;
				}
				CollectArtCaches(type);
				if (ArtCaches.Count == 0)
				{
					Plugin.Log.LogWarning((object)"ArtExpander bridge: no ArtCache fields found.");
					return false;
				}
				Type type2 = ArtCaches[0].GetType();
				_resolveArtPath = FindResolveArtPathMethod(type2);
				_loadSprite = type2.GetMethod("LoadSprite", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(string) }, null);
				_available = _resolveArtPath != null && _loadSprite != null;
				if (_available)
				{
					Plugin.Log.LogInfo((object)$"ArtExpander bridge ready ({ArtCaches.Count} cache(s), cardart.assets).");
				}
				else
				{
					Plugin.Log.LogWarning((object)$"ArtExpander bridge: methods missing (ResolveArtPath={_resolveArtPath != null}, LoadSprite={_loadSprite != null}).");
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("ArtExpander bridge init failed: " + ex.Message));
				_available = false;
			}
			return _available;
		}

		private static MethodInfo? FindResolveArtPathMethod(Type cacheType)
		{
			MethodInfo[] methods = cacheType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (MethodInfo methodInfo in methods)
			{
				if (!(methodInfo.Name != "ResolveArtPath"))
				{
					ParameterInfo[] parameters = methodInfo.GetParameters();
					if (parameters.Length >= 4 && parameters[0].ParameterType == typeof(EMonsterType))
					{
						return methodInfo;
					}
				}
			}
			return null;
		}

		private static Type? FindArtExpanderPluginType()
		{
			Type type = Type.GetType("ArtExpander.Plugin, ArtExpander");
			if (type != null)
			{
				return type;
			}
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				if (string.Equals(assembly.GetName().Name, "ArtExpander", StringComparison.OrdinalIgnoreCase))
				{
					Type type2 = assembly.GetType("ArtExpander.Plugin", throwOnError: false);
					if (type2 != null)
					{
						return type2;
					}
				}
			}
			return null;
		}

		private static void CollectArtCaches(Type pluginType)
		{
			string[] array = new string[3] { "art_cache", "art_cache_bundle", "art_cache_directory" };
			for (int i = 0; i < array.Length; i++)
			{
				TryAddCacheField(pluginType, array[i]);
			}
			FieldInfo[] fields = pluginType.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo fieldInfo in fields)
			{
				if (IsArtCacheField(fieldInfo))
				{
					AddCacheValue(fieldInfo.GetValue(null));
				}
			}
		}

		private static void TryAddCacheField(Type pluginType, string fieldName)
		{
			FieldInfo field = pluginType.GetField(fieldName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			if (!(field == null))
			{
				AddCacheValue(field.GetValue(null));
			}
		}

		private static void AddCacheValue(object? cache)
		{
			if (cache != null && !ArtCaches.Contains(cache))
			{
				ArtCaches.Add(cache);
			}
		}

		private static bool IsArtCacheField(FieldInfo field)
		{
			if (!string.Equals(field.FieldType.Name, "ArtCache", StringComparison.Ordinal))
			{
				return string.Equals(field.FieldType.FullName, "ArtExpander.Core.ArtCache", StringComparison.Ordinal);
			}
			return true;
		}

		static ArtExpanderBridge()
		{
			ECardBorderType[] array = new ECardBorderType[7];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			BorderFallbackOrder = (ECardBorderType[])(object)array;
		}
	}
	internal static class Card3dInteractableRegistry
	{
		private static readonly Dictionary<Card3dUIGroup, InteractableCard3d> ByCard3d = new Dictionary<Card3dUIGroup, InteractableCard3d>();

		public static void Register(Card3dUIGroup? card3d, InteractableCard3d? interactable)
		{
			if (!((Object)(object)card3d == (Object)null))
			{
				if ((Object)(object)interactable == (Object)null)
				{
					ByCard3d.Remove(card3d);
				}
				else
				{
					ByCard3d[card3d] = interactable;
				}
			}
		}

		public static void UnregisterInteractable(InteractableCard3d interactable)
		{
			if (!((Object)(object)interactable?.m_Card3dUI == (Object)null))
			{
				ByCard3d.Remove(interactable.m_Card3dUI);
			}
		}

		public static InteractableCard3d? FindForCardUi(CardUI cardUi)
		{
			if ((Object)(object)cardUi == (Object)null)
			{
				return null;
			}
			InteractableCard3d componentInParent = ((Component)cardUi).GetComponentInParent<InteractableCard3d>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				return componentInParent;
			}
			object? value = CardUiFieldAccess.GetValue(cardUi, "m_Card3dUIGroup");
			Card3dUIGroup val = (Card3dUIGroup)((value is Card3dUIGroup) ? value : null);
			if (val != null && ByCard3d.TryGetValue(val, out var value2))
			{
				return value2;
			}
			return null;
		}
	}
	internal static class Card3dUiGroupAccess
	{
		private const BindingFlags InstanceAny = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

		private static readonly Dictionary<string, FieldInfo> Fields = new Dictionary<string, FieldInfo>(StringComparer.Ordinal);

		public static object? GetValue(Card3dUIGroup group, string fieldName)
		{
			return GetField(fieldName)?.GetValue(group);
		}

		private static FieldInfo? GetField(string fieldName)
		{
			if (Fields.TryGetValue(fieldName, out var value))
			{
				return value;
			}
			FieldInfo field = typeof(Card3dUIGroup).GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				Fields[fieldName] = field;
			}
			return field;
		}
	}
	internal static class CardExtrasCacheAccess
	{
		private const string PackStackBackSpriteName = "T_CardBackMesh";

		private const string UiCardBackSpriteName = "CardBack";

		private const string CardExtrasFolderName = "CardExtrasImages";

		private static readonly FieldInfo? CardExtrasImagesCacheField = typeof(NewSwappingHandler).Assembly.GetType("TCGShopExpansionMod.Handlers.CacheHandler")?.GetField("cardExtrasImagesCache", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo? OriginalCardExtrasImagesCacheField = typeof(NewSwappingHandler).Assembly.GetType("TCGShopExpansionMod.Handlers.CacheHandler")?.GetField("originalCardExtrasImagesCache", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo? OriginalCardBackTextureField = typeof(NewSwappingHandler).Assembly.GetType("TCGShopExpansionMod.Handlers.CacheHandler")?.GetField("originalCardBackTexture", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static Sprite? _uiCardBackSprite;

		private static Sprite? _stackBackMeshSprite;

		private static Sprite? _pokemonUiBackSprite;

		private static bool _loggedUiCardBackSource;

		private static bool _loggedStackBackSource;

		private static bool _triedPokemonUiBack;

		public static Sprite? TryGetPokemonUiBackSprite()
		{
			if ((Object)(object)_pokemonUiBackSprite != (Object)null)
			{
				return _pokemonUiBackSprite;
			}
			if (_triedPokemonUiBack)
			{
				return null;
			}
			_triedPokemonUiBack = true;
			string text = Path.Combine(Paths.PluginPath, "TextureReplacer", "objects_textures", "CardBack.png");
			_pokemonUiBackSprite = TryLoadSpriteFromPath(text, "PokemonCardBack");
			if ((Object)(object)_pokemonUiBackSprite != (Object)null)
			{
				Plugin.Log.LogInfo((object)("Pokemon UI card back resolved from TextureReplacer: " + text));
			}
			else
			{
				Plugin.Log.LogWarning((object)("Pokemon UI card back not found at " + text + "; falling back to ExpansionMod CardBack."));
			}
			return _pokemonUiBackSprite;
		}

		public static Sprite? TryGetCachedSprite(string spriteName)
		{
			Sprite val = TryGetSpriteFromCacheList(CardExtrasImagesCacheField, spriteName);
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			Sprite val2 = TryGetSpriteFromCacheList(OriginalCardExtrasImagesCacheField, spriteName);
			if ((Object)(object)val2 != (Object)null)
			{
				return val2;
			}
			if (spriteName == "T_CardBackMesh")
			{
				object? obj = OriginalCardBackTextureField?.GetValue(null);
				Sprite val3 = (Sprite)((obj is Sprite) ? obj : null);
				if (val3 != null)
				{
					return val3;
				}
			}
			return TryLoadSpriteFromDisk(spriteName);
		}

		public static Sprite? TryGetUiCardBackSprite()
		{
			if ((Object)(object)_uiCardBackSprite != (Object)null)
			{
				return _uiCardBackSprite;
			}
			_uiCardBackSprite = TryGetCachedSprite("CardBack");
			if ((Object)(object)_uiCardBackSprite != (Object)null && !_loggedUiCardBackSource)
			{
				_loggedUiCardBackSource = true;
				Plugin.Log.LogInfo((object)$"Pack UI card back resolved: {"CardBack"} ({((Object)_uiCardBackSprite).name})");
			}
			return _uiCardBackSprite;
		}

		public static Sprite? TryGetStackBackMeshSprite()
		{
			if ((Object)(object)_stackBackMeshSprite != (Object)null)
			{
				return _stackBackMeshSprite;
			}
			_stackBackMeshSprite = TryGetCachedSprite("T_CardBackMesh");
			if ((Object)(object)_stackBackMeshSprite != (Object)null && !_loggedStackBackSource)
			{
				_loggedStackBackSource = true;
				Plugin.Log.LogInfo((object)$"Pack stack mesh back resolved: {"T_CardBackMesh"} ({((Object)_stackBackMeshSprite).name})");
			}
			return _stackBackMeshSprite;
		}

		private static Sprite? TryGetSpriteFromCacheList(FieldInfo? cacheField, string spriteName)
		{
			if (!(cacheField?.GetValue(null) is List<Sprite> list))
			{
				return null;
			}
			return NewSwappingHandler.TryGetSpriteFromCache(list, spriteName);
		}

		private static Sprite? TryLoadSpriteFromDisk(string spriteName)
		{
			string cardExtrasImagesDirectory = GetCardExtrasImagesDirectory();
			if (cardExtrasImagesDirectory == null)
			{
				return null;
			}
			return TryLoadSpriteFromPath(Path.Combine(cardExtrasImagesDirectory, spriteName + ".png"), spriteName);
		}

		private static Sprite? TryLoadSpriteFromPath(string pngPath, string spriteName)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_004f: 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 (!File.Exists(pngPath))
			{
				return null;
			}
			try
			{
				byte[] array = File.ReadAllBytes(pngPath);
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				if (!ImageConversion.LoadImage(val, array))
				{
					Object.Destroy((Object)(object)val);
					return null;
				}
				((Object)val).name = spriteName;
				Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
				((Object)obj).name = spriteName;
				return obj;
			}
			catch
			{
				return null;
			}
		}

		private static string? GetCardExtrasImagesDirectory()
		{
			Type type = AccessToolsTypeByName("TCGShopExpansionMod.Patches.PlayerPatches");
			if (type == null)
			{
				return null;
			}
			if (type.GetField("cardExtrasImages", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(null) is string text && !string.IsNullOrEmpty(text))
			{
				return text.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
			}
			if (type.GetField("customExpansionPackImages", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(null) is string text2 && !string.IsNullOrEmpty(text2))
			{
				return Path.Combine(text2.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar), "CardExtrasImages");
			}
			return null;
		}

		private static Type? AccessToolsTypeByName(string name)
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			for (int i = 0; i < assemblies.Length; i++)
			{
				Type type = assemblies[i].GetType(name, throwOnError: false);
				if (type != null)
				{
					return type;
				}
			}
			return null;
		}
	}
	internal static class CardOpeningSequenceFieldAccess
	{
		private const BindingFlags InstanceAny = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

		private static readonly Dictionary<string, FieldInfo> Fields = new Dictionary<string, FieldInfo>(StringComparer.Ordinal);

		public static object? GetValue(CardOpeningSequence sequence, string fieldName)
		{
			return GetField(fieldName)?.GetValue(sequence);
		}

		public static void SetValue(CardOpeningSequence sequence, string fieldName, object? value)
		{
			GetField(fieldName)?.SetValue(sequence, value);
		}

		private static FieldInfo? GetField(string fieldName)
		{
			if (Fields.TryGetValue(fieldName, out var value))
			{
				return value;
			}
			FieldInfo field = typeof(CardOpeningSequence).GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				Fields[fieldName] = field;
			}
			return field;
		}
	}
	internal static class CardUiDisplayContext
	{
		public static Card3dUIGroup? ResolveCard3dGroup(CardUI cardUi)
		{
			if ((Object)(object)cardUi == (Object)null)
			{
				return null;
			}
			object? value = CardUiFieldAccess.GetValue(cardUi, "m_Card3dUIGroup");
			Card3dUIGroup val = (Card3dUIGroup)((value is Card3dUIGroup) ? value : null);
			if (val != null)
			{
				return val;
			}
			return ((Component)cardUi).GetComponentInParent<Card3dUIGroup>();
		}

		public static bool IsBinderAlbumCard(CardUI cardUi)
		{
			if ((Object)(object)cardUi == (Object)null)
			{
				return false;
			}
			if ((Object)(object)((Component)cardUi).GetComponentInParent<BinderPageGrp>() != (Object)null)
			{
				return true;
			}
			Card3dUIGroup? obj = ResolveCard3dGroup(cardUi);
			if ((Object)(object)((obj != null) ? ((Component)obj).GetComponentInParent<BinderPageGrp>() : null) != (Object)null)
			{
				return true;
			}
			InteractableCard3d val = Card3dInteractableRegistry.FindForCardUi(cardUi);
			if ((Object)(object)val != (Object)null)
			{
				if (!val.m_IsCardAlbumCard)
				{
					return (Object)(object)val.m_CollectionBinderFlipAnimCtrl != (Object)null;
				}
				return true;
			}
			return false;
		}

		public static bool ShouldUseRotatableWorldCardBack(CardUI cardUi)
		{
			if ((Object)(object)cardUi == (Object)null || IsFlatAlbumOrBinderCard(cardUi))
			{
				return false;
			}
			if (PackOpeningState.IsPackOpeningInProgress() || PackOpeningState.IsFanRowVisible())
			{
				return false;
			}
			if ((Object)(object)ResolveCard3dGroup(cardUi) == (Object)null)
			{
				return false;
			}
			InteractableCard3d val = Card3dInteractableRegistry.FindForCardUi(cardUi);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			if (val.m_IsCardAlbumCard || (Object)(object)val.m_CollectionBinderFlipAnimCtrl != (Object)null)
			{
				return false;
			}
			return val.IsDisplayedOnShelf();
		}

		public static bool IsFlatAlbumOrBinderCard(CardUI cardUi)
		{
			if (IsBinderAlbumCard(cardUi))
			{
				return true;
			}
			InteractableCard3d val = Card3dInteractableRegistry.FindForCardUi(cardUi);
			if ((Object)(object)val != (Object)null)
			{
				if (!val.m_IsCardAlbumCard)
				{
					return (Object)(object)val.m_CollectionBinderFlipAnimCtrl != (Object)null;
				}
				return true;
			}
			return false;
		}
	}
	internal static class CardUiFieldAccess
	{
		private const BindingFlags InstanceAny = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

		private static readonly Dictionary<string, FieldInfo> Fields = new Dictionary<string, FieldInfo>(StringComparer.Ordinal);

		public static object? GetValue(CardUI cardUi, string fieldName)
		{
			return GetField(fieldName)?.GetValue(cardUi);
		}

		private static FieldInfo? GetField(string fieldName)
		{
			if (Fields.TryGetValue(fieldName, out var value))
			{
				return value;
			}
			FieldInfo field = typeof(CardUI).GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				Fields[fieldName] = field;
			}
			return field;
		}
	}
	internal static class CashRegisterTmpRepair
	{
		private const int DefaultHudImageQueue = 3005;

		private static bool _loggedQueueSample;

		public static void RepairHierarchy(Transform? root, string reason)
		{
			if ((Object)(object)root == (Object)null)
			{
				return;
			}
			PhoneFontMaterialSnapshot.CaptureIfNeeded();
			int num = ResolveMaxImageRenderQueue(root);
			int num2 = 0;
			TextMeshProUGUI[] componentsInChildren = ((Component)root).GetComponentsInChildren<TextMeshProUGUI>(true);
			foreach (TextMeshProUGUI val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && RepairLabel(val, num))
				{
					num2++;
				}
			}
			PhoneCanvasRepair.EnsurePhoneCanvasesReady(root);
			if (!_loggedQueueSample)
			{
				_loggedQueueSample = true;
				Plugin.Log.LogInfo((object)$"Cash/credit TMP repair sample: maxImageQueue={num}, labels={num2}, reason={reason}.");
			}
			else
			{
				Plugin.Log.LogInfo((object)$"Cash/credit TMP repair ({reason}): {num2} label(s) under '{((Object)root).name}'.");
			}
		}

		private static int ResolveMaxImageRenderQueue(Transform root)
		{
			int num = 3005;
			Image[] componentsInChildren = ((Component)root).GetComponentsInChildren<Image>(true);
			foreach (Image val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null))
				{
					Material val2 = ((Graphic)val).materialForRendering ?? ((Graphic)val).material;
					if ((Object)(object)val2 != (Object)null && val2.renderQueue > num)
					{
						num = val2.renderQueue;
					}
				}
			}
			return num;
		}

		private static bool RepairLabel(TextMeshProUGUI label, int targetQueue)
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			TMP_FontAsset font = ((TMP_Text)label).font;
			if ((Object)(object)font == (Object)null)
			{
				return false;
			}
			Material val = ((TMP_Text)label).fontMaterial;
			if ((Object)(object)val != (Object)null && ((Object)val).name != null && ((Object)val).name.StartsWith("PhoneLabel_", StringComparison.Ordinal))
			{
				((TMP_Text)label).fontMaterial = null;
				val = null;
			}
			Material val2 = (((Object)(object)val != (Object)null && ((Object)val).name != null && ((Object)val).name.StartsWith("HudLabel_", StringComparison.Ordinal)) ? val : (((TMP_Text)label).fontMaterial = PhoneFontMaterialSnapshot.CreateHudLabelMaterial(font)));
			int num = targetQueue + 1;
			if (val2.renderQueue < num)
			{
				val2.renderQueue = num;
			}
			if (((Graphic)label).color.a < 0.05f || (((Graphic)label).color.r < 0.05f && ((Graphic)label).color.g < 0.05f && ((Graphic)label).color.b < 0.05f))
			{
				((Graphic)label).color = Color.white;
			}
			((TMP_Text)label).faceColor = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
			((Behaviour)label).enabled = true;
			if ((Object)(object)((Component)label).gameObject != (Object)null && !((Component)label).gameObject.activeSelf)
			{
				((Component)label).gameObject.SetActive(true);
			}
			PhoneCanvasRepair.EnsureLabelCanvasChannels(((Graphic)label).canvas);
			CanvasRenderer canvasRenderer = label.canvasRenderer;
			if ((Object)(object)canvasRenderer != (Object)null)
			{
				canvasRenderer.SetColor(Color.white);
				canvasRenderer.SetAlpha(1f);
				canvasRenderer.cull = false;
				canvasRenderer.cullTransparentMesh = false;
				canvasRenderer.materialCount = 1;
				canvasRenderer.SetMaterial(val2, 0);
				if ((Object)(object)font.atlasTexture != (Object)null)
				{
					canvasRenderer.SetTexture((Texture)(object)font.atlasTexture);
				}
			}
			((Graphic)label).SetAllDirty();
			if (((Component)label).gameObject.activeInHierarchy)
			{
				((TMP_Text)label).ForceMeshUpdate(true, false);
			}
			return true;
		}
	}
	internal static class GradedCardCaseSprite
	{
		private const string SpriteName = "GradedCardCase";

		private const int TextureSize = 512;

		private static Sprite? _sprite;

		private static Texture2D? _texture;

		private static bool _loggedSource;

		public static readonly Vector2 SlabAnchorMin = new Vector2(0.17f, 0.05f);

		public static readonly Vector2 SlabAnchorMax = new Vector2(0.83f, 0.95f);

		public static readonly Vector2 FaceAnchorMin = new Vector2(0.26f, 0.09f);

		public static readonly Vector2 FaceAnchorMax = new Vector2(0.74f, 0.75f);

		public static readonly Vector2 HeaderAnchorMin = new Vector2(0.21f, 0.78f);

		public static readonly Vector2 HeaderAnchorMax = new Vector2(0.79f, 0.92f);

		public static Sprite Get()
		{
			if ((Object)(object)_sprite != (Object)null)
			{
				return _sprite;
			}
			Sprite val = TryLoadFromTextureReplacer();
			if ((Object)(object)val != (Object)null && !LooksLikeBrokenStub(val))
			{
				_sprite = val;
				LogSource("TextureReplacer/objects_textures");
				return _sprite;
			}
			Sprite val2 = TryLoadFromPluginResources();
			if ((Object)(object)val2 != (Object)null && !LooksLikeBrokenStub(val2))
			{
				_sprite = val2;
				LogSource("plugin Resources");
				return _sprite;
			}
			_sprite = CreateProceduralSlabSprite();
			LogSource($"procedural {512}x{512}");
			return _sprite;
		}

		private static void LogSource(string source)
		{
			if (!_loggedSource)
			{
				_loggedSource = true;
				Plugin.Log.LogInfo((object)("GradedCardCase sprite restored from " + source + "."));
			}
		}

		private static bool LooksLikeBrokenStub(Sprite sprite)
		{
			//IL_0060: 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_0068: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			Texture2D texture = sprite.texture;
			if ((Object)(object)texture == (Object)null)
			{
				return true;
			}
			if (((Texture)texture).width <= 64 || ((Texture)texture).height <= 64)
			{
				return true;
			}
			try
			{
				Color32[] pixels = texture.GetPixels32();
				if (pixels == null || pixels.Length == 0)
				{
					return false;
				}
				long num = 0L;
				int num2 = 0;
				int num3 = Mathf.Max(1, pixels.Length / 256);
				int num4 = 0;
				for (int i = 0; i < pixels.Length; i += num3)
				{
					Color32 val = pixels[i];
					num += val.r + val.g + val.b;
					if (val.a > 8)
					{
						num2++;
					}
					num4++;
				}
				if (num4 <= 0)
				{
					return true;
				}
				return (float)num / (float)(num4 * 3) < 4f && num2 > num4 / 2;
			}
			catch
			{
				return false;
			}
		}

		private static Sprite? TryLoadFromTextureReplacer()
		{
			return LoadSpriteFile(Path.Combine(Paths.PluginPath, "TextureReplacer", "objects_textures", "GradedCardCase.png"));
		}

		private static Sprite? TryLoadFromPluginResources()
		{
			return LoadSpriteFile(Path.Combine(Path.GetDirectoryName(typeof(GradedCardCaseSprite).Assembly.Location) ?? string.Empty, "Resources", "GradedCardCase.png"));
		}

		private static Sprite? LoadSpriteFile(string path)
		{
			//IL_0016: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_0061: 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)
			if (!File.Exists(path))
			{
				return null;
			}
			try
			{
				byte[] array = File.ReadAllBytes(path);
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false)
				{
					name = "GradedCardCase",
					filterMode = (FilterMode)1,
					wrapMode = (TextureWrapMode)1
				};
				if (!ImageConversion.LoadImage(val, array))
				{
					Object.Destroy((Object)(object)val);
					return null;
				}
				Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
				((Object)obj).name = "GradedCardCase";
				return obj;
			}
			catch
			{
				return null;
			}
		}

		private static Sprite? TryFindLoadedSprite()
		{
			Sprite[] array = Resources.FindObjectsOfTypeAll<Sprite>();
			foreach (Sprite val in array)
			{
				if (!((Object)(object)val == (Object)null) && ((Object)val).name != null && (string.Equals(((Object)val).name, "GradedCardCase", StringComparison.OrdinalIgnoreCase) || string.Equals(((Object)val).name, "GradedCardCase(Clone)", StringComparison.OrdinalIgnoreCase)))
				{
					return val;
				}
			}
			return null;
		}

		private static Sprite CreateProceduralSlabSprite()
		{
			//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_001c: 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_002f: Expected O, but got Unknown
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			_texture = new Texture2D(512, 512, (TextureFormat)4, false)
			{
				name = "GradedCardCase0703",
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)1
			};
			Color32 val = default(Color32);
			((Color32)(ref val))..ctor((byte)0, (byte)0, (byte)0, (byte)0);
			Color32 color = default(Color32);
			((Color32)(ref color))..ctor((byte)18, (byte)20, (byte)24, byte.MaxValue);
			Color32 color2 = default(Color32);
			((Color32)(ref color2))..ctor((byte)72, (byte)78, (byte)88, byte.MaxValue);
			Color32 color3 = default(Color32);
			((Color32)(ref color3))..ctor((byte)175, (byte)182, (byte)195, (byte)240);
			Color32 color4 = default(Color32);
			((Color32)(ref color4))..ctor((byte)36, (byte)40, (byte)46, byte.MaxValue);
			Color32 color5 = default(Color32);
			((Color32)(ref color5))..ctor((byte)14, (byte)15, (byte)18, byte.MaxValue);
			Color32 color6 = default(Color32);
			((Color32)(ref color6))..ctor((byte)175, (byte)182, (byte)192, (byte)230);
			Color32[] array = (Color32[])(object)new Color32[262144];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = val;
			}
			int num = Mathf.RoundToInt(512f * SlabAnchorMin.x);
			int num2 = Mathf.RoundToInt(512f * SlabAnchorMin.y);
			int num3 = Mathf.RoundToInt(512f * SlabAnchorMax.x) - 1;
			int num4 = Mathf.RoundToInt(512f * SlabAnchorMax.y) - 1;
			FillRoundedRect(array, 512, num, num2, num3, num4, 18, color2);
			StrokeRoundedRect(array, 512, num, num2, num3, num4, 18, color3, 3);
			StrokeRoundedRect(array, 512, num + 5, num2 + 5, num3 - 5, num4 - 5, 14, color4, 2);
			int num5 = Mathf.RoundToInt(512f * HeaderAnchorMin.x);
			int num6 = Mathf.RoundToInt(512f * HeaderAnchorMax.x) - 1;
			int num7 = Mathf.RoundToInt(512f * HeaderAnchorMin.y);
			int y = Mathf.RoundToInt(512f * HeaderAnchorMax.y) - 1;
			FillRoundedRect(array, 512, num5, num7, num6, y, 6, color5);
			FillRect(array, 512, num5 + 4, num7 - 3, num6 - 4, num7 - 1, color6);
			int x = Mathf.RoundToInt(512f * FaceAnchorMin.x);
			int x2 = Mathf.RoundToInt(512f * FaceAnchorMax.x) - 1;
			int y2 = Mathf.RoundToInt(512f * FaceAnchorMin.y);
			int y3 = Mathf.RoundToInt(512f * FaceAnchorMax.y) - 1;
			FillRect(array, 512, x, y2, x2, y3, color);
			StrokeRect(array, 512, x, y2, x2, y3, color4, 2);
			_texture.SetPixels32(array);
			_texture.Apply(false, false);
			Sprite obj = Sprite.Create(_texture, new Rect(0f, 0f, 512f, 512f), new Vector2(0.5f, 0.5f), 100f);
			((Object)obj).name = "GradedCardCase0703";
			return obj;
		}

		private static void FillRect(Color32[] pixels, int size, int x0, int y0, int x1, int y1, Color32 color)
		{
			//IL_0042: 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)
			x0 = Mathf.Clamp(x0, 0, size - 1);
			x1 = Mathf.Clamp(x1, 0, size - 1);
			y0 = Mathf.Clamp(y0, 0, size - 1);
			y1 = Mathf.Clamp(y1, 0, size - 1);
			for (int i = y0; i <= y1; i++)
			{
				int num = i * size;
				for (int j = x0; j <= x1; j++)
				{
					pixels[num + j] = color;
				}
			}
		}

		private static void StrokeRect(Color32[] pixels, int size, int x0, int y0, int x1, int y1, Color32 color, int width)
		{
			//IL_0013: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < width; i++)
			{
				FillRect(pixels, size, x0 + i, y0 + i, x1 - i, y0 + i, color);
				FillRect(pixels, size, x0 + i, y1 - i, x1 - i, y1 - i, color);
				FillRect(pixels, size, x0 + i, y0 + i, x0 + i, y1 - i, color);
				FillRect(pixels, size, x1 - i, y0 + i, x1 - i, y1 - i, color);
			}
		}

		private static void FillRoundedRect(Color32[] pixels, int size, int x0, int y0, int x1, int y1, int radius, Color32 color)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			radius = Mathf.Max(0, Mathf.Min(new int[3]
			{
				radius,
				(x1 - x0) / 2,
				(y1 - y0) / 2
			}));
			for (int i = y0; i <= y1; i++)
			{
				for (int j = x0; j <= x1; j++)
				{
					if (InsideRoundedRect(j, i, x0, y0, x1, y1, radius))
					{
						pixels[i * size + j] = color;
					}
				}
			}
		}

		private static void StrokeRoundedRect(Color32[] pixels, int size, int x0, int y0, int x1, int y1, int radius, Color32 color, int width)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < width; i++)
			{
				FillRoundedRectOutline(pixels, size, x0 + i, y0 + i, x1 - i, y1 - i, Mathf.Max(0, radius - i), color);
			}
		}

		private static void FillRoundedRectOutline(Color32[] pixels, int size, int x0, int y0, int x1, int y1, int radius, Color32 color)
		{
			//IL_0042: 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)
			for (int i = y0; i <= y1; i++)
			{
				for (int j = x0; j <= x1; j++)
				{
					bool num = InsideRoundedRect(j, i, x0, y0, x1, y1, radius);
					bool flag = InsideRoundedRect(j, i, x0 + 1, y0 + 1, x1 - 1, y1 - 1, Mathf.Max(0, radius - 1));
					if (num && !flag)
					{
						pixels[i * size + j] = color;
					}
				}
			}
		}

		private static bool InsideRoundedRect(int x, int y, int x0, int y0, int x1, int y1, int radius)
		{
			if (x < x0 || x > x1 || y < y0 || y > y1)
			{
				return false;
			}
			if (radius <= 0)
			{
				return true;
			}
			if (x < x0 + radius && y < y0 + radius)
			{
				return DistSq(x, y, x0 + radius, y0 + radius) <= radius * radius;
			}
			if (x > x1 - radius && y < y0 + radius)
			{
				return DistSq(x, y, x1 - radius, y0 + radius) <= radius * radius;
			}
			if (x < x0 + radius && y > y1 - radius)
			{
				return DistSq(x, y, x0 + radius, y1 - radius) <= radius * radius;
			}
			if (x > x1 - radius && y > y1 - radius)
			{
				return DistSq(x, y, x1 - radius, y1 - radius) <= radius * radius;
			}
			return true;
		}

		private static int DistSq(int x0, int y0, int x1, int y1)
		{
			int num = x0 - x1;
			int num2 = y0 - y1;
			return num * num + num2 * num2;
		}
	}
	internal static class GradedScratchClearSprite
	{
		private static Sprite? _sprite;

		private static Texture2D? _texture;

		public static Texture2D ClearTexture
		{
			get
			{
				EnsureCreated();
				return _texture;
			}
		}

		public static Sprite Get()
		{
			EnsureCreated();
			return _sprite;
		}

		private static void EnsureCreated()
		{
			//IL_001f: 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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_004f: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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_006c: 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_0078: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_sprite != (Object)null) || !((Object)(object)_texture != (Object)null))
			{
				_texture = new Texture2D(2, 2, (TextureFormat)4, false)
				{
					name = "GradedScratchClear0703",
					filterMode = (FilterMode)0,
					wrapMode = (TextureWrapMode)1
				};
				_texture.SetPixels((Color[])(object)new Color[4]
				{
					Color.clear,
					Color.clear,
					Color.clear,
					Color.clear
				});
				_texture.Apply(false, true);
				_sprite = Sprite.Create(_texture, new Rect(0f, 0f, 2f, 2f), new Vector2(0.5f, 0.5f), 100f);
				((Object)_sprite).name = "GradedScratchClear0703";
			}
		}
	}
	internal sealed class PackOpeningLateSyncBehaviour : MonoBehaviour
	{
		private const float BootstrapRetryIntervalSeconds = 1f;

		private const int BootstrapGiveUpRetries = 45;

		private float _bootstrapRetryTimer;

		private int _bootstrapRetryCount;

		private bool _packRefsReady;

		private bool _loggedBootstrapSuccess;

		private bool _loggedBootstrapGiveUp;

		private void Update()
		{
			if (_packRefsReady)
			{
				return;
			}
			_bootstrapRetryTimer += Time.unscaledDeltaTime;
			if (_bootstrapRetryTimer < 1f)
			{
				return;
			}
			_bootstrapRetryTimer = 0f;
			_bootstrapRetryCount++;
			CardOpeningSequence instance = CSingleton<CardOpeningSequence>.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			PackOpeningRefsBootstrap.TryBootstrap(instance);
			bool flag = PackOpeningRefsBootstrap.HasMinimumPackOpenRefs(instance);
			bool flag2 = PackOpeningRefsBootstrap.HasOpenSequenceUiRefs(instance);
			if (flag && flag2)
			{
				_packRefsReady = true;
				PackOpeningRefsBootstrap.TryRecoverStart(instance);
				if (!_loggedBootstrapSuccess)
				{
					_loggedBootstrapSuccess = true;
					Plugin.Log.LogInfo((object)("CardOpeningSequence pack refs ready after late sync " + $"(retries={_bootstrapRetryCount}, animator=True, mesh=True, startLerp=True, ui=True)."));
				}
			}
			else if (!_loggedBootstrapGiveUp && _bootstrapRetryCount >= 45)
			{
				_loggedBootstrapGiveUp = true;
				Plugin.Log.LogWarning((object)("CardOpeningSequence pack ref late sync giving up after " + $"{45}s: minRefs={flag}, uiRefs={flag2}, " + $"animator={(Object)(object)instance.m_CardPackAnimator != (Object)null}, mesh={(Object)(object)instance.m_CardPackMesh != (Object)null}, " + $"startLerp={(Object)(object)instance.m_StartLerpTransform != (Object)null}. " + "Pack wrapper animation may stay broken until scene objects are restored from vanilla 0.70.3."));
			}
		}

		private void LateUpdate()
		{
			CardOpeningSequence instance = CSingleton<CardOpeningSequence>.Instance;
			if (!PackOpeningState.ShouldSyncPackPresentation(instance))
			{
				return;
			}
			try
			{
				PackOpeningState.SyncFromSequence(instance);
				int stateIndex = instance.m_StateIndex;
				if (stateIndex >= 0 && stateIndex < 7)
				{
					PackOpening0703Patches.SyncAllPackOpeningPresentations(instance);
				}
				else if (stateIndex >= 7)
				{
					PackOpening0703Patches.HidePackVisualsDuringFanRow(instance);
					PackOpening0703Patches.SyncAllFanRowPresentations(instance);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Pack opening late sync failed: " + ex.GetType().Name + ": " + ex.Message));
			}
		}
	}
	internal static class PackOpeningRefsBootstrap
	{
		private const int CardDataPoolSize = 10;

		private static bool _loggedBootstrap;

		private static bool _loggedDiagnostics;

		private static bool _loggedPoolRepair;

		private static bool _loggedPackOpenReadiness;

		private static readonly HashSet<int> _dumpedStackStates = new HashSet<int>();

		private static bool _loggedFanDiagnostics;

		private static readonly string[] OpenCardClipNames = new string[4] { "OpenCardSlideExit", "OpenCardNewCard", "OpenCardFinalReveal", "OpenCardDefaultPos" };

		public static void TryBootstrap(CardOpeningSequence sequence)
		{
			if (!((Object)(object)sequence == (Object)null))
			{
				bool flag = false;
				flag |= TryBootstrapFromOpeningUiAnchor(sequence);
				flag |= TryBootstrapFromLocalHierarchy(sequence);
				if (!HasMinimumPackOpenRefs(sequence) || !HasOpenSequenceUiRefs(sequence))
				{
					flag |= TryBootstrapFromSceneSearch(sequence);
				}
				flag |= TryBootstrapCardLists(sequence);
				flag |= TryBootstrapAnimationAndIcons(sequence);
				flag |= TryBootstrapOpenPackVfx(sequence);
				flag |= EnsureCardOpeningUiGroup(sequence);
				EnsurePackOpenFeedbackIcons(sequence);
				TryEnsureCardDataPools(sequence);
				if (flag && !_loggedBootstrap)
				{
					_loggedBootstrap = true;
					Plugin.Log.LogWarning((object)"Repaired missing CardOpeningSequence pack references from scene search (sharedassets port).");
				}
				if ((!HasMinimumPackOpenRefs(sequence) || !HasOpenSequenceUiRefs(sequence)) && !_loggedDiagnostics)
				{
					_loggedDiagnostics = true;
					LogDiagnostics(sequence);
				}
			}
		}

		public static bool HasMinimumPackOpenRefs(CardOpeningSequence sequence)
		{
			if ((Object)(object)sequence.m_CardPackAnimator != (Object)null && (Object)(object)sequence.m_CardPackMesh != (Object)null)
			{
				return (Object)(object)sequence.m_StartLerpTransform != (Object)null;
			}
			return false;
		}

		public static bool HasOpenSequenceUiRefs(CardOpeningSequence sequence)
		{
			if ((Object)(object)sequence.m_CardOpeningUIGroup != (Object)null && (Object)(object)sequence.m_CardOpeningSequenceUI != (Object)null && (Object)(object)sequence.m_CardOpeningRotateToFrontAnim != (Object)null && sequence.m_Card3dUIList != null && sequence.m_Card3dUIList.Count > 0 && sequence.m_CardAnimList != null)
			{
				return sequence.m_CardAnimList.Count > 0;
			}
			return false;
		}

		public static void TryEnsureCardDataPools(CardOpeningSequence sequence)
		{
			if ((EnsureCardDataPool(sequence, "m_CardDataPool") | EnsureCardDataPool(sequence, "m_CardDataPool2")) && !_loggedPoolRepair)
			{
				_loggedPoolRepair = true;
				Plugin.Log.LogWarning((object)"Repaired empty CardOpeningSequence card data pools after Start() failure (sharedassets port).");
			}
		}

		public static bool EnsureCardOpeningUiGroup(CardOpeningSequence sequence)
		{
			if ((Object)(object)sequence.m_CardOpeningUIGroup != (Object)null)
			{
				return false;
			}
			if (sequence.m_Card3dUIList != null && sequence.m_Card3dUIList.Count > 0)
			{
				Transform parent = ((Component)sequence.m_Card3dUIList[0]).transform.parent;
				if ((Object)(object)parent != (Object)null)
				{
					sequence.m_CardOpeningUIGroup = ((Component)parent).gameObject;
					return true;
				}
			}
			if ((Object)(object)sequence.m_CardOpeningSequenceUI != (Object)null)
			{
				Transform transform = ((Component)sequence.m_CardOpeningSequenceUI).transform;
				sequence.m_CardOpeningUIGroup = (((Object)(object)transform.parent != (Object)null) ? ((Component)transform.parent).gameObject : ((Component)transform).gameObject);
				return true;
			}
			return false;
		}

		public static bool TryRunReadyingCardPack(CardOpeningSequence sequence, Item item)
		{
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			EnsureCardOpeningUiGroup(sequence);
			if (!HasMinimumPackOpenRefs(sequence) || (Object)(object)sequence.m_CardOpeningUIGroup == (Object)null || (Object)(object)item == (Object)null)
			{
				return false;
			}
			object value = CardOpeningSequenceFieldAccess.GetValue(sequence, "m_IsReadyingToOpen");
			if (value is bool && (bool)value)
			{
				return true;
			}
			CardOpeningSequenceFieldAccess.SetValue(sequence, "m_IsScreenActive", true);
			CSingleton<InteractionPlayerController>.Instance.EnterLockMoveMode();
			CSingleton<InteractionPlayerController>.Instance.OnEnterOpenPackState();
			CardOpeningSequenceFieldAccess.SetValue(sequence, "m_IsReadyingToOpen", true);
			CardOpeningSequenceFieldAccess.SetValue(sequence, "m_IsReadyToOpen", false);
			CardOpeningSequenceFieldAccess.SetValue(sequence, "m_LerpPosTimer", 0f);
			CardOpeningSequenceFieldAccess.SetValue(sequence, "m_CurrentItem", item);
			((Component)sequence.m_CardPackAnimator).transform.position = sequence.m_StartLerpTransform.position;
			((Component)sequence.m_CardPackAnimator).transform.rotation = sequence.m_StartLerpTransform.rotation;
			((Component)sequence.m_CardPackAnimator).transform.localScale = sequence.m_StartLerpTransform.localScale;
			if ((Object)(object)item.m_Mesh != (Object)null)
			{
				((Renderer)sequence.m_CardPackMesh).material = ((Renderer)item.m_Mesh).sharedMaterial;
			}
			((Component)sequence.m_CardPackAnimator).gameObject.SetActive(true);
			((Component)item).gameObject.SetActive(false);
			sequence.m_CardOpeningUIGroup.SetActive(false);
			sequence.m_CardPackAnimator.Play("PackOpenAnim", -1, 0f);
			CSingleton<InteractionPlayerController>.Instance.m_BlackBGWorldUIFade.SetFadeIn(3f, 0f);
			TutorialManager.SetGameUIVisible(false);
			CenterDot.SetVisibility(false);
			GameUIScreen.HideEnterGoNextDayIndicatorVisible();
			InteractionPlayerController.TempHideToolTip();
			InteractionPlayerController.AddToolTip((EGameAction)30, true, false);
			InteractionPlayerController.AddToolTip((EGameAction)29, false, false);
			InteractionPlayerController.SetAllHoldItemVisibility(false);
			CSingleton<InteractionPlayerController>.Instance.m_CameraFOVController.StartLerpToFOV(40f);
			SoundManager.GenericPop(1f, 1f);
			return true;
		}

		public static bool TryRunInitOpenSequence(CardOpeningSequence sequence)
		{
			EnsureCardOpeningUiGroup(sequence);
			if ((Object)(object)sequence.m_CardPackAnimator == (Object)null || (Object)(object)sequence.m_CardOpeningUIGroup == (Object)null || sequence.m_Card3dUIList == null || sequence.m_Card3dUIList.Count == 0)
			{
				return false;
			}
			sequence.m_CardPackAnimator.speed = 0f;
			((Component)sequence.m_CardPackAnimator).gameObject.SetActive(true);
			sequence.m_CardPackAnimator.Play("PackOpenAnim", -1, 0f);
			if ((Object)(object)sequence.m_CardOpeningRotateToFrontAnim != (Object)null)
			{
				sequence.m_CardOpeningRotateToFrontAnim.Play("CardOpenSeq0_Idle");
			}
			sequence.m_CardOpeningUIGroup.SetActive(true);
			if ((Object)(object)sequence.m_NewCardIcon != (Object)null)
			{
				sequence.m_NewCardIcon.SetActive(false);
			}
			if ((Object)(object)sequence.m_HighValueCardIcon != (Object)null)
			{
				sequence.m_HighValueCardIcon.SetActive(false);
			}
			InteractionPlayerController.RemoveToolTip((EGameAction)29);
			InteractionPlayerController.RemoveToolTip((EGameAction)30);
			InteractionPlayerController.AddToolTip((EGameAction)30, true, false);
			object value = CardOpeningSequenceFieldAccess.GetValue(sequence, "m_MultiplierStateTimer");
			if (value is float)
			{
				_ = (float)value;
				CGameManager instance = CSingleton<CGameManager>.Instance;
				float num = (((Object)(object)instance != (Object)null) ? instance.m_OpenPackSpeedSlider : 0f);
				CardOpeningSequenceFieldAccess.SetValue(sequence, "m_MultiplierStateTimer", 1f + 2.5f * num);
			}
			CardOpeningSequenceFieldAccess.SetValue(sequence, "m_HighValueCardThreshold", 10f + (float)CPlayerData.m_ShopLevel / 5f * 2f);
			return true;
		}

		public static void LogPackOpenReadiness(CardOpeningSequence sequence)
		{
			if (!_loggedPackOpenReadiness)
			{
				_loggedPackOpenReadiness = true;
				string value = (((Object)(object)sequence.m_CardOpeningRotateToFrontAnim != (Object)null) ? GetHierarchyPath(((Component)sequence.m_CardOpeningRotateToFrontAnim).transform) : "null");
				Plugin.Log.LogWarning((object)("Pack open readiness: " + $"animator={(Object)(object)sequence.m_CardPackAnimator != (Object)null}, mesh={(Object)(object)sequence.m_CardPackMesh != (Object)null}, " + $"startLerp={(Object)(object)sequence.m_StartLerpTransform != (Object)null}, " + $"uiGroup={(Object)(object)sequence.m_CardOpeningUIGroup != (Object)null}, rotateAnim={(Object)(object)sequence.m_CardOpeningRotateToFrontAnim != (Object)null}, " + $"rotatePath={value}, newCardIcon={(Object)(object)sequence.m_NewCardIcon != (Object)null}, highValueIcon={(Object)(object)sequence.m_HighValueCardIcon != (Object)null}, " + $"card3d={sequence.m_Card3dUIList?.Count ?? 0}, cardAnim={sequence.m_CardAnimList?.Count ?? 0}, " + $"cardAnimClips={sequence.m_CardAnimList != null && CardAnimListHasOpenCardClips(sequence.m_CardAnimList)}, " + $"showAllPos={sequence.m_ShowAllCardPosList?.Count ?? 0}, openVfx={(Object)(object)sequence.m_OpenPackVFX != (Object)null}, " + $"sequenceUi={(Object)(object)sequence.m_CardOpeningSequenceUI != (Object)null}, " + $"enableTooltip={CSingleton<CGameManager>.Instance?.m_EnableTooltip}"));
				if ((Object)(object)sequence.m_CardPackAnimator == (Object)null || (Object)(object)sequence.m_CardPackMesh == (Object)null || (Object)(object)sequence.m_StartLerpTransform == (Object)null)
				{
					Plugin.Log.LogWarning((object)"Pack open visuals incomplete: animator/mesh/startLerp still missing at pack-open time (UI card fan may still run). Check sharedassets scene objects vs vanilla 0.70.3.");
				}
			}
		}

		public static void ResetOpenDiagnostics()
		{
			_dumpedStackStates.Clear();
			_loggedFanDiagnostics = false;
		}

		public static void DumpCardStackDiagnostics(CardOpeningSequence sequence)
		{
			//IL_0067: 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_006c: 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_0076: 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_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: 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_05d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0412: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_042c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0431: Unknown result type (might be due to invalid IL or missing references)
			//IL_0453: Unknown result type (might be due to invalid IL or missing references)
			if (sequence.m_Card3dUIList == null || sequence.m_Card3dUIList.Count == 0)
			{
				return;
			}
			int stateIndex = sequence.m_StateIndex;
			if (stateIndex < 2 || stateIndex > 6 || _dumpedStackStates.Contains(stateIndex))
			{
				return;
			}
			_dumpedStackStates.Add(stateIndex);
			Camera val = CSingleton<InteractionPlayerController>.Instance?.m_Cam;
			Vector3 val2 = (((Object)(object)val != (Object)null) ? ((Component)val).transform.position : Vector3.zero);
			Vector3 val3 = (((Object)(object)val != (Object)null) ? ((Component)val).transform.forward : Vector3.forward);
			int currentOpenedCardIndex = PackOpeningState.GetCurrentOpenedCardIndex();
			Plugin.Log.LogWarning((object)$"CardStack dump at state={sequence.m_StateIndex} openedIndex={currentOpenedCardIndex} count={sequence.m_Card3dUIList.Count}");
			for (int i = 0; i < sequence.m_Card3dUIList.Count; i++)
			{
				Card3dUIGroup val4 = sequence.m_Card3dUIList[i];
				if ((Object)(object)val4 == (Object)null)
				{
					Plugin.Log.LogWarning((object)$"CardStack[{i}] = null");
					continue;
				}
				Transform transform = ((Component)val4).transform;
				float value = (((Object)(object)val != (Object)null) ? Vector3.Distance(transform.position, val2) : (-1f));
				float value2 = Vector3.Dot(transform.forward, val3);
				CardUI cardUI = val4.m_CardUI;
				bool value3 = (Object)(object)cardUI?.m_CardFront != (Object)null && cardUI.m_CardFront.activeSelf;
				bool value4 = (Object)(object)cardUI?.m_CardBack != (Object)null && cardUI.m_CardBack.activeSelf;
				object obj;
				if (cardUI == null)
				{
					obj = null;
				}
				else
				{
					Image cardBackImage = cardUI.m_CardBackImage;
					obj = ((cardBackImage != null) ? cardBackImage.sprite : null);
				}
				string value5 = (((Object)obj != (Object)null) ? ((Object)cardUI.m_CardBackImage.sprite).name : "null");
				bool value6 = (Object)(object)val4.m_CardBackMesh != (Object)null && val4.m_CardBackMesh.activeSelf;
				CardData val5 = (((Object)(object)cardUI != (Object)null) ? cardUI.GetCardData() : null);
				string value7 = ((val5 != null) ? ((object)Unsafe.As<ECardExpansionType, ECardExpansionType>(ref val5.expansionType)/*cast due to .constrained prefix*/).ToString() : "null");
				if ((Object)(object)val4.m_CardBackMesh != (Object)null)
				{
					Renderer component = val4.m_CardBackMesh.GetComponent<Renderer>();
					if (component != null && (Object)(object)component.sharedMaterial != (Object)null && (Object)(object)component.sharedMaterial.mainTexture != (Object)null)
					{
						_ = ((Object)component.sharedMaterial.mainTexture).name;
					}
				}
				Vector3 lossyScale = transform.lossyScale;
				string value8 = "front=null";
				if ((Object)(object)cardUI?.m_CardFront != (Object)null)
				{
					Transform transform2 = cardUI.m_CardFront.transform;
					float value9 = (((Object)(object)val != (Object)null) ? Vector3.Dot(transform2.forward, val3) : 0f);
					float value10 = (((Object)(object)val != (Object)null) ? Vector3.Distance(transform2.position, val2) : (-1f));
					value8 = $"frontLossy={transform2.lossyScale.x:F2} frontFacing={value9:F2} frontDist={value10:F1} frontActiveHier={cardUI.m_CardFront.activeInHierarchy}";
				}
				string value11 = "back=null";
				if ((Object)(object)cardUI?.m_CardBack != (Object)null)
				{
					Transform transform3 = cardUI.m_CardBack.transform;
					float value12 = (((Object)(object)val != (Object)null) ? Vector3.Dot(transform3.forward, val3) : 0f);
					float value13 = (((Object)(object)val != (Object)null) ? Vector3.Distance(transform3.position, val2) : (-1f));
					value11 = $"backLossy={transform3.lossyScale.x:F2} backFacing={value12:F2} backDist={value13:F1} backActiveHier={cardUI.m_CardBack.activeInHierarchy}";
				}
				Plugin.Log.LogWarning((object)$"CardStack[{i}] name={((Object)transform).name} sib={transform.GetSiblingIndex()} active={((Component)val4).gameObject.activeSelf} openIdx={currentOpenedCardIndex} expansion={value7} facing={value2:F2} frontActive={value3} backActive={value4} cardLossy={lossyScale.x:F2} camDist={value:F1} {value8} {value11} backSprite={value5} backMeshActive={value6}");
			}
		}

		public static void DumpFanDiagnostics(CardOpeningSequence sequence)
		{
			//IL_0055: 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_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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: 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_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0406: Unknown result type (might be due to invalid IL or missing references)
			//IL_0460: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			if (_loggedFanDiagnostics || sequence.m_StateIndex < 7 || sequence.m_Card3dUIList == null || sequence.m_Card3dUIList.Count == 0)
			{
				return;
			}
			_loggedFanDiagnostics = true;
			Camera val = CSingleton<InteractionPlayerController>.Instance?.m_Cam;
			Vector3 val2 = (((Object)(object)val != (Object)null) ? ((Component)val).transform.position : Vector3.zero);
			Vector3 val3 = (((Object)(object)val != (Object)null) ? ((Component)val).transform.forward : Vector3.forward);
			Plugin.Log.LogWarning((object)$"FanDump at state={sequence.m_StateIndex} camPos={val2} camForward={val3}");
			for (int i = 0; i < sequence.m_Card3dUIList.Count; i++)
			{
				Card3dUIGroup val4 = sequence.m_Card3dUIList[i];
				if (!((Object)(object)val4 == (Object)null))
				{
					Transform transform = ((Component)val4).transform;
					float value = Vector3.Dot(transform.position - val2, ((Vector3)(ref val3)).normalized);
					float value2 = Vector3.Distance(transform.position, val2);
					Canvas val5 = (((Object)(object)val4.m_CardUI != (Object)null) ? ((Component)val4.m_CardUI).GetComponentInParent<Canvas>() : null);
					string value3 = (((Object)(object)val5 != (Object)null) ? $"canvas={((Object)val5).name} mode={val5.renderMode} order={val5.sortingOrder} override={val5.overrideSorting}" : "canvas=null");
					int value4 = -1;
					Canvas val6 = null;
					if ((Object)(object)val4.m_CardUI != (Object)null && (Object)(object)val4.m_CardUI.m_CardFrontImage != (Object)null)
					{
						Material materialForRendering = ((Graphic)val4.m_CardUI.m_CardFrontImage).materialForRendering;
						value4 = (((Object)(object)materialForRendering != (Object)null) ? materialForRendering.renderQueue : (-1));
						val6 = ((Graphic)val4.m_CardUI.m_CardFrontImage).canvas;
					}
					string value5 = (((Object)(object)val6 != (Object)null) ? $"frontCanvas={((Object)val6).name} fOrder={val6.sortingOrder} fOverride={val6.overrideSorting}" : "frontCanvas=null");
					Plugin.Log.LogWarning((object)$"FanCard[{i}] name={((Object)transform).name} active={((Component)val4).gameObject.activeSelf} worldPos={transform.position} depth={value:F3} camDist={value2:F3} frontQueue={value4} {value3} {value5}");
				}
			}
			if (sequence.m_ShowAllCardPosList != null)
			{
				for (int j = 0; j < sequence.m_ShowAllCardPosList.Count; j++)
				{
					Transform val7 = sequence.m_ShowAllCardPosList[j];
					if (!((Object)(object)val7 == (Object)null))
					{
						float value6 = Vector3.Dot(val7.position - val2, ((Vector3)(ref val3)).normalized);
						Plugin.Log.LogWarning((object)$"FanPos[{j}] name={((Object)val7).name} worldPos={val7.position} depth={value6:F3}");
					}
				}
			}
			DumpCardOpeningUiOverlay(sequence, val, val2, val3);
			DumpBlackBgBackdrop(val, val2, val3);
		}

		private static void DumpBlackBgBackdrop(Camera? cam, Vector3 camPos, Vector3 camForward)
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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_0121: 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_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			InteractionPlayerController instance = CSingleton<InteractionPlayerController>.Instance;
			MaterialFadeInOut val = (((Object)(object)instance != (Object)null) ? instance.m_BlackBGWorldUIFade : null);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"Backdrop: m_BlackBGWorldUIFade is NULL");
				return;
			}
			MeshRenderer mesh = val.m_Mesh;
			if ((Object)(object)mesh == (Object)null)
			{
				Plugin.Log.LogWarning((object)"Backdrop: m_BlackBGWorldUIFade.m_Mesh is NULL");
				return;
			}
			Material material = ((Renderer)mesh).material;
			Color val2 = (Color)(((Object)(object)material != (Object)null) ? material.color : new Color(-1f, -1f, -1f, -1f));
			Transform transform = ((Component)mesh).transform;
			float value = (((Object)(object)cam != (Object)null) ? Vector3.Dot(transform.position - camPos, ((Vector3)(ref camForward)).normalized) : (-1f));
			int value2 = (((Object)(object)material != (Object)null) ? material.renderQueue : (-1));
			Plugin.Log.LogWarning((object)$"Backdrop: meshEnabled={((Renderer)mesh).enabled} active={((Component)mesh).gameObject.activeInHierarchy} matColor={val2} matAlpha={val2.a:F3} worldPos={transform.position} depth={value:F3} scale={transform.lossyScale} renderQueue={value2} sortLayer={((Renderer)mesh).sortingLayerID} sortOrder={((Renderer)mesh).sortingOrder} matName={(((Object)(object)material != (Object)null) ? ((Object)material).name : "null")} srcMat={(((Object)(object)val.m_Mat != (Object)null) ? ((Object)val.m_Mat).name : "null")}");
		}

		private static void DumpCardOpeningUiOverlay(CardOpeningSequence sequence, Camera? cam, Vector3 camPos, Vector3 camForward)
		{
			//IL_0072: 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_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: 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_0213: Unknown result type (might be due to invalid IL or missing references)
			Image[] array = Object.FindObjectsOfType<Image>(false);
			Plugin.Log.LogWarning((object)$"FanOverlay: scene-wide scan of {array.Length} active Image(s)");
			int num = 0;
			for (int i = 0; i < array.Length; i++)
			{
				if (num >= 30)
				{
					break;
				}
				Image val = array[i];
				if (!((Object)(object)val == (Object)null) && ((Behaviour)val).enabled)
				{
					Rect worldRectApprox = GetWorldRectApprox(((Graphic)val).rectTransform);
					bool num2 = ((Rect)(ref worldRectApprox)).width > 800f && ((Rect)(ref worldRectApprox)).height > 600f;
					bool flag = ((Graphic)val).color.a > 0.4f && ((Graphic)val).color.r < 0.4f && ((Graphic)val).color.g < 0.4f && ((Graphic)val).color.b < 0.4f;
					if (num2 || flag)
					{
						Canvas canvas = ((Graphic)val).canvas;
						string value = (((Object)(object)canvas != (Object)null) ? $"{((Object)canvas).name}/{canvas.renderMode}/order={canvas.sortingOrder}" : "null");
						float value2 = (((Object)(object)cam != (Object)null) ? Vector3.Dot(((Component)val).transform.position - camPos, ((Vector3)(ref camForward)).normalized) : (-1f));
						Plugin.Log.LogWarning((object)$"FanOverlayImg name={((Object)val).name} path={GetHierarchyPath(((Component)val).transform)} active={((Component)val).gameObject.activeSelf} color={((Graphic)val).color} screenRect={((Rect)(ref worldRectApprox)).width:F0}x{((Rect)(ref worldRectApprox)).height:F0} depth={value2:F3} canvas={value}");
						num++;
					}
				}
			}
		}

		private static Rect GetWorldRectApprox(RectTransform rt)
		{
			//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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: 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_0089: 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)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_00b3: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			rt.GetWorldCorners(array);
			Camera val = CSingleton<InteractionPlayerController>.Instance?.m_Cam;
			if ((Object)(object)val == (Object)null)
			{
				float num = Vector3.Distance(array[0], array[3]);
				float num2 = Vector3.Distance(array[0], array[1]);
				return new Rect(0f, 0f, num, num2);
			}
			Vector3 val2 = val.WorldToScreenPoint(array[0]);
			Vector3 val3 = val.WorldToScreenPoint(array[2]);
			return new Rect(val2.x, val2.y, Mathf.Abs(val3.x - val2.x), Mathf.Abs(val3.y - val2.y));
		}

		public static void EnsurePackOpenFeedbackIcons(CardOpeningSequence sequence)
		{
			Transform parent = (((Object)(object)sequence.m_CardOpeningUIGroup != (Object)null) ? sequence.m_CardOpeningUIGroup.transform : ((Component)sequence).transform);
			if ((Object)(object)sequence.m_NewCardIcon == (Object)null)
			{
				sequence.m_NewCardIcon = FindSceneGameObjectByName("NewCardIcon") ?? EnsureRuntimeStubObject(parent, "NewCardIcon0703Bootstrap");
			}
			if ((Object)(object)sequence.m_HighValueCardIcon == (Object)null)
			{
				sequence.m_HighValueCardIcon = FindSceneGameObjectByName("HighValueCardIcon") ?? EnsureRuntimeStubObject(parent, "HighValueCardIcon0703Bootstrap");
			}
			sequence.m_NewCardIcon.SetActive(false);
			sequence.m_HighValueCardIcon.SetActive(false);
		}

		private static GameObject EnsureRuntimeStubObject(Transform parent, string name)
		{
			//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)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			Transform val = parent.Find(name);
			if ((Object)(object)val != (Object)null)
			{
				return ((Component)val).gameObject;
			}
			GameObject val2 = new GameObject(name);
			val2.transform.SetParent(parent, false);
			val2.SetActive(false);
			return val2;
		}

		private static bool TryBootstrapFromOpeningUiAnchor(CardOpeningSequence sequence)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			CardOpeningSequenceUI[] array = FindSceneComponents<CardOpeningSequenceUI>();
			if (array.Length == 0)
			{
				return false;
			}
			CardOpeningSequenceUI val = null;
			int num = int.MinValue;
			foreach (CardOpeningSequenceUI val2 in array)
			{
				if (!((Object)(object)val2 == (Object)null))
				{
					int num2 = 100 - (int)Vector3.Distance(((Component)val2).transform.position, ((Component)sequence).transform.position);
					Card3dUIGroup[] componentsInChildren = ((Component)val2).GetComponentsInChildren<Card3dUIGroup>(true);
					num2 += componentsInChildren.Length * 10;
					if (num2 > num)
					{
						num = num2;
						val = val2;
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			bool flag = false;
			if ((Object)(object)sequence.m_CardOpeningSequenceUI == (Object)null)
			{
				sequence.m_CardOpeningSequenceUI = val;
				flag = true;
			}
			Transform val3 = null;
			int num3 = 0;
			Transform val4 = ((Component)val).transform;
			for (int j = 0; j < 10; j++)
			{
				if (!((Object)(object)val4 != (Object)null))
				{
					break;
				}
				Card3dUIGroup[] componentsInChildren2 = ((Component)val4).GetComponentsInChildren<Card3dUIGroup>(true);
				if (componentsInChildren2.Length > num3)
				{
					num3 = componentsInChildren2.Length;
					val3 = val4;
				}
				val4 = val4.parent;
			}
			if ((Object)(object)val3 != (Object)null)
			{
				flag |= TryAssignFromTransformTree(val3, sequence);
			}
			return flag;
		}

		private static bool TryBootstrapOpenPackVfx(CardOpeningSequence sequence)
		{
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)sequence.m_OpenPackVFX != (Object)null)
			{
				return false;
			}
			ParticleSystem[] array = FindSceneComponents<ParticleSystem>();
			ParticleSystem val = null;
			int num = int.MinValue;
			foreach (ParticleSystem val2 in array)
			{
				if (!((Object)(object)val2 == (Object)null))
				{
					int num2 = 0;
					string hierarchyPath = GetHierarchyPath(((Component)val2).transform);
					if (hierarchyPath.IndexOf("OpenPack", StringComparison.OrdinalIgnoreCase) >= 0)
					{
						num2 += 80;
					}
					if (hierarchyPath.IndexOf("CardOpening", StringComparison.OrdinalIgnoreCase) >= 0 || hierarchyPath.IndexOf("PackOpen", StringComparison.OrdinalIgnoreCase) >= 0)
					{
						num2 += 40;
					}
					float num3 = Vector3.Distance(((Component)val2).transform.position, ((Component)sequence).transform.position);
					if (num3 < 25f)
					{
						num2 += Math.Max(0, 20 - (int)num3);
					}
					if (num2 > num)
					{
						num = num2;
						val = val2;
					}
				}
			}
			if ((Object)(object)val != (Object)null && num > 0)
			{
				sequence.m_OpenPackVFX = val;
				return true;
			}
			return false;
		}

		private static bool EnsureCardDataPool(CardOpeningSequence sequence, string fieldName)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			if (!(CardOpeningSequenceFieldAccess.GetValue(sequence, fieldName) is List<CardData> list))
			{
				return false;
			}
			if (list.Count >= 10)
			{
				return false;
			}
			while (list.Count < 10)
			{
				list.Add(new CardData());
			}
			return true;
		}

		public static void TryRecoverStart(CardOpeningSequence sequence)
		{
			TryEnsureCardDataPools(sequence);
			if ((Object)(object)sequence.m_CardPackAnimator == (Object)null || (Object)(object)sequence.m_CardOpeningUIGroup == (Object)null)
			{
				return;
			}
			try
			{
				((Component)sequence.m_CardPackAnimator).gameObject.SetActive(false);
				sequence.m_CardPackAnimator.speed = 0f;
				sequence.m_CardOpeningUIGroup.SetActive(false);
				if ((Object)(object)sequence.m_NewCardIcon != (Object)null)
				{
					sequence.m_NewCardIcon.SetActive(false);
				}
				if ((Object)(object)sequence.m_HighValueCardIcon != (Object)null)
				{
					sequence.m_HighValueCardIcon.SetActive(false);
				}
				if ((Object)(object)sequence.m_CardOpeningSequenceUI != (Object)null)
				{
					if ((Object)(object)sequence.m_CardOpeningSequenceUI.m_CardValueTextGrp != (Object)null)
					{
						sequence.m_CardOpeningSequenceUI.m_CardValueTextGrp.SetActive(false);
					}
					if ((Object)(object)sequence.m_CardOpeningSequenceUI.m_TotalCardValueTextGrp != (Object)null)
					{
						sequence.m_CardOpeningSequenceUI.m_TotalCardValueTextGrp.SetActive(false);
					}
					if ((Object)(object)sequence.m_CardOpeningSequenceUI.m_FoilRainbowGlowingBG != (Object)null)
					{
						sequence.m_CardOpeningSequenceUI.m_FoilRainbowGlowingBG.SetActive(false);
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("CardOpeningSequence start recovery failed: " + ex.GetType().Name + ": " + ex.Message));
			}
		}

		private static bool TryBootstrapFromLocalHierarchy(CardOpeningSequence sequence)
		{
			bool flag = false;
			Transform[] array = (Transform[])(object)new Transform[2]
			{
				((Component)sequence).transform,
				((Component)sequence).transform.parent
			};
			foreach (Transform val in array)
			{
				if (!((Object)(object)val == (Object)null))
				{
					flag |= TryAssignFromTransformTree(val, sequence);
					if (HasMinimumPackOpenRefs(sequence))
					{
						return flag;
					}
				}
			}
			return flag;
		}

		private static bool TryBootstrapFromSceneSearch(CardOpeningSequence sequence)
		{
			bool flag = false;
			if ((Object)(object)sequence.m_CardOpeningSequenceUI == (Object)null)
			{
				CardOpeningSequenceUI[] array = FindSceneComponents<CardOpeningSequenceUI>();
				if (array.Length != 0)
				{
					sequence.m_CardOpeningSequenceUI = array[0];
					flag = true;
				}
			}
			if ((Object)(object)sequence.m_CardOpeningUIGroup == (Object)null)
			{
				Transform val = FindSceneTransformByName("CardOpeningUIGroup");
				if ((Object)(object)val != (Object)null)
				{
					sequence.m_CardOpeningUIGroup = ((Component)val).gameObject;
					flag = true;
				}
			}
			if ((Object)(object)sequence.m_StartLerpTransform == (Object)null)
			{
				sequence.m_StartLerpTransform = FindSceneTransformByName("StartLerpTransform") ?? FindSceneTransformByName("StartLerpPos") ?? FindSceneTransformByName("PackStartLerpTransform");
				if ((Object)(object)sequence.m_StartLerpTransform != (Object)null)
				{
					flag = true;
				}
			}
			if ((Object)(object)sequence.m_CardPackAnimator == (Object)null)
			{
				Animator[] array2 = FindSceneComponents<Animator>();
				Animator val2 = null;
				int num = int.MinValue;
				foreach (Animator val3 in array2)
				{
					if (!((Object)(object)val3 == (Object)null))
					{
						int num2 = ScorePackAnimatorCandidate(val3, ((Component)sequence).transform);
						if (num2 > num)
						{
							num = num2;
							val2 = val3;
						}
					}
				}
				if ((Object)(object)val2 != (Object)null && num > 0)
				{
					sequence.m_CardPackAnimator = val2;
					flag = true;
				}
			}
			if ((Object)(object)sequence.m_CardPackMesh == (Object)null && (Object)(object)sequence.m_CardPackAnimator != (Object)null)
			{
				sequence.m_CardPackMesh = ((Component)sequence.m_CardPackAnimator).GetComponent<SkinnedMeshRenderer>() ?? ((Component)sequence.m_CardPackAnimator).GetComponentInChildren<SkinnedMeshRenderer>(true);
				if ((Object)(object)sequence.m_CardPackMesh != (Object)null)
				{
					flag = true;
				}
			}
			if ((Object)(object)sequence.m_CardPackMesh == (Object)null)
			{
				SkinnedMeshRenderer[] array3 = FindSceneComponents<SkinnedMeshRenderer>();
				SkinnedMeshRenderer val4 = null;
				int num3 = int.MinValue;
				foreach (SkinnedMeshRenderer val5 in array3)
				{
					if (!((Object)(object)val5 == (Object)null))
					{
						int num4 = ScorePackMeshCandidate(val5, ((Component)sequence).transform);
						if (num4 > num3)
						{
							num3 = num4;
							val4 = val5;
						}
					}
				}
				if ((Object)(object)val4 != (Object)null && num3 > 0)
				{
					sequence.m_CardPackMesh = val4;
					if ((Object)(object)sequence.m_CardPackAnimator == (Object)null)
					{
						sequence.m_CardPackAnimator = ((Component)val4).GetComponentInParent<Animator>(true);
					}
					flag = true;
				}
			}
			if ((Object)(object)sequence.m_StartLerpTransform == (Object)null && (Object)(object)sequence.m_CardPackAnimator != (Object)null)
			{
				sequence.m_StartLerpTransform = EnsureRuntimeStartLerpTransform(sequence);
				flag = true;
			}
			flag |= TryBootstrapAnimationAndIcons(sequence);
			return flag | TryBootstrapCardLists(sequence);
		}

		private static bool TryBootstrapAnimationAndIcons(CardOpeningSequence sequence)
		{
			bool result = false;
			EnsurePackOpenFeedbackIcons(sequence);
			if ((Object)(object)sequence.m_CardOpeningRotateToFrontAnim == (Object)null || IsPerCardPackAnimation(sequence.m_CardOpeningRotateToFrontAnim))
			{
				Animation val = FindPackOpeningSequenceAnimation(sequence);
				if ((Object)(object)val != (Object)null)
				{
					sequence.m_CardOpeningRotateToFrontAnim = val;
					result = true;
				}
			}
			if ((Object)(object)sequence.m_NewCardIcon != (Object)null && (Object)(object)sequence.m_HighValueCardIcon != (Object)null)
			{
				result = true;
			}
			return result;
		}

		private static Animation? FindPackOpeningSequenceAnimation(CardOpeningSequence sequence)
		{
			Animation val = FindAnimationWithClip("CardOpenSeq1_RotateToFront", ((Component)sequence).transform);
			if ((Object)(object)val != (Object)null && !IsPerCardPackAnimation(val))
			{
				return val;
			}
			val = FindAnimationWithClip("CardOpenSeq0_Idle", ((Component)sequence).transform);
			if ((Object)(object)val != (Object)null && !IsPerCardPackAnimation(val))
			{
				return val;
			}
			return null;
		}

		private static bool IsPerCardPackAnimation(Animation animation)
		{
			return GetHierarchyPath(((Component)animation).transform).IndexOf("Card3d", StringComparison.OrdinalIgnoreCase) >= 0;
		}

		private static bool TryBootstrapCardLists(CardOpeningSequence sequence)
		{
			bool result = false;
			if (sequence.m_Card3dUIList == null || sequence.m_Card3dUIList.Count == 0)
			{
				List<Card3dUIGroup> list = CollectCard3dGroups(sequence);
				if (list.Count > 0)
				{
					sequence.m_Card3dUIList = list;
					result = true;
				}
			}
			if (sequence.m_Card3dUIList != null && sequence.m_Card3dUIList.Count > 0 && (sequence.m_CardAnimList == null || sequence.m_CardAnimList.Count != sequence.m_Card3dUIList.Count || !CardAnimListHasOpenCardClips(sequence.m_CardAnimList)))
			{
				List<Animation> list2 = new List<Animation>(sequence.m_Card3dUIList.Count);
				for (int i = 0; i < sequence.m_Card3dUIList.Count; i++)
				{
					Card3dUIGroup val = sequence.m_Card3dUIList[i];
					Animation val2 = (((Object)(object)val != (Object)null) ? FindOpenCardAnimationFor(val) : null);
					if ((Object)(object)val2 != (Object)null)
					{
						list2.Add(val2);
					}
				}
				if (list2.Count == sequence.m_Card3dUIList.Count)
				{
					sequence.m_CardAnimList = list2;
					result = true;
				}
			}
			if (sequence.m_ShowAllCardPosList == null || sequence.m_ShowAllCardPosList.Count == 0 || ShowAllCardPositionsLookLikeAnimGroupFallback(sequence))
			{
				List<Transform> list3 = CollectShowAllCardPositions(sequence);
				if (list3.Count > 0)
				{
					sequence.m_ShowAllCardPosList = list3;
					result = true;
				}
			}
			return result;
		}

		private static bool CardAnimListHasOpenCardClips(List<Animation> cardAnims)
		{
			for (int i = 0; i < cardAnims.Count; i++)
			{
				Animation val = cardAnims[i];
				if ((Object)(object)val == (Object)null || !AnimationHasAnyOpenCardClip(val))
				{
					return false;
				}
			}
			return true;
		}

		private static bool AnimationHasAnyOpenCardClip(Animation animation)
		{
			for (int i = 0; i < OpenCardClipNames.Length; i++)
			{
				if (AnimationHasClip(animation, OpenCardClipNames[i]))
				{
					return true;
				}
			}
			return false;
		}

		private static Animation? FindOpenCardAnimationFor(Card3dUIGroup card3d)
		{
			if ((Object)(object)card3d.m_Anim != (Object)null && AnimationHasAnyOpenCardClip(card3d.m_Anim))
			{
				return card3d.m_Anim;
			}
			Transform val = ((Component)card3d).transform;
			for (int i = 0; i < 12; i++)
			{
				if (!((Object)(object)val != (Object)null))
				{
					break;
				}
				Animation component = ((Component)val).GetComponent<Animation>();
				if ((Object)(object)component != (Object)null && AnimationHasAnyOpenCardClip(component))
				{
					return component;
				}
				val = val.parent;
			}
			Animation[] componentsInChildren = ((Component)card3d).GetComponentsInChildren<Animation>(true);
			for (int j = 0; j < componentsInChildren.Length; j++)
			{
				if ((Object)(object)componentsInChildren[j] != (Object)null && AnimationHasAnyOpenCardClip(componentsInChildren[j]))
				{
					return componentsInChildren[j];
				}
			}
			return null;
		}

		private static bool ShowAllCardPositionsLookLikeAnimGroupFallback(CardOpeningSequence sequence)
		{
			if (sequence.m_ShowAllCardPosList == null || sequence.m_ShowAllCardPosList.Count == 0)
			{
				return false;
			}
			for (int i = 0; i < sequence.m_ShowAllCardPosList.Count; i++)
			{
				Transform val = sequence.m_ShowAllCardPosList[i];
				if ((Object)(object)val != (Object)null && ((Object)val).name.IndexOf("CardUIAnim", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return true;
				}
			}
			return false;
		}

		private static List<Card3dUIGroup> CollectCard3dGroups(CardOpeningSequence sequence)
		{
			List<Card3dUIGroup> list = new List<Card3dUIGroup>();
			if ((Object)(object)sequence.m_CardOpeningUIGroup != (Object)null)
			{
				AppendSortedCardGroups(sequence.m_CardOpeningUIGroup.GetComponentsInChildren<Card3dUIGroup>(true), list);
			}
			if (list.Count == 0)
			{
				Card3dUIGroup[] array = FindSceneComponents<Card3dUIGroup>();
				int num = array.Length;
				if (num >= 7 && num <= 12)
				{
					AppendSortedCardGroups(array, list);
				}
				else
				{
					foreach (Card3dUIGroup val in array)
					{
						if (!((Object)(object)val == (Object)null))
						{
							string hierarchyPath = GetHierarchyPath(((Component)val).transform);
							if (hierarchyPath.IndexOf("CardOpening", StringComparison.OrdinalIgnoreCase) >= 0 || hierarchyPath.IndexOf("OpenPack", StringComparison.OrdinalIgnoreCase) >= 0 || hierarchyPath.IndexOf("PackOpen", StringComparison.OrdinalIgnoreCase) >= 0)
							{
								list.Add(val);
							}
						}
					}
					list.Sort(CompareSiblingOrder);
				}
			}
			list.Reverse();
			return list;
		}

		private static void AppendSortedCardGroups(IReadOnlyList<Card3dUIGroup> source, List<Card3dUIGroup> destination)
		{
			for (int i = 0; i < source.Count; i++)
			{
				Card3dUIGroup val = source[i];
				if ((Object)(object)val != (Object)null && !destination.Contains(val))
				{
					destination.Add(val);
				}
			}
			destination.Sort(CompareCardGroupOrder);
		}

		private static int CompareCardGroupOrder(Card3dUIGroup left, Card3dUIGroup right)
		{
			int num = ExtractTrailingNumber((left != null) ? ((Object)((Component)left).transform).name : null);
			int num2 = ExtractTrailingNumber((right != null) ? ((Object)((Component)right).transform).name : null);
			if (num >= 0 && num2 >= 0 && num != num2)
			{
				return num.CompareTo(num2);
			}
			return CompareSiblingOrder(left, right);
		}

		private static int ExtractTrailingNumber(string? name)
		{
			if (string.IsNullOrEmpty(name))
			{
				return -1;
			}
			int num = name.Length - 1;
			while (num >= 0 && char.IsDigit(name[num]))
			{
				num--;
			}
			if (num == name.Length - 1)
			{
				return -1;
			}
			if (!int.TryParse(name.Substring(num + 1), out var result))
			{
				return -1;
			}
			return result;
		}

		private static int CompareSiblingOrder(Card3dUIGroup left, Card3dUIGroup right)
		{
			Transform val = ((left != null) ? ((Component)left).transform : null);
			Transform val2 = ((right != null) ? ((Component)right).transform : null);
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				return 0;
			}
			if ((Object)(object)val.parent == (Object)(object)val2.parent)
			{
				return val.GetSiblingIndex().CompareTo(val2.GetSiblingIndex());
			}
			return string.Compare(GetHierarchyPath(val), GetHierarchyPath(val2), StringComparison.Ordinal);
		}

		private static List<Transform> CollectShowAllCardPositions(CardOpeningSequence sequence)
		{
			List<Transform> list = new List<Transform>();
			CollectShowAllCardPositionsUnderRoot(((Object)(object)sequence.m_CardOpeningUIGroup != (Object)null) ? sequence.m_CardOpeningUIGroup.transform : (((Object)(object)sequence.m_CardOpeningSequenceUI != (Object)null) ? ((Component)sequence.m_CardOpeningSequenceUI).transform : ((Component)sequence).transform), list);
			if (list.Count == 0)
			{
				Transform[] array = FindSceneComponents<Transform>();
				foreach (Transform val in array)
				{
					if ((Object)(object)val != (Object)null && ((Object)val).name.StartsWith("ShowAllCardPos", StringComparison.OrdinalIgnoreCase))
					{
						list.Add(val);
					}
				}
			}
			list.Sort(CompareShowAllCardPositionOrder);
			return list;
		}

		private static void CollectShowAllCardPositionsUnderRoot(Transform? root, List<Transform> positions)
		{
			if (!((Object)(object)root == (Object)null))
			{
				if (((Object)root).name.StartsWith("ShowAllCardPos", StringComparison.OrdinalIgnoreCase))
				{
					positions.Add(root);
				}
				for (int i = 0; i < root.childCount; i++)
				{
					CollectShowAllCardPositionsUnderRoot(root.GetChild(i), positions);
				}
			}
		}

		private static int CompareShowAllCardPositionOrder(Transform left, Transform right)
		{
			int num = ExtractTrailingNumber(((Object)left).name);
			int num2 = ExtractTrailingNumber(((Object)right).name);
			if (num >= 0 && num2 >= 0 && num != num2)
			{
				return num.CompareTo(num2);
			}
			return string.Compare(((Object)left).name, ((Object)right).name, StringComparison.OrdinalIgnoreCase);
		}

		private static Animation? FindAnimationWithClip(string clipName, Transform sequenceTransform)
		{
			//IL_00a1: 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)
			Animation[] array = FindSceneComponents<Animation>();
			Animation result = null;
			int num = int.MinValue;
			foreach (Animation val in array)
			{
				if (!((Object)(object)val == (Object)null) && AnimationHasClip(val, clipName))
				{
					int num2 = 0;
					string hierarchyPath = GetHierarchyPath(((Component)val).transform);
					if (hierarchyPath.IndexOf("CardOpening", StringComparison.OrdinalIgnoreCase) >= 0)
					{
						num2 += 50;
					}
					if (hierarchyPath.IndexOf("Rotate", StringComparison.OrdinalIgnoreCase) >= 0 || hierarchyPath.IndexOf("OpenSeq", StringComparison.OrdinalIgnoreCase) >= 0)
					{
						num2 += 30;
					}
					if (hierarchyPath.IndexOf("Card3d", StringComparison.OrdinalIgnoreCase) >= 0)
					{
						num2 -= 100;
					}
					float num3 = Vector3.Distance(((Component)val).transform.position, sequenceTransform.position);
					if (num3 < 25f)
					{
						num2 += Math.Max(0, 20 - (int)num3);
					}
					if (num2 > num)
					{
						num = num2;
						result = val;
					}
				}
			}
			return result;
		}

		private static bool AnimationHasClip(Animation animation, string clipName)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			foreach (AnimationState item in animation)
			{
				AnimationState val = item;
				if ((TrackedReference)(object)val != (TrackedReference)null && string.Equals(val.name, clipName, StringComparison.Ordinal))
				{
					return true;
				}
			}
			return false;
		}

		private static GameObject? FindSceneGameObjectByName(string name)
		{
			Transform? obj = FindSceneTransformByName(name);
			if (obj == null)
			{
				return null;
			}
			return ((Component)obj).gameObject;
		}

		private static bool TryAssignFromTransformTree(Transform root, CardOpeningSequence sequence)
		{
			bool flag = false;
			if ((Object)(object)sequence.m_CardPackAnimator == (Object)null)
			{
				Animator componentInChildren = ((Component)root).GetComponentInChildren<Animator>(true);
				if ((Object)(object)componentInChildren != (Object)null && ScorePackAnimatorCandidate(componentInChildren, ((Component)sequence).transform) > 0)
				{
					sequence.m_CardPackAnimator = componentInChildren;
					flag = true;
				}
			}
			if ((Object)(object)sequence.m_CardPackMesh == (Object)null)
			{
				SkinnedMeshRenderer componentInChildren2 = ((Component)root).GetComponentInChildren<SkinnedMeshRenderer>(true);
				if ((Object)(object)componentInChildren2 != (Object)null && ScorePackMeshCandidate(componentInChildren2, ((Component)sequence).transform) > 0)
				{
					sequence.m_CardPackMesh = componentInChildren2;
					flag = true;
				}
			}
			if ((Object)(object)sequence.m_StartLerpTransform == (Object)null)
			{
				Transform val = FindDeepChild(root, "StartLerpTransform") ?? FindDeepChild(root, "StartLerpPos");
				if ((Object)(object)val != (Object)null)
				{
					sequence.m_StartLerpTransform = val;
					flag = true;
				}
			}
			if ((Object)(object)sequence.m_CardOpeningUIGroup == (Object)null)
			{
				Transform val2 = FindDeepChild(root, "CardOpeningUIGroup");
				if ((Object)(object)val2 != (Object)null)
				{
					sequence.m_CardOpeningUIGroup = ((Component)val2).gameObject;
					flag = true;
				}
			}
			if ((Object)(object)sequence.m_CardOpeningSequenceUI == (Object)null)
			{
				CardOpeningSequenceUI componentInChildren3 = ((Component)root).GetComponentInChildren<CardOpeningSequenceUI>(true);
				if ((Object)(object)componentInChildren3 != (Object)null)
				{
					sequence.m_CardOpeningSequenceUI = componentInChildren3;
					flag = true;
				}
			}
			if ((Object)(object)sequence.m_CardOpeningRotateToFrontAnim == (Object)null || IsPerCardPackAnimation(sequence.m_CardOpeningRotateToFrontAnim))
			{
				Animation val3 = FindPackOpeningSequenceAnimation(sequence);
				if ((Object)(object)val3 != (Object)null)
				{
					sequence.m_CardOpeningRotateToFrontAnim = val3;
					flag = true;
				}
			}
			if ((Object)(object)sequence.m_NewCardIcon == (Object)null)
			{
				Transform val4 = FindDeepChild(root, "NewCardIcon");
				if ((Object)(object)val4 != (Object)null)
				{
					sequence.m_NewCardIcon = ((Component)val4).gameObject;
					flag = true;
				}
			}
			if ((Object)(object)sequence.m_HighValueCardIcon == (Object)null)
			{
				Transform val5 = FindDeepChild(root, "HighValueCardIcon");
				if ((Object)(object)val5 != (Object)null)
				{
					sequence.m_Hig