BepInEx/plugins/UEI/UEI.dll

Decompiled an hour 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.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("UEI - Unknown Enough Items")]
[assembly: AssemblyProduct("UEI - Unknown Enough Items")]
[assembly: AssemblyCompany("Aakber (小叶子)")]
[assembly: AssemblyCopyright("Copyright (c) 2026 Aakber (小叶子)")]
[assembly: AssemblyFileVersion("1.2.4")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyVersion("1.2.4.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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;
		}
	}
}
[BepInPlugin("casualtiesunknown.uei", "UEI - Unknown Enough Items", "1.2.4")]
public sealed class UeiPlugin : BaseUnityPlugin
{
	public const string PluginGuid = "casualtiesunknown.uei";

	public const string PluginName = "UEI - Unknown Enough Items";

	public const string PluginVersionBase = "1.2";

	public const string PluginVersion = "1.2.4";

	public const string PluginAuthor = "Aakber (小叶子)";

	internal static UeiPlugin Instance;

	internal static ConfigEntry<string> FavoriteEntries;

	internal static ConfigEntry<string> LanguageMode;

	internal static ConfigEntry<string> PanelPosition;

	internal static ConfigEntry<float> PanelScale;

	internal static ConfigEntry<bool> CheatEnabled;

	private static ConfigFile? ConfigFileRef;

	private static ManualLogSource? LogSourceRef;

	private static UeiRuntime? RuntimeRef;

	private static UeiProbeListener? ProbeRef;

	private Harmony? _harmony;

	private void Awake()
	{
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Expected O, but got Unknown
		((BaseUnityPlugin)this).Logger.LogInfo((object)"UEI plugin Awake.");
		Instance = this;
		ConfigFileRef = ((BaseUnityPlugin)this).Config;
		LogSourceRef = ((BaseUnityPlugin)this).Logger;
		Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
		FavoriteEntries = ((BaseUnityPlugin)this).Config.Bind<string>("Favorites", "FavoriteEntries", string.Empty, "Favorited UEI entries, persisted as item:<id>|liquid:<id>.");
		UeiFavorites.Load(FavoriteEntries.Value);
		LanguageMode = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Language", "auto", "UEI UI language: auto, en, zh.");
		PanelPosition = ((BaseUnityPlugin)this).Config.Bind<string>("General", "PanelPosition", "left", "UEI panel position: left or right.");
		PanelScale = ((BaseUnityPlugin)this).Config.Bind<float>("General", "PanelScale", 1f, "UEI panel scale multiplier. The in-panel setting cycles 0.85 - 1.30.");
		CheatEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Cheat", "Enabled", false, "When enabled, left-clicking a legal UEI item gives one item to the player's inventory.");
		_harmony = new Harmony("casualtiesunknown.uei");
		_harmony.PatchAll(typeof(UeiPlugin).Assembly);
		LogPatchStatus();
		EnsureRuntime("plugin Awake");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"UEI - Unknown Enough Items 1.2.4 loaded.");
	}

	private void OnDisable()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"UEI plugin OnDisable. runtimeAlive={(Object)(object)RuntimeRef != (Object)null} probeAlive={(Object)(object)ProbeRef != (Object)null}");
	}

	private void OnDestroy()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"UEI plugin OnDestroy. runtimeAlive={(Object)(object)RuntimeRef != (Object)null} probeAlive={(Object)(object)ProbeRef != (Object)null}");
		Instance = null;
	}

	internal static void EnsureRuntime(string source)
	{
		//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_001f: Expected O, but got Unknown
		//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_0052: Expected O, but got Unknown
		bool flag = false;
		if ((Object)(object)RuntimeRef == (Object)null)
		{
			GameObject val = new GameObject("UEI.Runtime");
			Object.DontDestroyOnLoad((Object)val);
			RuntimeRef = val.AddComponent<UeiRuntime>();
			LogInfo("Created standalone UEI runtime object.");
			flag = true;
		}
		if ((Object)(object)ProbeRef == (Object)null)
		{
			GameObject val2 = new GameObject("UEI.Probe");
			Object.DontDestroyOnLoad((Object)val2);
			ProbeRef = val2.AddComponent<UeiProbeListener>();
			LogInfo("Created standalone UEI probe listener object.");
			flag = true;
		}
		if (flag)
		{
			LogInfo("UEI runtime ensured via " + source + ".");
		}
	}

	internal static void ClearRuntime(UeiRuntime runtime)
	{
		if ((Object)(object)RuntimeRef == (Object)(object)runtime)
		{
			RuntimeRef = null;
		}
	}

	internal static void ClearProbe(UeiProbeListener probe)
	{
		if ((Object)(object)ProbeRef == (Object)(object)probe)
		{
			ProbeRef = null;
		}
	}

	internal static void SaveFavorites()
	{
		if (FavoriteEntries != null)
		{
			FavoriteEntries.Value = UeiFavorites.Serialize();
			ConfigFile? configFileRef = ConfigFileRef;
			if (configFileRef != null)
			{
				configFileRef.Save();
			}
		}
	}

	internal static void SetLanguageMode(string mode)
	{
		if (LanguageMode != null)
		{
			LanguageMode.Value = mode;
			ConfigFile? configFileRef = ConfigFileRef;
			if (configFileRef != null)
			{
				configFileRef.Save();
			}
		}
	}

	internal static void SetPanelPosition(string position)
	{
		if (PanelPosition != null)
		{
			PanelPosition.Value = position;
			ConfigFile? configFileRef = ConfigFileRef;
			if (configFileRef != null)
			{
				configFileRef.Save();
			}
		}
	}

	internal static void SetPanelScale(float scale)
	{
		if (PanelScale != null)
		{
			PanelScale.Value = Mathf.Clamp(scale, 0.85f, 1.3f);
			ConfigFile? configFileRef = ConfigFileRef;
			if (configFileRef != null)
			{
				configFileRef.Save();
			}
		}
	}

	internal static void SetCheatEnabled(bool enabled)
	{
		if (CheatEnabled != null)
		{
			CheatEnabled.Value = enabled;
			ConfigFile? configFileRef = ConfigFileRef;
			if (configFileRef != null)
			{
				configFileRef.Save();
			}
		}
	}

	internal static void LogInfo(string message)
	{
		ManualLogSource? logSourceRef = LogSourceRef;
		if (logSourceRef != null)
		{
			logSourceRef.LogInfo((object)message);
		}
	}

	internal static void LogWarning(string message)
	{
		ManualLogSource? logSourceRef = LogSourceRef;
		if (logSourceRef != null)
		{
			logSourceRef.LogWarning((object)message);
		}
	}

	internal static void LogError(string message)
	{
		ManualLogSource? logSourceRef = LogSourceRef;
		if (logSourceRef != null)
		{
			logSourceRef.LogError((object)message);
		}
	}

	private void LogPatchStatus()
	{
		TryLogPatchStatus(typeof(PlayerCamera), "HandleInput");
		TryLogPatchStatus(typeof(PlayerCamera), "HandleRadialMenu");
		TryLogPatchStatus(typeof(PlayerCamera), "HandleWoundView");
		TryLogPatchStatus(typeof(GlobalDark), "Update");
	}

	private void TryLogPatchStatus(Type ownerType, string methodName)
	{
		try
		{
			MethodInfo methodInfo = AccessTools.Method(ownerType, methodName, (Type[])null, (Type[])null);
			if (methodInfo == null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("UEI patch target missing: " + ownerType.Name + "." + methodName));
				return;
			}
			Patches patchInfo = Harmony.GetPatchInfo((MethodBase)methodInfo);
			string text = ((patchInfo == null) ? "none" : string.Join(",", patchInfo.Prefixes.Select((Patch x) => "pre:" + x.owner).Concat(patchInfo.Postfixes.Select((Patch x) => "post:" + x.owner)).Concat(patchInfo.Transpilers.Select((Patch x) => "trans:" + x.owner))
				.Distinct()));
			((BaseUnityPlugin)this).Logger.LogInfo((object)("UEI patch target " + ownerType.Name + "." + methodName + " owners=" + text));
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("UEI patch status failed for " + ownerType.Name + "." + methodName + ": " + ex.Message));
		}
	}
}
internal static class UeiFavorites
{
	private static readonly HashSet<string> Favorites = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

	public static int Count => Favorites.Count;

	public static void Load(string serialized)
	{
		Favorites.Clear();
		if (string.IsNullOrWhiteSpace(serialized))
		{
			return;
		}
		string[] array = serialized.Split('|');
		for (int i = 0; i < array.Length; i++)
		{
			string text = array[i].Trim();
			if (!string.IsNullOrEmpty(text))
			{
				Favorites.Add(text);
			}
		}
	}

	public static bool Contains(string entryKey)
	{
		return Favorites.Contains(entryKey);
	}

	public static void Toggle(string entryKey)
	{
		if (!string.IsNullOrWhiteSpace(entryKey))
		{
			if (!Favorites.Remove(entryKey))
			{
				Favorites.Add(entryKey);
			}
			UeiPlugin.SaveFavorites();
		}
	}

	public static void ClearAll()
	{
		if (Favorites.Count != 0)
		{
			Favorites.Clear();
			UeiPlugin.SaveFavorites();
		}
	}

	public static string Serialize()
	{
		return string.Join("|", Favorites.OrderBy<string, string>((string x) => x, StringComparer.OrdinalIgnoreCase));
	}
}
internal static class UeiCatalog
{
	public const string CategoryAll = "All";

	public const string CategoryFavorites = "Favorites";

	public const string CategoryLiquid = "Liquid";

	private static readonly List<UeiEntry> EntriesBacking = new List<UeiEntry>();

	private static readonly List<string> CategoryKeysBacking = new List<string>();

	private static readonly Dictionary<string, UeiEntry> EntriesByKey = new Dictionary<string, UeiEntry>(StringComparer.OrdinalIgnoreCase);

	private static readonly Dictionary<string, List<UeiRecipeLink>> ProducedByLinks = new Dictionary<string, List<UeiRecipeLink>>(StringComparer.OrdinalIgnoreCase);

	private static readonly Dictionary<string, List<UeiRecipeLink>> UsedInLinks = new Dictionary<string, List<UeiRecipeLink>>(StringComparer.OrdinalIgnoreCase);

	private static int _itemCount = -1;

	private static int _liquidCount = -1;

	private static int _recipeCount = -1;

	private static int _playerInt = -1;

	private static int _madeRecipeCount = -1;

	private static int _specialKnownCount = -1;

	private static string _localeName = string.Empty;

	private static int _revision;

	private static float _lastRecipeFlagCheck = -999f;

	public static IReadOnlyList<UeiEntry> Entries => EntriesBacking;

	public static IReadOnlyList<string> CategoryKeys => CategoryKeysBacking;

	public static int Revision => _revision;

	public static void ForceRebuild()
	{
		_itemCount = -1;
		_liquidCount = -1;
		_recipeCount = -1;
		_playerInt = -1;
		_madeRecipeCount = -1;
		_specialKnownCount = -1;
		_localeName = string.Empty;
		_lastRecipeFlagCheck = -999f;
		_revision++;
	}

	public static bool EnsureBuilt()
	{
		if (!IsRuntimeDataReady())
		{
			return false;
		}
		int count = Item.GlobalItems.Count;
		int count2 = Liquids.Registry.Count;
		int count3 = Recipes.recipes.Count;
		int iNT = PlayerCamera.main.body.skills.INT;
		string text = SafeString(() => Locale.currentLangName, string.Empty);
		bool flag = count == _itemCount && count2 == _liquidCount && count3 == _recipeCount && iNT == _playerInt && string.Equals(text, _localeName, StringComparison.Ordinal) && EntriesBacking.Count > 0;
		if (flag && Time.unscaledTime - _lastRecipeFlagCheck < 1f)
		{
			return true;
		}
		int num = 0;
		int num2 = 0;
		foreach (Recipe recipe in Recipes.recipes)
		{
			if (recipe.hasMadeBefore)
			{
				num++;
			}
			if (recipe.specialKnown)
			{
				num2++;
			}
		}
		_lastRecipeFlagCheck = Time.unscaledTime;
		if (flag && num == _madeRecipeCount && num2 == _specialKnownCount)
		{
			return true;
		}
		Build(count, count2, count3, iNT, num, num2, text);
		return true;
	}

	public static string EntryKey(UeiEntryKind kind, string id)
	{
		return ((kind == UeiEntryKind.Item) ? "item:" : "liquid:") + id;
	}

	public static bool TryGetEntry(UeiEntryKind kind, string id, out UeiEntry? entry)
	{
		string key = EntryKey(kind, id);
		if (EntriesByKey.TryGetValue(key, out entry))
		{
			return true;
		}
		string baseId = RshLibHelper.GetBaseId(id);
		if (baseId != id)
		{
			return EntriesByKey.TryGetValue(EntryKey(kind, baseId), out entry);
		}
		entry = null;
		return false;
	}

