Decompiled source of SiegeUpgrades v1.1.0

SiegeUpgrades.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mirror;
using SiegeUpgrades.Core;
using SiegeUpgrades.Net;
using SiegeUpgrades.Server;
using SiegeUpgrades.UI;
using SiegeUpgrades.World;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("Digger.Core")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SiegeUpgrades")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Upgrade the automated wall Ballistas and Catapults in a window styled like the game: Forge levels buy damage, attack speed, projectile speed, extra projectiles, range and blast area; each wave survived buys on-hit effects. All players need the mod.")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+1a502b85a98a3c27a7c4f33b7a195f4b29dd6fc4")]
[assembly: AssemblyProduct("SiegeUpgrades")]
[assembly: AssemblyTitle("SiegeUpgrades")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SiegeUpgrades
{
	[BepInPlugin("catedralemchamas.stonewards.siegeupgrades", "SiegeUpgrades", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			SiegeConfig.Init(((BaseUnityPlugin)this).Config);
			ClientState.Init();
			SiegeNet.RegisterSerializers();
			_harmony = new Harmony("catedralemchamas.stonewards.siegeupgrades");
			_harmony.PatchAll();
			((Component)this).gameObject.AddComponent<SiegeDirector>();
			((Component)this).gameObject.AddComponent<DefenseScanner>();
			((Component)this).gameObject.AddComponent<SiegeWindow>();
			((Component)this).gameObject.AddComponent<SiegeHud>();
			((Component)this).gameObject.AddComponent<InputGuard>();
			Log.LogInfo((object)string.Format("SiegeUpgrades: {0} v{1} carregado (protocolo {2}).", "SiegeUpgrades", "1.1.0", 2));
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	internal static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "catedralemchamas.stonewards.siegeupgrades";

		public const string PLUGIN_NAME = "SiegeUpgrades";

		public const string PLUGIN_VERSION = "1.1.0";

		public const string PLUGIN_AUTHOR = "CatedralEmChamas";
	}
}
namespace SiegeUpgrades.World
{
	internal class DefenseInteractable : MonoBehaviour, IInteractable, ICrosshairTarget
	{
		private BoxCollider _box;

		private bool _boxSized;

		private QuickOutline _outline;

		private bool _outlineTried;

		private Renderer[] _renderers;

		private bool _highlighted;

		public static readonly List<DefenseInteractable> All = new List<DefenseInteractable>();

		private static MaterialPropertyBlock _block;

		public AutomatedWeapon Weapon { get; private set; }

		public DefenseType Type { get; private set; }

		public bool Usable
		{
			get
			{
				if ((Object)(object)Weapon != (Object)null && Weapon.syncIsUnlocked)
				{
					return ClientState.Usable;
				}
				return false;
			}
		}

		public static DefenseInteractable Attach(AutomatedWeapon weapon, DefenseType type)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_0061: 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_0081: 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)
			Transform val = (((Object)(object)weapon.unlockedObject != (Object)null) ? weapon.unlockedObject.transform : ((Component)weapon).transform);
			GameObject val2 = new GameObject("SiegeUpgradesInteract");
			val2.SetActive(false);
			int num = LayerMask.NameToLayer("Interactable");
			val2.layer = ((num >= 0) ? num : 11);
			val2.transform.SetParent(val, false);
			val2.transform.localPosition = Vector3.zero;
			val2.transform.localRotation = Quaternion.identity;
			val2.transform.localScale = Vector3.one;
			BoxCollider val3 = val2.AddComponent<BoxCollider>();
			((Collider)val3).isTrigger = true;
			val3.size = Vector3.one;
			DefenseInteractable defenseInteractable = val2.AddComponent<DefenseInteractable>();
			defenseInteractable.Weapon = weapon;
			defenseInteractable.Type = type;
			defenseInteractable._box = val3;
			val2.SetActive(true);
			return defenseInteractable;
		}

		private void OnEnable()
		{
			if (!All.Contains(this))
			{
				All.Add(this);
			}
		}

		private void OnDisable()
		{
			All.Remove(this);
			SetHighlight(on: false);
		}

		private void OnDestroy()
		{
			All.Remove(this);
		}

		private void Update()
		{
			bool usable = Usable;
			if (usable && !_boxSized)
			{
				SizeBox();
			}
			bool flag = usable && PlayerNear();
			if (((Collider)_box).enabled != flag)
			{
				((Collider)_box).enabled = flag;
			}
			if (!flag && _highlighted)
			{
				SetHighlight(on: false);
			}
		}

		private bool PlayerNear()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			FirstPersonController val = (((Object)(object)GameManager.Instance != (Object)null) ? GameManager.Instance.LocalPlayer : null);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			float num = SiegeConfig.InteractDistance.Value + 6f;
			Vector3 val2 = ((Component)val).transform.position - ((Component)this).transform.position;
			return ((Vector3)(ref val2)).sqrMagnitude < num * num;
		}

		private void SizeBox()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: 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_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: 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_01d6: 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_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: 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_0232: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: 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)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: 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_011e: 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_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			Transform parent = ((Component)this).transform.parent;
			if ((Object)(object)parent == (Object)null)
			{
				return;
			}
			_renderers = ((Component)parent).GetComponentsInChildren<Renderer>(false);
			bool flag = false;
			Vector3 val = Vector3.positiveInfinity;
			Vector3 val2 = Vector3.negativeInfinity;
			Renderer[] renderers = _renderers;
			foreach (Renderer val3 in renderers)
			{
				if ((Object)(object)val3 == (Object)null || val3 is ParticleSystemRenderer || val3 is TrailRenderer || val3 is LineRenderer)
				{
					continue;
				}
				Bounds bounds = val3.bounds;
				Vector3 size = ((Bounds)(ref bounds)).size;
				if (!(((Vector3)(ref size)).sqrMagnitude < 0.0001f))
				{
					Vector3 center = ((Bounds)(ref bounds)).center;
					Vector3 extents = ((Bounds)(ref bounds)).extents;
					for (int j = 0; j < 8; j++)
					{
						Vector3 val4 = center + new Vector3(((j & 1) == 0) ? (0f - extents.x) : extents.x, ((j & 2) == 0) ? (0f - extents.y) : extents.y, ((j & 4) == 0) ? (0f - extents.z) : extents.z);
						Vector3 val5 = ((Component)this).transform.InverseTransformPoint(val4);
						val = Vector3.Min(val, val5);
						val2 = Vector3.Max(val2, val5);
					}
					flag = true;
				}
			}
			if (!flag)
			{
				((Vector3)(ref val))..ctor(-1.5f, -0.5f, -1.5f);
				((Vector3)(ref val2))..ctor(1.5f, 2.5f, 1.5f);
			}
			Vector3 lossyScale = ((Component)this).transform.lossyScale;
			float num = 0.25f / Mathf.Max(0.1f, Mathf.Max(lossyScale.x, Mathf.Max(lossyScale.y, lossyScale.z)));
			_box.center = (val + val2) * 0.5f;
			_box.size = val2 - val + Vector3.one * (num * 2f);
			_boxSized = true;
			SiegeConfig.Verbose($"{((Object)Weapon).name}: caixa de interação {_box.size} (centro {_box.center}), {_renderers.Length} modelos.");
		}

		public bool TryGetWorldBounds(out Bounds bounds)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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)
			bounds = default(Bounds);
			if ((Object)(object)_box == (Object)null || !((Collider)_box).enabled || !_boxSized)
			{
				return false;
			}
			bounds = ((Collider)_box).bounds;
			return true;
		}

		public void Interact(FirstPersonController owner)
		{
			if (Usable)
			{
				SiegeWindow.Instance?.Open(this);
			}
		}

		public void OnCrosshairEnter()
		{
			SetHighlight(on: true);
		}

		public void OnCrosshairExit()
		{
			SetHighlight(on: false);
		}

		public string GetInteractionText()
		{
			if (!Usable)
			{
				return string.Empty;
			}
			if (Type != DefenseType.Catapult)
			{
				return "Melhorias da Balista";
			}
			return "Melhorias da Catapulta";
		}

		public string GetInteractionInput()
		{
			if (!Usable)
			{
				return string.Empty;
			}
			return "<style=Player/Interact> ";
		}

		public string GetInteractionStatInfo()
		{
			return string.Empty;
		}

		public float GetInteractionDistance()
		{
			return SiegeConfig.InteractDistance.Value;
		}

		private void SetHighlight(bool on)
		{
			if (_highlighted == on)
			{
				return;
			}
			_highlighted = on;
			if (!(!SiegeConfig.Outline.Value && on))
			{
				EnsureOutline();
				if ((Object)(object)_outline != (Object)null)
				{
					((Behaviour)_outline).enabled = on;
				}
				else
				{
					Tint(on);
				}
			}
		}

		private void EnsureOutline()
		{
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Expected O, but got Unknown
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			if (_outlineTried)
			{
				return;
			}
			_outlineTried = true;
			try
			{
				if (_renderers == null)
				{
					_renderers = (Renderer[])(((Object)(object)((Component)this).transform.parent != (Object)null) ? ((Array)((Component)((Component)this).transform.parent).GetComponentsInChildren<Renderer>(false)) : ((Array)new Renderer[0]));
				}
				List<Renderer> list = new List<Renderer>();
				Renderer[] renderers = _renderers;
				foreach (Renderer val in renderers)
				{
					SkinnedMeshRenderer val2 = (SkinnedMeshRenderer)(object)((val is SkinnedMeshRenderer) ? val : null);
					object obj;
					if (val2 == null)
					{
						if (!(val is MeshRenderer))
						{
							obj = null;
						}
						else
						{
							MeshFilter component = ((Component)val).GetComponent<MeshFilter>();
							obj = ((component != null) ? component.sharedMesh : null);
						}
					}
					else
					{
						obj = val2.sharedMesh;
					}
					Mesh val3 = (Mesh)obj;
					if ((Object)(object)val3 != (Object)null && val3.isReadable)
					{
						list.Add(val);
					}
				}
				if (list.Count == 0)
				{
					SiegeConfig.Verbose(((Object)Weapon).name + ": modelos sem leitura; destaque por cor em vez do contorno.");
					return;
				}
				GameObject val4 = new GameObject("SiegeUpgradesOutline");
				val4.transform.SetParent(((Component)this).transform, false);
				_outline = val4.AddComponent<QuickOutline>();
				_outline.OutlineMode = (Mode)1;
				_outline.OutlineColor = Color.green;
				_outline.OutlineWidth = 7f;
				((Behaviour)_outline).enabled = false;
				_outline.Init(list.ToArray());
			}
			catch (Exception ex)
			{
				_outline = null;
				Plugin.Log.LogWarning((object)("SiegeUpgrades: contorno da defesa indisponível: " + ex.Message));
			}
		}

		private void Tint(bool on)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_0081: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			if (_renderers == null)
			{
				return;
			}
			if (_block == null)
			{
				_block = new MaterialPropertyBlock();
			}
			Renderer[] renderers = _renderers;
			foreach (Renderer val in renderers)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				if (!on)
				{
					val.SetPropertyBlock((MaterialPropertyBlock)null);
					continue;
				}
				Material sharedMaterial = val.sharedMaterial;
				if (!((Object)(object)sharedMaterial == (Object)null))
				{
					_block.Clear();
					if (sharedMaterial.HasProperty("_BaseColor"))
					{
						_block.SetColor("_BaseColor", sharedMaterial.GetColor("_BaseColor") * new Color(1.25f, 1.4f, 1.25f, 1f));
					}
					if (sharedMaterial.HasProperty("_Color"))
					{
						_block.SetColor("_Color", sharedMaterial.GetColor("_Color") * new Color(1.25f, 1.4f, 1.25f, 1f));
					}
					val.SetPropertyBlock(_block);
				}
			}
		}
	}
	internal class DefenseScanner : MonoBehaviour
	{
		private readonly HashSet<int> _attached = new HashSet<int>();

		private int _levelKey;

		private float _nextScan;

		private InputManager _subscribedInput;

		private Action<bool> _onInteract;

		private void Awake()
		{
			_onInteract = OnInteract;
		}

		private void OnDestroy()
		{
			if ((Object)(object)_subscribedInput != (Object)null)
			{
				_subscribedInput.OnInteract -= _onInteract;
			}
		}

		private void Update()
		{
			try
			{
				Tick();
			}
			catch (Exception ex)
			{
				if (Time.unscaledTime >= _nextScan)
				{
					Plugin.Log.LogWarning((object)("SiegeUpgrades: erro ao preparar as defesas: " + ex.Message));
				}
				_nextScan = Time.unscaledTime + 5f;
			}
		}

		private void Tick()
		{
			InputManager instance = InputManager.Instance;
			if ((Object)(object)instance != (Object)(object)_subscribedInput)
			{
				if ((Object)(object)_subscribedInput != (Object)null)
				{
					_subscribedInput.OnInteract -= _onInteract;
				}
				_subscribedInput = instance;
				if ((Object)(object)instance != (Object)null)
				{
					instance.OnInteract += _onInteract;
				}
			}
			if (Time.unscaledTime < _nextScan)
			{
				return;
			}
			_nextScan = Time.unscaledTime + 1f;
			LevelManager instance2 = LevelManager.Instance;
			if (!((Object)(object)instance2 == (Object)null) && SiegeConfig.Enabled.Value)
			{
				int instanceID = ((Object)instance2).GetInstanceID();
				if (instanceID != _levelKey)
				{
					_levelKey = instanceID;
					_attached.Clear();
				}
				AttachAll(instance2.AutomatedBallistas, DefenseType.Ballista);
				AttachAll(instance2.AutomatedCatapults, DefenseType.Catapult);
			}
		}

		private void AttachAll(List<AutomatedWeapon> list, DefenseType type)
		{
			if (list == null)
			{
				return;
			}
			foreach (AutomatedWeapon item in list)
			{
				if (!((Object)(object)item == (Object)null) && _attached.Add(((Object)item).GetInstanceID()))
				{
					DefenseInteractable.Attach(item, type);
					SiegeConfig.Verbose("interação preparada em " + ((Object)item).name + " (" + SiegeTypes.DefenseName(type) + ").");
				}
			}
		}

		private static void OnInteract(bool pressed)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Invalid comparison between Unknown and I4
			try
			{
				if (!SiegeConfig.Enabled.Value || !SiegeConfig.LookAtFallback.Value || !ClientState.Usable || (Object)(object)SiegeWindow.Instance == (Object)null || SiegeWindow.Instance.IsOpen || (Object)(object)InputManager.Instance == (Object)null || (int)InputManager.Instance.CurrentInputState != 2)
				{
					return;
				}
				FirstPersonController val = (((Object)(object)GameManager.Instance != (Object)null) ? GameManager.Instance.LocalPlayer : null);
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val.PlayerStats == (Object)null) && !val.PlayerStats.isDead && (!((Object)(object)val.PlayerInteraction != (Object)null) || val.PlayerInteraction.currentTarget == null))
				{
					float distance;
					DefenseInteractable defenseInteractable = LookedAt(out distance);
					if ((Object)(object)defenseInteractable != (Object)null)
					{
						SiegeWindow.Instance.Open(defenseInteractable);
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("SiegeUpgrades: erro na mira alternativa: " + ex.Message));
			}
		}

		public static DefenseInteractable LookedAt(out float distance)
		{
			//IL_0031: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: 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)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			distance = float.PositiveInfinity;
			CameraManager instance = CameraManager.Instance;
			Camera val = (((Object)(object)instance != (Object)null) ? instance.MainCamera : null);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Vector3 position = ((Component)val).transform.position;
			Vector3 forward = ((Component)val).transform.forward;
			float value = SiegeConfig.InteractDistance.Value;
			DefenseInteractable result = null;
			float num = default(float);
			foreach (DefenseInteractable item in DefenseInteractable.All)
			{
				if ((Object)(object)item == (Object)null || !item.Usable || !item.TryGetWorldBounds(out var bounds))
				{
					continue;
				}
				if (((Bounds)(ref bounds)).Contains(position))
				{
					Vector3 val2 = ((Bounds)(ref bounds)).center - position;
					if (Vector3.Angle(forward, val2) > 60f)
					{
						continue;
					}
					num = 0f;
				}
				else if (!((Bounds)(ref bounds)).IntersectRay(new Ray(position, forward), ref num) || num > value)
				{
					continue;
				}
				if (num < distance)
				{
					distance = num;
					result = item;
				}
			}
			return result;
		}
	}
	[HarmonyPatch(typeof(Projectile), "LocalImpactFX")]
	internal static class ExplosionVfxPatch
	{
		private static bool Prefix(Projectile __instance, Vector3 _Pos)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_0066: 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)
			//IL_0099: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			if (!(__instance is CatapultProjectile) || (Object)(object)__instance.impactFX == (Object)null || SiegeConfig.ScaleExplosionVfx == null || !SiegeConfig.ScaleExplosionVfx.Value)
			{
				return true;
			}
			Vector3 syncVelocity = __instance.SyncVelocity;
			if (!Mathf.Approximately(syncVelocity.y, -7777.5f) || syncVelocity.x <= 0f || syncVelocity.z <= 0.01f)
			{
				return true;
			}
			float num = Mathf.Clamp(syncVelocity.x / syncVelocity.z, 0.25f, 4f);
			if (Mathf.Abs(num - 1f) < 0.02f)
			{
				return true;
			}
			GameObject val = Object.Instantiate<GameObject>(__instance.impactFX, _Pos, Quaternion.identity);
			try
			{
				ParticleSystem[] componentsInChildren = val.GetComponentsInChildren<ParticleSystem>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					MainModule main = componentsInChildren[i].main;
					((MainModule)(ref main)).scalingMode = (ParticleSystemScalingMode)0;
				}
				val.transform.localScale = val.transform.localScale * num;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("SiegeUpgrades: não deu para escalar a explosão: " + ex.Message));
			}
			return false;
		}
	}
}
namespace SiegeUpgrades.UI
{
	internal class InputGuard : MonoBehaviour
	{
		private const float PendingTimeout = 60f;

