Decompiled source of SeneaL PoV Bridge v3.0.3

SeneaLUI.PovSkills.dll

Decompiled 3 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using PassiveTree;
using PassiveTree.Encounters;
using PassiveTree.Encounters.HallMaps;
using PassiveTree.Loot;
using PassiveTree.RunicCraft;
using PassiveTree.UI;
using SeneaL.API;
using SeneaLUI.Components;
using SeneaLUI.Core;
using SeneaLUI.Hud;
using SeneaLUI.Inv;
using SeneaLUI.Map;
using SeneaLUI.Mods;
using SeneaLUI.Patches;
using SeneaLUI.Theme;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Valheiman.Api;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("SeneaLUI.PovSkills")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SeneaLUI.PovSkills")]
[assembly: AssemblyTitle("SeneaLUI.PovSkills")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SeneaLUI.PovSkills;

internal sealed class AnvilView
{
	private sealed class Cell
	{
		public Slot Slot;

		public TextMeshProUGUI Count;

		public Image Own;

		public Image Flash;

		public Cell Pov;

		public Vector2 At;

		public bool Popped;

		public int Index = -1;

		public readonly Tip Tip = new Tip();
	}

	private sealed class Flight
	{
		public RectTransform Rt;

		public Image Img;

		public Vector2 From;

		public Vector2 To;

		public float T;
	}

	private const float TargetTop = 66f;

	private const float BarTop = 140f;

	private const float SlotsTop = 184f;

	private const float ActionTop = 252f;

	private const float WhyTop = 278f;

	private const float CostTop = 306f;

	private const float ForgeTop = 350f;

	private const float StockTop = 416f;

	private const int SlotSize = 56;

	private const int StockSize = 44;

	private const TextAlignmentOptions Left = (TextAlignmentOptions)257;

	private const TextAlignmentOptions Mid = (TextAlignmentOptions)258;

	private static readonly string[] Dust = new string[2] { "PT_AzuriteDust", "PT_DivineAzuriteDust" };

	private static readonly Color Rune = new Color(0.45f, 0.85f, 1f);

	private static FieldRef<RectTransform> _window;

	private static FieldRef<Container> _shown;

	private static FieldRef<Cell> _targetCell;

	private static FieldRef<List<Cell>> _slotCells;

	private static FieldRef<List<Cell>> _stockCells;

	private static FieldRef<string[]> _chosen;

	private static FieldRef<TMP_Text> _title;

	private static FieldRef<TMP_Text> _potentialText;

	private static FieldRef<TMP_Text> _actionText;

	private static FieldRef<TMP_Text> _whyText;

	private static FieldRef<TMP_Text> _buttonLabel;

	private static FieldRef<TMP_Text> _upgradeLabel;

	private static FieldRef<TMP_Text> _repairLabel;

	private static FieldRef<Image> _potentialFill;

	private static FieldRef<Image> _potentialCost;

	private static FieldRef<Button> _forge;

	private static FieldRef<Button> _upgrade;

	private static FieldRef<Button> _repair;

	private static FieldRef<UITooltip> _forgeTip;

	private static FieldRef<UITooltip> _upgradeTip;

	private static FieldRef<UITooltip> _repairTip;

	private static FieldRef<GameObject[]> _costSlots;

	private static FieldRef<Cell, string> _id;

	private static FieldRef<Cell, Image> _icon;

	private static FieldRef<Cell, TMP_Text> _number;

	private static FieldRef<Cell, UITooltip> _tip;

	private static FieldRef<Cell, Color> _rest;

	private static FieldRef<Cell, Color> _popColor;

	private static FieldRef<Cell, float> _pop;

	private static FieldRef<List<RectTransform>> _flying;

	private static Action<Cell, InputButton> _click;

	private static Action _onForge;

	private static Action _onUpgrade;

	private static Action _onRepair;

	private static Action<Container, Cell, InputButton, bool> _clickNow;

	private static readonly FieldRef<InventoryGui, ItemData> DragItem = AccessTools.FieldRefAccess<InventoryGui, ItemData>("m_dragItem");

	private static FieldRef<CraftView, bool> _foreign;

	private static string _missing;

	private static bool _broken;

	private static bool _chestHidden;

	private static bool _raised;

	private static float _fullH;

	private static AnvilView _page;

	private readonly CraftView _view;

	private readonly CraftCover _cover;

	private readonly RectTransform _root;

	private readonly RectTransform _bar;

	private readonly RectTransform _fill;

	private readonly RectTransform _cost;

	private readonly RectTransform _stockBox;

	private readonly float _w;

	private readonly TextMeshProUGUI _heading;

	private readonly TextMeshProUGUI _info;

	private readonly TextMeshProUGUI _potential;

	private readonly TextMeshProUGUI _action;

	private readonly TextMeshProUGUI _why;

	private readonly GoldButton _forgeBtn;

	private readonly GoldButton _upgradeBtn;

	private readonly GoldButton _repairBtn;

	private readonly Cell _target;

	private readonly Cell[] _slots = new Cell[4];

	private readonly List<Cell> _stock = new List<Cell>();

	private readonly ReqChip[] _dustChips = (ReqChip[])(object)new ReqChip[2];

	private readonly ReqChip[] _upChips = (ReqChip[])(object)new ReqChip[4];

	private readonly Tip _forgeHint = new Tip();

	private readonly Tip _upgradeHint = new Tip();

	private readonly Tip _repairHint = new Tip();

	private readonly Sprite _lock;

	private readonly List<Flight> _flights = new List<Flight>();

	private readonly HashSet<int> _flown = new HashSet<int>();

	private float _h;

	private float _next;

	private float _fit;

	private float _stockH = 100f;

	private int _placed = -1;

	private bool _pressedOnCell;

	internal static bool Active { get; private set; }

	internal static string Lmb => MouseName("Lmb", "LMB");

	internal static string Rmb => MouseName("Rmb", "RMB");

	private static FieldRef<T> Pov<T>(string name)
	{
		FieldInfo fieldInfo = AccessTools.Field(typeof(RunicAnvilWindow), name);
		if (fieldInfo == null || fieldInfo.FieldType != typeof(T))
		{
			_missing = _missing ?? ("PoV RunicAnvilWindow." + name);
			return null;
		}
		return AccessTools.StaticFieldRefAccess<T>(fieldInfo);
	}

	private static FieldRef<Cell, T> OfCell<T>(string name)
	{
		FieldInfo fieldInfo = AccessTools.Field(typeof(Cell), name);
		if (fieldInfo == null || fieldInfo.FieldType != typeof(T))
		{
			_missing = _missing ?? ("PoV RunicAnvilWindow.Cell." + name);
			return null;
		}
		return AccessTools.FieldRefAccess<Cell, T>(fieldInfo);
	}

	private static Action Call(string name)
	{
		MethodInfo methodInfo = AccessTools.Method(typeof(RunicAnvilWindow), name, Type.EmptyTypes, (Type[])null);
		if (methodInfo == null)
		{
			_missing = _missing ?? ("PoV RunicAnvilWindow." + name);
			return null;
		}
		return AccessTools.MethodDelegate<Action>(methodInfo, (object)null, true);
	}

	internal static string Patch(Harmony harmony)
	{
		//IL_034a: Unknown result type (might be due to invalid IL or missing references)
		//IL_035f: Unknown result type (might be due to invalid IL or missing references)
		//IL_036c: Expected O, but got Unknown
		//IL_036c: Expected O, but got Unknown
		_window = Pov<RectTransform>("window");
		_shown = Pov<Container>("shown");
		_targetCell = Pov<Cell>("targetCell");
		_slotCells = Pov<List<Cell>>("slotCells");
		_stockCells = Pov<List<Cell>>("stockCells");
		_chosen = Pov<string[]>("chosen");
		_title = Pov<TMP_Text>("title");
		_potentialText = Pov<TMP_Text>("potentialText");
		_actionText = Pov<TMP_Text>("actionText");
		_whyText = Pov<TMP_Text>("whyText");
		_buttonLabel = Pov<TMP_Text>("buttonLabel");
		_upgradeLabel = Pov<TMP_Text>("upgradeLabel");
		_repairLabel = Pov<TMP_Text>("repairLabel");
		_potentialFill = Pov<Image>("potentialFill");
		_potentialCost = Pov<Image>("potentialCost");
		_forge = Pov<Button>("forge");
		_upgrade = Pov<Button>("upgrade");
		_repair = Pov<Button>("repair");
		_forgeTip = Pov<UITooltip>("forgeTip");
		_upgradeTip = Pov<UITooltip>("upgradeTip");
		_repairTip = Pov<UITooltip>("repairTip");
		_costSlots = Pov<GameObject[]>("costSlots");
		_id = OfCell<string>("Id");
		_icon = OfCell<Image>("Icon");
		_number = OfCell<TMP_Text>("Number");
		_tip = OfCell<UITooltip>("Tip");
		_rest = OfCell<Color>("Rest");
		_popColor = OfCell<Color>("PopColor");
		_pop = OfCell<float>("Pop");
		_flying = Pov<List<RectTransform>>("flying");
		_onForge = Call("OnForge");
		_onUpgrade = Call("OnUpgrade");
		_onRepair = Call("OnRepair");
		MethodInfo methodInfo = AccessTools.Method(typeof(RunicAnvilWindow), "Click", new Type[2]
		{
			typeof(Cell),
			typeof(InputButton)
		}, (Type[])null);
		FieldInfo fieldInfo = AccessTools.Field(typeof(CraftView), "_foreign");
		MethodInfo methodInfo2 = AccessTools.Method(typeof(CraftView), "Tick", new Type[2]
		{
			typeof(bool),
			typeof(bool)
		}, (Type[])null);
		if (_missing == null && methodInfo == null)
		{
			_missing = "PoV RunicAnvilWindow.Click";
		}
		if (_missing == null && (fieldInfo == null || methodInfo2 == null))
		{
			_missing = "SeneaL CraftView.Tick / _foreign";
		}
		if (_missing != null)
		{
			return _missing;
		}
		_click = AccessTools.MethodDelegate<Action<Cell, InputButton>>(methodInfo, (object)null, true);
		_foreign = AccessTools.FieldRefAccess<CraftView, bool>(fieldInfo);
		MethodInfo methodInfo3 = AccessTools.Method(typeof(RunicAnvilWindow), "ClickNow", new Type[4]
		{
			typeof(Container),
			typeof(Cell),
			typeof(InputButton),
			typeof(bool)
		}, (Type[])null);
		if (methodInfo3 != null)
		{
			_clickNow = AccessTools.MethodDelegate<Action<Container, Cell, InputButton, bool>>(methodInfo3, (object)null, true);
		}
		harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(AnvilView), "TickPrefix", (Type[])null), new HarmonyMethod(typeof(AnvilView), "TickPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		Active = true;
		return null;
	}

	private static bool Open()
	{
		RectTransform val = _window.Invoke();
		if (Object.op_Implicit((Object)(object)val) && ((Component)val).gameObject.activeSelf)
		{
			return Object.op_Implicit((Object)(object)_shown.Invoke());
		}
		return false;
	}

	private static void TickPrefix(ref bool chestShown)
	{
		if (Active && Open())
		{
			chestShown = false;
		}
	}

	private static void HideChest(bool hide)
	{
		if (hide || _chestHidden)
		{
			_chestHidden = hide;
			CraftPanelWindows.SetChestHidden(hide);
		}
	}

	private static void Raise(RectTransform panel, bool up)
	{
		//IL_001e: 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_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)panel) && (up || _raised))
		{
			if (up && !_raised)
			{
				_fullH = panel.sizeDelta.y;
			}
			_raised = up;
			panel.anchoredPosition = InventoryView.RightAt(1, up ? 32f : TabsView.Below);
			float num = ((up && _page != null && _page._fit > 0f) ? Mathf.Min(_fullH, _page._fit) : _fullH);
			if (num > 0f && Mathf.Abs(panel.sizeDelta.y - num) > 0.5f)
			{
				panel.sizeDelta = new Vector2(panel.sizeDelta.x, num);
			}
		}
	}

	private static void TickPostfix(CraftView __instance)
	{
		Plugin.Guard(ref _broken, "Runic Anvil", delegate
		{
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			RectTransform panel = __instance.Panel;
			bool num = Active && Open() && Object.op_Implicit((Object)(object)_targetCell.Invoke()) && !_foreign.Invoke(__instance) && Object.op_Implicit((Object)(object)panel) && ((Component)panel).gameObject.activeInHierarchy && Object.op_Implicit((Object)(object)Player.m_localPlayer);
			HideChest(num);
			if (!num)
			{
				if (_page != null)
				{
					_page._cover.Release();
				}
				Raise(panel, up: false);
			}
			else
			{
				Raise(panel, up: true);
				if (_page != null && (!_page._cover.Alive || _page._view != __instance || _page._w != panel.sizeDelta.x - 44f))
				{
					_page._cover.Release();
					if (Object.op_Implicit((Object)(object)_page._cover.Root))
					{
						Object.Destroy((Object)(object)((Component)_page._cover.Root).gameObject);
					}
					_page = null;
				}
				if (_page == null)
				{
					_page = new AnvilView(__instance);
				}
				_page.Draw();
			}
		});
		if (_broken && Active)
		{
			Active = false;
			try
			{
				HideChest(hide: false);
				Raise(__instance.Panel, up: false);
				_page?._cover.Release();
			}
			catch (Exception)
			{
			}
			_page = null;
		}
	}

	private AnvilView(CraftView view)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Expected O, but got Unknown
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Expected O, but got Unknown
		//IL_00b3: 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_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0231: Unknown result type (might be due to invalid IL or missing references)
		//IL_023b: Expected O, but got Unknown
		//IL_0250: Unknown result type (might be due to invalid IL or missing references)
		//IL_02be: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0345: Unknown result type (might be due to invalid IL or missing references)
		//IL_0393: Unknown result type (might be due to invalid IL or missing references)
		//IL_0403: Unknown result type (might be due to invalid IL or missing references)
		//IL_042f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0434: Unknown result type (might be due to invalid IL or missing references)
		//IL_043e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0449: Expected O, but got Unknown
		//IL_0449: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_05af: Expected O, but got Unknown
		//IL_05ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_0678: Unknown result type (might be due to invalid IL or missing references)
		//IL_0682: Expected O, but got Unknown
		_view = view;
		_cover = new CraftCover(view.Panel, "povanvil");
		_root = _cover.Root;
		_w = view.Panel.sizeDelta.x - 44f;
		_lock = Icons.Get("lock");
		TextStyle heading = TextStyles.Heading;
		TextStyle legend = TextStyles.Legend;
		TextStyle val = TextStyle.Body(14f, Palette.Linen);
		_heading = Ui.Label((Transform)(object)_root, "title", heading, 0f, 0f, heading.Baseline(1.3f), _w, (TextAlignmentOptions)257);
		_info = Ui.Label((Transform)(object)_root, "info", legend, 0f, 0f, 28f + legend.Baseline(1.3f), _w, (TextAlignmentOptions)257);
		Ui.Img(Ui.TL((Transform)(object)_root, "rule", 0f, 54f, _w, 1f), (Sprite)null, Palette.BrassLine14);
		_target = NewCell((Transform)(object)_root, "target", 64, 44, count: false);
		Put(_target, new Vector2((_w - 64f) * 0.5f, -66f));
		_repairBtn = new GoldButton((Transform)(object)_root, "repair", Mathf.Min(220f, (_w - 64f) * 0.5f - 16f), (Action)delegate
		{
			_onRepair();
		}, 50, true, TextStyles.BtnDarkText);
		_repairBtn.Root.anchoredPosition = new Vector2(0f, -73f);
		BridgeTips.Bind(_repairBtn.Root, () => Hint(_repairHint, _repairTip.Invoke()));
		float num = Mathf.Round(_w * 0.5f);
		_bar = Ui.TL((Transform)(object)_root, "bar", (_w - num) * 0.5f, 140f, num, 8f);
		Ui.Img(_bar, (Sprite)null, Palette.Black60);
		_fill = Ui.TL((Transform)(object)_bar, "fill", 0f, 0f, 0f, 8f);
		Ui.Img(_fill, (Sprite)null, Rune);
		_cost = Ui.TL((Transform)(object)_bar, "cost", 0f, 0f, 0f, 8f);
		Ui.Img(_cost, (Sprite)null, new Color(1f, 0.85f, 0.45f));
		_potential = Ui.Label((Transform)(object)_root, "potential", val, 0f, 0f, 154f + val.Baseline(1.3f), _w, (TextAlignmentOptions)258);
		((Graphic)_potential).color = Rune;
		float num2 = 248f;
		for (int num3 = 0; num3 < _slots.Length; num3++)
		{
			Cell obj = (_slots[num3] = NewCell((Transform)(object)_root, "slot" + num3, 56, 38, count: false));
			obj.Index = num3;
			Put(obj, new Vector2((_w - num2) * 0.5f + (float)num3 * 64f, -184f));
			obj.Own = Ui.Img(Ui.Stretch((Transform)(object)obj.Slot.Root, "own", 0f), Skin.Sliced(24, new BoxStyle(8f, Palette.Clear, Color.white, 1.5f), 0), Rune);
			obj.Own.type = (Type)1;
			((Graphic)obj.Own).raycastTarget = false;
			((Behaviour)obj.Own).enabled = false;
		}
		_action = Ui.Label((Transform)(object)_root, "action", TextStyle.Body(15f, Palette.Linen), 0f, 0f, 267f, _w, (TextAlignmentOptions)258);
		((TMP_Text)_action).overflowMode = (TextOverflowModes)1;
		((TMP_Text)_action).textWrappingMode = (TextWrappingModes)0;
		_why = Ui.Label((Transform)(object)_root, "why", TextStyle.Body(13f, Palette.Ash), 0f, 0f, 291f, _w, (TextAlignmentOptions)258);
		((TMP_Text)_why).overflowMode = (TextOverflowModes)1;
		((TMP_Text)_why).textWrappingMode = (TextWrappingModes)0;
		for (int num4 = 0; num4 < _dustChips.Length; num4++)
		{
			_dustChips[num4] = Chip("dust" + num4);
		}
		float num5 = Mathf.Min(300f, _w);
		_forgeBtn = new GoldButton((Transform)(object)_root, "forge", num5, (Action)delegate
		{
			_onForge();
			_next = 0f;
		}, 50, false, (TextStyle)null);
		_forgeBtn.Root.anchoredPosition = new Vector2((_w - num5) * 0.5f, -350f);
		BridgeTips.Bind(_forgeBtn.Root, () => Hint(_forgeHint, _forgeTip.Invoke()));
		_stockBox = Ui.TL((Transform)(object)_root, "stock", 0f, 416f, _w, 44f);
		for (int num6 = 0; num6 < _upChips.Length; num6++)
		{
			_upChips[num6] = Chip("up" + num6);
		}
		_upgradeBtn = new GoldButton((Transform)(object)_root, "upgrade", num5, (Action)delegate
		{
			_onUpgrade();
			_next = 0f;
		}, 50, true, TextStyles.BtnDarkText);
		BridgeTips.Bind(_upgradeBtn.Root, () => Hint(_upgradeHint, _upgradeTip.Invoke()));
	}

	private ReqChip Chip(string name)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		ReqChip val = new ReqChip((Transform)(object)_root, name, true, false);
		val.Show(false);
		return val;
	}

	private Cell NewCell(Transform parent, string name, int size, int icon, bool count)
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		//IL_0045: 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_0109: 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_011e: Expected O, but got Unknown
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		Cell c = new Cell
		{
			Slot = new Slot(parent, name, 0f, 0f, size, icon, (string)null, false)
		};
		((Graphic)Ui.Img(c.Slot.Root, (Sprite)null, Palette.Clear)).raycastTarget = true;
		UIInputHandler obj = ((Component)c.Slot.Root).gameObject.AddComponent<UIInputHandler>();
		obj.m_onLeftClick = delegate
		{
			Click(c, (InputButton)0);
		};
		obj.m_onRightClick = delegate
		{
			Click(c, (InputButton)1);
		};
		obj.m_onPointerEnter = delegate
		{
			c.Slot.SetHover(true);
		};
		obj.m_onPointerExit = delegate
		{
			c.Slot.SetHover(false);
		};
		BridgeTips.Bind(obj, c.Slot.Root, () => TipOf(c));
		c.Flash = Ui.Img(Ui.Stretch((Transform)(object)c.Slot.Root, "flash", 0f), Skin.Sliced(24, new BoxStyle(8f, Palette.Clear, Color.white, 2f), 0), Palette.Clear);
		c.Flash.type = (Type)1;
		((Graphic)c.Flash).raycastTarget = false;
		if (count)
		{
			TextStyle slotCount = TextStyles.SlotCount;
			c.Count = Ui.LabelBottom((Transform)(object)c.Slot.Root, "cnt", slotCount, 1f, -5f, 3f + slotCount.BaselineFromBottom(1f), (float)size, (TextAlignmentOptions)1028);
			((Graphic)c.Count).raycastTarget = false;
		}
		return c;
	}

	private void Click(Cell c, InputButton button)
	{
		//IL_0085: 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_001f: Invalid comparison between Unknown and I4
		if (!Object.op_Implicit((Object)(object)c.Pov))
		{
			return;
		}
		InventoryGui instance = InventoryGui.instance;
		if (c == _target && (int)button == 1 && _clickNow != null && Object.op_Implicit((Object)(object)instance) && DragItem.Invoke(instance) == null)
		{
			Container box = _shown.Invoke();
			Cell pov = c.Pov;
			Anvil.Do(box, (Action)delegate
			{
				_clickNow(box, pov, (InputButton)0, arg4: true);
			});
		}
		else
		{
			_click(c.Pov, button);
		}
		_next = 0f;
	}

	private static void Put(Cell c, Vector2 at)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		c.At = at;
		c.Slot.Root.anchoredPosition = at;
	}

	private void Animate()
	{
		//IL_023a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0241: Unknown result type (might be due to invalid IL or missing references)
		//IL_0248: Unknown result type (might be due to invalid IL or missing references)
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0269: Unknown result type (might be due to invalid IL or missing references)
		//IL_026e: Unknown result type (might be due to invalid IL or missing references)
		//IL_029b: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		Pop(_target, 0.14f);
		Cell[] slots = _slots;
		for (int i = 0; i < slots.Length; i++)
		{
			Pop(slots[i], 0.18f);
		}
		foreach (Cell item in _stock)
		{
			Pop(item, 0.18f);
		}
		List<RectTransform> obj = _flying.Invoke();
		if (obj.Count == 0)
		{
			_flown.Clear();
		}
		foreach (RectTransform item2 in obj)
		{
			if (Object.op_Implicit((Object)(object)item2) && _flown.Add(((Object)item2).GetInstanceID()))
			{
				Image component = ((Component)item2).GetComponent<Image>();
				Cell cell = (Object.op_Implicit((Object)(object)component) ? Holder(component.sprite) : null);
				if (cell != null)
				{
					Flight flight = new Flight
					{
						Rt = Ui.TL((Transform)(object)_root, "fly", 0f, 0f, 30f, 30f),
						From = Centre(cell),
						To = Centre(_target)
					};
					flight.Rt.pivot = new Vector2(0.5f, 0.5f);
					flight.Img = Ui.Img(flight.Rt, component.sprite, Color.white);
					flight.Img.preserveAspect = true;
					((Graphic)flight.Img).raycastTarget = false;
					_flights.Add(flight);
				}
			}
		}
		for (int num = _flights.Count - 1; num >= 0; num--)
		{
			Flight flight2 = _flights[num];
			flight2.T += Time.unscaledDeltaTime / 0.45f;
			float num2 = Mathf.Min(1f, flight2.T);
			float num3 = 1f - (1f - num2) * (1f - num2);
			if (Object.op_Implicit((Object)(object)flight2.Rt))
			{
				flight2.Rt.anchoredPosition = Vector2.Lerp(flight2.From, flight2.To, num3) + Vector2.up * Mathf.Sin(num3 * (float)Math.PI) * 18f;
				float num4 = Mathf.Lerp(1f, 0.45f, num3);
				((Transform)flight2.Rt).localScale = new Vector3(num4, num4, 1f);
				((Graphic)flight2.Img).color = new Color(1f, 1f, 1f, 1f - num3 * num3);
			}
			if (!(flight2.T < 1f))
			{
				if (Object.op_Implicit((Object)(object)flight2.Rt))
				{
					Object.Destroy((Object)(object)((Component)flight2.Rt).gameObject);
				}
				_flights.RemoveAt(num);
			}
		}
	}

	private static void Pop(Cell c, float by)
	{
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: 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_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_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		float num = (Object.op_Implicit((Object)(object)c.Pov) ? _pop.Invoke(c.Pov) : 0f);
		if (!(num <= 0f) || c.Popped)
		{
			c.Popped = num > 0f;
			float num2 = 1f + by * Mathf.Sin(num * (float)Math.PI);
			RectTransform root = c.Slot.Root;
			float num3 = root.sizeDelta.x * 0.5f * (num2 - 1f);
			((Transform)root).localScale = new Vector3(num2, num2, 1f);
			root.anchoredPosition = c.At + new Vector2(0f - num3, num3);
			Color color = (c.Popped ? _popColor.Invoke(c.Pov) : Palette.Clear);
			color.a *= num;
			((Graphic)c.Flash).color = color;
		}
	}

	private Cell Holder(Sprite sprite)
	{
		if (!Object.op_Implicit((Object)(object)sprite))
		{
			return null;
		}
		Cell[] slots = _slots;
		foreach (Cell cell in slots)
		{
			Image val = (Object.op_Implicit((Object)(object)cell.Pov) ? _icon.Invoke(cell.Pov) : null);
			if (Object.op_Implicit((Object)(object)val) && ((Behaviour)val).enabled && (Object)(object)val.sprite == (Object)(object)sprite)
			{
				return cell;
			}
		}
		foreach (Cell item in _stock)
		{
			if (Object.op_Implicit((Object)(object)item.Pov))
			{
				ItemData obj = Anvil.Sample(_id.Invoke(item.Pov));
				if ((Object)(object)((obj != null) ? obj.GetIcon() : null) == (Object)(object)sprite)
				{
					return item;
				}
			}
		}
		return null;
	}

	private Vector2 Centre(Cell c)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		RectTransform root = c.Slot.Root;
		RectTransform root2 = _root;
		Rect rect = root.rect;
		Vector2 val = Vector2.op_Implicit(((Transform)root2).InverseTransformPoint(((Transform)root).TransformPoint(Vector2.op_Implicit(((Rect)(ref rect)).center))));
		rect = _root.rect;
		float xMin = ((Rect)(ref rect)).xMin;
		rect = _root.rect;
		return val - new Vector2(xMin, ((Rect)(ref rect)).yMax);
	}

	private Cell Under()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		Canvas componentInParent = ((Component)_root).GetComponentInParent<Canvas>();
		Camera cam = ((!Object.op_Implicit((Object)(object)componentInParent) || (int)componentInParent.renderMode == 0) ? null : componentInParent.worldCamera);
		if (Over(_target, cam))
		{
			return _target;
		}
		Cell[] slots = _slots;
		foreach (Cell cell in slots)
		{
			if (Over(cell, cam))
			{
				return cell;
			}
		}
		foreach (Cell item in _stock)
		{
			if (Over(item, cam))
			{
				return item;
			}
		}
		return null;
	}

	private static bool Over(Cell c, Camera cam)
	{
		//IL_002f: 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)
		if (Object.op_Implicit((Object)(object)c.Pov) && ((Component)c.Slot.Root).gameObject.activeInHierarchy)
		{
			return RectTransformUtility.RectangleContainsScreenPoint(c.Slot.Root, Vector2.op_Implicit(Input.mousePosition), cam);
		}
		return false;
	}

	private void Drop()
	{
		if (Input.GetMouseButtonDown(0))
		{
			_pressedOnCell = Under() != null;
		}
		if (!Input.GetMouseButtonUp(0) || _pressedOnCell)
		{
			return;
		}
		InventoryGui instance = InventoryGui.instance;
		if (Object.op_Implicit((Object)(object)instance) && DragItem.Invoke(instance) != null)
		{
			Cell cell = Under();
			if (cell != null)
			{
				Click(cell, (InputButton)0);
			}
		}
	}

	private ItemData ItemOf(Cell c)
	{
		if (c == _target)
		{
			return Anvil.Target(_shown.Invoke());
		}
		string text = ((c.Index >= 0) ? _chosen.Invoke()[c.Index] : _id.Invoke(c.Pov));
		if (text == null)
		{
			return null;
		}
		return Anvil.Sample(text);
	}

	private Tip TipOf(Cell c)
	{
		if (!Object.op_Implicit((Object)(object)c.Pov))
		{
			return null;
		}
		UITooltip val = _tip.Invoke(c.Pov);
		string text = (Object.op_Implicit((Object)(object)val) ? StatsPage.Clean(val.m_text) : "");
		int num = text.IndexOf('\n');
		ItemData val2 = ItemOf(c);
		if (val2 != null && num < 0)
		{
			Tip val3 = Tips.ForItem(val2, 4, false, 0);
			if (val3.Footer.Count == 0)
			{
				if (c == _target)
				{
					val3.AddKey(Lmb, "Pick up");
					val3.AddKey(Rmb, "To the bag");
				}
				else if (c.Index >= 0)
				{
					val3.AddKey(Lmb, "Take out of the slot");
				}
				else
				{
					if (Defs.IsModifier(_id.Invoke(c.Pov)))
					{
						val3.AddKey(Lmb, "Use in a slot");
					}
					val3.AddKey(Rmb, "To the bag");
				}
			}
			return val3;
		}
		if (text.Length == 0)
		{
			return null;
		}
		if (num >= 0)
		{
			return Tips.Text(c.Tip, text.Substring(0, num), text.Substring(num + 1));
		}
		return Tips.Text(c.Tip, text, "");
	}

	private static string MouseName(string property, string fallback)
	{
		return (AccessTools.Property(typeof(Tips), property)?.GetValue(null) as string) ?? fallback;
	}

	private static Tip Hint(Tip cache, UITooltip from)
	{
		if (!Object.op_Implicit((Object)(object)from))
		{
			return null;
		}
		string text = StatsPage.Clean(from.m_topic);
		string text2 = StatsPage.Clean(from.m_text);
		if (text.Length == 0 && text2.Length == 0)
		{
			return null;
		}
		if (text.Length != 0)
		{
			return Tips.Text(cache, text, text2);
		}
		return Tips.Text(cache, text2, "");
	}

	private void Draw()
	{
		//IL_0011: 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_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: 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_00ca: 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_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Unknown result type (might be due to invalid IL or missing references)
		//IL_0425: Unknown result type (might be due to invalid IL or missing references)
		//IL_043f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02be: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c0: 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_0354: Unknown result type (might be due to invalid IL or missing references)
		//IL_0365: Unknown result type (might be due to invalid IL or missing references)
		_cover.Hold();
		float x = _bar.sizeDelta.x;
		Image val = _potentialFill.Invoke();
		_fill.sizeDelta = new Vector2(Object.op_Implicit((Object)(object)val) ? (x * Mathf.Clamp01(((Graphic)val).rectTransform.anchorMax.x)) : 0f, 8f);
		Image val2 = _potentialCost.Invoke();
		bool flag = Object.op_Implicit((Object)(object)val2) && ((Component)val2).gameObject.activeSelf;
		if (((Component)_cost).gameObject.activeSelf != flag)
		{
			((Component)_cost).gameObject.SetActive(flag);
		}
		if (flag)
		{
			float num = Mathf.Clamp01(((Graphic)val2).rectTransform.anchorMin.x);
			float num2 = Mathf.Clamp01(((Graphic)val2).rectTransform.anchorMax.x);
			_cost.anchoredPosition = new Vector2(x * num, 0f);
			_cost.sizeDelta = new Vector2(x * Mathf.Max(0f, num2 - num), 8f);
		}
		Drop();
		Animate();
		float y = _root.sizeDelta.y;
		if (y != _h)
		{
			_h = y;
			_next = 0f;
		}
		if (Time.unscaledTime < _next)
		{
			return;
		}
		_next = Time.unscaledTime + 0.1f;
		Container val3 = _shown.Invoke();
		((TMP_Text)_heading).text = L.Id("piece.runicanvil.name", "Runic Anvil");
		BookView.Copy(_info, _title.Invoke());
		BookView.Copy(_potential, _potentialText.Invoke());
		BookView.Copy(_action, _actionText.Invoke());
		TMP_Text val4 = _whyText.Invoke();
		BookView.Copy(_why, val4);
		if (Object.op_Implicit((Object)(object)val4))
		{
			((Graphic)_why).color = ((Graphic)val4).color;
		}
		_target.Pov = _targetCell.Invoke();
		ItemData val5 = Anvil.Target(val3);
		if (val5 != null)
		{
			_target.Slot.Set(val5);
		}
		else
		{
			_target.Slot.Clear();
		}
		List<Cell> list = _slotCells.Invoke();
		for (int i = 0; i < _slots.Length; i++)
		{
			Cell cell = _slots[i];
			cell.Pov = ((i < list.Count) ? list[i] : null);
			if (Object.op_Implicit((Object)(object)cell.Pov))
			{
				Color val6 = _rest.Invoke(cell.Pov);
				bool flag2 = val6.a > 0.5f && val6.r < 0.4f;
				Image val7 = _icon.Invoke(cell.Pov);
				if (!flag2 && Object.op_Implicit((Object)(object)val7) && ((Behaviour)val7).enabled && Object.op_Implicit((Object)(object)val7.sprite))
				{
					cell.Slot.SetIcon(val7.sprite, false);
				}
				else
				{
					cell.Slot.Clear();
				}
				cell.Slot.Ghost(flag2 ? _lock : null, 22f, Palette.Ash);
				((Behaviour)cell.Own).enabled = val6.a > 0.5f && !flag2;
			}
		}
		Stock();
		Costs(val3);
		BookView.Mirror(_forgeBtn, _forge.Invoke(), _buttonLabel.Invoke(), show: true);
		BookView.Mirror(_repairBtn, _repair.Invoke(), _repairLabel.Invoke(), show: true);
		BookView.Mirror(_upgradeBtn, _upgrade.Invoke(), _upgradeLabel.Invoke(), show: true);
		_upgradeBtn.Root.anchoredPosition = new Vector2((_w - _upgradeBtn.Root.sizeDelta.x) * 0.5f, 0f - (y - 50f));
		_fit = 416f + _stockH + (((Component)_upgradeBtn.Root).gameObject.activeSelf ? 116f : 4f) + 40f;
	}

	private void Stock()
	{
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		List<Cell> list = _stockCells.Invoke();
		while (_stock.Count < list.Count)
		{
			_stock.Add(NewCell((Transform)(object)_stockBox, "s" + _stock.Count, 44, 30, count: true));
		}
		if (_placed != list.Count)
		{
			_placed = list.Count;
			Place(list);
		}
		for (int i = 0; i < _stock.Count; i++)
		{
			Cell cell = _stock[i];
			cell.Pov = ((i < list.Count) ? list[i] : null);
			if (((Component)cell.Slot.Root).gameObject.activeSelf != Object.op_Implicit((Object)(object)cell.Pov))
			{
				((Component)cell.Slot.Root).gameObject.SetActive(Object.op_Implicit((Object)(object)cell.Pov));
			}
			if (Object.op_Implicit((Object)(object)cell.Pov))
			{
				ItemData val = Anvil.Sample(_id.Invoke(cell.Pov));
				if (val != null)
				{
					cell.Slot.SetIcon(val.GetIcon(), false);
				}
				else
				{
					cell.Slot.Clear();
				}
				Image val2 = _icon.Invoke(cell.Pov);
				if (Object.op_Implicit((Object)(object)val2))
				{
					cell.Slot.SetTint(((Graphic)val2).color);
				}
				TMP_Text val3 = _number.Invoke(cell.Pov);
				string text = (Object.op_Implicit((Object)(object)val3) ? val3.text : "");
				if (((TMP_Text)cell.Count).text != text)
				{
					((TMP_Text)cell.Count).text = text;
				}
				if (Object.op_Implicit((Object)(object)val3))
				{
					((Graphic)cell.Count).color = ((Graphic)val3).color;
				}
			}
		}
	}

	private void Place(List<Cell> stock)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: 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_008a: 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_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: 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_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		float num = 0f;
		float num2 = 0f;
		float num3 = 0f;
		float num4 = 0f;
		int num5 = 1;
		int num6 = 0;
		for (int i = 0; i < stock.Count; i++)
		{
			Vector2 anchoredPosition = ((RectTransform)((Component)stock[i]).transform).anchoredPosition;
			if (i == 0)
			{
				num = anchoredPosition.y;
			}
			if (i > 0 && Mathf.Abs(anchoredPosition.y - num2) < 0.5f)
			{
				num6++;
				if (num4 <= 0f)
				{
					num4 = anchoredPosition.x - num3;
				}
			}
			else
			{
				num6 = 1;
			}
			num5 = Mathf.Max(num5, num6);
			num2 = anchoredPosition.y;
			num3 = anchoredPosition.x;
		}
		float num7 = Mathf.Min(50f, Mathf.Floor(_w / (float)num5));
		float num8 = ((num4 > 0f) ? (num7 / num4) : 1f);
		_stockH = 44f;
		for (int j = 0; j < stock.Count; j++)
		{
			Vector2 anchoredPosition2 = ((RectTransform)((Component)stock[j]).transform).anchoredPosition;
			_stockH = Mathf.Max(_stockH, Mathf.Round((num - anchoredPosition2.y) * num8) + 44f);
			Put(_stock[j], new Vector2(Mathf.Round(_w * 0.5f + anchoredPosition2.x * num8 - 22f), 0f - Mathf.Round((num - anchoredPosition2.y) * num8)));
		}
	}

	private void Costs(Container box)
	{
		GameObject[] array = _costSlots.Invoke();
		for (int i = 0; i < _dustChips.Length; i++)
		{
			GameObject val = ((array != null && i < array.Length) ? array[i] : null);
			ItemData val2 = ((Object.op_Implicit((Object)(object)val) && val.activeSelf) ? Anvil.Sample(Dust[i]) : null);
			Transform val3 = ((val2 != null) ? val.transform.Find("res_amount") : null);
			UITooltip val4 = ((val2 != null) ? val.GetComponent<UITooltip>() : null);
			if (Object.op_Implicit((Object)(object)val3))
			{
				TMP_Text component = ((Component)val3).GetComponent<TMP_Text>();
				if (int.TryParse((component != null) ? component.text : null, out var result))
				{
					string obj = (Object.op_Implicit((Object)(object)val4) ? val4.m_text : "");
					if (!long.TryParse(obj.Substring(obj.LastIndexOf(' ') + 1), out var result2))
					{
						result2 = result;
					}
					Fill(_dustChips[i], val2, result, result2);
					continue;
				}
			}
			_dustChips[i].Show(false);
		}
		Row(_dustChips, 306f);
		List<(string, int, long)> list = ((Object.op_Implicit((Object)(object)_upgrade.Invoke()) && ((Component)_upgrade.Invoke()).gameObject.activeSelf) ? Anvil.UpgradeCost(box) : null);
		for (int j = 0; j < _upChips.Length; j++)
		{
			ItemData val5 = ((list != null && j < list.Count) ? Anvil.Sample(list[j].Item1) : null);
			if (val5 == null)
			{
				_upChips[j].Show(false);
			}
			else
			{
				Fill(_upChips[j], val5, list[j].Item2, list[j].Item3);
			}
		}
		Row(_upChips, _h - 50f - 10f - 36f);
	}

	private static void Fill(ReqChip chip, ItemData sample, int need, long have)
	{
		chip.Fill(sample.GetIcon(), sample.m_shared.m_name, need, (int)Math.Min(have, 2147483647L), have >= need, false, Loc.Have, 0);
	}

	private void Row(ReqChip[] chips, float top)
	{
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		float num = -8f;
		ReqChip[] array = chips;
		foreach (ReqChip val in array)
		{
			if (((Component)val.Root).gameObject.activeSelf)
			{
				num += val.Width + 8f;
			}
		}
		float num2 = Mathf.Round((_w - num) * 0.5f);
		array = chips;
		foreach (ReqChip val2 in array)
		{
			if (((Component)val2.Root).gameObject.activeSelf)
			{
				val2.Root.anchoredPosition = new Vector2(num2, 0f - top);
				num2 += val2.Width + 8f;
			}
		}
	}
}
internal static class BallistaInfo
{
	private const string BallistaPrefab = "PT_Ballista";