	public static List<UeiRecipeLink> GetProducedBy(UeiEntry entry)
	{
		if (!ProducedByLinks.TryGetValue(entry.EntryKey, out List<UeiRecipeLink> value))
		{
			return new List<UeiRecipeLink>();
		}
		return value;
	}

	public static List<UeiRecipeLink> GetUsedIn(UeiEntry entry)
	{
		if (!UsedInLinks.TryGetValue(entry.EntryKey, out List<UeiRecipeLink> value))
		{
			return new List<UeiRecipeLink>();
		}
		return value;
	}

	public static string CategoryLabel(string categoryKey)
	{
		return UeiI18n.CategoryLabel(categoryKey);
	}

	public static bool IsDangerousLiquid(string id)
	{
		if (Liquids.DangerList != null)
		{
			return Liquids.DangerList.Contains(id);
		}
		return false;
	}

	private static bool IsRuntimeDataReady()
	{
		try
		{
			return Item.GlobalItems != null && Item.GlobalItems.Count > 0 && Liquids.Registry != null && Liquids.Registry.Count > 0 && Recipes.recipes != null && Recipes.recipes.Count > 0 && (Object)(object)PlayerCamera.main != (Object)null && (Object)(object)PlayerCamera.main.body != (Object)null;
		}
		catch
		{
			return false;
		}
	}

	private static void Build(int itemCount, int liquidCount, int recipeCount, int playerInt, int madeRecipeCount, int specialKnownCount, string localeName)
	{
		EntriesBacking.Clear();
		EntriesByKey.Clear();
		ProducedByLinks.Clear();
		UsedInLinks.Clear();
		Sprite droplet = SafeLoadDroplet();
		foreach (KeyValuePair<string, ItemInfo> item in Item.GlobalItems.OrderBy<KeyValuePair<string, ItemInfo>, string>((KeyValuePair<string, ItemInfo> x) => x.Key, StringComparer.OrdinalIgnoreCase))
		{
			UeiEntry ueiEntry = BuildItemEntry(item.Key, item.Value);
			EntriesBacking.Add(ueiEntry);
			EntriesByKey[ueiEntry.EntryKey] = ueiEntry;
		}
		foreach (KeyValuePair<string, LiquidType> item2 in Liquids.Registry.OrderBy<KeyValuePair<string, LiquidType>, string>((KeyValuePair<string, LiquidType> x) => x.Key, StringComparer.OrdinalIgnoreCase))
		{
			UeiEntry ueiEntry2 = BuildLiquidEntry(item2.Key, item2.Value, droplet);
			EntriesBacking.Add(ueiEntry2);
			EntriesByKey[ueiEntry2.EntryKey] = ueiEntry2;
		}
		BuildCategories();
		BuildRecipeLinks();
		_itemCount = itemCount;
		_liquidCount = liquidCount;
		_recipeCount = recipeCount;
		_playerInt = playerInt;
		_madeRecipeCount = madeRecipeCount;
		_specialKnownCount = specialKnownCount;
		_localeName = localeName;
		_revision++;
		UeiPlugin.LogInfo($"UEI catalog built: {EntriesBacking.Count} entries, {Recipes.recipes.Count} recipes.");
	}

	private static UeiEntry BuildItemEntry(string id, ItemInfo info)
	{
		//IL_00f8: 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)
		if (CuCoreLibHelper.TryGetItemInfo(id, out ItemInfo info2) && info2 != null)
		{
			info = info2;
		}
		string text = UeiI18n.ItemText(id, string.Empty);
		if (string.IsNullOrWhiteSpace(text))
		{
			text = SafeString(() => info.fullName, id);
		}
		string text2 = UeiI18n.ItemText(id + "dsc", string.Empty);
		if (string.IsNullOrWhiteSpace(text2))
		{
			text2 = SafeString(() => info.description, string.Empty);
		}
		string categoryKey = (string.IsNullOrWhiteSpace(info.category) ? "other" : info.category.Trim());
		UeiEntry obj = new UeiEntry
		{
			Kind = UeiEntryKind.Item,
			Id = id,
			EntryKey = EntryKey(UeiEntryKind.Item, id),
			DisplayName = text,
			Description = text2,
			CategoryKey = categoryKey,
			CategoryLabel = CategoryLabel(categoryKey),
			Icon = SafeLoadItemSprite(id),
			IconColor = Color.white,
			ItemInfo = info
		};
		AddTags(obj, info);
		AddQualities(obj, info.qualities);
		obj.SearchText = BuildSearchText(obj);
		return obj;
	}

	private static UeiEntry BuildLiquidEntry(string id, LiquidType info, Sprite? droplet)
	{
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		string text = UeiI18n.LiquidText(id, string.Empty);
		if (string.IsNullOrWhiteSpace(text) || text == id)
		{
			string text2 = SafeString(() => info.localeName, id);
			text = UeiI18n.LiquidText(text2, text2);
		}
		UeiEntry ueiEntry = new UeiEntry
		{
			Kind = UeiEntryKind.Liquid,
			Id = id,
			EntryKey = EntryKey(UeiEntryKind.Liquid, id),
			DisplayName = text,
			Description = UeiI18n.LiquidText(id + "dsc", string.Empty),
			CategoryKey = "Liquid",
			CategoryLabel = CategoryLabel("Liquid"),
			Icon = droplet,
			IconColor = info.color,
			LiquidInfo = info
		};
		if (info.injectable)
		{
			ueiEntry.Tags.Add("injectable");
		}
		if (info.healthUsable)
		{
			ueiEntry.Tags.Add("health");
		}
		if (IsDangerousLiquid(id))
		{
			ueiEntry.Tags.Add("danger");
		}
		AddQualities(ueiEntry, info.qualities);
		ueiEntry.SearchText = BuildSearchText(ueiEntry);
		return ueiEntry;
	}

	private static void BuildCategories()
	{
		CategoryKeysBacking.Clear();
		CategoryKeysBacking.Add("All");
		CategoryKeysBacking.Add("Favorites");
		foreach (string item in (from x in EntriesBacking
			where x.Kind == UeiEntryKind.Item
			select x.CategoryKey into x
			where !string.IsNullOrWhiteSpace(x)
			select x).Distinct<string>(StringComparer.OrdinalIgnoreCase).OrderBy<string, string>((string x) => x, StringComparer.OrdinalIgnoreCase))
		{
			CategoryKeysBacking.Add(item);
		}
		CategoryKeysBacking.Add("Liquid");
	}

	private static void BuildRecipeLinks()
	{
		for (int i = 0; i < Recipes.recipes.Count; i++)
		{
			Recipe recipe = Recipes.recipes[i];
			AddProducedLink(recipe, i);
			AddUsedLinks(recipe, i);
		}
	}

	private static void AddProducedLink(Recipe recipe, int recipeIndex)
	{
		if (recipe.result == null || string.IsNullOrWhiteSpace(recipe.result.id))
		{
			return;
		}
		string id = recipe.result.id;
		UeiEntryKind kind = (recipe.result.isLiquid ? UeiEntryKind.Liquid : UeiEntryKind.Item);
		string key = RshLibHelper.TryResolveKey(id, kind, EntriesByKey);
		if (EntriesByKey.ContainsKey(key) || EntriesByKey.ContainsKey(EntryKey(kind, id)))
		{
			if (!EntriesByKey.ContainsKey(key))
			{
				key = EntryKey(kind, id);
			}
			GetOrCreate(ProducedByLinks, key).Add(NewRecipeLink(recipe, recipeIndex, UeiRecipeRelation.ProducedBy));
		}
	}

	private static void AddUsedLinks(Recipe recipe, int recipeIndex)
	{
		if (recipe.items == null)
		{
			return;
		}
		HashSet<string> hashSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
		foreach (RecipeItem item in recipe.items)
		{
			foreach (UeiEntry item2 in EntriesBacking)
			{
				if (RecipeItemUsesEntry(item, item2) && hashSet.Add(item2.EntryKey))
				{
					GetOrCreate(UsedInLinks, item2.EntryKey).Add(NewRecipeLink(recipe, recipeIndex, UeiRecipeRelation.UsedIn));
				}
			}
		}
	}

	private static bool RecipeItemUsesEntry(RecipeItem item, UeiEntry entry)
	{
		if (item.isLiquid != (entry.Kind == UeiEntryKind.Liquid))
		{
			return false;
		}
		if (item.specific || !string.IsNullOrWhiteSpace(item.specificId))
		{
			string text = item.specificId ?? string.Empty;
			if (string.Equals(text, entry.Id, StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			return string.Equals(RshLibHelper.GetBaseId(text), entry.Id, StringComparison.OrdinalIgnoreCase);
		}
		if (item.quality == null || string.IsNullOrWhiteSpace(item.quality.id))
		{
			return false;
		}
		if (entry.Kind == UeiEntryKind.Liquid)
		{
			return entry.Qualities.Any((CraftingQuality q) => string.Equals(q.id, item.quality.id, StringComparison.OrdinalIgnoreCase) && q.amount > 0f);
		}
		return entry.Qualities.Any((CraftingQuality q) => string.Equals(q.id, item.quality.id, StringComparison.OrdinalIgnoreCase) && q.amount >= item.quality.amount);
	}

	private static UeiRecipeLink NewRecipeLink(Recipe recipe, int recipeIndex, UeiRecipeRelation relation)
	{
		return new UeiRecipeLink
		{
			RecipeIndex = recipeIndex,
			Relation = relation,
			Visible = SafeBool(() => recipe.visible, fallback: true),
			HasMadeBefore = recipe.hasMadeBefore
		};
	}

	private static List<UeiRecipeLink> GetOrCreate(Dictionary<string, List<UeiRecipeLink>> map, string key)
	{
		if (!map.TryGetValue(key, out List<UeiRecipeLink> value))
		{
			value = (map[key] = new List<UeiRecipeLink>());
		}
		return value;
	}

	private static void AddTags(UeiEntry entry, ItemInfo info)
	{
		try
		{
			string[] tags = info.GetTags();
			if (tags == null)
			{
				return;
			}
			string[] array = tags;
			foreach (string text in array)
			{
				if (!string.IsNullOrWhiteSpace(text))
				{
					entry.Tags.Add(text.Trim());
				}
			}
		}
		catch
		{
			if (string.IsNullOrWhiteSpace(info.tags))
			{
				return;
			}
			string[] array = info.tags.Split(',');
			foreach (string text2 in array)
			{
				if (!string.IsNullOrWhiteSpace(text2))
				{
					entry.Tags.Add(text2.Trim());
				}
			}
		}
	}

	private static void AddQualities(UeiEntry entry, List<CraftingQuality>? qualities)
	{
		if (qualities == null)
		{
			return;
		}
		foreach (CraftingQuality quality in qualities)
		{
			if (quality != null && !string.IsNullOrWhiteSpace(quality.id))
			{
				entry.Qualities.Add(quality);
			}
		}
	}

	private static string BuildSearchText(UeiEntry entry)
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.Append(entry.Id).Append(' ');
		stringBuilder.Append(entry.EntryKey).Append(' ');
		stringBuilder.Append(entry.DisplayName).Append(' ');
		stringBuilder.Append(entry.Description).Append(' ');
		stringBuilder.Append(entry.CategoryKey).Append(' ');
		stringBuilder.Append(entry.CategoryLabel).Append(' ');
		foreach (string tag in entry.Tags)
		{
			stringBuilder.Append(tag).Append(' ');
		}
		foreach (CraftingQuality quality in entry.Qualities)
		{
			stringBuilder.Append(quality.id).Append(' ');
			stringBuilder.Append(SafeString(() => quality.LocaleName, string.Empty)).Append(' ');
		}
		return stringBuilder.ToString();
	}

	private static Sprite? SafeLoadItemSprite(string id)
	{
		Sprite val = CuCoreLibHelper.GetCustomItemSprite(id) ?? RshLibHelper.GetCustomItemSprite(id) ?? SexModHelper.GetCustomItemSprite(id);
		if ((Object)(object)val != (Object)null)
		{
			return val;
		}
		try
		{
			GameObject val2 = Resources.Load<GameObject>(id);
			if ((Object)(object)val2 == (Object)null)
			{
				return null;
			}
			SpriteRenderer component = val2.GetComponent<SpriteRenderer>();
			return ((Object)(object)component != (Object)null) ? component.sprite : null;
		}
		catch
		{
			return null;
		}
	}

	private static Sprite? SafeLoadDroplet()
	{
		try
		{
			return Resources.Load<Sprite>("Sprites/droplet");
		}
		catch
		{
			return null;
		}
	}

	private static string SafeString(Func<string> getter, string fallback)
	{
		try
		{
			string text = getter();
			return string.IsNullOrWhiteSpace(text) ? fallback : text;
		}
		catch
		{
			return fallback;
		}
	}

	private static bool SafeBool(Func<bool> getter, bool fallback)
	{
		try
		{
			return getter();
		}
		catch
		{
			return fallback;
		}
	}
}
internal enum TogetherNetworkState
{
	NotInstalled,
	Offline,
	Client,
	Server,
	Unknown
}
internal enum UeiGiveRoute
{
	Unavailable,
	LocalFactory,
	ServerCommand,
	HostRequired
}
internal static class UeiCheatPolicy
{
	internal static bool HasTogetherAccess(TogetherNetworkState state, bool? adminGranted, bool? serverCheats)
	{
		switch (state)
		{
		case TogetherNetworkState.NotInstalled:
		case TogetherNetworkState.Offline:
			return true;
		case TogetherNetworkState.Client:
			return adminGranted == true;
		case TogetherNetworkState.Server:
			return serverCheats == true;
		default:
			return false;
		}
	}

