Decompiled source of CardStatPreview v1.0.0

CardStatPreview.dll

Decompiled 14 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using TMPro;
using UnboundLib;
using UnboundLib.Utils.UI;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = "")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace CardStatPreview;

internal static class PickSelection
{
	[HarmonyPatch(typeof(CardInfo), "RPCA_ChangeSelected")]
	private static class ChangeSelectedPatch
	{
		private static void Postfix(CardInfo __instance, bool setSelected)
		{
			if (!((Object)(object)__instance == (Object)null))
			{
				GameObject gameObject = ((Component)__instance).gameObject;
				if (setSelected)
				{
					Current = gameObject;
				}
				else if ((Object)(object)Current == (Object)(object)gameObject)
				{
					Current = null;
				}
			}
		}
	}

	[HarmonyPatch(typeof(CardChoice), "RPCA_DoEndPick")]
	private static class EndPickPatch
	{
		private static void Prefix()
		{
			Current = null;
		}
	}

	[HarmonyPatch(typeof(CardChoice), "RPCA_DonePicking")]
	private static class DonePickingPatch
	{
		private static void Prefix()
		{
			Current = null;
		}
	}

	internal static GameObject Current { get; private set; }

	internal static void Clear()
	{
		Current = null;
	}
}
internal static class PlayerUtil
{
	private static readonly Dictionary<int, bool> s_botCache = new Dictionary<int, bool>();

	private static bool s_rwbLookedUp;

	private static MethodInfo s_rwbGetData;

	private static PropertyInfo s_rwbIsBot;

	internal static bool IsMine(Player p)
	{
		if ((Object)(object)p != (Object)null && (Object)(object)p.data != (Object)null && (Object)(object)p.data.view != (Object)null)
		{
			return p.data.view.IsMine;
		}
		return false;
	}

	internal static bool IsAlive(Player p)
	{
		if ((Object)(object)p != (Object)null && (Object)(object)p.data != (Object)null && !p.data.dead)
		{
			return ((Component)p).gameObject.activeInHierarchy;
		}
		return false;
	}

	internal static bool IsLocalHuman(Player p)
	{
		if (IsMine(p))
		{
			return !IsBot(p);
		}
		return false;
	}

	internal static bool IsBot(Player p)
	{
		if ((Object)(object)p == (Object)null || (Object)(object)p.data == (Object)null)
		{
			return false;
		}
		int instanceID = ((Object)p).GetInstanceID();
		if (s_botCache.TryGetValue(instanceID, out var value) && value)
		{
			return true;
		}
		int num;
		if (!HasRwbBotFlag(p))
		{
			num = (HasAiComponent(p) ? 1 : 0);
			if (num == 0)
			{
				goto IL_0053;
			}
		}
		else
		{
			num = 1;
		}
		s_botCache[instanceID] = true;
		goto IL_0053;
		IL_0053:
		return (byte)num != 0;
	}

	private static bool HasAiComponent(Player p)
	{
		MonoBehaviour[] componentsInChildren = ((Component)p).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if ((Object)(object)val != (Object)null && ((object)val).GetType().Name.StartsWith("PlayerAI", StringComparison.Ordinal))
			{
				return true;
			}
		}
		return false;
	}

	private static bool HasRwbBotFlag(Player p)
	{
		if (!s_rwbLookedUp)
		{
			s_rwbLookedUp = true;
			Type type = AccessTools.TypeByName("RoundsWithBots.Extensions.CharacterDataExtension");
			s_rwbGetData = ((type != null) ? AccessTools.Method(type, "GetAdditionalData", (Type[])null, (Type[])null) : null);
			Type type2 = AccessTools.TypeByName("RoundsWithBots.Extensions.CharacterDataAdditionalData");
			s_rwbIsBot = ((type2 != null) ? AccessTools.Property(type2, "IsBot") : null);
		}
		if (s_rwbGetData == null || s_rwbIsBot == null)
		{
			return false;
		}
		try
		{
			object obj = s_rwbGetData.Invoke(null, new object[1] { p.data });
			return obj != null && (bool)s_rwbIsBot.GetValue(obj, null);
		}
		catch
		{
			return false;
		}
	}
}
internal sealed class PreviewResult
{
	public readonly float[] Before = new float[StatDefs.Count];

	public readonly float[] After = new float[StatDefs.Count];

	public readonly bool[] Estimated = new bool[StatDefs.Count];

	public readonly List<StatId> Rows = new List<StatId>(StatDefs.Count);

	public string CardName = "";

	public bool AnyEstimated;
}
internal static class Preview
{
	private static readonly float[] exactAfter = new float[StatDefs.Count];

	internal static void Compute(Player player, GameObject card, bool percentOfBase, PreviewResult into)
	{
		into.Rows.Clear();
		into.AnyEstimated = false;
		for (int i = 0; i < StatDefs.Count; i++)
		{
			into.Estimated[i] = false;
		}
		CardInfo component = card.GetComponent<CardInfo>();
		into.CardName = (((Object)(object)component != (Object)null && !string.IsNullOrEmpty(component.cardName)) ? component.cardName.ToUpperInvariant() : "");
		RawStats rawStats = RawStats.Capture(player);
		rawStats.ToDisplay(into.Before);
		rawStats.WithCard(card).ToDisplay(exactAfter);
		float num = CurrentThorns(player);
		into.Before[13] = num;
		exactAfter[13] = num;
		Array.Copy(exactAfter, into.After, StatDefs.Count);
		CardInfoStat[] array = (((Object)(object)component != (Object)null) ? component.cardStats : null);
		bool flag = false;
		if (array != null)
		{
			CardInfoStat[] array2 = array;
			for (int j = 0; j < array2.Length; j++)
			{
				if (StatLines.TryParse(array2[j], out var result))
				{
					if (result.Stat == StatId.Projectiles)
					{
						flag = true;
					}
					int stat = (int)result.Stat;
					float num2 = into.Before[stat];
					if (!float.IsNaN(num2) && (into.Estimated[stat] || StatDefs.SameOnScreen(result.Stat, num2, exactAfter[stat])))
					{
						into.After[stat] = StatLines.Apply(result, into.After[stat], percentOfBase);
						into.Estimated[stat] = true;
					}
				}
			}
		}
		for (int k = 0; k < StatDefs.Count; k++)
		{
			StatId statId = (StatId)k;
			if (float.IsNaN(into.Before[k]) || float.IsNaN(into.After[k]) || (statId == StatId.Projectiles && !flag))
			{
				continue;
			}
			into.After[k] = Clamp(statId, into.After[k]);
			if (!StatDefs.SameOnScreen(statId, into.Before[k], into.After[k]))
			{
				into.Rows.Add(statId);
				if (into.Estimated[k])
				{
					into.AnyEstimated = true;
				}
			}
		}
	}

	private static float CurrentThorns(Player player)
	{
		float num = 0f;
		List<CardInfo> list = (((Object)(object)player.data != (Object)null) ? player.data.currentCards : null);
		if (list == null)
		{
			return 0f;
		}
		foreach (CardInfo item in list)
		{
			if ((Object)(object)item == (Object)null || item.cardStats == null)
			{
				continue;
			}
			CardInfoStat[] cardStats = item.cardStats;
			for (int i = 0; i < cardStats.Length; i++)
			{
				if (StatLines.TryParse(cardStats[i], out var result) && result.Stat == StatId.Thorns)
				{
					num = StatLines.Apply(result, num, percentOfBase: false);
				}
			}
		}
		return num;
	}

	private static float Clamp(StatId id, float v)
	{
		switch (id)
		{
		case StatId.Ammo:
			return Mathf.Clamp(Mathf.Round(v), 1f, 90f);
		case StatId.Blocks:
			return Mathf.Max(1f, Mathf.Round(v));
		case StatId.Damage:
			return Mathf.Max(0f, v);
		case StatId.AttackSpeed:
		case StatId.Reload:
		case StatId.Spread:
		case StatId.Health:
		case StatId.Regen:
		case StatId.Lifesteal:
		case StatId.Thorns:
		case StatId.Decay:
		case StatId.BlockCooldown:
			return Mathf.Max(0f, v);
		case StatId.Projectiles:
			return Mathf.Max(1f, Mathf.Round(v));
		default:
			if (!StatDefs.IsWhole(id))
			{
				return Mathf.Max(0f, v);
			}
			return Mathf.Max(0f, Mathf.Round(v));
		}
	}
}
internal enum AmountKind
{
	Percent,
	Flat,
	Seconds,
	Times
}
internal struct StatLine
{
	public StatId Stat;

	public AmountKind Kind;

	public float Value;

	public bool Inverse;
}
internal static class StatLines
{
	private static readonly Regex AmountRx = new Regex("^\\s*(?<sign>[+\\-−])?\\s*(?<x1>[x×])?\\s*(?<num>\\d+(?:[.,]\\d+)?)\\s*(?<x2>[x×])?\\s*(?<unit>%|s\\b|sec\\b|secs\\b|seconds?\\b)?", RegexOptions.IgnoreCase | RegexOptions.Compiled);

	private static readonly Regex TagRx = new Regex("<[^<>]*>", RegexOptions.Compiled);