	private static readonly FieldRef<BuildInfoView, TextMeshProUGUI> Desc = AccessTools.FieldRefAccess<BuildInfoView, TextMeshProUGUI>("_desc");

	private static readonly FieldRef<BuildInfoView, Piece> Shown = AccessTools.FieldRefAccess<BuildInfoView, Piece>("_piece");

	private static readonly FieldRef<BuildInfoView, float> DescH = AccessTools.FieldRefAccess<BuildInfoView, float>("_descH");

	private static string _line;

	private static bool _broken;

	internal static string Patch(Harmony harmony)
	{
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Expected O, but got Unknown
		MethodInfo methodInfo = AccessTools.Method(typeof(BuildInfoView), "Tick", new Type[1] { typeof(Player) }, (Type[])null);
		if (methodInfo == null)
		{
			return "SeneaL BuildInfoView.Tick";
		}
		if (!Pov.Has("ballistas"))
		{
			return "PoV ballistas feature";
		}
		harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(BallistaInfo), "TickPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		return null;
	}

	private static void TickPostfix(BuildInfoView __instance)
	{
		Plugin.Guard(ref _broken, "Ballista count", delegate
		{
			Piece val = Shown.Invoke(__instance);
			TextMeshProUGUI val2 = Desc.Invoke(__instance);
			if (Object.op_Implicit((Object)(object)val2))
			{
				string text = ((TMP_Text)val2).text;
				if (_line != null && text.EndsWith(_line))
				{
					text = text.Substring(0, text.Length - _line.Length);
				}
				_line = null;
				if (Object.op_Implicit((Object)(object)val) && ((Object)val).name.StartsWith("PT_Ballista"))
				{
					_line = ((text.Length > 0) ? "\n" : "") + "<color=#E0B53F>" + string.Format(Texts.Get("ballista.menu.limit", "Ballistas {0}/{1}"), Ballistas.Count, Ballistas.Limit) + "</color>";
					text += _line;
				}
				if (text != ((TMP_Text)val2).text)
				{
					((TMP_Text)val2).text = text;
					DescH.Invoke(__instance) = -1f;
				}
			}
		});
	}
}
internal sealed class BookView
{
	private sealed class Square
	{
		public RectTransform Root;