	internal static UeiGiveRoute GiveRoute(TogetherNetworkState state, bool customItem, bool resourceItem)
	{
		if (!customItem && !resourceItem)
		{
			return UeiGiveRoute.Unavailable;
		}
		switch (state)
		{
		case TogetherNetworkState.Client:
			return customItem ? UeiGiveRoute.HostRequired : UeiGiveRoute.ServerCommand;
		case TogetherNetworkState.Server:
			return customItem ? UeiGiveRoute.LocalFactory : UeiGiveRoute.ServerCommand;
		case TogetherNetworkState.NotInstalled:
		case TogetherNetworkState.Offline:
			return UeiGiveRoute.LocalFactory;
		default:
			return UeiGiveRoute.Unavailable;
		}
	}
}
internal static class UeiI18n
{
	private static readonly Dictionary<string, string> En = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
	{
		["category.all"] = "All",
		["category.favorites"] = "Favorites",
		["category.liquid"] = "Liquid",
		["category.other"] = "Other",
		["itemCategory.medical"] = "Medical",
		["itemCategory.drug"] = "Drugs",
		["itemCategory.container"] = "Containers",
		["itemCategory.food"] = "Food",
		["itemCategory.water"] = "Water",
		["itemCategory.tool"] = "Tools",
		["itemCategory.trash"] = "Trash",
		["itemCategory.utility"] = "Utility",
		["itemCategory.custom"] = "Custom",
		["itemCategory.unobtainable"] = "Unobtainable",
		["itemCategory.other"] = "Other",
		["recipeCategory.materials"] = "Materials",
		["recipeCategory.tools"] = "Tools",
		["recipeCategory.medicine"] = "Medicine",
		["recipeCategory.utilities"] = "Utilities",
		["recipeCategory.food"] = "Food",
		["quality.foliage"] = "Foliage",
		["quality.nails"] = "Nails",
		["quality.water"] = "Water",
		["quality.hammering"] = "Hammering",
		["quality.cutting"] = "Cutting",
		["quality.rippable"] = "Rippable",
		["quality.disinfectant"] = "Antiseptic",
		["quality.blood"] = "Blood",
		["quality.opiate"] = "Opiate",
		["quality.dressing"] = "Dressing",
		["quality.produce"] = "Produce",
		["quality.meat"] = "Meat",
		["quality.firestarter"] = "Firestarter",
		["quality.heatsource"] = "Heat source",
		["quality.flammable"] = "Flammable",
		["quality.flour"] = "Flour",
		["quality.fat"] = "Fat",
		["quality.condiment"] = "Condiments",
		["search.placeholder"] = "Search...",
		["loading.items"] = "Waiting for item data...",
		["detail.source"] = "Source",
		["detail.uses"] = "Uses",
		["detail.mode.source"] = "SRC",
		["detail.mode.uses"] = "USE",
		["detail.empty"] = "No recipes",
		["detail.noIngredients"] = "No ingredients",
		["status.usedIn"] = "Used in",
		["status.source"] = "Source",
		["status.liquidSource"] = "Liquid source",
		["status.liquidUse"] = "Liquid use",
		["status.detailOnly"] = "Detail only",
		["status.recipes"] = "Recipes",
		["status.recipeLinkFailed"] = "Recipe link failed",
		["status.jumpRecipe"] = "Jumped",
		["status.jumpNoRecipe"] = "No recipe to jump",
		["status.jumpFailed"] = "Jump failed",
		["status.pinRecipe"] = "Pinned",
		["status.unpinRecipe"] = "Unpinned",
		["status.pinFailed"] = "Pin failed",
		["status.cheatSpawned"] = "Gave 1",
		["status.cheatRequestSent"] = "Give requested",
		["status.cheatHostRequired"] = "Mod item: ask the host to spawn it",
		["status.cheatIllegal"] = "Not a legal item",
		["status.cheatFailed"] = "Give failed",
		["status.reviveDone"] = "Revived",
		["status.reviveRequestSent"] = "Revive requested",
		["status.reviveFailed"] = "Revive failed",
		["button.settings.short"] = "S",
		["button.settings"] = "Settings",
		["button.settings.desc"] = "Open UEI settings",
		["button.revive"] = "Revive",
		["button.revive.desc"] = "Fully heal and revive the player character",
		["button.closeDetail"] = "Close",
		["button.closeDetail.desc"] = "Close UEI detail panel",
		["button.jumpRecipe"] = "Jump",
		["button.jumpRecipe.desc"] = "Open the original crafting panel at this recipe",
		["button.pinRecipe"] = "Pin recipe",
		["button.pinRecipe.desc"] = "Pin or unpin this recipe with the original crafting panel",
		["settings.title"] = "UEI Settings",
		["settings.language"] = "Language",
		["settings.language.auto"] = "Auto",
		["settings.language.zh"] = "Chinese",
		["settings.language.en"] = "English",
		["settings.position"] = "Position",
		["settings.position.left"] = "Left",
		["settings.position.right"] = "Right",
		["settings.scale"] = "Scale",
		["settings.apply"] = "Apply",
		["settings.cheat"] = "Cheat",
		["settings.on"] = "On",
		["settings.off"] = "Off",
		["settings.noCommandAccess"] = "No access",
		["settings.about"] = "About",
		["settings.aboutText"] = "UEI - Unknown Enough Items\nVersion: {0}\nGUID: {1}\nAuthor: {2}",
		["recipe.visible"] = "Visible",
		["recipe.locked"] = "Locked",
		["recipe.made"] = "Made",
		["recipe.new"] = "New",
		["recipe.int"] = "INT",
		["recipe.fallback"] = "Recipe",
		["ingredient.liquid"] = "Liquid",
		["ingredient.any"] = "Any",
		["ingredient.anyShort"] = "Any",
		["ingredient.liquidShort"] = "Liq",
		["ingredient.anyItemTitle"] = "Any item: {0}",
		["ingredient.anyLiquidTitle"] = "Any liquid: {0}",
		["ingredient.requirement"] = "Requirement",
		["ingredient.quality"] = "Quality",
		["ingredient.minimumCondition"] = "Minimum condition",
		["ingredient.matchingItems"] = "Matching items",
		["ingredient.matchingLiquids"] = "Matching liquids",
		["ingredient.noMatches"] = "No matching entries",
		["ingredient.moreMatches"] = "...and {0} more",
		["ingredient.needsMl"] = "{0} mL needed",
		["tooltip.id"] = "ID",
		["tooltip.value"] = "Value",
		["tooltip.injectable"] = "Injectable",
		["tooltip.healthUse"] = "Health use",
		["tooltip.weight"] = "Weight",
		["selection.noResults"] = "No results",
		["selection.entries"] = "{0} entries"
	};

	private static readonly Dictionary<string, string> Zh = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
	{
		["category.all"] = "全部",
		["category.favorites"] = "收藏",
		["category.liquid"] = "液体",
		["category.other"] = "其他",
		["itemCategory.medical"] = "医疗用品",
		["itemCategory.drug"] = "药物",
		["itemCategory.container"] = "容器",
		["itemCategory.food"] = "食物",
		["itemCategory.water"] = "饮料",
		["itemCategory.tool"] = "工具",
		["itemCategory.trash"] = "垃圾",
		["itemCategory.utility"] = "实用物品",
		["itemCategory.custom"] = "自定义",
		["itemCategory.unobtainable"] = "不可获得",
		["itemCategory.other"] = "其他",
		["recipeCategory.materials"] = "材料",
		["recipeCategory.tools"] = "工具",
		["recipeCategory.medicine"] = "药物",
		["recipeCategory.utilities"] = "杂项",
		["recipeCategory.food"] = "食物",
		["quality.foliage"] = "纤维",
		["quality.nails"] = "铁钉",
		["quality.water"] = "液体",
		["quality.hammering"] = "可捶打",
		["quality.cutting"] = "可切割",
		["quality.rippable"] = "可撕碎",
		["quality.disinfectant"] = "消毒",
		["quality.blood"] = "血液",
		["quality.opiate"] = "阿片",
		["quality.dressing"] = "敷料",
		["quality.produce"] = "农产品",
		["quality.meat"] = "肉类",
		["quality.firestarter"] = "火种",
		["quality.heatsource"] = "热源",
		["quality.flammable"] = "易燃的",
		["quality.flour"] = "面粉",
		["quality.fat"] = "脂肪",
		["quality.condiment"] = "调味料",
		["search.placeholder"] = "搜索...",
		["loading.items"] = "等待物品数据...",
		["detail.source"] = "来源",
		["detail.uses"] = "用途",
		["detail.mode.source"] = "源",
		["detail.mode.uses"] = "用",
		["detail.empty"] = "无配方",
		["detail.noIngredients"] = "无材料",
		["status.usedIn"] = "用途",
		["status.source"] = "来源",
		["status.liquidSource"] = "液体来源",
		["status.liquidUse"] = "液体用途",
		["status.detailOnly"] = "仅详情",
		["status.recipes"] = "配方",
		["status.recipeLinkFailed"] = "配方联动失败",
		["status.jumpRecipe"] = "已跳转",
		["status.jumpNoRecipe"] = "没有可跳转配方",
		["status.jumpFailed"] = "跳转失败",
		["status.pinRecipe"] = "已收藏配方",
		["status.unpinRecipe"] = "已取消收藏",
		["status.pinFailed"] = "收藏失败",
		["status.cheatSpawned"] = "已发放 1 个",
		["status.cheatRequestSent"] = "已请求服务器发放",
		["status.cheatHostRequired"] = "模组物品需由房主生成",
		["status.cheatIllegal"] = "不是合法物品",
		["status.cheatFailed"] = "发放失败",
		["status.reviveDone"] = "已复活",
		["status.reviveRequestSent"] = "已请求服务器复活",
		["status.reviveFailed"] = "复活失败",
		["button.settings.short"] = "设",
		["button.settings"] = "设置",
		["button.settings.desc"] = "打开 UEI 设置",
		["button.revive"] = "一键复活",
		["button.revive.desc"] = "回满并复活玩家角色",
		["button.closeDetail"] = "关闭",
		["button.closeDetail.desc"] = "关闭 UEI 详情面板",
		["button.jumpRecipe"] = "跳转",
		["button.jumpRecipe.desc"] = "在原版制作面板中打开这条配方",
		["button.pinRecipe"] = "收藏配方",
		["button.pinRecipe.desc"] = "调用原版制作面板收藏或取消收藏这条配方",
		["settings.title"] = "UEI 设置",
		["settings.language"] = "语言",
		["settings.language.auto"] = "自动",
		["settings.language.zh"] = "中文",
		["settings.language.en"] = "English",
		["settings.position"] = "位置",
		["settings.position.left"] = "左侧",
		["settings.position.right"] = "右侧",
		["settings.scale"] = "比例",
		["settings.apply"] = "应用",
		["settings.cheat"] = "作弊",
		["settings.on"] = "开启",
		["settings.off"] = "关闭",
		["settings.noCommandAccess"] = "无权限",
		["settings.about"] = "关于",
		["settings.aboutText"] = "UEI - Unknown Enough Items\n版本:{0}\nGUID:{1}\n作者:{2}",
		["recipe.visible"] = "可见",
		["recipe.locked"] = "锁定",
		["recipe.made"] = "已制作",
		["recipe.new"] = "未制作",
		["recipe.int"] = "智力",
		["recipe.fallback"] = "配方",
		["ingredient.liquid"] = "液体",
		["ingredient.any"] = "任意",
		["ingredient.anyShort"] = "任意",
		["ingredient.liquidShort"] = "液",
		["ingredient.anyItemTitle"] = "任意物品:{0}",
		["ingredient.anyLiquidTitle"] = "任意液体:{0}",
		["ingredient.requirement"] = "需求",
		["ingredient.quality"] = "质量",
		["ingredient.minimumCondition"] = "最低耐久",
		["ingredient.matchingItems"] = "可用物品",
		["ingredient.matchingLiquids"] = "可用液体",
		["ingredient.noMatches"] = "没有匹配项",
		["ingredient.moreMatches"] = "...以及另外 {0} 项",
		["ingredient.needsMl"] = "需要 {0} mL",
		["tooltip.id"] = "ID",
		["tooltip.value"] = "价值",
		["tooltip.injectable"] = "可注射",
		["tooltip.healthUse"] = "医疗用途",
		["tooltip.weight"] = "重量",
		["selection.noResults"] = "无结果",
		["selection.entries"] = "{0} 项"
	};