	internal static bool TryParse(CardInfoStat line, out StatLine result)
	{
		result = default(StatLine);
		if (line == null || string.IsNullOrEmpty(line.stat) || string.IsNullOrEmpty(line.amount))
		{
			return false;
		}
		string text = StripTags(line.stat);
		string text2 = StripTags(line.amount);
		if (text.Length == 0 || text2.Length == 0)
		{
			return false;
		}
		if (!TryMapStat(Normalize(text), out var stat, out var inverse))
		{
			return false;
		}
		Match match = AmountRx.Match(text2);
		if (!match.Success)
		{
			return false;
		}
		if (!float.TryParse(match.Groups["num"].Value.Replace(',', '.'), NumberStyles.Float, CultureInfo.InvariantCulture, out var result2))
		{
			return false;
		}
		string text3 = match.Groups["unit"].Value.ToLowerInvariant();
		AmountKind amountKind = ((match.Groups["x1"].Success || match.Groups["x2"].Success) ? AmountKind.Times : ((!(text3 == "%")) ? ((!text3.StartsWith("s")) ? AmountKind.Flat : AmountKind.Seconds) : AmountKind.Percent));
		if (amountKind != AmountKind.Times)
		{
			string value = match.Groups["sign"].Value;
			if (value == "-" || value == "−")
			{
				result2 = 0f - result2;
			}
			else if (value != "+" && !((StatDefs.Direction(stat) == Better.Lower && !inverse) ? (!line.positive) : line.positive))
			{
				result2 = 0f - result2;
			}
		}
		result = new StatLine
		{
			Stat = stat,
			Kind = amountKind,
			Value = result2,
			Inverse = inverse
		};
		return true;
	}

	internal static float Apply(StatLine l, float value, bool percentOfBase)
	{
		StatId stat = l.Stat;
		switch (l.Kind)
		{
		case AmountKind.Times:
			if (!l.Inverse && stat != StatId.AttackSpeed)
			{
				return value * l.Value;
			}
			return value / Math.Max(0.0001f, l.Value);
		case AmountKind.Percent:
		{
			float num = l.Value / 100f;
			if (stat == StatId.Lifesteal || stat == StatId.Thorns || stat == StatId.Spread)
			{
				return value + l.Value;
			}
			if (l.Inverse)
			{
				return value / Math.Max(0.05f, 1f + num);
			}
			if (stat == StatId.AttackSpeed)
			{
				if (!(num >= 0f))
				{
					return value * (1f - num);
				}
				return value / (1f + num);
			}
			if (percentOfBase)
			{
				return value + StatDefs.BaseValue(stat) * num;
			}
			return value * (1f + num);
		}
		default:
			switch (stat)
			{
			case StatId.Spread:
			case StatId.Thorns:
				return value + l.Value * ((Math.Abs(l.Value) < 1f) ? 100f : 1f);
			case StatId.MoveSpeed:
				return value + ((Math.Abs(l.Value) < 5f) ? l.Value : (l.Value / 100f));
			case StatId.BulletSpeed:
			case StatId.Knockback:
			case StatId.JumpHeight:
			case StatId.Size:
				return value + l.Value * ((Math.Abs(l.Value) < 5f) ? 100f : 1f);
			case StatId.AttackSpeed:
				return value;
			default:
				return value + l.Value;
			}
		}
	}

	private static string StripTags(string s)
	{
		if (s.IndexOf('<') >= 0)
		{
			return TagRx.Replace(s, "").Trim();
		}
		return s.Trim();
	}

	private static string Normalize(string s)
	{
		StringBuilder stringBuilder = new StringBuilder(s.Length);
		bool flag = false;
		string text = s.ToLowerInvariant();
		foreach (char c in text)
		{
			if (char.IsLetter(c))
			{
				stringBuilder.Append(c);
				flag = false;
			}
			else if (!flag && stringBuilder.Length > 0)
			{
				stringBuilder.Append(' ');
				flag = true;
			}
		}
		return stringBuilder.ToString().Trim();
	}

	private static bool Has(string s, string word)
	{
		return (" " + s + " ").Contains(" " + word + " ");
	}

	private static bool TryMapStat(string s, out StatId stat, out bool inverse)
	{
		inverse = false;
		stat = StatId.Count;
		if (s.Contains("block") && (s.Contains("cooldown") || Has(s, "cd")))
		{
			stat = StatId.BlockCooldown;
			return true;
		}
		if (s == "blocks" || s.Contains("extra block") || s.Contains("additional block"))
		{
			stat = StatId.Blocks;
			return true;
		}
		if (s.Contains("bullet speed") || s.Contains("projectile speed") || s.Contains("bullet velocity"))
		{
			stat = StatId.BulletSpeed;
			return true;
		}
		if (s.Contains("reload"))
		{
			stat = StatId.Reload;
			inverse = s.Contains("speed");
			return true;
		}
		if (s.Contains("attack speed") || s.Contains("atk spd") || s.Contains("atkspd") || s.Contains("fire rate") || s.Contains("firerate") || s.Contains("attackspeed") || s == "ats")
		{
			stat = StatId.AttackSpeed;
			return true;
		}
		if (s.Contains("lifesteal") || s.Contains("life steal"))
		{
			stat = StatId.Lifesteal;
			return true;
		}
		if (s.Contains("decay"))
		{
			stat = StatId.Decay;
			return true;
		}
		if (s.Contains("regen"))
		{
			stat = StatId.Regen;
			return true;
		}
		if ((s.Contains("damage") || Has(s, "dmg")) && !s.Contains("taken") && !s.Contains("reduction") && !s.Contains("resist") && !s.Contains("self") && !s.Contains("bounce"))
		{
			stat = StatId.Damage;
			return true;
		}
		if (s.Contains("ammo") || s.Contains("magazine"))
		{
			stat = StatId.Ammo;
			return true;
		}
		if (s.Contains("burst"))
		{
			stat = StatId.Bursts;
			return true;
		}
		if (s.Contains("bounce"))
		{
			stat = StatId.Bounces;
			return true;
		}
		if (s.Contains("projectile") && !s.Contains("size") && !s.Contains("speed"))
		{
			stat = StatId.Projectiles;
			return true;
		}
		if (s.Contains("spread"))
		{
			stat = StatId.Spread;
			return true;
		}
		if (s.Contains("thorn"))
		{
			stat = StatId.Thorns;
			return true;
		}
		if (s.Contains("knockback"))
		{
			stat = StatId.Knockback;
			return true;
		}
		if (s.Contains("health") || Has(s, "hp") || s == "max hp")
		{
			stat = StatId.Health;
			return true;
		}
		if (s.Contains("movement speed") || s.Contains("move speed") || s.Contains("movespeed") || s == "speed" || s == "run speed")
		{
			stat = StatId.MoveSpeed;
			return true;
		}
		if (s.Contains("jump height") || s == "jump")
		{
			stat = StatId.JumpHeight;
			return true;
		}
		if (s == "jumps" || s.Contains("extra jump") || s.Contains("double jump"))
		{
			stat = StatId.Jumps;
			return true;
		}
		if (!(s == "size") && !s.Contains("player size"))
		{
			switch (s)
			{
			case "body size":
				break;
			default:
				if (!s.Contains("respawn") && !s.Contains("extra li"))
				{
					return false;
				}
				goto case "lives";
			case "lives":
			case "life":
				stat = StatId.Lives;
				return true;
			}
		}
		stat = StatId.Size;
		return true;
	}
}
internal enum StatId
{
	Damage,
	AttackSpeed,
	Reload,
	Ammo,
	Projectiles,
	Bursts,
	Bounces,
	BulletSpeed,
	Spread,
	Knockback,
	Health,
	Regen,
	Lifesteal,
	Thorns,
	Decay,
	Lives,
	MoveSpeed,
	JumpHeight,
	Jumps,
	Size,
	BlockCooldown,
	Blocks,
	Unblockable,
	Count
}
internal enum Better
{
	Higher,
	Lower,
	Neutral
}
internal static class StatDefs
{
	internal static readonly int Count = 23;

	internal static string Name(StatId id)
	{
		return id switch
		{
			StatId.Damage => "Damage", 
			StatId.AttackSpeed => "Attack speed", 
			StatId.Reload => "Reload time", 
			StatId.Ammo => "Ammo", 
			StatId.Projectiles => "Projectiles", 
			StatId.Bursts => "Bursts", 
			StatId.Bounces => "Bounces", 
			StatId.BulletSpeed => "Bullet speed", 
			StatId.Spread => "Spread", 
			StatId.Knockback => "Knockback", 
			StatId.Health => "Health", 
			StatId.Regen => "Regen", 
			StatId.Lifesteal => "Lifesteal", 
			StatId.Thorns => "Thorns", 
			StatId.Decay => "Decay", 
			StatId.Lives => "Extra lives", 
			StatId.MoveSpeed => "Move speed", 
			StatId.JumpHeight => "Jump height", 
			StatId.Jumps => "Jumps", 
			StatId.Size => "Size", 
			StatId.BlockCooldown => "Block cooldown", 
			StatId.Blocks => "Blocks", 
			StatId.Unblockable => "Unblockable", 
			_ => id.ToString(), 
		};
	}