		public Image Frame;

		public Image Icon;

		public CanvasGroup Group;

		public Cell Pov;
	}

	private const float SummaryH = 44f;

	private const float DetailH = 118f;

	private const float ButtonsH = 62f;

	private const float Top = 64f;

	private const TextAlignmentOptions Left = (TextAlignmentOptions)257;

	private const TextAlignmentOptions Mid = (TextAlignmentOptions)258;

	private static FieldRef<RectTransform> _boardArea;

	private static FieldRef<RectTransform> _mapArea;

	private static FieldRef<RectTransform> _planArea;

	private static FieldRef<TMP_Text> _info;

	private static FieldRef<TMP_Text> _summary;

	private static FieldRef<TMP_Text> _detailTitle;

	private static FieldRef<TMP_Text> _detailBody;

	private static FieldRef<TMP_Text> _hint;

	private static FieldRef<TMP_Text> _mapText;

	private static FieldRef<TMP_Text> _status;

	private static FieldRef<TMP_Text> _packLabel;

	private static FieldRef<TMP_Text> _newLabel;

	private static FieldRef<TMP_Text> _launchLabel;

	private static FieldRef<Button> _pack;

	private static FieldRef<Button> _newBoard;

	private static FieldRef<Button> _launch;

	private static FieldRef<Button> _fresh;