	public static string T(string key)
	{
		if ((IsChinese() ? Zh : En).TryGetValue(key, out string value))
		{
			return value;
		}
		if (!En.TryGetValue(key, out value))
		{
			return key;
		}
		return value;
	}

	public static string Format(string key, params object[] args)
	{
		return string.Format(T(key), args);
	}

	public static string ItemText(string localeKey, string fallback)
	{
		if (string.IsNullOrWhiteSpace(localeKey))
		{
			return fallback;
		}
		string text = SafeString(() => Locale.GetItem(localeKey), string.Empty);
		if (IsResolvedLocaleValue(text, localeKey))
		{
			return text;
		}
		string itemText = CuCoreLibHelper.GetItemText(localeKey);
		if (!IsResolvedLocaleValue(itemText, localeKey))
		{
			return fallback;
		}
		return itemText;
	}

	public static string OtherText(string localeKey, string fallback)
	{
		if (string.IsNullOrWhiteSpace(localeKey))
		{
			return fallback;
		}
		string text = SafeString(() => Locale.GetOther(localeKey), string.Empty);
		if (!IsResolvedLocaleValue(text, localeKey))
		{
			return fallback;
		}
		return text;
	}

	public static string LiquidText(string localeKey, string fallback)
	{
		return OtherText(localeKey, fallback);
	}

	public static string CategoryLabel(string categoryKey)
	{
		if (string.Equals(categoryKey, "All", StringComparison.OrdinalIgnoreCase))
		{
			return T("category.all");
		}
		if (string.Equals(categoryKey, "Favorites", StringComparison.OrdinalIgnoreCase))
		{
			return T("category.favorites");
		}
		if (string.Equals(categoryKey, "Liquid", StringComparison.OrdinalIgnoreCase))
		{
			return T("category.liquid");
		}
		if (string.IsNullOrWhiteSpace(categoryKey))
		{
			return T("category.other");
		}
		return ItemCategoryLabel(categoryKey);
	}

	public static string ItemCategoryLabel(string categoryKey)
	{
		if (string.IsNullOrWhiteSpace(categoryKey))
		{
			return T("category.other");
		}
		string text = categoryKey.Trim().ToLowerInvariant();
		if (TryTableText("itemCategory." + text, out string value))
		{
			return value;
		}
		string text2 = OtherText("category" + text, string.Empty);
		if (!string.IsNullOrWhiteSpace(text2))
		{
			return text2;
		}
		return HumanizeKey(categoryKey);
	}

	public static string RecipeCategoryLabel(object category)
	{
		string text = SafeString(() => category.ToString() ?? string.Empty, string.Empty);
		if (string.IsNullOrWhiteSpace(text))
		{
			return T("category.other");
		}
		string text2 = text.Trim().ToLowerInvariant();
		if (TryTableText("recipeCategory." + text2, out string value))
		{
			return value;
		}
		string text3 = OtherText("craftingcategory" + text2, string.Empty);
		if (!string.IsNullOrWhiteSpace(text3))
		{
			return text3;
		}
		return HumanizeKey(text);
	}

	public static string QualityLabel(string qualityId, string fallback)
	{
		if (string.IsNullOrWhiteSpace(qualityId))
		{
			return fallback;
		}
		string text = qualityId.Trim();
		if (text.StartsWith("cq", StringComparison.OrdinalIgnoreCase) && text.Length > 2)
		{
			text = text.Substring(2);
		}
		text = text.ToLowerInvariant();
		if (TryTableText("quality." + text, out string value))
		{
			return value;
		}
		string text2 = OtherText("cq" + text, string.Empty);
		if (!string.IsNullOrWhiteSpace(text2))
		{
			return text2;
		}
		if (!string.IsNullOrWhiteSpace(fallback))
		{
			return fallback;
		}
		return qualityId;
	}

	public static bool IsChinese()
	{
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Invalid comparison between Unknown and I4
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Invalid comparison between Unknown and I4
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Invalid comparison between Unknown and I4
		string value = SafeString(() => UeiPlugin.LanguageMode.Value, "auto").Trim();
		if (IsExplicitChinese(value))
		{
			return true;
		}
		if (IsExplicitEnglish(value))
		{
			return false;
		}
		string value2 = SafeString(() => Locale.currentLangName, string.Empty);
		if (string.IsNullOrWhiteSpace(value2))
		{
			value2 = SafeString(() => PlayerPrefs.GetString("locale"), string.Empty);
		}
		if (IsExplicitChinese(value2))
		{
			return true;
		}
		if (IsExplicitEnglish(value2))
		{
			return false;
		}
		SystemLanguage systemLanguage = Application.systemLanguage;
		if ((int)systemLanguage != 6 && (int)systemLanguage != 40)
		{
			return (int)systemLanguage == 41;
		}
		return true;
	}

	private static bool IsExplicitChinese(string value)
	{
		if (string.IsNullOrWhiteSpace(value))
		{
			return false;
		}
		string text = value.Trim().ToLowerInvariant();
		switch (text)
		{
		default:
			if (!text.Contains("简体"))
			{
				return text.Contains("中文");
			}
			break;
		case "zh":
		case "cn":
		case "chs":
		case "zh-cn":
		case "zh-hans":
		case "chinese":
			break;
		}
		return true;
	}

	private static bool IsExplicitEnglish(string value)
	{
		if (string.IsNullOrWhiteSpace(value))
		{
			return false;
		}
		string text = value.Trim().ToLowerInvariant();
		switch (text)
		{
		default:
			return text.StartsWith("en-");
		case "en":
		case "eng":
		case "english":
			return true;
		}
	}

	private static bool TryTableText(string key, out string value)
	{
		if ((IsChinese() ? Zh : En).TryGetValue(key, out string value2) || En.TryGetValue(key, out value2))
		{
			value = value2;
			return true;
		}
		value = string.Empty;
		return false;
	}

	private static bool IsResolvedLocaleValue(string value, string key)
	{
		if (!string.IsNullOrWhiteSpace(value))
		{
			return !string.Equals(value, key, StringComparison.OrdinalIgnoreCase);
		}
		return false;
	}

	private static string HumanizeKey(string key)
	{
		if (string.IsNullOrWhiteSpace(key))
		{
			return T("category.other");
		}
		string text = key.Trim().Replace('_', ' ').Replace('-', ' ');
		if (text.Length != 0)
		{
			return char.ToUpperInvariant(text[0]) + text.Substring(1);
		}
		return T("category.other");
	}

	private static string SafeString(Func<string> getter, string fallback)
	{
		try
		{
			string text = getter();
			return string.IsNullOrWhiteSpace(text) ? fallback : text;
		}
		catch
		{
			return fallback;
		}
	}
}
internal enum UeiEntryKind
{
	Item,
	Liquid
}
internal enum UeiRecipeRelation
{
	ProducedBy,
	UsedIn
}
internal sealed class UeiEntry
{
	public UeiEntryKind Kind;

	public string Id = string.Empty;

	public string EntryKey = string.Empty;

	public string DisplayName = string.Empty;

	public string Description = string.Empty;

	public string CategoryKey = string.Empty;

	public string CategoryLabel = string.Empty;

	public string SearchText = string.Empty;

	public Sprite? Icon;

	public Color IconColor = Color.white;

	public ItemInfo? ItemInfo;

	public LiquidType? LiquidInfo;

	public readonly List<string> Tags = new List<string>();

	public readonly List<CraftingQuality> Qualities = new List<CraftingQuality>();

	public bool IsFavorite => UeiFavorites.Contains(EntryKey);
}
internal sealed class UeiRecipeLink
{
	public int RecipeIndex;

	public UeiRecipeRelation Relation;

	public bool Visible;

	public bool HasMadeBefore;

	public Recipe? Recipe
	{
		get
		{
			if (Recipes.recipes == null || RecipeIndex < 0 || RecipeIndex >= Recipes.recipes.Count)
			{
				return null;
			}
			return Recipes.recipes[RecipeIndex];
		}
	}
}
internal static class UeiOptionalTypes
{
	private static readonly object Gate;

	private static readonly Dictionary<string, Type?> Types;

	private static Assembly[] _assemblies;

	private static int _generation;

	private static int _cachedGeneration;

	internal static int Generation => Volatile.Read(in _generation);

	static UeiOptionalTypes()
	{
		Gate = new object();
		Types = new Dictionary<string, Type>(StringComparer.Ordinal);
		_assemblies = Array.Empty<Assembly>();
		_cachedGeneration = -1;
		AppDomain.CurrentDomain.AssemblyLoad += delegate
		{
			Interlocked.Increment(ref _generation);
		};
	}

	internal static Type? Find(string fullName)
	{
		lock (Gate)
		{
			int generation = Generation;
			if (_cachedGeneration != generation)
			{
				Types.Clear();
				_assemblies = AppDomain.CurrentDomain.GetAssemblies();
				_cachedGeneration = generation;
			}
			if (Types.TryGetValue(fullName, out Type value))
			{
				return value;
			}
			Type type = null;
			Assembly[] assemblies = _assemblies;
			foreach (Assembly assembly in assemblies)
			{
				try
				{
					type = assembly.GetType(fullName, throwOnError: false);
				}
				catch
				{
					continue;
				}
				if (type != null)
				{
					break;
				}
			}
			Types[fullName] = type;
			return type;
		}
	}

	internal static MethodInfo? StaticMethod(Type? type, string name, Type returnType, params Type[] parameters)
	{
		if ((object)type == null || !type.IsVisible)
		{
			return null;
		}
		try
		{
			MethodInfo method = type.GetMethod(name, BindingFlags.Static | BindingFlags.Public, null, parameters, null);
			return (method?.ReturnType == returnType) ? method : null;
		}
		catch
		{
			return null;
		}
	}
}
internal static class RshLibHelper
{
	private static int _generation = -1;

	private static FieldInfo? _registryField;

	private static FieldInfo? _spriteField;

	private static IDictionary? Registry()
	{
		int generation = UeiOptionalTypes.Generation;
		if (_generation != generation)
		{
			_registryField = UeiOptionalTypes.Find("RshLib.Plugin")?.GetField("itemRegistry", BindingFlags.Static | BindingFlags.Public);
			_spriteField = UeiOptionalTypes.Find("RshLib.RshItem")?.GetField("sprite", BindingFlags.Instance | BindingFlags.Public);
			_generation = generation;
		}
		return _registryField?.GetValue(null) as IDictionary;
	}

	public static Sprite? GetCustomItemSprite(string itemId)
	{
		try
		{
			object obj = Registry()?[GetBaseId(itemId)];
			return (Sprite?)((obj == null) ? null : /*isinst with value type is only supported in some contexts*/);
		}
		catch
		{
			return null;
		}
	}

	public static bool IsCustomItem(string itemId)
	{
		try
		{
			return Registry()?.Contains(GetBaseId(itemId)) ?? false;
		}
		catch
		{
			return false;
		}
	}

	public static string GetBaseId(string id)
	{
		if (string.IsNullOrEmpty(id))
		{
			return id;
		}
		int num = id.IndexOf('$');
		if (num < 0)
		{
			return id;
		}
		return id.Substring(0, num);
	}

	public static string TryResolveKey(string fullId, UeiEntryKind kind, Dictionary<string, UeiEntry> entriesByKey)
	{
		string text = UeiCatalog.EntryKey(kind, fullId);
		if (entriesByKey.ContainsKey(text))
		{
			return text;
		}
		string baseId = GetBaseId(fullId);
		string text2 = UeiCatalog.EntryKey(kind, baseId);
		if (!(baseId != fullId) || !entriesByKey.ContainsKey(text2))
		{
			return text;
		}
		return text2;
	}
}
internal static class CuCoreLibHelper
{
	private static int _generation = -1;

	private static MethodInfo? _tryGetIcon;

	private static MethodInfo? _tryGetCustomInfo;

	private static MethodInfo? _tryGetItemInfo;

	private static MethodInfo? _instantiate;

	private static MethodInfo? _isAvailable;

	private static MethodInfo? _isRunning;

	private static MethodInfo? _isClient;

	private static MethodInfo? _isServer;

	private static void EnsureBindings()
	{
		int generation = UeiOptionalTypes.Generation;
		if (_generation != generation)
		{
			Type type = UeiOptionalTypes.Find("CUCoreLib.Registries.ItemRegistry");
			_tryGetIcon = UeiOptionalTypes.StaticMethod(type, "TryGetIcon", typeof(bool), typeof(string), typeof(Sprite).MakeByRefType());
			Type type2 = UeiOptionalTypes.Find("CUCoreLib.Data.CustomItemInfo");
			_tryGetCustomInfo = ((type2 == null) ? null : UeiOptionalTypes.StaticMethod(type, "TryGetCustomInfo", typeof(bool), typeof(string), type2.MakeByRefType()));
			_tryGetItemInfo = UeiOptionalTypes.StaticMethod(type, "TryGetItemInfo", typeof(bool), typeof(string), typeof(ItemInfo).MakeByRefType());
			_instantiate = UeiOptionalTypes.StaticMethod(UeiOptionalTypes.Find("CUCoreLib.Helpers.CustomInstantiate"), "InstantiateReturn", typeof(GameObject), typeof(string), typeof(Vector3), typeof(Quaternion), typeof(float?));
			Type? type3 = UeiOptionalTypes.Find("CUCoreLib.Networking.MultiplayerApi");
			_isAvailable = UeiOptionalTypes.StaticMethod(type3, "get_IsAvailable", typeof(bool));
			_isRunning = UeiOptionalTypes.StaticMethod(type3, "get_IsRunning", typeof(bool));
			_isClient = UeiOptionalTypes.StaticMethod(type3, "get_IsClient", typeof(bool));
			_isServer = UeiOptionalTypes.StaticMethod(type3, "get_IsServer", typeof(bool));
			_generation = generation;
		}
	}