	internal static Better Direction(StatId id)
	{
		if ((uint)(id - 1) <= 1u || id == StatId.Spread || (uint)(id - 19) <= 1u)
		{
			return Better.Lower;
		}
		return Better.Higher;
	}

	internal static bool IsWhole(StatId id)
	{
		switch (id)
		{
		case StatId.Ammo:
		case StatId.Projectiles:
		case StatId.Bursts:
		case StatId.Bounces:
		case StatId.Lives:
		case StatId.Jumps:
		case StatId.Blocks:
		case StatId.Unblockable:
			return true;
		default:
			return false;
		}
	}

	internal static float BaseValue(StatId id)
	{
		switch (id)
		{
		case StatId.Damage:
			return 55f;
		case StatId.AttackSpeed:
			return 0.3f;
		case StatId.Reload:
			return 2f;
		case StatId.Ammo:
			return 3f;
		case StatId.Health:
			return 100f;
		case StatId.BlockCooldown:
			return 4f;
		case StatId.BulletSpeed:
		case StatId.Knockback:
		case StatId.JumpHeight:
		case StatId.Size:
			return 100f;
		default:
			return 1f;
		}
	}

	internal static string Format(StatId id, float v)
	{
		switch (id)
		{
		case StatId.Damage:
		case StatId.Health:
			return Mathf.RoundToInt(v).ToString();
		case StatId.AttackSpeed:
			return v.ToString("0.00");
		case StatId.Reload:
		case StatId.Decay:
		case StatId.BlockCooldown:
			return v.ToString("0.00").TrimEnd(new char[1] { '0' }).TrimEnd(new char[1] { '.' }) + "s";
		case StatId.Regen:
			return v.ToString((v < 10f) ? "0.#" : "0") + "/s";
		case StatId.MoveSpeed:
			return v.ToString("0.00");
		case StatId.BulletSpeed:
		case StatId.Spread:
		case StatId.Knockback:
		case StatId.Lifesteal:
		case StatId.Thorns:
		case StatId.JumpHeight:
		case StatId.Size:
			return Mathf.RoundToInt(v) + "%";
		case StatId.Unblockable:
			if (!(v > 0.5f))
			{
				return "No";
			}
			return "Yes";
		default:
			return Mathf.RoundToInt(v).ToString();
		}
	}

	internal static bool SameOnScreen(StatId id, float a, float b)
	{
		return Format(id, a) == Format(id, b);
	}
}
internal struct RawStats
{
	public bool HasGun;

	public bool HasAmmo;

	public bool HasStats;

	public bool HasBlock;

	public float damage;

	public float bulletDamageMultiplier;

	public float attackSpeed;

	public float defaultCooldown;

	public float attackSpeedMultiplier;

	public float projectileSpeed;

	public float knockback;

	public float spread;

	public float multiplySpread;

	public bool lockGunToDefault;

	public bool unblockable;

	public int numberOfProjectiles;

	public int bursts;

	public int reflects;

	public int maxAmmo;

	public float reloadTime;

	public float reloadTimeAdd;

	public float reloadTimeMultiplier;

	public float maxHealth;

	public float movementSpeed;

	public float jump;

	public float sizeMultiplier;

	public float regeneration;

	public float lifeSteal;

	public float decay;

	public int jumps;

	public int respawns;

	public float blockCooldown;

	public float cdAdd;

	public float cdMultiplier;

	public int additionalBlocks;

	internal static RawStats Capture(Player p)
	{
		RawStats result = default(RawStats);
		CharacterData data = p.data;
		Gun val = (((Object)(object)data.weaponHandler != (Object)null) ? data.weaponHandler.gun : null);
		if ((Object)(object)val != (Object)null)
		{
			result.HasGun = true;
			result.damage = val.damage;
			result.bulletDamageMultiplier = val.bulletDamageMultiplier;
			result.attackSpeed = val.attackSpeed;
			result.defaultCooldown = val.defaultCooldown;
			result.lockGunToDefault = val.lockGunToDefault;
			result.attackSpeedMultiplier = val.attackSpeedMultiplier;
			result.projectileSpeed = val.projectileSpeed;
			result.knockback = val.knockback;
			result.spread = val.spread;
			result.multiplySpread = val.multiplySpread;
			result.unblockable = val.unblockable;
			result.numberOfProjectiles = val.numberOfProjectiles;
			result.bursts = val.bursts;
			result.reflects = val.reflects;
			GunAmmo componentInChildren = ((Component)val).GetComponentInChildren<GunAmmo>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				result.HasAmmo = true;
				result.maxAmmo = componentInChildren.maxAmmo;
				result.reloadTime = componentInChildren.reloadTime;
				result.reloadTimeAdd = componentInChildren.reloadTimeAdd;
				result.reloadTimeMultiplier = componentInChildren.reloadTimeMultiplier;
			}
		}
		result.maxHealth = data.maxHealth;
		result.jumps = data.jumps;
		if ((Object)(object)data.stats != (Object)null)
		{
			result.HasStats = true;
			result.movementSpeed = data.stats.movementSpeed;
			result.jump = data.stats.jump;
			result.sizeMultiplier = data.stats.sizeMultiplier;
			result.lifeSteal = data.stats.lifeSteal;
			result.decay = data.stats.secondsToTakeDamageOver;
			result.respawns = data.stats.respawns;
		}
		if ((Object)(object)data.healthHandler != (Object)null)
		{
			result.regeneration = data.healthHandler.regeneration;
		}
		if ((Object)(object)data.block != (Object)null)
		{
			result.HasBlock = true;
			result.blockCooldown = data.block.cooldown;
			result.cdAdd = data.block.cdAdd;
			result.cdMultiplier = data.block.cdMultiplier;
			result.additionalBlocks = data.block.additionalBlocks;
		}
		return result;
	}

	internal RawStats WithCard(GameObject card)
	{
		RawStats result = this;
		Gun component = card.GetComponent<Gun>();
		CharacterStatModifiers component2 = card.GetComponent<CharacterStatModifiers>();
		Block componentInChildren = card.GetComponentInChildren<Block>();
		if ((Object)(object)component != (Object)null && result.HasGun)
		{
			if (result.HasAmmo)
			{
				result.maxAmmo = Mathf.Clamp(result.maxAmmo + component.ammo, 1, 90);
				result.reloadTimeMultiplier *= component.reloadTime;
				result.reloadTimeAdd += component.reloadTimeAdd;
			}
			if (component.lockGunToDefault)
			{
				result.defaultCooldown = component.forceSpecificAttackSpeed;
				result.lockGunToDefault = true;
			}
			float num = 1f;
			if (component.numberOfProjectiles != 0 && result.numberOfProjectiles != 1)
			{
				num = (float)component.numberOfProjectiles / (float)(component.numberOfProjectiles + result.numberOfProjectiles);
			}
			result.damage *= 1f - num * (1f - component.damage);
			if (result.damage < 0.25f)
			{
				result.damage = 0.25f;
			}
			result.knockback *= 1f - num * (1f - component.knockback);
			result.projectileSpeed *= component.projectileSpeed;
			result.spread += component.spread;
			result.multiplySpread *= component.multiplySpread;
			result.attackSpeed *= component.attackSpeed;
			result.bulletDamageMultiplier *= component.bulletDamageMultiplier;
			result.numberOfProjectiles += component.numberOfProjectiles;
			result.reflects += component.reflects;
			result.bursts += component.bursts;
			if (component.unblockable)
			{
				result.unblockable = true;
			}
		}
		if ((Object)(object)component2 != (Object)null)
		{
			result.sizeMultiplier *= component2.sizeMultiplier;
			result.maxHealth *= component2.health;
			result.movementSpeed *= component2.movementSpeed;
			result.jump *= component2.jump;
			result.jumps += component2.numberOfJumps;
			result.regeneration += component2.regen;
			result.lifeSteal += component2.lifeSteal;
			result.decay += component2.secondsToTakeDamageOver;
			result.respawns += component2.respawns;
		}
		if ((Object)(object)componentInChildren != (Object)null && result.HasBlock)
		{
			result.cdMultiplier *= componentInChildren.cdMultiplier;
			result.cdAdd += componentInChildren.cdAdd;
			result.additionalBlocks += componentInChildren.additionalBlocks;
		}
		return result;
	}

	internal void ToDisplay(float[] v)
	{
		for (int i = 0; i < v.Length; i++)
		{
			v[i] = float.NaN;
		}
		if (HasGun)
		{
			v[0] = 55f * damage * bulletDamageMultiplier;
			float num = (lockGunToDefault ? defaultCooldown : attackSpeed);
			v[1] = ((attackSpeedMultiplier > 0.0001f) ? (num / attackSpeedMultiplier) : float.NaN);
			v[4] = numberOfProjectiles;
			v[8] = spread * multiplySpread * 100f;
			v[5] = bursts;
			v[6] = reflects;
			v[7] = projectileSpeed * 100f;
			v[9] = knockback * 100f;
			v[22] = (unblockable ? 1f : 0f);
		}
		if (HasAmmo)
		{
			v[3] = maxAmmo;
			v[2] = (reloadTime + reloadTimeAdd) * reloadTimeMultiplier;
		}
		v[10] = maxHealth;
		v[11] = regeneration;
		v[18] = jumps;
		if (HasStats)
		{
			v[12] = lifeSteal * 100f;
			v[14] = decay;
			v[15] = respawns;
			v[16] = movementSpeed;
			v[17] = jump * 100f;
			v[19] = sizeMultiplier * 100f;
		}
		if (HasBlock)
		{
			v[20] = (blockCooldown + cdAdd) * cdMultiplier;
			v[21] = 1 + additionalBlocks;
		}
	}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.zen.rounds.cardstatpreview", "Card Stat Preview", "1.0.0")]