	private static FieldRef<Cell> _mapCell;

	private static FieldRef<List<Cell>> _cells;

	private static FieldRef<List<Image>> _links;

	private static FieldRef<List<Image>> _plan;

	private static FieldRef<(int, int)> _hover;

	private static FieldRef<int> _seen;

	private static FieldRef<float> _cs;

	private static FieldRef<Cell, int> _c;

	private static FieldRef<Cell, int> _r;

	private static FieldRef<Cell, Image> _icon;

	private static FieldRef<Cell, Image> _frame;

	private static Action<Cell, InputButton> _click;

	private static Action _askPack;

	private static Action _askNewBoard;

	private static Action _askLaunch;

	private static FieldRef<CraftView, bool> _foreign;

	private static FieldRef<InventoryGui, ItemData> _dragItem;

	private static string _missing;

	private static bool _broken;

	private static BookView _page;

	private readonly CraftView _view;

	private readonly CraftCover _cover;

	private readonly RectTransform _root;

	private readonly RectTransform _board;

	private readonly RectTransform _linkLayer;

	private readonly RectTransform _detail;

	private readonly RectTransform _map;

	private readonly RectTransform _planBox;

	private readonly float _w;

	private readonly TextMeshProUGUI _title;

	private readonly TextMeshProUGUI _infoText;

	private readonly TextMeshProUGUI _summaryText;

	private readonly TextMeshProUGUI _detailName;

	private readonly TextMeshProUGUI _detailText;

	private readonly TextMeshProUGUI _mapLines;

	private readonly TextMeshProUGUI _hintText;

	private readonly TextMeshProUGUI _statusText;

	private readonly GoldButton _packBtn;

	private readonly GoldButton _newBtn;

	private readonly GoldButton _launchBtn;

	private readonly GoldButton _freshBtn;

	private readonly Square _mapSquare;

	private readonly Sprite _slotBg;

	private readonly List<Square> _squares = new List<Square>();

	private readonly List<Image> _linkImgs = new List<Image>();

	private readonly List<Image> _planImgs = new List<Image>();

	private float _h;

	private float _next;

	private float _side;

	internal static bool Active { get; private set; }

	private static FieldRef<T> Pov<T>(string name)
	{
		FieldInfo fieldInfo = AccessTools.Field(typeof(HallMapWindow), name);
		if (fieldInfo == null || fieldInfo.FieldType != typeof(T))
		{
			_missing = _missing ?? ("PoV HallMapWindow." + name);
			return null;
		}
		return AccessTools.StaticFieldRefAccess<T>(fieldInfo);
	}

	private static FieldRef<Cell, T> OfCell<T>(string name)
	{
		FieldInfo fieldInfo = AccessTools.Field(typeof(Cell), name);
		if (fieldInfo == null || fieldInfo.FieldType != typeof(T))
		{
			_missing = _missing ?? ("PoV HallMapWindow.Cell." + name);
			return null;
		}
		return AccessTools.FieldRefAccess<Cell, T>(fieldInfo);
	}

	private static Action Call(string name)
	{
		MethodInfo methodInfo = AccessTools.Method(typeof(HallMapWindow), name, Type.EmptyTypes, (Type[])null);
		if (methodInfo == null)
		{
			_missing = _missing ?? ("PoV HallMapWindow." + name);
			return null;
		}
		return AccessTools.MethodDelegate<Action>(methodInfo, (object)null, true);
	}

	internal static string Patch(Harmony harmony)
	{
		//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e3: Expected O, but got Unknown
		_boardArea = Pov<RectTransform>("boardArea");
		_mapArea = Pov<RectTransform>("mapArea");
		_planArea = Pov<RectTransform>("planArea");
		_info = Pov<TMP_Text>("info");
		_summary = Pov<TMP_Text>("summary");
		_detailTitle = Pov<TMP_Text>("detailTitle");
		_detailBody = Pov<TMP_Text>("detailBody");
		_hint = Pov<TMP_Text>("hint");
		_mapText = Pov<TMP_Text>("mapText");
		_status = Pov<TMP_Text>("status");
		_packLabel = Pov<TMP_Text>("packLabel");
		_newLabel = Pov<TMP_Text>("newLabel");
		_launchLabel = Pov<TMP_Text>("launchLabel");
		_pack = Pov<Button>("pack");
		_newBoard = Pov<Button>("newBoard");
		_launch = Pov<Button>("launch");
		_fresh = Pov<Button>("fresh");
		_mapCell = Pov<Cell>("mapCell");
		_cells = Pov<List<Cell>>("cells");
		_links = Pov<List<Image>>("links");
		_plan = Pov<List<Image>>("plan");
		_hover = Pov<(int, int)>("hover");
		_seen = Pov<int>("seen");
		_cs = Pov<float>("cs");
		_c = OfCell<int>("C");
		_r = OfCell<int>("R");
		_icon = OfCell<Image>("Icon");
		_frame = OfCell<Image>("Frame");
		_askPack = Call("AskPack");
		_askNewBoard = Call("AskNewBoard");
		_askLaunch = Call("AskLaunch");
		MethodInfo methodInfo = AccessTools.Method(typeof(HallMapWindow), "Click", new Type[2]
		{
			typeof(Cell),
			typeof(InputButton)
		}, (Type[])null);
		FieldInfo fieldInfo = AccessTools.Field(typeof(CraftView), "_foreign");
		MethodInfo methodInfo2 = AccessTools.Method(typeof(CraftView), "Tick", new Type[2]
		{
			typeof(bool),
			typeof(bool)
		}, (Type[])null);
		if (_missing == null && methodInfo == null)
		{
			_missing = "PoV HallMapWindow.Click";
		}
		if (_missing == null && (fieldInfo == null || methodInfo2 == null))
		{
			_missing = "SeneaL CraftView.Tick / _foreign";
		}
		if (_missing != null)
		{
			return _missing;
		}
		_click = AccessTools.MethodDelegate<Action<Cell, InputButton>>(methodInfo, (object)null, true);
		_foreign = AccessTools.FieldRefAccess<CraftView, bool>(fieldInfo);
		_dragItem = AccessTools.FieldRefAccess<InventoryGui, ItemData>("m_dragItem");
		harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(BookView), "TickPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		Active = true;
		return null;
	}

