Decompiled source of SeneaLUI PovSkills v2.7.0

SeneaLUI.PovSkills.dll

Decompiled 3 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
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.Bootstrap;
using BepInEx.Logging;
using HarmonyLib;
using PassiveTree;
using PassiveTree.Encounters.HallMaps;
using PassiveTree.Encounters.Halls;
using PassiveTree.Gear;
using PassiveTree.UI;
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.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 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 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 || HallMapWindow.IsOpen || HallMapShopWindow.IsOpen))
		{
			_active = true;
			_show.Invoke(view, new object[1] { false });
			_fallback.Invoke(view, new object[2] { true, false });
			SetChestHidden(flag);
		}
		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;
		}
	}

	private 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 static class HallsPins
{
	private const string GatePrefix = "pov_hallsgate_";

	private static Dictionary<string, PinData> _shown;

	private static MethodInfo _iconFor;

	internal static string Patch(Harmony harmony)
	{
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Expected O, but got Unknown
		Type type = AccessTools.TypeByName("PassiveTree.Encounters.Pins");
		Type type2 = AccessTools.TypeByName("SeneaLUI.Map.MapPins");
		_shown = ((type == null) ? null : AccessTools.Field(type, "shown")?.GetValue(null)) as Dictionary<string, PinData>;
		if (_shown == null || type2 == null)
		{
			return "PoV/SeneaL pin registry";
		}
		MethodInfo methodInfo = AccessTools.Method(type2, "Sync", (Type[])null, (Type[])null);
		_iconFor = AccessTools.Method(type2, "IconFor", (Type[])null, (Type[])null);
		if (methodInfo == null || _iconFor == null)
		{
			return "SeneaL map rendering";
		}
		harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(HallsPins), "UseOriginalIcon", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
		return null;
	}

	private static IEnumerable<CodeInstruction> UseOriginalIcon(IEnumerable<CodeInstruction> instructions)
	{
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Expected O, but got Unknown
		List<CodeInstruction> list = new List<CodeInstruction>(instructions);
		int num = list.FindIndex((CodeInstruction instruction) => CodeInstructionExtensions.Calls(instruction, _iconFor));
		FieldInfo fieldInfo = AccessTools.Field(typeof(PinData), "m_type");
		if (num < 3 || list.FindLastIndex((CodeInstruction instruction) => CodeInstructionExtensions.Calls(instruction, _iconFor)) != num || !CodeInstructionExtensions.LoadsField(list[num - 2], fieldInfo, false) || !CodeInstructionExtensions.IsLdloc(list[num - 3], (LocalBuilder)null) || list[num].blocks.Count != 0)
		{
			throw new InvalidOperationException("SeneaL pin icon call changed");
		}
		CodeInstruction val = new CodeInstruction(list[num - 3].opcode, list[num - 3].operand);
		val.labels.AddRange(list[num].labels);
		list[num].labels.Clear();
		list[num].operand = AccessTools.Method(typeof(HallsPins), "IconFor", (Type[])null, (Type[])null);
		list.Insert(num, val);
		return list;
	}

	private static string IconFor(PinType type, int custom, PinData pin)
	{
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Invalid comparison between Unknown and I4
		if (Object.op_Implicit((Object)(object)pin.m_icon) && (int)type == 3 && !pin.m_save)
		{
			foreach (KeyValuePair<string, PinData> item in _shown)
			{
				if (item.Value == pin && item.Key.StartsWith("pov_hallsgate_", StringComparison.Ordinal))
				{
					return null;
				}
			}
		}
		return MapPins.IconFor(type, custom);
	}
}
internal static class ItemFacts
{
	private static readonly Dictionary<string, string> SameRow = new Dictionary<string, string>
	{
		{ "usestamina", "stamina" },
		{ "blockarmour", "block" },
		{ "blockarmor", "block" },
		{ "blockforce", "knockbackforce" },
		{ "parrybonus", "parry" },
		{ "parryadrenaline", "adrenaline" }
	};

	private static Func<bool> _held;

	private static FieldInfo _itemTip;

	private static bool _wasHeld;

	private const BindingFlags Any = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

	private static readonly Regex Tags = new Regex("</?[A-Za-z#][^<>\\n]*>", RegexOptions.Compiled);

	private static readonly string[] KindBreaks = new string[2] { "  ·  ", "\n" };

	private static readonly string[] CoreLists = new string[3] { "Main", "Usage", "Facts" };

	private static MethodInfo _build;

	private static FieldInfo _details;

	private static Type _model;

	private static bool _broken;