	public static Sprite? GetCustomItemSprite(string itemId)
	{
		if (string.IsNullOrWhiteSpace(itemId))
		{
			return null;
		}
		EnsureBindings();
		if (_tryGetIcon == null)
		{
			return null;
		}
		try
		{
			object[] array = new object[2] { itemId, null };
			object obj = _tryGetIcon?.Invoke(null, array);
			return (Sprite?)((obj is bool && (bool)obj) ? /*isinst with value type is only supported in some contexts*/: null);
		}
		catch
		{
			return null;
		}
	}

	public static bool IsCustomItem(string itemId)
	{
		if (string.IsNullOrWhiteSpace(itemId))
		{
			return false;
		}
		EnsureBindings();
		if (_tryGetCustomInfo == null)
		{
			return false;
		}
		try
		{
			object obj = _tryGetCustomInfo?.Invoke(null, new object[2] { itemId, null });
			return obj is bool && (bool)obj;
		}
		catch
		{
			return false;
		}
	}

	public static bool TryGetItemInfo(string itemId, out ItemInfo? info)
	{
		info = null;
		if (string.IsNullOrWhiteSpace(itemId))
		{
			return false;
		}
		EnsureBindings();
		if (_tryGetItemInfo == null)
		{
			return false;
		}
		try
		{
			object[] array = new object[2] { itemId, null };
			object obj = _tryGetItemInfo.Invoke(null, array);
			if (!(obj is bool) || !(bool)obj)
			{
				return false;
			}
			object obj2 = array[1];
			info = (ItemInfo?)((obj2 is ItemInfo) ? obj2 : null);
			return info != null;
		}
		catch
		{
			return false;
		}
	}

	public static string GetItemText(string localeKey)
	{
		if (string.IsNullOrWhiteSpace(localeKey))
		{
			return string.Empty;
		}
		if (IsCustomItem(localeKey) && TryGetItemInfo(localeKey, out ItemInfo info))
		{
			return info.fullName ?? string.Empty;
		}
		if (localeKey.EndsWith("dsc", StringComparison.Ordinal) && IsCustomItem(localeKey.Substring(0, localeKey.Length - 3)) && TryGetItemInfo(localeKey.Substring(0, localeKey.Length - 3), out ItemInfo info2))
		{
			return info2.description ?? string.Empty;
		}
		return string.Empty;
	}

	public static GameObject? CreateInstance(string itemId, Vector3 position, float rotation)
	{
		//IL_002a: 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)
		if (!IsCustomItem(itemId) || _instantiate == null)
		{
			return null;
		}
		try
		{
			object? obj = _instantiate.Invoke(null, new object[4]
			{
				itemId,
				position,
				Quaternion.Euler(0f, 0f, rotation),
				1f
			});
			return (GameObject?)((obj is GameObject) ? obj : null);
		}
		catch (Exception ex)
		{
			UeiPlugin.LogWarning("UEI CUCoreLib factory failed for " + itemId + ": " + ex.Message);
			return null;
		}
	}

	public static bool TryGetRunningNetworkState(out TogetherNetworkState state)
	{
		EnsureBindings();
		state = TogetherNetworkState.Unknown;
		if (ReadBool(_isAvailable) != true || ReadBool(_isRunning) != true)
		{
			return false;
		}
		bool? flag = ReadBool(_isClient);
		bool? flag2 = ReadBool(_isServer);
		if (flag == true && flag2 == false)
		{
			state = TogetherNetworkState.Client;
		}
		else if (flag2 == true && flag == false)
		{
			state = TogetherNetworkState.Server;
		}
		return true;
	}

	private static bool? ReadBool(MethodInfo? getter)
	{
		try
		{
			return (getter?.Invoke(null, null) is bool value) ? new bool?(value) : ((bool?)null);
		}
		catch
		{
			return null;
		}
	}
}
internal static class SexModHelper
{
	private static int _generation = -1;

	private static MethodInfo? _isRegistered;

	private static MethodInfo? _getIcon;

	private static MethodInfo? _createInstance;

	private static void EnsureBindings()
	{
		int generation = UeiOptionalTypes.Generation;
		if (_generation != generation)
		{
			Type type = UeiOptionalTypes.Find("ScavPrototypeSexMod.Registers.ItemRegistry");
			_isRegistered = UeiOptionalTypes.StaticMethod(type, "IsRegistered", typeof(bool), typeof(string));
			_getIcon = UeiOptionalTypes.StaticMethod(type, "GetIcon", typeof(Sprite), typeof(string));
			_createInstance = UeiOptionalTypes.StaticMethod(type, "CreateInstance", typeof(GameObject), typeof(string), typeof(Vector2), typeof(float));
			_generation = generation;
		}
	}

	public static bool IsRegistered(string itemId)
	{
		if (string.IsNullOrWhiteSpace(itemId))
		{
			return false;
		}
		EnsureBindings();
		if (_isRegistered == null)
		{
			return false;
		}
		try
		{
			object obj = _isRegistered?.Invoke(null, new object[1] { itemId });
			return obj is bool && (bool)obj;
		}
		catch
		{
			return false;
		}
	}

	public static Sprite? GetCustomItemSprite(string itemId)
	{
		if (string.IsNullOrWhiteSpace(itemId))
		{
			return null;
		}
		EnsureBindings();
		if (_getIcon == null)
		{
			return null;
		}
		try
		{
			object? obj = _getIcon?.Invoke(null, new object[1] { itemId });
			return (Sprite?)((obj is Sprite) ? obj : null);
		}
		catch
		{
			return null;
		}
	}

	public static GameObject? CreateInstance(string itemId, Vector2 position, float rotation)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		if (!IsRegistered(itemId))
		{
			return null;
		}
		try
		{
			object? obj = _createInstance?.Invoke(null, new object[3] { itemId, position, rotation });
			return (GameObject?)((obj is GameObject) ? obj : null);
		}
		catch (Exception ex)
		{
			UeiPlugin.LogWarning("UEI SexMod factory failed for " + itemId + ": " + ex.Message);
			return null;
		}
	}
}
internal sealed class UeiPanel
{
	private enum CheatActionResult
	{
		Failed,
		Completed,
		RequestSent,
		HostRequired
	}

	private const int Columns = 6;

	private const int Rows = 10;

	private const int PageSize = 60;

	private const float HeaderHeight = 22f;

	private const float PageButtonWidth = 26f;

	private const float PageTextWidth = 64f;

	private const float PageTextSize = 13f;

	private const float CategoryBarHeight = 20f;

	private const float CategoryButtonWidth = 76f;

	private const float SearchInputHeight = 22f;

	private const float SearchTextSize = 11f;

	private const float SearchBorderThickness = 1f;

	private const float SearchHorizontalPadding = 5f;

	private const float SearchVerticalPadding = 2f;

	private const float SettingsButtonWidth = 22f;

	private const float ReviveButtonWidth = 22f;

	private const int RecipePageSize = 2;

	private const float DetailPanelWidth = 310f;

	private const float DetailGap = 12f;

	private const float DetailHeaderHeight = 22f;

	private const float RecipeCardHeight = 132f;

	private const float RecipeIconSize = 32f;

	private const float RecipeIngredientSize = 26f;

	private const float DetailActionButtonSize = 22f;

	private const float EnterAnimationSeconds = 0.16f;

	private const float ExitAnimationSeconds = 0.12f;

	private const float WheelPageThreshold = 0.1f;

	private const float PointerBoundsPadding = 8f;

	private const float PanelEdgeInset = 18f;

	private const BindingFlags StaticLookup = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;

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

	private static readonly Color TransparentBlockerColor = new Color(0f, 0f, 0f, 0f);

	private static readonly Color CellColor = new Color(0f, 0f, 0f, 0f);

	private static readonly Color CellSelectedColor = new Color(1f, 1f, 1f, 0.12f);

	private static readonly Color SearchColor = new Color(0f, 0f, 0f, 0.96f);

	private static readonly Color PixelBorderColor = new Color(0.72f, 0.76f, 0.78f, 1f);

	private static readonly Color TextColor = new Color(0.92f, 0.92f, 0.92f, 1f);

	private static readonly Color MutedTextColor = new Color(0.7f, 0.72f, 0.74f, 1f);

	private static bool _ownsNativeTooltip;

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

	private readonly Canvas _canvas;

	private readonly int _uiLayer;

	private readonly TMP_FontAsset? _font;

	private readonly GameObject _root;

	private readonly RectTransform _panelRect;

	private readonly CanvasGroup _panelCanvasGroup;

	private readonly RectTransform _detailRect;

	private readonly GameObject _detailPanel;

	private readonly CanvasGroup _detailCanvasGroup;

	private readonly RectTransform _recipeContent;

	private readonly RectTransform _settingsRect;

	private readonly GameObject _settingsPanel;

	private readonly CanvasGroup _settingsCanvasGroup;

	private readonly RectTransform _settingsContent;

	private readonly GridLayoutGroup _grid;

	private readonly RectTransform _gridContent;

	private readonly TMP_InputField _searchInput;

	private GameObject _reviveButton;

	private TextMeshProUGUI _pageText;

	private TextMeshProUGUI _categoryText;

	private TextMeshProUGUI _detailModeText;

	private TextMeshProUGUI _detailTitleText;

	private TextMeshProUGUI _recipePageText;

	private TextMeshProUGUI _settingsTitleText;

	private TextMeshProUGUI _settingsButtonText;

	private TextMeshProUGUI _scaleValueText;

	private Slider _scaleSlider;

	private readonly TextMeshProUGUI _selectionText;

	private LayoutElement _gridFrameLayout;

	private const float PanelSpacing = 6f;

	private const float SelectionHeight = 16f;

	private int _catalogRevision = -1;

	private int _lastScreenWidth = -1;

	private int _lastScreenHeight = -1;

	private string _lastPanelPosition = string.Empty;

	private float _lastPanelScale = -1f;

	private int _page;

	private int _lastPageCount = 1;

	private int _categoryIndex;

	private int _recipePage;

	private int _lastRecipePageCount = 1;

	private bool _dirty = true;

	private bool _detailDirty = true;

	private bool _loadingShown;

	private bool _settingsOpen;

	private bool _wantsVisible;

	private float _animationProgress;

	private int _lastAnimationFrame = -1;

	private int _lastPagingInputFrame = -1;

	private int _lastWheelSampleFrame = -1;

	private int _lastPointerCheckFrame = -1;

	private float _wheelAccumulator;

	private bool _lastPointerOverPanel;

	private string _searchText = string.Empty;

	private string _statusMessage = string.Empty;

	private UeiRecipeRelation _detailMode;

	private UeiEntry? _selectedEntry;

	private float _pendingPanelScale;

	public bool IsAlive
	{
		get
		{
			if ((Object)(object)_root != (Object)null)
			{
				return (Object)(object)_canvas != (Object)null;
			}
			return false;
		}
	}

	public bool IsTextInputFocused
	{
		get
		{
			if (IsAlive && _root.activeInHierarchy && _animationProgress > 0.98f)
			{
				return _searchInput.isFocused;
			}
			return false;
		}
	}