	private static void TickPostfix(CraftView __instance)
	{
		Plugin.Guard(ref _broken, "Book of the Halls", delegate
		{
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			RectTransform panel = __instance.Panel;
			if (!HallMapWindow.IsOpen || !Object.op_Implicit((Object)(object)_boardArea.Invoke()) || !Object.op_Implicit((Object)(object)_mapArea.Invoke()) || _foreign.Invoke(__instance) || !Object.op_Implicit((Object)(object)panel) || !((Component)panel).gameObject.activeInHierarchy || !Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				if (_page != null)
				{
					_page._cover.Release();
				}
			}
			else
			{
				if (_page != null && (!_page._cover.Alive || _page._view != __instance || _page._w != panel.sizeDelta.x - 44f))
				{
					_page._cover.Release();
					if (Object.op_Implicit((Object)(object)_page._cover.Root))
					{
						Object.Destroy((Object)(object)((Component)_page._cover.Root).gameObject);
					}
					_page = null;
				}
				if (_page == null)
				{
					_page = new BookView(__instance);
				}
				_page.Draw();
			}
		});
		if (_broken)
		{
			Active = false;
			try
			{
				_page?._cover.Release();
			}
			catch (Exception)
			{
			}
			_page = null;
		}
	}

	private BookView(CraftView view)
	{
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: 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_020e: Unknown result type (might be due to invalid IL or missing references)
		//IL_028a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_031b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0325: Expected O, but got Unknown
		//IL_0359: Unknown result type (might be due to invalid IL or missing references)
		//IL_0363: Expected O, but got Unknown
		//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0456: Unknown result type (might be due to invalid IL or missing references)
		//IL_0471: Unknown result type (might be due to invalid IL or missing references)
		//IL_04fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0505: Expected O, but got Unknown
		//IL_0544: Unknown result type (might be due to invalid IL or missing references)
		//IL_054e: Expected O, but got Unknown
		_view = view;
		_cover = new CraftCover(view.Panel, "povbook");
		_root = _cover.Root;
		_w = view.Panel.sizeDelta.x - 44f;
		_slotBg = Skin.Sliced(48, Styles.SlotHas, -1);
		TextStyle heading = TextStyles.Heading;
		TextStyle legend = TextStyles.Legend;
		TextStyle style = TextStyle.Body(14f, Palette.Linen);
		_title = Ui.Label((Transform)(object)_root, "title", heading, 0f, 0f, heading.Baseline(1.3f), _w, (TextAlignmentOptions)257);
		_infoText = Ui.Label((Transform)(object)_root, "info", legend, 0f, 0f, 28f + legend.Baseline(1.3f), _w, (TextAlignmentOptions)257);
		((Graphic)_infoText).color = Palette.Gold;
		Ui.Img(Ui.TL((Transform)(object)_root, "rule", 0f, 54f, _w, 1f), (Sprite)null, Palette.BrassLine14);
		_board = Ui.TL((Transform)(object)_root, "board", 0f, 64f, 100f, 100f);
		_linkLayer = Ui.Stretch((Transform)(object)_board, "links", 0f);
		_summaryText = Wrapped((Transform)(object)_root, "summary", style, _w, 44f, (TextAlignmentOptions)258);
		_detail = Ui.TL((Transform)(object)_root, "detail", 0f, 0f, _w, 118f);
		Ui.Img(Ui.Stretch((Transform)(object)_detail, "bg", 0f), Skin.Sliced(40, Styles.RowHover, -1), Color.white).type = (Type)1;
		_detailName = Ui.Label((Transform)(object)_detail, "n", heading, 0f, 12f, 8f + heading.Baseline(1.3f), _w - 24f, (TextAlignmentOptions)257);
		((TMP_Text)_detailName).overflowMode = (TextOverflowModes)1;
		((TMP_Text)_detailName).textWrappingMode = (TextWrappingModes)0;
		_detailText = Wrapped((Transform)(object)_detail, "t", TextStyle.Body(13f, Palette.Linen), _w - 24f, 74f, (TextAlignmentOptions)257);
		((TMP_Text)_detailText).rectTransform.anchoredPosition = new Vector2(12f, -38f);
		float num = Mathf.Floor((_w - 12f) * 0.5f);
		_packBtn = new GoldButton((Transform)(object)_root, "pack", num, (Action)delegate
		{
			_askPack();
		}, 50, false, (TextStyle)null);
		_newBtn = new GoldButton((Transform)(object)_root, "new", num, (Action)delegate
		{
			_askNewBoard();
		}, 50, true, TextStyles.BtnDarkText);
		_map = Ui.TL((Transform)(object)_root, "map", 0f, 64f, _w, 100f);
		_mapSquare = NewSquare((Transform)(object)_map, "mapcell");
		_mapSquare.Root.anchoredPosition = new Vector2((_w - 96f) * 0.5f, -8f);
		_mapSquare.Root.sizeDelta = new Vector2(96f, 96f);
		_planBox = Ui.TR((Transform)(object)_map, "plan", 0f, 8f, 140f, 140f);
		_mapLines = Wrapped((Transform)(object)_map, "lines", style, _w, 240f, (TextAlignmentOptions)258);
		((TMP_Text)_mapLines).rectTransform.anchoredPosition = new Vector2(0f, -160f);
		_hintText = Wrapped((Transform)(object)_map, "hint", TextStyle.Body(14f, Palette.Gold), _w, 44f, (TextAlignmentOptions)258);
		_statusText = Wrapped((Transform)(object)_map, "status", style, _w, 64f, (TextAlignmentOptions)258);
		_launchBtn = new GoldButton((Transform)(object)_map, "launch", Mathf.Min(320f, _w), (Action)delegate
		{
			_askLaunch();
		}, 50, false, (TextStyle)null);
		_freshBtn = new GoldButton((Transform)(object)_map, "fresh", Mathf.Min(320f, _w), (Action)delegate
		{
			_askNewBoard();
		}, 50, false, (TextStyle)null);
	}

	private static TextMeshProUGUI Wrapped(Transform parent, string name, TextStyle style, float w, float h, TextAlignmentOptions align)
	{
		//IL_0019: 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)
		TextMeshProUGUI obj = Ui.Label(parent, name, style, 0f, 0f, style.Baseline(1.3f), w, align);
		((TMP_Text)obj).textWrappingMode = (TextWrappingModes)1;
		((TMP_Text)obj).overflowMode = (TextOverflowModes)1;
		((TMP_Text)obj).rectTransform.sizeDelta = new Vector2(w, h);
		return obj;
	}

	private Square NewSquare(Transform parent, string name)
	{
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		Square s = new Square
		{
			Root = Ui.TL(parent, name, 0f, 0f, 64f, 64f)
		};
		s.Frame = Ui.Img(s.Root, (Sprite)null, Palette.Clear);
		((Graphic)s.Frame).raycastTarget = true;
		Ui.Skinned(Ui.Stretch((Transform)(object)s.Root, "cell", -3f), _slotBg, Styles.SlotHas.Pad, true);
		s.Icon = Ui.Img(Ui.Stretch((Transform)(object)s.Root, "icon", -3f), (Sprite)null, Color.white);
		s.Icon.preserveAspect = true;
		s.Group = ((Component)s.Root).gameObject.AddComponent<CanvasGroup>();
		UIInputHandler obj = ((Component)s.Root).gameObject.AddComponent<UIInputHandler>();
		obj.m_onLeftClick = delegate
		{
			Click(s, (InputButton)0);
		};
		obj.m_onRightClick = delegate
		{
			Click(s, (InputButton)1);
		};
		obj.m_onPointerEnter = delegate
		{
			Hover(s, on: true);
		};
		obj.m_onPointerExit = delegate
		{
			Hover(s, on: false);
		};
		return s;
	}