[BepInProcess("Rounds.exe")]
public class CardStatPreview : BaseUnityPlugin
{
	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static UnityAction <>9__12_0;

		public static UnityAction<bool> <>9__13_0;

		public static UnityAction<float> <>9__13_3;

		public static UnityAction<bool> <>9__13_1;

		public static UnityAction <>9__13_2;

		internal void <Start>b__12_0()
		{
		}

		internal void <BuildMenu>b__13_0(bool v)
		{
			Enabled.Value = v;
		}

		internal void <BuildMenu>b__13_3(float v)
		{
			Scale.Value = Mathf.Round(v * 20f) / 20f;
		}

		internal void <BuildMenu>b__13_1(bool v)
		{
			PercentOfBase.Value = v;
		}

		internal void <BuildMenu>b__13_2()
		{
			PreviewUI.Instance?.ShowDemo();
		}
	}

	public const string ModId = "com.zen.rounds.cardstatpreview";

	public const string ModName = "Card Stat Preview";

	public const string Version = "1.0.0";

	public const string ModInitials = "Zen";

	internal static ConfigEntry<bool> Enabled;

	internal static ConfigEntry<bool> PercentOfBase;

	internal static ConfigEntry<float> Scale;

	internal static ManualLogSource Log { get; private set; }

	private void Awake()
	{
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Expected O, but got Unknown
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Show the stat preview under the card the picker has highlighted.");
		PercentOfBase = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "PercentOfBase", false, "How percentages written on modded cards are estimated. Off: they scale your current value (most cards). On: they add a share of the starting value instead.");
		Scale = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Scale", 1f, new ConfigDescription("Size of the preview panel.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.7f, 1.5f), Array.Empty<object>()));
		try
		{
			new Harmony("com.zen.rounds.cardstatpreview").PatchAll(typeof(CardStatPreview).Assembly);
		}
		catch (Exception arg)
		{
			Log.LogError((object)$"Couldn't hook card selection: {arg}");
		}
		((Component)this).gameObject.AddComponent<PreviewUI>();
	}

	private void Start()
	{
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Expected O, but got Unknown
		Unbound.RegisterClientSideMod("com.zen.rounds.cardstatpreview");
		Unbound.RegisterCredits("Card Stat Preview", new string[1] { "Zen" }, new string[1] { "Thunderstore" }, new string[1] { "https://thunderstore.io/c/rounds/p/Zenith/" });
		object obj = <>c.<>9__12_0;
		if (obj == null)
		{
			UnityAction val = delegate
			{
			};
			<>c.<>9__12_0 = val;
			obj = (object)val;
		}
		Unbound.RegisterMenu("Card Stat Preview", (UnityAction)obj, (Action<GameObject>)BuildMenu, (GameObject)null, true);
	}

	private static void BuildMenu(GameObject menu)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_0228: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Expected O, but got Unknown
		TextMeshProUGUI val = default(TextMeshProUGUI);
		MenuHandler.CreateText("Card Stat Preview", menu, ref val, 60, false, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
		MenuHandler.CreateText("See how a card changes your stats before you take it", menu, ref val, 25, false, (Color?)Color.gray, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
		MenuHandler.CreateText(" ", menu, ref val, 15, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
		MenuHandler.CreateToggle(Enabled.Value, "Show stat preview", menu, (UnityAction<bool>)delegate(bool v)
		{
			Enabled.Value = v;
		}, 40, false, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
		Slider val2 = default(Slider);
		MenuHandler.CreateSlider("Panel size", menu, 30, 0.7f, 1.5f, Scale.Value, (UnityAction<float>)delegate(float v)
		{
			Scale.Value = Mathf.Round(v * 20f) / 20f;
		}, ref val2, false, (Color?)null, (Direction)0, false, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
		MenuHandler.CreateToggle(PercentOfBase.Value, "Modded % = share of starting stats", menu, (UnityAction<bool>)delegate(bool v)
		{
			PercentOfBase.Value = v;
		}, 30, false, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
		MenuHandler.CreateText("Leave off unless a card pack's % values look too high.", menu, ref val, 20, false, (Color?)Color.gray, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
		MenuHandler.CreateText(" ", menu, ref val, 15, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
		object obj = <>c.<>9__13_2;
		if (obj == null)
		{
			UnityAction val3 = delegate
			{
				PreviewUI.Instance?.ShowDemo();
			};
			<>c.<>9__13_2 = val3;
			obj = (object)val3;
		}
		MenuHandler.CreateButton("Show example", menu, (UnityAction)obj, 35, false, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
		MenuHandler.CreateText(" ", menu, ref val, 15, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
		MenuHandler.CreateText("Made by Zen", menu, ref val, 20, false, (Color?)Color.gray, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
	}
}
internal sealed class PreviewUI : MonoBehaviour
{
	private sealed class Row
	{
		public GameObject Go;

		public TextMeshProUGUI Name;

		public TextMeshProUGUI Before;

		public TextMeshProUGUI Arrow;

		public TextMeshProUGUI After;
	}

	private sealed class ToggleButton : MonoBehaviour, IPointerClickHandler, IEventSystemHandler, IPointerEnterHandler, IPointerExitHandler
	{
		internal Action Clicked;

		internal Action<bool> Hover;

		public void OnPointerClick(PointerEventData e)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			if ((int)e.button != 0)
			{
				return;
			}
			try
			{
				Clicked?.Invoke();
			}
			catch (Exception ex)
			{
				CardStatPreview.Log.LogWarning((object)ex.Message);
			}
		}

		public void OnPointerEnter(PointerEventData e)
		{
			try
			{
				Hover?.Invoke(obj: true);
			}
			catch
			{
			}
		}

		public void OnPointerExit(PointerEventData e)
		{
			try
			{
				Hover?.Invoke(obj: false);
			}
			catch
			{
			}
		}
	}

	private static readonly Color BorderColor = new Color(1f, 1f, 1f, 0.1f);

	private static readonly Color FillColor = new Color(0.055f, 0.067f, 0.09f, 0.95f);

	private static readonly Color Divider = new Color(1f, 1f, 1f, 0.08f);

	private static readonly Color TextMain = new Color(0.93f, 0.94f, 0.96f, 1f);

	private static readonly Color Muted = new Color(0.56f, 0.6f, 0.67f, 1f);

	private static readonly Color Dim = new Color(0.74f, 0.77f, 0.82f, 1f);

	private static readonly Color Good = new Color(0.44f, 0.86f, 0.52f, 1f);

	private static readonly Color Bad = new Color(0.96f, 0.43f, 0.43f, 1f);

	private const float NameWidth = 150f;

	private const float BeforeWidth = 70f;

	private const float ArrowWidth = 20f;

	private const float AfterWidth = 82f;

	private const float ColGap = 6f;

	private const float PadX = 16f;

	private const float PanelWidth = 372f;

	private const float Gap = 14f;

	private const float Margin = 12f;

	private const float FadeIn = 9f;

	private const float FadeOut = 14f;

	private const float Follow = 16f;

	private static FieldRef<CardChoice, List<GameObject>> spawnedCardsRef;

	private static FieldRef<CardChoice, int> selectedRef;

	private static FieldRef<CardChoice, bool> isPlayingRef;

	private static FieldRef<CardChoice, PickerType> pickerTypeRef;

	private static bool broken;

	private int errors;

	private GameObject canvasGO;

	private RectTransform canvasRT;

	private RectTransform panel;

	private CanvasGroup group;

	private TextMeshProUGUI title;

	private TextMeshProUGUI empty;

	private TextMeshProUGUI foot;

	private readonly List<Row> rows = new List<Row>();

	private string arrow = ">";

	private readonly PreviewResult result = new PreviewResult();

	private GameObject shownCard;

	private Player shownPlayer;

	private int shownCardCount = -1;

	private bool hasPos;

	private Vector2 pos;

	private float demoUntil = -1f;

	private Transform cardRoot;

	private Camera cardCam;

	private Vector3 bottomLeft;

	private Vector3 bottomRight;

	private bool measured;

	private float lastMeasure;

	private GameObject toggleGO;

	private Image toggleFill;

	private Image toggleBorder;

	private TextMeshProUGUI toggleText;

	private TextMeshProUGUI toggleHint;

	private GameObject ownEventSystem;

	private float lastPicking = -10f;

	private const float ButtonGrace = 1f;

	private readonly Vector3[] corners = (Vector3[])(object)new Vector3[4];

	private readonly List<Graphic> graphics = new List<Graphic>(64);

	internal static PreviewUI Instance { get; private set; }

	private void Awake()
	{
		Instance = this;
		try
		{
			spawnedCardsRef = AccessTools.FieldRefAccess<CardChoice, List<GameObject>>("spawnedCards");
			selectedRef = AccessTools.FieldRefAccess<CardChoice, int>("currentlySelectedCard");
			isPlayingRef = AccessTools.FieldRefAccess<CardChoice, bool>("isPlaying");
			pickerTypeRef = AccessTools.FieldRefAccess<CardChoice, PickerType>("pickerType");
		}
		catch (Exception ex)
		{
			broken = true;
			CardStatPreview.Log.LogError((object)("Card pick fields not found, preview disabled: " + ex.Message));
		}
	}

	private void OnDestroy()
	{
		DestroyToggle();
		if ((Object)(object)canvasGO != (Object)null)
		{
			Object.Destroy((Object)(object)canvasGO);
		}
	}

	private void LateUpdate()
	{
		if (broken)
		{
			HideNow();
			return;
		}
		try
		{
			Tick(Time.unscaledDeltaTime);
		}
		catch (Exception arg)
		{
			HideNow();
			ForgetShown();
			if (++errors <= 3)
			{
				CardStatPreview.Log.LogWarning((object)$"Preview hidden after an error: {arg}");
			}
			if (errors > 20)
			{
				broken = true;
				CardStatPreview.Log.LogError((object)"Too many preview errors; Card Stat Preview turned itself off until restart.");
			}
		}
	}

	private void Tick(float dt)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		UpdateToggle();
		bool flag = false;
		Vector2 center = Vector2.zero;
		if (CardStatPreview.Enabled.Value && TryGetHighlighted(out var player, out var card))
		{
			EnsureUI();
			if ((Object)(object)card != (Object)(object)shownCard || (Object)(object)player != (Object)(object)shownPlayer || CardCount(player) != shownCardCount)
			{
				Rebuild(player, card);
			}
			if (!measured && Time.unscaledTime - lastMeasure > 0.2f)
			{
				Measure(card);
			}
			flag = measured && TryPlace(out center);
		}
		else if (demoUntil > Time.unscaledTime && (Object)(object)panel != (Object)null)
		{
			flag = true;
			center = Vector2.zero;
		}
		else
		{
			ForgetShown();
		}
		if ((Object)(object)panel == (Object)null)
		{
			return;
		}
		if (flag)
		{
			if (!((Component)panel).gameObject.activeSelf)
			{
				((Component)panel).gameObject.SetActive(true);
				group.alpha = 0f;
				hasPos = false;
			}
			if (!hasPos)
			{
				pos = center;
				hasPos = true;
			}
			else
			{
				pos = Vector2.Lerp(pos, center, 1f - Mathf.Exp(-16f * dt));
			}
			panel.anchoredPosition = new Vector2(Mathf.Round(pos.x), Mathf.Round(pos.y));
			group.alpha = Mathf.MoveTowards(group.alpha, 1f, 9f * dt);
		}
		else if (((Component)panel).gameObject.activeSelf)
		{
			group.alpha = Mathf.MoveTowards(group.alpha, 0f, 14f * dt);
			if (group.alpha <= 0.001f)
			{
				HideNow();
			}
		}
	}

	private bool TryGetHighlighted(out Player player, out GameObject card)
	{
		player = null;
		card = null;
		CardChoice instance = CardChoice.instance;
		if ((Object)(object)instance == (Object)null || !instance.IsPicking || instance.pickrID < 0)
		{
			PickSelection.Clear();
			return false;
		}
		if (EscapeMenuHandler.isEscMenu)
		{
			return false;
		}
		player = Picker(instance);
		if ((Object)(object)player == (Object)null)
		{
			return false;
		}
		if (isPlayingRef.Invoke(instance))
		{
			return false;
		}
		card = PickSelection.Current;
		if ((Object)(object)card == (Object)null)
		{
			List<GameObject> list = spawnedCardsRef.Invoke(instance);
			if (list != null && list.Count > 0)
			{
				card = list[Mathf.Clamp(selectedRef.Invoke(instance), 0, list.Count - 1)];
			}
		}
		if ((Object)(object)card != (Object)null)
		{
			return card.activeInHierarchy;
		}
		return false;
	}

	private static Player Picker(CardChoice cc)
	{
		List<Player> list = (((Object)(object)PlayerManager.instance != (Object)null) ? PlayerManager.instance.players : null);
		if (list == null)
		{
			return null;
		}
		bool flag = (int)pickerTypeRef.Invoke(cc) == 0;
		Player val = null;
		for (int i = 0; i < list.Count; i++)
		{
			Player val2 = list[i];
			if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.data == (Object)null) && !(flag ? (val2.teamID != cc.pickrID) : (val2.playerID != cc.pickrID)))
			{
				if ((Object)(object)val == (Object)null || ((Object)(object)val2.data.view != (Object)null && val2.data.view.IsMine))
				{
					val = val2;
				}
				if (!flag)
				{
					break;
				}
			}
		}
		return val;
	}

	private static int CardCount(Player p)
	{
		if (!((Object)(object)p.data != (Object)null) || p.data.currentCards == null)
		{
			return 0;
		}
		return p.data.currentCards.Count;
	}

	private void ForgetShown()
	{
		shownCard = null;
		shownPlayer = null;
		shownCardCount = -1;
		cardRoot = null;
		measured = false;
	}

	private void HideNow()
	{
		if ((Object)(object)panel != (Object)null && ((Component)panel).gameObject.activeSelf)
		{
			group.alpha = 0f;
			((Component)panel).gameObject.SetActive(false);
		}
		hasPos = false;
	}

	private void Rebuild(Player player, GameObject card)
	{
		bool num = (Object)(object)card == (Object)(object)shownCard;
		shownCard = card;
		shownPlayer = player;
		shownCardCount = CardCount(player);
		Preview.Compute(player, card, CardStatPreview.PercentOfBase.Value, result);
		Fill(result);
		if (!num)
		{
			Measure(card);
		}
	}

	private void Fill(PreviewResult r)
	{
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		((TMP_Text)title).text = (string.IsNullOrEmpty(r.CardName) ? "IF YOU TAKE IT" : r.CardName);
		for (int i = 0; i < rows.Count; i++)
		{
			Row row = rows[i];
			if (i >= r.Rows.Count)
			{
				if (row.Go.activeSelf)
				{
					row.Go.SetActive(false);
				}
				continue;
			}
			StatId statId = r.Rows[i];
			float num = r.Before[(int)statId];
			float num2 = r.After[(int)statId];
			bool flag = r.Estimated[(int)statId];
			((TMP_Text)row.Name).text = StatDefs.Name(statId);
			((TMP_Text)row.Before).text = StatDefs.Format(statId, num);
			((TMP_Text)row.Arrow).text = arrow;
			((TMP_Text)row.After).text = (flag ? "~" : "") + StatDefs.Format(statId, num2);
			((Graphic)row.After).color = ChangeColor(statId, num, num2);
			if (!row.Go.activeSelf)
			{
				row.Go.SetActive(true);
			}
		}
		bool flag2 = r.Rows.Count == 0;
		((Component)empty).gameObject.SetActive(flag2);
		((Component)foot).gameObject.SetActive(!flag2 && r.AnyEstimated);
		((Transform)panel).localScale = Vector3.one * Mathf.Clamp(CardStatPreview.Scale.Value, 0.7f, 1.5f);
		LayoutRebuilder.ForceRebuildLayoutImmediate(panel);
	}

	private static Color ChangeColor(StatId id, float before, float after)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		Better better = StatDefs.Direction(id);
		if (better == Better.Neutral)
		{
			return TextMain;
		}
		bool flag = after > before;
		if (!((better == Better.Higher) ? flag : (!flag)))
		{
			return Bad;
		}
		return Good;
	}

	private void Measure(GameObject card)
	{
		//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_0240: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: 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_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_021a: 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_0224: 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)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0229: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_0437: Unknown result type (might be due to invalid IL or missing references)
		//IL_043c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0450: Unknown result type (might be due to invalid IL or missing references)
		//IL_0455: Unknown result type (might be due to invalid IL or missing references)
		//IL_03db: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_038a: Unknown result type (might be due to invalid IL or missing references)
		//IL_038c: Unknown result type (might be due to invalid IL or missing references)
		lastMeasure = Time.unscaledTime;
		measured = false;
		cardRoot = card.transform;
		cardCam = null;
		HashSet<Transform> hashSet = new HashSet<Transform>();
		CardVisuals componentInChildren = card.GetComponentInChildren<CardVisuals>();
		if ((Object)(object)componentInChildren != (Object)null && componentInChildren.objectsToToggle != null)
		{
			GameObject[] objectsToToggle = componentInChildren.objectsToToggle;
			foreach (GameObject val in objectsToToggle)
			{
				if ((Object)(object)val != (Object)null)
				{
					hashSet.Add(val.transform);
				}
			}
		}
		graphics.Clear();
		card.GetComponentsInChildren<Graphic>(false, graphics);
		List<Rect> list = new List<Rect>();
		float num = float.MinValue;
		int num2 = -1;
		foreach (Graphic graphic in graphics)
		{
			if ((Object)(object)cardCam == (Object)null && (Object)(object)graphic != (Object)null && (Object)(object)graphic.canvas != (Object)null && (int)graphic.canvas.renderMode != 0)
			{
				cardCam = (((Object)(object)graphic.canvas.worldCamera != (Object)null) ? graphic.canvas.worldCamera : Camera.main);
			}
			TMP_Text val2 = (TMP_Text)(object)((graphic is TMP_Text) ? graphic : null);
			if (val2 == null || !((Behaviour)val2).enabled || string.IsNullOrEmpty(val2.text) || ((Graphic)val2).color.a < 0.05f)
			{
				continue;
			}
			Bounds textBounds = val2.textBounds;
			if (!(((Bounds)(ref textBounds)).size.x <= 0.0001f) && !(((Bounds)(ref textBounds)).size.y <= 0.0001f))
			{
				Rect item = ToCardRect(val2.transform, ((Bounds)(ref textBounds)).min, ((Bounds)(ref textBounds)).max);
				list.Add(item);
				if (((Rect)(ref item)).yMax > num)
				{
					num = ((Rect)(ref item)).yMax;
					num2 = list.Count - 1;
				}
			}
		}
		Rect a = default(Rect);
		bool flag = false;
		for (int j = 0; j < list.Count; j++)
		{
			if (j != num2 || list.Count <= 1)
			{
				a = (flag ? Union(a, list[j]) : list[j]);
				flag = true;
			}
		}
		Rect val3 = default(Rect);
		bool flag2 = false;
		if (flag)
		{
			float num3 = ((Rect)(ref a)).height * 0.03f;
			float num4 = float.MaxValue;
			foreach (Graphic graphic2 in graphics)
			{
				if ((Object)(object)graphic2 == (Object)null || graphic2 is TMP_Text || !((Behaviour)graphic2).enabled || graphic2.color.a < 0.05f || UnderAny(((Component)graphic2).transform, hashSet, cardRoot))
				{
					continue;
				}
				graphic2.rectTransform.GetWorldCorners(corners);
				Rect val4 = ToCardRect(corners);
				if (!(((Rect)(ref val4)).xMin > ((Rect)(ref a)).xMin + num3) && !(((Rect)(ref val4)).xMax < ((Rect)(ref a)).xMax - num3) && !(((Rect)(ref val4)).yMin > ((Rect)(ref a)).yMin + num3) && !(((Rect)(ref val4)).yMax < ((Rect)(ref a)).yMax - num3) && !(((Rect)(ref val4)).height > ((Rect)(ref a)).height * 4f) && !(((Rect)(ref val4)).width > ((Rect)(ref a)).width * 4f))
				{
					float num5 = ((Rect)(ref val4)).width * ((Rect)(ref val4)).height;
					if (num5 < num4)
					{
						num4 = num5;
						val3 = val4;
						flag2 = true;
					}
				}
			}
			if (!flag2)
			{
				val3 = Rect.MinMaxRect(((Rect)(ref a)).xMin, ((Rect)(ref a)).yMin - ((Rect)(ref a)).height * 0.12f, ((Rect)(ref a)).xMax, ((Rect)(ref a)).yMax);
				flag2 = true;
			}
		}
		graphics.Clear();
		if (flag2 && !(((Rect)(ref val3)).width <= 0f) && !(((Rect)(ref val3)).height <= 0f))
		{
			float num6 = ((Rect)(ref val3)).yMin - ((Rect)(ref val3)).width * 0.1f;
			bottomLeft = new Vector3(((Rect)(ref val3)).xMin, num6, 0f);
			bottomRight = new Vector3(((Rect)(ref val3)).xMax, num6, 0f);
			measured = true;
		}
	}

	private Rect ToCardRect(Transform t, Vector3 localMin, Vector3 localMax)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: 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_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: 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_0058: 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)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: 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_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		corners[0] = t.TransformPoint(new Vector3(localMin.x, localMin.y, 0f));
		corners[1] = t.TransformPoint(new Vector3(localMin.x, localMax.y, 0f));
		corners[2] = t.TransformPoint(new Vector3(localMax.x, localMax.y, 0f));
		corners[3] = t.TransformPoint(new Vector3(localMax.x, localMin.y, 0f));
		return ToCardRect(corners);
	}

	private Rect ToCardRect(Vector3[] world)
	{
		//IL_0026: 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_0030: 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_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: 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_0072: Unknown result type (might be due to invalid IL or missing references)
		float num = float.MaxValue;
		float num2 = float.MinValue;
		float num3 = float.MaxValue;
		float num4 = float.MinValue;
		for (int i = 0; i < 4; i++)
		{
			Vector3 val = cardRoot.InverseTransformPoint(world[i]);
			if (val.x < num)
			{
				num = val.x;
			}
			if (val.x > num2)
			{
				num2 = val.x;
			}
			if (val.y < num3)
			{
				num3 = val.y;
			}
			if (val.y > num4)
			{
				num4 = val.y;
			}
		}
		return Rect.MinMaxRect(num, num3, num2, num4);
	}

	private static Rect Union(Rect a, Rect b)
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		return Rect.MinMaxRect(Mathf.Min(((Rect)(ref a)).xMin, ((Rect)(ref b)).xMin), Mathf.Min(((Rect)(ref a)).yMin, ((Rect)(ref b)).yMin), Mathf.Max(((Rect)(ref a)).xMax, ((Rect)(ref b)).xMax), Mathf.Max(((Rect)(ref a)).yMax, ((Rect)(ref b)).yMax));
	}

	private static bool UnderAny(Transform t, HashSet<Transform> set, Transform stop)
	{
		if (set.Count == 0)
		{
			return false;
		}
		Transform val = t;
		while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)stop)
		{
			if (set.Contains(val))
			{
				return true;
			}
			val = val.parent;
		}
		return false;
	}

	private bool TryPlace(out Vector2 center)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		center = Vector2.zero;
		if ((Object)(object)cardRoot == (Object)null || !Object.op_Implicit((Object)(object)cardRoot) || (Object)(object)canvasRT == (Object)null)
		{
			return false;
		}
		if (!ToCanvas(cardRoot.TransformPoint(bottomLeft), out var local))
		{
			return false;
		}
		if (!ToCanvas(cardRoot.TransformPoint(bottomRight), out var local2))
		{
			return false;
		}
		Rect rect = canvasRT.rect;
		Vector2 val = ((Rect)(ref rect)).size * 0.5f;
		float x = ((Transform)panel).localScale.x;
		rect = panel.rect;
		float num = ((Rect)(ref rect)).width * x;
		rect = panel.rect;
		float num2 = ((Rect)(ref rect)).height * x;
		float num3 = (local.x + local2.x) * 0.5f;
		float num4 = Mathf.Min(local.y, local2.y) - 14f - num2 * 0.5f;
		num3 = Mathf.Clamp(num3, 0f - val.x + 12f + num * 0.5f, val.x - 12f - num * 0.5f);
		num4 = Mathf.Clamp(num4, 0f - val.y + 12f + num2 * 0.5f, val.y - 12f - num2 * 0.5f);
		center = new Vector2(num3, num4);
		return true;
	}

	private bool ToCanvas(Vector3 world, out Vector2 local)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		local = Vector2.zero;
		if ((Object)(object)cardCam != (Object)null && cardCam.WorldToViewportPoint(world).z < 0f)
		{
			return false;
		}
		Vector2 val = RectTransformUtility.WorldToScreenPoint(cardCam, world);
		return RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRT, val, (Camera)null, ref local);
	}

	private void UpdateToggle()
	{
		CardChoice instance = CardChoice.instance;
		bool flag = (Object)(object)instance != (Object)null && instance.IsPicking && instance.pickrID >= 0;
		if (flag)
		{
			lastPicking = Time.unscaledTime;
		}
		if (!flag && Time.unscaledTime - lastPicking > 1f)
		{
			DestroyToggle();
		}
		else if (flag)
		{
			EnsureToggle();
			bool flag2 = !EscapeMenuHandler.isEscMenu;
			if (toggleGO.activeSelf != flag2)
			{
				toggleGO.SetActive(flag2);
			}
		}
	}

	private void EnsureToggle()
	{
		//IL_005e: 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_00ab: 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_00ad: 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_00c4: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0204: 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_0052: Expected O, but got Unknown
		if ((Object)(object)toggleGO != (Object)null)
		{
			return;
		}
		EnsureUI();
		if ((Object)(object)EventSystem.current == (Object)null)
		{
			ownEventSystem = new GameObject("CardStatPreview EventSystem", new Type[2]
			{
				typeof(EventSystem),
				typeof(StandaloneInputModule)
			});
		}
		toggleBorder = UIKit.Box(canvasGO.transform, BorderColor, 10, "Preview Toggle");
		toggleGO = ((Component)toggleBorder).gameObject;
		RectTransform rectTransform = ((Graphic)toggleBorder).rectTransform;
		Vector2 val = default(Vector2);
		((Vector2)(ref val))..ctor(1f, 0f);
		rectTransform.pivot = val;
		Vector2 anchorMin = (rectTransform.anchorMax = val);
		rectTransform.anchorMin = anchorMin;
		rectTransform.anchoredPosition = new Vector2(-22f, 22f);
		rectTransform.sizeDelta = new Vector2(44f, 44f);
		((Graphic)toggleBorder).raycastTarget = true;
		toggleFill = UIKit.Box((Transform)(object)rectTransform, FillColor, 9, "Fill");
		UIKit.Stretch(((Graphic)toggleFill).rectTransform, 1f, 1f, 1f, 1f);
		toggleText = UIKit.Text((Transform)(object)rectTransform, "?", 24f, TextMain, (FontStyles)1, (TextAlignmentOptions)514, "Q");
		UIKit.Stretch(((TMP_Text)toggleText).rectTransform);
		toggleHint = UIKit.Text((Transform)(object)rectTransform, "", 13f, Muted, (FontStyles)0, (TextAlignmentOptions)4100, "Hint");
		RectTransform rectTransform2 = ((TMP_Text)toggleHint).rectTransform;
		rectTransform2.anchorMin = new Vector2(0f, 0.5f);
		rectTransform2.anchorMax = new Vector2(0f, 0.5f);
		rectTransform2.pivot = new Vector2(1f, 0.5f);
		rectTransform2.anchoredPosition = new Vector2(-10f, 0f);
		rectTransform2.sizeDelta = new Vector2(200f, 24f);
		((Component)toggleHint).gameObject.SetActive(false);
		ToggleButton toggleButton = toggleGO.AddComponent<ToggleButton>();
		toggleButton.Clicked = OnToggleClicked;
		toggleButton.Hover = delegate(bool h)
		{
			if (!((Object)(object)toggleHint == (Object)null))
			{
				((Component)toggleHint).gameObject.SetActive(h);
				RefreshToggle(h);
			}
		};
		RefreshToggle(hover: false);
	}

	private void OnToggleClicked()
	{
		CardStatPreview.Enabled.Value = !CardStatPreview.Enabled.Value;
		if (!CardStatPreview.Enabled.Value)
		{
			HideNow();
			ForgetShown();
		}
		RefreshToggle(hover: true);
	}

	private void RefreshToggle(bool hover)
	{
		//IL_002a: 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_0080: 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_00bd: 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)toggleGO == (Object)null))
		{
			bool value = CardStatPreview.Enabled.Value;
			((Graphic)toggleText).color = (value ? TextMain : Muted);
			((Graphic)toggleBorder).color = (value ? new Color(1f, 1f, 1f, hover ? 0.35f : 0.18f) : new Color(1f, 1f, 1f, hover ? 0.22f : 0.08f));
			((Graphic)toggleFill).color = (Color)(value ? FillColor : new Color(FillColor.r, FillColor.g, FillColor.b, 0.7f));
			((TMP_Text)toggleHint).text = (value ? "Hide stat preview" : "Show stat preview");
		}
	}

	private void DestroyToggle()
	{
		if ((Object)(object)toggleGO != (Object)null)
		{
			Object.Destroy((Object)(object)toggleGO);
		}
		toggleGO = null;
		toggleBorder = (toggleFill = null);
		toggleText = (toggleHint = null);
		if ((Object)(object)ownEventSystem != (Object)null)
		{
			Object.Destroy((Object)(object)ownEventSystem);
		}
		ownEventSystem = null;
	}

	internal void ShowDemo()
	{
		EnsureUI();
		PreviewResult r = result;
		r.Rows.Clear();
		r.CardName = "EXAMPLE CARD";
		r.AnyEstimated = true;
		for (int i = 0; i < StatDefs.Count; i++)
		{
			r.Before[i] = float.NaN;
			r.After[i] = float.NaN;
			r.Estimated[i] = false;
		}
		Set(StatId.Damage, 55f, 82f);
		Set(StatId.AttackSpeed, 0.3f, 0.45f);
		Set(StatId.Reload, 2f, 1.5f, est: true);
		Set(StatId.Ammo, 3f, 5f);
		Set(StatId.BlockCooldown, 4f, 3.6f);
		Set(StatId.Thorns, 0f, 20f, est: true);
		ForgetShown();
		Fill(r);
		demoUntil = Time.unscaledTime + 5f;
		void Set(StatId id, float b, float a, bool est = false)
		{
			r.Before[(int)id] = b;
			r.After[(int)id] = a;
			r.Estimated[(int)id] = est;
			r.Rows.Add(id);
		}
	}

	private void EnsureUI()
	{
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Expected O, but got Unknown
		//IL_00ea: 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_012b: Expected O, but got Unknown
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: 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_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0250: 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_031a: Unknown result type (might be due to invalid IL or missing references)
		//IL_036f: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)panel != (Object)null)
		{
			return;
		}
		if ((Object)(object)UIKit.Font == (Object)null)
		{
			UIKit.Font = FindFont(bold: false);
		}
		if ((Object)(object)UIKit.BoldFont == (Object)null)
		{
			UIKit.BoldFont = FindFont(bold: true);
		}
		TMP_FontAsset val = UIKit.Font ?? UIKit.BoldFont;
		try
		{
			if ((Object)(object)val != (Object)null && val.HasCharacter('→'))
			{
				arrow = "→";
			}
		}
		catch
		{
		}
		canvasGO = new GameObject("CardStatPreview Canvas", new Type[3]
		{
			typeof(RectTransform),
			typeof(Canvas),
			typeof(CanvasScaler)
		});
		Canvas component = canvasGO.GetComponent<Canvas>();
		component.renderMode = (RenderMode)0;
		component.sortingOrder = 28000;
		CanvasScaler component2 = canvasGO.GetComponent<CanvasScaler>();
		component2.uiScaleMode = (ScaleMode)1;
		component2.referenceResolution = new Vector2(1920f, 1080f);
		component2.matchWidthOrHeight = 0.5f;
		canvasGO.AddComponent<GraphicRaycaster>();
		Object.DontDestroyOnLoad((Object)(object)canvasGO);
		canvasRT = (RectTransform)canvasGO.transform;
		Image val2 = UIKit.Box(canvasGO.transform, BorderColor, 14, "Panel");
		panel = ((Graphic)val2).rectTransform;
		RectTransform obj2 = panel;
		RectTransform obj3 = panel;
		Vector2 val3 = default(Vector2);
		((Vector2)(ref val3))..ctor(0.5f, 0.5f);
		obj3.anchorMax = val3;
		obj2.anchorMin = val3;
		panel.pivot = new Vector2(0.5f, 0.5f);
		group = ((Component)val2).gameObject.AddComponent<CanvasGroup>();
		group.interactable = false;
		group.blocksRaycasts = false;
		UIKit.HL((Component)(object)val2, 0f, 1, 1, 1, 1, (TextAnchor)0, expandW: true, expandH: true);
		ContentSizeFitter obj4 = ((Component)val2).gameObject.AddComponent<ContentSizeFitter>();
		obj4.horizontalFit = (FitMode)2;
		obj4.verticalFit = (FitMode)2;
		Image val4 = UIKit.Box(((Component)val2).transform, FillColor, 13, "Inner");
		UIKit.VL((Component)(object)val4, 5f, 16, 16, 12, 13, (TextAnchor)0);
		UIKit.LE((Component)(object)val4, 372f, 372f, 0f);
		title = UIKit.Text(((Component)val4).transform, "", 16f, TextMain, (FontStyles)1, (TextAlignmentOptions)4097, "Title");
		((TMP_Text)title).characterSpacing = 3f;
		UIKit.LE((Component)(object)title, -1f, -1f, -1f, 22f, 22f);
		UIKit.LE((Component)(object)UIKit.Box(((Component)val4).transform, Divider, 0, "Divider"), -1f, -1f, -1f, 1f, 1f);
		for (int i = 0; i < StatDefs.Count; i++)
		{
			rows.Add(MakeRow(((Component)val4).transform));
		}
		empty = UIKit.Text(((Component)val4).transform, "No direct stat changes", 15f, Muted, (FontStyles)0, (TextAlignmentOptions)4097, "Empty");
		UIKit.LE((Component)(object)empty, -1f, -1f, -1f, 24f, 24f);
		foot = UIKit.Text(((Component)val4).transform, "~ estimated from the card's text", 12f, Muted, (FontStyles)0, (TextAlignmentOptions)4097, "Foot");
		UIKit.LE((Component)(object)foot, -1f, -1f, -1f, 18f, 18f);
		((Component)panel).gameObject.SetActive(false);
	}

	private Row MakeRow(Transform parent)
	{
		//IL_005c: 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_00a8: 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)
		RectTransform val = UIKit.Rect(parent, "Row");
		UIKit.HL((Component)(object)val, 6f, 0, 0, 0, 0, (TextAnchor)3);
		UIKit.LE((Component)(object)val, -1f, -1f, -1f, 24f, 24f);
		Row obj = new Row
		{
			Go = ((Component)val).gameObject,
			Name = Cell((Transform)(object)val, 15f, Muted, (FontStyles)0, (TextAlignmentOptions)4097, 150f, "Name"),
			Before = Cell((Transform)(object)val, 15f, Dim, (FontStyles)0, (TextAlignmentOptions)4100, 70f, "Before"),
			Arrow = Cell((Transform)(object)val, 14f, Muted, (FontStyles)0, (TextAlignmentOptions)514, 20f, "Arrow"),
			After = Cell((Transform)(object)val, 16f, TextMain, (FontStyles)1, (TextAlignmentOptions)4097, 82f, "After")
		};
		((Component)val).gameObject.SetActive(false);
		return obj;
	}

	private static TextMeshProUGUI Cell(Transform parent, float size, Color color, FontStyles style, TextAlignmentOptions align, float width, string name)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		TextMeshProUGUI obj = UIKit.Text(parent, "", size, color, style, align, name);
		((TMP_Text)obj).overflowMode = (TextOverflowModes)0;
		((TMP_Text)obj).enableAutoSizing = true;
		((TMP_Text)obj).fontSizeMax = size;
		((TMP_Text)obj).fontSizeMin = size * 0.7f;
		UIKit.LE((Component)(object)obj, width, width, 0f);
		return obj;
	}

	private static TMP_FontAsset FindFont(bool bold)
	{
		string[] array = ((!bold) ? new string[3] { "Gravity-Book SDF", "Gravity-Regular SDF", "Gravity-Bold SDF" } : new string[3] { "Gravity-Bold SDF", "Gravity-Regular SDF", "Gravity-Book SDF" });
		try
		{
			TMP_FontAsset[] source = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
			string[] array2 = array;
			foreach (string name in array2)
			{
				TMP_FontAsset val = ((IEnumerable<TMP_FontAsset>)source).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset a) => (Object)(object)a != (Object)null && ((Object)a).name == name));
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			TMP_FontAsset val2 = ((IEnumerable<TMP_FontAsset>)source).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset a) => (Object)(object)a != (Object)null && ((Object)a).name == "LiberationSans SDF"));
			if ((Object)(object)val2 != (Object)null)
			{
				return val2;
			}
		}
		catch
		{
		}
		try
		{
			return TMP_Settings.defaultFontAsset;
		}
		catch
		{
			return null;
		}
	}
}
internal static class UIKit
{
	internal static TMP_FontAsset Font;