	public bool IsPointerOverPanel
	{
		get
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				int frameCount = Time.frameCount;
				if (_lastPointerCheckFrame == frameCount)
				{
					return _lastPointerOverPanel;
				}
				_lastPointerCheckFrame = frameCount;
				_lastPointerOverPanel = false;
				if (!IsAlive || !_root.activeInHierarchy || _animationProgress <= 0.02f)
				{
					return false;
				}
				Camera uiCamera = GetUiCamera();
				_lastPointerOverPanel = RectTransformUtility.RectangleContainsScreenPoint(_panelRect, Vector2.op_Implicit(Input.mousePosition), uiCamera) || (_detailPanel.activeInHierarchy && RectTransformUtility.RectangleContainsScreenPoint(_detailRect, Vector2.op_Implicit(Input.mousePosition), uiCamera)) || (_settingsPanel.activeInHierarchy && RectTransformUtility.RectangleContainsScreenPoint(_settingsRect, Vector2.op_Implicit(Input.mousePosition), uiCamera)) || IsPointerInsidePanelScreenBounds(uiCamera) || IsPointerOverPanelGraphic();
				return _lastPointerOverPanel;
			}
			catch
			{
				return false;
			}
		}
	}

	public UeiPanel(Canvas canvas)
	{
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: 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_01eb: Expected O, but got Unknown
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0302: Unknown result type (might be due to invalid IL or missing references)
		//IL_031c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0336: Unknown result type (might be due to invalid IL or missing references)
		//IL_0389: Unknown result type (might be due to invalid IL or missing references)
		//IL_0393: Expected O, but got Unknown
		//IL_0472: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_04bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0544: Unknown result type (might be due to invalid IL or missing references)
		//IL_054e: Expected O, but got Unknown
		_canvas = canvas;
		_uiLayer = LayerMask.NameToLayer("UI");
		_font = FindFont(canvas);
		EnsureEventSystem();
		if ((Object)(object)((Component)_canvas).GetComponent<GraphicRaycaster>() == (Object)null)
		{
			((Component)_canvas).gameObject.AddComponent<GraphicRaycaster>();
		}
		_root = NewUiObject("UEI.Root", ((Component)_canvas).transform);
		_root.GetComponent<RectTransform>().SetStretch();
		GameObject val = AddImage(_root.transform, "Panel", TransparentBlockerColor, raycast: true);
		_panelRect = val.GetComponent<RectTransform>();
		_panelRect.anchorMin = new Vector2(0f, 0.5f);
		_panelRect.anchorMax = new Vector2(0f, 0.5f);
		_panelRect.pivot = new Vector2(0f, 0.5f);
		_panelRect.anchoredPosition = PanelShownPosition() + PanelHiddenOffset();
		_panelRect.sizeDelta = new Vector2(310f, 680f);
		_panelCanvasGroup = val.AddComponent<CanvasGroup>();
		_panelCanvasGroup.alpha = 0f;
		_panelCanvasGroup.interactable = false;
		_panelCanvasGroup.blocksRaycasts = false;
		VerticalLayoutGroup obj = val.AddComponent<VerticalLayoutGroup>();
		((LayoutGroup)obj).padding = new RectOffset(0, 0, 0, 0);
		((HorizontalOrVerticalLayoutGroup)obj).spacing = 6f;
		((LayoutGroup)obj).childAlignment = (TextAnchor)1;
		((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = true;
		((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true;
		((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = true;
		((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false;
		BuildHeader(val.transform);
		BuildCategoryBar(val.transform);
		_gridContent = BuildGrid(val.transform, out _grid);
		_selectionText = AddText(val.transform, "Selection", string.Empty, 11f, MutedTextColor, (TextAlignmentOptions)4097);
		LayoutElement orAddLayoutElement = ((Component)(object)_selectionText).GetOrAddLayoutElement();
		orAddLayoutElement.preferredHeight = 16f;
		orAddLayoutElement.minHeight = 16f;
		_searchInput = BuildBottomBar(val.transform);
		_detailPanel = AddImage(_root.transform, "DetailPanel", TransparentBlockerColor, raycast: true);
		_detailRect = _detailPanel.GetComponent<RectTransform>();
		_detailRect.anchorMin = new Vector2(0f, 0.5f);
		_detailRect.anchorMax = new Vector2(0f, 0.5f);
		_detailRect.pivot = new Vector2(0f, 0.5f);
		_detailRect.sizeDelta = new Vector2(310f, 420f);
		_detailCanvasGroup = _detailPanel.AddComponent<CanvasGroup>();
		_detailCanvasGroup.alpha = 0f;
		_detailCanvasGroup.interactable = false;
		_detailCanvasGroup.blocksRaycasts = false;
		VerticalLayoutGroup obj2 = _detailPanel.AddComponent<VerticalLayoutGroup>();
		((LayoutGroup)obj2).padding = new RectOffset(0, 0, 0, 0);
		((HorizontalOrVerticalLayoutGroup)obj2).spacing = 6f;
		((LayoutGroup)obj2).childAlignment = (TextAnchor)0;
		((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = true;
		((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true;
		((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = true;
		((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = false;
		BuildDetailHeader(_detailPanel.transform);
		_recipeContent = NewUiObject("RecipeContent", _detailPanel.transform).GetComponent<RectTransform>();
		LayoutElement obj3 = ((Component)_recipeContent).gameObject.AddComponent<LayoutElement>();
		obj3.flexibleHeight = 1f;
		obj3.minHeight = 250f;
		VerticalLayoutGroup obj4 = ((Component)_recipeContent).gameObject.AddComponent<VerticalLayoutGroup>();
		((HorizontalOrVerticalLayoutGroup)obj4).spacing = 6f;
		((LayoutGroup)obj4).childAlignment = (TextAnchor)0;
		((HorizontalOrVerticalLayoutGroup)obj4).childControlWidth = true;
		((HorizontalOrVerticalLayoutGroup)obj4).childControlHeight = true;
		((HorizontalOrVerticalLayoutGroup)obj4).childForceExpandWidth = true;
		((HorizontalOrVerticalLayoutGroup)obj4).childForceExpandHeight = false;
		_detailPanel.SetActive(false);
		_settingsPanel = AddImage(_root.transform, "SettingsPanel", TransparentBlockerColor, raycast: true);
		_settingsRect = _settingsPanel.GetComponent<RectTransform>();
		_settingsRect.anchorMin = new Vector2(0f, 0.5f);
		_settingsRect.anchorMax = new Vector2(0f, 0.5f);
		_settingsRect.pivot = new Vector2(0f, 0.5f);
		_settingsRect.sizeDelta = new Vector2(310f, 260f);
		_settingsCanvasGroup = _settingsPanel.AddComponent<CanvasGroup>();
		_settingsCanvasGroup.alpha = 0f;
		_settingsCanvasGroup.interactable = false;
		_settingsCanvasGroup.blocksRaycasts = false;
		VerticalLayoutGroup obj5 = _settingsPanel.AddComponent<VerticalLayoutGroup>();
		((LayoutGroup)obj5).padding = new RectOffset(0, 0, 0, 0);
		((HorizontalOrVerticalLayoutGroup)obj5).spacing = 6f;
		((LayoutGroup)obj5).childAlignment = (TextAnchor)0;
		((HorizontalOrVerticalLayoutGroup)obj5).childControlWidth = true;
		((HorizontalOrVerticalLayoutGroup)obj5).childControlHeight = true;
		((HorizontalOrVerticalLayoutGroup)obj5).childForceExpandWidth = true;
		((HorizontalOrVerticalLayoutGroup)obj5).childForceExpandHeight = false;
		BuildSettingsHeader(_settingsPanel.transform);
		_settingsContent = NewUiObject("SettingsContent", _settingsPanel.transform).GetComponent<RectTransform>();
		((Component)_settingsContent).gameObject.AddComponent<LayoutElement>().flexibleHeight = 1f;
		VerticalLayoutGroup obj6 = ((Component)_settingsContent).gameObject.AddComponent<VerticalLayoutGroup>();
		((HorizontalOrVerticalLayoutGroup)obj6).spacing = 6f;
		((LayoutGroup)obj6).childAlignment = (TextAnchor)0;
		((HorizontalOrVerticalLayoutGroup)obj6).childControlWidth = true;
		((HorizontalOrVerticalLayoutGroup)obj6).childControlHeight = true;
		((HorizontalOrVerticalLayoutGroup)obj6).childForceExpandWidth = true;
		((HorizontalOrVerticalLayoutGroup)obj6).childForceExpandHeight = false;
		_settingsPanel.SetActive(false);
		Hide();
	}

	public void Show(PlayerCamera camera)
	{
		BeginShow();
		if (_loadingShown)
		{
			_loadingShown = false;
			_dirty = true;
			_detailDirty = true;
		}
		UpdateCheatActionBar();
		UpdatePanelSize(camera);
		HandlePagingInput();
		if (_catalogRevision != UeiCatalog.Revision)
		{
			_catalogRevision = UeiCatalog.Revision;
			_dirty = true;
			_detailDirty = true;
		}
		if (_dirty)
		{
			RefreshGrid();
		}
		if (_detailDirty)
		{
			RefreshDetail();
		}
		TickAnimation();
	}

	public void ShowLoading(PlayerCamera camera)
	{
		BeginShow();
		UpdateCheatActionBar();
		UpdatePanelSize(camera);
		if (!_loadingShown)
		{
			ClearChildren((Transform)(object)_gridContent);
			((TMP_Text)_pageText).text = "...";
			((TMP_Text)_categoryText).text = UeiI18n.T("category.all");
			((TMP_Text)_selectionText).text = UeiI18n.T("loading.items");
			_detailPanel.SetActive(false);
			_loadingShown = true;
		}
		TickAnimation();
	}

	public void Hide()
	{
		_wantsVisible = false;
		ClearNativeTooltip();
		if (!IsAlive)
		{
			return;
		}
		if (!_root.activeSelf)
		{
			if (_animationProgress > 0f)
			{
				_animationProgress = 0f;
				ApplyAnimation();
			}
		}
		else
		{
			TickAnimation();
		}
	}

	public void Destroy()
	{
		ClearNativeTooltip();
		if ((Object)(object)_root != (Object)null)
		{
			Object.Destroy((Object)(object)_root);
		}
	}

	public string DescribeVisualState()
	{
		//IL_006c: 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_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		if (!IsAlive)
		{
			return "destroyed";
		}
		RectTransform component = ((Component)_canvas).GetComponent<RectTransform>();
		object[] obj = new object[17]
		{
			_root.activeSelf,
			_root.activeInHierarchy,
			_root.transform.GetSiblingIndex(),
			_panelRect.anchoredPosition.x,
			_panelRect.anchoredPosition.y,
			_panelRect.sizeDelta.x,
			_panelRect.sizeDelta.y,
			_panelCanvasGroup.alpha,
			_animationProgress,
			((Object)_canvas).name,
			((Component)_canvas).transform.localScale.x,
			((Component)_canvas).transform.localScale.y,
			((Component)_canvas).transform.localScale.z,
			null,
			null,
			null,
			null
		};
		float num;
		Rect rect;
		if (!((Object)(object)component != (Object)null))
		{
			num = 0f;
		}
		else
		{
			rect = component.rect;
			num = ((Rect)(ref rect)).width;
		}
		obj[13] = num;
		float num2;
		if (!((Object)(object)component != (Object)null))
		{
			num2 = 0f;
		}
		else
		{
			rect = component.rect;
			num2 = ((Rect)(ref rect)).height;
		}
		obj[14] = num2;
		obj[15] = _page + 1;
		obj[16] = _lastPageCount;
		return string.Format("rootActive={0} inHierarchy={1} sibling={2} panelPos=({3:0.##},{4:0.##}) panelSize=({5:0.##},{6:0.##}) alpha={7:0.##} anim={8:0.##} canvas={9} canvasScale=({10:0.##},{11:0.##},{12:0.##}) canvasSize=({13:0.##},{14:0.##}) page={15}/{16}", obj);
	}

	public bool ShowItemUses(Item item)
	{
		try
		{
			if ((Object)(object)item == (Object)null || string.IsNullOrWhiteSpace(item.id))
			{
				return false;
			}
			if (!UeiCatalog.TryGetEntry(UeiEntryKind.Item, item.id, out UeiEntry entry) || entry == null)
			{
				return false;
			}
			if (_settingsOpen)
			{
				CloseSettings();
			}
			FocusGridEntry(entry);
			SelectEntry(entry, UeiRecipeRelation.UsedIn, linkOriginalRecipe: false);
			return true;
		}
		catch (Exception ex)
		{
			UeiPlugin.LogWarning("Failed to open UEI uses for inventory item: " + ex.Message);
			return false;
		}
	}

	private void BeginShow()
	{
		_wantsVisible = true;
		if (!_root.activeSelf)
		{
			_root.SetActive(true);
			_dirty = true;
			ApplyAnimation();
		}
		BringToFront();
	}

	private void BringToFront()
	{
		Transform parent = _root.transform.parent;
		if ((Object)(object)parent != (Object)null && _root.transform.GetSiblingIndex() != parent.childCount - 1)
		{
			_root.transform.SetAsLastSibling();
		}
	}

	private void TickAnimation()
	{
		if (_lastAnimationFrame == Time.frameCount)
		{
			ApplyAnimation();
			return;
		}
		_lastAnimationFrame = Time.frameCount;
		float num = (_wantsVisible ? 0.16f : 0.12f);
		float num2 = (_wantsVisible ? 1f : (-1f));
		float num3 = Mathf.Min(Time.unscaledDeltaTime, 0.033f);
		float num4 = ((num <= 0.001f) ? 1f : (num3 / num));
		_animationProgress = Mathf.Clamp01(_animationProgress + num2 * num4);
		ApplyAnimation();
		if (!_wantsVisible && _animationProgress <= 0f && _root.activeSelf)
		{
			_root.SetActive(false);
		}
	}

	private void ApplyAnimation()
	{
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		float num = EaseOutCubic(_animationProgress);
		_panelCanvasGroup.alpha = num;
		_panelCanvasGroup.interactable = _wantsVisible && _animationProgress > 0.98f;
		_panelCanvasGroup.blocksRaycasts = _animationProgress > 0.02f;
		_panelRect.anchoredPosition = PanelShownPosition() + PanelHiddenOffset() * (1f - num);
		_detailCanvasGroup.alpha = num;
		_detailCanvasGroup.interactable = _wantsVisible && _animationProgress > 0.98f;
		_detailCanvasGroup.blocksRaycasts = _animationProgress > 0.02f;
		_detailRect.anchoredPosition = DetailShownPosition() + PanelHiddenOffset() * (1f - num);
		_settingsCanvasGroup.alpha = num;
		_settingsCanvasGroup.interactable = _wantsVisible && _settingsOpen && _animationProgress > 0.98f;
		_settingsCanvasGroup.blocksRaycasts = _settingsOpen && _animationProgress > 0.02f;
		_settingsRect.anchoredPosition = DetailShownPosition() + PanelHiddenOffset() * (1f - num);
	}

	private static float EaseOutCubic(float value)
	{
		float num = Mathf.Clamp01(value);
		float num2 = 1f - num;
		return 1f - num2 * num2 * num2;
	}

	private void BuildHeader(Transform parent)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Expected O, but got Unknown
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Expected O, but got Unknown
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Expected O, but got Unknown
		GameObject val = NewUiObject("Header", parent);
		LayoutElement obj = val.AddComponent<LayoutElement>();
		obj.preferredHeight = 22f;
		obj.minHeight = 22f;
		HorizontalLayoutGroup obj2 = val.AddComponent<HorizontalLayoutGroup>();
		((LayoutGroup)obj2).padding = new RectOffset(0, 0, 0, 0);
		((HorizontalOrVerticalLayoutGroup)obj2).spacing = 4f;
		((LayoutGroup)obj2).childAlignment = (TextAnchor)4;
		((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = true;
		((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true;
		((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = false;
		((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = false;
		Button obj3 = AddButton(val.transform, "PreviousPage", "<", 13f, 22f, 26f);
		LayoutElement component = ((Component)obj3).GetComponent<LayoutElement>();
		component.preferredWidth = 26f;
		component.minWidth = 26f;
		((UnityEvent)obj3.onClick).AddListener((UnityAction)delegate
		{
			ChangePage(-1);
		});
		_pageText = AddText(val.transform, "PageText", "1/1", 13f, TextColor, (TextAlignmentOptions)514);
		LayoutElement orAddLayoutElement = ((Component)(object)_pageText).GetOrAddLayoutElement();
		orAddLayoutElement.preferredWidth = 64f;
		orAddLayoutElement.minWidth = 64f;
		orAddLayoutElement.preferredHeight = 22f;
		((TMP_Text)_pageText).enableWordWrapping = false;
		((TMP_Text)_pageText).overflowMode = (TextOverflowModes)0;
		Button obj4 = AddButton(val.transform, "NextPage", ">", 13f, 22f, 26f);
		LayoutElement component2 = ((Component)obj4).GetComponent<LayoutElement>();
		component2.preferredWidth = 26f;
		component2.minWidth = 26f;
		((UnityEvent)obj4.onClick).AddListener((UnityAction)delegate
		{
			ChangePage(1);
		});
	}

	private void BuildCategoryBar(Transform parent)
	{
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Expected O, but got Unknown
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Expected O, but got Unknown
		GameObject val = NewUiObject("CategoryBar", parent);
		LayoutElement obj = val.AddComponent<LayoutElement>();
		obj.preferredHeight = 20f;
		obj.minHeight = 20f;
		HorizontalLayoutGroup obj2 = val.AddComponent<HorizontalLayoutGroup>();
		((HorizontalOrVerticalLayoutGroup)obj2).spacing = 4f;
		((LayoutGroup)obj2).childAlignment = (TextAnchor)4;
		((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = true;
		((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true;
		((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = false;
		((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = false;
		Button obj3 = AddButton(val.transform, "PreviousCategory", "<", 10f, 20f, 22f);
		((Component)obj3).GetComponent<LayoutElement>().preferredWidth = 22f;
		((UnityEvent)obj3.onClick).AddListener((UnityAction)delegate
		{
			ChangeCategory(-1);
		});
		_categoryText = AddText(val.transform, "CategoryText", UeiI18n.T("category.all"), 10f, TextColor, (TextAlignmentOptions)514);
		LayoutElement orAddLayoutElement = ((Component)(object)_categoryText).GetOrAddLayoutElement();
		orAddLayoutElement.preferredWidth = 76f;
		orAddLayoutElement.minWidth = 76f;
		orAddLayoutElement.preferredHeight = 20f;
		((TMP_Text)_categoryText).enableWordWrapping = false;
		Button obj4 = AddButton(val.transform, "NextCategory", ">", 10f, 20f, 22f);
		((Component)obj4).GetComponent<LayoutElement>().preferredWidth = 22f;
		((UnityEvent)obj4.onClick).AddListener((UnityAction)delegate
		{
			ChangeCategory(1);
		});
	}

	private void BuildDetailHeader(Transform parent)
	{
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Expected O, but got Unknown
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Expected O, but got Unknown
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Expected O, but got Unknown
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0273: Unknown result type (might be due to invalid IL or missing references)
		//IL_027d: Expected O, but got Unknown
		GameObject val = NewUiObject("DetailHeader", parent);
		LayoutElement obj = val.AddComponent<LayoutElement>();
		obj.preferredHeight = 22f;
		obj.minHeight = 22f;
		HorizontalLayoutGroup obj2 = val.AddComponent<HorizontalLayoutGroup>();
		((HorizontalOrVerticalLayoutGroup)obj2).spacing = 4f;
		((LayoutGroup)obj2).childAlignment = (TextAnchor)4;
		((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = true;
		((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true;
		((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = false;
		((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = false;
		Button val2 = AddButton(val.transform, "Mode", UeiI18n.T("detail.mode.source"), 10f, 22f, 36f);
		((Component)val2).GetComponent<LayoutElement>().preferredWidth = 36f;
		_detailModeText = ((Component)val2).GetComponentInChildren<TextMeshProUGUI>();
		((UnityEvent)val2.onClick).AddListener(new UnityAction(ToggleDetailMode));
		Button obj3 = AddButton(val.transform, "PreviousRecipe", "<", 10f, 22f, 22f);
		((Component)obj3).GetComponent<LayoutElement>().preferredWidth = 22f;
		((UnityEvent)obj3.onClick).AddListener((UnityAction)delegate
		{
			ChangeRecipePage(-1);
		});
		Button obj4 = AddButton(val.transform, "CloseDetail", "×", 10f, 22f, 22f);
		LayoutElement component = ((Component)obj4).GetComponent<LayoutElement>();
		component.preferredWidth = 22f;
		component.minWidth = 22f;
		((UnityEvent)obj4.onClick).AddListener(new UnityAction(CloseDetail));
		BindTooltip(((Component)obj4).gameObject, UeiI18n.T("button.closeDetail"), UeiI18n.T("button.closeDetail.desc"));
		_detailTitleText = AddText(val.transform, "Title", string.Empty, 10f, TextColor, (TextAlignmentOptions)514);
		LayoutElement orAddLayoutElement = ((Component)(object)_detailTitleText).GetOrAddLayoutElement();
		orAddLayoutElement.flexibleWidth = 1f;
		orAddLayoutElement.preferredHeight = 22f;
		((TMP_Text)_detailTitleText).enableWordWrapping = false;
		_recipePageText = AddText(val.transform, "RecipePage", "0/0", 10f, MutedTextColor, (TextAlignmentOptions)514);
		LayoutElement orAddLayoutElement2 = ((Component)(object)_recipePageText).GetOrAddLayoutElement();
		orAddLayoutElement2.preferredWidth = 42f;
		orAddLayoutElement2.minWidth = 42f;
		orAddLayoutElement2.preferredHeight = 22f;
		((TMP_Text)_recipePageText).enableWordWrapping = false;
		Button obj5 = AddButton(val.transform, "NextRecipe", ">", 10f, 22f, 22f);
		((Component)obj5).GetComponent<LayoutElement>().preferredWidth = 22f;
		((UnityEvent)obj5.onClick).AddListener((UnityAction)delegate
		{
			ChangeRecipePage(1);
		});
	}

	private void BuildSettingsHeader(Transform parent)
	{
		//IL_0077: 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_010e: Expected O, but got Unknown
		GameObject val = NewUiObject("SettingsHeader", parent);
		LayoutElement obj = val.AddComponent<LayoutElement>();
		obj.preferredHeight = 22f;
		obj.minHeight = 22f;
		HorizontalLayoutGroup obj2 = val.AddComponent<HorizontalLayoutGroup>();
		((HorizontalOrVerticalLayoutGroup)obj2).spacing = 4f;
		((LayoutGroup)obj2).childAlignment = (TextAnchor)4;
		((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = true;
		((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true;
		((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = false;
		((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = false;
		_settingsTitleText = AddText(val.transform, "Title", UeiI18n.T("settings.title"), 10f, TextColor, (TextAlignmentOptions)514);
		LayoutElement orAddLayoutElement = ((Component)(object)_settingsTitleText).GetOrAddLayoutElement();
		orAddLayoutElement.flexibleWidth = 1f;
		orAddLayoutElement.preferredHeight = 22f;
		((TMP_Text)_settingsTitleText).enableWordWrapping = false;
		Button obj3 = AddButton(val.transform, "CloseSettings", "×", 10f, 22f, 22f);
		LayoutElement component = ((Component)obj3).GetComponent<LayoutElement>();
		component.preferredWidth = 22f;
		component.minWidth = 22f;
		((UnityEvent)obj3.onClick).AddListener(new UnityAction(CloseSettings));
		BindTooltip(((Component)obj3).gameObject, UeiI18n.T("button.closeDetail"), UeiI18n.T("button.closeDetail.desc"));
	}

	private RectTransform BuildGrid(Transform parent, out GridLayoutGroup grid)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Expected O, but got Unknown
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = AddImage(parent, "GridFrame", Color.clear, raycast: true);
		_gridFrameLayout = val.AddComponent<LayoutElement>();
		_gridFrameLayout.flexibleHeight = 0f;
		_gridFrameLayout.preferredHeight = 430f;
		_gridFrameLayout.minHeight = 0f;
		GameObject val2 = NewUiObject("Grid", val.transform);
		RectTransform component = val2.GetComponent<RectTransform>();
		component.SetStretch();
		component.offsetMin = new Vector2(2f, 2f);
		component.offsetMax = new Vector2(-2f, -2f);
		grid = val2.AddComponent<GridLayoutGroup>();
		grid.constraint = (Constraint)1;
		grid.constraintCount = 6;
		grid.spacing = new Vector2(6f, 6f);
		((LayoutGroup)grid).padding = new RectOffset(0, 0, 0, 0);
		((LayoutGroup)grid).childAlignment = (TextAnchor)1;
		grid.cellSize = new Vector2(42f, 42f);
		return component;
	}

	private TMP_InputField BuildBottomBar(Transform parent)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Expected O, but got Unknown
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Expected O, but got Unknown
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Expected O, but got Unknown
		GameObject val = NewUiObject("BottomBar", parent);
		LayoutElement obj = val.AddComponent<LayoutElement>();
		obj.preferredHeight = 22f;
		obj.minHeight = 22f;
		HorizontalLayoutGroup obj2 = val.AddComponent<HorizontalLayoutGroup>();
		((LayoutGroup)obj2).padding = new RectOffset(0, 0, 0, 0);
		((HorizontalOrVerticalLayoutGroup)obj2).spacing = 4f;
		((LayoutGroup)obj2).childAlignment = (TextAnchor)4;
		((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = true;
		((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true;
		((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = false;
		((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = false;
		TMP_InputField obj3 = AddInput(val.transform, "SearchInput", UeiI18n.T("search.placeholder"));
		LayoutElement component = ((Component)obj3).GetComponent<LayoutElement>();
		component.flexibleWidth = 1f;
		component.minWidth = 60f;
		((UnityEvent<string>)(object)obj3.onValueChanged).AddListener((UnityAction<string>)delegate(string value)
		{
			_searchText = value ?? string.Empty;
			_page = 0;
			_dirty = true;
			RefreshGrid();
		});
		Button val2 = AddButton(val.transform, "Settings", string.Empty, 11f, 22f, 22f);
		LayoutElement component2 = ((Component)val2).GetComponent<LayoutElement>();
		component2.preferredWidth = 22f;
		component2.minWidth = 22f;
		_settingsButtonText = ((Component)val2).GetComponentInChildren<TextMeshProUGUI>();
		AddGearIcon(((Component)val2).transform);
		((UnityEvent)val2.onClick).AddListener(new UnityAction(OpenSettings));
		BindTooltip(((Component)val2).gameObject, UeiI18n.T("button.settings"), UeiI18n.T("button.settings.desc"));
		Button val3 = AddButton(val.transform, "Revive", string.Empty, 11f, 22f, 22f);
		LayoutElement component3 = ((Component)val3).GetComponent<LayoutElement>();
		component3.preferredWidth = 22f;
		component3.minWidth = 22f;
		AddReviveIcon(((Component)val3).transform);
		((UnityEvent)val3.onClick).AddListener(new UnityAction(HandleCheatRevive));
		BindTooltip(((Component)val3).gameObject, UeiI18n.T("button.revive"), UeiI18n.T("button.revive.desc"));
		_reviveButton = ((Component)val3).gameObject;
		_reviveButton.SetActive(false);
		return obj3;
	}

	private void HandlePagingInput()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: 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_007c: 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)
		Camera uiCamera = GetUiCamera();
		bool flag = _detailPanel.activeInHierarchy && (RectTransformUtility.RectangleContainsScreenPoint(_detailRect, Vector2.op_Implicit(Input.mousePosition), uiCamera) || IsPointerInsideScreenBounds(_detailRect, uiCamera));
		bool num = _settingsPanel.activeInHierarchy && (RectTransformUtility.RectangleContainsScreenPoint(_settingsRect, Vector2.op_Implicit(Input.mousePosition), uiCamera) || IsPointerInsideScreenBounds(_settingsRect, uiCamera));
		bool flag2 = RectTransformUtility.RectangleContainsScreenPoint(_panelRect, Vector2.op_Implicit(Input.mousePosition), uiCamera) || IsPointerInsideScreenBounds(_panelRect, uiCamera);
		if (num || (!flag && !flag2))
		{
			return;
		}
		int frameCount = Time.frameCount;
		if (_lastPagingInputFrame == frameCount)
		{
			return;
		}
		int num2 = ReadWheelPageDelta(frameCount);
		if (num2 == 0)
		{
			if (Input.GetKeyDown((KeyCode)280))
			{
				num2 = -1;
			}
			else if (Input.GetKeyDown((KeyCode)281))
			{
				num2 = 1;
			}
		}
		if (num2 != 0)
		{
			_lastPagingInputFrame = frameCount;
			if (flag)
			{
				ChangeRecipePage(num2);
			}
			else
			{
				ChangePage(num2);
			}
		}
	}

	private int ReadWheelPageDelta(int frame)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		if (_lastWheelSampleFrame == frame)
		{
			return 0;
		}
		_lastWheelSampleFrame = frame;
		float y = Input.mouseScrollDelta.y;
		if (Mathf.Abs(y) < 0.001f)
		{
			return 0;
		}
		if (_wheelAccumulator != 0f && Mathf.Sign(_wheelAccumulator) != Mathf.Sign(y))
		{
			_wheelAccumulator = 0f;
		}
		_wheelAccumulator += y;
		if (_wheelAccumulator >= 0.1f)
		{
			_wheelAccumulator = 0f;
			return -1;
		}
		if (_wheelAccumulator <= -0.1f)
		{
			_wheelAccumulator = 0f;
			return 1;
		}
		return 0;
	}

	private void ChangePage(int delta)
	{
		_page = Mathf.Clamp(_page + delta, 0, Math.Max(0, _lastPageCount - 1));
		_dirty = true;
		RefreshGrid();
	}

	private void ChangeCategory(int delta)
	{
		if (UeiCatalog.EnsureBuilt() && UeiCatalog.CategoryKeys.Count != 0)
		{
			int count = UeiCatalog.CategoryKeys.Count;
			_categoryIndex = (_categoryIndex + delta) % count;
			if (_categoryIndex < 0)
			{
				_categoryIndex += count;
			}
			_page = 0;
			_dirty = true;
			RefreshGrid();
		}
	}

	private void ChangeRecipePage(int delta)
	{
		_recipePage = Mathf.Clamp(_recipePage + delta, 0, Math.Max(0, _lastRecipePageCount - 1));
		_detailDirty = true;
		RefreshDetail();
	}

	private void ToggleDetailMode()
	{
		if (_selectedEntry != null)
		{
			_detailMode = ((_detailMode == UeiRecipeRelation.ProducedBy) ? UeiRecipeRelation.UsedIn : UeiRecipeRelation.ProducedBy);
			_recipePage = 0;
			_detailDirty = true;
			RefreshDetail();
		}
	}

	private void OpenSettings()
	{
		_settingsOpen = true;
		ClearNativeTooltip();
		_detailPanel.SetActive(false);
		_settingsPanel.SetActive(true);
		_pendingPanelScale = CurrentPanelScale();
		RefreshSettings();
	}

	private void CloseSettings()
	{
		_settingsOpen = false;
		ClearNativeTooltip();
		_settingsPanel.SetActive(false);
		_settingsCanvasGroup.blocksRaycasts = false;
		if (_selectedEntry != null)
		{
			_detailDirty = true;
			RefreshDetail();
		}
	}

	private void CloseDetail()
	{
		if (_settingsOpen)
		{
			CloseSettings();
		}
		_selectedEntry = null;
		_statusMessage = string.Empty;
		_recipePage = 0;
		ClearNativeTooltip();
		_detailDirty = true;
		_dirty = true;
		RefreshDetail();
		RefreshGrid();
	}

	private void RefreshSettings()
	{
		ClearChildren((Transform)(object)_settingsContent);
		UpdateStaticLanguageText();
		((TMP_Text)_settingsTitleText).text = UeiI18n.T("settings.title");
		AddSettingRow((Transform)(object)_settingsContent, UeiI18n.T("settings.language"), CurrentLanguageLabel(), CycleLanguageMode);
		AddSettingRow((Transform)(object)_settingsContent, UeiI18n.T("settings.position"), CurrentPositionLabel(), CyclePanelPosition);
		AddScaleSettingRow((Transform)(object)_settingsContent);
		bool flag = HasCheatPermission();
		if (!flag && CheatConfigured())
		{
			UeiPlugin.SetCheatEnabled(enabled: false);
		}
		bool flag2 = CheatEnabled();
		AddSettingRow((Transform)(object)_settingsContent, UeiI18n.T("settings.cheat"), (!flag) ? UeiI18n.T("settings.noCommandAccess") : (flag2 ? UeiI18n.T("settings.on") : UeiI18n.T("settings.off")), ToggleCheatMode, flag2, flag);
		AddSettingText((Transform)(object)_settingsContent, UeiI18n.T("settings.about") + "\n" + UeiI18n.Format("settings.aboutText", "1.2.4", "casualtiesunknown.uei", "Aakber (小叶子)"));
	}

	private void AddSettingRow(Transform parent, string label, string value, Action action, bool danger = false, bool enabled = true)
	{
		//IL_0041: 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_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Expected O, but got Unknown
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: 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_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f0: Expected O, but got Unknown
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		Color color = (danger ? new Color(0.55f, 0.04f, 0.02f, 0.72f) : new Color(0f, 0f, 0f, 0.42f));
		Color color2 = (Color)((!enabled) ? MutedTextColor : (danger ? new Color(1f, 0.34f, 0.28f, 1f) : TextColor));
		GameObject val = AddImage(parent, "SettingRow", color, raycast: true);
		LayoutElement obj = val.AddComponent<LayoutElement>();
		obj.preferredHeight = 30f;
		obj.minHeight = 30f;
		AddPixelBorder(val.transform, PixelBorderColor, 1f);
		HorizontalLayoutGroup obj2 = val.AddComponent<HorizontalLayoutGroup>();
		((LayoutGroup)obj2).padding = new RectOffset(6, 4, 3, 3);
		((HorizontalOrVerticalLayoutGroup)obj2).spacing = 6f;
		((LayoutGroup)obj2).childAlignment = (TextAnchor)4;
		((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = true;
		((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true;
		((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = false;
		((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = false;
		TextMeshProUGUI obj3 = AddText(val.transform, "Label", label, 10f, color2, (TextAlignmentOptions)4097);
		LayoutElement orAddLayoutElement = ((Component)(object)obj3).GetOrAddLayoutElement();
		orAddLayoutElement.flexibleWidth = 1f;
		orAddLayoutElement.preferredHeight = 22f;
		((TMP_Text)obj3).enableWordWrapping = false;
		Button val2 = AddButton(val.transform, "Value", value, 10f, 22f, 82f);
		TextMeshProUGUI componentInChildren = ((Component)val2).GetComponentInChildren<TextMeshProUGUI>();
		if ((Object)(object)componentInChildren != (Object)null && (danger || !enabled))
		{
			((Graphic)componentInChildren).color = color2;
		}
		LayoutElement component = ((Component)val2).GetComponent<LayoutElement>();
		component.preferredWidth = 92f;
		component.minWidth = 82f;
		ColorBlock colors = ((Selectable)val2).colors;
		((ColorBlock)(ref colors)).disabledColor = new Color(0.58f, 0.58f, 0.58f, 0.55f);
		((Selectable)val2).colors = colors;
		((Selectable)val2).interactable = enabled;
		if (enabled)
		{
			((UnityEvent)val2.onClick).AddListener((UnityAction)delegate
			{
				action();
			});
		}
	}

	private void AddScaleSettingRow(Transform parent)
	{
		//IL_001b: 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_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Expected O, but got Unknown
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_022d: Expected O, but got Unknown
		GameObject val = AddImage(parent, "SettingScaleRow", new Color(0f, 0f, 0f, 0.42f), raycast: true);
		LayoutElement obj = val.AddComponent<LayoutElement>();
		obj.preferredHeight = 30f;
		obj.minHeight = 30f;
		AddPixelBorder(val.transform, PixelBorderColor, 1f);
		HorizontalLayoutGroup obj2 = val.AddComponent<HorizontalLayoutGroup>();
		((LayoutGroup)obj2).padding = new RectOffset(6, 4, 3, 3);
		((HorizontalOrVerticalLayoutGroup)obj2).spacing = 6f;
		((LayoutGroup)obj2).childAlignment = (TextAnchor)4;
		((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = true;
		((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true;
		((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = false;
		((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = false;
		TextMeshProUGUI obj3 = AddText(val.transform, "Label", UeiI18n.T("settings.scale"), 10f, TextColor, (TextAlignmentOptions)4097);
		LayoutElement orAddLayoutElement = ((Component)(object)obj3).GetOrAddLayoutElement();
		orAddLayoutElement.preferredWidth = 48f;
		orAddLayoutElement.minWidth = 40f;
		orAddLayoutElement.preferredHeight = 22f;
		((TMP_Text)obj3).enableWordWrapping = false;
		_scaleSlider = AddSlider(val.transform, "ScaleSlider", 85f, 130f, Mathf.RoundToInt(_pendingPanelScale * 100f));
		LayoutElement component = ((Component)_scaleSlider).GetComponent<LayoutElement>();
		component.flexibleWidth = 1f;
		component.minWidth = 80f;
		component.preferredHeight = 22f;
		((UnityEvent<float>)(object)_scaleSlider.onValueChanged).AddListener((UnityAction<float>)delegate(float value)
		{
			_pendingPanelScale = Mathf.Round(value) / 100f;
			if ((Object)(object)_scaleValueText != (Object)null)
			{
				((TMP_Text)_scaleValueText).text = CurrentScaleLabel(_pendingPanelScale);
			}
		});
		_scaleValueText = AddText(val.transform, "Value", CurrentScaleLabel(_pendingPanelScale), 10f, TextColor, (TextAlignmentOptions)514);
		LayoutElement orAddLayoutElement2 = ((Component)(object)_scaleValueText).GetOrAddLayoutElement();
		orAddLayoutElement2.preferredWidth = 38f;
		orAddLayoutElement2.minWidth = 38f;
		orAddLayoutElement2.preferredHeight = 22f;
		((TMP_Text)_scaleValueText).enableWordWrapping = false;
		Button obj4 = AddButton(val.transform, "ApplyScale", UeiI18n.T("settings.apply"), 10f, 22f, 48f);
		LayoutElement component2 = ((Component)obj4).GetComponent<LayoutElement>();
		component2.preferredWidth = 50f;
		component2.minWidth = 48f;
		((UnityEvent)obj4.onClick).AddListener(new UnityAction(ApplyPendingPanelScale));
	}

	private void AddSettingText(Transform parent, string text)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		TextMeshProUGUI obj = AddText(parent, "SettingText", text, 10f, MutedTextColor, (TextAlignmentOptions)4097);
		LayoutElement orAddLayoutElement = ((Component)(object)obj).GetOrAddLayoutElement();
		orAddLayoutElement.preferredHeight = 78f;
		orAddLayoutElement.minHeight = 78f;
		((TMP_Text)obj).enableWordWrapping = true;
	}

	private static string CurrentLanguageLabel()
	{
		switch (SafeConfigString(() => UeiPlugin.LanguageMode.Value, "auto").Trim().ToLowerInvariant())
		{
		case "zh":
		case "cn":
		case "chinese":
			return UeiI18n.T("settings.language.zh");
		case "en":
		case "eng":
		case "english":
			return UeiI18n.T("settings.language.en");
		default:
			return UeiI18n.T("settings.language.auto");