	private void Click(Square s, InputButton button)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)s.Pov))
		{
			_click(s.Pov, button);
			_next = 0f;
		}
	}

	private void Hover(Square s, bool on)
	{
		if (!Object.op_Implicit((Object)(object)s.Pov) || s == _mapSquare)
		{
			return;
		}
		(int, int) tuple = (_c.Invoke(s.Pov), _r.Invoke(s.Pov));
		if (on)
		{
			_hover.Invoke() = tuple;
		}
		else
		{
			if (!_hover.Invoke().Equals(tuple))
			{
				return;
			}
			_hover.Invoke() = (-1, -1);
		}
		_seen.Invoke() = -1;
		_next = 0f;
	}

	internal static void Copy(TextMeshProUGUI to, TMP_Text from)
	{
		string text = (Object.op_Implicit((Object)(object)from) ? StatsPage.Clean(from.text) : "");
		if (((TMP_Text)to).text != text)
		{
			((TMP_Text)to).text = text;
		}
	}

	internal static void Mirror(GoldButton to, Button from, TMP_Text label, bool show)
	{
		show = show && Object.op_Implicit((Object)(object)from) && ((Component)from).gameObject.activeSelf;
		if (((Component)to.Root).gameObject.activeSelf != show)
		{
			((Component)to.Root).gameObject.SetActive(show);
		}
		if (show)
		{
			to.SetEnabled(((Selectable)from).interactable);
			TMP_Text val = (Object.op_Implicit((Object)(object)label) ? label : ((Component)from).GetComponentInChildren<TMP_Text>());
			if (Object.op_Implicit((Object)(object)val))
			{
				to.SetLabel(StatsPage.Clean(val.text));
			}
		}
	}

	private void Draw()
	{
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		_cover.Hold();
		InventoryGui instance = InventoryGui.instance;
		if (Input.GetMouseButtonUp(0) && Object.op_Implicit((Object)(object)instance) && _dragItem.Invoke(instance) != null && ((Component)_board).gameObject.activeSelf)
		{
			Canvas componentInParent = ((Component)_root).GetComponentInParent<Canvas>();
			Camera val = ((!Object.op_Implicit((Object)(object)componentInParent) || (int)componentInParent.renderMode == 0) ? null : componentInParent.worldCamera);
			foreach (Square square in _squares)
			{
				if (((Component)square.Root).gameObject.activeSelf && RectTransformUtility.RectangleContainsScreenPoint(square.Root, Vector2.op_Implicit(Input.mousePosition), val))
				{
					Click(square, (InputButton)0);
					break;
				}
			}
		}
		float y = _root.sizeDelta.y;
		if (y != _h)
		{
			_h = y;
			_next = 0f;
		}
		if (!(Time.unscaledTime < _next))
		{
			_next = Time.unscaledTime + 0.1f;
			((TMP_Text)_title).text = L.Id("enc.hmap.book", "Book of the Halls");
			Copy(_infoText, _info.Invoke());
			bool activeSelf = ((Component)_boardArea.Invoke()).gameObject.activeSelf;
			if (((Component)_board).gameObject.activeSelf != activeSelf)
			{
				((Component)_board).gameObject.SetActive(activeSelf);
				((Component)_summaryText).gameObject.SetActive(activeSelf);
				((Component)_detail).gameObject.SetActive(activeSelf);
			}
			if (((Component)_map).gameObject.activeSelf == activeSelf)
			{
				((Component)_map).gameObject.SetActive(!activeSelf);
			}
			Mirror(_packBtn, _pack.Invoke(), _packLabel.Invoke(), activeSelf);
			Mirror(_newBtn, _newBoard.Invoke(), _newLabel.Invoke(), activeSelf);
			if (activeSelf)
			{
				Board(y);
			}
			else
			{
				Map(y);
			}
		}
	}

	private void Board(float h)
	{
		//IL_00d5: 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_02d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0309: Unknown result type (might be due to invalid IL or missing references)
		//IL_0374: Unknown result type (might be due to invalid IL or missing references)
		//IL_0394: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: 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)
		List<Cell> list = _cells.Invoke();
		int num = 1;
		int num2 = 1;
		foreach (Cell item in list)
		{
			num = Mathf.Max(num, _c.Invoke(item) + 1);
			num2 = Mathf.Max(num2, _r.Invoke(item) + 1);
		}
		float num3 = h - 64f - 8f - 44f - 6f - 118f - 10f - 62f;
		float num4 = Mathf.Floor(Mathf.Min(_w / (float)num, num3 / (float)num2));
		float num5 = num4 * (float)num;
		float num6 = num4 * (float)num2;
		_board.anchoredPosition = new Vector2((_w - num5) * 0.5f, -64f);
		_board.sizeDelta = new Vector2(num5, num6);
		_side = num4;
		for (int i = 0; i < list.Count; i++)
		{
			if (i == _squares.Count)
			{
				_squares.Add(NewSquare((Transform)(object)_board, "c" + i));
			}
			Square square = _squares[i];
			Cell val = (square.Pov = list[i]);
			bool flag = Object.op_Implicit((Object)(object)val) && ((Component)val).gameObject.activeSelf;
			if (((Component)square.Root).gameObject.activeSelf != flag)
			{
				((Component)square.Root).gameObject.SetActive(flag);
			}
			if (flag)
			{
				float num7 = Mathf.Round(num4 * 0.07f);
				square.Root.anchoredPosition = new Vector2((float)_c.Invoke(val) * num4 + num7, 0f - ((float)(num2 - 1 - _r.Invoke(val)) * num4 + num7));
				square.Root.sizeDelta = new Vector2(num4 - num7 * 2f, num4 - num7 * 2f);
				Paint(square, val);
			}
		}
		for (int j = list.Count; j < _squares.Count; j++)
		{
			((Component)_squares[j].Root).gameObject.SetActive(false);
		}
		((Transform)_linkLayer).SetAsLastSibling();
		Images(_links.Invoke(), _linkImgs, _linkLayer, num4 / Mathf.Max(1f, _cs.Invoke()), centred: true);
		float num8 = 64f + num6 + 8f;
		((TMP_Text)_summaryText).rectTransform.anchoredPosition = new Vector2(0f, 0f - num8);
		Copy(_summaryText, _summary.Invoke());
		num8 += 50f;
		_detail.anchoredPosition = new Vector2(0f, 0f - num8);
		Copy(_detailName, _detailTitle.Invoke());
		Copy(_detailText, _detailBody.Invoke());
		num8 = h - 50f;
		float num9 = Mathf.Floor((_w - 12f) * 0.5f);
		_packBtn.Root.anchoredPosition = new Vector2(0f, 0f - num8);
		_newBtn.Root.anchoredPosition = new Vector2(num9 + 12f, 0f - num8);
	}

	private static void Paint(Square s, Cell pov)
	{
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		Image val = _icon.Invoke(pov);
		bool flag = Object.op_Implicit((Object)(object)val) && ((Behaviour)val).enabled && Object.op_Implicit((Object)(object)val.sprite);
		if (((Behaviour)s.Icon).enabled != flag)
		{
			((Behaviour)s.Icon).enabled = flag;
		}
		if (flag)
		{
			s.Icon.sprite = val.sprite;
			((Graphic)s.Icon).color = ((Graphic)val).color;
		}
		Image val2 = _frame.Invoke(pov);
		((Graphic)s.Frame).color = (Object.op_Implicit((Object)(object)val2) ? ((Graphic)val2).color : Palette.Clear);
		CanvasGroup component = ((Component)pov).GetComponent<CanvasGroup>();
		s.Group.alpha = (Object.op_Implicit((Object)(object)component) ? Mathf.Max(component.alpha, 0.18f) : 1f);
	}

	private static void Images(List<Image> from, List<Image> to, RectTransform parent, float scale, bool centred)
	{
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: 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_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: 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)
		//IL_00f2: 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)
		int num = 0;
		foreach (Image item2 in from)
		{
			if (Object.op_Implicit((Object)(object)item2) && ((Component)item2).gameObject.activeSelf)
			{
				if (num == to.Count)
				{
					Image item = Ui.Img(Ui.TL((Transform)(object)parent, "i" + num, 0f, 0f, 1f, 1f), (Sprite)null, Color.white);
					to.Add(item);
				}
				Image val = to[num++];
				if (!((Component)val).gameObject.activeSelf)
				{
					((Component)val).gameObject.SetActive(true);
				}
				RectTransform rectTransform = ((Graphic)item2).rectTransform;
				RectTransform rectTransform2 = ((Graphic)val).rectTransform;
				rectTransform2.pivot = (centred ? new Vector2(0.5f, 0.5f) : new Vector2(0f, 1f));
				rectTransform2.anchoredPosition = rectTransform.anchoredPosition * scale;
				rectTransform2.sizeDelta = rectTransform.sizeDelta * scale;
				((Graphic)val).color = ((Graphic)item2).color;
			}
		}
		for (int i = num; i < to.Count; i++)
		{
			if (((Component)to[i]).gameObject.activeSelf)
			{
				((Component)to[i]).gameObject.SetActive(false);
			}
		}
	}

	private void Map(float h)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_0222: Unknown result type (might be due to invalid IL or missing references)
		_map.sizeDelta = new Vector2(_w, h - 64f);
		Cell val = _mapCell.Invoke();
		_mapSquare.Pov = val;
		if (Object.op_Implicit((Object)(object)val))
		{
			Paint(_mapSquare, val);
		}
		RectTransform val2 = _planArea.Invoke();
		Images(_plan.Invoke(), _planImgs, _planBox, (Object.op_Implicit((Object)(object)val2) && val2.sizeDelta.x > 0f) ? (140f / val2.sizeDelta.x) : 1f, centred: false);
		Copy(_mapLines, _mapText.Invoke());
		float num = h - 64f;
		TMP_Text val3 = _hint.Invoke();
		bool flag = Object.op_Implicit((Object)(object)val3) && ((Component)val3).gameObject.activeSelf;
		if (((Component)_hintText).gameObject.activeSelf != flag)
		{
			((Component)_hintText).gameObject.SetActive(flag);
		}
		Copy(_hintText, val3);
		Copy(_statusText, _status.Invoke());
		Mirror(_launchBtn, _launch.Invoke(), _launchLabel.Invoke(), show: true);
		Mirror(_freshBtn, _fresh.Invoke(), null, show: true);
		float num2 = (_w - _launchBtn.Root.sizeDelta.x) * 0.5f;
		_launchBtn.Root.anchoredPosition = new Vector2(num2, 0f - (num - 50f));
		_freshBtn.Root.anchoredPosition = new Vector2(num2, 0f - (num - 50f));
		((TMP_Text)_statusText).rectTransform.anchoredPosition = new Vector2(0f, 0f - (num - 50f - 12f - 64f));
		((TMP_Text)_hintText).rectTransform.anchoredPosition = new Vector2(0f, 0f - (num - 50f - 12f - 64f - 50f));
	}
}
internal static class BridgeTips
{
	private static readonly HashSet<int> Anchors = new HashSet<int>();

	private static FieldRef<RectTransform> _anchor;

	internal static void Bind(RectTransform rt, Func<Tip> provider)
	{
		Anchors.Add(((Object)rt).GetInstanceID());
		Tooltip.Bind(rt, provider, (RectTransform)null);
	}

	internal static void Bind(UIInputHandler ih, RectTransform anchor, Func<Tip> provider)
	{
		Anchors.Add(((Object)anchor).GetInstanceID());
		Tooltip.Bind(ih, anchor, provider, false);
	}

	internal static void Show(RectTransform anchor, Func<Tip> provider)
	{
		Anchors.Add(((Object)anchor).GetInstanceID());
		Tooltip.Show(anchor, provider, false);
	}

	internal static string Patch(Harmony harmony)
	{
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Expected O, but got Unknown
		MethodInfo methodInfo = AccessTools.PropertyGetter(typeof(Elem), "Active");
		FieldInfo fieldInfo = AccessTools.Field(typeof(Tooltip), "_anchor");
		if (methodInfo == null || fieldInfo == null || fieldInfo.FieldType != typeof(RectTransform))
		{
			return "SeneaL Prefs.Elem.Active / Tooltip._anchor";
		}
		_anchor = AccessTools.StaticFieldRefAccess<RectTransform>(fieldInfo);
		harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(BridgeTips), "ActivePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		return null;
	}

	private static void ActivePostfix(Elem __instance, ref bool __result)
	{
		if (!__result && __instance == Prefs.Tooltips && !__instance.Hidden)
		{
			RectTransform val = _anchor.Invoke();
			if (Object.op_Implicit((Object)(object)val) && Anchors.Contains(((Object)val).GetInstanceID()))
			{
				__result = true;
			}
		}
	}
}
internal static class CompareTip
{
	private sealed class State
	{
		public object[] Vars;

		public object[] Lists;
	}

	private const BindingFlags Statics = BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

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

	private static FieldInfo[] _vars;

	private static FieldInfo[] _lists;

	private static FieldInfo[] _tipFields;

	private static FieldInfo _root;

	private static FieldInfo _panel;

	private static FieldInfo _arrow;

	private static FieldInfo _arrowIn;

	private static FieldInfo _anchor;

	private static FieldInfo _provider;

	private static FieldInfo _timer;

	private static FieldInfo _shown;

	private static FieldInfo _width;

	private static FieldInfo _height;

	private static FieldInfo _canvas;

	private static FieldInfo _lastSize;

	private static FieldInfo _left;

	private static FieldInfo _scale;

	private static FieldInfo _tickFrame;

	private static Action<bool> _tick;

	private static Action<Transform, float> _init;

	private static State _b;

	private static RectTransform _bRoot;

	private static RectTransform _bPanel;

	private static readonly Tip Worn = new Tip();

	private static readonly Func<Tip> WornTip = () => Worn;

	private static int _key;

	private static int _frame;

	private static bool _broken;

	internal static ItemData Hovered;

	internal static int HoveredFrame = -1;

	internal static bool Inside { get; private set; }

	private static FieldInfo F(string name, ref string missing)
	{
		FieldInfo? field = typeof(Tooltip).GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
		if (field == null)
		{
			missing = missing ?? ("SeneaL Tooltip." + name);
		}
		return field;
	}

