Decompiled source of CraftTodo v0.8.4

CraftTodo.dll

Decompiled 5 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LazyBearTechnology;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CraftTodo")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.8.4.0")]
[assembly: AssemblyInformationalVersion("0.8.4+f45ba5c9d145406612c6da1a8deca54190c7a389")]
[assembly: AssemblyProduct("CraftTodo")]
[assembly: AssemblyTitle("CraftTodo")]
[assembly: AssemblyVersion("0.8.4.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CraftTodo
{
	internal static class Compat
	{
		private readonly struct GameField
		{
			public readonly Type Owner;

			public readonly string Name;

			public readonly Type Expected;

			public readonly string Effect;

			public GameField(Type owner, string name, Type expected, string effect)
			{
				Owner = owner;
				Name = name;
				Expected = expected;
				Effect = effect;
			}
		}

		private const BindingFlags AnyMethod = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		private static readonly string[] PatchMethodNames = new string[4] { "Prefix", "Postfix", "Finalizer", "Transpiler" };

		private static readonly HashSet<string> reported = new HashSet<string>();

		private static readonly Dictionary<Type, string> HookEffects = new Dictionary<Type, string>
		{
			[typeof(HandleOutputPatch)] = "finished crafts and repairs won't be counted",
			[typeof(HandleOutputConveyorPatch)] = "crafts finished on conveyors won't be counted",
			[typeof(BuildBuildingPatch)] = "placed buildings won't be counted",
			[typeof(LazyInputUpdatePatch)] = "typing in the picker's search box may also move the player, and the gamepad can't be used on the panel and the picker"
		};

		private static readonly GameField[] GameFields = new GameField[24]
		{
			new GameField(typeof(GUIElements), "uiFitter", typeof(Component), "the windows are parented to the game's UI root directly"),
			new GameField(typeof(UIPrefabsPooler), "poolsCache", typeof(IDictionary), "the game's item cells and craft tabs can't be found, so cells and the picker's sections fall back to plain widgets"),
			new GameField(typeof(UICraftSelectionWindow), "closeButton", typeof(LazyButton), "the close button is a plain one"),
			new GameField(typeof(UICraftSelectionWindow), "startCraftButton", typeof(LazyButton), "the Add button is a plain one"),
			new GameField(typeof(UICraftSelectionWindow), "startCraftButtonText", typeof(TextMeshProUGUI), "the Add button's label may keep the game's text"),
			new GameField(typeof(UICraftSelectionWindow), "plusCraftButton", typeof(LazyButton), "the + button is a plain one"),
			new GameField(typeof(UICraftSelectionWindow), "minusCraftButton", typeof(LazyButton), "the - button is a plain one"),
			new GameField(typeof(UICraftSelectionWindow), "headerLabel", typeof(TextMeshProUGUI), "titles use a fallback font"),
			new GameField(typeof(UICraftWindow), "closeButton", typeof(LazyButton), "the close button is a plain one"),
			new GameField(typeof(UICraftWindow), "uiInfoWidget", typeof(UIInfoWidget), "body and small text use a fallback font"),
			new GameField(typeof(UICraftWindow), "craftScrollRect", typeof(ScrollRect), "lists have no game scrollbar and no list width to copy"),
			new GameField(typeof(UICraftWindow), "craftListContent", typeof(GameObject), "list layouts have no game template to copy"),
			new GameField(typeof(UIInfoWidget), "description", typeof(TextMeshProUGUI), "body and small text use a fallback font"),
			new GameField(typeof(UIInfoWidget), "descriptionTick", typeof(TextMeshProUGUI), "small text uses the body style"),
			new GameField(typeof(UICraftsTabWidget), "defaultTabBgIcon", typeof(Sprite), "workbench sections lose their tab background"),
			new GameField(typeof(UICraftsTabWidget), "craftsParent", typeof(Transform), "the picker draws plain recipe grids instead of the game's tab sections"),
			new GameField(typeof(UICraftPreviewItemCell), "tabButton", typeof(LazyButton), "recipe cells may show the game's tab button"),
			new GameField(typeof(UICraftPreviewItemCell), "uknownCraftBlocker", typeof(GameObject), "recipe cells may show a locked overlay"),
			new GameField(typeof(UICraftPreviewItemCell), "canNotStartCraftBlocker", typeof(GameObject), "recipe cells may show a can't-craft overlay"),
			new GameField(typeof(UICraftPreviewItemCell), "customImageNonInteractableBlocker", typeof(GameObject), "recipe cells may show a non-interactable overlay"),
			new GameField(typeof(GenericWindowLayout), "layoutGroupTopPaddingWithHeader", typeof(int), "the window's content starts at a default offset below the header"),
			new GameField(typeof(GenericWindowLayout), "header", typeof(GameObject), "the window header can't be copied, so a plain one is drawn"),
			new GameField(typeof(LazyWidget<UICraftPreviewItemCellData>), "data", typeof(UICraftPreviewItemCellData), "the picker draws plain recipe grids instead of the game's tab sections"),
			new GameField(typeof(DropData), "<IsDroppedFromPlayer>k__BackingField", typeof(bool), "items taken out of the chests are scattered by the game's own kick and search, so they may land far from the player")
		};

		internal static void Run(Harmony harmony)
		{
			try
			{
				List<string> list = new List<string>();
				int num = 0;
				int num2 = 0;
				foreach (Type item in HookClasses())
				{
					num++;
					string value;
					string effect = (HookEffects.TryGetValue(item, out value) ? value : "part of the mod stops working");
					List<string> list2 = InspectHook(item);
					if (list2.Count == 0)
					{
						try
						{
							harmony.CreateClassProcessor(item).Patch();
							num2++;
						}
						catch (Exception e)
						{
							list2.Add(Describe(item) + ": " + FirstLine(e));
							goto IL_0098;
						}
						continue;
					}
					goto IL_0098;
					IL_0098:
					list.AddRange(list2.Select((string p) => "Hook " + p + " (" + effect + ")"));
				}
				int checkedCount;
				List<string> list3 = InspectFields(out checkedCount);
				foreach (string item2 in list)
				{
					Plugin.Log.LogError((object)item2);
				}
				foreach (string item3 in list3)
				{
					Plugin.Log.LogWarning((object)item3);
				}
				string text = "game " + Application.version + ", Assembly-CSharp " + typeof(CraftComponent).Assembly.ManifestModule.ModuleVersionId.ToString("N").Substring(0, 8);
				string text2 = $"Compatibility check: {num2}/{num} hooks installed, {checkedCount - list3.Count}/{checkedCount} game fields found ({text})";
				if (list.Count + list3.Count == 0)
				{
					Plugin.Log.LogInfo((object)(text2 + ", all OK"));
				}
				else
				{
					Plugin.Log.LogWarning((object)(text2 + ". The game has probably been updated; the mod still loads but is partly degraded, see above."));
				}
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Compatibility check failed: {arg}");
			}
		}

		internal static void MissingField(Type type, string name)
		{
			if (reported.Add(type.Name + "." + name))
			{
				Plugin.Log.LogWarning((object)("Game field " + type.Name + "." + name + " not found"));
			}
		}

		internal static IEnumerable<Type> HookClasses()
		{
			return (from t in AccessTools.GetTypesFromAssembly(typeof(Compat).Assembly)
				where t.GetCustomAttributes(typeof(HarmonyPatch), inherit: false).Length != 0
				select t).OrderBy<Type, string>((Type t) => t.FullName, StringComparer.Ordinal);
		}

		internal static List<string> InspectHook(Type patch)
		{
			List<string> list = new List<string>();
			string text = Describe(patch);
			MethodBase methodBase;
			try
			{
				methodBase = ResolveTarget(HarmonyMethodExtensions.GetMergedFromType(patch));
			}
			catch (Exception e)
			{
				list.Add(text + ": " + FirstLine(e));
				return list;
			}
			if (methodBase == null)
			{
				list.Add(text + ": target method not found");
				return list;
			}
			ParameterInfo[] parameters = methodBase.GetParameters();
			foreach (MethodInfo item in from m in patch.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
				where PatchMethodNames.Contains(m.Name)
				select m)
			{
				ParameterInfo[] parameters2 = item.GetParameters();
				foreach (ParameterInfo p in parameters2)
				{
					if (p.Name.StartsWith("___", StringComparison.Ordinal))
					{
						string text2 = p.Name.Substring(3);
						FieldInfo fieldInfo = AccessTools.Field(methodBase.DeclaringType, text2);
						Type type = (p.ParameterType.IsByRef ? p.ParameterType.GetElementType() : p.ParameterType);
						if (fieldInfo == null)
						{
							list.Add(text + ": field '" + text2 + "' (injected as " + p.Name + ") not found");
						}
						else if (!type.IsAssignableFrom(fieldInfo.FieldType))
						{
							list.Add(text + ": field '" + text2 + "' is now " + fieldInfo.FieldType.Name + ", the patch expects " + type.Name);
						}
					}
					else if (!p.Name.StartsWith("__", StringComparison.Ordinal) && parameters.All((ParameterInfo tp) => tp.Name != p.Name))
					{
						list.Add(text + ": parameter '" + p.Name + "' no longer exists on the target");
					}
				}
			}
			return list;
		}

		internal static List<string> InspectFields(out int checkedCount)
		{
			checkedCount = GameFields.Length;
			List<string> list = new List<string>();
			GameField[] gameFields = GameFields;
			for (int i = 0; i < gameFields.Length; i++)
			{
				GameField gameField = gameFields[i];
				string text = gameField.Owner.Name + "." + gameField.Name;
				FieldInfo fieldInfo = AccessTools.Field(gameField.Owner, gameField.Name);
				if (fieldInfo == null)
				{
					reported.Add(text);
					list.Add("Game field " + text + " not found: " + gameField.Effect);
				}
				else if (!gameField.Expected.IsAssignableFrom(fieldInfo.FieldType))
				{
					reported.Add(text);
					list.Add("Game field " + text + " is now " + fieldInfo.FieldType.Name + ", expected " + gameField.Expected.Name + ": " + gameField.Effect);
				}
			}
			return list;
		}

		private static MethodBase ResolveTarget(HarmonyMethod info)
		{
			if (info?.declaringType == null || info.methodName == null)
			{
				return null;
			}
			return AccessTools.DeclaredMethod(info.declaringType, info.methodName, info.argumentTypes, (Type[])null);
		}

		private static string Describe(Type patch)
		{
			HarmonyMethod mergedFromType = HarmonyMethodExtensions.GetMergedFromType(patch);
			if (!(mergedFromType?.declaringType != null) || mergedFromType.methodName == null)
			{
				return patch.Name;
			}
			return mergedFromType.declaringType.Name + "." + mergedFromType.methodName;
		}

		private static string FirstLine(Exception e)
		{
			string text = (e.Message ?? "").Split('\n')[0].Trim();
			return e.GetType().Name + ": " + text;
		}
	}
	internal sealed class DropSpots
	{
		private const int GroundMask = 7424;

		private const int ObstacleMask = 16843008;

		private const int SightMask = 3328;

		private const float Margin = 0.15f;

		private static readonly float[] Rings = new float[6] { 0.9f, 1.2f, 1.5f, 1.8f, 2.1f, 2.4f };

		private const float AngleStep = 15f;

		private static readonly Vector2 Spacing = new Vector2(0.9f, 0.5f);

		private readonly Vector3 origin;

		private readonly List<Vector3> candidates = new List<Vector3>();

		private readonly List<Vector3> taken = new List<Vector3>();

		private int next;

		public bool RanOut { get; private set; }

		public DropSpots(Vector3 playerPos, Vector2 facing)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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_0049: 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_0093: 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_00a5: 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_00ac: 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)
			origin = playerPos;
			Vector3 back = default(Vector3);
			((Vector3)(ref back))..ctor(facing.x, 0f, facing.y);
			if (((Vector3)(ref back)).sqrMagnitude < 0.0001f)
			{
				back = Vector3.back;
			}
			((Vector3)(ref back)).Normalize();
			float[] rings = Rings;
			foreach (float num in rings)
			{
				for (int j = 0; j < Mathf.RoundToInt(24f); j++)
				{
					float num2 = (float)((j != 0) ? ((j % 2 == 1) ? ((j + 1) / 2) : (-(j / 2))) : 0) * 15f;
					candidates.Add(playerPos + Quaternion.Euler(0f, num2, 0f) * back * num);
				}
			}
		}

		public bool TryTake(out Vector3 spot)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			while (next < candidates.Count)
			{
				Vector3 c = candidates[next++];
				if (!TooCloseToTaken(c) && Usable(c, out spot))
				{
					taken.Add(spot);
					return true;
				}
			}
			RanOut = true;
			spot = default(Vector3);
			return false;
		}

		private bool TooCloseToTaken(Vector3 c)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			foreach (Vector3 item in taken)
			{
				if (Mathf.Abs(item.x - c.x) < Spacing.x && Mathf.Abs(item.z - c.z) < Spacing.y)
				{
					return true;
				}
			}
			return false;
		}

		private bool Usable(Vector3 c, out Vector3 spot)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			spot = default(Vector3);
			if (!GroundAt(c, out var ground))
			{
				return false;
			}
			Vector3 val = LazyConsts.BIG_DROP_COLLIDER_SIZE / 2f + new Vector3(0.15f, 0f, 0.15f);
			if (Physics.OverlapBox(ground, val, Quaternion.identity, 16843008).Length != 0)
			{
				return false;
			}
			Vector3 val2 = origin + Vector3.up * 0.6f;
			Vector3 val3 = ground + Vector3.up * 0.6f - val2;
			float magnitude = ((Vector3)(ref val3)).magnitude;
			if (magnitude > 0.001f && Physics.Raycast(val2, val3 / magnitude, magnitude, 3328, (QueryTriggerInteraction)1))
			{
				return false;
			}
			spot = ground;
			Vector3 val4 = default(Vector3);
			if (SpecialPhysicsCastUtils.TrySnapDropPosToTopmostGround(ground, ref val4))
			{
				if (!SpecialPhysicsCastUtils.IsReachableDropElevation(origin.y, val4.y))
				{
					return false;
				}
				spot = val4;
			}
			return true;
		}

		private bool GroundAt(Vector3 c, out Vector3 ground)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			ground = default(Vector3);
			RaycastHit[] array = Physics.BoxCastAll(new Vector3(c.x, origin.y + 2f, c.z), LazyConsts.BIG_DROP_COLLIDER_SIZE / 2f, Vector3.down, Quaternion.identity, 5f, 7424, (QueryTriggerInteraction)1);
			Array.Sort(array, (RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance));
			RaycastHit[] array2 = array;
			WaterComponentTag val2 = default(WaterComponentTag);
			for (int num = 0; num < array2.Length; num++)
			{
				RaycastHit val = array2[num];
				Collider collider = ((RaycastHit)(ref val)).collider;
				if ((Object)(object)collider == (Object)null)
				{
					continue;
				}
				if (((Component)collider).TryGetComponent<WaterComponentTag>(ref val2))
				{
					return false;
				}
				switch (((Component)collider).gameObject.layer)
				{
				case 8:
					return false;
				case 11:
				case 12:
					if (SpecialPhysicsCastUtils.IsReachableDropElevation(origin.y, ((RaycastHit)(ref val)).point.y))
					{
						ground = new Vector3(c.x, ((RaycastHit)(ref val)).point.y, c.z);
						return true;
					}
					break;
				}
			}
			return false;
		}
	}
	internal enum TextKind
	{
		Title,
		Body,
		Small
	}
	internal enum ButtonKind
	{
		Close,
		Primary,
		Plus,
		Minus,
		Next,
		Prev
	}
	internal struct RibbonParts
	{
		public TMP_Text Title;

		public float Height;

		public float LeftEnd;

		public float RightEnd;

		public float MinWidth;
	}
	internal sealed class GameUi
	{
		public const int PanelSorting = 55;

		public const int PickerSorting = 390;

		private Transform holder;

		private Canvas rootCanvas;

		private readonly List<GameObject> owned = new List<GameObject>();

		private readonly Dictionary<ButtonKind, GameObject> buttons = new Dictionary<ButtonKind, GameObject>();

		private readonly Dictionary<GameObject, Vector2> templateSizes = new Dictionary<GameObject, Vector2>();

		private string primaryLabelPath;

		private readonly Dictionary<TextKind, TextMeshProUGUI> labels = new Dictionary<TextKind, TextMeshProUGUI>();

		private GameObject scrollbarTemplate;

		private float scrollbarWidth;

		private Sprite fadeSprite;

		private Type fadeType;

		private float fadeHeight = 10f;

		private GameObject chromeTemplate;

		private string chromeHeaderPath;

		private string chromeTitlePath;

		private string chromeClosePath;

		private string chromeDecorLeft;

		private string chromeDecorRight;

		private RectOffset windowPadding = new RectOffset(24, 24, 47, 23);

		private Sprite arrowSprite;

		private Material arrowMaterial;

		private Vector2 arrowSize = new Vector2(14f, 8f);

		private Vector2 arrowFlip = Vector2.one;

		private string arrowClickSound;

		private string arrowEnterSound;

		private FieldInfo previewDataField;

		private UICraftPreviewItemCellData emptyPreviewData;

		private IDictionary poolsCache;

		private const float ButtonTextMargin = 14f;

		private const float PlainScrollbarWidth = 4f;

		public RectTransform Root { get; private set; }

		public Image FrameSource { get; private set; }

		public GameObject ListContentSource { get; private set; }

		public Sprite TabBackSprite { get; private set; }

		public bool HasItemCellPool { get; private set; }

		public bool UseCraftTabs { get; private set; }

		public Vector2 ItemCellSize { get; private set; } = new Vector2(32f, 32f);

		public float ListWidth { get; private set; }

		public bool Alive
		{
			get
			{
				if ((Object)(object)Root != (Object)null)
				{
					return (Object)(object)holder != (Object)null;
				}
				return false;
			}
		}

		public float ScrollbarWidth
		{
			get
			{
				if (!((Object)(object)scrollbarTemplate != (Object)null))
				{
					return 0f;
				}
				return scrollbarWidth + 2f;
			}
		}

		private static UIPrefabsPooler Pooler => UIPrefabsPooler.Instance;

		public static GameUi Create()
		{
			GameUi gameUi = new GameUi();
			gameUi.Init();
			return gameUi;
		}

		private void Init()
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected O, but got Unknown
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: 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_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_040f: Unknown result type (might be due to invalid IL or missing references)
			GUIElements instance = GUIElements.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				throw new InvalidOperationException("GUIElements not ready");
			}
			Component val = Field<Component>(instance, "uiFitter");
			Root = (RectTransform)(((Object)(object)val != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
			if ((Object)(object)Root == (Object)null)
			{
				Root = instance.Root;
			}
			Canvas componentInParent = ((Component)Root).GetComponentInParent<Canvas>();
			rootCanvas = ((componentInParent != null) ? componentInParent.rootCanvas : null);
			GameObject val2 = new GameObject("CraftTodo_Templates", new Type[1] { typeof(RectTransform) });
			val2.SetActive(false);
			val2.layer = ((Component)Root).gameObject.layer;
			val2.transform.SetParent((Transform)(object)Root, false);
			holder = val2.transform;
			owned.Add(val2);
			StringBuilder stringBuilder = new StringBuilder("UI templates:");
			poolsCache = Field<IDictionary>(UIPrefabsPooler.Instance, "poolsCache");
			UICraftSelectionWindow sel = Try(() => LazyUI.GetWindow<UICraftSelectionWindow>(), "UICraftSelectionWindow");
			UICraftWindow craft = Try(() => LazyUI.GetWindow<UICraftWindow>(), "UICraftWindow");
			Try(delegate
			{
				AddButtonTemplate(ButtonKind.Close, (Component)(object)(Field<LazyButton>(sel, "closeButton") ?? Field<LazyButton>(craft, "closeButton")));
				LazyButton val3 = Field<LazyButton>(sel, "startCraftButton");
				AddButtonTemplate(ButtonKind.Primary, (Component)(object)val3);
				TextMeshProUGUI val4 = Field<TextMeshProUGUI>(sel, "startCraftButtonText");
				if ((Object)(object)val3 != (Object)null && (Object)(object)val4 != (Object)null && ((TMP_Text)val4).transform.IsChildOf(((Component)val3).transform))
				{
					primaryLabelPath = PathFrom(((Component)val3).transform, ((TMP_Text)val4).transform);
				}
				AddButtonTemplate(ButtonKind.Plus, (Component)(object)Field<LazyButton>(sel, "plusCraftButton"));
				AddButtonTemplate(ButtonKind.Minus, (Component)(object)Field<LazyButton>(sel, "minusCraftButton"));
			}, "buttons");
			Try(delegate
			{
				MonoBehaviour obj7 = PoolPrefab(typeof(UICraftItemCell));
				UICraftItemCell val3 = (UICraftItemCell)(object)((obj7 is UICraftItemCell) ? obj7 : null);
				if (val3 != null)
				{
					AddButtonTemplate(ButtonKind.Next, (Component)(object)val3.NextItemButton);
					AddButtonTemplate(ButtonKind.Prev, (Component)(object)val3.PrevItemButton);
					HarvestArrow(val3.NextItemButton);
				}
			}, "arrow buttons");
			Try(delegate
			{
				AddLabelTemplate(TextKind.Title, Field<TextMeshProUGUI>(sel, "headerLabel"));
				object obj7 = Field<object>(craft, "uiInfoWidget");
				AddLabelTemplate(TextKind.Body, Field<TextMeshProUGUI>(obj7, "description"));
				AddLabelTemplate(TextKind.Small, Field<TextMeshProUGUI>(obj7, "descriptionTick") ?? Field<TextMeshProUGUI>(obj7, "description"));
				if (!labels.ContainsKey(TextKind.Body) && labels.TryGetValue(TextKind.Title, out var value))
				{
					labels[TextKind.Body] = value;
				}
				if (!labels.ContainsKey(TextKind.Small) && labels.TryGetValue(TextKind.Body, out var value2))
				{
					labels[TextKind.Small] = value2;
				}
			}, "labels");
			Try(delegate
			{
				HarvestChrome(sel);
			}, "window chrome");
			Try(delegate
			{
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0101: 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_0127: Unknown result type (might be due to invalid IL or missing references)
				//IL_015a: Unknown result type (might be due to invalid IL or missing references)
				//IL_015f: Unknown result type (might be due to invalid IL or missing references)
				ScrollRect val3 = Field<ScrollRect>(craft, "craftScrollRect");
				Rect rect2;
				if ((Object)(object)val3 != (Object)null && (Object)(object)val3.verticalScrollbar != (Object)null)
				{
					GameObject gameObject = ((Component)val3.verticalScrollbar).gameObject;
					GameUi gameUi = this;
					Transform transform = gameObject.transform;
					rect2 = ((RectTransform)((transform is RectTransform) ? transform : null)).rect;
					gameUi.scrollbarWidth = Mathf.Max(4f, ((Rect)(ref rect2)).width);
					scrollbarTemplate = CleanClone(gameObject, "Scrollbar");
				}
				ListContentSource = Field<GameObject>(craft, "craftListContent");
				Image val4 = (((Object)(object)craft != (Object)null) ? ((IEnumerable<Image>)((Component)craft).GetComponentsInChildren<Image>(true)).FirstOrDefault((Func<Image, bool>)((Image i) => (Object)(object)i.sprite != (Object)null && ((Object)i).name == "FadeDown")) : null);
				if ((Object)(object)val4 != (Object)null)
				{
					fadeSprite = val4.sprite;
					fadeType = val4.type;
					fadeHeight = SizeOf(((Graphic)val4).rectTransform, new Vector2(0f, fadeHeight)).y;
				}
				float num;
				if (!((Object)(object)val3 != (Object)null) || !((Object)(object)val3.viewport != (Object)null))
				{
					num = 0f;
				}
				else
				{
					rect2 = val3.viewport.rect;
					num = ((Rect)(ref rect2)).width;
				}
				float listWidth = num;
				ListWidth = listWidth;
			}, "scroll");
			Try(delegate
			{
				//IL_009a: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a4: Expected O, but got Unknown
				//IL_005b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Unknown result type (might be due to invalid IL or missing references)
				//IL_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)
				HasItemCellPool = (Object)(object)PoolPrefab(typeof(UIItemCell)) != (Object)null;
				MonoBehaviour obj7 = PoolPrefab(typeof(UIItemCell));
				UIItemCell val3 = (UIItemCell)(object)((obj7 is UIItemCell) ? obj7 : null);
				if (val3 != null)
				{
					GameUi gameUi = this;
					Transform transform = ((Component)val3).transform;
					gameUi.ItemCellSize = SizeOf((RectTransform)(object)((transform is RectTransform) ? transform : null), ItemCellSize);
				}
				previewDataField = AccessTools.Field(typeof(LazyWidget<UICraftPreviewItemCellData>), "data");
				emptyPreviewData = new UICraftPreviewItemCellData((CraftDef)null, (WgoData)null, (Action<CraftDef, List<NeedItemData>, CraftParamsData, int>)null, (Action<CraftDef, List<NeedItemData>, CraftParamsData, int>)null, "", false, (Sprite)null);
				MonoBehaviour obj8 = PoolPrefab(typeof(UICraftsTabWidget));
				UICraftsTabWidget val4 = (UICraftsTabWidget)(object)((obj8 is UICraftsTabWidget) ? obj8 : null);
				MonoBehaviour obj9 = PoolPrefab(typeof(UICraftPreviewItemCell));
				UICraftPreviewItemCell val5 = (UICraftPreviewItemCell)(object)((obj9 is UICraftPreviewItemCell) ? obj9 : null);
				if ((Object)(object)val4 != (Object)null)
				{
					TabBackSprite = Field<Sprite>(val4, "defaultTabBgIcon");
					Transform transform2 = ((Component)val4).transform;
					Rect rect2 = ((RectTransform)((transform2 is RectTransform) ? transform2 : null)).rect;
					float width = ((Rect)(ref rect2)).width;
					if (ListWidth < 50f && width > 50f)
					{
						ListWidth = width;
					}
				}
				UseCraftTabs = (Object)(object)val4 != (Object)null && (Object)(object)val5 != (Object)null && previewDataField != null && (Object)(object)Field<Transform>(val4, "craftsParent") != (Object)null && (Object)(object)PoolPrefab(typeof(UICraftsTabSeparatorWidget)) != (Object)null;
			}, "pools");
			if (ListWidth < 50f)
			{
				ListWidth = (ItemCellSize.x + 2f) * 7f;
			}
			object[] obj = new object[4]
			{
				((Object)Root).name,
				null,
				null,
				null
			};
			Canvas obj2 = rootCanvas;
			obj[1] = ((obj2 != null) ? new float?(obj2.scaleFactor) : ((float?)null));
			Rect rect = Root.rect;
			obj[2] = ((Rect)(ref rect)).width;
			rect = Root.rect;
			obj[3] = ((Rect)(ref rect)).height;
			stringBuilder.Append(string.Format(" root={0} scale={1} size={2:0}x{3:0}", obj));
			stringBuilder.Append(" buttons=[" + string.Join(",", buttons.Keys) + "] labels=[" + string.Join(",", labels.Select(delegate(KeyValuePair<TextKind, TextMeshProUGUI> kv)
			{
				object arg = kv.Key;
				TMP_FontAsset font = ((TMP_Text)kv.Value).font;
				return $"{arg}:{((font != null) ? ((Object)font).name : null)}/{((TMP_Text)kv.Value).fontSize}";
			})) + "]");
			object[] array = new object[8];
			Image frameSource = FrameSource;
			object obj3;
			if (frameSource == null)
			{
				obj3 = null;
			}
			else
			{
				Sprite sprite = frameSource.sprite;
				obj3 = ((sprite != null) ? ((Object)sprite).name : null);
			}
			array[0] = obj3;
			array[1] = (Object)(object)chromeTemplate != (Object)null;
			array[2] = chromeHeaderPath;
			array[3] = chromeTitlePath;
			array[4] = chromeClosePath;
			array[5] = chromeDecorLeft;
			array[6] = chromeDecorRight;
			array[7] = windowPadding;
			stringBuilder.Append(string.Format(" frame={0} chrome={1} header={2} title={3} close={4} decor={5}/{6} padding={7}", array));
			Sprite obj4 = arrowSprite;
			stringBuilder.Append($" arrow={((obj4 != null) ? ((Object)obj4).name : null)} {arrowSize} flip={arrowFlip}");
			object[] obj5 = new object[6]
			{
				(Object)(object)scrollbarTemplate != (Object)null,
				null,
				null,
				null,
				null,
				null
			};
			Sprite obj6 = fadeSprite;
			obj5[1] = ((obj6 != null) ? ((Object)obj6).name : null);
			obj5[2] = ItemCellSize;
			obj5[3] = ListWidth;
			obj5[4] = UseCraftTabs;
			Sprite tabBackSprite = TabBackSprite;
			obj5[5] = ((tabBackSprite != null) ? ((Object)tabBackSprite).name : null);
			stringBuilder.Append(string.Format(" scrollbar={0} fade={1} cell={2} listWidth={3:0} craftTabs={4} tabBack={5}", obj5));
			Plugin.Log.LogInfo((object)stringBuilder.ToString());
		}

		private void AddButtonTemplate(ButtonKind kind, Component source)
		{
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)source == (Object)null)
			{
				return;
			}
			GameObject val = CleanClone(source.gameObject, "Tpl_" + kind);
			Transform[] componentsInChildren = val.GetComponentsInChildren<Transform>(true);
			foreach (Transform val2 in componentsInChildren)
			{
				if ((Object)(object)val2 != (Object)(object)val.transform && ((Object)val2).name.IndexOf("gamepad", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					((Component)val2).gameObject.SetActive(false);
				}
			}
			Dictionary<GameObject, Vector2> dictionary = templateSizes;
			Transform transform = source.transform;
			dictionary[val] = SizeOf((RectTransform)(object)((transform is RectTransform) ? transform : null), new Vector2(24f, 24f));
			buttons[kind] = val;
		}

		private void AddLabelTemplate(TextKind kind, TextMeshProUGUI source)
		{
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)source == (Object)null)
			{
				return;
			}
			GameObject val = Object.Instantiate<GameObject>(((Component)source).gameObject, holder, false);
			((Object)val).name = "Tpl_Label_" + kind;
			foreach (Transform item in ((IEnumerable)val.transform).Cast<Transform>().ToList())
			{
				Object.DestroyImmediate((Object)(object)((Component)item).gameObject);
			}
			HashSet<Type> hashSet = new HashSet<Type>
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(TextMeshProUGUI),
				typeof(TextStyleComponent)
			};
			foreach (Component item2 in val.GetComponents<Component>().Reverse())
			{
				if ((Object)(object)item2 != (Object)null && !hashSet.Contains(((object)item2).GetType()) && !(item2 is TextMeshProUGUI))
				{
					Object.DestroyImmediate((Object)(object)item2);
				}
			}
			TextMeshProUGUI component = val.GetComponent<TextMeshProUGUI>();
			((TMP_Text)component).text = "";
			((Graphic)component).raycastTarget = false;
			((TMP_Text)component).margin = Vector4.zero;
			val.SetActive(true);
			labels[kind] = component;
		}

		private void HarvestChrome(UICraftSelectionWindow sel)
		{
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Expected O, but got Unknown
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Expected O, but got Unknown
			GenericWindowLayout val = (((Object)(object)sel != (Object)null) ? ((Component)sel).GetComponentInChildren<GenericWindowLayout>(true) : null);
			FrameSource = FindFrame(((Object)(object)val != (Object)null) ? ((Component)val).transform : (((Object)(object)sel != (Object)null) ? ((Component)sel).transform : null));
			if ((Object)(object)val == (Object)null || (Object)(object)FrameSource == (Object)null)
			{
				return;
			}
			VerticalLayoutGroup component = ((Component)val).GetComponent<VerticalLayoutGroup>();
			int num = ((AccessTools.Field(typeof(GenericWindowLayout), "layoutGroupTopPaddingWithHeader")?.GetValue(val) is int num2) ? num2 : 47);
			if ((Object)(object)component != (Object)null)
			{
				windowPadding = new RectOffset(((LayoutGroup)component).padding.left, ((LayoutGroup)component).padding.right, num, ((LayoutGroup)component).padding.bottom);
			}
			Transform transform = ((Component)FrameSource).transform;
			GameObject val2 = Field<GameObject>(val, "header");
			LazyButton close = Field<LazyButton>(sel, "closeButton");
			if ((Object)(object)val2 != (Object)null && val2.transform.IsChildOf(transform))
			{
				chromeHeaderPath = PathFrom(transform, val2.transform);
				TextMeshProUGUI val3 = ((IEnumerable<TextMeshProUGUI>)val2.GetComponentsInChildren<TextMeshProUGUI>(true)).FirstOrDefault((Func<TextMeshProUGUI, bool>)((TextMeshProUGUI l) => (Object)(object)close == (Object)null || !((TMP_Text)l).transform.IsChildOf(((Component)close).transform)));
				if ((Object)(object)val3 != (Object)null)
				{
					chromeTitlePath = PathFrom(transform, ((TMP_Text)val3).transform);
				}
				foreach (Transform item in val2.transform)
				{
					Transform val4 = item;
					if (((Object)val4).name.IndexOf("decor", StringComparison.OrdinalIgnoreCase) < 0)
					{
						continue;
					}
					if (((Object)val4).name.IndexOf("left", StringComparison.OrdinalIgnoreCase) >= 0)
					{
						if (chromeDecorLeft == null)
						{
							chromeDecorLeft = ((Object)val4).name;
						}
					}
					else if (((Object)val4).name.IndexOf("right", StringComparison.OrdinalIgnoreCase) >= 0 && chromeDecorRight == null)
					{
						chromeDecorRight = ((Object)val4).name;
					}
				}
			}
			if ((Object)(object)close != (Object)null && ((Component)close).transform.IsChildOf(transform))
			{
				chromeClosePath = PathFrom(transform, ((Component)close).transform);
			}
			chromeTemplate = CleanClone(((Component)transform).gameObject, "Tpl_Chrome");
			LazyButtonTipsStr[] componentsInChildren = chromeTemplate.GetComponentsInChildren<LazyButtonTipsStr>(true);
			for (int num3 = 0; num3 < componentsInChildren.Length; num3++)
			{
				Object.DestroyImmediate((Object)(object)((Component)componentsInChildren[num3]).gameObject);
			}
		}

		private void HarvestArrow(LazyButton source)
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)source == (Object)null)
			{
				return;
			}
			Image val = (from i in ((Component)source).GetComponentsInChildren<Image>(true)
				where (Object)(object)i.sprite != (Object)null && (Object)(object)i != (Object)(object)((Selectable)source).targetGraphic
				select i).OrderBy(delegate(Image i)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				Rect rect = ((Graphic)i).rectTransform.rect;
				float width = ((Rect)(ref rect)).width;
				rect = ((Graphic)i).rectTransform.rect;
				return width * ((Rect)(ref rect)).height;
			}).FirstOrDefault();
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			arrowSprite = val.sprite;
			if ((Object)(object)((Graphic)val).material != (Object)(object)((Graphic)val).defaultMaterial)
			{
				arrowMaterial = ((Graphic)val).material;
			}
			arrowSize = SizeOf(((Graphic)val).rectTransform, arrowSize);
			float num = 1f;
			float num2 = 1f;
			Transform val2 = ((Component)val).transform;
			while ((Object)(object)val2 != (Object)null)
			{
				num *= Mathf.Sign(val2.localScale.x);
				num2 *= Mathf.Sign(val2.localScale.y);
				if ((Object)(object)val2 == (Object)(object)((Component)source).transform)
				{
					break;
				}
				val2 = val2.parent;
			}
			arrowFlip = new Vector2(num, num2);
			arrowClickSound = source.onClickSound;
			arrowEnterSound = source.onEnterSound;
		}

		private GameObject CleanClone(GameObject source, string name)
		{
			GameObject val = Object.Instantiate<GameObject>(source, holder, false);
			((Object)val).name = name;
			val.SetActive(true);
			LazyButton[] componentsInChildren = val.GetComponentsInChildren<LazyButton>(true);
			foreach (LazyButton val2 in componentsInChildren)
			{
				val2.LazyUIElementId = null;
				UnityEventBase[] array = (UnityEventBase[])(object)new UnityEventBase[10]
				{
					(UnityEventBase)((Button)val2).onClick,
					(UnityEventBase)val2.onDown,
					(UnityEventBase)val2.onUp,
					(UnityEventBase)val2.onEnter,
					(UnityEventBase)val2.onExit,
					(UnityEventBase)val2.onNotInteractableDown,
					(UnityEventBase)val2.onNotInteractableUp,
					(UnityEventBase)val2.onNotInteractableEnter,
					(UnityEventBase)val2.onNotInteractableExit,
					(UnityEventBase)val2.onNotInteractableClick
				};
				for (int j = 0; j < array.Length; j++)
				{
					DisableForeignListeners(array[j], val.transform);
				}
			}
			Button[] componentsInChildren2 = val.GetComponentsInChildren<Button>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				DisableForeignListeners((UnityEventBase)(object)componentsInChildren2[i].onClick, val.transform);
			}
			LocalizedLabel[] componentsInChildren3 = val.GetComponentsInChildren<LocalizedLabel>(true);
			for (int i = 0; i < componentsInChildren3.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren3[i]);
			}
			return val;
		}

		private static void DisableForeignListeners(UnityEventBase e, Transform root)
		{
			if (e == null)
			{
				return;
			}
			for (int i = 0; i < e.GetPersistentEventCount(); i++)
			{
				Object persistentTarget = e.GetPersistentTarget(i);
				Component val = (Component)(object)((persistentTarget is Component) ? persistentTarget : null);
				object obj;
				if (val == null)
				{
					GameObject val2 = (GameObject)(object)((persistentTarget is GameObject) ? persistentTarget : null);
					obj = ((val2 != null) ? val2.transform : null);
				}
				else
				{
					obj = val.transform;
				}
				Transform val3 = (Transform)obj;
				if ((Object)(object)val3 == (Object)null || !val3.IsChildOf(root))
				{
					e.SetPersistentListenerState(i, (UnityEventCallState)0);
				}
			}
		}

		private static Image FindFrame(Transform window)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Invalid comparison between Unknown and I4
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Invalid comparison between Unknown and I4
			if ((Object)(object)window == (Object)null)
			{
				return null;
			}
			Image result = null;
			float num = 0f;
			Image[] componentsInChildren = ((Component)window).GetComponentsInChildren<Image>(true);
			foreach (Image val in componentsInChildren)
			{
				if (!((Object)(object)val.sprite == (Object)null) && !(val.sprite.border == Vector4.zero) && ((int)val.type == 1 || (int)val.type == 2))
				{
					Rect rect = ((Graphic)val).rectTransform.rect;
					float num2 = ((Rect)(ref rect)).width * ((Rect)(ref rect)).height;
					if (num2 > num)
					{
						num = num2;
						result = val;
					}
				}
			}
			return result;
		}

		private MonoBehaviour PoolPrefab(Type type)
		{
			if (poolsCache == null || !poolsCache.Contains(type))
			{
				return null;
			}
			object? obj = poolsCache[type];
			object? obj2 = ((obj is UIPrefabPool) ? obj : null);
			if (obj2 == null)
			{
				return null;
			}
			return ((UIPrefabPool)obj2).Prefab;
		}

		public void Destroy()
		{
			foreach (GameObject item in owned)
			{
				if ((Object)(object)item != (Object)null)
				{
					Object.Destroy((Object)(object)item);
				}
			}
			owned.Clear();
			holder = null;
		}

		public RectTransform NewRect(string name, Transform parent)
		{
			//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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			RectTransform val = (RectTransform)new GameObject(name, new Type[1] { typeof(RectTransform) })
			{
				layer = ((Component)Root).gameObject.layer
			}.transform;
			((Transform)val).SetParent(parent, false);
			return val;
		}

		public RectTransform MakeHost(string name, int sortingOrder)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = NewRect(name, (Transform)(object)Root);
			Stretch(val);
			Canvas val2 = ((Component)val).gameObject.AddComponent<Canvas>();
			if ((Object)(object)rootCanvas != (Object)null)
			{
				val2.additionalShaderChannels = rootCanvas.additionalShaderChannels;
			}
			CanvasSorting canvasSorting = ((Component)val).gameObject.AddComponent<CanvasSorting>();
			canvasSorting.Order = sortingOrder;
			canvasSorting.Apply();
			((Component)val).gameObject.AddComponent<GraphicRaycaster>();
			((Transform)val).SetAsLastSibling();
			owned.Add(((Component)val).gameObject);
			return val;
		}

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

		public static void CenterIn(RectTransform rt)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			Rect rect = rt.rect;
			Vector2 size = ((Rect)(ref rect)).size;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0.5f, 0.5f);
			rt.anchorMax = val;
			rt.anchorMin = val;
			rt.sizeDelta = size;
			rt.anchoredPosition = new Vector2((rt.pivot.x - 0.5f) * size.x, (rt.pivot.y - 0.5f) * size.y);
		}

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

		public static HorizontalLayoutGroup HLayout(Component c, float spacing, TextAnchor align = (TextAnchor)3, RectOffset padding = null)
		{
			//IL_0013: 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)
			HorizontalLayoutGroup obj = c.gameObject.AddComponent<HorizontalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)obj).spacing = spacing;
			((LayoutGroup)obj).childAlignment = align;
			((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = false;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false;
			((LayoutGroup)obj).padding = (RectOffset)(((object)padding) ?? ((object)new RectOffset()));
			return obj;
		}

		public static VerticalLayoutGroup VLayout(Component c, float spacing, TextAnchor align = (TextAnchor)0, RectOffset padding = null)
		{
			//IL_0013: 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)
			VerticalLayoutGroup obj = c.gameObject.AddComponent<VerticalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)obj).spacing = spacing;
			((LayoutGroup)obj).childAlignment = align;
			((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false;
			((LayoutGroup)obj).padding = (RectOffset)(((object)padding) ?? ((object)new RectOffset()));
			return obj;
		}

		public RectOffset AddWindowChrome(RectTransform window, string title, Action onClose, out RectTransform dragArea, out LazyButton closeButton)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: 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_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Expected O, but got Unknown
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Expected O, but got Unknown
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Expected O, but got Unknown
			closeButton = null;
			if ((Object)(object)chromeTemplate != (Object)null)
			{
				GameObject val = Object.Instantiate<GameObject>(chromeTemplate, (Transform)(object)window, false);
				((Object)val).name = "Chrome";
				RectTransform val2 = (RectTransform)val.transform;
				Stretch(val2);
				((Transform)val2).SetAsFirstSibling();
				(val.GetComponent<LayoutElement>() ?? val.AddComponent<LayoutElement>()).ignoreLayout = true;
				if (chromeTitlePath != null)
				{
					Transform obj = ((Transform)val2).Find(chromeTitlePath);
					TMP_Text val3 = ((obj != null) ? ((Component)obj).GetComponent<TMP_Text>() : null);
					if (val3 != null)
					{
						val3.text = title;
					}
				}
				dragArea = (RectTransform)(((object)((chromeHeaderPath != null) ? /*isinst with value type is only supported in some contexts*/: null)) ?? ((object)val2));
				if (chromeClosePath != null)
				{
					Transform obj2 = ((Transform)val2).Find(chromeClosePath);
					closeButton = ((obj2 != null) ? ((Component)obj2).GetComponent<LazyButton>() : null);
				}
				if ((Object)(object)closeButton != (Object)null)
				{
					if (onClose != null)
					{
						((UnityEvent)((Button)closeButton).onClick).AddListener((UnityAction)delegate
						{
							Plugin.Safe(onClose);
						});
					}
					else
					{
						((Component)closeButton).gameObject.SetActive(false);
					}
				}
				else if (onClose != null)
				{
					closeButton = MakeButton((Transform)(object)dragArea, ButtonKind.Close, null, onClose);
					Transform transform = ((Component)closeButton).transform;
					PinTopRight((RectTransform)(object)((transform is RectTransform) ? transform : null));
				}
				return new RectOffset(windowPadding.left, windowPadding.right, windowPadding.top, windowPadding.bottom);
			}
			((Graphic)(((Component)window).gameObject.GetComponent<Image>() ?? ((Component)window).gameObject.AddComponent<Image>())).color = new Color(0.16f, 0.13f, 0.11f, 0.94f);
			RectTransform val4 = NewRect("Header", (Transform)(object)window);
			val4.anchorMin = new Vector2(0f, 1f);
			val4.anchorMax = new Vector2(1f, 1f);
			val4.pivot = new Vector2(0.5f, 1f);
			val4.sizeDelta = new Vector2(0f, 20f);
			val4.anchoredPosition = Vector2.zero;
			((Component)val4).gameObject.AddComponent<LayoutElement>().ignoreLayout = true;
			((Graphic)((Component)val4).gameObject.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0.25f);
			Stretch(((TMP_Text)MakeLabel((Transform)(object)val4, title, TextKind.Title, (TextAlignmentOptions)514)).rectTransform, 4f, 0f, 24f);
			if (onClose != null)
			{
				closeButton = MakeButton((Transform)(object)val4, ButtonKind.Close, null, onClose);
				Transform transform2 = ((Component)closeButton).transform;
				PinTopRight((RectTransform)(object)((transform2 is RectTransform) ? transform2 : null));
			}
			dragArea = val4;
			return new RectOffset(8, 8, 26, 8);
		}

		public GameObject HeaderDecorRight(Transform header)
		{
			if (chromeDecorRight == null || !((Object)(object)header != (Object)null))
			{
				return null;
			}
			Transform obj = header.Find(chromeDecorRight);
			if (obj == null)
			{
				return null;
			}
			return ((Component)obj).gameObject;
		}

		public RibbonParts AddRibbon(RectTransform bar, string title)
		{
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Expected O, but got Unknown
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Expected O, but got Unknown
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			RibbonParts result = new RibbonParts
			{
				LeftEnd = 4f,
				RightEnd = 4f
			};
			if ((Object)(object)chromeTemplate != (Object)null && chromeHeaderPath != null)
			{
				GameObject val = Object.Instantiate<GameObject>(chromeTemplate, (Transform)(object)bar, false);
				((Object)val).name = "Ribbon";
				RectTransform val2 = (RectTransform)val.transform;
				Transform obj = ((Transform)val2).Find(chromeHeaderPath);
				RectTransform val3 = (RectTransform)(object)((obj is RectTransform) ? obj : null);
				if ((Object)(object)val3 != (Object)null)
				{
					Stretch(val2);
					((Transform)val2).SetAsFirstSibling();
					Rect rect = val3.rect;
					result.Height = ((Rect)(ref rect)).height;
					Transform val4 = (Transform)(object)val3;
					while ((Object)(object)val4 != (Object)(object)val2)
					{
						foreach (Transform item in val4.parent)
						{
							Transform val5 = item;
							if ((Object)(object)val5 != (Object)(object)val4)
							{
								((Component)val5).gameObject.SetActive(false);
							}
						}
						Image[] components = ((Component)val4.parent).GetComponents<Image>();
						for (int i = 0; i < components.Length; i++)
						{
							((Behaviour)components[i]).enabled = false;
						}
						Stretch((RectTransform)val4);
						val4 = val4.parent;
					}
					if (chromeClosePath != null)
					{
						Transform obj2 = ((Transform)val2).Find(chromeClosePath);
						if (obj2 != null)
						{
							((Component)obj2).gameObject.SetActive(false);
						}
					}
					if (chromeDecorLeft != null)
					{
						Transform obj3 = ((Transform)val3).Find(chromeDecorLeft);
						RectTransform val6 = (RectTransform)(object)((obj3 is RectTransform) ? obj3 : null);
						if (val6 != null && ((Component)val6).gameObject.activeSelf)
						{
							rect = val6.rect;
							result.LeftEnd = ((Rect)(ref rect)).width;
						}
					}
					if (chromeDecorRight != null)
					{
						Transform obj4 = ((Transform)val3).Find(chromeDecorRight);
						RectTransform val7 = (RectTransform)(object)((obj4 is RectTransform) ? obj4 : null);
						if (val7 != null)
						{
							((Component)val7).gameObject.SetActive(true);
							rect = val7.rect;
							result.RightEnd = ((Rect)(ref rect)).width;
						}
					}
					Image val8 = (from val10 in ((Component)val3).GetComponentsInChildren<Image>(true)
						where (int)val10.type == 1 && (Object)(object)val10.sprite != (Object)null && val10.sprite.border != Vector4.zero
						select val10).OrderByDescending(delegate(Image val10)
					{
						//IL_0006: Unknown result type (might be due to invalid IL or missing references)
						//IL_000b: Unknown result type (might be due to invalid IL or missing references)
						Rect rect2 = ((Graphic)val10).rectTransform.rect;
						return ((Rect)(ref rect2)).width;
					}).FirstOrDefault();
					if ((Object)(object)val8 != (Object)null)
					{
						float num = (((Object)(object)rootCanvas != (Object)null) ? rootCanvas.referencePixelsPerUnit : 100f);
						float num2 = val8.sprite.pixelsPerUnit / num * val8.pixelsPerUnitMultiplier;
						if (num2 > 0f)
						{
							result.MinWidth = (val8.sprite.border.x + val8.sprite.border.z) / num2;
						}
					}
					if (chromeTitlePath != null)
					{
						Transform obj5 = ((Transform)val2).Find(chromeTitlePath);
						result.Title = ((obj5 != null) ? ((Component)obj5).GetComponent<TMP_Text>() : null);
					}
					if ((Object)(object)result.Title != (Object)null)
					{
						result.Title.text = title;
					}
					bar.sizeDelta = new Vector2(bar.sizeDelta.x, result.Height);
					return result;
				}
				Object.Destroy((Object)(object)val);
			}
			((Graphic)(((Component)bar).gameObject.GetComponent<Image>() ?? ((Component)bar).gameObject.AddComponent<Image>())).color = new Color(0.16f, 0.13f, 0.11f, 0.94f);
			TextMeshProUGUI val9 = MakeLabel((Transform)(object)bar, title, TextKind.Title, (TextAlignmentOptions)514);
			Stretch(((TMP_Text)val9).rectTransform);
			result.Title = (TMP_Text)(object)val9;
			result.Height = 20f;
			bar.sizeDelta = new Vector2(bar.sizeDelta.x, result.Height);
			return result;
		}

		private static void PinTopRight(RectTransform rt)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(1f, 1f);
			rt.pivot = val;
			Vector2 anchorMin = (rt.anchorMax = val);
			rt.anchorMin = anchorMin;
			rt.anchoredPosition = new Vector2(-2f, -2f);
		}

		public LazyButton MakeArrowButton(Transform parent, float angle, Action onClick, float size = 14f)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: 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)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Expected O, but got Unknown
			RectTransform val = NewRect("Arrow", parent);
			val.sizeDelta = new Vector2(size, size);
			Layout((Component)(object)val, size, size, 0f, 0f, size, size);
			((Graphic)((Component)val).gameObject.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0f);
			RectTransform val2 = NewRect("Icon", (Transform)(object)val);
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0.5f, 0.5f);
			val2.pivot = val3;
			Vector2 anchorMin = (val2.anchorMax = val3);
			val2.anchorMin = anchorMin;
			val2.anchoredPosition = Vector2.zero;
			Graphic val6;
			if ((Object)(object)arrowSprite != (Object)null)
			{
				val2.sizeDelta = arrowSize;
				((Transform)val2).localScale = new Vector3(arrowFlip.x, arrowFlip.y, 1f);
				Image val5 = ((Component)val2).gameObject.AddComponent<Image>();
				val5.sprite = arrowSprite;
				if ((Object)(object)arrowMaterial != (Object)null)
				{
					((Graphic)val5).material = arrowMaterial;
				}
				val6 = (Graphic)(object)val5;
			}
			else
			{
				val2.sizeDelta = new Vector2(size, size);
				TextMeshProUGUI obj = MakeLabel((Transform)(object)val2, "^", TextKind.Body, (TextAlignmentOptions)514);
				Stretch(((TMP_Text)obj).rectTransform);
				val6 = (Graphic)(object)obj;
			}
			val6.raycastTarget = false;
			((Transform)val2).localEulerAngles = new Vector3(0f, 0f, angle);
			LazyButton val7 = ((Component)val).gameObject.AddComponent<LazyButton>();
			((Selectable)val7).targetGraphic = val6;
			((Selectable)val7).transition = (Transition)1;
			ColorBlock colors = ((Selectable)val7).colors;
			((ColorBlock)(ref colors)).normalColor = Color.white;
			((ColorBlock)(ref colors)).highlightedColor = new Color(1f, 0.85f, 0.55f);
			((ColorBlock)(ref colors)).selectedColor = Color.white;
			((ColorBlock)(ref colors)).pressedColor = new Color(0.75f, 0.6f, 0.45f);
			((ColorBlock)(ref colors)).colorMultiplier = 1f;
			((ColorBlock)(ref colors)).fadeDuration = 0f;
			((Selectable)val7).colors = colors;
			Navigation navigation = default(Navigation);
			((Navigation)(ref navigation)).mode = (Mode)0;
			((Selectable)val7).navigation = navigation;
			val7.onClickSound = arrowClickSound;
			val7.onEnterSound = arrowEnterSound;
			if (onClick != null)
			{
				((UnityEvent)((Button)val7).onClick).AddListener((UnityAction)delegate
				{
					Plugin.Safe(onClick);
				});
			}
			return val7;
		}

		public static void SetArrowAngle(LazyButton button, float angle)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			Transform val = (((Object)(object)button != (Object)null) ? ((Component)button).transform.Find("Icon") : null);
			if ((Object)(object)val != (Object)null)
			{
				val.localEulerAngles = new Vector3(0f, 0f, angle);
			}
		}

		public TextMeshProUGUI MakeLabel(Transform parent, string text, TextKind kind, TextAlignmentOptions align = (TextAlignmentOptions)4097, bool wrap = false)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val;
			if (labels.TryGetValue(kind, out var value) && (Object)(object)value != (Object)null)
			{
				val = Object.Instantiate<TextMeshProUGUI>(value, parent, false);
				((Object)val).name = "Label";
			}
			else
			{
				val = ((Component)NewRect("Label", parent)).gameObject.AddComponent<TextMeshProUGUI>();
				((TMP_Text)val).fontSize = kind switch
				{
					TextKind.Body => 12, 
					TextKind.Title => 14, 
					_ => 10, 
				};
				((Graphic)val).color = new Color(0.93f, 0.88f, 0.78f);
			}
			RectTransform rectTransform = ((TMP_Text)val).rectTransform;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0f, 1f);
			rectTransform.pivot = val2;
			Vector2 anchorMin = (rectTransform.anchorMax = val2);
			rectTransform.anchorMin = anchorMin;
			((TMP_Text)val).text = text ?? "";
			((TMP_Text)val).alignment = align;
			((TMP_Text)val).textWrappingMode = (TextWrappingModes)(wrap ? 1 : 0);
			((TMP_Text)val).overflowMode = (TextOverflowModes)(!wrap);
			((Graphic)val).raycastTarget = false;
			((TMP_Text)val).richText = true;
			return val;
		}

		public LazyButton MakeButton(Transform parent, ButtonKind kind, string text, Action onClick, bool growToText = false)
		{
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: 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_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Expected O, but got Unknown
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			LazyButton val2;
			if (buttons.TryGetValue(kind, out var value) && (Object)(object)value != (Object)null)
			{
				GameObject val = Object.Instantiate<GameObject>(value, parent, false);
				((Object)val).name = kind.ToString() + "Button";
				val2 = val.GetComponent<LazyButton>();
				RectTransform val3 = (RectTransform)val.transform;
				Vector2 val4;
				if (!templateSizes.TryGetValue(value, out var value2))
				{
					Rect rect = val3.rect;
					val4 = ((Rect)(ref rect)).size;
				}
				else
				{
					val4 = value2;
				}
				Vector2 val5 = val4;
				Vector2 val6 = default(Vector2);
				((Vector2)(ref val6))..ctor(0.5f, 0.5f);
				val3.pivot = val6;
				Vector2 anchorMin = (val3.anchorMax = val6);
				val3.anchorMin = anchorMin;
				val3.sizeDelta = val5;
				val3.anchoredPosition = Vector2.zero;
				((Transform)val3).localRotation = Quaternion.identity;
				Layout((Component)(object)val2, val5.x, val5.y, 0f, 0f, val5.x, val5.y);
				if (text != null)
				{
					TMP_Text val8 = null;
					if (kind == ButtonKind.Primary && primaryLabelPath != null)
					{
						Transform obj = val.transform.Find(primaryLabelPath);
						val8 = ((obj != null) ? ((Component)obj).GetComponent<TMP_Text>() : null);
					}
					if ((Object)(object)val8 == (Object)null)
					{
						val8 = val.GetComponentInChildren<TMP_Text>(true);
					}
					if ((Object)(object)val8 != (Object)null)
					{
						val8.text = text;
					}
					if ((Object)(object)val8 != (Object)null && growToText)
					{
						float num = Mathf.Min(Mathf.Ceil(val8.GetPreferredValues(text).x + 28f), val5.x * 2f);
						if (num > val5.x)
						{
							val5.x = num;
							val3.sizeDelta = val5;
							Layout((Component)(object)val2, val5.x, val5.y, 0f, 0f, val5.x, val5.y);
						}
					}
				}
			}
			else
			{
				RectTransform val9 = NewRect(kind.ToString() + "Button", parent);
				Image val10 = ((Component)val9).gameObject.AddComponent<Image>();
				((Graphic)val10).color = new Color(0.35f, 0.27f, 0.2f, 1f);
				val2 = ((Component)val9).gameObject.AddComponent<LazyButton>();
				((Selectable)val2).targetGraphic = (Graphic)(object)val10;
				string text2 = (string)(text ?? (kind switch
				{
					ButtonKind.Prev => "<", 
					ButtonKind.Next => ">", 
					ButtonKind.Minus => "-", 
					ButtonKind.Plus => "+", 
					ButtonKind.Close => "X", 
					_ => "OK", 
				}));
				Stretch(((TMP_Text)MakeLabel((Transform)(object)val9, text2, TextKind.Body, (TextAlignmentOptions)514)).rectTransform);
				float num2 = ((kind == ButtonKind.Primary) ? 64f : 14f);
				Layout((Component)(object)val2, num2, 14f, 0f, 0f, num2, 14f);
			}
			if (onClick != null)
			{
				((UnityEvent)((Button)val2).onClick).AddListener((UnityAction)delegate
				{
					Plugin.Safe(onClick);
				});
			}
			return val2;
		}

		public Vector2 ButtonSize(ButtonKind kind)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (buttons.TryGetValue(kind, out var value) && (Object)(object)value != (Object)null && templateSizes.TryGetValue(value, out var value2))
			{
				return value2;
			}
			if (kind != ButtonKind.Primary)
			{
				return new Vector2(14f, 14f);
			}
			return new Vector2(64f, 14f);
		}

		public ScrollRect MakeScroll(Transform parent, out RectTransform content, bool indicators = false)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Expected O, but got Unknown
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = NewRect("Scroll", parent);
			ScrollRect val2 = ((Component)val).gameObject.AddComponent<ScrollRect>();
			RectTransform val3 = NewRect("Viewport", (Transform)(object)val);
			Stretch(val3);
			val3.pivot = new Vector2(0f, 1f);
			((Component)val3).gameObject.AddComponent<RectMask2D>();
			((Graphic)((Component)val3).gameObject.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0f);
			content = NewRect("Content", (Transform)(object)val3);
			content.anchorMin = new Vector2(0f, 1f);
			content.anchorMax = new Vector2(1f, 1f);
			content.pivot = new Vector2(0.5f, 1f);
			content.sizeDelta = Vector2.zero;
			content.anchoredPosition = Vector2.zero;
			val2.viewport = val3;
			val2.content = content;
			val2.horizontal = false;
			val2.vertical = true;
			val2.movementType = (MovementType)2;
			val2.inertia = false;
			val2.scrollSensitivity = ItemCellSize.y;
			Scrollbar val4 = null;
			if ((Object)(object)scrollbarTemplate != (Object)null)
			{
				GameObject obj = Object.Instantiate<GameObject>(scrollbarTemplate, (Transform)(object)val, false);
				((Object)obj).name = "Scrollbar";
				PinRightEdge((RectTransform)obj.transform, scrollbarWidth);
				val4 = obj.GetComponent<Scrollbar>();
			}
			else if (indicators)
			{
				val4 = MakePlainScrollbar(val, 4f);
			}
			if ((Object)(object)val4 != (Object)null)
			{
				val4.direction = (Direction)2;
				val2.verticalScrollbar = val4;
				val2.verticalScrollbarVisibility = (ScrollbarVisibility)2;
				val2.verticalScrollbarSpacing = 2f;
			}
			if (indicators)
			{
				AddScrollFades(val2);
			}
			try
			{
				SmoothMouseWheelScroll.EnsureForItem(val2, ItemCellSize.y);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogDebug((object)("Smooth scroll unavailable: " + ex.Message));
			}
			return val2;
		}

		private static void PinRightEdge(RectTransform rt, float width)
		{
			//IL_000b: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			rt.anchorMin = new Vector2(1f, 0f);
			rt.anchorMax = new Vector2(1f, 1f);
			rt.pivot = new Vector2(1f, 1f);
			rt.sizeDelta = new Vector2(width, 0f);
			rt.anchoredPosition = Vector2.zero;
		}

		private Scrollbar MakePlainScrollbar(RectTransform parent, float width)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: 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_013d: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = NewRect("Scrollbar", (Transform)(object)parent);
			PinRightEdge(val, width);
			((Graphic)((Component)val).gameObject.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0.3f);
			RectTransform val2 = NewRect("SlidingArea", (Transform)(object)val);
			Stretch(val2);
			RectTransform val3 = NewRect("Handle", (Transform)(object)val2);
			Stretch(val3);
			Image val4 = ((Component)val3).gameObject.AddComponent<Image>();
			((Graphic)val4).color = new Color(0.851f, 0.702f, 0.475f, 1f);
			Scrollbar obj = ((Component)val).gameObject.AddComponent<Scrollbar>();
			obj.handleRect = val3;
			((Selectable)obj).targetGraphic = (Graphic)(object)val4;
			Navigation navigation = default(Navigation);
			((Navigation)(ref navigation)).mode = (Mode)0;
			((Selectable)obj).navigation = navigation;
			ColorBlock colors = ((Selectable)obj).colors;
			((ColorBlock)(ref colors)).normalColor = new Color(0.8f, 0.8f, 0.8f);
			((ColorBlock)(ref colors)).highlightedColor = Color.white;
			((ColorBlock)(ref colors)).pressedColor = Color.white;
			((ColorBlock)(ref colors)).selectedColor = ((ColorBlock)(ref colors)).normalColor;
			((ColorBlock)(ref colors)).fadeDuration = 0f;
			((Selectable)obj).colors = colors;
			return obj;
		}

		private void AddScrollFades(ScrollRect scroll)
		{
			GameObject top;
			GameObject bottom;
			if (!((Object)(object)fadeSprite == (Object)null))
			{
				top = MakeFade(scroll.viewport, atTop: true);
				bottom = MakeFade(scroll.viewport, atTop: false);
				((UnityEvent<Vector2>)(object)scroll.onValueChanged).AddListener((UnityAction<Vector2>)delegate
				{
					Plugin.Safe(Refresh);
				});
				Refresh();
			}
			void Refresh()
			{
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				Rect rect = scroll.content.rect;
				float height = ((Rect)(ref rect)).height;
				rect = scroll.viewport.rect;
				float num = height - ((Rect)(ref rect)).height;
				float y = scroll.content.anchoredPosition.y;
				top.SetActive(num > 0.5f && y > 0.5f);
				bottom.SetActive(num > 0.5f && y < num - 0.5f);
			}
		}

		private GameObject MakeFade(RectTransform viewport, bool atTop)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = NewRect(atTop ? "FadeUp" : "FadeDown", (Transform)(object)viewport);
			float num = (atTop ? 1f : 0f);
			val.anchorMin = new Vector2(0f, num);
			val.anchorMax = new Vector2(1f, num);
			val.pivot = new Vector2(0.5f, 0.5f);
			val.sizeDelta = new Vector2(0f, fadeHeight);
			val.anchoredPosition = new Vector2(0f, atTop ? ((0f - fadeHeight) / 2f) : (fadeHeight / 2f));
			if (atTop)
			{
				((Transform)val).localScale = new Vector3(1f, -1f, 1f);
			}
			Image obj = ((Component)val).gameObject.AddComponent<Image>();
			obj.sprite = fadeSprite;
			obj.type = fadeType;
			((Graphic)obj).raycastTarget = false;
			return ((Component)val).gameObject;
		}

		public static void CopyLayout(GameObject source, GameObject target)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)source == (Object)null))
			{
				VerticalLayoutGroup component = source.GetComponent<VerticalLayoutGroup>();
				if (component != null)
				{
					VerticalLayoutGroup obj = target.GetComponent<VerticalLayoutGroup>() ?? target.AddComponent<VerticalLayoutGroup>();
					((LayoutGroup)obj).padding = new RectOffset(((LayoutGroup)component).padding.left, ((LayoutGroup)component).padding.right, ((LayoutGroup)component).padding.top, ((LayoutGroup)component).padding.bottom);
					((HorizontalOrVerticalLayoutGroup)obj).spacing = ((HorizontalOrVerticalLayoutGroup)component).spacing;
					((LayoutGroup)obj).childAlignment = ((LayoutGroup)component).childAlignment;
					((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = ((HorizontalOrVerticalLayoutGroup)component).childControlWidth;
					((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = ((HorizontalOrVerticalLayoutGroup)component).childControlHeight;
					((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = ((HorizontalOrVerticalLayoutGroup)component).childForceExpandWidth;
					((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = ((HorizontalOrVerticalLayoutGroup)component).childForceExpandHeight;
					((HorizontalOrVerticalLayoutGroup)obj).childScaleWidth = ((HorizontalOrVerticalLayoutGroup)component).childScaleWidth;
					((HorizontalOrVerticalLayoutGroup)obj).childScaleHeight = ((HorizontalOrVerticalLayoutGroup)component).childScaleHeight;
				}
				ContentSizeFitter component2 = source.GetComponent<ContentSizeFitter>();
				if (component2 != null)
				{
					ContentSizeFitter obj2 = target.GetComponent<ContentSizeFitter>() ?? target.AddComponent<ContentSizeFitter>();
					obj2.horizontalFit = (FitMode)0;
					obj2.verticalFit = component2.verticalFit;
				}
			}
		}

		public TMP_InputField MakeInputField(Transform parent, string placeholder, float height)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = NewRect("Search", parent);
			((Component)val).gameObject.SetActive(false);
			Image val2 = ((Component)val).gameObject.AddComponent<Image>();
			((Graphic)val2).color = new Color(0f, 0f, 0f, 0.3f);
			Layout((Component)(object)val2, -1f, height, 1f, 0f, 0f, height);
			RectTransform val3 = NewRect("TextArea", (Transform)(object)val);
			Stretch(val3, 4f, 1f, 4f, 1f);
			((Component)val3).gameObject.AddComponent<RectMask2D>();
			TextMeshProUGUI val4 = MakeLabel((Transform)(object)val3, placeholder, TextKind.Body, (TextAlignmentOptions)4097);
			Stretch(((TMP_Text)val4).rectTransform);
			((Graphic)val4).color = new Color(((Graphic)val4).color.r, ((Graphic)val4).color.g, ((Graphic)val4).color.b, ((Graphic)val4).color.a * 0.5f);
			TextMeshProUGUI val5 = MakeLabel((Transform)(object)val3, "", TextKind.Body, (TextAlignmentOptions)4097);
			Stretch(((TMP_Text)val5).rectTransform);
			((TMP_Text)val5).richText = false;
			((TMP_Text)val5).overflowMode = (TextOverflowModes)0;
			TMP_InputField obj = ((Component)val).gameObject.AddComponent<TMP_InputField>();
			obj.textViewport = val3;
			obj.textComponent = (TMP_Text)(object)val5;
			obj.placeholder = (Graphic)(object)val4;
			((Selectable)obj).targetGraphic = (Graphic)(object)val2;
			obj.lineType = (LineType)0;
			obj.characterLimit = 40;
			obj.richText = false;
			obj.caretWidth = 1;
			obj.customCaretColor = true;
			obj.caretColor = ((Graphic)val5).color;
			obj.selectionColor = new Color(1f, 1f, 1f, 0.25f);
			obj.restoreOriginalTextOnEscape = false;
			((Component)val).gameObject.SetActive(true);
			return obj;
		}

		public RectTransform MakeSlot(Transform parent, Vector2 size, string name = "Slot")
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			RectTransform obj = NewRect(name, parent);
			obj.sizeDelta = size;
			Layout((Component)(object)obj, size.x, size.y, 0f, 0f, size.x, size.y);
			return obj;
		}

		private static void Normalize(Transform t)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			t.localScale = Vector3.one;
			t.localRotation = Quaternion.identity;
			Vector3 localPosition = t.localPosition;
			t.localPosition = new Vector3(localPosition.x, localPosition.y, 0f);
		}

		public UIItemCell GetItemCell(Transform parent, bool center = true)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			UIPrefabsPooler pooler = Pooler;
			UIItemCell val = ((pooler != null) ? pooler.GetElementFromPool<UIItemCell>(parent) : null);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			if ((Object)(object)((Component)val).transform.parent != (Object)(object)parent)
			{
				((Component)val).transform.SetParent(parent, false);
			}
			Normalize(((Component)val).transform);
			if (center)
			{
				CenterIn((RectTransform)((Component)val).transform);
			}
			val.Flush(true);
			return val;
		}

		public void ReleaseItemCell(UIItemCell cell)
		{
			if (!((Object)(object)cell == (Object)null))
			{
				HideTooltipAt(((Component)cell).transform);
				cell.Flush(true);
				UIPrefabsPooler pooler = Pooler;
				if (pooler != null)
				{
					pooler.ReleaseElementToPool<UIItemCell>(cell);
				}
			}
		}

		public UICraftPreviewItemCell GetRecipePreviewCell(Transform parent)
		{
			UICraftPreviewItemCell elementFromPool = Pooler.GetElementFromPool<UICraftPreviewItemCell>(parent);
			if ((Object)(object)elementFromPool == (Object)null)
			{
				return null;
			}
			Normalize(((Component)elementFromPool).transform);
			previewDataField.SetValue(elementFromPool, emptyPreviewData);
			SetActive((Component)(object)Field<LazyButton>(elementFromPool, "tabButton"), active: false);
			SetActive(Field<GameObject>(elementFromPool, "uknownCraftBlocker"), active: false);
			SetActive(Field<GameObject>(elementFromPool, "canNotStartCraftBlocker"), active: false);
			SetActive(Field<GameObject>(elementFromPool, "customImageNonInteractableBlocker"), active: false);
			if ((Object)(object)elementFromPool.customImageBack != (Object)null)
			{
				((Component)elementFromPool.customImageBack).gameObject.SetActive(false);
			}
			((Component)elementFromPool.uiItemCell).gameObject.SetActive(true);
			elementFromPool.uiItemCell.Flush(true);
			return elementFromPool;
		}

		public UICraftPreviewItemCell GetTabPreviewCell(Transform parent, string wgoId)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			UICraftPreviewItemCell elementFromPool = Pooler.GetElementFromPool<UICraftPreviewItemCell>(parent);
			if ((Object)(object)elementFromPool == (Object)null)
			{
				return null;
			}
			Normalize(((Component)elementFromPool).transform);
			elementFromPool.uiItemCell.Flush(true);
			if ((Object)(object)TabBackSprite != (Object)null)
			{
				((LazyWidget<UICraftPreviewItemCellData>)(object)elementFromPool).Draw(new UICraftPreviewItemCellData((CraftDef)null, (WgoData)null, (Action<CraftDef, List<NeedItemData>, CraftParamsData, int>)null, (Action<CraftDef, List<NeedItemData>, CraftParamsData, int>)null, wgoId, false, TabBackSprite));
			}
			else
			{
				previewDataField.SetValue(elementFromPool, emptyPreviewData);
				SetActive((Component)(object)Field<LazyButton>(elementFromPool, "tabButton"), active: false);
				SetActive(Field<GameObject>(elementFromPool, "uknownCraftBlocker"), active: false);
				SetActive(Field<GameObject>(elementFromPool, "canNotStartCraftBlocker"), active: false);
				SetActive(Field<GameObject>(elementFromPool, "customImageNonInteractableBlocker"), active: false);
				elementFromPool.customImage.sprite = LazySingletonSO<EasySpritesCollection>.Instance.GetSprite("i_b_" + wgoId, "i_b_null");
				((Component)elementFromPool.uiItemCell).gameObject.SetActive(false);
			}
			return elementFromPool;
		}

		public void ReleasePreviewCell(UICraftPreviewItemCell cell)
		{
			if (!((Object)(object)cell == (Object)null))
			{
				HideTooltipAt(((Object)(object)cell.uiItemCell != (Object)null) ? ((Component)cell.uiItemCell).transform : ((Component)cell).transform);
				UIItemCell uiItemCell = cell.uiItemCell;
				if (uiItemCell != null)
				{
					uiItemCell.Flush(true);
				}
				((LazyWidgetBase)cell).Hide();
				UIPrefabsPooler pooler = Pooler;
				if (pooler != null)
				{
					pooler.ReleaseElementToPool<UICraftPreviewItemCell>(cell);
				}
			}
		}

		public UICraftsTabWidget GetTabWidget(Transform parent, out Transform cellsParent)
		{
			UICraftsTabWidget elementFromPool = Pooler.GetElementFromPool<UICraftsTabWidget>(parent);
			Normalize(((Component)elementFromPool).transform);
			((Component)elementFromPool).gameObject.SetActive(true);
			cellsParent = Field<Transform>(elementFromPool, "craftsParent") ?? ((Component)elementFromPool).transform;
			return elementFromPool;
		}

		public void ReleaseTabWidget(UICraftsTabWidget tab)
		{
			if (!((Object)(object)tab == (Object)null))
			{
				UIPrefabsPooler pooler = Pooler;
				if (pooler != null)
				{
					pooler.ReleaseElementToPool<UICraftsTabWidget>(tab);
				}
			}
		}

		public UICraftsTabSeparatorWidget GetSeparator(Transform parent)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			UICraftsTabSeparatorWidget elementFromPool = Pooler.GetElementFromPool<UICraftsTabSeparatorWidget>(parent);
			Normalize(((Component)elementFromPool).transform);
			((LazyWidget<UICraftsTabSeparatorWidgetData>)(object)elementFromPool).Draw(new UICraftsTabSeparatorWidgetData());
			return elementFromPool;
		}

		public void ReleaseSeparator(UICraftsTabSeparatorWidget sep)
		{
			if (!((Object)(object)sep == (Object)null))
			{
				((LazyWidgetBase)sep).Hide();
				UIPrefabsPooler pooler = Pooler;
				if (pooler != null)
				{
					pooler.ReleaseElementToPool<UICraftsTabSeparatorWidget>(sep);
				}
			}
		}

		private static void HideTooltipAt(Transform t)
		{
			try
			{
				RectTransform val = (RectTransform)(object)((t is RectTransform) ? t : null);
				if (val != null && UITooltip.IsTooltipShowingAtTarget(val))
				{
					UITooltip.HideImmediately();
				}
			}
			catch
			{
			}
		}

		private static void SetActive(Component c, bool active)
		{
			if ((Object)(object)c != (Object)null)
			{
				c.gameObject.SetActive(active);
			}
		}

		private static void SetActive(GameObject go, bool active)
		{
			if ((Object)(object)go != (Object)null)
			{
				go.SetActive(active);
			}
		}

		public static T Field<T>(object obj, string name) where T : class
		{
			if (obj != null)
			{
				Object val = (Object)((obj is Object) ? obj : null);
				if (val == null || !(val == (Object)null))
				{
					FieldInfo fieldInfo = AccessTools.Field(obj.GetType(), name);
					if (fieldInfo == null)
					{
						Compat.MissingField(obj.GetType(), name);
						return null;
					}
					object value = fieldInfo.GetValue(obj);
					Object val2 = (Object)((value is Object) ? value : null);
					if (val2 != null && val2 == (Object)null)
					{
						return null;
					}
					return value as T;
				}
			}
			return null;
		}

		private static T Try<T>(Func<T> f, string what) where T : class
		{
			try
			{
				return f();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("UI template '" + what + "' unavailable: " + ex.Message));
				return null;
			}
		}

		private static void Try(Action a, string what)
		{
			try
			{
				a();
			}
			catch (Exception arg)
			{
				Plugin.Log.LogWarning((object)$"UI templates '{what}' failed: {arg}");
			}
		}

		private static Vector2 SizeOf(RectTransform rt, Vector2 fallback)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0027: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)rt == (Object)null)
			{
				return fallback;
			}
			Rect rect = rt.rect;
			Vector2 val = ((Rect)(ref rect)).size;
			if (val.x < 1f || val.y < 1f)
			{
				val = rt.sizeDelta;
			}
			if (!(val.x >= 1f) || !(val.y >= 1f))
			{
				return fallback;
			}
			return val;
		}

		private static string PathFrom(Transform root, Transform t)
		{
			List<string> list = new List<string>();
			Transform val = t;
			while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)root)
			{
				list.Insert(0, ((Object)val).name);
				val = val.parent;
			}
			return string.Join("/", list);
		}
	}
	internal sealed class CanvasSorting : MonoBehaviour
	{
		public int Order;

		private void OnEnable()
		{
			Apply();
		}

		public void Apply()
		{
			Canvas component = ((Component)this).GetComponent<Canvas>();
			if (!((Object)(object)component == (Object)null))
			{
				component.overrideSorting = true;
				component.sortingOrder = Order;
			}
		}
	}
	internal sealed class DragHandle : MonoBehaviour, IBeginDragHandler, IEventSystemHandler, IDragHandler, IEndDragHandler
	{
		public RectTransform Target;

		public Action OnDragEnd;

		private Vector2 startMouse;

		private Vector2 startPos;

		public bool Dragging { get; private set; }

		public void OnBeginDrag(PointerEventData e)
		{
			//IL_001a: 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_0036: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)Target == (Object)null))
			{
				RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform)((Transform)Target).parent, e.position, e.pressEventCamera, ref startMouse);
				startPos = Target.anchoredPosition;
				Dragging = true;
			}
		}

		public void OnDrag(PointerEventData e)
		{
			//IL_001a: 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_0032: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)Target == (Object)null))
			{