	internal static string Patch(Harmony harmony)
	{
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Expected O, but got Unknown
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Expected O, but got Unknown
		MethodInfo methodInfo = AccessTools.Method(typeof(Tips), "PovRows", (Type[])null, (Type[])null);
		if (methodInfo == null)
		{
			return "SeneaL Tips.PovRows";
		}
		Type type = AccessTools.TypeByName("PassiveTree.UI.ItemTooltip");
		_build = ((type == null) ? null : AccessTools.Method(type, "Build", new Type[1] { typeof(ItemData) }, (Type[])null));
		_model = type?.GetNestedType("Model", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
		if (_build == null || _model == null || _model.GetField("Kind", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) == null)
		{
			return "PoV ItemTooltip.Build";
		}
		_details = type.GetField("probeDetails", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
		MethodInfo methodInfo2 = AccessTools.PropertyGetter(typeof(Tips), "DetailsHeld");
		if (methodInfo2 == null)
		{
			return "SeneaL Tips.DetailsHeld";
		}
		_held = (Func<bool>)Delegate.CreateDelegate(typeof(Func<bool>), methodInfo2);
		harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(ItemFacts), "RowsPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		MethodInfo methodInfo3 = AccessTools.Method(typeof(Tips), "ForItem", (Type[])null, (Type[])null);
		_itemTip = AccessTools.Field(typeof(Tips), "ItemTip");
		if (methodInfo3 != null && _itemTip != null)
		{
			harmony.Patch((MethodBase)methodInfo3, new HarmonyMethod(typeof(ItemFacts), "ForItemPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		return null;
	}

	private static void ForItemPrefix()
	{
		if (!_broken && _held() != _wasHeld)
		{
			_wasHeld = !_wasHeld;
			object? value = _itemTip.GetValue(null);
			Tip val = (Tip)((value is Tip) ? value : null);
			if (val != null)
			{
				val.Version = 0;
			}
		}
	}

	private static void RowsPostfix(Tip __0, ItemData __1)
	{
		Plugin.Guard(ref _broken, "PoV rows in item tooltips", delegate
		{
			Add(__0, __1);
		});
	}

	private static void Add(Tip tip, ItemData item)
	{
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_027f: Unknown result type (might be due to invalid IL or missing references)
		if (tip == null || item == null || !_held())
		{
			return;
		}
		bool flag = _details != null && (bool)_details.GetValue(null);
		object obj;
		try
		{
			_details?.SetValue(null, true);
			obj = _build.Invoke(null, new object[1] { item });
		}
		finally
		{
			_details?.SetValue(null, flag);
		}
		if (obj == null)
		{
			return;
		}
		HashSet<string> hashSet = new HashSet<string> { "" };
		foreach (Row row in tip.Rows)
		{
			string text = Norm(row.Label);
			hashSet.Add(text);
			if (SameRow.TryGetValue(text, out var value))
			{
				hashSet.Add(value);
			}
		}
		string text2 = Norm(tip.Sub);
		List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>();
		string[] array = (Text(obj, "Kind") ?? "").Split(KindBreaks, StringSplitOptions.RemoveEmptyEntries);
		foreach (string s in array)
		{
			string text3 = Norm(s);
			if (text3.Length > 0 && !text2.Contains(text3) && hashSet.Add(text3))
			{
				list.Add(new KeyValuePair<string, string>(Plain(s), ""));
			}
		}
		array = CoreLists;
		foreach (string name in array)
		{
			Take(_model.GetField(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(obj) as IEnumerable, hashSet, list);
		}
		if (_model.GetField("Sections", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(obj) is IEnumerable enumerable)
		{
			foreach (object item2 in enumerable)
			{
				if (item2 != null)
				{
					Take(item2.GetType().GetField("Rows", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(item2) as IEnumerable, hashSet, list);
				}
			}
		}
		if (list.Count == 0)
		{
			return;
		}
		tip.Rows.Add(new Row
		{
			Head = true,
			Label = "PATH OF VALHEIMAN"
		});
		foreach (KeyValuePair<string, string> item3 in list)
		{
			tip.AddRow(item3.Key, item3.Value, (string)null);
		}
	}

	private static void Take(IEnumerable rows, HashSet<string> seen, List<KeyValuePair<string, string>> found)
	{
		if (rows == null)
		{
			return;
		}
		foreach (object row in rows)
		{
			if (row != null)
			{
				string text = Plain(Text(row, "Label"));
				if (seen.Add(Norm(text)))
				{
					string text2 = Plain(Text(row, "Value"));
					string text3 = Plain(Text(row, "Second"));
					found.Add(new KeyValuePair<string, string>(text, (text3.Length > 0) ? (text2 + " " + text3) : text2));
				}
			}
		}
	}

	private static string Text(object from, string field)
	{
		return from.GetType().GetField(field, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(from) as string;
	}

	private static string Plain(string s)
	{
		if (!string.IsNullOrEmpty(s))
		{
			return Tags.Replace(s, "").Trim();
		}
		return "";
	}

	private static string Norm(string s)
	{
		StringBuilder stringBuilder = new StringBuilder();
		string text = Plain(s);
		foreach (char c in text)
		{
			if (char.IsLetterOrDigit(c) || c == '+' || c == '-' || c == '%')
			{
				stringBuilder.Append(char.ToLowerInvariant(c));
			}
		}
		return stringBuilder.ToString();
	}
}
internal static class NewCells
{
	private struct NewCell
	{
		public int Slot;

		public string Id;

		public string Word;

		public string English;
	}

	private static readonly NewCell[] Cells = new NewCell[2]
	{
		new NewCell
		{
			Slot = 7,
			Id = "quiver",
			Word = "Quiver",
			English = "Quiver"
		},
		new NewCell
		{
			Slot = 60,
			Id = "belt.lantern",
			Word = "BeltLantern",
			English = "Belt lantern"
		}
	};

	private static bool _broken;

	internal static string Patch(Harmony harmony)
	{
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Expected O, but got Unknown
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Expected O, but got Unknown
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Expected O, but got Unknown
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Expected O, but got Unknown
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Expected O, but got Unknown
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Expected O, but got Unknown
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Expected O, but got Unknown
		//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0200: Expected O, but got Unknown
		NewCell[] cells = Cells;
		for (int i = 0; i < cells.Length; i++)
		{
			NewCell newCell = cells[i];
			if (Equipment.Cell(newCell.Id) == null)
			{
				return "PoV cell " + newCell.Id;
			}
		}
		Type typeFromHandle = typeof(PovGear);
		MethodInfo methodInfo = AccessTools.Method(typeFromHandle, "Read", (Type[])null, (Type[])null);
		MethodInfo[] array = new MethodInfo[7]
		{
			AccessTools.Method(typeFromHandle, "HasCell", (Type[])null, (Type[])null),
			AccessTools.Method(typeFromHandle, "IsOpen", (Type[])null, (Type[])null),
			AccessTools.Method(typeFromHandle, "TakeOut", (Type[])null, (Type[])null),
			AccessTools.Method(typeFromHandle, "Cell", (Type[])null, (Type[])null),
			AccessTools.Method(typeFromHandle, "Accepts", (Type[])null, (Type[])null),
			AccessTools.Method(typeFromHandle, "Assign", (Type[])null, (Type[])null),
			AccessTools.Method(typeFromHandle, "Routed", (Type[])null, (Type[])null)
		};
		if (methodInfo == null || Array.IndexOf(array, null) >= 0)
		{
			return "SeneaL PovGear routing";
		}
		harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(NewCells), "ReadPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		harmony.Patch((MethodBase)array[0], new HarmonyMethod(typeof(NewCells), "HasCellPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		harmony.Patch((MethodBase)array[1], new HarmonyMethod(typeof(NewCells), "IsOpenPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		harmony.Patch((MethodBase)array[2], new HarmonyMethod(typeof(NewCells), "TakeOutPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		harmony.Patch((MethodBase)array[3], new HarmonyMethod(typeof(NewCells), "CellPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		harmony.Patch((MethodBase)array[4], new HarmonyMethod(typeof(NewCells), "AcceptsPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		harmony.Patch((MethodBase)array[5], new HarmonyMethod(typeof(NewCells), "AssignPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		harmony.Patch((MethodBase)array[6], new HarmonyMethod(typeof(NewCells), "HasCellPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		return null;
	}

	private static string IdOf(int slot)
	{
		if (_broken)
		{
			return null;
		}
		NewCell[] cells = Cells;
		for (int i = 0; i < cells.Length; i++)
		{
			NewCell newCell = cells[i];
			if (newCell.Slot == slot)
			{
				return newCell.Id;
			}
		}
		return null;
	}

	private static void ReadPostfix(Player player, List<AzuSlot> into, List<AzuSlot> pool, ref int __result)
	{
		int n = __result;
		if (n == 0 || !Object.op_Implicit((Object)(object)player))
		{
			return;
		}
		Plugin.Guard(ref _broken, "New equipment cells", delegate
		{
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: 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_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Expected O, but got Unknown
			Inventory inventory = ((Humanoid)player).GetInventory();
			NewCell[] cells = Cells;
			for (int i = 0; i < cells.Length; i++)
			{
				NewCell c = cells[i];
				AzuSlot val = into.Find((AzuSlot slot) => slot.Pov == c.Slot);
				ItemData val2 = ((c.Slot == 7) ? Quivers.Worn(player) : null);
				if (val == null || val2 != null)
				{
					bool flag = Equipment.IsOpen(player, c.Id);
					Vector2i val3 = val2?.m_gridPos ?? Equipment.GridPosition(player, c.Id);
					if (val3.x >= 0 && (flag || inventory.GetItemAt(val3.x, val3.y) != null))
					{
						if (val == null && pool.Count <= n)
						{
							pool.Add(new AzuSlot());
						}
						AzuSlot val4 = val ?? pool[n++];
						val4.Index = c.Slot;
						val4.Name = PovGear.Word(c.Word);
						val4.Original = c.English;
						val4.Quick = false;
						val4.Equip = true;
						val4.Custom = false;
						val4.Grid = val3;
						val4.Linear = val3.y * inventory.GetWidth() + val3.x;
						val4.Item = inventory.GetItemAt(val3.x, val3.y);
						val4.Occupied = val4.Item != null;
						val4.Kind = 0;
						val4.Pov = c.Slot;
						val4.KindIndex = 0;
						val4.Our = 0;
						val4.QuickIndex = -1;
						val4.Closed = false;
						if (val == null)
						{
							into.Add(val4);
						}
					}
				}
			}
		});
		__result = n;
	}

	private static bool HasCellPrefix(int slot, ref bool __result)
	{
		if (IdOf(slot) == null)
		{
			return true;
		}
		__result = true;
		return false;
	}

	private static bool IsOpenPrefix(Player p, int slot, ref bool __result)
	{
		string text = IdOf(slot);
		if (text == null)
		{
			return true;
		}
		__result = Object.op_Implicit((Object)(object)p) && Equipment.IsOpen(p, text);
		return false;
	}

	private static bool TakeOutPrefix(Player p, int slot, ref bool __result)
	{
		string text = IdOf(slot);
		if (text == null)
		{
			return true;
		}
		if (Object.op_Implicit((Object)(object)p))
		{
			Equipment.TakeOut(p, text);
		}
		__result = Object.op_Implicit((Object)(object)p);
		return false;
	}

	private static bool CellPrefix(Inventory inv, int slot, ref Vector2i __result)
	{
		//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)
		string text = IdOf(slot);
		Player localPlayer = Player.m_localPlayer;
		if (text == null || !Object.op_Implicit((Object)(object)localPlayer) || ((Humanoid)localPlayer).GetInventory() != inv)
		{
			return true;
		}
		__result = Equipment.GridPosition(localPlayer, text);
		return false;
	}

	private static bool AcceptsPrefix(Player p, int slot, ItemData item, ref bool __result)
	{
		string text = IdOf(slot);
		if (text == null)
		{
			return true;
		}
		__result = Object.op_Implicit((Object)(object)p) && item != null && Equipment.Accepts(text, item) && Equipment.IsOpen(p, text);
		return false;
	}

	private static bool AssignPrefix(Player p, int slot, ItemData item, ref bool __result)
	{
		string text = IdOf(slot);
		if (text == null)
		{
			return true;
		}
		__result = Object.op_Implicit((Object)(object)p) && item != null && Equipment.Put(p, text, item);
		return false;
	}
}
[BepInPlugin("avesatanas.senealui.povskills", "SeneaLUI PoV 6.0 Bridge", "2.7.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	internal const string Guid = "avesatanas.senealui.povskills";

	internal static ManualLogSource Log;

	private void Awake()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		Harmony harmony = new Harmony("avesatanas.senealui.povskills");
		Part(harmony, "SkillsWindow", "Skills (gem board) window", SkillsBoard.Patch, "The Skills button beside Appearance and the gem board window it opens. Off: no button, and Path of Valheiman's gem board cannot be reached while SeneaL UI draws the inventory.");
		Part(harmony, "StatsWindow", "Stats (character sheet) window", SkillsBoard.PatchStats, "The Stats button beside Appearance and the character sheet window it opens. Off: no button, and Path of Valheiman's character sheet cannot be reached while SeneaL UI draws the inventory.");
		Part(harmony, "EquipmentCells", "quiver and belt lantern cells", NewCells.Patch, "The quiver and belt lantern cells among SeneaL UI's equipment cells. Off: both cells disappear from the equipment block; items already in them stay where Path of Valheiman keeps them.");
		Part(harmony, "BowsBeforeHoesQuivers", "BowsBeforeHoes quiver equipment", Quivers.PatchEquipment, "BowsBeforeHoes quivers in Path of Valheiman's quiver cell. Off: that cell takes only Path of Valheiman's own quivers.");
		Part(harmony, "HallsPins", "PoV Halls map icons", HallsPins.Patch, "Path of Valheiman's own artwork for Halls pins on SeneaL UI's map. Off: those pins use SeneaL UI's pin icons.");
		Part(harmony, "CraftPanelWindows", "Runic Anvil and Book of the Halls windows", CraftPanelWindows.Patch, "Showing the Runic Anvil, Book of the Halls and Halls shop in SeneaL UI's craft column. Off: those windows open behind SeneaL UI's crafting panel and cannot be used.");
		Part(harmony, "BallistaCount", "ballista count in the build panel", BallistaInfo.Patch, "The «Ballistas n/m» line in SeneaL UI's build panel. Off: the line is not shown.");
		Part(harmony, "TooltipRows", "PoV rows in item tooltips", ItemFacts.Patch, "The Path of Valheiman section in item tooltips while Shift is held. Off: tooltips show only what SeneaL UI itself lists.");
		Part(harmony, "PvpIcon", "PvP tab icon", PvpIcon.Patch, "The shield on the PvP tab while PvP is off. Off: the tab keeps SeneaL UI's sword either way.");
		Part(harmony, "TestCommand", "test command pov_halls_gate", TestCommands.Patch, "The pov_halls_gate console command. Off: the command does not exist.");
	}

	private void Part(Harmony harmony, string key, string name, Func<Harmony, string> patch, string what)
	{
		if (!((BaseUnityPlugin)this).Config.Bind<bool>("Parts", key, true, what + " Applies the next time the game starts.").Value)
		{
			Log.LogInfo((object)(name + ": off (switched off in the config)"));
			return;
		}
		string text;
		try
		{
			text = patch(harmony);
		}
		catch (Exception ex)
		{
			text = ex.Message;
		}
		if (text == null)
		{
			Log.LogInfo((object)(name + ": on"));
		}
		else
		{
			Log.LogError((object)(name + ": off (" + text + ")"));
		}
	}

	internal static void Guard(ref bool broken, string name, Action body)
	{
		if (broken)
		{
			return;
		}
		try
		{
			body();
		}
		catch (Exception ex)
		{
			broken = true;
			Log.LogError((object)(name + " turned off: " + ex));
		}
	}
}
internal static class PvpIcon
{
	private const int Tab = 4;

	private static readonly FieldRef<TabsView, List<Image>> Icons = AccessTools.FieldRefAccess<TabsView, List<Image>>("_tabIcons");

	private static Sprite _on;

	private static Sprite _off;

	private static bool _broken;

	internal static string Patch(Harmony harmony)
	{
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Expected O, but got Unknown
		MethodInfo methodInfo = AccessTools.Method(typeof(TabsView), "Tick", new Type[3]
		{
			typeof(bool),
			typeof(bool),
			typeof(float)
		}, (Type[])null);
		if (methodInfo == null)
		{
			return "SeneaL TabsView.Tick";
		}
		harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(PvpIcon), "TickPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		return null;
	}

	private static void TickPostfix(TabsView __instance, bool open)
	{
		if (!open)
		{
			return;
		}
		Plugin.Guard(ref _broken, "PvP tab icon", delegate
		{
			InventoryGui instance = InventoryGui.instance;
			List<Image> list = Icons.Invoke(__instance);
			if (Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)instance.m_pvp) && list.Count > 4 && Object.op_Implicit((Object)(object)list[4]))
			{
				Image val = list[4];
				if (!Object.op_Implicit((Object)(object)_off))
				{
					_on = val.sprite;
					_off = Phosphor.Get(Phosphor.Has("shield-check") ? "shield-check" : "shield");
					if (!Object.op_Implicit((Object)(object)_off))
					{
						return;
					}
				}
				Sprite val2 = (instance.m_pvp.isOn ? _on : _off);
				if ((Object)(object)val.sprite != (Object)(object)val2)
				{
					val.sprite = val2;
				}
			}
		});
	}
}
internal static class Quivers
{
	private const string Bbh = "Azumatt.BowsBeforeHoes";

	private static FieldInfo _prefabs;

	private static Func<Humanoid, ItemData> _bbhWorn;

	private static Func<Humanoid, ItemData> _povWorn;

	private static Func<ItemData, bool> _isBbh;

	private static readonly HashSet<string> Registered = new HashSet<string>(StringComparer.Ordinal);

	internal static ItemData Worn(Player player)
	{
		ItemData val = _bbhWorn?.Invoke((Humanoid)(object)player);
		if (val == null || !((Humanoid)player).GetInventory().ContainsItem(val))
		{
			return null;
		}
		return val;
	}

	internal static string PatchEquipment(Harmony harmony)
	{
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Expected O, but got Unknown
		//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Expected O, but got Unknown
		if (!Chainloader.PluginInfos.TryGetValue("Azumatt.BowsBeforeHoes", out var value))
		{
			return "BowsBeforeHoes absent";
		}
		Type type = ((object)value.Instance).GetType().Assembly.GetType("BowsBeforeHoes.Util.Functions");
		MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, "GetEquippedQuiver", (Type[])null, (Type[])null));
		MethodInfo methodInfo2 = ((type == null) ? null : AccessTools.Method(type, "IsQuiverSlot", new Type[1] { typeof(ItemData) }, (Type[])null));
		MethodInfo methodInfo3 = AccessTools.Method(typeof(QuiverSlot), "Get", (Type[])null, (Type[])null);
		_prefabs = AccessTools.Field(((object)value.Instance).GetType(), "QuiverList");
		if (methodInfo == null || methodInfo2 == null || methodInfo3 == null || _prefabs == null)
		{
			return "quiver equipment contract";
		}
		_bbhWorn = (Func<Humanoid, ItemData>)Delegate.CreateDelegate(typeof(Func<Humanoid, ItemData>), methodInfo);
		_povWorn = (Func<Humanoid, ItemData>)Delegate.CreateDelegate(typeof(Func<Humanoid, ItemData>), methodInfo3);
		_isBbh = (Func<ItemData, bool>)Delegate.CreateDelegate(typeof(Func<ItemData, bool>), methodInfo2);
		MethodInfo methodInfo4 = AccessTools.Method(typeof(ZNetScene), "Awake", (Type[])null, (Type[])null);
		HarmonyMethod val = new HarmonyMethod(typeof(Quivers), "Register", (Type[])null);
		val.priority = 0;
		val.after = new string[1] { "Azumatt.BowsBeforeHoes" };
		harmony.Patch((MethodBase)methodInfo4, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		MethodInfo methodInfo5 = AccessTools.Method(typeof(Humanoid), "EquipItem", (Type[])null, (Type[])null);
		val = new HarmonyMethod(typeof(Quivers), "OneQuiver", (Type[])null);
		val.priority = 0;
		val.after = new string[1] { "Azumatt.BowsBeforeHoes" };
		harmony.Patch((MethodBase)methodInfo5, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		return null;
	}

	private static void Register(ZNetScene __instance)
	{
		foreach (GameObject item in (IEnumerable<GameObject>)_prefabs.GetValue(null))
		{
			if (Object.op_Implicit((Object)(object)item) && Object.op_Implicit((Object)(object)__instance.GetPrefab(((Object)item).name)) && Registered.Add(((Object)item).name))
			{
				EquipmentApi.RegisterQuiver(((Object)item).name, 3, (Func<Player, ItemData, bool>)((Player player, ItemData item) => Worn(player) == item || (((Humanoid)player).EquipItem(item, true) && Worn(player) == item)), (Action<Player, ItemData>)delegate(Player player, ItemData item)
				{
					((Humanoid)player).UnequipItem(item, true);
				}, (Func<Player, ItemData, bool>)((Player player, ItemData item) => Worn(player) == item));
			}
		}
	}

	private static void OneQuiver(Humanoid __instance, ItemData item, bool __result)
	{
		if (!__result || item == null)
		{
			return;
		}
		Player val = (Player)(object)((__instance is Player) ? __instance : null);
		if (val == null)
		{
			return;
		}
		ItemData val2 = Worn(val);
		ItemData val3 = _povWorn((Humanoid)(object)val);
		if (val2 != null && val3 != null && val2 != val3)
		{
			if (val2 == item && _isBbh(item))
			{
				((Humanoid)val).UnequipItem(val3, false);
			}
			else if (val3 == item)
			{
				((Humanoid)val).UnequipItem(val2, false);
			}
		}
	}
}
internal static class SkillsBoard
{
	private sealed class Panel
	{
		public string Name;

		public string Type;

		public string Feature;

		public string TipKey;

		public string TipWord;

		public string Icon;

		public string IconFallback;

		public string TabIcon;

		public Type[] CtorTypes;

		public Func<RectTransform, object[]> CtorArgs;

		public ConstructorInfo Ctor;

		public MethodInfo Show;

		public MethodInfo Fit;

		public MethodInfo Tick;

		public MethodInfo Closed;

		public RectTransform Btn;

		public RectTransform Host;

		public Image BtnBg;

		public Dialog Dlg;

		public Tb[] Tabs;

		public object Board;

		public StatsPage Page;

		public float W = 640f;

		public float H = 820f;

		public bool Native;

		public bool Want;

		public bool Open;

		public bool Broken;

		public float SkinAt;

		public readonly ForeignSkin Skin = new ForeignSkin();

		public readonly Tip Tip = new Tip();
	}

	private const float TabGap = 6f;

	private static readonly FieldRef<InventoryView, RectTransform> LooksBtn = AccessTools.FieldRefAccess<InventoryView, RectTransform>("_looksBtn");

	private static readonly FieldRef<InventoryView, Sprite> DollN = AccessTools.FieldRefAccess<InventoryView, Sprite>("_dollN");

	private static readonly FieldRef<InventoryView, Sprite> DollH = AccessTools.FieldRefAccess<InventoryView, Sprite>("_dollH");

	private static readonly FieldInfo Dialogs = AccessTools.Field(typeof(InventoryGuiPatches), "_dialogs");

	private static readonly FieldInfo LooksDlg = AccessTools.Field(typeof(PovLooksView), "_dlg");

	private static readonly FieldInfo LooksWant = AccessTools.Field(typeof(PovLooksView), "_want");

	private static readonly Panel Gems = new Panel
	{
		Name = "Skills window",
		Type = "PassiveTree.Gems.GemBoardPanel",
		Feature = "gems",
		TipKey = "gem.tab",
		TipWord = "Skills",
		Icon = "hexagon",
		IconFallback = "diamond",
		TabIcon = "spark",
		CtorTypes = new Type[3]
		{
			typeof(RectTransform),
			typeof(TMP_FontAsset),
			typeof(InventoryGui)
		},
		CtorArgs = (RectTransform host) => new object[3]
		{
			host,
			null,
			InventoryGui.instance
		}
	};

	private static readonly Panel Stats = new Panel
	{
		Name = "Stats window",
		Type = "PassiveTree.UI.CharacterSheet",
		Native = true,
		W = 900f,
		H = 840f,
		TipKey = "charsheet.tab.stats",
		TipWord = "Stats",
		Icon = "chart-bar",
		IconFallback = "list",
		TabIcon = "rows",
		CtorTypes = new Type[3]
		{
			typeof(InventoryGui),
			typeof(RectTransform),
			typeof(TMP_FontAsset)
		},
		CtorArgs = (RectTransform host) => new object[3]
		{
			InventoryGui.instance,
			host,
			null
		}
	};

	private static readonly List<Panel> Panels = new List<Panel>();

	private static Tb[] _looksTabs;

	private static bool _looksTabsBroken;

	internal static string Patch(Harmony harmony)
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Expected O, but got Unknown
		string text = Hook(harmony, Gems);
		if (text != null)
		{
			return text;
		}
		MethodInfo methodInfo = AccessTools.Method("PassiveTree.Gear.Module:ShowSkills", (Type[])null, (Type[])null);
		if (methodInfo != null)
		{
			harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(SkillsBoard), "ShowSkillsPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		return null;
	}

	internal static string PatchStats(Harmony harmony)
	{
		return Hook(harmony, Stats);
	}

	private static string Hook(Harmony harmony, Panel p)
	{
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Expected O, but got Unknown
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Expected O, but got Unknown
		Type type = AccessTools.TypeByName(p.Type);
		if (type == null)
		{
			return "PoV " + p.Type;
		}
		p.Ctor = AccessTools.Constructor(type, p.CtorTypes, false);
		p.Show = AccessTools.Method(type, "Show", new Type[1] { typeof(bool) }, (Type[])null);
		p.Fit = AccessTools.Method(type, "Fit", new Type[2]
		{
			typeof(Vector2),
			typeof(Vector2)
		}, (Type[])null);
		p.Tick = AccessTools.Method(type, "Tick", new Type[1] { typeof(Player) }, (Type[])null);
		p.Closed = type.GetMethod("Closed", Type.EmptyTypes);
		if (p.Ctor == null || p.Show == null || p.Fit == null || p.Tick == null)
		{
			return "PoV " + p.Type + " members";
		}
		if (p.Native)
		{
			string text = StatsPage.Resolve(type);
			if (text != null)
			{
				return text;
			}
		}
		if (Panels.Count == 0)
		{
			MethodInfo methodInfo = AccessTools.Method(typeof(InventoryView), "TickPov", (Type[])null, (Type[])null);
			if (methodInfo == null)
			{
				return "SeneaL InventoryView.TickPov";
			}
			harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(SkillsBoard), "TickPovPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(InventoryGui), "Hide", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(SkillsBoard), "HidePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		Panels.Add(p);
		return null;
	}

	private static void ShowSkillsPostfix()
	{
		Go(Gems);
	}

	private static void TickPovPostfix(InventoryView __instance, Player player)
	{
		int num = 0;
		foreach (Panel p in Panels)
		{
			if (!p.Broken)
			{
				int at = num++;
				Plugin.Guard(ref p.Broken, p.Name, delegate
				{
					Tick(p, at, __instance, player);
				});
			}
			if (p.Broken)
			{
				Close(p);
				if (Object.op_Implicit((Object)(object)p.Btn))
				{
					((Component)p.Btn).gameObject.SetActive(false);
				}
			}
		}
		Plugin.Guard(ref _looksTabsBroken, "tabs in the Appearance window", LooksTabs);
	}

	private static void HidePostfix()
	{
		foreach (Panel panel in Panels)
		{
			Close(panel);
		}
	}

	private static void Close(Panel p)
	{
		p.Want = false;
		SetOpen(p, on: false);
		if (p.Dlg != null)
		{
			p.Dlg.Show(false);
			((Component)p.Dlg.Root).gameObject.SetActive(false);
		}
	}

	private static void Tick(Panel p, int slot, InventoryView view, Player player)
	{
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		RectTransform val = LooksBtn.Invoke(view);
		if (!Object.op_Implicit((Object)(object)val))
		{
			return;
		}
		if (!Object.op_Implicit((Object)(object)p.Btn))
		{
			BuildButton(p, view, val);
		}
		bool flag = ((Component)val).gameObject.activeSelf && Usable(p);
		if (((Component)p.Btn).gameObject.activeSelf != flag)
		{
			((Component)p.Btn).gameObject.SetActive(flag);
			if (!flag)
			{
				Tooltip.Exit(p.Btn);
			}
		}
		p.Btn.anchoredPosition = val.anchoredPosition - new Vector2((val.sizeDelta.x + 6f) * (float)(slot + 1), 0f);
		if (!flag || !Object.op_Implicit((Object)(object)player))
		{
			p.Want = false;
		}
		if (p.Dlg == null)
		{
			if (!p.Want)
			{
				return;
			}
			BuildWindow(p, view);
		}
		SetOpen(p, p.Want);
		p.Dlg.Show(p.Want);
		p.Dlg.Tick();
		if (p.Dlg.Shown)
		{
			for (int i = 0; i < p.Tabs.Length; i++)
			{
				LightTab(p.Tabs, i, p);
			}
			p.Fit.Invoke(p.Board, new object[2]
			{
				Vector2.zero,
				p.Host.sizeDelta
			});
			p.Tick.Invoke(p.Board, new object[1] { player });
			if (p.Page != null)
			{
				p.Page.Tick();
			}
			else
			{
				Restyle(p);
			}
		}
	}

	private static bool Usable(Panel p)
	{
		if (p.Feature != null)
		{
			return Pov.Has(p.Feature);
		}
		return true;
	}

	private static void BuildButton(Panel p, InventoryView view, RectTransform looks)
	{
		RectTransform btn = (p.Btn = Object.Instantiate<GameObject>(((Component)looks).gameObject, ((Transform)looks).parent, false).GetComponent<RectTransform>());
		((Object)btn).name = "pov" + p.TipWord.ToLowerInvariant() + "btn";
		p.BtnBg = ((Component)btn).GetComponent<Image>();
		Transform obj = ((Transform)btn).Find("i");
		Image val = ((obj != null) ? ((Component)obj).GetComponent<Image>() : null);
		if (Object.op_Implicit((Object)(object)val))
		{
			val.sprite = Phosphor.Get(Phosphor.Has(p.Icon) ? p.Icon : p.IconFallback);
		}
		UIInputHandler component = ((Component)btn).GetComponent<UIInputHandler>();
		component.m_onPointerEnter = delegate
		{
			if (Object.op_Implicit((Object)(object)p.BtnBg))
			{
				p.BtnBg.sprite = DollH.Invoke(view);
			}
			Tooltip.Show(btn, (Func<Tip>)(() => Tips.Text(p.Tip, Word(p), (string)null)), false);
		};
		component.m_onPointerExit = delegate
		{
			if (Object.op_Implicit((Object)(object)p.BtnBg))
			{
				p.BtnBg.sprite = DollN.Invoke(view);
			}
			Tooltip.Exit(btn);
		};
		component.m_onLeftClick = delegate
		{
			Tooltip.Exit(btn);
			Click.Play();
			if (p.Want)
			{
				p.Want = false;
			}
			else
			{
				Go(p);
			}
		};
	}

	private static void BuildWindow(Panel p, InventoryView view)
	{
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Expected O, but got Unknown
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		object? obj = Dialogs?.GetValue(null);
		RectTransform val = (RectTransform)((obj is RectTransform) ? obj : null);
		p.Dlg = new Dialog((Transform)(object)(Object.op_Implicit((Object)(object)val) ? val : view.Root), "pov" + p.TipWord.ToLowerInvariant(), p.W, p.H, (Action)delegate
		{
			p.Want = false;
		}, false, true)
		{
			FooterRight = true
		};
		p.Dlg.SetTitle(Word(p).ToUpperInvariant(), Loc.CloseBtn);
		p.Host = Ui.TL((Transform)(object)p.Dlg.Panel, "host", 28f, p.Dlg.ContentTop, p.Dlg.InnerW, p.Dlg.ContentH);
		p.Board = p.Ctor.Invoke(p.CtorArgs(p.Host));
		p.Show.Invoke(p.Board, new object[1] { false });
		if (p.Native)
		{
			CanvasGroup obj2 = ((Component)p.Host).gameObject.AddComponent<CanvasGroup>();
			obj2.alpha = 0f;
			bool blocksRaycasts = (obj2.interactable = false);
			obj2.blocksRaycasts = blocksRaycasts;
			p.Host.sizeDelta = new Vector2(600f, 700f);
			p.Page = new StatsPage(Ui.TL((Transform)(object)p.Dlg.Panel, "page", 28f, p.Dlg.ContentTop, p.Dlg.InnerW, p.Dlg.ContentH), p.Board);
		}
		else
		{
			Transform[] componentsInChildren = ((Component)p.Host).GetComponentsInChildren<Transform>(true);
			foreach (Transform val2 in componentsInChildren)
			{
				if (((Object)val2).name == "Opaque underlay" || ((Object)val2).name == "Crafting wood")
				{
					((Component)val2).gameObject.SetActive(false);
				}
			}
		}
		p.Tabs = MakeTabs(p.Dlg.Panel, p.H);
	}

	private static void SetOpen(Panel p, bool on)
	{
		if (p.Open != on && p.Board != null)
		{
			p.Open = on;
			p.Show.Invoke(p.Board, new object[1] { on });
			if (!on)
			{
				p.Closed?.Invoke(p.Board, null);
			}
		}
	}

	private static void Restyle(Panel p)
	{
		p.Skin.Tick((Transform)(object)p.Host);
		if (Time.unscaledTime < p.SkinAt)
		{
			return;
		}
		p.SkinAt = Time.unscaledTime + 0.5f;
		InventoryGui instance = InventoryGui.instance;
		object obj;
		if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)instance.m_recipeDecription))
		{
			obj = null;
		}
		else
		{
			Transform parent = instance.m_recipeDecription.transform.parent;
			obj = ((parent != null) ? ((Component)parent).GetComponent<Image>() : null);
		}
		Image val = (Image)obj;
		Sprite val2 = (Object.op_Implicit((Object)(object)val) ? val.sprite : null);
		Image[] componentsInChildren = ((Component)p.Host).GetComponentsInChildren<Image>(true);
		foreach (Image val3 in componentsInChildren)
		{
			Sprite sprite = val3.sprite;
			if (Object.op_Implicit((Object)(object)sprite) && ((Object)(object)sprite == (Object)(object)val2 || ((Object)sprite).name == "item_background"))
			{
				VanillaSkin.Glass(val3);
			}
		}
	}

	private static Tb[] MakeTabs(RectTransform panel, float height)
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Expected O, but got Unknown
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Expected O, but got Unknown
		//IL_0118: 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)
		Tb[] array = (Tb[])(object)new Tb[3]
		{
			new Tb((Transform)(object)panel, "povtab0", "tunic", (Action)delegate
			{
				Go(null);
			}, (Func<Tip>)null, (Action)null),
			new Tb((Transform)(object)panel, "povtab1", Gems.TabIcon, (Action)delegate
			{
				Go(Gems);
			}, (Func<Tip>)null, (Action)null),
			new Tb((Transform)(object)panel, "povtab2", Stats.TabIcon, (Action)delegate
			{
				Go(Stats);
			}, (Func<Tip>)null, (Action)null)
		};
		string[] array2 = new string[3]
		{
			Texts.Get("charsheet.tab.appearance", "Appearance"),
			Word(Gems),
			Word(Stats)
		};
		float num = 28f;
		float num2 = height - 28f - 50f + 7f;
		for (int num3 = 0; num3 < array.Length; num3++)
		{
			array[num3].SetLabel(array2[num3]);
			array[num3].Root.anchoredPosition = new Vector2(num, 0f - num2);
			num += array[num3].Root.sizeDelta.x + 6f;
		}
		return array;
	}

	private static void LightTab(Tb[] tabs, int i, Panel current)
	{
		Panel panel = i switch
		{
			2 => Stats, 
			1 => Gems, 
			_ => null, 
		};
		bool active = ((panel != null) ? (Panels.Contains(panel) && !panel.Broken && Usable(panel)) : (LooksDlg != null && LooksWant != null && InventoryGuiPatches.Looks != null));
		((Component)tabs[i].Root).gameObject.SetActive(active);
		tabs[i].SetLit(panel == current);
	}

	private static void LooksTabs()
	{
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		PovLooksView looks = InventoryGuiPatches.Looks;
		if (looks == null || LooksDlg == null || LooksWant == null || Panels.Count == 0)
		{
			return;
		}
		object? value = LooksDlg.GetValue(looks);
		Dialog val = (Dialog)((value is Dialog) ? value : null);
		if (val != null && val.Shown)
		{
			if (_looksTabs == null || !Object.op_Implicit((Object)(object)_looksTabs[0].Root))
			{
				_looksTabs = MakeTabs(val.Panel, val.Panel.sizeDelta.y);
			}
			for (int i = 0; i < _looksTabs.Length; i++)
			{
				LightTab(_looksTabs, i, null);
			}
		}
	}

	private static void Go(Panel target)
	{
		foreach (Panel panel in Panels)
		{
			panel.Want = panel == target && !panel.Broken;
		}
		PovLooksView looks = InventoryGuiPatches.Looks;
		if (looks != null)
		{
			LooksWant?.SetValue(looks, target == null);
		}
	}

	private static string Word(Panel p)
	{
		return Texts.Get(p.TipKey, p.TipWord);
	}
}
internal sealed class StatsPage
{
	private sealed class Card
	{
		public RectTransform Root;

		public Image Bg;

		public Image Icon;

		public TextMeshProUGUI Value;

		public TextMeshProUGUI Name;

		public TextMeshProUGUI Sub;

		public string Title;

		public Func<string> Body;

		public readonly Tip Tip = new Tip();
	}

	private sealed class Cell
	{
		public RectTransform Root;

		public Image Band;

		public TextMeshProUGUI Name;

		public TextMeshProUGUI Value;

		public object Entry;

		public readonly Tip Tip = new Tip();
	}

	private sealed class Head
	{
		public RectTransform Root;

		public TextMeshProUGUI Name;
	}

	private struct TileData
	{
		public string Value;

		public string Label;

		public string Sub;

		public Sprite Icon;

		public Func<string> Body;
	}

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

	private const float Gap = 10f;

	private const float HeadH = 44f;

	private const float RowH = 28f;

	private const float ValW = 150f;

	private const TextAlignmentOptions Left = (TextAlignmentOptions)257;

	private const TextAlignmentOptions Right = (TextAlignmentOptions)260;

	private static readonly Regex Foreign = new Regex("</?link[^>]*>|<sprite[^>]*>", RegexOptions.Compiled);

	private static readonly string[] TabKeys = new string[4] { "damage", "defence", "minions", "other" };

	private static readonly string[] TabWords = new string[4] { "Damage", "Defence", "Minions & Constructs", "Other" };

	private static FieldInfo _name;

	private static FieldInfo _level;

	private static FieldInfo _attrs;

	private static FieldInfo _vitals;

	private static FieldInfo _defences;

	private static FieldInfo _resists;

	private static FieldInfo _lists;

	private static FieldInfo _tValue;

	private static FieldInfo _tLabel;

	private static FieldInfo _tSub;

	private static FieldInfo _tIcon;

	private static FieldInfo _tClick;

	private static FieldInfo _tLive;

	private static FieldInfo _aValue;

	private static FieldInfo _aLabel;

	private static FieldInfo _aIcon;

	private static FieldInfo _aClick;

	private static FieldInfo _hoverText;

	private static FieldInfo _eHeader;

	private static FieldInfo _eLabel;

	private static FieldInfo _eValue;

	private static FieldInfo _eMeaning;

	private static FieldInfo _eSources;

	private static FieldInfo _eRow;

	private static MethodInfo _compose;

	private readonly object _sheet;

	private readonly RectTransform _root;

	private readonly float _w;

	private readonly float _listTop;

	private readonly Sprite _cardBg;

	private readonly Sprite _cardOn;

	private readonly TextMeshProUGUI _nameText;

	private readonly TextMeshProUGUI _levelText;

	private readonly List<Card>[] _cards = new List<Card>[4]
	{
		new List<Card>(),
		new List<Card>(),
		new List<Card>(),
		new List<Card>()
	};

	private readonly ChipBar _tabs;

	private readonly ScrollBox _box;

	private readonly List<Head> _heads = new List<Head>();

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

	private readonly StringBuilder _sig = new StringBuilder();

	private string _shown;

	private int _tab;

	private float _next;

	private static readonly float[] CardTop = new float[4] { 0f, 66f, 152f, 238f };

	private static readonly float[] CardH = new float[4] { 56f, 76f, 76f, 64f };

	internal static string Resolve(Type sheet)
	{
		Type nestedType = sheet.GetNestedType("Tile", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		Type nestedType2 = sheet.GetNestedType("AttrChip", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		Type nestedType3 = sheet.GetNestedType("StatHover", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		Type nestedType4 = sheet.GetNestedType("Entry", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		if (nestedType == null || nestedType2 == null || nestedType3 == null || nestedType4 == null)
		{
			return "PoV CharacterSheet parts";
		}
		_compose = AccessTools.Method(sheet, "Compose", (Type[])null, (Type[])null);
		FieldInfo[] array = new FieldInfo[24]
		{
			_name = sheet.GetField("nameText", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic),
			_level = sheet.GetField("levelText", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic),
			_attrs = sheet.GetField("attrs", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic),
			_vitals = sheet.GetField("vitals", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic),
			_defences = sheet.GetField("defences", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic),
			_resists = sheet.GetField("resists", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic),
			_lists = sheet.GetField("lists", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic),
			_tValue = nestedType.GetField("value", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic),
			_tLabel = nestedType.GetField("label", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic),
			_tSub = nestedType.GetField("sub", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic),
			_tIcon = nestedType.GetField("icon", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic),
			_tClick = nestedType.GetField("click", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic),
			_tLive = nestedType.GetField("Live", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic),
			_aValue = nestedType2.GetField("value", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic),
			_aLabel = nestedType2.GetField("label", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic),
			_aIcon = nestedType2.GetField("icon", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic),
			_aClick = nestedType2.GetField("click", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic),
			_hoverText = nestedType3.GetField("Text", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic),
			_eHeader = nestedType4.GetField("Header", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic),
			_eLabel = nestedType4.GetField("Label", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic),
			_eValue = nestedType4.GetField("Value", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic),
			_eMeaning = nestedType4.GetField("Meaning", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic),
			_eSources = nestedType4.GetField("Sources", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic),
			_eRow = nestedType4.GetField("Row", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
		};
		if (!(_compose == null) && Array.IndexOf(array, null) < 0)
		{
			return null;
		}
		return "PoV CharacterSheet members";
	}

	internal StatsPage(RectTransform root, object sheet)
	{
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Expected O, but got Unknown
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Expected O, but got Unknown
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		_root = root;
		_sheet = sheet;
		_w = root.sizeDelta.x;
		_cardBg = Skin.Sliced(40, Styles.RowHover, -1);
		_cardOn = Skin.Sliced(40, Styles.RowOn, -1);
		TextStyle heading = TextStyles.Heading;
		TextStyle legend = TextStyles.Legend;
		_nameText = Ui.Label((Transform)(object)root, "name", heading, 0f, 0f, 6f + heading.Baseline(1.2f), _w * 0.5f, (TextAlignmentOptions)257);
		_levelText = Ui.Label((Transform)(object)root, "level", legend, 0f, 0f, 36f + legend.Baseline(1.2f), _w * 0.5f, (TextAlignmentOptions)257);
		((Graphic)_levelText).color = Palette.Gold;
		_tabs = new ChipBar((Transform)(object)root, "tabs", new string[TabKeys.Length], (Action<int>)delegate(int i)
		{
			_tab = i;
			_shown = null;
			_box.ScrollTop();
		});
		_tabs.Show = new bool[TabKeys.Length];
		_tabs.Root.anchoredPosition = new Vector2(0f, -312f);
		_listTop = 350f;
		_box = new ScrollBox((Transform)(object)root, "rows", _w - 11f, root.sizeDelta.y - _listTop, 96f);
		_box.Place(0f, _listTop, _w - 11f, root.sizeDelta.y - _listTop, 8f);
	}

	internal void Tick()
	{
		//IL_0213: Unknown result type (might be due to invalid IL or missing references)
		//IL_022f: Unknown result type (might be due to invalid IL or missing references)
		_box.Tick((Component)(object)_root);
		if (Time.unscaledTime < _next && _shown != null)
		{
			return;
		}
		_next = Time.unscaledTime + 0.25f;
		List<TileData> list = Tiles((IEnumerable)_attrs.GetValue(_sheet), _aValue, _aLabel, null, _aIcon, _aClick, null);
		List<TileData> list2 = Tiles((IEnumerable)_vitals.GetValue(_sheet), _tValue, _tLabel, _tSub, _tIcon, _tClick, _tLive);
		List<TileData> list3 = Tiles((IEnumerable)_defences.GetValue(_sheet), _tValue, _tLabel, _tSub, _tIcon, _tClick, _tLive);
		List<TileData> list4 = Tiles((IEnumerable)_resists.GetValue(_sheet), _tValue, _tLabel, _tSub, _tIcon, _tClick, _tLive);
		IList[] array = new IList[TabKeys.Length];
		foreach (DictionaryEntry item in (IDictionary)_lists.GetValue(_sheet))
		{
			int num = Convert.ToInt32(item.Key);
			if (num >= 0 && num < array.Length)
			{
				array[num] = item.Value as IList;
			}
		}
		for (int i = 0; i < array.Length; i++)
		{
			_tabs.Show[i] = array[i] != null && array[i].Count > 0;
		}
		if (!_tabs.Show[_tab])
		{
			_tab = Mathf.Max(0, Array.IndexOf(_tabs.Show, value: true));
		}
		string text = ((TMP_Text)_name.GetValue(_sheet)).text;
		string text2 = ((TMP_Text)_level.GetValue(_sheet)).text;
		_sig.Length = 0;
		_sig.Append(text).Append('|').Append(text2)
			.Append('|')
			.Append(_tab);
		List<TileData>[] array2 = new List<TileData>[4] { list, list2, list3, list4 };
		for (int j = 0; j < array2.Length; j++)
		{
			foreach (TileData item2 in array2[j])
			{
				_sig.Append('|').Append(item2.Value).Append(item2.Label)
					.Append(item2.Sub);
			}
		}
		if (array[_tab] != null)
		{
			foreach (object item3 in array[_tab])
			{
				_sig.Append('|').Append(_eLabel.GetValue(item3)).Append(_eValue.GetValue(item3));
			}
		}
		string text3 = _sig.ToString();
		if (!(text3 == _shown))
		{
			_shown = text3;
			((TMP_Text)_nameText).text = text;
			((TMP_Text)_levelText).text = text2;
			Cards(0, list, _w - ((float)list.Count * 120f + (float)(list.Count - 1) * 10f), 120f);
			Cards(1, list2, 0f, 0f);
			Cards(2, list3, 0f, 0f);
			Cards(3, list4, 0f, 0f);
			string[] array3 = new string[TabKeys.Length];
			for (int k = 0; k < array3.Length; k++)
			{
				array3[k] = Texts.Get("charsheet.tab." + TabKeys[k], TabWords[k]);
			}
			_tabs.SetLabels(array3);
			_tabs.SetOn(_tab);
			Rows(array[_tab]);
		}
	}

	private static List<TileData> Tiles(IEnumerable tiles, FieldInfo value, FieldInfo label, FieldInfo sub, FieldInfo icon, FieldInfo click, FieldInfo live)
	{
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		List<TileData> list = new List<TileData>();
		foreach (object tile in tiles)
		{
			if (tile != null && (!(live != null) || (bool)live.GetValue(tile)))
			{
				object value2 = click.GetValue(tile);
				object? value3 = icon.GetValue(tile);
				Image val = (Image)((value3 is Image) ? value3 : null);
				list.Add(new TileData
				{
					Value = ((TMP_Text)value.GetValue(tile)).text,
					Label = ((TMP_Text)label.GetValue(tile)).text,
					Sub = ((sub == null) ? "" : ((TMP_Text)sub.GetValue(tile)).text),
					Icon = ((Object.op_Implicit((Object)(object)val) && ((Behaviour)val).enabled) ? val.sprite : null),
					Body = ((value2 == null) ? null : (_hoverText.GetValue(value2) as Func<string>))
				});
			}
		}
		return list;
	}

	private void Cards(int row, List<TileData> data, float left, float fixedW)
	{
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_023b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0245: Unknown result type (might be due to invalid IL or missing references)
		List<Card> list = _cards[row];
		float num = CardH[row];
		float num2 = ((fixedW > 0f) ? fixedW : ((_w - 10f * (float)Mathf.Max(0, data.Count - 1)) / (float)Mathf.Max(1, data.Count)));
		for (int i = 0; i < data.Count; i++)
		{
			if (i == list.Count)
			{
				list.Add(NewCard(row + "_" + i, num));
			}
			Card card = list[i];
			TileData tileData = data[i];
			((Component)card.Root).gameObject.SetActive(true);
			card.Root.anchoredPosition = new Vector2(left + (float)i * (num2 + 10f), 0f - CardTop[row]);
			card.Root.sizeDelta = new Vector2(num2, num);
			bool flag = Object.op_Implicit((Object)(object)tileData.Icon);
			((Component)card.Icon).gameObject.SetActive(flag);
			if (flag)
			{
				card.Icon.sprite = tileData.Icon;
			}
			float num3 = num2 - 28f - (flag ? 30f : 0f);
			((TMP_Text)card.Value).rectTransform.sizeDelta = new Vector2(num3, ((TMP_Text)card.Value).rectTransform.sizeDelta.y);
			((TMP_Text)card.Value).text = tileData.Value;
			((TMP_Text)card.Name).text = (tileData.Label ?? "").ToUpperInvariant();
			((TMP_Text)card.Sub).text = tileData.Sub ?? "";
			float num4 = (string.IsNullOrEmpty(tileData.Sub) ? 0f : Mathf.Min(num2 * 0.6f, Ui.Measure(card.Sub, tileData.Sub).x + 4f));
			((TMP_Text)card.Sub).rectTransform.sizeDelta = new Vector2(num4, ((TMP_Text)card.Sub).rectTransform.sizeDelta.y);
			((TMP_Text)card.Name).rectTransform.sizeDelta = new Vector2(num2 - 28f - num4, ((TMP_Text)card.Name).rectTransform.sizeDelta.y);
			card.Title = tileData.Label;
			card.Body = tileData.Body;
		}
		for (int j = data.Count; j < list.Count; j++)
		{
			((Component)list[j].Root).gameObject.SetActive(false);
		}
	}

	private Card NewCard(string id, float h)
	{
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_021c: Unknown result type (might be due to invalid IL or missing references)
		Card c = new Card();
		TextStyle skillLevel = TextStyles.SkillLevel;
		TextStyle cardLabel = TextStyles.CardLabel;
		TextStyle legend = TextStyles.Legend;
		c.Root = Ui.TL((Transform)(object)_root, "card" + id, 0f, 0f, 100f, h);
		c.Bg = Ui.Img(c.Root, _cardBg, Color.white);
		c.Bg.type = (Type)1;
		((Graphic)c.Bg).raycastTarget = true;
		c.Value = Ui.Label((Transform)(object)c.Root, "v", skillLevel, 0f, 14f, 8f + skillLevel.Baseline(1.1f), 100f, (TextAlignmentOptions)257);
		((TMP_Text)c.Value).enableAutoSizing = true;
		((TMP_Text)c.Value).fontSizeMax = skillLevel.Size;
		((TMP_Text)c.Value).fontSizeMin = 12f;
		((TMP_Text)c.Value).textWrappingMode = (TextWrappingModes)0;
		float num = h - 12f - cardLabel.Size * 1.2f;
		c.Name = Ui.Label((Transform)(object)c.Root, "n", cardLabel, 0f, 14f, num + cardLabel.Baseline(1.2f), 100f, (TextAlignmentOptions)257);
		((TMP_Text)c.Name).overflowMode = (TextOverflowModes)1;
		((TMP_Text)c.Name).textWrappingMode = (TextWrappingModes)0;
		c.Sub = Ui.Label((Transform)(object)c.Root, "s", legend, 1f, -14f, num + legend.Baseline(1.2f), 100f, (TextAlignmentOptions)260);
		((TMP_Text)c.Sub).textWrappingMode = (TextWrappingModes)0;
		c.Icon = Ui.Icon((Transform)(object)c.Root, "i", (Sprite)null, Color.white, 1f, 1f, -12f, -10f, 24f);
		c.Icon.preserveAspect = true;
		UIInputHandler obj = ((Component)c.Root).gameObject.AddComponent<UIInputHandler>();
		obj.m_onPointerEnter = delegate
		{
			c.Bg.sprite = _cardOn;
		};
		obj.m_onPointerExit = delegate
		{
			c.Bg.sprite = _cardBg;
		};
		Tooltip.Bind(obj, c.Root, (Func<Tip>)(() => Tips.Text(c.Tip, c.Title, Clean(c.Body?.Invoke()))), false);
		return c;
	}

	private void Rows(IList entries)
	{
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Floor((_w - 11f - 10f) * 0.5f);
		int num2 = 0;
		int num3 = 0;
		int num4 = 0;
		float num5 = 0f;
		if (entries != null)
		{
			foreach (object entry in entries)
			{
				string s = _eLabel.GetValue(entry) as string;
				if ((bool)_eHeader.GetValue(entry))
				{
					if (num4 == 1)
					{
						num5 += 28f;
					}
					num4 = 0;
					if (num2 == _heads.Count)
					{
						_heads.Add(NewHead(num2));
					}
					Head head = _heads[num2++];
					((Component)head.Root).gameObject.SetActive(true);
					head.Root.anchoredPosition = new Vector2(0f, 0f - num5);
					((TMP_Text)head.Name).text = Clean(s);
					num5 += 44f;
					continue;
				}
				if (num3 == _cells.Count)
				{
					_cells.Add(NewCell(num3, num));
				}
				Cell cell = _cells[num3++];
				((Component)cell.Root).gameObject.SetActive(true);
				cell.Root.anchoredPosition = new Vector2((float)num4 * (num + 10f), 0f - num5);
				((TMP_Text)cell.Name).text = Clean(s);
				((TMP_Text)cell.Value).text = Clean(_eValue.GetValue(entry) as string);
				cell.Entry = entry;
				if (num4 == 1)
				{
					num5 += 28f;
				}
				num4 = 1 - num4;
			}
		}
		if (num4 == 1)
		{
			num5 += 28f;
		}
		for (int i = num2; i < _heads.Count; i++)
		{
			((Component)_heads[i].Root).gameObject.SetActive(false);
		}
		for (int j = num3; j < _cells.Count; j++)
		{
			((Component)_cells[j].Root).gameObject.SetActive(false);
		}
		_box.SetContentHeight(num5 + 4f);
	}

	private Head NewHead(int n)
	{
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		TextStyle heading = TextStyles.Heading;
		float num = _w - 11f;
		Head obj = new Head
		{
			Root = Ui.TL((Transform)(object)_box.Content, "h" + n, 0f, 0f, num, 44f)
		};
		obj.Name = Ui.Label((Transform)(object)obj.Root, "n", heading, 0f, 0f, 8f + heading.Baseline(1.2f), num, (TextAlignmentOptions)257);
		Ui.Img(Ui.TL((Transform)(object)obj.Root, "l", 0f, 36f, num, 1f), (Sprite)null, Palette.Rgba(214, 178, 110, 0.22f));
		return obj;
	}

	private Cell NewCell(int n, float colW)
	{
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		TextStyle statLabel = TextStyles.StatLabel;
		TextStyle statValue = TextStyles.StatValue;
		Cell cell = new Cell
		{
			Root = Ui.TL((Transform)(object)_box.Content, "c" + n, 0f, 0f, colW, 28f)
		};
		cell.Band = Ui.Img(Ui.Stretch((Transform)(object)cell.Root, "band", 0f), (Sprite)null, Palette.Clear);
		((Graphic)cell.Band).raycastTarget = true;
		cell.Name = Ui.Label((Transform)(object)cell.Root, "n", statLabel, 0f, 14f, (28f - statLabel.Size * 1.3f) * 0.5f + statLabel.Baseline(1.3f), colW - 150f - 18f, (TextAlignmentOptions)257);
		((TMP_Text)cell.Name).overflowMode = (TextOverflowModes)1;
		((TMP_Text)cell.Name).textWrappingMode = (TextWrappingModes)0;
		cell.Value = Ui.Label((Transform)(object)cell.Root, "v", statValue, 0f, colW - 150f - 6f, (28f - statValue.Size * 1.3f) * 0.5f + statValue.Baseline(1.3f), 150f, (TextAlignmentOptions)260);
		((TMP_Text)cell.Value).textWrappingMode = (TextWrappingModes)0;
		((Graphic)Ui.Img(Ui.TL((Transform)(object)cell.Root, "l", 6f, 27f, colW - 12f, 1f), (Sprite)null, Palette.Rgba(214, 178, 110, 0.08f))).raycastTarget = false;
		UIInputHandler obj = ((Component)cell.Root).gameObject.AddComponent<UIInputHandler>();
		obj.m_onPointerEnter = delegate
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			((Graphic)cell.Band).color = new Color(0.85f, 0.72f, 0.43f, 0.07f);
		};
		obj.m_onPointerExit = delegate
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			((Graphic)cell.Band).color = Palette.Clear;
		};
		Tooltip.Bind(obj, cell.Root, (Func<Tip>)(() => Tips.Text(cell.Tip, ((TMP_Text)cell.Name).text, Explain(cell.Entry))), false);
		return cell;
	}

	private string Explain(object entry)
	{
		if (entry == null)
		{
			return "";
		}
		string text = Clean(_eMeaning.GetValue(entry) as string);
		string text2 = Clean(_compose.Invoke(_sheet, new object[3]
		{
			"",
			_eSources.GetValue(entry),
			_eRow.GetValue(entry)
		}) as string);
		if (text.Length <= 0 || text2.Length <= 0)
		{
			return text + text2;
		}
		return text + "\n\n" + text2;
	}

	private static string Clean(string s)
	{
		if (!string.IsNullOrEmpty(s))
		{
			return Foreign.Replace(s, "").Trim();
		}
		return "";
	}
}
internal static class TestCommands
{
	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static ConsoleEvent <>9__2_0;

		internal void <Register>b__2_0(ConsoleEventArgs args)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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)
			Player localPlayer = Player.m_localPlayer;
			if (Object.op_Implicit((Object)(object)localPlayer))
			{
				HallsGate val = HallsGate.SpawnAt(((Component)localPlayer).transform.position + ((Component)localPlayer).transform.forward * 4f, ((Component)localPlayer).transform.eulerAngles.y + 180f);
				args.Context.AddString(Object.op_Implicit((Object)(object)val) ? "gate placed: use it (E) for the Book of the Halls, Shift+E for the lobby" : "PoV has no gate prefab yet");
			}
		}
	}

	private static bool _registered;

	internal static string Patch(Harmony harmony)
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Expected O, but got Unknown
		MethodInfo methodInfo = AccessTools.Method(typeof(Terminal), "InitTerminal", (Type[])null, (Type[])null);
		if (methodInfo == null)
		{
			return "Terminal.InitTerminal";
		}
		harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(TestCommands), "Register", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		return null;
	}

	private static void Register()
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Expected O, but got Unknown
		if (_registered)
		{
			return;
		}
		_registered = true;
		object obj = <>c.<>9__2_0;
		if (obj == null)
		{
			ConsoleEvent val = delegate(ConsoleEventArgs args)
			{
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_002f: 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)
				Player localPlayer = Player.m_localPlayer;
				if (Object.op_Implicit((Object)(object)localPlayer))
				{
					HallsGate val2 = HallsGate.SpawnAt(((Component)localPlayer).transform.position + ((Component)localPlayer).transform.forward * 4f, ((Component)localPlayer).transform.eulerAngles.y + 180f);
					args.Context.AddString(Object.op_Implicit((Object)(object)val2) ? "gate placed: use it (E) for the Book of the Halls, Shift+E for the lobby" : "PoV has no gate prefab yet");
				}
			};
			<>c.<>9__2_0 = val;
			obj = (object)val;
		}
		new ConsoleCommand("pov_halls_gate", "- a Halls of Oaths gate 4 m in front of you, themed for this biome", (ConsoleEvent)obj, true, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
	}
}