	internal static string Patch(Harmony harmony)
	{
		//IL_0248: Unknown result type (might be due to invalid IL or missing references)
		//IL_0255: Expected O, but got Unknown
		string missing = null;
		_root = F("_root", ref missing);
		_panel = F("_panel", ref missing);
		_arrow = F("_arrow", ref missing);
		_arrowIn = F("_arrowIn", ref missing);
		_anchor = F("_anchor", ref missing);
		_provider = F("_provider", ref missing);
		_timer = F("_timer", ref missing);
		_shown = F("_shown", ref missing);
		_width = F("_width", ref missing);
		_height = F("_height", ref missing);
		_canvas = F("_canvas", ref missing);
		_lastSize = F("_lastSize", ref missing);
		_left = F("_left", ref missing);
		_scale = F("_scale", ref missing);
		_tickFrame = F("_frame", ref missing);
		MethodInfo methodInfo = AccessTools.Method(typeof(Tooltip), "Tick", new Type[1] { typeof(bool) }, (Type[])null);
		MethodInfo methodInfo2 = AccessTools.Method(typeof(Tooltip), "Init", new Type[2]
		{
			typeof(Transform),
			typeof(float)
		}, (Type[])null);
		if (missing == null && (methodInfo == null || methodInfo2 == null))
		{
			missing = "SeneaL Tooltip.Tick / Init";
		}
		if (missing != null)
		{
			return missing;
		}
		List<FieldInfo> list = new List<FieldInfo>();
		List<FieldInfo> list2 = new List<FieldInfo>();
		FieldInfo[] fields = typeof(Tooltip).GetFields(BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
		foreach (FieldInfo fieldInfo in fields)
		{
			if (!fieldInfo.IsLiteral)
			{
				if (!fieldInfo.IsInitOnly)
				{
					list.Add(fieldInfo);
				}
				else if (fieldInfo.GetValue(null) is IList)
				{
					list2.Add(fieldInfo);
				}
			}
		}
		_vars = list.ToArray();
		_lists = list2.ToArray();
		_tipFields = typeof(Tip).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		_tick = AccessTools.MethodDelegate<Action<bool>>(methodInfo, (object)null, true);
		_init = AccessTools.MethodDelegate<Action<Transform, float>>(methodInfo2, (object)null, true);
		harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(CompareTip), "TickPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		return null;
	}

	private static State Capture()
	{
		State state = new State
		{
			Vars = new object[_vars.Length],
			Lists = new object[_lists.Length]
		};
		for (int i = 0; i < _vars.Length; i++)
		{
			state.Vars[i] = _vars[i].GetValue(null);
		}
		for (int j = 0; j < _lists.Length; j++)
		{
			object value = _lists[j].GetValue(null);
			state.Lists[j] = ((value is Array array) ? array.Clone() : new ArrayList((IList)value).ToArray());
		}
		return state;
	}

	private static void Apply(State s)
	{
		for (int i = 0; i < _vars.Length; i++)
		{
			_vars[i].SetValue(null, s.Vars[i]);
		}
		for (int j = 0; j < _lists.Length; j++)
		{
			object value = _lists[j].GetValue(null);
			Array array = (Array)s.Lists[j];
			if (value is Array array2)
			{
				Array.Copy(array, array2, Math.Min(array.Length, array2.Length));
				continue;
			}
			IList list = (IList)value;
			list.Clear();
			foreach (object item in array)
			{
				list.Add(item);
			}
		}
	}

	private static void Copy(Tip from, Tip to)
	{
		FieldInfo[] tipFields = _tipFields;
		foreach (FieldInfo fieldInfo in tipFields)
		{
			object value = fieldInfo.GetValue(from);
			if (fieldInfo.IsInitOnly && value is IList list)
			{
				IList list2 = (IList)fieldInfo.GetValue(to);
				list2.Clear();
				foreach (object item in list)
				{
					list2.Add(item);
				}
			}
			else if (!fieldInfo.IsInitOnly)
			{
				fieldInfo.SetValue(to, value);
			}
		}
	}

	private static void TickPostfix()
	{
		if (!Inside && !_broken)
		{
			Plugin.Guard(ref _broken, "tooltip compare", Run);
		}
	}

	private static void Run()
	{
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Expected O, but got Unknown
		//IL_0137: 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_01c3: 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)
		//IL_01f3: Expected O, but got Unknown
		//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Expected O, but got Unknown
		//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0243: Unknown result type (might be due to invalid IL or missing references)
		//IL_0302: Unknown result type (might be due to invalid IL or missing references)
		//IL_0319: Unknown result type (might be due to invalid IL or missing references)
		//IL_031e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0346: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
		if (_frame == Time.frameCount)
		{
			return;
		}
		_frame = Time.frameCount;
		ItemData val = (((bool)_shown.GetValue(null) && HoveredFrame == Time.frameCount && ItemFacts.Shift) ? ItemFacts.Worn(Hovered) : null);
		if (val == null)
		{
			if (Object.op_Implicit((Object)(object)_bPanel) && ((Component)_bPanel).gameObject.activeSelf)
			{
				((Component)_bPanel).gameObject.SetActive(false);
			}
			return;
		}
		Inside = true;
		State state = null;
		try
		{
			int num = (((object)val).GetHashCode() * 31 + (int)Time.unscaledTime) * 2 + (ItemFacts.Details ? 1 : 0);
			if (num != _key)
			{
				_key = num;
				Copy(Tips.ForItem(val, 4, false, 0), Worn);
				Worn.Footer.Clear();
				Worn.VneiKey = null;
				Worn.Sub = (string.IsNullOrEmpty(Worn.Sub) ? "Worn now" : ("Worn now · " + Worn.Sub));
				Worn.Version = num;
			}
			RectTransform val2 = (RectTransform)_root.GetValue(null);
			RectTransform val3 = (RectTransform)_panel.GetValue(null);
			object value = _anchor.GetValue(null);
			object value2 = _canvas.GetValue(null);
			float arg = (float)_scale.GetValue(null);
			float num2 = (float)_width.GetValue(null);
			Vector2 anchoredPosition = val3.anchoredPosition;
			state = Capture();
			if (_b == null || !Object.op_Implicit((Object)(object)_bRoot))
			{
				_root.SetValue(null, null);
				_init(((Transform)val2).parent, arg);
				((Object)(RectTransform)_root.GetValue(null)).name = "SeneaLUI_TooltipCompare";
			}
			else
			{
				Apply(_b);
			}
			_bRoot = (RectTransform)_root.GetValue(null);
			_bPanel = (RectTransform)_panel.GetValue(null);
			if ((Object)(object)((Transform)_bRoot).parent != (Object)(object)((Transform)val2).parent)
			{
				((Transform)_bRoot).SetParent(((Transform)val2).parent, false);
				_canvas.SetValue(null, value2);
				_lastSize.SetValue(null, Vector2.zero);
			}
			_anchor.SetValue(null, value);
			_provider.SetValue(null, WornTip);
			_left.SetValue(null, false);
			_timer.SetValue(null, 1f);
			_tickFrame.SetValue(null, -1);
			_tick(obj: true);
			float num3 = (float)_width.GetValue(null);
			float num4 = (float)_height.GetValue(null);
			float num5 = anchoredPosition.x - num3 - 8f;
			if (num5 < 8f)
			{
				num5 = anchoredPosition.x + num2 + 8f;
			}
			float num6 = 0f - anchoredPosition.y;
			Rect rect = _bRoot.rect;
			float num7 = Mathf.Clamp(num6, 8f, Mathf.Max(8f, ((Rect)(ref rect)).height - num4 - 8f));
			_bPanel.anchoredPosition = new Vector2(num5, 0f - num7);
			FieldInfo[] array = new FieldInfo[2] { _arrow, _arrowIn };
			for (int i = 0; i < array.Length; i++)
			{
				object? value3 = array[i].GetValue(null);
				RectTransform val4 = (RectTransform)((value3 is RectTransform) ? value3 : null);
				if (Object.op_Implicit((Object)(object)val4) && ((Component)val4).gameObject.activeSelf)
				{
					((Component)val4).gameObject.SetActive(false);
				}
			}
			if (!((Component)_bPanel).gameObject.activeSelf)
			{
				((Component)_bPanel).gameObject.SetActive(true);
			}
			_b = Capture();
		}
		finally
		{
			if (state != null)
			{
				Apply(state);
			}
			Inside = false;
		}
	}
}
internal sealed class CraftCover
{
	private struct Kept
	{
		public CanvasGroup Group;

		public float Alpha;

		public bool Rays;
	}

	internal readonly RectTransform Root;

	private readonly RectTransform _panel;

	private readonly Dictionary<Transform, Kept> _hidden = new Dictionary<Transform, Kept>();

	private bool _on;

	internal bool Alive
	{
		get
		{
			if (Object.op_Implicit((Object)(object)Root))
			{
				return Object.op_Implicit((Object)(object)_panel);
			}
			return false;
		}
	}

	internal CraftCover(RectTransform panel, string name)
	{
		//IL_0026: 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)
		_panel = panel;
		Root = Ui.TL((Transform)(object)panel, name, 22f, 18f, panel.sizeDelta.x - 44f, panel.sizeDelta.y - 40f);
		((Component)Root).gameObject.SetActive(false);
	}

	internal void Hold()
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		if (!_on)
		{
			_on = true;
			((Component)Root).gameObject.SetActive(true);
		}
		Vector2 val = default(Vector2);
		((Vector2)(ref val))..ctor(_panel.sizeDelta.x - 44f, _panel.sizeDelta.y - 40f);
		if (Root.sizeDelta != val)
		{
			Root.sizeDelta = val;
		}
		for (int i = 0; i < ((Transform)_panel).childCount; i++)
		{
			Transform child = ((Transform)_panel).GetChild(i);
			if (!((Object)(object)child == (Object)(object)Root) && !_hidden.ContainsKey(child) && !(((Object)child).name == "bg") && !(((Object)child).name == "inner"))
			{
				CanvasGroup val2 = ((Component)child).GetComponent<CanvasGroup>();
				bool flag = Object.op_Implicit((Object)(object)val2);
				if (!flag)
				{
					val2 = ((Component)child).gameObject.AddComponent<CanvasGroup>();
				}
				_hidden[child] = new Kept
				{
					Group = val2,
					Alpha = (flag ? val2.alpha : 1f),
					Rays = (!flag || val2.blocksRaycasts)
				};
			}
		}
		foreach (Kept value in _hidden.Values)
		{
			if (Object.op_Implicit((Object)(object)value.Group) && (value.Group.alpha != 0f || value.Group.blocksRaycasts))
			{
				value.Group.alpha = 0f;
				value.Group.blocksRaycasts = false;
			}
		}
	}

	internal void Release()
	{
		if (!_on)
		{
			return;
		}
		_on = false;
		if (Object.op_Implicit((Object)(object)Root))
		{
			((Component)Root).gameObject.SetActive(false);
		}
		foreach (Kept value in _hidden.Values)
		{
			if (Object.op_Implicit((Object)(object)value.Group))
			{
				value.Group.alpha = value.Alpha;
				value.Group.blocksRaycasts = value.Rays;
			}
		}
		_hidden.Clear();
	}
}
internal static class CraftPanelWindows
{
	private static MethodInfo _fallback;

	private static MethodInfo _show;

	private static FieldInfo _vanilla;

	private static FieldInfo _applied;

	private static FieldInfo _foreign;

	private static FieldInfo _fallbackHide;

	private static readonly FieldRef<RectTransform> AnvilWindow = AccessTools.StaticFieldRefAccess<RectTransform>(AccessTools.Field(typeof(RunicAnvilWindow), "window"));

	private static readonly FieldRef<Container> AnvilShown = AccessTools.StaticFieldRefAccess<Container>(AccessTools.Field(typeof(RunicAnvilWindow), "shown"));

	private static bool _active;

	private static CanvasGroup _chestGroup;

	private static bool _broken;

	private static readonly Color Usable = new Color(1f, 0.8f, 0.42f);

	private static readonly Color Unusable = new Color(0.55f, 0.55f, 0.55f);

	private static readonly List<Button> Buttons = new List<Button>();

	private static float _nextScan;

	internal static string Patch(Harmony harmony)
	{
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Expected O, but got Unknown
		Type typeFromHandle = typeof(CraftView);
		_fallback = AccessTools.Method(typeFromHandle, "Fallback", new Type[2]
		{
			typeof(bool),
			typeof(bool)
		}, (Type[])null);
		_show = AccessTools.Method(typeFromHandle, "Show", new Type[1] { typeof(bool) }, (Type[])null);
		_vanilla = AccessTools.Field(typeFromHandle, "_vanilla");
		_applied = AccessTools.Field(typeFromHandle, "_applied");
		_foreign = AccessTools.Field(typeFromHandle, "_foreign");
		_fallbackHide = AccessTools.Field(typeFromHandle, "_fallbackHide");
		MethodInfo methodInfo = AccessTools.Method(typeFromHandle, "Tick", new Type[2]
		{
			typeof(bool),
			typeof(bool)
		}, (Type[])null);
		if (_fallback == null || _show == null || _vanilla == null || _applied == null || _foreign == null || _fallbackHide == null || methodInfo == null)
		{
			return "SeneaL CraftView fallback members";
		}
		harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(CraftPanelWindows), "TickPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		return null;
	}

	private static bool AnvilOpen()
	{
		RectTransform val = AnvilWindow.Invoke();
		if (Object.op_Implicit((Object)(object)val) && ((Component)val).gameObject.activeSelf)
		{
			return (Object)(object)AnvilShown.Invoke() != (Object)null;
		}
		return false;
	}

	private static void TickPostfix(CraftView __instance, bool open)
	{
		Plugin.Guard(ref _broken, "Runic Anvil / Book of the Halls windows", delegate
		{
			Tick(__instance, open);
		});
		if (_broken && _active)
		{
			Release(__instance);
		}
	}

	private static void Tick(CraftView view, bool open)
	{
		bool num = (bool)_applied.GetValue(view) && !(bool)_foreign.GetValue(view);
		bool flag = AnvilOpen();
		if (num && open && ((flag && !AnvilView.Active) || (HallMapWindow.IsOpen && !BookView.Active) || (HallMapShopWindow.IsOpen && !ShopView.Active)))
		{
			_active = true;
			_show.Invoke(view, new object[1] { false });
			_fallback.Invoke(view, new object[2] { true, false });
			SetChestHidden(flag && !AnvilView.Active);
		}
		else if (_active)
		{
			Release(view);
		}
		if (open)
		{
			TintButtons();
		}
	}

	private static void TintButtons()
	{
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		RectTransform val = (Object.op_Implicit((Object)(object)InventoryGui.instance) ? InventoryGui.instance.m_crafting : null);
		if (!Object.op_Implicit((Object)(object)val))
		{
			return;
		}
		if (Time.unscaledTime >= _nextScan)
		{
			_nextScan = Time.unscaledTime + 0.5f;
			((Component)val).GetComponentsInChildren<Button>(true, Buttons);
			Buttons.RemoveAll((Button b) => ((Object)b).name != "PT_AnvilButton");
		}
		foreach (Button button in Buttons)
		{
			if (Object.op_Implicit((Object)(object)button) && Object.op_Implicit((Object)(object)((Selectable)button).image))
			{
				Color val2 = (((Selectable)button).interactable ? Usable : Unusable);
				if (((Graphic)((Selectable)button).image).color != val2)
				{
					((Graphic)((Selectable)button).image).color = val2;
				}
			}
		}
	}