	internal static TMP_FontAsset BoldFont;

	private static readonly Dictionary<int, Sprite> roundedCache = new Dictionary<int, Sprite>();

	internal static Sprite Rounded(int radius)
	{
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		radius = Mathf.Clamp(radius, 1, 64);
		if (roundedCache.TryGetValue(radius, out var value) && (Object)(object)value != (Object)null)
		{
			return value;
		}
		int num = radius * 2 + 3;
		Texture2D val = NewTexture(num, num, "CardStatPreview_Rounded" + radius);
		Color32[] array = (Color32[])(object)new Color32[num * num];
		for (int i = 0; i < num; i++)
		{
			for (int j = 0; j < num; j++)
			{
				float num2 = (float)j + 0.5f;
				float num3 = (float)i + 0.5f;
				float num4 = Mathf.Max(new float[3]
				{
					(float)radius - num2,
					0f,
					num2 - (float)(num - radius)
				});
				float num5 = Mathf.Max(new float[3]
				{
					(float)radius - num3,
					0f,
					num3 - (float)(num - radius)
				});
				float num6 = Mathf.Sqrt(num4 * num4 + num5 * num5);
				float num7 = Mathf.Clamp01((float)radius - num6 + 0.5f);
				array[i * num + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)Mathf.RoundToInt(num7 * 255f));
			}
		}
		val.SetPixels32(array);
		val.Apply(false, true);
		float num8 = radius + 1;
		Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)num, (float)num), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0, new Vector4(num8, num8, num8, num8));
		((Object)val2).hideFlags = (HideFlags)61;
		((Object)val2).name = ((Object)val).name;
		roundedCache[radius] = val2;
		return val2;
	}

	private static Texture2D NewTexture(int w, int h, string name)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Expected O, but got Unknown
		return new Texture2D(w, h, (TextureFormat)4, false)
		{
			filterMode = (FilterMode)1,
			wrapMode = (TextureWrapMode)1,
			hideFlags = (HideFlags)61,
			name = name
		};
	}

	internal static RectTransform Rect(Transform parent, string name)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: 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_0049: Expected O, but got Unknown
		RectTransform val = (RectTransform)new GameObject(name, new Type[1] { typeof(RectTransform) })
		{
			layer = (((Object)(object)parent != (Object)null) ? ((Component)parent).gameObject.layer : 5)
		}.transform;
		((Transform)val).SetParent(parent, false);
		return val;
	}

	internal static void Stretch(RectTransform rt, float left = 0f, float right = 0f, float top = 0f, float bottom = 0f)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: 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_003e: Unknown result type (might be due to invalid IL or missing references)
		rt.anchorMin = Vector2.zero;
		rt.anchorMax = Vector2.one;
		rt.pivot = new Vector2(0.5f, 0.5f);
		rt.offsetMin = new Vector2(left, bottom);
		rt.offsetMax = new Vector2(0f - right, 0f - top);
	}

	internal static Image Box(Transform parent, Color color, int radius = 0, string name = "Box")
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		Image val = ((Component)Rect(parent, name)).gameObject.AddComponent<Image>();
		((Graphic)val).color = color;
		((Graphic)val).raycastTarget = false;
		if (radius > 0)
		{
			val.sprite = Rounded(radius);
			val.type = (Type)1;
			val.fillCenter = true;
		}
		return val;
	}

	internal static TextMeshProUGUI Text(Transform parent, string text, float size, Color color, FontStyles style = (FontStyles)0, TextAlignmentOptions align = (TextAlignmentOptions)4097, string name = "Text")
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Invalid comparison between Unknown and I4
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: 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_007b: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
		TextMeshProUGUI val = ((Component)Rect(parent, name)).gameObject.AddComponent<TextMeshProUGUI>();
		if ((style & 1) > 0 && (Object)(object)BoldFont != (Object)null)
		{
			((TMP_Text)val).font = BoldFont;
			style = (FontStyles)(style & -2);
		}
		else if ((Object)(object)Font != (Object)null)
		{
			((TMP_Text)val).font = Font;
		}
		((TMP_Text)val).richText = false;
		((TMP_Text)val).text = text ?? "";
		((TMP_Text)val).fontSize = size;
		((Graphic)val).color = color;
		((TMP_Text)val).fontStyle = style;
		((TMP_Text)val).alignment = align;
		((TMP_Text)val).enableWordWrapping = false;
		((TMP_Text)val).overflowMode = (TextOverflowModes)1;
		((Graphic)val).raycastTarget = false;
		((TMP_Text)val).margin = Vector4.zero;
		return val;
	}

	internal static LayoutElement LE(Component c, float minW = -1f, float prefW = -1f, float flexW = -1f, float minH = -1f, float prefH = -1f, float flexH = -1f)
	{
		LayoutElement obj = c.gameObject.GetComponent<LayoutElement>() ?? c.gameObject.AddComponent<LayoutElement>();
		obj.minWidth = minW;
		obj.preferredWidth = prefW;
		obj.flexibleWidth = flexW;
		obj.minHeight = minH;
		obj.preferredHeight = prefH;
		obj.flexibleHeight = flexH;
		return obj;
	}

	internal static HorizontalLayoutGroup HL(Component c, float spacing, int padL = 0, int padR = 0, int padT = 0, int padB = 0, TextAnchor align = (TextAnchor)3, bool expandW = false, bool expandH = false)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Expected O, but got Unknown
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		HorizontalLayoutGroup obj = c.gameObject.AddComponent<HorizontalLayoutGroup>();
		((HorizontalOrVerticalLayoutGroup)obj).spacing = spacing;
		((LayoutGroup)obj).padding = new RectOffset(padL, padR, padT, padB);
		((LayoutGroup)obj).childAlignment = align;
		((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = true;
		((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true;
		((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = expandW;
		((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = expandH;
		return obj;
	}

	internal static VerticalLayoutGroup VL(Component c, float spacing, int padL = 0, int padR = 0, int padT = 0, int padB = 0, TextAnchor align = (TextAnchor)0, bool expandW = true, bool expandH = false)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Expected O, but got Unknown
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		VerticalLayoutGroup obj = c.gameObject.AddComponent<VerticalLayoutGroup>();
		((HorizontalOrVerticalLayoutGroup)obj).spacing = spacing;
		((LayoutGroup)obj).padding = new RectOffset(padL, padR, padT, padB);
		((LayoutGroup)obj).childAlignment = align;
		((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = true;
		((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true;
		((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = expandW;
		((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = expandH;
		return obj;
	}

	internal static void Spacer(Transform parent, float flexW = 1f, float flexH = 0f)
	{
		LE((Component)(object)Rect(parent, "Spacer"), 0f, -1f, flexW, 0f, -1f, flexH);
	}

	internal static Image Bordered(Transform parent, Color fill, Color border, int radius, int thickness, string name = "Card")
	{
		//IL_0001: 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)
		Image obj = Box(parent, border, radius, name);
		HL((Component)(object)obj, 0f, thickness, thickness, thickness, thickness, (TextAnchor)0, expandW: true, expandH: true);
		return Box(((Component)obj).transform, fill, Mathf.Max(1, radius - thickness), "Inner");
	}
}