		private static float _pendingUntil = -1f;

		private bool _ourWindowWasOpen;

		private InputState _lastState;

		private float _nextCheck;

		private static bool Pending => _pendingUntil > Time.unscaledTime;

		internal static void MarkPending()
		{
			_pendingUntil = Time.unscaledTime + 60f;
		}

		private static void ClearPending()
		{
			_pendingUntil = -1f;
		}

		private void LateUpdate()
		{
			//IL_001d: 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)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Invalid comparison between Unknown and I4
			//IL_00ea: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Invalid comparison between Unknown and I4
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Invalid comparison between Unknown and I4
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Invalid comparison between Unknown and I4
			InputManager instance = InputManager.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				_ourWindowWasOpen = false;
				ClearPending();
				return;
			}
			InputState currentInputState = instance.CurrentInputState;
			bool flag = OurWindowOpen();
			if (_ourWindowWasOpen && (int)_lastState == 13 && IsVanillaMenuState(currentInputState))
			{
				MarkPending();
				FixOpenMenus();
			}
			if (Pending)
			{
				if ((int)currentInputState == 2 || (int)currentInputState == 4 || (int)currentInputState == 1 || (Object)(object)GameManager.Instance == (Object)null)
				{
					ClearPending();
				}
				else if (currentInputState != _lastState || Time.unscaledTime >= _nextCheck)
				{
					bool flag2 = IsVanillaMenuState(currentInputState);
					_nextCheck = Time.unscaledTime + (flag2 ? 1f : 0.25f);
					if (flag2)
					{
						FixOpenMenus();
					}
					else if ((int)currentInputState == 13 && !flag && !OtherGeneralMenuOpen())
					{
						Plugin.Log.LogInfo((object)"SiegeUpgrades: input preso em GeneralMenu depois de um menu do jogo; voltando para o jogo.");
						GameInput.RestoreGameplay(restore: true);
						ClearPending();
					}
				}
			}
			_ourWindowWasOpen = flag;
			_lastState = currentInputState;
		}

		internal static bool OurWindowOpen()
		{
			if ((Object)(object)SiegeWindow.Instance != (Object)null)
			{
				return SiegeWindow.Instance.IsOpen;
			}
			return false;
		}