	private static void Release(CraftView view)
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Expected O, but got Unknown
		_active = false;
		SetChestHidden(hide: false);
		if ((bool)_applied.GetValue(view) && !(bool)_foreign.GetValue(view))
		{
			CanvasGroup val = (CanvasGroup)_vanilla.GetValue(view);
			if (Object.op_Implicit((Object)(object)val))
			{
				val.alpha = 0f;
				val.blocksRaycasts = false;
				val.interactable = false;
			}
			_fallbackHide.SetValue(view, -1);
			CraftView.Dirty = true;
		}
	}

	internal static void SetChestHidden(bool hide)
	{
		ContainerView chest = InventoryGuiPatches.Chest;
		if (chest == null || !Object.op_Implicit((Object)(object)chest.Panel))
		{
			return;
		}
		if (!Object.op_Implicit((Object)(object)_chestGroup))
		{
			if (!hide)
			{
				return;
			}
			_chestGroup = ((Component)chest.Panel).GetComponent<CanvasGroup>() ?? ((Component)chest.Panel).gameObject.AddComponent<CanvasGroup>();
		}
		_chestGroup.alpha = (hide ? 0f : 1f);
		_chestGroup.blocksRaycasts = !hide;
		_chestGroup.interactable = !hide;
	}
}
internal sealed class EnchantTab
{
	private struct Kept
	{
		public CanvasGroup Group;

		public float Alpha;

		public bool Rays;
	}

	private const string PovTabName = "PT_TabEnchant";

	private const float ListW = 400f;

	private const float RowH = 40f;

	private const float TierH = 34f;

	private const float HeadH = 28f;

	private const float BottomH = 190f;

	private const TextAlignmentOptions Left = (TextAlignmentOptions)257;

	private const TextAlignmentOptions Right = (TextAlignmentOptions)260;

	private const TextAlignmentOptions Mid = (TextAlignmentOptions)258;

	private static FieldRef<bool> _open;

	private static FieldRef<ItemData> _target;

	private static FieldRef<Tab> _shownTab;

	private static FieldRef<Row> _pickRow;

	private static FieldRef<int> _pickTier;

	private static FieldRef<string> _expanded;

	private static FieldRef<string> _builtKey;

	private static FieldRef<string> _toast;

	private static FieldRef<float> _toastUntil;

	private static FieldRef<Color> _toastColor;

	private static Action _onButton;

	private static Action _close;

	private static Action<ItemData> _place;

	private static Func<Row, int, string> _range;

	private static Func<Row, Sprite> _themeIcon;

	private static FieldRef<CraftView, bool> _foreign;

	private static FieldRef<CraftView, Button[]> _fbtn;

	private static FieldRef<CraftView, RectTransform[]> _tabs;

	private static FieldRef<CraftView, RectTransform[]> _tabUnder;

	private static FieldRef<CraftView, TextMeshProUGUI[]> _tabTexts;

	private static FieldRef<InventoryGui, ItemData> _dragItem;

	private static FieldRef<InventoryGui, Inventory> _dragInv;

	private static Action<InventoryGui, ItemData, Inventory, int> _setupDrag;

	private static string _missing;

	private static bool _broken;

	private static EnchantTab _page;

	private readonly CraftView _view;

	private readonly RectTransform _panel;

	private readonly RectTransform _root;

	private readonly RectTransform _divider;

	private readonly RectTransform _side;

	private readonly RectTransform _bottom;

	private readonly RectTransform _rows;

	private readonly RectTransform _under;

	private readonly float _w;

	private readonly ChipBar _kinds;

	private readonly ScrollBox _box;

	private readonly Slot _slot;

	private readonly TextMeshProUGUI _name;

	private readonly TextMeshProUGUI _pick;

	private readonly TextMeshProUGUI _why;

	private readonly TextMeshProUGUI _req;

	private readonly ReqChip[] _chips = (ReqChip[])(object)new ReqChip[2];

	private readonly GoldButton _button;

	private readonly Sprite _rowOn;

	private readonly Sprite _rowHover;

	private readonly Tip _slotTip = new Tip();

	private readonly Dictionary<Transform, Kept> _hidden = new Dictionary<Transform, Kept>();

	private readonly Image[] _unders = (Image[])(object)new Image[5];

	private bool _shown;

	private bool _dirty = true;

	private string _key;

	private float _h;

	private float _top;

	private float _kindsH;

	private float _next;

	private float _revealTop = -1f;

	private float _revealBottom;

	private ItemData _slotItem;

	private const float Delay = 0.5f;

	private float _busyFrom = -1f;

	private ItemData _busyItem;

	private Row _busyRow;

	private int _busyTier;

	private static FieldRef<T> Pov<T>(string name)
	{
		FieldInfo fieldInfo = AccessTools.Field(typeof(EnchantWindow), name);
		if (fieldInfo == null || fieldInfo.FieldType != typeof(T))
		{
			_missing = _missing ?? ("PoV EnchantWindow." + name);
			return null;
		}
		return AccessTools.StaticFieldRefAccess<T>(fieldInfo);
	}

	private static T PovCall<T>(string name) where T : Delegate
	{
		MethodInfo methodInfo = AccessTools.Method(typeof(EnchantWindow), name, (Type[])null, (Type[])null);
		if (methodInfo == null)
		{
			_missing = _missing ?? ("PoV EnchantWindow." + name);
			return null;
		}
		return AccessTools.MethodDelegate<T>(methodInfo, (object)null, true);
	}

	private static FieldRef<CraftView, T> View<T>(string name)
	{
		FieldInfo fieldInfo = AccessTools.Field(typeof(CraftView), name);
		if (fieldInfo == null || fieldInfo.FieldType != typeof(T))
		{
			_missing = _missing ?? ("SeneaL CraftView." + name);
			return null;
		}
		return AccessTools.FieldRefAccess<CraftView, T>(fieldInfo);
	}

	internal static string Patch(Harmony harmony)
	{
		//IL_0229: Unknown result type (might be due to invalid IL or missing references)
		//IL_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_024b: Expected O, but got Unknown
		//IL_024b: Expected O, but got Unknown
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_026c: Expected O, but got Unknown
		_open = Pov<bool>("open");
		_target = Pov<ItemData>("target");
		_shownTab = Pov<Tab>("shownTab");
		_pickRow = Pov<Row>("pickRow");
		_pickTier = Pov<int>("pickTier");
		_expanded = Pov<string>("expanded");
		_builtKey = Pov<string>("builtKey");
		_toast = Pov<string>("toast");
		_toastUntil = Pov<float>("toastUntil");
		_toastColor = Pov<Color>("toastColor");
		_onButton = PovCall<Action>("OnButton");
		_close = PovCall<Action>("Close");
		_place = PovCall<Action<ItemData>>("Place");
		_range = PovCall<Func<Row, int, string>>("Range");
		_themeIcon = PovCall<Func<Row, Sprite>>("ThemeIcon");
		_foreign = View<bool>("_foreign");
		_fbtn = View<Button[]>("_fbtn");
		_tabs = View<RectTransform[]>("_tabs");
		_tabUnder = View<RectTransform[]>("_tabUnder");
		_tabTexts = View<TextMeshProUGUI[]>("_tabTexts");
		MethodInfo methodInfo = AccessTools.Method(typeof(CraftView), "Tick", new Type[2]
		{
			typeof(bool),
			typeof(bool)
		}, (Type[])null);
		MethodInfo methodInfo2 = AccessTools.Method(typeof(CraftView), "OnTab", new Type[1] { typeof(int) }, (Type[])null);
		MethodInfo methodInfo3 = AccessTools.Method(typeof(InventoryGui), "SetupDragItem", (Type[])null, (Type[])null);
		if (_missing == null && (methodInfo == null || methodInfo2 == null))
		{
			_missing = "SeneaL CraftView.Tick / OnTab";
		}
		if (_missing == null && methodInfo3 == null)
		{
			_missing = "InventoryGui.SetupDragItem";
		}
		if (_missing != null)
		{
			return _missing;
		}
		_dragItem = AccessTools.FieldRefAccess<InventoryGui, ItemData>("m_dragItem");
		_dragInv = AccessTools.FieldRefAccess<InventoryGui, Inventory>("m_dragInventory");
		_setupDrag = AccessTools.MethodDelegate<Action<InventoryGui, ItemData, Inventory, int>>(methodInfo3, (object)null, true);
		harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(EnchantTab), "OnTabPrefix", (Type[])null), new HarmonyMethod(typeof(EnchantTab), "OnTabPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(EnchantTab), "TickPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		return null;
	}

	private static int TabIndex(CraftView view)
	{
		Button[] array = _fbtn.Invoke(view);
		for (int i = 0; i < array.Length; i++)
		{
			if (Object.op_Implicit((Object)(object)array[i]) && ((Object)array[i]).name == "PT_TabEnchant")
			{
				return 5 + i;
			}
		}
		return -1;
	}

	private static void OnTabPrefix(CraftView __instance, int i)
	{
		if (_broken)
		{
			return;
		}
		try
		{
			if (_open.Invoke() && i != TabIndex(__instance))
			{
				_close();
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Enchant tab: closing it failed: " + ex.Message));
		}
	}

	private static void OnTabPostfix(CraftView __instance, int i)
	{
		if (!_broken && i >= 5 && i == TabIndex(__instance))
		{
			_foreign.Invoke(__instance) = false;
			CraftView.Dirty = true;
		}
	}

	private static void TickPostfix(CraftView __instance)
	{
		Plugin.Guard(ref _broken, "Enchant tab", delegate
		{
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			RectTransform panel = __instance.Panel;
			int num = TabIndex(__instance);
			if (num < 0 || !_open.Invoke() || _foreign.Invoke(__instance) || !Object.op_Implicit((Object)(object)panel) || !((Component)panel).gameObject.activeInHierarchy || !Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				if (_page != null)
				{
					_page.Hide();
				}
			}
			else
			{
				if (_page != null && (!Object.op_Implicit((Object)(object)_page._root) || _page._view != __instance || _page._w != panel.sizeDelta.x - 44f))
				{
					_page.Hide();
					if (Object.op_Implicit((Object)(object)_page._root))
					{
						Object.Destroy((Object)(object)((Component)_page._root).gameObject);
					}
					_page = null;
				}
				if (_page == null)
				{
					_page = new EnchantTab(__instance);
				}
				_page.Draw(num);
			}
		});
		if (_broken && _page != null)
		{
			try
			{
				_page.Hide();
			}
			catch (Exception)
			{
			}
			_page = null;
		}
	}

	private EnchantTab(CraftView view)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Expected O, but got Unknown
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Expected O, but got Unknown
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0202: Expected O, but got Unknown
		//IL_020e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0324: Unknown result type (might be due to invalid IL or missing references)
		//IL_0333: Unknown result type (might be due to invalid IL or missing references)
		//IL_0396: Unknown result type (might be due to invalid IL or missing references)
		//IL_0437: Unknown result type (might be due to invalid IL or missing references)
		//IL_043d: Expected O, but got Unknown
		//IL_048a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0494: Expected O, but got Unknown
		//IL_04a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d0: Unknown result type (might be due to invalid IL or missing references)
		_view = view;
		_panel = view.Panel;
		_w = _panel.sizeDelta.x - 44f;
		_rowOn = Skin.Sliced(40, Styles.RowOn, -1);
		_rowHover = Skin.Sliced(40, Styles.RowHover, -1);
		_root = Ui.TL((Transform)(object)_panel, "povench", 22f, 0f, _w, 100f);
		_kinds = new ChipBar((Transform)(object)_root, "kinds", new string[Enchants.Tabs.Count], (Action<int>)delegate(int i)
		{
			_shownTab.Invoke() = Enchants.Tabs[i];
			_expanded.Invoke() = null;
			Changed();
		});
		_kinds.MaxWidth = _w;
		_box = new ScrollBox((Transform)(object)_root, "list", 400f, 100f, 96f);
		_rows = Ui.TL((Transform)(object)_box.Content, "rows", 0f, 0f, 400f, 0f);
		_divider = Ui.TL((Transform)(object)_root, "div", 418f, 0f, 1f, 100f);
		Ui.Img(_divider, (Sprite)null, Palette.BrassLine14);
		float num = 437f;
		float num2 = _w - num;
		_side = Ui.TL((Transform)(object)_root, "side", num, 0f, num2, 100f);
		_slot = new Slot((Transform)(object)_side, "item", (num2 - 64f) * 0.5f, 6f, 64, 40, (string)null, false);
		((Graphic)Ui.Img(_slot.Root, (Sprite)null, Palette.Clear)).raycastTarget = true;
		UIInputHandler obj = ((Component)_slot.Root).gameObject.AddComponent<UIInputHandler>()