		private static bool IsVanillaMenuState(InputState state)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_000d: 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_0012: Invalid comparison between Unknown and I4
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Invalid comparison between Unknown and I4
			if ((int)state != 13 && (int)state != 2 && (int)state != 4 && (int)state != 0 && (int)state != 1)
			{
				return (int)state != 12;
			}
			return false;
		}

		internal static InputState GameplayState()
		{
			FirstPersonController val = (((Object)(object)GameManager.Instance != (Object)null) ? GameManager.Instance.LocalPlayer : null);
			if ((Object)(object)val != (Object)null && (Object)(object)val.PlayerStats != (Object)null && val.PlayerStats.isDead)
			{
				return (InputState)4;
			}
			return (InputState)2;
		}

		private static void FixOpenMenus()
		{
			//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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Invalid comparison between Unknown and I4
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Invalid comparison between Unknown and I4
			//IL_003c: 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)
			InputState previousState = GameplayState();
			BaseMenu[] array = Object.FindObjectsByType<BaseMenu>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			foreach (BaseMenu val in array)
			{
				if ((Object)(object)val != (Object)null && val.IsOpen && (int)val.previousState == 13 && (int)val.InputState != 13)
				{
					val.previousState = previousState;
				}
			}
		}

		private static bool OtherGeneralMenuOpen()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Invalid comparison between Unknown and I4
			if ((Object)(object)CraftManager.Instance != (Object)null && (Object)(object)CraftManager.Instance.craftMenu != (Object)null && ((BaseMenu)CraftManager.Instance.craftMenu).IsOpen)
			{
				return true;
			}
			BaseMenu[] array = Object.FindObjectsByType<BaseMenu>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			foreach (BaseMenu val in array)
			{
				if ((Object)(object)val != (Object)null && val.IsOpen && (int)val.InputState == 13)
				{
					return true;
				}
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(BaseMenu), "HandleInput")]
	internal static class SiegeBaseMenuHandleInputPatch
	{
		private static void Prefix(bool _Show, out bool __state)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Invalid comparison between Unknown and I4
			__state = false;
			try
			{
				__state = _Show && (Object)(object)InputManager.Instance != (Object)null && (int)InputManager.Instance.CurrentInputState == 13 && InputGuard.OurWindowOpen();
			}
			catch
			{
			}
		}

		private static void Postfix(BaseMenu __instance, bool __state)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Invalid comparison between Unknown and I4
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			if (!__state)
			{
				return;
			}
			try
			{
				if ((int)__instance.previousState == 13 && (int)__instance.InputState != 13)
				{
					__instance.previousState = InputGuard.GameplayState();
					InputGuard.MarkPending();
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("SiegeUpgrades: não consegui ajustar o menu do jogo: " + ex.Message));
			}
		}
	}
	internal static class GameInput
	{
		public static void RestoreGameplay(bool restore)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Invalid comparison between Unknown and I4
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if (restore && !((Object)(object)InputManager.Instance == (Object)null) && (int)InputManager.Instance.CurrentInputState == 13)
			{
				InputManager.Instance.SetState(InputGuard.GameplayState(), true);
			}
		}

		public static void ReleaseMouseCapture()
		{
			if (GUIUtility.hotControl != 0)
			{
				GUIUtility.hotControl = 0;
			}
		}
	}
	internal enum SiegeIcon
	{
		PortraitBallista,
		PortraitCatapult,
		Ballista,
		Catapult,
		Anvil,
		Choice,
		Damage,
		AttackSpeed,
		ProjectileSpeed,
		ExtraProjectiles,
		Area,
		Range,
		Ricochet,
		Freeze,
		Fire,
		Poison,
		Slow,
		Bomb,
		Close,
		Lock,
		Wall
	}
	internal static class SiegeArt
	{
		private static readonly (string palette, string[] rows)[] Data = new(string, string[])[21]
		{
			("O:1E140E W:A86E3C w:70461F L:D09A58 M:9AA6B6 m:5E6878 H:E8EEF6 S:EDE3C4 R:8A3C2A F:D84A3A", new string[32]
			{
				"................................", "..................OO............", ".................OLwO...........", "..................OWwO..........", "................OOSOWwO.........", "...............OSSOOWwO.........", "..............OSOO..OWwO........", "............OOSO....OWwO........", "....OOO....OSSO......OWwOOO.....", "...OFFFOOOOSOOOOOOOOOOWwOMHOO...",
				"...OOOLLLLLLLLLLLLLLLLLLMMHHMO..", "..OLFFFLRRLLLLLLLLLLMMMMOMHOO...", "..OWWWWWRRWWWWWWWWWWMMMMOOO.....", "..OwwwwwRRwwwwwwwwwwMMMMO.......", "..OWWWWWSOOOOOOOOOOOmmmmO.......", ".OWWwLwWWSSmmmmmO...OOWwO.......", ".OWwwLwwWOOSMMMmO....OWwO.......", ".OWLLLLLWOOmSmmmO...OWwO........", ".OWwwLwwWOOwwSSwwO..OWwO........", ".OWWwLwWWOOwwOOSwO.OWwO.........",
				"..OWWWWWOOwwO..OSwOOWwO.........", "...OOOOO.OwwO..OwSSWwO..........", "........OwwO....OwLwO...........", "........OwwOOOOOOwwO............", ".......OWWWWWWWWWWWwO...........", ".......OwwwwwwwwwwwwO...........", "......OwwOOOOOOOOOOwwO..........", "......OwwO........OwwO..........", "....OOwwO.........OOwwO.........", "...OWWWWWO.......OWWWWWO........",
				"...OWWWWWO.......OWWWWWO........", "....OOOOO.........OOOOO........."
			}),
			("O:1E140E W:A86E3C w:70461F L:D09A58 M:9AA6B6 m:5E6878 H:E8EEF6 S:EDE3C4 G:8E8A86 g:C4C0B8 k:4C4A48", new string[32]
			{
				"................................", "................................", "....O...........................", "...OSOO.........................", "...OSLLO........................", "...OSLLLOO......................", "..OSOOOLLLOO....................", ".OGGGO.OLLLLO...................", "OGgGGGO.OOLLLOOOO...............", "OGGGGGO...OOLLLHHO..............",
				"OGGGkGO.....OLLWMO..............", ".OGGGO......OMMWWWO.............", "..OOO.......OWWOWWWO............", "............OWWOwwWWOO..........", "...........OWWO.OwwWWWOOOO......", "...........OWWO.OwwOMMMMMMO.....", "...........OWWO.OwwOmmmmmmO.....", "..........OWWOOOOOwwmkkkkmO.....", "..........OwwwwwwwwwmkkkkmO.....", "..........OWWOOOOOwwmkkkkmO.....",
				".........OWWO.....OwmmmmmmO.....", ".........OWWO.....OwwOOOOO......", "........OWWO.......OwwO.........", "...OOOOOOWWOOOOOOOOOwwOOOOO.....", "..OLLLLLLLLLLLLLLLLLLLLLLLLO....", "..OWWWWWWWWWWWWWWWWWWWWWWWWO....", "..OwwwwwwwwwwwwwwwwwwwwwwwwO....", "...OOwwwwwOOOOOOOOOOwwwwwOO.....", "....OwwMwwO........OwwMwwO......", "....OwwwwwO........OwwwwwO......",
				".....OwwwO..........OwwwO.......", "......OOO............OOO........"
			}),
			("O:1E140E W:A86E3C w:70461F L:D09A58 M:9AA6B6 H:E8EEF6 S:EDE3C4", new string[16]
			{
				"..........O.....", ".........OWO....", ".........OOWO...", "........OSSWO...", "......OOSOOOWO..", "....OOSSOOOOWOO.", "..OOLLLLLLLMMMHO", ".OLLLLLLLLLMMOO.", ".OWWWWWWWWWMMO..", "..OOSSOwwOOOO...",
				"....OOSOOwOOWO..", "....OwOSSOwOWO..", "....OwOOOSSWO...", "...OwO...OOWO...", "..OwO....OWOwO..", "...O......O.O..."
			}),
			("O:1E140E W:A86E3C w:70461F L:D09A58 M:9AA6B6 m:5E6878 G:9C9892 g:D8D4CC", new string[16]
			{
				"...O............", ".OOLOO..........", "OgGLLLOOOO......", "OGGGLLLLMMO.....", ".OGOOOLLLWwO....", "..O...OWLOWwO...", "......OWWOwWWOO.", ".....OWWO.OwmmmO", "....OWWO..OwmmmO", "....OWWO...OmmmO",
				".OOOWWOOOOOOwwO.", "OLLLLLLLLLLLLLLO", "OWWWWWWWWWWWWWWO", ".OOwwOOOOOOwwOO.", "..OwwO....OwwO..", "...OO......OO..."
			}),
			("O:14161C M:9AA4B4 m:5A6272 H:DCE4EE Y:FFD04A W:FFF6C8", new string[16]
			{
				"................", "..........Y.....", ".........YWY....", "....Y.....Y.....", "...YWY..........", "....Y...........", ".OOOOOOOOOOOO...", ".OHHHHHHHHHHHOO.", ".OMMMMMMMMMMMMO.", "..OmmmmmmmmmmO..",
				".....OMMMMO.....", ".....OmMMmO.....", "...OOMMMMMMOO...", "...OmmmmmmmmO...", "...OOOOOOOOOO...", "................"
			}),
			("O:1A1030 B:6A5ACD b:45389A h:9C8CF0 Y:FFD84A", new string[16]
			{
				"................", ".OOOOOOOOOOOOO..", ".OhhhhhhhhhhbO..", ".OhBBBBYBBBBbO..", ".OhBBBYYYBBBbO..", ".OhBYYYYYYYBbO..", ".OhBBYYYYYBBbO..", ".OhBBBYYYBBBbO..", ".OhBBYYBYYBBbO..", ".OhBBYBBBYBBbO..",
				"..OhBBBBBBBbO...", "...OhBBBBBbO....", "....OhBBBbO.....", ".....ObBbO......", "......OOO.......", "................"
			}),
			("O:12141A W:EEF3F8 g:A6B2C0 Y:E8B840 y:A67A20 b:6E4424", new string[16]
			{
				"................", "............OOO.", "...........OWWO.", "..........OWWgO.", ".........OWWgO..", "........OWWgO...", ".......OWWgO....", "..OO..OWWgO.....", "..OYOOWWgO......", "...OYYWgO.......",
				"....OYyO........", "...ObOYyO.......", "..ObO.OYyO......", ".ObO...OO.......", ".OO.............", "................"
			}),
			("O:0C1A24 B:7FE4FF b:2FA4D8 h:E6FBFF", new string[16]
			{
				"................", ".........OOOOO..", "........OhBBbO..", ".......OhBBbO...", "......OhBBbO....", ".....OhBBbO.....", "....OhBBBOOOOO..", "...OhhhhhhBBbO..", "...OOOOOBBBbO...", ".......OBBbO....",
				"......OBBbO.....", ".....OBBbO......", "....OBbbO.......", "....ObbO........", "....OOO.........", "................"
			}),
			("O:12141A B:A86E3C L:D09A58 F:E85050 M:9AA6B6 H:E8EEF6 s:7FE4FF", new string[16]
			{
				"................", "................", "....ss..........", "sss.............", "............O...", ".OO........OMO..", "OFFOOOOOOOOOMHO.", ".OFLLLLLLLLLMHHO", ".OFBBBBBBBBBMHHO", "OFFOOOOOOOOOMHO.",
				".OO........OMO..", "............O...", "sss.............", "....ss..........", "................", "................"
			}),
			("O:12141A B:C08040 H:E8EEF6 F:E85050", new string[16]
			{
				".......O........", "......OHO.......", ".OO..OHHHO...OO.", "OHHO..OBO...OHHO", "OHBO..OBO...OBHO", ".OOBO.OBO..OBOO.", "..OBO.OBO..OBO..", "...OBOOBO.OBO...", "...OBOOBO.OBO...", "....OBOBOOBO....",
				"....OBOBOOBO....", ".....OBBOBO.....", ".....OBBOBO.....", "......OBBO......", ".....OFFFO......", "......OOO......."
			}),
			("O:3A0E08 R:FF5A1C Y:FFC43A W:FFF6C8", new string[16]
			{
				".......O........", "......ORO.......", ".....ORRRO..OO..", ".OOOOORRROOORRO.", "ORRRRRRRRRRRRO..", ".ORRRRRYYYRRRO..", "..ORRRYYYYYRO...", "...ORYYYWYYYO...", "...ORYYWWWYYO...", "..ORRYYYWYYYRO..",
				".ORRRRYYYYYRRRO.", ".ORRRORYYYOOOO..", "OROOO.ORRO......", ".O....ORRO......", ".......OO.......", "................"
			}),
			("L:D0D6E0 R:FF5A4A W:FFFFFF", new string[16]
			{
				".......WW.......", ".......WW.......", "....LLLWWLLL....", "...LL......LL...", "..LL........LL..", "..L..RRRRRR..L..", "..L..R....R..L..", "WWW..R.RR.R..WWW", "WWW..R.RR.RR.WWW", "..L..R....R..L..",
				"..L..RRRRRR..L..", "..LL....R...LL..", "...LL......LL...", "....LLLWWLLL....", ".......WW.......", ".......WW......."
			}),
			("O:3A2A08 Y:FFE14A y:D9A820 W:FFFFFF", new string[16]
			{
				"..........OOOOO.", ".........OYYYYYO", ".OO......OYYYYYO", "OYyO......OOYYYO", ".OYyO.......OYYO", ".OYyO......OYYYO", "..OYyO....OYyOO.", "...OYyO..OYyO...", "...OYyO..OYyO...", "....OYyOOYyO....",
				"....OYyOYyO.....", ".....OYYyO......", ".....OOOOO......", "....OWOWOWO.....", ".....OOWOO......", ".......O........"
			}),
			("C:9FE8FF W:FFFFFF", new string[16]
			{
				"................", ".......C........", "..C..C.C.C..C...", "...C..CCC..C....", "....C..C..C.....", ".....C.C.C......", "......CCC.......", ".CCCCCCWCCCCCC..", "......CCC.......", ".....C.C.C......",
				"....C..C..C.....", "...C..CCC..C....", "..C..C.C.C..C...", ".......C........", "................", "................"
			}),
			("O:3A0E08 R:FF4A1C Y:FFB02A W:FFF1B0", new string[16]
			{
				"................", "........O.......", ".......ORO......", ".......ORRO.....", "......ORRRO.....", ".....ORRYRRO....", "....ORRYYRRO....", "...ORRYYYYRRO...", "...ORYYWYYYRO...", "..ORRYYWWYYRRO..",
				"..ORYYWWWWYYRO..", "..ORYYWWWWYYRO..", "...ORYYWWYYRO...", "....ORRYYRRO....", ".....OOOOOO.....", "................"
			}),
			("O:0C2410 G:6CD64A g:3A8A2A h:D8FFC8 b:9CF07A", new string[16]
			{
				"..b.............", ".b.b...O........", "..b...OGO.......", "......OGO.......", ".....OGGGO......", ".....OGGGO...b..", "....OGGhGGO.b.b.", "...OGGhGGGGO.b..", "...OGhGGGGgO....", "..OGGhGGGGGgO...",
				"..OGGGGGGGGgO...", "..OGGGGGGGggO...", "...OGGGGGggO....", "....OggggggO....", ".....OOOOOO.....", "................"
			}),
			("O:1A1030 W:E8E0F8 S:B98CFF", new string[16]
			{
				"................", "...OOOOOOOOO....", "...OWWWWWWWO....", "....OSSSSSO.....", "....OSSSSSO.....", ".....OSSSO......", "......OSO.......", ".......O........", "......O.O.......", ".....O.S.O......",
				"....O..S..O.....", "....O.SSS.O.....", "...OSSSSSSSO....", "...OWWWWWWWO....", "...OOOOOOOOO....", "................"
			}),
			("O:0C0C10 K:3A3E4A k:22252C h:8A92A6 b:C08040 Y:FFD04A W:FFFFFF", new string[16]
			{
				"................", "..........Y.....", ".........YWY....", "..........Y.....", ".........b......", "........b.......", ".....OOOOO......", "...OOKKKKKOO....", "..OKKhKKKKKKO...", "..OKhKKKKKKKO...",
				".OKKKKKKKKKKKO..", ".OKKKKKKKKKKKO..", ".OKKKKKKKKKkKO..", "..OKKKKKKKkkO...", "...OOKKKKKOO....", ".....OOOOO......"
			}),
			("O:14100A W:F4F1E8 g:B8B2A2", new string[16]
			{
				"................", "................", "...OO......OO...", "..OWWO....OWWO..", "..OgWWO..OWWgO..", "...OgWWOOWWgO...", "....OgWWWWgO....", ".....OgWWgO.....", ".....OWWWWO.....", "....OWWggWWO....",
				"...OWWgOOgWWO...", "..OWWgO..OgWWO..", "..OggO....OggO..", "...OO......OO...", "................", "................"
			}),
			("O:14100A Y:E8B840 y:A67A20 h:FFE28A g:C0C8D0 d:7A828C", new string[16]
			{
				"................", "................", ".....OOOOOO.....", "....OggggggO....", "...OgdOOOOgdO...", "...OgO....OgO...", "...OgO....OgO...", "..OOOOOOOOOOOO..", "..OhhhhhhhhhhO..", "..OYYYYOOYYYyO..",
				"..OYYYYOOYYYyO..", "..OYYYYYOYYYyO..", "..OYYYYYYYYYyO..", "..OyyyyyyyyyyO..", "...OOOOOOOOOO...", "................"
			}),
			("O:14100A S:9C98A0 s:6C6874 h:C8C4CC", new string[16]
			{
				"................", "..OOO..OOO..OOO.", "..OhO..OhO..OhO.", "..OSOOOOSOOOOSO.", "..OSSSSSSSSSSSO.", "..OOOOOOOOOOOOO.", "..OSShOSShOSSsO.", "..OSSsOSSsOSSsO.", "..OOOOOOOOOOOOO.", "..OShOSShOSShsO.",
				"..OSsOSSsOSSssO.", "..OOOOOOOOOOOOO.", "..OSShOSShOSSsO.", "..OSSsOSSsOSSsO.", "..OOOOOOOOOOOOO.", "................"
			})
		};

		private static readonly Texture2D[] Cache = (Texture2D[])(object)new Texture2D[Data.Length];

		public static Texture2D Get(SiegeIcon icon)
		{
			int num = (int)icon;
			if (num < 0 || num >= Cache.Length)
			{
				return Texture2D.whiteTexture;
			}
			if ((Object)(object)Cache[num] != (Object)null)
			{
				return Cache[num];
			}
			Dictionary<char, Color> palette = ParsePalette(Data[num].palette);
			Cache[num] = BuildTexture(Data[num].rows, palette, "Siege_" + icon);
			return Cache[num];
		}

		public static Texture2D Portrait(DefenseType type)
		{
			return Get((type == DefenseType.Catapult) ? SiegeIcon.PortraitCatapult : SiegeIcon.PortraitBallista);
		}

		public static Texture2D DefenseIcon(DefenseType type)
		{
			return Get((type == DefenseType.Catapult) ? SiegeIcon.Catapult : SiegeIcon.Ballista);
		}

		public static Texture2D StatIcon(StatKind stat)
		{
			return Get(stat switch
			{
				StatKind.Damage => SiegeIcon.Damage, 
				StatKind.AttackSpeed => SiegeIcon.AttackSpeed, 
				StatKind.ProjectileSpeed => SiegeIcon.ProjectileSpeed, 
				StatKind.ExtraProjectiles => SiegeIcon.ExtraProjectiles, 
				StatKind.ExplosionArea => SiegeIcon.Area, 
				_ => SiegeIcon.Range, 
			});
		}

		public static Texture2D EffectIcon(EffectKind effect)
		{
			return Get(effect switch
			{
				EffectKind.Ricochet => SiegeIcon.Ricochet, 
				EffectKind.Freeze => SiegeIcon.Freeze, 
				EffectKind.Burn => SiegeIcon.Fire, 
				EffectKind.Poison => SiegeIcon.Poison, 
				EffectKind.Slow => SiegeIcon.Slow, 
				_ => SiegeIcon.Bomb, 
			});
		}

		public static Color EffectColor(EffectKind effect)
		{
			//IL_001c: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			return (Color)(effect switch
			{
				EffectKind.Ricochet => Ui.RicochetYellow, 
				EffectKind.Freeze => Ui.Ice, 
				EffectKind.Burn => Ui.Fire, 
				EffectKind.Poison => Ui.PoisonGreen, 
				EffectKind.Slow => Ui.SlowPurple, 
				_ => Ui.BlastRed, 
			});
		}

		public static Color PortraitGlow(DefenseType type)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if (type != DefenseType.Catapult)
			{
				return new Color(1f, 0.72f, 0.38f, 1f);
			}
			return new Color(0.55f, 0.7f, 0.95f, 1f);
		}

		private static Dictionary<char, Color> ParsePalette(string spec)
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<char, Color> dictionary = new Dictionary<char, Color>();
			string[] array = spec.Split(' ');
			foreach (string text in array)
			{
				if (text.Length == 8 && text[1] == ':')
				{
					int num = Convert.ToInt32(text.Substring(2), 16);
					dictionary[text[0]] = new Color((float)((num >> 16) & 0xFF) / 255f, (float)((num >> 8) & 0xFF) / 255f, (float)(num & 0xFF) / 255f, 1f);
				}
			}
			return dictionary;
		}

		private static Texture2D BuildTexture(string[] rows, Dictionary<char, Color> palette, string name)
		{
			//IL_0011: 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_001d: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0086: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			int num = rows.Length;
			int length = rows[0].Length;
			Texture2D val = new Texture2D(length, num, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)0,
				wrapMode = (TextureWrapMode)1,
				hideFlags = (HideFlags)61,
				name = name
			};
			Color[] array = (Color[])(object)new Color[length * num];
			for (int i = 0; i < num; i++)
			{
				string text = rows[i];
				for (int j = 0; j < length; j++)
				{
					char key = ((j < text.Length) ? text[j] : '.');
					array[(num - 1 - i) * length + j] = (palette.TryGetValue(key, out var value) ? value : Color.clear);
				}
			}
			val.SetPixels(array);
			val.Apply(false, false);
			return val;
		}
	}
	internal class SiegeHud : MonoBehaviour
	{
		private string _notice;

		private NoticeStyle _style;

		private float _start;

		private float _until;

		private GUIStyle _noticeStyle;

		private Font _font;

		private void Awake()
		{
			SiegeNet.OnNotice += delegate(SiegeNoticeMsg m)
			{
				if (SiegeConfig.ShowNotices == null || SiegeConfig.ShowNotices.Value || m.Style == NoticeStyle.Error)
				{
					_notice = m.Text;
					_style = m.Style;
					_start = Time.unscaledTime;
					_until = Time.unscaledTime + ((m.Style == NoticeStyle.Error) ? 3.5f : 4f);
				}
			};
		}

		private void OnGUI()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Invalid comparison between Unknown and I4
			//IL_007e: 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_008f: 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_009d: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			//IL_00bf: Expected O, but got Unknown
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			GUI.depth = -1001;
			if (_notice != null && !(Time.unscaledTime >= _until) && (int)Event.current.type == 7)
			{
				Ui.EnsureStyles();
				float num = Mathf.Clamp((float)Screen.height / 1080f, 0.7f, 2.5f);
				if (_noticeStyle == null || (Object)(object)_font != (Object)(object)Ui.GameFont)
				{
					_font = Ui.GameFont;
					_noticeStyle = new GUIStyle(GUI.skin.label)
					{
						font = _font,
						alignment = (TextAnchor)4,
						clipping = (TextClipping)0,
						wordWrap = false,
						richText = false,
						padding = new RectOffset(0, 0, 0, 0)
					};
					_noticeStyle.normal.textColor = Color.white;
				}
				float num2 = Time.unscaledTime - _start;
				float a = Mathf.Min(1f, num2 / 0.12f) * Mathf.Min(1f, (_until - Time.unscaledTime) / 0.35f);
				float num3 = 1f + 0.12f * Mathf.Max(0f, 1f - num2 / 0.15f);
				_noticeStyle.fontSize = Mathf.Max(8, Mathf.RoundToInt(32f * num * num3 * (((Object)(object)Ui.GameFont != (Object)null) ? 1f : 0.7f)));
				float num4 = 52f * num;
				Rect r = default(Rect);
				((Rect)(ref r))..ctor(0f, NoticeY(num4), (float)Screen.width, num4);
				Color color = (Color)(_style switch
				{
					NoticeStyle.Success => new Color(0.6f, 1f, 0.55f), 
					NoticeStyle.Error => new Color(1f, 0.55f, 0.5f), 
					_ => new Color(1f, 0.9f, 0.55f), 
				});
				color.a = a;
				Ui.Outlined(r, _notice, _noticeStyle, color, Mathf.Max(1.2f, 2f * num));
			}
		}

		private static float NoticeY(float height)
		{
			//IL_0028: 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)
			float num = (float)Screen.height * 0.27f;
			if ((Object)(object)SiegeWindow.Instance == (Object)null || !SiegeWindow.Instance.IsOpen)
			{
				return num;
			}
			Rect panelScreenRect = SiegeWindow.PanelScreenRect;
			if (num + height <= ((Rect)(ref panelScreenRect)).y || num >= ((Rect)(ref panelScreenRect)).yMax)
			{
				return num;
			}
			if (((Rect)(ref panelScreenRect)).y >= height + 2f)
			{
				return ((Rect)(ref panelScreenRect)).y - height - 2f;
			}
			if ((float)Screen.height - ((Rect)(ref panelScreenRect)).yMax >= height + 2f)
			{
				return ((Rect)(ref panelScreenRect)).yMax + 2f;
			}
			return ((Rect)(ref panelScreenRect)).yMax - height;
		}
	}
	internal class SiegeWindow : MonoBehaviour
	{
		private struct Pop
		{
			public int Shown;

			public float Start;

			public int Direction;

			public bool Has;
		}

		private enum Side
		{
			Left,
			Right
		}

		public static SiegeWindow Instance;

		private const float PanelWidth = 1180f;

		private const float PanelHeight = 920f;

		private const float OpenSeconds = 0.16f;

		private bool _open;

		private float _openedAt;

		private DefenseType _tab;

		private AutomatedWeapon _weapon;

		private Pop _pointsPop;

		private Pop _choicesPop;

		private CachedText _pointsTip;

		private CachedText _choicesTip;

		private readonly CachedText[] _level = new CachedText[2];

		private readonly CachedText[] _status = new CachedText[2];

		private readonly CachedText[] _chipDamage = new CachedText[2];

		private readonly CachedText[] _chipRate = new CachedText[2];

		private readonly CachedText[] _chipSpeed = new CachedText[2];

		private readonly CachedText[] _chipExtra = new CachedText[2];

		private readonly CachedText[] _chipArea = new CachedText[2];

		private readonly CachedText[] _chipRange = new CachedText[2];

		private readonly CachedText[] _chipCooldown = new CachedText[2];

		private readonly CachedText[] _effectChip = new CachedText[12];

		private const float RowH = 48f;

		private const float RowGap = 5f;

		private const float SectionH = 38f;

		private CachedText _pointsLeft;

		private CachedText _choicesLeft;

		private readonly Dictionary<int, (int level, float until)> _pending = new Dictionary<int, (int, float)>();

		private readonly CachedText[] _statValues = new CachedText[12];

		private readonly CachedText[] _statLevels = new CachedText[12];

		private readonly CachedText[] _statTips = new CachedText[12];

		private readonly CachedText[] _effectValues = new CachedText[12];

		private readonly CachedText[] _effectLevels = new CachedText[12];

		private readonly CachedText[] _effectTips = new CachedText[12];

		private CachedText _missing;

		public bool IsOpen => _open;

		private static float PanelScale => Ui.WindowScale(1180f, 920f);

		public static Rect PanelScreenRect
		{
			get
			{
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				float panelScale = PanelScale;
				float num = 1180f * panelScale;
				float num2 = 920f * panelScale;
				return new Rect(((float)Screen.width - num) / 2f, ((float)Screen.height - num2) / 2f, num, num2);
			}
		}

		private void Awake()
		{
			Instance = this;
		}

		public void Open(DefenseInteractable target)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Invalid comparison between Unknown and I4
			if (!_open && !((Object)(object)target == (Object)null) && !((Object)(object)target.Weapon == (Object)null) && !((Object)(object)InputManager.Instance == (Object)null) && ClientState.Usable && (int)InputManager.Instance.CurrentInputState == 2)
			{
				_weapon = target.Weapon;
				_tab = target.Type;
				_open = true;
				_openedAt = Time.unscaledTime;
				_pending.Clear();
				InputManager.Instance.SetState((InputState)13, true);
				GameSounds.PlayUi("UPGRADE_UI_SHOW", 0.6f);
			}
		}

		public void Close(bool restoreInput = true)
		{
			if (_open)
			{
				_open = false;
				_weapon = null;
				GameInput.ReleaseMouseCapture();
				GameInput.RestoreGameplay(restoreInput);
			}
		}

		private void Update()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Invalid comparison between Unknown and I4
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			if (!_open)
			{
				return;
			}
			if ((Object)(object)_weapon == (Object)null || (Object)(object)InputManager.Instance == (Object)null || !ClientState.Usable || (int)InputManager.Instance.CurrentInputState != 13)
			{
				Close();
				return;
			}
			if (Time.unscaledTime - _openedAt > 0.3f && (Input.GetKeyDown((KeyCode)27) || Input.GetKeyDown((KeyCode)101) || Input.GetKeyDown((KeyCode)9)))
			{
				Close();
				return;
			}
			FirstPersonController val = (((Object)(object)GameManager.Instance != (Object)null) ? GameManager.Instance.LocalPlayer : null);
			if ((Object)(object)val == (Object)null || ((Object)(object)val.PlayerStats != (Object)null && val.PlayerStats.isDead) || Vector3.Distance(((Component)val).transform.position, ((Component)_weapon).transform.position) > SiegeConfig.InteractDistance.Value + 8f)
			{
				Close();
			}
		}

		private void OnGUI()
		{
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			if (!_open)
			{
				return;
			}
			GUI.depth = -1000;
			float num = Mathf.Clamp01((Time.unscaledTime - _openedAt) / 0.16f);
			float num2 = 1f - (1f - num) * (1f - num) * (1f - num);
			float num3 = PanelScale * Mathf.Lerp(0.96f, 1f, num2);
			Matrix4x4 matrix = GUI.matrix;
			Color color = GUI.color;
			GUI.matrix = Matrix4x4.Scale(new Vector3(num3, num3, 1f));
			GUI.color = new Color(1f, 1f, 1f, Mathf.Lerp(0.2f, 1f, num2));
			try
			{
				float num4 = (float)Screen.width / num3;
				float num5 = (float)Screen.height / num3;
				Ui.BeginWindow();
				DrawWindow(new Rect((num4 - 1180f) / 2f, (num5 - 920f) / 2f, 1180f, 920f));
				Ui.EndWindow(num4, num5);
			}
			catch (Exception ex)
			{
				Ui.LogOnce("janela das defesas", ex);
			}
			finally
			{
				GUI.matrix = matrix;
				GUI.color = color;
			}
		}

		private void DrawWindow(Rect panel)
		{
			//IL_0000: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: 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_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0378: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_041f: Unknown result type (might be due to invalid IL or missing references)
			//IL_042e: Unknown result type (might be due to invalid IL or missing references)
			Ui.Window(panel);
			Rect r = default(Rect);
			((Rect)(ref r))..ctor(((Rect)(ref panel)).x + 12f, ((Rect)(ref panel)).y + 12f, ((Rect)(ref panel)).width - 24f, 68f);
			Ui.Header(r);
			Ui.Icon(new Rect(((Rect)(ref r)).x + 14f, ((Rect)(ref r)).y + 11f, 44f, 44f), SiegeArt.Get(SiegeIcon.Ballista));
			Ui.Label(new Rect(((Rect)(ref r)).x + 68f, ((Rect)(ref r)).y + 2f, 480f, 60f), "Defesas do Muro", Ui.TitleStyle, Ui.Title);
			Rect r2 = default(Rect);
			((Rect)(ref r2))..ctor(((Rect)(ref r)).xMax - 64f, ((Rect)(ref r)).y + 10f, 52f, 48f);
			if (Ui.Button(r2, null, ButtonKind.Red, enabled: true, SiegeArt.Get(SiegeIcon.Close), -1, null, "Fechar (E / Esc)"))
			{
				Close();
				return;
			}
			Rect r3 = default(Rect);
			((Rect)(ref r3))..ctor(((Rect)(ref r2)).x - 14f - 150f, ((Rect)(ref r)).y + 10f, 150f, 48f);
			DrawCounter(new Rect(((Rect)(ref r3)).x - 12f - 150f, ((Rect)(ref r)).y + 10f, 150f, 48f), SiegeArt.Get(SiegeIcon.Anvil), ClientState.PointsAvailable, ref _pointsPop, PointsTooltip());
			DrawCounter(r3, SiegeArt.Get(SiegeIcon.Choice), ClientState.ChoicesAvailable, ref _choicesPop, ChoicesTooltip());
			Rect r4 = default(Rect);
			((Rect)(ref r4))..ctor(((Rect)(ref panel)).x + 24f, ((Rect)(ref panel)).y + 138f, ((Rect)(ref panel)).width - 48f, ((Rect)(ref panel)).height - 138f - 54f);
			Ui.Card(r4);
			float num = ((Rect)(ref panel)).x + 30f;
			float num2 = ((Rect)(ref r4)).y - 46f;
			if (Ui.Tab(new Rect(num, num2, 260f, 46f), "Balista", SiegeArt.Get(SiegeIcon.Ballista), _tab == DefenseType.Ballista))
			{
				_tab = DefenseType.Ballista;
			}
			if (Ui.Tab(new Rect(num + 260f + 8f, num2, 260f, 46f), "Catapulta", SiegeArt.Get(SiegeIcon.Catapult), _tab == DefenseType.Catapult))
			{
				_tab = DefenseType.Catapult;
			}
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((Rect)(ref r4)).x + 20f, ((Rect)(ref r4)).y + 20f, ((Rect)(ref r4)).width - 40f, ((Rect)(ref r4)).height - 40f);
			if (!ClientState.HasState)
			{
				Ui.Label(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y, ((Rect)(ref val)).width, 40f), "Aguardando o servidor...", Ui.Body, Ui.Muted, (TextAnchor)3);
			}
			else
			{
				DrawSheet(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y, 440f, ((Rect)(ref val)).height), _tab);
				float num3 = ((Rect)(ref val)).x + 470f;
				DrawUpgrades(new Rect(num3, ((Rect)(ref val)).y, ((Rect)(ref val)).xMax - num3, ((Rect)(ref val)).height), _tab);
			}
			float num4 = ((Rect)(ref panel)).yMax - 50f;
			Ui.Label(new Rect(((Rect)(ref panel)).x + 32f, num4, 260f, 40f), "E / Esc: fechar", Ui.Small, Ui.Dim, (TextAnchor)3);
			float num5 = Ui.TextWidth("Cada nível da Forja dá 1 ponto · cada wave sobrevivida dá 1 escolha de efeito", Ui.Small);
			float num6 = ((Rect)(ref panel)).xMax - 32f - num5;
			Ui.Icon(new Rect(num6 - 34f, num4 + 7f, 26f, 26f), SiegeArt.Get(SiegeIcon.Choice), 0.85f);
			Ui.Icon(new Rect(num6 - 64f, num4 + 7f, 26f, 26f), SiegeArt.Get(SiegeIcon.Anvil), 0.85f);
			Ui.Label(new Rect(num6, num4, num5 + 4f, 40f), "Cada nível da Forja dá 1 ponto · cada wave sobrevivida dá 1 escolha de efeito", Ui.Small, Ui.Dim, (TextAnchor)3);
		}

		private static void DrawCounter(Rect r, Texture2D icon, int value, ref Pop pop, string tooltip)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: 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_016d: Invalid comparison between Unknown and I4
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			if ((int)Event.current.type == 7 && (!pop.Has || value != pop.Shown))
			{
				if (pop.Has)
				{
					pop.Start = Time.unscaledTime;
					pop.Direction = ((value > pop.Shown) ? 1 : (-1));
				}
				pop.Shown = value;
				pop.Has = true;
			}
			Ui.Inset(r);
			float num = (Time.unscaledTime - pop.Start) / 0.35f;
			float num2 = ((num >= 0f && num < 1f) ? (Mathf.Sin(num * MathF.PI) * (1f - num * 0.4f)) : 0f);
			float num3 = 38f * (1f + 0.2f * num2);
			Ui.Icon(new Rect(((Rect)(ref r)).x + 26f - num3 / 2f, ((Rect)(ref r)).center.y - num3 / 2f, num3, num3), icon);
			Color color = ((num2 > 0f) ? Color.Lerp(Ui.Text, (pop.Direction > 0) ? Ui.Warn : Ui.Bad, num2) : Ui.Text);
			Ui.Label(new Rect(((Rect)(ref r)).x + 50f, ((Rect)(ref r)).y - 2f, ((Rect)(ref r)).width - 62f, ((Rect)(ref r)).height), Txt.Int(value), Ui.NumberBig, color, (TextAnchor)5);
			if ((int)Event.current.type == 7 && Ui.MouseOver(r))
			{
				Ui.Tooltip(tooltip);
			}
		}

		private string PointsTooltip()
		{
			SiegeStateMsg state = ClientState.State;
			long key = CachedText.Key(state.PointsEarned, state.PointsSpent, state.ForgeLevel);
			if (!_pointsTip.Needs(key))
			{
				return _pointsTip.Text;
			}
			return _pointsTip.Set(key, $"Pontos da Forja: {ClientState.PointsAvailable} para gastar ({state.PointsEarned} ganhos, {state.PointsSpent} gastos). " + $"Cada nível novo da Forja dá pontos (agora a Forja está no nível {state.ForgeLevel}). Valem para as melhorias das duas defesas.");
		}

		private string ChoicesTooltip()
		{
			SiegeStateMsg state = ClientState.State;
			long key = CachedText.Key(state.ChoicesEarned, state.ChoicesSpent, state.WavesSurvived);
			if (!_choicesTip.Needs(key))
			{
				return _choicesTip.Text;
			}
			return _choicesTip.Set(key, $"Escolhas de efeito: {ClientState.ChoicesAvailable} para usar ({state.ChoicesEarned} ganhas, {state.ChoicesSpent} usadas). " + $"Cada wave sobrevivida dá uma escolha ({state.WavesSurvived} waves até agora).");
		}

		private void DrawSheet(Rect r, DefenseType type)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Invalid comparison between Unknown and I4
			//IL_0123: 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_0154: 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_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: 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_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0391: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_041f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0516: Unknown result type (might be due to invalid IL or missing references)
			//IL_0483: Unknown result type (might be due to invalid IL or missing references)
			//IL_0579: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_059c: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_063a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0649: Unknown result type (might be due to invalid IL or missing references)
			//IL_0823: Unknown result type (might be due to invalid IL or missing references)
			//IL_0832: Unknown result type (might be due to invalid IL or missing references)
			//IL_086d: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0741: Unknown result type (might be due to invalid IL or missing references)
			//IL_0746: Unknown result type (might be due to invalid IL or missing references)
			//IL_0748: Unknown result type (might be due to invalid IL or missing references)
			//IL_0753: Unknown result type (might be due to invalid IL or missing references)
			//IL_0755: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b2: Unknown result type (might be due to invalid IL or missing references)
			float x = ((Rect)(ref r)).x;
			float y = ((Rect)(ref r)).y;
			Rect r2 = default(Rect);
			((Rect)(ref r2))..ctor(x, y, 150f, 200f);
			DrawPortrait(r2, type);
			int num = ClientState.TotalLevels(type);
			string text = (_level[(uint)type].Needs(num) ? _level[(uint)type].Set(num, "Nv " + num) : _level[(uint)type].Text);
			float num2 = Mathf.Max(76f, Ui.TextWidth(text, Ui.BadgeText) + 26f);
			Ui.Badge(new Rect(((Rect)(ref r2)).xMax - num2 + 6f, ((Rect)(ref r2)).yMax - 20f, num2, 36f), text);
			if ((int)Event.current.type == 7 && Ui.MouseOver(r2))
			{
				Ui.Tooltip("Nível = melhorias e efeitos comprados para esta defesa. Valem para as duas posições do muro, e também para uma defesa construída depois.");
			}
			float num3 = x + 170f;
			float num4 = 270f;
			Ui.Label(new Rect(num3, y - 2f, num4, 52f), SiegeTypes.DefenseName(type), Ui.H1, Ui.Title, (TextAnchor)3);
			Ui.Label(new Rect(num3 + 2f, y + 46f, num4, 28f), "Defesa automática", Ui.Small, Ui.Muted, (TextAnchor)3);
			bool built;
			string text2 = StatusText(type, out built);
			float num5 = Mathf.Min(118f, Ui.TextHeight(text2, Ui.SmallWrap, num4) + 4f);
			Ui.Label(new Rect(num3, y + 82f, num4, num5), text2, Ui.SmallWrap, built ? Ui.Good : Ui.Muted);
			float cy = y + 222f;
			float colW = 215f;
			float num6 = ClientState.BaseDamage(type) * Mult(type, StatKind.Damage);
			int num7 = Mathf.RoundToInt(num6 * 10f);
			Ui.Chip(Cell(0), SiegeArt.StatIcon(StatKind.Damage), _chipDamage[(uint)type].Needs(num7) ? _chipDamage[(uint)type].Set(num7, "Dano " + Txt.Dec(num6)) : _chipDamage[(uint)type].Text, Ui.Text, "Dano de cada disparo (com as cartas do jogo e a melhoria de Dano)");
			float num8 = Mult(type, StatKind.AttackSpeed);
			int num9 = Mathf.RoundToInt(num8 * 100f);
			Ui.Chip(Cell(1), SiegeArt.StatIcon(StatKind.AttackSpeed), _chipRate[(uint)type].Needs(num9) ? _chipRate[(uint)type].Set(num9, "Vel. ataque ×" + Txt.Dec(num8, "0.00")) : _chipRate[(uint)type].Text, Ui.Text, "Velocidade de ataque comparada com a defesa normal");
			float num10 = ClientState.BaseProjectileSpeed(type) * Mult(type, StatKind.ProjectileSpeed);
			int num11 = Mathf.RoundToInt(num10 * 10f);
			Ui.Chip(Cell(2), SiegeArt.StatIcon(StatKind.ProjectileSpeed), _chipSpeed[(uint)type].Needs(num11) ? _chipSpeed[(uint)type].Set(num11, "Vel. projétil " + Txt.Dec(num10, "0") + " m/s") : _chipSpeed[(uint)type].Text, Ui.Text, (type == DefenseType.Catapult) ? "Velocidade da pedra (cai no mesmo ponto, só chega antes)" : "Velocidade do virote");
			int num12 = ClientState.StatLevel(type, StatKind.ExtraProjectiles);
			Ui.Chip(Cell(3), SiegeArt.StatIcon(StatKind.ExtraProjectiles), _chipExtra[(uint)type].Needs(num12) ? _chipExtra[(uint)type].Set(num12, "Projéteis +" + num12) : _chipExtra[(uint)type].Text, (num12 > 0) ? Ui.Good : Ui.Text, "Projéteis extras em cada disparo");
			float num13 = ClientState.BaseCooldown(type) / Mathf.Max(0.01f, num8);
			float num14 = ClientState.Range(type);
			if (type == DefenseType.Catapult)
			{
				float num15 = ClientState.BaseArea(type) * Mult(type, StatKind.ExplosionArea);
				int num16 = Mathf.RoundToInt(num15 * 10f);
				Ui.Chip(Cell(4), SiegeArt.StatIcon(StatKind.ExplosionArea), _chipArea[(uint)type].Needs(num16) ? _chipArea[(uint)type].Set(num16, "Área " + Txt.Dec(num15, "0.0") + " m") : _chipArea[(uint)type].Text, Ui.Text, "Raio da explosão da pedra");
			}
			else
			{
				int num17 = Mathf.RoundToInt(num13 * 100f);
				Ui.Chip(Cell(4), SiegeArt.Get(SiegeIcon.AttackSpeed), _chipCooldown[(uint)type].Needs(num17) ? _chipCooldown[(uint)type].Set(num17, "Recarga " + Txt.Dec(num13, "0.00") + " s") : _chipCooldown[(uint)type].Text, Ui.Text, "Tempo mínimo entre disparos (a animação de disparo também acelera quando precisa)");
			}
			int num18 = Mathf.RoundToInt(num14);
			Ui.Chip(Cell(5), SiegeArt.Get(SiegeIcon.Range), _chipRange[(uint)type].Needs(num18) ? _chipRange[(uint)type].Set(num18, "Alcance " + num18 + " m") : _chipRange[(uint)type].Text, Ui.Text, "Distância em que a defesa acha monstros");
			float num19 = cy + 156f + 6f;
			Ui.Label(new Rect(x, num19, 440f, 32f), "Efeitos ativos", Ui.H3, Ui.Title, (TextAnchor)3);
			num19 += 36f;
			int num20 = 0;
			Rect r3 = default(Rect);
			for (int i = 0; i < 6; i++)
			{
				EffectKind effectKind = (EffectKind)i;
				int num21 = ClientState.EffectLevel(type, effectKind);
				if (num21 > 0 && SiegeTypes.EffectApplies(type, effectKind))
				{
					int num22 = Mathf.RoundToInt(Mathf.Clamp01((float)num21 * ClientState.EffectChancePerLevel(effectKind)) * 100f);
					int num23 = (int)type * 6 + i;
					string text3 = (_effectChip[num23].Needs(num22) ? _effectChip[num23].Set(num22, $"{SiegeTypes.EffectShortName(type, effectKind)} {num22}%") : _effectChip[num23].Text);
					((Rect)(ref r3))..ctor(x + (float)(num20 % 2) * 224f, num19 + (float)(num20 / 2) * 42f, 216f, 34f);
					Color val = SiegeArt.EffectColor(effectKind);
					Ui.Chip(r3, SiegeArt.EffectIcon(effectKind), text3, val, Ui.MouseOver(r3) ? EffectTooltip(type, effectKind, num21) : null);
					Ui.Solid(new Rect(((Rect)(ref r3)).x + 6f, ((Rect)(ref r3)).yMax - 5f, ((Rect)(ref r3)).width - 12f, 2f), Ui.WithAlpha(val, 0.65f));
					num20++;
				}
			}
			if (num20 == 0)
			{
				Ui.Label(new Rect(x, num19, 440f, 30f), "Nenhum ainda — use as escolhas de wave", Ui.Small, Ui.Dim, (TextAnchor)3);
			}
			float num24 = num19 + 126f + 8f;
			Ui.Label(new Rect(x, num24, 440f, 32f), "Posições no muro", Ui.H3, Ui.Title, (TextAnchor)3);
			num24 += 38f;
			float num25 = 214f;
			DrawWallSlot(new Rect(x, num24, num25, Mathf.Min(96f, ((Rect)(ref r)).yMax - num24)), Side.Left, type);
			DrawWallSlot(new Rect(x + num25 + 12f, num24, num25, Mathf.Min(96f, ((Rect)(ref r)).yMax - num24)), Side.Right, type);
			Rect Cell(int num26)
			{
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				return new Rect(x + (float)(num26 % 2) * (colW + 10f), cy + (float)(num26 / 2) * 52f, colW, 42f);
			}
		}

		private static void DrawPortrait(Rect r, DefenseType type)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Invalid comparison between Unknown and I4
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: 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_01e2: Unknown result type (might be due to invalid IL or missing references)
			Ui.Inset(r);
			if ((int)Event.current.type == 7)
			{
				Color val = SiegeArt.PortraitGlow(type);
				Rect val2 = default(Rect);
				((Rect)(ref val2))..ctor(((Rect)(ref r)).x + 3f, ((Rect)(ref r)).y + 3f, ((Rect)(ref r)).width - 6f, ((Rect)(ref r)).height - 6f);
				GUI.BeginGroup(val2);
				Ui.Solid(new Rect(0f, 0f, ((Rect)(ref val2)).width, ((Rect)(ref val2)).height), new Color(val.r * 0.2f, val.g * 0.2f, val.b * 0.2f, 0.9f));
				Ui.Glow(new Rect((0f - ((Rect)(ref val2)).width) * 0.25f, (0f - ((Rect)(ref val2)).height) * 0.05f, ((Rect)(ref val2)).width * 1.5f, ((Rect)(ref val2)).height * 1.1f), new Color(val.r, val.g, val.b, 0.35f));
				Ui.Solid(new Rect(0f, ((Rect)(ref val2)).height * 0.86f, ((Rect)(ref val2)).width, ((Rect)(ref val2)).height * 0.14f), new Color(0f, 0f, 0f, 0.35f));
				Texture2D val3 = SiegeArt.Portrait(type);
				int num = Mathf.Max(1, Mathf.FloorToInt(Mathf.Min((((Rect)(ref val2)).width - 6f) / (float)((Texture)val3).width, (((Rect)(ref val2)).height - 10f) / (float)((Texture)val3).height)));
				float num2 = ((Texture)val3).width * num;
				float num3 = ((Texture)val3).height * num;
				Ui.Icon(new Rect((((Rect)(ref val2)).width - num2) / 2f, ((Rect)(ref val2)).height - num3 - Mathf.Max(6f, (((Rect)(ref val2)).height - num3) * 0.3f), num2, num3), val3);
				GUI.EndGroup();
			}
		}

		private static void DrawWallSlot(Rect r, Side side, DefenseType tab)
		{
			//IL_00bf: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Invalid comparison between Unknown and I4
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Invalid comparison between Unknown and I4
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			if (!(((Rect)(ref r)).height < 40f))
			{
				AutomatedWeapon val = FindWeapon(DefenseType.Ballista, side);
				AutomatedWeapon val2 = FindWeapon(DefenseType.Catapult, side);
				bool flag = (Object)(object)val != (Object)null && val.syncIsUnlocked;
				DefenseType? defenseType = (((Object)(object)val2 != (Object)null && val2.syncIsUnlocked) ? new DefenseType?(DefenseType.Catapult) : (flag ? new DefenseType?(DefenseType.Ballista) : ((DefenseType?)null)));
				bool flag2 = defenseType.HasValue && defenseType.Value == tab;
				Color frame = (Color)(flag2 ? Ui.GoldLight : (defenseType.HasValue ? new Color(0.55f, 0.6f, 0.7f, 1f) : new Color(0.3f, 0.33f, 0.4f, 1f)));
				if (flag2 && (int)Event.current.type == 7)
				{
					float num = 0.8f + 0.2f * Mathf.Sin(Time.unscaledTime * 2.5f);
					Ui.Glow(new Rect(((Rect)(ref r)).x - 10f, ((Rect)(ref r)).y - 10f, ((Rect)(ref r)).width + 20f, ((Rect)(ref r)).height + 20f), Ui.WithAlpha(Ui.GoldLight, 0.18f * num));
				}
				Ui.Slot(r, frame);
				float num2 = ((Rect)(ref r)).height - 24f;
				Rect r2 = default(Rect);
				((Rect)(ref r2))..ctor(((Rect)(ref r)).x + 12f, ((Rect)(ref r)).y + 12f, num2, num2);
				if (defenseType.HasValue)
				{
					Ui.Icon(r2, SiegeArt.DefenseIcon(defenseType.Value));
				}
				else
				{
					Ui.Icon(r2, SiegeArt.Get(SiegeIcon.Wall), 0.45f);
				}
				float num3 = ((Rect)(ref r2)).xMax + 12f;
				Ui.Label(new Rect(num3, ((Rect)(ref r)).y + 12f, ((Rect)(ref r)).xMax - num3 - 8f, 30f), (side == Side.Left) ? "Esquerda" : "Direita", Ui.Body, Ui.Text, (TextAnchor)3);
				string text = (defenseType.HasValue ? SiegeTypes.DefenseName(defenseType.Value) : "Vazia");
				Ui.Label(new Rect(num3, ((Rect)(ref r)).y + 44f, ((Rect)(ref r)).xMax - num3 - 8f, 28f), text, Ui.Small, flag2 ? Ui.Good : (defenseType.HasValue ? Ui.Muted : Ui.Dim), (TextAnchor)3);
				if ((int)Event.current.type == 7 && Ui.MouseOver(r))
				{
					Ui.Tooltip(defenseType.HasValue ? ("Posição " + ((side == Side.Left) ? "esquerda" : "direita") + " do muro: " + SiegeTypes.DefenseName(defenseType.Value) + " construída") : "Posição livre: as cartas 'Adicionar balista' e 'Adicionar trabuco' do fim da wave constroem aqui");
				}
			}
		}

		private static AutomatedWeapon FindWeapon(DefenseType type, Side side)
		{
			LevelManager instance = LevelManager.Instance;
			List<AutomatedWeapon> list = (((Object)(object)instance == (Object)null) ? null : ((type == DefenseType.Catapult) ? instance.AutomatedCatapults : instance.AutomatedBallistas));
			if (list == null)
			{
				return null;
			}
			string value = ((side == Side.Left) ? " L" : " R");
			foreach (AutomatedWeapon item in list)
			{
				if ((Object)(object)item != (Object)null && ((Object)item).name.EndsWith(value, StringComparison.Ordinal))
				{
					return item;
				}
			}
			int num = ((side == Side.Left) ? 1 : 0);
			if (num >= list.Count)
			{
				return null;
			}
			return list[num];
		}

		private string StatusText(DefenseType type, out bool built)
		{
			AutomatedWeapon val = FindWeapon(type, Side.Left);
			AutomatedWeapon val2 = FindWeapon(type, Side.Right);
			bool flag = (Object)(object)val != (Object)null && val.syncIsUnlocked;
			bool flag2 = (Object)(object)val2 != (Object)null && val2.syncIsUnlocked;
			built = flag || flag2;
			int num = 0;
			Side[] array = new Side[2]
			{
				Side.Left,
				Side.Right
			};
			foreach (Side side in array)
			{
				AutomatedWeapon val3 = FindWeapon(DefenseType.Ballista, side);
				AutomatedWeapon val4 = FindWeapon(DefenseType.Catapult, side);
				if (((Object)(object)val3 == (Object)null || !val3.syncIsUnlocked) && ((Object)(object)val4 == (Object)null || !val4.syncIsUnlocked))
				{
					num++;
				}
			}
			int num2 = (int)type * 64 + (flag ? 1 : 0) + (flag2 ? 2 : 0) + num * 4;
			ref CachedText reference = ref _status[(uint)type];
			if (!reference.Needs(num2))
			{
				return reference.Text;
			}
			string text = ((flag && flag2) ? "Ativa (esquerda e direita)" : (built ? (flag ? "Ativa (esquerda)" : "Ativa (direita)") : ((num != 0) ? ("Não construída — escolha a carta '" + SiegeTypes.UnlockCardName(type) + "' no fim de uma wave.") : "Não construída — as duas posições do muro já estão ocupadas.")));
			return reference.Set(num2, text);
		}

		private static float Mult(DefenseType type, StatKind stat)
		{
			return 1f + ClientState.StatPercent(stat) / 100f * (float)Mathf.Min(ClientState.StatLevel(type, stat), ClientState.StatMax(stat));
		}

		private void DrawUpgrades(Rect r, DefenseType type)
		{
			//IL_0020: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			float x = ((Rect)(ref r)).x;
			float width = ((Rect)(ref r)).width;
			float y = ((Rect)(ref r)).y;
			DrawSection(new Rect(x, y, width, 38f), "Melhorias com pontos da Forja", SiegeArt.Get(SiegeIcon.Anvil), ClientState.PointsAvailable, ref _pointsLeft, "ponto", "pontos");
			y += 44f;
			for (int i = 0; i < 6; i++)
			{
				StatKind stat = (StatKind)i;
				if (SiegeTypes.StatApplies(type, stat))
				{
					DrawStatRow(new Rect(x, y, width, 48f), type, stat);
					y += 53f;
				}
			}
			y += 8f;
			DrawSection(new Rect(x, y, width, 38f), "Efeitos (1 escolha por wave)", SiegeArt.Get(SiegeIcon.Choice), ClientState.ChoicesAvailable, ref _choicesLeft, "escolha", "escolhas");
			y += 44f;
			for (int j = 0; j < 6; j++)
			{
				if (SiegeTypes.EffectApplies(type, (EffectKind)j))
				{
					DrawEffectRow(new Rect(x, y, width, 48f), type, (EffectKind)j);
					y += 53f;
				}
			}
			float num = ((Rect)(ref r)).yMax - y;
			string text = ((type == DefenseType.Catapult) ? "Na Catapulta os efeitos valem para todos os monstros da explosão; os estilhaços saem uma vez por pedra." : "Na Balista cada acerto sorteia os efeitos, inclusive o ricochete do virote.");
			float num2 = Ui.TextHeight(text, Ui.TinyWrap, width);
			if (num >= num2 + 4f)
			{
				Ui.Label(new Rect(x, y + 2f, width, num2 + 2f), text, Ui.TinyWrap, Ui.Dim);
			}
		}

		private static void DrawSection(Rect r, string title, Texture2D icon, int available, ref CachedText cache, string one, string many)
		{
			//IL_0009: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			Ui.Icon(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).center.y - 16f, 32f, 32f), icon);
			Ui.Label(new Rect(((Rect)(ref r)).x + 40f, ((Rect)(ref r)).y, ((Rect)(ref r)).width - 200f, ((Rect)(ref r)).height), title, Ui.H2, Ui.Title, (TextAnchor)3);
			string text = (cache.Needs(available) ? cache.Set(available, (available == 1) ? ("1 " + one + " para usar") : $"{available} {many} para usar") : cache.Text);
			Ui.Label(new Rect(((Rect)(ref r)).xMax - 200f, ((Rect)(ref r)).y, 200f, ((Rect)(ref r)).height), text, Ui.Small, (available > 0) ? Ui.Good : Ui.Dim, (TextAnchor)5);
		}

		private static int PendingKey(BuyKind kind, DefenseType type, int index)
		{
			return (int)kind * 100 + (int)type * 10 + index;
		}

		private void DrawStatRow(Rect r, DefenseType type, StatKind stat)
		{
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			int num = (int)type * 6 + (int)stat;
			int num2 = ClientState.StatLevel(type, stat);
			int num3 = ClientState.StatMax(stat);
			int num4 = ClientState.StatNextCost(type, stat);
			bool flag = num4 < 0;
			long key = CachedText.Key(num2, flag ? 1 : 0, Mathf.RoundToInt(ClientState.BaseDamage(type) * 10f) ^ Mathf.RoundToInt(ClientState.StatPercent(stat) * 100f));
			string values = (_statValues[num].Needs(key) ? _statValues[num].Set(key, StatValues(type, stat, num2, flag)) : _statValues[num].Text);
			long key2 = CachedText.Key(num2, num3);
			string levelText = (_statLevels[num].Needs(key2) ? _statLevels[num].Set(key2, $"Nv {num2}/{num3}") : _statLevels[num].Text);
			long key3 = CachedText.Key(num2, num4, Mathf.RoundToInt(ClientState.StatPercent(stat) * 100f));
			string tooltip = (_statTips[num].Needs(key3) ? _statTips[num].Set(key3, StatTooltip(type, stat, num4)) : _statTips[num].Text);
			DrawRow(r, SiegeArt.StatIcon(stat), Color.white, SiegeTypes.StatName(stat), levelText, values, flag, tooltip, BuyKind.Stat, type, (int)stat, num2, num4, ClientState.PointsAvailable, SiegeArt.Get(SiegeIcon.Anvil), "pontos da Forja");
		}

		private void DrawEffectRow(Rect r, DefenseType type, EffectKind effect)
		{
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			int num = (int)type * 6 + (int)effect;
			int num2 = ClientState.EffectLevel(type, effect);
			int num3 = ClientState.EffectMax(effect);
			int num4 = ClientState.EffectNextCost(type, effect);
			bool flag = num4 < 0;
			float num5 = ClientState.EffectChancePerLevel(effect);
			int num6 = Mathf.RoundToInt(Mathf.Clamp01((float)num2 * num5) * 100f);
			int num7 = Mathf.RoundToInt(Mathf.Clamp01((float)(num2 + 1) * num5) * 100f);
			long key = CachedText.Key(num6, flag ? (-1) : num7);
			string values = (_effectValues[num].Needs(key) ? _effectValues[num].Set(key, flag ? $"Chance {num6}%" : $"Chance {num6}% » {num7}%") : _effectValues[num].Text);
			long key2 = CachedText.Key(num2, num3);
			string levelText = (_effectLevels[num].Needs(key2) ? _effectLevels[num].Set(key2, $"Nv {num2}/{num3}") : _effectLevels[num].Text);
			long key3 = CachedText.Key(num2, num4, Mathf.RoundToInt(ClientState.EffectValueA(effect) * 10f) ^ Mathf.RoundToInt(ClientState.EffectValueB(effect) * 100f));
			string tooltip = (_effectTips[num].Needs(key3) ? _effectTips[num].Set(key3, EffectTooltip(type, effect, num2)) : _effectTips[num].Text);
			DrawRow(r, SiegeArt.EffectIcon(effect), SiegeArt.EffectColor(effect), SiegeTypes.EffectName(type, effect), levelText, values, flag, tooltip, BuyKind.Effect, type, (int)effect, num2, num4, ClientState.ChoicesAvailable, SiegeArt.Get(SiegeIcon.Choice), "escolhas de efeito");
		}

		private void DrawRow(Rect r, Texture2D icon, Color accent, string name, string levelText, string values, bool maxed, string tooltip, BuyKind kind, DefenseType type, int index, int level, int cost, int available, Texture2D priceIcon, string currency)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: 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_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Invalid comparison between Unknown and I4
			//IL_01e0: 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_02ea: Unknown result type (might be due to invalid IL or missing references)
			Ui.Inset(r);
			if (level > 0)
			{
				Ui.Solid(new Rect(((Rect)(ref r)).x + 3f, ((Rect)(ref r)).y + 6f, 3f, ((Rect)(ref r)).height - 12f), Ui.WithAlpha((accent == Color.white) ? Ui.Good : accent, 0.85f));
			}
			Ui.Icon(new Rect(((Rect)(ref r)).x + 12f, ((Rect)(ref r)).y + (((Rect)(ref r)).height - 32f) / 2f, 32f, 32f), icon);
			Rect r2 = default(Rect);
			((Rect)(ref r2))..ctor(((Rect)(ref r)).xMax - 140f - 4f, ((Rect)(ref r)).y + 3f, 140f, ((Rect)(ref r)).height - 6f);
			float num = ((Rect)(ref r)).x + 54f;
			Ui.Label(style: (Ui.TextWidth(name, Ui.Body) <= 236f) ? Ui.Body : Ui.Small, r: new Rect(num, ((Rect)(ref r)).y + 1f, 236f, 26f), text: name, color: Ui.Text, anchor: (TextAnchor)3);
			Ui.Label(new Rect(num, ((Rect)(ref r)).y + 24f, 236f, 22f), levelText, Ui.Tiny, (level > 0) ? Ui.Muted : Ui.Dim, (TextAnchor)3);
			float num2 = ((Rect)(ref r)).x + 300f;
			DrawValues(new Rect(num2, ((Rect)(ref r)).y, ((Rect)(ref r2)).x - num2 - 8f, ((Rect)(ref r)).height - 2f), values, maxed);
			if ((int)Event.current.type == 7 && Ui.MouseOver(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, ((Rect)(ref r2)).x - ((Rect)(ref r)).x, ((Rect)(ref r)).height)))
			{
				Ui.Tooltip(tooltip);
			}
			if (maxed)
			{
				Ui.Badge(new Rect(((Rect)(ref r2)).x + 15f, ((Rect)(ref r2)).y + (((Rect)(ref r2)).height - 34f) / 2f, 110f, 34f), "MÁX");
				return;
			}
			int key = PendingKey(kind, type, index);
			(int, float) value;
			bool flag = _pending.TryGetValue(key, out value) && value.Item1 == level && Time.unscaledTime < value.Item2;
			bool flag2 = available >= cost;
			string tooltip2;
			if (!flag2)
			{
				long key2 = CachedText.Key(cost - available, (int)kind);
				tooltip2 = (_missing.Needs(key2) ? _missing.Set(key2, $"Faltam {cost - available} {currency}") : _missing.Text);
			}
			else
			{
				tooltip2 = (flag ? "Comprando..." : "Comprar o próximo nível");
			}
			if (Ui.Button(r2, null, ButtonKind.Green, flag2 && !flag, null, cost, priceIcon, tooltip2, small: true) && !flag)
			{
				_pending[key] = (level, Time.unscaledTime + 1f);
				SiegeNet.SendToServer<SiegeBuyMsg>(new SiegeBuyMsg
				{
					Kind = kind,
					Defense = type,
					Index = (byte)index,
					ExpectedLevel = (byte)Mathf.Clamp(level, 0, 255)
				});
			}
		}

		private static void DrawValues(Rect r, string values, bool maxed)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_009a: 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_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: 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)
			if (!string.IsNullOrEmpty(values))
			{
				int num = values.IndexOf('»');
				GUIStyle style = ((Ui.TextWidth(values, Ui.Small) <= ((Rect)(ref r)).width) ? Ui.Small : Ui.Tiny);
				if (maxed || num < 0)
				{
					Ui.Label(r, values, style, maxed ? Ui.Good : Ui.Muted, (TextAnchor)3);
					return;
				}
				string text = values.Substring(0, num).TrimEnd();
				string text2 = values.Substring(num + 1).TrimStart();
				float num2 = Ui.TextWidth(text, style);
				Ui.Label(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, num2 + 4f, ((Rect)(ref r)).height), text, style, Ui.Muted, (TextAnchor)3);
				float num3 = ((Rect)(ref r)).x + num2 + 8f;
				Ui.Label(new Rect(num3, ((Rect)(ref r)).y, 18f, ((Rect)(ref r)).height), "»", style, Ui.GoldLight, (TextAnchor)3);
				Ui.Label(new Rect(num3 + 18f, ((Rect)(ref r)).y, Mathf.Max(0f, ((Rect)(ref r)).xMax - num3 - 18f), ((Rect)(ref r)).height), text2, style, Ui.Good, (TextAnchor)3);
			}
		}

		private static string StatValues(DefenseType type, StatKind stat, int level, bool maxed)
		{
			float num = ClientState.StatPercent(stat) / 100f;
			float num2 = 1f + num * (float)level;
			float num3 = 1f + num * (float)(level + 1);
			switch (stat)
			{
			case StatKind.Damage:
			{
				float num6 =