Decompiled source of AdvancedEquipment 2 EQ Sets v1.0.0

AdvancedEquipment.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using HypnoCode;
using Microsoft.CodeAnalysis;
using Splatform;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace HypnoCode
{
	internal static class Admin
	{
		private static readonly FieldInfo AdminListField = AccessTools.Field(typeof(ZNet), "m_adminList");

		private static string Bare(string value)
		{
			return value.Substring(value.LastIndexOf('_') + 1).Trim();
		}

		private static bool Listed(IEnumerable<string> admins, string id)
		{
			if (admins == null || string.IsNullOrEmpty(id))
			{
				return false;
			}
			string text = Bare(id);
			if (text.Length == 0)
			{
				return false;
			}
			foreach (string admin in admins)
			{
				if (admin != null && (string.Equals(admin.Trim(), id, StringComparison.OrdinalIgnoreCase) || string.Equals(Bare(admin), text, StringComparison.OrdinalIgnoreCase)))
				{
					return true;
				}
			}
			return false;
		}

		internal static bool IsPeer(long uid)
		{
			ZNet instance = ZNet.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			if (uid == ZNet.GetUID())
			{
				return true;
			}
			ZNetPeer peer = instance.GetPeer(uid);
			if (peer == null || peer.m_socket == null)
			{
				return false;
			}
			string hostName = peer.m_socket.GetHostName();
			if (string.IsNullOrEmpty(hostName))
			{
				return false;
			}
			if (instance.IsAdmin(hostName))
			{
				return true;
			}
			SyncedList val = (SyncedList)((AdminListField != null) ? /*isinst with value type is only supported in some contexts*/: null);
			return Listed((val != null) ? val.GetList() : instance.GetAdminList(), hostName);
		}

		internal static bool IsLocal(bool serverSays = false)
		{
			ZNet instance = ZNet.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			if (instance.LocalPlayerIsAdminOrHost() || serverSays)
			{
				return true;
			}
			string id;
			try
			{
				id = ((object)Unsafe.As<PlatformUserID, PlatformUserID>(ref UserInfo.GetLocalUser().UserId)/*cast due to .constrained prefix*/).ToString();
			}
			catch
			{
				return false;
			}
			return Listed(instance.GetAdminList(), id);
		}
	}
	internal static class Compat
	{
		internal enum Kind
		{
			CompatMode,
			Info,
			Option,
			Resolved
		}

		internal sealed class Known
		{
			public string Guid;

			public string TypeName;

			public string Name;

			public Kind Kind;

			public Dictionary<string, string> Does;

			public Dictionary<string, string> Toggle;
		}

		private const string Backpack = "the backpack's rows and its portal/ship dock follow SeneaL's layout, and the inventory is saved around SeneaL's own saving (no items lost at a save)";

		private const string BackpackSlots = "the backpack's rows go right after the player's own rows, before Extra Slots' special slots";

		private const string BackpackArchery = "the backpack's row goes above Better Archery's quiver rows, and the portal/ship dock leaves the quiver where it is";

		internal static readonly Known[] Table = new Known[7]
		{
			new Known
			{
				Guid = "seneaL.valheim.ui",
				Name = "SeneaL UI",
				Kind = Kind.CompatMode,
				Does = new Dictionary<string, string>
				{
					{ "COAH", "the backpack's rows and its portal/ship dock follow SeneaL's layout, and the inventory is saved around SeneaL's own saving (no items lost at a save)" },
					{ "AdvancedBackpacks", "the backpack's rows and its portal/ship dock follow SeneaL's layout, and the inventory is saved around SeneaL's own saving (no items lost at a save)" }
				},
				Toggle = new Dictionary<string, string>
				{
					{ "COAH", "SeneaLUI" },
					{ "AdvancedBackpacks", "SeneaLUI" }
				}
			},
			new Known
			{
				Guid = "seneaL.valheim.api",
				Name = "SeneaL API",
				Kind = Kind.Info,
				Does = new Dictionary<string, string> { { "ImmersiveTrader", "the Quest Log gets a tab in SeneaL's character window" } },
				Toggle = new Dictionary<string, string> { { "ImmersiveTrader", "SeneaLQuestLogTab" } }
			},
			new Known
			{
				Guid = "shudnal.ExtraSlots",
				Name = "Extra Slots",
				Kind = Kind.CompatMode,
				Does = new Dictionary<string, string>
				{
					{ "COAH", "the backpack's rows go right after the player's own rows, before Extra Slots' special slots" },
					{ "AdvancedBackpacks", "the backpack's rows go right after the player's own rows, before Extra Slots' special slots" }
				},
				Toggle = new Dictionary<string, string>
				{
					{ "COAH", "ExtraSlots" },
					{ "AdvancedBackpacks", "ExtraSlots" }
				}
			},
			new Known
			{
				Guid = "ishid4.mods.betterarchery",
				Name = "Better Archery",
				Kind = Kind.CompatMode,
				Does = new Dictionary<string, string>
				{
					{ "COAH", "the backpack's row goes above Better Archery's quiver rows, and the portal/ship dock leaves the quiver where it is" },
					{ "AdvancedBackpacks", "the backpack's row goes above Better Archery's quiver rows, and the portal/ship dock leaves the quiver where it is" }
				},
				Toggle = new Dictionary<string, string>
				{
					{ "COAH", "BetterArchery" },
					{ "AdvancedBackpacks", "BetterArchery" }
				}
			},
			new Known
			{
				TypeName = "ValheimProfessions.ProfessionManager",
				Name = "ValheimProfessions",
				Kind = Kind.Option,
				Does = new Dictionary<string, string> { { "ImmersiveTrader", "traders, boards and caravans turn away a player with a profession when [Compatibility] BlockPlayersWithProfession is on" } },
				Toggle = new Dictionary<string, string> { { "ImmersiveTrader", "BlockPlayersWithProfession" } }
			},
			new Known
			{
				Guid = "goldenrevolver.quick_stack_store",
				Name = "Quick Stack Store",
				Kind = Kind.Info,
				Does = new Dictionary<string, string> { { "SortByQoL", "works with it: when it refreshes the crafting list, the sorting and the filters are applied again" } }
			},
			new Known
			{
				Guid = "p0kahontazz.coah",
				Name = "Children of the Ancient Heart",
				Kind = Kind.Resolved,
				Does = new Dictionary<string, string>
				{
					{ "AdvancedBackpacks", "Advanced Backpacks is switched off (COAH has the same backpacks); the Advanced Backpacks a player carries become COAH backpacks with what they hold" },
					{ "AdvancedPortal", "the Advanced Portal is no longer in the hammer (COAH's Heart Portal is the same); the ones standing keep working" }
				}
			}
		};

		private static readonly Dictionary<string, string> OurGuids = new Dictionary<string, string>
		{
			{ "ImmersiveTrader", "p0kahontazz.immersivetrader" },
			{ "COAH", "p0kahontazz.coah" },
			{ "AdvancedBackpacks", "p0kahontazz.advancedbackpacks" },
			{ "AdvancedPortal", "p0kahontazz.advancedportal" },
			{ "SortByQoL", "p0kahontazz.sortbyqol" }
		};

		internal static Type FindType(string fullName)
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				try
				{
					Type type = assembly.GetType(fullName, throwOnError: false);
					if (type != null)
					{
						return type;
					}
				}
				catch
				{
				}
			}
			return null;
		}

		internal static bool Installed(Known known, out string version)
		{
			version = "";
			try
			{
				if (known.Guid != null)
				{
					if (!Chainloader.PluginInfos.TryGetValue(known.Guid, out var value) || value == null)
					{
						return false;
					}
					version = ((value.Metadata != null && value.Metadata.Version != null) ? value.Metadata.Version.ToString() : "");
					return true;
				}
				return known.TypeName != null && FindType(known.TypeName) != null;
			}
			catch
			{
				return false;
			}
		}

		private static string Off(Known known, string ours)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			try
			{
				if (known.Toggle == null || !known.Toggle.TryGetValue(ours, out var value) || !OurGuids.TryGetValue(ours, out var value2))
				{
					return "";
				}
				if (!Chainloader.PluginInfos.TryGetValue(value2, out var value3) || value3 == null || (Object)(object)value3.Instance == (Object)null)
				{
					return "";
				}
				ConfigFile config = value3.Instance.Config;
				ConfigDefinition val = new ConfigDefinition("Compatibility", value);
				if (config == null || !config.ContainsKey(val) || !(config[val].BoxedValue is bool))
				{
					return "";
				}
				return ((bool)config[val].BoxedValue) ? "" : (" (off: [Compatibility] " + value + " = false)");
			}
			catch
			{
				return "";
			}
		}

		internal static void Report(ManualLogSource log, string ours)
		{
			if (log == null)
			{
				return;
			}
			Known[] table = Table;
			foreach (Known known in table)
			{
				if (known.Does != null && known.Does.TryGetValue(ours, out var value) && Installed(known, out var version))
				{
					log.LogInfo((object)("Detected " + known.Name + ((version.Length > 0) ? (" " + version) : "") + ": " + value + Off(known, ours) + "."));
				}
			}
		}

		internal static List<string> Lines()
		{
			List<string> list = new List<string>();
			Known[] table = Table;
			foreach (Known known in table)
			{
				if (Installed(known, out var version))
				{
					list.Add(known.Name + ((version.Length > 0) ? (" " + version) : "") + " (" + (known.Guid ?? known.TypeName) + ", " + known.Kind.ToString() + "): " + string.Join("; ", known.Does.Select((KeyValuePair<string, string> p) => p.Key + " - " + p.Value + Off(known, p.Key)).ToArray()));
				}
			}
			return list;
		}
	}
	internal static class LogLimit
	{
		private sealed class Seen
		{
			public float Next = float.MinValue;

			public int Skipped;
		}

		private const float Every = 10f;

		private static readonly Dictionary<string, Seen> State = new Dictionary<string, Seen>();

		internal static void Warn(ManualLogSource log, string key, string message)
		{
			if (log != null)
			{
				float unscaledTime = Time.unscaledTime;
				if (!State.TryGetValue(key, out var value))
				{
					value = (State[key] = new Seen());
				}
				if (unscaledTime < value.Next)
				{
					value.Skipped++;
					return;
				}
				log.LogWarning((object)((value.Skipped > 0) ? (message + " (and " + value.Skipped + " more times in the last " + 10f.ToString("0") + " s)") : message));
				value.Next = unscaledTime + 10f;
				value.Skipped = 0;
			}
		}
	}
	internal static class ModReport
	{
		private sealed class Listener : ILogListener, IDisposable
		{
			public void LogEvent(object sender, LogEventArgs e)
			{
				//IL_0004: Unknown result type (might be due to invalid IL or missing references)
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				if (e == null || (e.Level & 7) == 0)
				{
					return;
				}
				string text = Convert.ToString(e.Data) ?? "";
				if (text.Length > 800)
				{
					text = text.Substring(0, 800) + " ...";
				}
				string item = DateTime.Now.ToString("HH:mm:ss") + " [" + ((object)e.Level/*cast due to .constrained prefix*/).ToString() + ": " + ((e.Source != null) ? e.Source.SourceName : "?") + "] " + text.Replace("\r", "").Replace("\n", " | ");
				lock (recent)
				{
					recent.Enqueue(item);
					while (recent.Count > 200)
					{
						recent.Dequeue();
					}
				}
			}

			public void Dispose()
			{
			}
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Func<PluginInfo, bool> <>9__8_0;

			public static Func<PluginInfo, string> <>9__8_1;

			public static Func<PluginInfo, bool> <>9__8_2;

			public static Func<KeyValuePair<ConfigDefinition, ConfigEntryBase>, string> <>9__9_0;

			public static Func<KeyValuePair<ConfigDefinition, ConfigEntryBase>, string> <>9__9_1;

			public static ConsoleEvent <>9__12_0;

			public static Func<PluginInfo, bool> <>9__13_0;

			public static Func<PluginInfo, string> <>9__13_1;

			internal bool <Plugins>b__8_0(PluginInfo p)
			{
				if (p != null)
				{
					return p.Metadata != null;
				}
				return false;
			}

			internal string <Plugins>b__8_1(PluginInfo p)
			{
				return p.Metadata.GUID;
			}

			internal bool <Plugins>b__8_2(PluginInfo p)
			{
				return IsHypnogoogic(p.Metadata.GUID);
			}

			internal string <ChangedSettings>b__9_0(KeyValuePair<ConfigDefinition, ConfigEntryBase> p)
			{
				return p.Key.Section;
			}

			internal string <ChangedSettings>b__9_1(KeyValuePair<ConfigDefinition, ConfigEntryBase> p)
			{
				return p.Key.Key;
			}

			internal void <RegisterCommand>b__12_0(ConsoleEventArgs args)
			{
				if (args.Length < 2 || !string.Equals(args[1], "report", StringComparison.OrdinalIgnoreCase))
				{
					if ((Object)(object)args.Context != (Object)null)
					{
						args.Context.AddString("Usage: hypno report");
					}
					return;
				}
				try
				{
					string text = WriteCommon();
					if ((Object)(object)args.Context != (Object)null)
					{
						args.Context.AddString("Report written: " + text + " - send this file with your bug report (it holds no account name or secrets).");
					}
				}
				catch (Exception ex)
				{
					if ((Object)(object)args.Context != (Object)null)
					{
						args.Context.AddString("The report could not be written: " + ex.Message);
					}
				}
			}

			internal bool <WriteCommon>b__13_0(PluginInfo p)
			{
				if (p != null && p.Metadata != null && (Object)(object)p.Instance != (Object)null)
				{
					return IsHypnogoogic(p.Metadata.GUID);
				}
				return false;
			}

			internal string <WriteCommon>b__13_1(PluginInfo p)
			{
				return p.Metadata.Name;
			}
		}

		private const int Keep = 200;

		private static readonly Queue<string> recent = new Queue<string>();

		private static Listener listener;

		internal const string CommonFile = "Hypnogoogic-report.txt";

		internal static void StartLog()
		{
			if (listener == null)
			{
				listener = new Listener();
				Logger.Listeners.Add((ILogListener)(object)listener);
			}
		}

		internal static bool IsHypnogoogic(string guid)
		{
			if (guid != null)
			{
				if (!guid.StartsWith("p0kahontazz.", StringComparison.OrdinalIgnoreCase))
				{
					return guid == "pl.rootsandremedies.foods";
				}
				return true;
			}
			return false;
		}

		internal static string GameType()
		{
			ZNet instance = ZNet.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return "main menu (no world)";
			}
			if (!instance.IsServer())
			{
				return "client on a server";
			}
			if (instance.IsDedicated())
			{
				return "dedicated server";
			}
			bool flag = true;
			try
			{
				FieldInfo field = typeof(ZNet).GetField("m_openServer", BindingFlags.Static | BindingFlags.NonPublic);
				if (field != null)
				{
					flag = (bool)field.GetValue(null);
				}
			}
			catch
			{
			}
			if (!flag)
			{
				return "single player";
			}
			return "host (others can join)";
		}

		internal static void Head(StringBuilder sb, string title)
		{
			sb.AppendLine("=== " + title + " ===");
			sb.AppendLine("Written: " + DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + " UTC");
			try
			{
				sb.AppendLine("Valheim: " + Version.GetVersionString(false));
			}
			catch
			{
				sb.AppendLine("Valheim: ?");
			}
			sb.AppendLine("Game: " + GameType());
			try
			{
				if ((Object)(object)ZNet.instance != (Object)null && ZNet.instance.GetWorldName() != null)
				{
					sb.AppendLine("World: " + ZNet.instance.GetWorldName());
				}
			}
			catch
			{
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer != (Object)null)
			{
				sb.AppendLine("Character: " + localPlayer.GetPlayerName() + " (player id " + localPlayer.GetPlayerID() + ")");
			}
			sb.AppendLine();
		}

		internal static void Plugins(StringBuilder sb)
		{
			List<PluginInfo> list = Chainloader.PluginInfos.Values.Where((PluginInfo p) => p != null && p.Metadata != null).OrderBy<PluginInfo, string>((PluginInfo p) => p.Metadata.GUID, StringComparer.OrdinalIgnoreCase).ToList();
			sb.AppendLine("--- Hypnogoogic mods ---");
			foreach (PluginInfo item in list.Where((PluginInfo p) => IsHypnogoogic(p.Metadata.GUID)))
			{
				sb.AppendLine(item.Metadata.Name + " " + item.Metadata.Version?.ToString() + "  (" + item.Metadata.GUID + ")");
			}
			sb.AppendLine();
			sb.AppendLine("--- Known mods (how ours work with them, see Compat) ---");
			List<string> list2 = Compat.Lines();
			if (list2.Count == 0)
			{
				sb.AppendLine("(none installed)");
			}
			foreach (string item2 in list2)
			{
				sb.AppendLine(item2);
			}
			sb.AppendLine();
			sb.AppendLine("--- All plugins (" + list.Count + ") ---");
			foreach (PluginInfo item3 in list)
			{
				sb.AppendLine(item3.Metadata.GUID + "  " + item3.Metadata.Version?.ToString() + "  " + item3.Metadata.Name);
			}
			sb.AppendLine();
		}

		internal static void ChangedSettings(StringBuilder sb, ConfigFile config, string title)
		{
			sb.AppendLine("--- " + title + ": settings changed from the default ---");
			int num = 0;
			if (config != null)
			{
				foreach (KeyValuePair<ConfigDefinition, ConfigEntryBase> item in from p in (IEnumerable<KeyValuePair<ConfigDefinition, ConfigEntryBase>>)config
					orderby p.Key.Section, p.Key.Key
					select p)
				{
					ConfigEntryBase value = item.Value;
					if (value != null && !object.Equals(value.BoxedValue, value.DefaultValue))
					{
						string text = item.Key.Section + "." + item.Key.Key;
						string text2 = item.Key.Key.ToLowerInvariant();
						bool flag = value.SettingType == typeof(string) && (text2.Contains("key") || text2.Contains("token") || text2.Contains("password") || text2.Contains("secret") || text2.Contains("webhook"));
						sb.AppendLine(text + " = " + (flag ? "(hidden)" : value.GetSerializedValue()) + "   (default " + (flag ? "(hidden)" : ((value.DefaultValue != null) ? Convert.ToString(value.DefaultValue) : "none")) + ")");
						num++;
					}
				}
			}
			if (num == 0)
			{
				sb.AppendLine("(none)");
			}
			sb.AppendLine();
		}

		internal static void RecentLog(StringBuilder sb)
		{
			string[] array;
			lock (recent)
			{
				array = recent.ToArray();
			}
			sb.AppendLine("--- Last " + array.Length + " warnings and errors of the log (all mods) ---");
			if (listener == null)
			{
				sb.AppendLine("(not kept: the log was not watched)");
			}
			string[] array2 = array;
			foreach (string value in array2)
			{
				sb.AppendLine(value);
			}
			sb.AppendLine();
		}

		internal static void RegisterCommand()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			StartLog();
			object obj = <>c.<>9__12_0;
			if (obj == null)
			{
				ConsoleEvent val = delegate(ConsoleEventArgs args)
				{
					if (args.Length < 2 || !string.Equals(args[1], "report", StringComparison.OrdinalIgnoreCase))
					{
						if ((Object)(object)args.Context != (Object)null)
						{
							args.Context.AddString("Usage: hypno report");
						}
						return;
					}
					try
					{
						string text = WriteCommon();
						if ((Object)(object)args.Context != (Object)null)
						{
							args.Context.AddString("Report written: " + text + " - send this file with your bug report (it holds no account name or secrets).");
						}
					}
					catch (Exception ex)
					{
						if ((Object)(object)args.Context != (Object)null)
						{
							args.Context.AddString("The report could not be written: " + ex.Message);
						}
					}
				};
				<>c.<>9__12_0 = val;
				obj = (object)val;
			}
			new ConsoleCommand("hypno", "hypno report - writes BepInEx/Hypnogoogic-report.txt (game, mods, settings, last warnings) to send with a bug report", (ConsoleEvent)obj, false, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
		}

		internal static string WriteCommon()
		{
			StringBuilder stringBuilder = new StringBuilder();
			Head(stringBuilder, "Hypnogoogic mods report");
			Plugins(stringBuilder);
			foreach (PluginInfo item in Chainloader.PluginInfos.Values.Where((PluginInfo p) => p != null && p.Metadata != null && (Object)(object)p.Instance != (Object)null && IsHypnogoogic(p.Metadata.GUID)).OrderBy<PluginInfo, string>((PluginInfo p) => p.Metadata.Name, StringComparer.OrdinalIgnoreCase))
			{
				ChangedSettings(stringBuilder, item.Instance.Config, item.Metadata.Name + " " + item.Metadata.Version);
			}
			RecentLog(stringBuilder);
			return Write("Hypnogoogic-report.txt", stringBuilder.ToString());
		}

		internal static string Write(string fileName, string text)
		{
			string text2 = Path.Combine(Paths.BepInExRootPath, fileName);
			File.WriteAllText(text2, text, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
			return text2;
		}
	}
	internal static class Prefabs
	{
		private static Dictionary<int, GameObject> Named(ZNetScene scene)
		{
			return (Dictionary<int, GameObject>)AccessTools.Field(typeof(ZNetScene), "m_namedPrefabs").GetValue(scene);
		}

		internal static void RegisterScene(ZNetScene scene, GameObject prefab)
		{
			Dictionary<int, GameObject> dictionary = Named(scene);
			int stableHashCode = StringExtensionMethods.GetStableHashCode(((Object)prefab).name);
			if (dictionary.ContainsKey(stableHashCode))
			{
				throw new InvalidOperationException("Prefab name collision: " + ((Object)prefab).name);
			}
			dictionary.Add(stableHashCode, prefab);
			scene.m_prefabs.Add(prefab);
		}

		internal static void Replace(ZNetScene scene, GameObject prefab)
		{
			Named(scene)[StringExtensionMethods.GetStableHashCode(((Object)prefab).name)] = prefab;
			if (!scene.m_prefabs.Contains(prefab))
			{
				scene.m_prefabs.Add(prefab);
			}
		}

		internal static PieceTable Hammer(ZNetScene scene)
		{
			GameObject val = (((Object)(object)scene != (Object)null) ? scene.GetPrefab("Hammer") : null);
			ItemDrop val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null);
			if (!((Object)(object)val2 != (Object)null))
			{
				return null;
			}
			return val2.m_itemData.m_shared.m_buildPieces;
		}

		internal static void AddToHammer(PieceTable table, GameObject prefab)
		{
			if (!((Object)(object)table == (Object)null) && !((Object)(object)prefab == (Object)null))
			{
				table.m_pieces.RemoveAll((GameObject p) => (Object)(object)p == (Object)null || ((Object)p).name == ((Object)prefab).name);
				table.m_pieces.Add(prefab);
			}
		}
	}
	internal static class StateFile
	{
		internal static Action<string> Info = delegate
		{
		};

		internal static Action<string> Warn = delegate
		{
		};

		private const int KeepBackups = 7;

		private static readonly Dictionary<string, string> backedUpOn = new Dictionary<string, string>();

		internal static string Folder(string mod)
		{
			string text = Path.Combine(Paths.BepInExRootPath, "data", mod);
			Directory.CreateDirectory(text);
			return text;
		}

		internal static string PathOf(string mod, string file)
		{
			string text = Path.Combine(Folder(mod), file);
			MoveOld(Path.Combine(Paths.ConfigPath, file), text);
			MoveOld(Path.Combine(Paths.ConfigPath, file + ".bak"), text + ".bak");
			return text;
		}

		private static void MoveOld(string old, string path)
		{
			try
			{
				if (!File.Exists(path) && File.Exists(old))
				{
					File.Copy(old, path);
					string text = old + ".moved";
					if (File.Exists(text))
					{
						File.Delete(text);
					}
					File.Move(old, text);
					Info("State file moved out of BepInEx/config: " + Path.GetFileName(old) + " -> " + path + " (the old one is kept as " + Path.GetFileName(text) + ").");
				}
			}
			catch (Exception ex)
			{
				Warn("State file " + Path.GetFileName(old) + " could not be moved (" + ex.Message + "); it is read where it is next time.");
			}
		}

		internal static string[] ReadLines(string path)
		{
			DailyBackup(path);
			string text = path + ".bak";
			try
			{
				if (File.Exists(path) && (new FileInfo(path).Length > 0 || !File.Exists(text) || new FileInfo(text).Length == 0L))
				{
					return File.ReadAllLines(path);
				}
			}
			catch (Exception ex)
			{
				Warn("State file " + Path.GetFileName(path) + " could not be read (" + ex.Message + "), trying its backup.");
			}
			try
			{
				if (File.Exists(text))
				{
					Warn("State file " + Path.GetFileName(path) + " is missing or empty: read from " + Path.GetFileName(text) + ".");
					return File.ReadAllLines(text);
				}
			}
			catch (Exception ex2)
			{
				Warn("State file backup " + Path.GetFileName(text) + " could not be read (" + ex2.Message + ").");
			}
			return new string[0];
		}

		internal static void Append(string path, string line)
		{
			Directory.CreateDirectory(Path.GetDirectoryName(path));
			File.AppendAllText(path, line + Environment.NewLine);
			DailyBackup(path);
		}

		internal static void Rewrite(string path, IEnumerable<string> lines)
		{
			Directory.CreateDirectory(Path.GetDirectoryName(path));
			string text = path + ".tmp";
			string text2 = path + ".bak";
			File.WriteAllLines(text, lines);
			try
			{
				if (File.Exists(path))
				{
					File.Replace(text, path, text2);
				}
				else
				{
					File.Move(text, path);
				}
			}
			catch (Exception ex)
			{
				Warn("State file " + Path.GetFileName(path) + ": atomic replace failed (" + ex.Message + "), copying instead.");
				if (File.Exists(path))
				{
					File.Copy(path, text2, overwrite: true);
				}
				File.Copy(text, path, overwrite: true);
				File.Delete(text);
			}
		}

		internal static void DailyBackup(string path)
		{
			try
			{
				string directoryName = Path.GetDirectoryName(path);
				if (string.IsNullOrEmpty(directoryName) || !Directory.Exists(directoryName))
				{
					return;
				}
				string text = DateTime.Now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
				if (backedUpOn.TryGetValue(directoryName, out var value) && value == text)
				{
					return;
				}
				backedUpOn[directoryName] = text;
				string text2 = Path.Combine(directoryName, "backups");
				string text3 = Path.Combine(text2, text);
				if (Directory.Exists(text3))
				{
					return;
				}
				string[] array = (from f in Directory.GetFiles(directoryName)
					where !f.EndsWith(".tmp", StringComparison.OrdinalIgnoreCase)
					select f).ToArray();
				if (array.Length != 0)
				{
					Directory.CreateDirectory(text3);
					string[] array2 = array;
					foreach (string text4 in array2)
					{
						File.Copy(text4, Path.Combine(text3, Path.GetFileName(text4)), overwrite: true);
					}
					array2 = (from d in Directory.GetDirectories(text2)
						where IsDaily(Path.GetFileName(d))
						select d).OrderByDescending<string, string>((string d) => Path.GetFileName(d), StringComparer.Ordinal).Skip(7).ToArray();
					for (int num = 0; num < array2.Length; num++)
					{
						Directory.Delete(array2[num], recursive: true);
					}
					Info("State files backed up to " + text3 + " (" + array.Length + " files, the " + 7 + " newest days are kept).");
				}
			}
			catch (Exception ex)
			{
				Warn("Daily backup of the state files failed (" + ex.Message + ").");
			}
		}

		private static bool IsDaily(string name)
		{
			DateTime result;
			if (name.Length == 10)
			{
				return DateTime.TryParseExact(name, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out result);
			}
			return false;
		}

		private static bool IsStateFile(string path)
		{
			string fileName = Path.GetFileName(path);
			if (!fileName.EndsWith(".bak", StringComparison.OrdinalIgnoreCase) && !fileName.EndsWith(".tmp", StringComparison.OrdinalIgnoreCase))
			{
				return !fileName.EndsWith(".moved", StringComparison.OrdinalIgnoreCase);
			}
			return false;
		}

		internal static string Snapshot(string dir, string label, out int count)
		{
			count = 0;
			string text = label + "-" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss", CultureInfo.InvariantCulture);
			string text2 = Path.Combine(dir, "backups", text);
			string[] array = (from f in Directory.GetFiles(dir)
				where !f.EndsWith(".tmp", StringComparison.OrdinalIgnoreCase)
				select f).ToArray();
			Directory.CreateDirectory(text2);
			string[] array2 = array;
			foreach (string text3 in array2)
			{
				File.Copy(text3, Path.Combine(text2, Path.GetFileName(text3)), overwrite: true);
				count++;
			}
			Info("State files copied to " + text2 + " (" + count + " files).");
			return text;
		}

		internal static List<KeyValuePair<string, string>> Backups(string dir)
		{
			List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>();
			string path = Path.Combine(dir, "backups");
			if (!Directory.Exists(path))
			{
				return list;
			}
			foreach (string item in from d in Directory.GetDirectories(path)
				orderby Directory.GetLastWriteTime(d) descending
				select d)
			{
				int num = Directory.GetFiles(item).Count(IsStateFile);
				list.Add(new KeyValuePair<string, string>(Path.GetFileName(item), Directory.GetLastWriteTime(item).ToString("yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture) + ", " + num + " state files"));
			}
			return list;
		}

		internal static int RestoreFrom(string dir, string backupName)
		{
			if (string.IsNullOrEmpty(backupName) || backupName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0 || backupName.Contains(".."))
			{
				return -1;
			}
			string text = Path.Combine(dir, "backups", backupName);
			if (!Directory.Exists(text))
			{
				return -1;
			}
			int num = 0;
			foreach (string item in Directory.GetFiles(text).Where(IsStateFile))
			{
				Rewrite(Path.Combine(dir, Path.GetFileName(item)), File.ReadAllLines(item));
				num++;
			}
			Info("State files restored from " + text + " (" + num + " files).");
			return num;
		}
	}
	internal static class UiKit
	{
		internal static Action<string> Warn = delegate
		{
		};

		internal static readonly Dictionary<string, Sprite> sprites = new Dictionary<string, Sprite>();

		internal static Sprite panelSprite;

		internal static Type panelType;

		internal static Color panelColor = new Color(0.25f, 0.17f, 0.1f, 0.97f);

		internal static float panelPpu = 1f;

		internal static Material panelMaterial;

		internal static Button buttonTemplate;

		internal static TMP_FontAsset font;

		internal static TMP_FontAsset titleFont;

		internal static Color titleColor = new Color(1f, 0.63f, 0.235f);

		internal static Color bodyColor = new Color(0.98f, 0.95f, 0.9f);

		internal static bool skin;

		internal static Sprite flat;

		internal static TMP_FontAsset BodyFont()
		{
			if ((Object)(object)font == (Object)null)
			{
				Discover();
			}
			return font;
		}

		internal static RectTransform Rect(string name, Transform parent, Vector2 aMin, Vector2 aMax, Vector2 oMin, Vector2 oMax)
		{
			//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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = new GameObject(name, new Type[1] { typeof(RectTransform) })
			{
				layer = LayerMask.NameToLayer("UI")
			}.GetComponent<RectTransform>();
			((Transform)component).SetParent(parent, false);
			component.anchorMin = aMin;
			component.anchorMax = aMax;
			component.offsetMin = oMin;
			component.offsetMax = oMax;
			return component;
		}

		internal static Image Box(string name, Transform parent, Vector2 aMin, Vector2 aMax, Vector2 oMin, Vector2 oMax, Color color)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			Image obj = ((Component)Rect(name, parent, aMin, aMax, oMin, oMax)).gameObject.AddComponent<Image>();
			((Graphic)obj).color = color;
			return obj;
		}

		internal static Sprite FindSprite(string name)
		{
			if (sprites.TryGetValue(name, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			value = null;
			Sprite[] array = Resources.FindObjectsOfTypeAll<Sprite>();
			foreach (Sprite val in array)
			{
				if ((Object)(object)val != (Object)null && ((Object)val).name == name)
				{
					value = val;
					break;
				}
			}
			sprites[name] = value;
			return value;
		}

		internal static bool Draws(TMP_FontAsset f)
		{
			if ((Object)(object)f == (Object)null)
			{
				return false;
			}
			try
			{
				return f.HasCharacter('A', true, true) && f.HasCharacter('g', true, true) && f.HasCharacter('7', true, true);
			}
			catch
			{
				return false;
			}
		}

		internal static void Discover()
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			skin = false;
			panelSprite = null;
			buttonTemplate = null;
			InventoryGui instance = InventoryGui.instance;
			TMP_FontAsset val = null;
			try
			{
				val = (((Object)(object)instance != (Object)null && (Object)(object)instance.m_recipeDecription != (Object)null) ? instance.m_recipeDecription.font : null);
				if ((Object)(object)instance != (Object)null && (Object)(object)instance.m_recipeDecription != (Object)null)
				{
					bodyColor = ((Graphic)instance.m_recipeDecription).color;
				}
			}
			catch
			{
			}
			try
			{
				titleFont = (((Object)(object)instance != (Object)null && (Object)(object)instance.m_recipeName != (Object)null && Draws(instance.m_recipeName.font)) ? instance.m_recipeName.font : null);
			}
			catch
			{
				titleFont = null;
			}
			TMP_FontAsset val2 = (Draws(val) ? val : null);
			if ((Object)(object)val2 == (Object)null)
			{
				TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
				foreach (TMP_FontAsset val3 in array)
				{
					if ((Object)(object)val3 != (Object)null && ((Object)val3).name.IndexOf("Averia", StringComparison.OrdinalIgnoreCase) >= 0 && Draws(val3))
					{
						val2 = val3;
						break;
					}
				}
			}
			if ((Object)(object)val2 == (Object)null)
			{
				try
				{
					TMP_FontAsset defaultFontAsset = TMP_Settings.defaultFontAsset;
					if (Draws(defaultFontAsset))
					{
						val2 = defaultFontAsset;
					}
				}
				catch
				{
				}
			}
			if ((Object)(object)val2 == (Object)null)
			{
				TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
				foreach (TMP_FontAsset val4 in array)
				{
					if (Draws(val4))
					{
						val2 = val4;
						break;
					}
				}
			}
			font = val2 ?? val;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.m_crafting == (Object)null)
			{
				return;
			}
			try
			{
				List<Image> list = ((Component)instance.m_crafting).GetComponentsInChildren<Image>(true).ToList();
				Transform parent = ((Transform)instance.m_crafting).parent;
				int num = 0;
				while (num < 3 && (Object)(object)parent != (Object)null)
				{
					Image component = ((Component)parent).GetComponent<Image>();
					if ((Object)(object)component != (Object)null)
					{
						list.Add(component);
					}
					num++;
					parent = parent.parent;
				}
				Func<Image, bool> bad = delegate(Image val6)
				{
					string text = (((Object)val6).name + " " + ((Object)val6.sprite).name).ToLowerInvariant();
					string[] array2 = new string[12]
					{
						"darken", "blob", "shadow", "glow", "select", "icon", "scroll", "handle", "bar", "highlight",
						"button", "tab"
					};
					foreach (string value in array2)
					{
						if (text.Contains(value))
						{
							return true;
						}
					}
					return false;
				};
				Image val5 = list.Where((Image val6) => (Object)(object)val6.sprite != (Object)null && !bad(val6) && ((Graphic)val6).color.a > 0.5f).OrderByDescending(delegate(Image val6)
				{
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					//IL_000b: Unknown result type (might be due to invalid IL or missing references)
					//IL_0019: Unknown result type (might be due to invalid IL or missing references)
					//IL_001e: Unknown result type (might be due to invalid IL or missing references)
					Rect rect = ((Graphic)val6).rectTransform.rect;
					float width = ((Rect)(ref rect)).width;
					rect = ((Graphic)val6).rectTransform.rect;
					return width * ((Rect)(ref rect)).height;
				}).FirstOrDefault();
				if ((Object)(object)val5 != (Object)null)
				{
					panelSprite = val5.sprite;
					panelType = val5.type;
					panelColor = ((Graphic)val5).color;
					panelPpu = val5.pixelsPerUnitMultiplier;
					panelMaterial = ((Graphic)val5).material;
				}
				buttonTemplate = instance.m_craftButton;
				skin = (Object)(object)val5 != (Object)null;
			}
			catch (Exception ex)
			{
				Warn("HypnoCode: the game's skin was not found (" + ex.Message + "), plain colours are used.");
			}
		}

		internal static TMP_Text Label(string name, Transform parent, Vector2 aMin, Vector2 aMax, Vector2 oMin, Vector2 oMax, string text, float size, Color color, TextAlignmentOptions align, bool ellipsis = false)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			GameObject gameObject = ((Component)Rect(name, parent, aMin, aMax, oMin, oMax)).gameObject;
			gameObject.SetActive(false);
			TextMeshProUGUI val = gameObject.AddComponent<TextMeshProUGUI>();
			if ((Object)(object)font != (Object)null)
			{
				((TMP_Text)val).font = font;
			}
			((TMP_Text)val).text = text;
			((TMP_Text)val).fontSize = size;
			((Graphic)val).color = color;
			((TMP_Text)val).alignment = align;
			((Graphic)val).raycastTarget = false;
			((TMP_Text)val).enableWordWrapping = false;
			((TMP_Text)val).overflowMode = (TextOverflowModes)(ellipsis ? 1 : 0);
			gameObject.SetActive(true);
			return (TMP_Text)(object)val;
		}

		internal static bool Keep(Component c)
		{
			if (!(c is Graphic) && !(c is Selectable) && !(c is Mask) && !(c is RectMask2D) && !(c is LayoutGroup) && !(c is ContentSizeFitter) && !(c is LayoutElement))
			{
				return c is BaseMeshEffect;
			}
			return true;
		}

		internal static Button MakeButton(string name, Transform parent, Vector2 aMin, Vector2 aMax, Vector2 oMin, Vector2 oMax, string text, Color colour, Action click, out TMP_Text labelOut, float size = 30f, bool edge = false)
		{
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Expected O, but got Unknown
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: Unknown result type (might be due to invalid IL or missing references)
			//IL_036a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: 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_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			Image val2;
			Button val3;
			if (skin && (Object)(object)buttonTemplate != (Object)null)
			{
				GameObject val = Object.Instantiate<GameObject>(((Component)buttonTemplate).gameObject, parent, false);
				((Object)val).name = name;
				val.SetActive(true);
				ColorBlock colors = ((Selectable)buttonTemplate).colors;
				Transition transition = ((Selectable)buttonTemplate).transition;
				SpriteState spriteState = ((Selectable)buttonTemplate).spriteState;
				foreach (MonoBehaviour item in val.GetComponentsInChildren<MonoBehaviour>(true).ToList())
				{
					if ((Object)(object)item != (Object)null && !Keep((Component)(object)item))
					{
						Object.DestroyImmediate((Object)(object)item);
					}
				}
				foreach (Selectable item2 in val.GetComponentsInChildren<Selectable>(true).ToList())
				{
					if ((Object)(object)item2 != (Object)null)
					{
						Object.DestroyImmediate((Object)(object)item2);
					}
				}
				val2 = val.GetComponent<Image>();
				val3 = val.AddComponent<Button>();
				((Selectable)val3).targetGraphic = (Graphic)(object)val2;
				((Selectable)val3).transition = transition;
				((Selectable)val3).colors = colors;
				((Selectable)val3).spriteState = spriteState;
				TMP_Text[] componentsInChildren = val.GetComponentsInChildren<TMP_Text>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					((Component)componentsInChildren[i]).gameObject.SetActive(false);
				}
				RectTransform val4 = (RectTransform)val.transform;
				val4.anchorMin = aMin;
				val4.anchorMax = aMax;
				val4.offsetMin = oMin;
				val4.offsetMax = oMax;
			}
			else
			{
				val2 = Box(name, parent, aMin, aMax, oMin, oMax, new Color(0.1f, 0.07f, 0.04f, 0.9f));
				val3 = ((Component)val2).gameObject.AddComponent<Button>();
				((Selectable)val3).targetGraphic = (Graphic)(object)val2;
			}
			((UnityEvent)val3.onClick).AddListener((UnityAction)delegate
			{
				ClickSound();
				click();
			});
			TMP_Text val5 = Label("text", ((Component)val2).transform, Vector2.zero, Vector2.one, Vector2.zero, Vector2.zero, text, size, colour, (TextAlignmentOptions)514);
			GameObject edge2 = null;
			RectTransform val6;
			if (edge)
			{
				val6 = Rect("edge", ((Component)val3).transform, Vector2.zero, Vector2.one, new Vector2(-1f, -1f), new Vector2(1f, 1f));
				Image val7 = ((Component)val6).gameObject.AddComponent<Image>();
				((Graphic)val7).raycastTarget = false;
				Sprite val8 = FindSprite("selection_frame");
				if ((Object)(object)val8 != (Object)null)
				{
					Vector4 border = val8.border;
					if (((Vector4)(ref border)).sqrMagnitude > 0f)
					{
						val7.sprite = val8;
						val7.type = (Type)1;
						((Graphic)val7).color = new Color(colour.r, colour.g, colour.b, 0.95f);
						goto IL_033e;
					}
				}
				((Graphic)val7).color = new Color(colour.r, colour.g, colour.b, 0f);
				Outline obj = ((Component)val6).gameObject.AddComponent<Outline>();
				((Shadow)obj).effectColor = new Color(colour.r, colour.g, colour.b, 0.9f);
				((Shadow)obj).effectDistance = new Vector2(2f, -2f);
				goto IL_033e;
			}
			goto IL_034e;
			IL_033e:
			((Transform)val6).SetAsFirstSibling();
			edge2 = ((Component)val6).gameObject;
			goto IL_034e;
			IL_034e:
			UiButtonTint uiButtonTint = ((Component)val3).gameObject.AddComponent<UiButtonTint>();
			uiButtonTint.Target = val3;
			uiButtonTint.Label = val5;
			uiButtonTint.Colour = colour;
			uiButtonTint.Edge = edge2;
			labelOut = val5;
			return val3;
		}

		internal static void ClickSound()
		{
			//IL_0041: 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)
			GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab("sfx_gui_button") : null);
			if ((Object)(object)val != (Object)null && (Object)(object)Utils.GetMainCamera() != (Object)null)
			{
				Object.Instantiate<GameObject>(val, ((Component)Utils.GetMainCamera()).transform.position, Quaternion.identity);
			}
		}

		internal static Sprite FlatSprite()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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_007e: 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)
			if ((Object)(object)flat != (Object)null)
			{
				return flat;
			}
			Texture2D val = new Texture2D(4, 4, (TextureFormat)4, false)
			{
				hideFlags = (HideFlags)61
			};
			Color32[] array = (Color32[])(object)new Color32[16];
			for (int i = 0; i < 16; i++)
			{
				array[i] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
			}
			val.SetPixels32(array);
			val.Apply(false, true);
			flat = Sprite.Create(val, new Rect(0f, 0f, 4f, 4f), new Vector2(0.5f, 0.5f), 100f);
			((Object)flat).hideFlags = (HideFlags)61;
			return flat;
		}
	}
	public sealed class UiButtonTint : MonoBehaviour
	{
		public Button Target;

		public TMP_Text Label;

		public Color Colour;

		public GameObject Edge;

		private void Update()
		{
			//IL_004e: 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)
			if (!((Object)(object)Target == (Object)null))
			{
				bool interactable = ((Selectable)Target).interactable;
				if ((Object)(object)Label != (Object)null)
				{
					((Graphic)Label).color = (Color)(interactable ? Colour : new Color(0.5f, 0.48f, 0.45f, 1f));
				}
				if ((Object)(object)Edge != (Object)null && Edge.activeSelf != interactable)
				{
					Edge.SetActive(interactable);
				}
			}
		}
	}
}
namespace AdvancedEquipment
{
	internal static class Assets
	{
		internal static GameObject Storage;

		internal static readonly List<GameObject> ItemPrefabs = new List<GameObject>();

		internal static readonly List<Object> Owned = new List<Object>();

		internal static void CreateStorage(ZNetScene scene)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			Release();
			Storage = new GameObject("Advanced Equipment storage");
			Storage.SetActive(false);
			Storage.transform.SetParent(((Component)scene).transform, false);
		}

		internal static void Release()
		{
			if (ItemPrefabs.Count > 0 && (Object)(object)ObjectDB.instance != (Object)null && ObjectDB.instance.m_items != null)
			{
				ObjectDB.instance.m_items.RemoveAll((GameObject i) => (Object)(object)i == (Object)null || ItemPrefabs.Contains(i));
			}
			ItemPrefabs.Clear();
			foreach (Object item in Owned)
			{
				if (item != (Object)null)
				{
					Object.Destroy(item);
				}
			}
			Owned.Clear();
			if ((Object)(object)Storage != (Object)null)
			{
				Object.Destroy((Object)(object)Storage);
			}
			Storage = null;
		}

		internal static void RegisterScene(ZNetScene scene, GameObject prefab)
		{
			Prefabs.RegisterScene(scene, prefab);
		}

		internal static GameObject Need(ZNetScene scene, string name)
		{
			return scene.GetPrefab(name) ?? throw new InvalidOperationException("Prefab missing: " + name);
		}

		internal static void RegisterItems(ObjectDB db)
		{
			if ((Object)(object)db == (Object)null || db.m_items == null || ItemPrefabs.Count == 0)
			{
				return;
			}
			bool flag = false;
			foreach (GameObject itemPrefab in ItemPrefabs)
			{
				if ((Object)(object)itemPrefab != (Object)null && !db.m_items.Contains(itemPrefab))
				{
					db.m_items.Add(itemPrefab);
					flag = true;
				}
			}
			if (!flag)
			{
				return;
			}
			try
			{
				AccessTools.Method(typeof(ObjectDB), "UpdateRegisters", (Type[])null, (Type[])null).Invoke(db, null);
			}
			catch (Exception ex)
			{
				AdvancedEquipmentPlugin.Log.LogError((object)("ObjectDB.UpdateRegisters failed: " + ex));
			}
		}

		internal static Stream Resource(string name)
		{
			return Assembly.GetExecutingAssembly().GetManifestResourceStream("advancedequipment." + name) ?? throw new FileNotFoundException("Embedded resource missing: " + name);
		}

		private static byte[] Bytes(string resource)
		{
			using Stream stream = Resource(resource);
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return memoryStream.ToArray();
		}

		internal static Texture2D LoadTexture(string resource)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true);
			if (!ImageConversion.LoadImage(val, Bytes(resource)))
			{
				throw new InvalidDataException(resource);
			}
			((Object)val).name = "AE " + resource;
			((Texture)val).wrapMode = (TextureWrapMode)1;
			Owned.Add((Object)(object)val);
			return val;
		}

		internal static Sprite LoadIcon(string resource)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_0054: 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)
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			if (!ImageConversion.LoadImage(val, Bytes(resource)))
			{
				throw new InvalidDataException(resource);
			}
			((Object)val).name = "AE " + resource;
			Owned.Add((Object)(object)val);
			Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			Owned.Add((Object)(object)val2);
			return val2;
		}

		internal static void ReadMeshes(string resource, out Mesh visual, out Mesh collision)
		{
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Expected O, but got Unknown
			//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_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Expected O, but got Unknown
			BinaryReader reader = new BinaryReader(Resource(resource));
			try
			{
				if (Encoding.ASCII.GetString(reader.ReadBytes(8)) != "COAHS100")
				{
					throw new InvalidDataException(resource + ": bad header");
				}
				int num = reader.ReadInt32();
				int arg = reader.ReadInt32();
				int arg2 = reader.ReadInt32();
				int arg3 = reader.ReadInt32();
				Func<int, Vector3[]> func = delegate(int count)
				{
					//IL_002e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0033: Unknown result type (might be due to invalid IL or missing references)
					Vector3[] array2 = (Vector3[])(object)new Vector3[count];
					for (int i = 0; i < count; i++)
					{
						array2[i] = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
					}
					return array2;
				};
				Func<int, int[]> func2 = delegate(int count)
				{
					int[] array2 = new int[count];
					for (int i = 0; i < count; i++)
					{
						array2[i] = reader.ReadInt32();
					}
					return array2;
				};
				Vector3[] vertices = func(num);
				Vector3[] normals = func(num);
				Vector2[] array = (Vector2[])(object)new Vector2[num];
				for (int num2 = 0; num2 < num; num2++)
				{
					array[num2] = new Vector2(reader.ReadSingle(), reader.ReadSingle());
				}
				visual = new Mesh
				{
					name = "AE " + resource
				};
				if (num > 65000)
				{
					visual.indexFormat = (IndexFormat)1;
				}
				visual.vertices = vertices;
				visual.normals = normals;
				visual.uv = array;
				visual.triangles = func2(arg);
				visual.RecalculateBounds();
				visual.RecalculateTangents();
				collision = new Mesh
				{
					name = "AE " + resource + " collider",
					vertices = func(arg2),
					triangles = func2(arg3)
				};
				collision.RecalculateBounds();
				collision.RecalculateNormals();
				Owned.Add((Object)(object)visual);
				Owned.Add((Object)(object)collision);
			}
			finally
			{
				if (reader != null)
				{
					((IDisposable)reader).Dispose();
				}
			}
		}

		internal static void AddGlow(Material material, string resource)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val;
			try
			{
				val = LoadTexture(resource);
			}
			catch (FileNotFoundException)
			{
				return;
			}
			catch (Exception ex2)
			{
				AdvancedEquipmentPlugin.Log.LogWarning((object)("Advanced Equipment: the glow " + resource + " could not be loaded: " + ex2.Message));
				return;
			}
			if (material.HasProperty("_EmissionMap"))
			{
				material.SetTexture("_EmissionMap", (Texture)(object)val);
			}
			if (material.HasProperty("_EmissionColor"))
			{
				material.SetColor("_EmissionColor", new Color(1.35f, 1.35f, 1.35f, 1f));
			}
			material.EnableKeyword("_EMISSION");
		}

		private static void SetTexture(Material m, string name, Texture t)
		{
			if (m.HasProperty(name))
			{
				m.SetTexture(name, t);
			}
		}

		private static void SetFloat(Material m, string name, float v)
		{
			if (m.HasProperty(name))
			{
				m.SetFloat(name, v);
			}
		}

		internal static Material Surface(string colour)
		{
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Expected O, but got Unknown
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Expected O, but got Unknown
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			ZNetScene instance = ZNetScene.instance;
			GameObject prefab = instance.GetPrefab("StoneGolem");
			GameObject val = Need(instance, "JotunWarrior");
			Material val2 = (from r in val.GetComponentsInChildren<SkinnedMeshRenderer>(true)
				where ((Object)r).name == "bodymale"
				select ((Renderer)r).sharedMaterial).FirstOrDefault((Func<Material, bool>)((Material m) => (Object)(object)m != (Object)null)) ?? (from r in val.GetComponentsInChildren<SkinnedMeshRenderer>(true)
				select ((Renderer)r).sharedMaterial).FirstOrDefault((Func<Material, bool>)((Material m) => (Object)(object)m != (Object)null));
			if ((Object)(object)val2 == (Object)null && (Object)(object)prefab != (Object)null)
			{
				val2 = (from r in prefab.GetComponentsInChildren<SkinnedMeshRenderer>(true)
					select ((Renderer)r).sharedMaterial).FirstOrDefault((Func<Material, bool>)((Material m) => (Object)(object)m != (Object)null));
			}
			Material val3 = (((Object)(object)val2 != (Object)null) ? new Material(val2) : new Material(Shader.Find("Standard") ?? Shader.Find("Diffuse")));
			((Object)val3).name = "AE " + colour;
			Owned.Add((Object)(object)val3);
			Texture2D val4 = new Texture2D(2, 2, (TextureFormat)4, true);
			if (!ImageConversion.LoadImage(val4, Bytes(colour)))
			{
				throw new InvalidDataException(colour);
			}
			((Object)val4).name = "AE " + colour;
			((Texture)val4).wrapMode = (TextureWrapMode)1;
			((Texture)val4).filterMode = (FilterMode)1;
			((Texture)val4).anisoLevel = 4;
			try
			{
				val4.Compress(false);
				val4.Apply(false, true);
			}
			catch (Exception ex)
			{
				AdvancedEquipmentPlugin.Log.LogWarning((object)("Texture compression skipped for " + colour + ": " + ex.Message));
			}
			Owned.Add((Object)(object)val4);
			val3.mainTexture = (Texture)(object)val4;
			val3.color = Color.white;
			SetTexture(val3, "_MetallicGlossMap", null);
			SetTexture(val3, "_EmissionMap", null);
			val3.DisableKeyword("_METALLICGLOSSMAP");
			val3.DisableKeyword("_EMISSION");
			SetFloat(val3, "_Metallic", 0f);
			SetFloat(val3, "_MetalGloss", 0f);
			SetFloat(val3, "_Glossiness", 0.06f);
			SetFloat(val3, "_GlossMapScale", 0.06f);
			SetFloat(val3, "_UseGlossmap", 0f);
			SetFloat(val3, "_Hue", 0f);
			SetFloat(val3, "_Saturation", 0f);
			SetFloat(val3, "_Value", 0f);
			if (val3.HasProperty("_EmissionColor"))
			{
				val3.SetColor("_EmissionColor", Color.black);
			}
			return val3;
		}
	}
	internal static class BackpackSlot
	{
		private sealed class Holder
		{
			internal ItemData Item;
		}

		[HarmonyPatch(typeof(Humanoid), "EquipItem")]
		internal static class EquipPatch
		{
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				List<CodeInstruction> list = instructions.ToList();
				int num = list.Count((CodeInstruction c) => CodeInstructionExtensions.LoadsField(c, Utility, false));
				int num2 = list.Count((CodeInstruction c) => CodeInstructionExtensions.StoresField(c, Utility));
				if (num != 1 || num2 != 1)
				{
					throw new InvalidOperationException("Humanoid.EquipItem reads m_utilityItem " + num + " time(s) and writes it " + num2 + " time(s): the backpack slot is not installed.");
				}
				MethodInfo get = AccessTools.Method(typeof(BackpackSlot), "Get", (Type[])null, (Type[])null);
				MethodInfo set = AccessTools.Method(typeof(BackpackSlot), "Set", (Type[])null, (Type[])null);
				foreach (CodeInstruction item in list)
				{
					if (CodeInstructionExtensions.LoadsField(item, Utility, false))
					{
						CodeInstruction val = new CodeInstruction(OpCodes.Ldarg_1, (object)null);
						val.labels.AddRange(item.labels);
						val.blocks.AddRange(item.blocks);
						yield return val;
						yield return new CodeInstruction(OpCodes.Call, (object)get);
					}
					else if (CodeInstructionExtensions.StoresField(item, Utility))
					{
						item.opcode = OpCodes.Call;
						item.operand = set;
						yield return item;
					}
					else
					{
						yield return item;
					}
				}
			}
		}

		[HarmonyPatch(typeof(Humanoid), "IsItemEquiped")]
		internal static class EquippedPatch
		{
			private static void Postfix(Humanoid __instance, ItemData item, ref bool __result)
			{
				if (!__result && item != null && Worn(__instance) == item)
				{
					__result = true;
				}
			}
		}

		[HarmonyPatch(typeof(Humanoid), "UnequipItem")]
		internal static class UnequipPatch
		{
			private static void Postfix(Humanoid __instance, ItemData item)
			{
				Clear(__instance, item);
			}
		}

		[HarmonyPatch(typeof(Humanoid), "UnequipAllItems")]
		internal static class UnequipAllPatch
		{
			private static void Postfix(Humanoid __instance)
			{
				__instance.UnequipItem(Worn(__instance), false);
			}
		}

		[HarmonyPatch(typeof(Player), "UnequipDeathDropItems")]
		internal static class DeathPatch
		{
			private static void Prefix(Player __instance)
			{
				((Humanoid)__instance).UnequipItem(Worn((Humanoid)(object)__instance), false);
			}
		}

		[HarmonyPatch(typeof(Player), "OnInventoryChanged")]
		internal static class InventoryPatch
		{
			private static void Postfix(Player __instance)
			{
				ItemData val = Worn((Humanoid)(object)__instance);
				if (val != null && !((Humanoid)__instance).GetInventory().ContainsItem(val))
				{
					Clear((Humanoid)(object)__instance, val);
				}
			}
		}

		internal const string Field = "backpack";

		private static readonly string[] Mods = new string[2] { "p0kahontazz.advancedbackpacks", "p0kahontazz.coah" };

		private static readonly FieldInfo Utility = AccessTools.Field(typeof(Humanoid), "m_utilityItem");

		private static readonly ConditionalWeakTable<Humanoid, Holder> held = new ConditionalWeakTable<Humanoid, Holder>();

		private static bool? present;

		internal static bool Present
		{
			get
			{
				if (!present.HasValue)
				{
					present = Mods.Any((string id) => Chainloader.PluginInfos.ContainsKey(id));
				}
				return present.Value;
			}
		}

		internal static ItemData Worn(Humanoid humanoid)
		{
			if (!((Object)(object)humanoid != (Object)null) || !held.TryGetValue(humanoid, out var value))
			{
				return null;
			}
			return value.Item;
		}

		private static void Clear(Humanoid humanoid, ItemData item)
		{
			if (item != null && (Object)(object)humanoid != (Object)null && held.TryGetValue(humanoid, out var value) && value.Item == item)
			{
				value.Item = null;
			}
		}

		private static ItemData Get(Humanoid humanoid, ItemData item)
		{
			if (!Slots.IsBackpack(item))
			{
				object? value = Utility.GetValue(humanoid);
				return (ItemData)((value is ItemData) ? value : null);
			}
			return Worn(humanoid);
		}

		private static void Set(Humanoid humanoid, ItemData item)
		{
			if (Slots.IsBackpack(item))
			{
				held.GetOrCreateValue(humanoid).Item = item;
			}
			else
			{
				Utility.SetValue(humanoid, item);
			}
		}
	}
	internal static class Items
	{
		internal const string BeltPrefix = "AdvancedBelt";

		internal const string QuiverPrefix = "AdvancedQuiver";

		internal static void Register(ZNetScene scene)
		{
			GameObject storage = Assets.Storage ?? throw new InvalidOperationException("Advanced Equipment storage missing.");
			string[] array = new string[3] { "Iron Belt", "Silver Belt", "Black Metal Belt" };
			string[] array2 = new string[3] { "belt3", "belt1", "belt2" };
			string[] array3 = new string[3] { "Basic Quiver", "Enhanced Quiver", "Superior Quiver" };
			string[] array4 = new string[3] { "A belt of riveted iron plates. Worn in the Utility slot of the equipment panel it carries two accessories: trinkets, utility items and keys.", "A belt of polished silver, edged with engraved lines and rivets. Carries three accessories: trinkets, utility items and keys.", "A belt of black metal with a horned clasp, green runes and two eyes that glow. Carries four accessories: trinkets, utility items and keys." };
			string[] array5 = new string[3] { "A slim leather quiver on a strap. Worn in the Quiver slot of the equipment panel it holds two stacks of 100 arrows or bolts.", "A quiver with a belted flap and a stitched pocket. Holds three stacks of 100 arrows or bolts.", "A broad quiver of dark leather, studded and flapped. Holds three stacks of 100 arrows or bolts, and the ammunition in it weighs half." };
			Slots.BeltByName.Clear();
			Slots.QuiverByName.Clear();
			for (int i = 0; i < 3; i++)
			{
				Add(scene, storage, "AdvancedBelt" + (i + 1), array2[i], array[i], array4[i]);
				Slots.BeltByName[array[i]] = i + 1;
				Add(scene, storage, "AdvancedQuiver" + (i + 1), "quiver" + (i + 1), array3[i], array5[i]);
				Slots.QuiverByName[array3[i]] = i + 1;
			}
			Assets.RegisterItems(ObjectDB.instance);
			Recipes.Build(scene);
			Recipes.Register(ObjectDB.instance);
		}

		private static void Add(ZNetScene scene, GameObject storage, string prefabName, string res, string name, string description)
		{
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Expected O, but got Unknown
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Expected O, but got Unknown
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				GameObject val = Assets.Need(scene, "Ruby");
				GameObject val2 = Object.Instantiate<GameObject>(val, storage.transform, false);
				((Object)val2).name = prefabName;
				for (int num = val2.transform.childCount - 1; num >= 0; num--)
				{
					Object.DestroyImmediate((Object)(object)((Component)val2.transform.GetChild(num)).gameObject);
				}
				Renderer[] components = val2.GetComponents<Renderer>();
				for (int i = 0; i < components.Length; i++)
				{
					Object.DestroyImmediate((Object)(object)components[i]);
				}
				MeshFilter[] components2 = val2.GetComponents<MeshFilter>();
				for (int i = 0; i < components2.Length; i++)
				{
					Object.DestroyImmediate((Object)(object)components2[i]);
				}
				Collider[] components3 = val2.GetComponents<Collider>();
				for (int i = 0; i < components3.Length; i++)
				{
					Object.DestroyImmediate((Object)(object)components3[i]);
				}
				LODGroup[] components4 = val2.GetComponents<LODGroup>();
				for (int i = 0; i < components4.Length; i++)
				{
					Object.DestroyImmediate((Object)(object)components4[i]);
				}
				Assets.ReadMeshes(res + ".bin", out var visual, out var _);
				GameObject val3 = new GameObject("attach");
				val3.transform.SetParent(val2.transform, false);
				val3.AddComponent<MeshFilter>().sharedMesh = visual;
				Material val4 = Assets.Surface(res + ".jpg");
				Assets.AddGlow(val4, res + "_glow.png");
				string[] array = new string[2] { "_Glossiness", "_MetalGloss" };
				foreach (string text in array)
				{
					if (val4.HasProperty(text))
					{
						val4.SetFloat(text, 0.12f);
					}
				}
				if (val4.HasProperty("_Metallic"))
				{
					val4.SetFloat("_Metallic", 0f);
				}
				((Renderer)val3.AddComponent<MeshRenderer>()).sharedMaterial = val4;
				BoxCollider obj = val2.AddComponent<BoxCollider>();
				Bounds bounds = visual.bounds;
				obj.center = ((Bounds)(ref bounds)).center;
				bounds = visual.bounds;
				obj.size = Vector3.Max(((Bounds)(ref bounds)).size, new Vector3(0.06f, 0.04f, 0.06f));
				ItemDrop component = val2.GetComponent<ItemDrop>();
				ItemDrop component2 = val.GetComponent<ItemDrop>();
				component.m_itemData = component2.m_itemData.Clone();
				SharedData val5 = (SharedData)AccessTools.Method(typeof(object), "MemberwiseClone", (Type[])null, (Type[])null).Invoke(component2.m_itemData.m_shared, null);
				val5.m_name = name;
				val5.m_description = description;
				val5.m_icons = (Sprite[])(object)new Sprite[1] { Assets.LoadIcon(res + "_icon.png") };
				val5.m_weight = 1f;
				val5.m_maxStackSize = 1;
				val5.m_value = 0;
				val5.m_itemType = (ItemType)16;
				val5.m_maxQuality = 1;
				val5.m_armor = 0f;
				val5.m_equipDuration = 1f;
				val5.m_teleportable = true;
				component.m_itemData.m_shared = val5;
				component.m_itemData.m_dropPrefab = val2;
				Assets.ItemPrefabs.Add(val2);
				Assets.RegisterScene(scene, val2);
			}
			catch (Exception ex)
			{
				AdvancedEquipmentPlugin.Log.LogError((object)("Advanced Equipment item " + prefabName + " failed: " + ex));
			}
		}
	}
	internal static class Lantern
	{
		[HarmonyPatch(typeof(Player), "Awake")]
		internal static class PlayerAwakePatch
		{
			private static void Postfix(Player __instance)
			{
				if ((Object)(object)((Component)__instance).GetComponent<HipLantern>() == (Object)null)
				{
					((Component)__instance).gameObject.AddComponent<HipLantern>();
				}
			}
		}

		internal const string Prefab = "Lantern";

		internal static int Version;

		private static ConfigEntry<bool> auto;

		private static ConfigEntry<string> bone;

		private static ConfigEntry<Vector3> offset;

		private static ConfigEntry<Vector3> rotation;

		private static ConfigEntry<float> scale;

		private static ConfigEntry<float> tilt;

		internal static bool AutoLight => auto.Value;

		internal static string Bone => bone.Value;

		internal static Vector3 Offset => offset.Value;

		internal static Vector3 Rotation => rotation.Value;

		internal static float Scale => scale.Value;

		internal static float Tilt => tilt.Value;

		internal static void Init(ConfigFile config)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			auto = config.Bind<bool>("Lantern", "OnlyInDark", false, "True: the belt lantern lights only when it is dark (at night, indoors in dungeons and caves, in the Mistlands). False: it is lit all the time, like the one held in the hand.");
			bone = config.Bind<string>("Lantern", "HipBone", "Hips", "The skeleton bone the lantern hangs from.");
			offset = config.Bind<Vector3>("Lantern", "Offset", new Vector3(0.13f, 0.25f, 0.12f), "Where the lantern hangs, in meters from the bone (applied live).");
			rotation = config.Bind<Vector3>("Lantern", "Rotation", Vector3.zero, "Rotation of the hook relative to the bone, in degrees (applied live).");
			scale = config.Bind<float>("Lantern", "Size", 0.45f, "Size of the lantern model (applied live; 0.3 was the size before it was made 50% bigger).");
			tilt = config.Bind<float>("Lantern", "Tilt", 30f, "How many degrees the lantern leans out from the body.");
			bone.SettingChanged += delegate
			{
				Version++;
			};
			offset.SettingChanged += delegate
			{
				Version++;
			};
			rotation.SettingChanged += delegate
			{
				Version++;
			};
			scale.SettingChanged += delegate
			{
				Version++;
			};
		}
	}
	internal sealed class HipLantern : MonoBehaviour
	{
		private static readonly int HangKey = StringExtensionMethods.GetStableHashCode("AE.Lantern");

		private static readonly int LitKey = StringExtensionMethods.GetStableHashCode("AE.LanternLit");

		private Player player;

		private ZNetView nview;

		private GameObject hook;

		private Transform lightRoot;

		private int shownVersion;

		private float nextCheck;

		private void Awake()
		{
			player = ((Component)this).GetComponent<Player>();
			nview = ((Component)this).GetComponent<ZNetView>();
		}

		private void Update()
		{
			if (Time.time < nextCheck)
			{
				return;
			}
			nextCheck = Time.time + 0.25f;
			if ((Object)(object)nview == (Object)null || !nview.IsValid())
			{
				return;
			}
			ZDO zDO = nview.GetZDO();
			bool flag;
			bool flag2;
			if (nview.IsOwner())
			{
				flag = (Object)(object)player == (Object)(object)Player.m_localPlayer && Wanted();
				flag2 = flag && Dark();
				if (zDO.GetInt(HangKey, 0) != (flag ? 1 : 0))
				{
					zDO.Set(HangKey, flag ? 1 : 0, false);
				}
				if (zDO.GetInt(LitKey, 0) != (flag2 ? 1 : 0))
				{
					zDO.Set(LitKey, flag2 ? 1 : 0, false);
				}
			}
			else
			{
				flag = zDO.GetInt(HangKey, 0) != 0;
				flag2 = zDO.GetInt(LitKey, 0) != 0;
			}
			if (flag != ((Object)(object)hook != (Object)null) || Lantern.Version != shownVersion)
			{
				Show(flag);
			}
			if ((Object)(object)lightRoot != (Object)null && ((Component)lightRoot).gameObject.activeSelf != flag2)
			{
				((Component)lightRoot).gameObject.SetActive(flag2);
			}
		}

		private bool Wanted()
		{
			if (((Character)player).IsDead() || ((Character)player).IsSwimming() || ((Character)player).InBed())
			{
				return false;
			}
			return Slots.Carried().Any(Slots.IsLantern);
		}

		private bool Dark()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			if (Lantern.AutoLight && EnvMan.IsDaylight() && !((Character)player).InInterior())
			{
				return (int)player.GetCurrentBiome() == 512;
			}
			return true;
		}

		private void Show(bool on)
		{
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Expected O, but got Unknown
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: 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)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Expected O, but got Unknown
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			Unhang();
			shownVersion = Lantern.Version;
			if (!on || (Object)(object)ObjectDB.instance == (Object)null)
			{
				return;
			}
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("Lantern");
			Transform val = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.transform.Find("attach") : null);
			Transform val2 = FindBone();
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				AdvancedEquipmentPlugin.Log.LogWarning((object)("Advanced Equipment: the belt lantern cannot be shown (model " + ((Object)(object)val != (Object)null) + ", bone '" + Lantern.Bone + "' " + ((Object)(object)val2 != (Object)null) + ")."));
				return;
			}
			hook = new GameObject("AE_Lantern");
			Vector3 lossyScale = val2.lossyScale;
			Vector3 val3 = default(Vector3);
			((Vector3)(ref val3))..ctor(1f / lossyScale.x, 1f / lossyScale.y, 1f / lossyScale.z);
			hook.transform.SetParent(val2, false);
			hook.transform.localScale = val3;
			hook.transform.localPosition = Vector3.Scale(Lantern.Offset, val3);
			hook.transform.localRotation = Quaternion.Euler(Lantern.Rotation);
			GameObject val4 = Object.Instantiate<GameObject>(((Component)val).gameObject, hook.transform, false);
			val4.SetActive(true);
			val4.transform.localPosition = Vector3.zero;
			val4.transform.localRotation = Quaternion.identity;
			val4.transform.localScale = val.localScale * Lantern.Scale;
			Collider[] componentsInChildren = val4.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].enabled = false;
			}
			Transform val5 = val4.transform.Find("equiped");
			if ((Object)(object)val5 != (Object)null)
			{
				((Component)val5).gameObject.SetActive(true);
				Rigidbody component = ((Component)val5).GetComponent<Rigidbody>();
				if ((Object)(object)component != (Object)null && !component.isKinematic)
				{
					LanternSwing lanternSwing = ((Component)val5).gameObject.AddComponent<LanternSwing>();
					lanternSwing.Player = ((Component)this).transform;
					lanternSwing.Hook = hook.transform;
				}
			}
			Transform val6 = Find(val4.transform, "flare");
			if ((Object)(object)val6 != (Object)null)
			{
				((Component)val6).gameObject.SetActive(false);
			}
			lightRoot = Find(val4.transform, "Point Light");
			if ((Object)(object)lightRoot == (Object)null)
			{
				GameObject val7 = new GameObject("Point Light");
				val7.transform.SetParent(((Object)(object)val5 != (Object)null) ? val5 : val4.transform, false);
				lightRoot = val7.transform;
			}
			MonoBehaviour[] components = ((Component)lightRoot).GetComponents<MonoBehaviour>();
			for (int i = 0; i < components.Length; i++)
			{
				Object.Destroy((Object)(object)components[i]);
			}
			Light obj = ((Component)lightRoot).GetComponent<Light>() ?? ((Component)lightRoot).gameObject.AddComponent<Light>();
			obj.type = (LightType)2;
			obj.range = 8f;
			obj.intensity = 1.5f;
			obj.color = new Color(1f, 0.78f, 0.29f);
			obj.shadows = (LightShadows)2;
			((Behaviour)obj).enabled = true;
			((Component)lightRoot).gameObject.SetActive(false);
		}

		private Transform FindBone()
		{
			VisEquipment visEquipment = ((Humanoid)player).GetVisEquipment();
			Transform val = ((IEnumerable<Transform>)(((Object)(object)visEquipment != (Object)null && (Object)(object)visEquipment.m_bodyModel != (Object)null) ? ((Array)visEquipment.m_bodyModel.bones) : ((Array)new Transform[0]))).FirstOrDefault((Func<Transform, bool>)((Transform b) => (Object)(object)b != (Object)null && ((Object)b).name == Lantern.Bone));
			if (!((Object)(object)val != (Object)null))
			{
				return Find(((Component)this).transform, Lantern.Bone);
			}
			return val;
		}

		private static Transform Find(Transform root, string name)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			foreach (Transform item in root)
			{
				Transform val = item;
				if (((Object)val).name == name)
				{
					return val;
				}
				Transform val2 = Find(val, name);
				if ((Object)(object)val2 != (Object)null)
				{
					return val2;
				}
			}
			return null;
		}

		private void Unhang()
		{
			lightRoot = null;
			if ((Object)(object)hook != (Object)null)
			{
				Object.Destroy((Object)(object)hook);
				hook = null;
			}
		}

		private void OnDestroy()
		{
			Unhang();
		}
	}
	internal sealed class LanternSwing : MonoBehaviour
	{
		internal Transform Player;

		internal Transform Hook;

		private Rigidbody body;

		private void Awake()
		{
			body = ((Component)this).GetComponent<Rigidbody>();
		}

		private void FixedUpdate()
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)body == (Object)null) && !body.isKinematic && !((Object)(object)Player == (Object)null) && !((Object)(object)Hook == (Object)null))
			{
				body.useGravity = Lantern.Tilt <= 0f;
				if (!(Lantern.Tilt <= 0f))
				{
					float num = Mathf.Sign(Vector3.Dot(Hook.position - Player.position, Player.right));
					float num2 = Lantern.Tilt * ((float)Math.PI / 180f);
					Rigidbody obj = body;
					Vector3 gravity = Physics.gravity;
					obj.AddForce(((Vector3)(ref gravity)).magnitude * (Mathf.Cos(num2) * Vector3.down + Mathf.Sin(num2) * num * Player.right), (ForceMode)5);
				}
			}
		}
	}
	internal static class Panel
	{
		private sealed class Cell
		{
			internal GameObject go;

			internal RectTransform rt;

			internal InventoryElement el;

			internal Image back;

			internal TMP_Text hint;

			internal ItemData lastItem;

			internal int lastStack;

			internal int lastDur;

			internal int x;

			internal int y;

			internal bool view;

			internal bool small;

			internal string field;

			internal Func<ItemData, bool> fits;

			internal string kind;

			internal string lastTip;
		}

		[HarmonyPatch(typeof(InventoryGui), "Update")]
		internal static class UpdatePatch
		{
			private static bool failed;

			private static Exception Finalizer(InventoryGui __instance, Exception __exception)
			{
				if (InventoryGui.IsVisible())
				{
					try
					{
						Tick(__instance);
					}
					catch (Exception ex)
					{
						if (!failed)
						{
							failed = true;
							AdvancedEquipmentPlugin.Log.LogError((object)("Advanced Equipment panel: " + ex));
						}
					}
				}
				return __exception;
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "OnDestroy")]
		internal static class DestroyPatch
		{
			private static void Postfix()
			{
				root = null;
				body = null;
				column = null;
				frameRt = null;
				foldRt = null;
				foldImage = null;
				hideImage = null;
				dataGrid = null;
				cells.Clear();
				ourButtons.Clear();
				styled = false;
				onSelected = null;
			}
		}

		private const float Slot = 64f;

		private const float Tile = 60f;

		private const float Figure = 56f;

		private const float Pad = 8f;

		private const float BraidTop = 12f;

		private const float BraidH = 10f;

		private const float Head = 28f;

		private const float ButtonSize = 38f;

		private const float GlyphSize = 30f;

		private const float Small = 28f;

		private const float SmallW = 32f;

		private const float FigX = 8f;

		private const float MidBraid = 206f;

		private const float PanelW = 260f;

		private const float AeTop = 220f;

		private const float BotTile = 48.8f;

		private const float BotCell = 44.8f;

		private const float PanelH = 325.6f;

		private const float BraidW = 236f;

		private const float FoodCell = 50f;

		private const float FoodPad = 6f;

		private const float FoodW = 118f;

		private const float FoodH = 174f;

		private const float ColumnX = 266f;

		private const float FoodTop = 44f;

		private const string FoldKey = "AE_BottomOpen";

		private static readonly Color Dim = new Color(0.72f, 0.72f, 0.72f, 1f);

		private static readonly Color Ghost = new Color(0.45f, 0.45f, 0.45f, 0.5f);

		private static readonly Color Burnt = new Color(0.09f, 0.05f, 0.02f, 0.26f);

		private static ConfigEntry<float> offsetX;

		private static ConfigEntry<float> offsetY;

		private static RectTransform root;

		private static RectTransform body;

		private static RectTransform column;

		private static RectTransform frameRt;

		private static Image hideImage;

		private static InventoryGrid dataGrid;

		private static readonly List<Cell> cells = new List<Cell>();

		private static RectTransform foldRt;

		private static Image foldImage;

		private static Sprite spriteLeft;

		private static Sprite spriteRight;

		private static Sprite spriteUp;

		private static Sprite spriteDown;

		private static Sprite faceSprite;

		private static Sprite roundSprite;

		private static Sprite braidSprite;

		private static readonly Dictionary<string, Sprite> pictures = new Dictionary<string, Sprite>();

		private static readonly List<KeyValuePair<Image, Button>> ourButtons = new List<KeyValuePair<Image, Button>>();

		private static bool styled;

		private static float nextStyle;

		private static Action<InventoryGrid, ItemData, Vector2i, Modifier> onSelected;

		private static bool Hidden
		{
			get
			{
				try
				{
					return PlayerPrefs.GetInt("AE_PanelHidden", 0) == 1;
				}
				catch
				{
					return false;
				}
			}
			set
			{
				try
				{
					PlayerPrefs.SetInt("AE_PanelHidden", value ? 1 : 0);
					PlayerPrefs.Save();
				}
				catch
				{
				}
			}
		}

		internal static void Init(ConfigFile config)
		{
			offsetX = config.Bind<float>("Panel", "OffsetX", 0f, "Moves the panel to the right (pixels) from where the Extra Slots mod puts its own: 100 px right of the inventory.");
			offsetY = config.Bind<float>("Panel", "OffsetY", 0f, "Moves the panel down (pixels).");
		}

		private static bool Open(string key)
		{
			try
			{
				return PlayerPrefs.GetInt(key, 1) == 1;
			}
			catch
			{
				return true;
			}
		}

		private static void SetOpen(string key, bool value)
		{
			try
			{
				PlayerPrefs.SetInt(key, value ? 1 : 0);
				PlayerPrefs.Save();
			}
			catch
			{
			}
		}

		private static float Seg(float px, float py, float ax, float ay, float bx, float by)
		{
			float num = bx - ax;
			float num2 = by - ay;
			float num3 = Mathf.Clamp01(((px - ax) * num + (py - ay) * num2) / (num * num + num2 * num2));
			float num4 = ax + num3 * num - px;
			float num5 = ay + num3 * num2 - py;
			return Mathf.Sqrt(num4 * num4 + num5 * num5);
		}

		private static void StyleButtons(InventoryGui gui)
		{
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Expected O, but got Unknown
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			if (styled || Time.unscaledTime < nextStyle || (Object)(object)root == (Object)null)
			{
				return;
			}
			nextStyle = Time.unscaledTime + 1f;
			Button val = null;
			int num = 0;
			Button[] componentsInChildren = ((Component)gui).GetComponentsInChildren<Button>(true);
			foreach (Button val2 in componentsInChildren)
			{
				Image val3 = (Image)(((Object)(object)val2 != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
				RectTransform val4 = (RectTransform)(((Object)(object)val2 != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
				if ((Object)(object)val3 == (Object)null || (Object)(object)val3.sprite == (Object)null || (Object)(object)val4 == (Object)null || ((Component)val2).transform.IsChildOf((Transform)(object)root))
				{
					continue;
				}
				Rect rect = val4.rect;
				if (((Rect)(ref rect)).width < 24f)
				{
					continue;
				}
				rect = val4.rect;
				if (((Rect)(ref rect)).width > 64f)
				{
					continue;
				}
				rect = val4.rect;
				float width = ((Rect)(ref rect)).width;
				rect = val4.rect;
				if (Mathf.Abs(width - ((Rect)(ref rect)).height) > 6f)
				{
					continue;
				}
				int num2 = 0;
				TMP_Text[] componentsInChildren2 = ((Component)val2).GetComponentsInChildren<TMP_Text>(true);
				foreach (TMP_Text val5 in componentsInChildren2)
				{
					if (val5.text != null && val5.text.Trim() == "S")
					{
						num2 = 3;
					}
				}
				Text[] componentsInChildren3 = ((Component)val2).GetComponentsInChildren<Text>(true);
				foreach (Text val6 in componentsInChildren3)
				{
					if (val6.text != null && val6.text.Trim() == "S")
					{
						num2 = 3;
					}
				}
				Image[] componentsInChildren4 = ((Component)val2).GetComponentsInChildren<Image>(true);
				foreach (Image val7 in componentsInChildren4)
				{
					if ((Object)(object)val7 != (Object)(object)val3 && (Object)(object)val7.sprite != (Object)null && ((Object)val7.sprite).name.ToLowerInvariant().Contains("star"))
					{
						num2 = Math.Max(num2, 2);
					}
				}
				if (num2 > num)
				{
					num = num2;
					val = val2;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Image val8 = (Image)((Selectable)val).targetGraphic;
			foreach (KeyValuePair<Image, Button> ourButton in ourButtons)
			{
				Image key = ourButton.Key;
				Button value = ourButton.Value;
				key.sprite = val8.sprite;
				key.type = val8.type;
				key.pixelsPerUnitMultiplier = val8.pixelsPerUnitMultiplier;
				((Graphic)key).color = ((Graphic)val8).color;
				((Graphic)key).material = ((Graphic)val8).material;
				((Selectable)value).transition = ((Selectable)val).transition;
				((Selectable)value).spriteState = ((Selectable)val).spriteState;
				((Selectable)value).colors = ((Selectable)val).colors;
			}
			styled = true;
			AdvancedEquipmentPlugin.Log.LogInfo((object)("Advanced Equipment: the panel's buttons copy the look of '" + ((Object)val).name + "' (sprite " + ((Object)val8.sprite).name + ", " + ((object)val8.type/*cast due to .constrained prefix*/).ToString() + ")."));
		}

		private static Sprite Glyph(bool vertical, bool tipHigh)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: 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_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)1,
				name = "AE glyph",
				hideFlags = (HideFlags)61
			};
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.96f, 0.62f, 0.18f, 1f);
			Color val3 = default(Color);
			((Color)(ref val3))..ctor(0.2f, 0.1f, 0.02f, 1f);
			Color val4 = default(Color);
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num = ((float)j + 0.5f) / 64f;
					float num2 = ((float)i + 0.5f) / 64f;
					float num3 = (tipHigh ? 0.4f : 0.6f);
					float num4 = (tipHigh ? 0.6f : 0.4f);
					float px = (vertical ? num2 : num);
					float py = (vertical ? num : num2);
					float num5 = Mathf.Min(Seg(px, py, num3, 0.3f, num4, 0.5f), Seg(px, py, num4, 0.5f, num3, 0.7f));
					((Color)(ref val4))..ctor(val3.r, val3.g, val3.b, Mathf.Clamp01((0.115f - num5) / 0.02f));
					val.SetPixel(j, i, Color.Lerp(val4, val2, Mathf.Clamp01((0.08f - num5) / 0.02f)));
				}
			}
			val.Apply(false, false);
			Sprite obj = Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 100f);
			((Object)obj).hideFlags = (HideFlags)61;
			return obj;
		}

		private static Sprite Face()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)1,
				name = "AE face",
				hideFlags = (HideFlags)61
			};
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.36f, 0.35f, 0.32f, 1f);
			Color val3 = default(Color);
			((Color)(ref val3))..ctor(0.17f, 0.16f, 0.15f, 1f);
			Color val4 = default(Color);
			((Color)(ref val4))..ctor(0.84f, 0.48f, 0.1f, 1f);
			Color val5 = default(Color);
			((Color)(ref val5))..ctor(0.33f, 0.11f, 0.06f, 1f);
			Color val6 = default(Color);
			((Color)(ref val6))..ctor(0.3f, 0.28f, 0.26f, 1f);
			Color val7 = default(Color);
			((Color)(ref val7))..ctor(0.15f, 0.14f, 0.13f, 1f);
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num = (float)j + 0.5f;
					float num2 = (float)i + 0.5f;
					float num3 = Mathf.Abs(num - 32f) - 26f;
					float num4 = Mathf.Abs(num2 - 32f) - 26f;
					float num5 = Mathf.Max(num3, 0f);
					float num6 = Mathf.Max(num4, 0f);
					float num7 = Mathf.Sqrt(num5 * num5 + num6 * num6) + Mathf.Min(Mathf.Max(num3, num4), 0f) - 6f;
					float num8 = 0f - num7;
					Color val8;
					if (num8 < 4f)
					{
						val8 = ((Mathf.Min(num, 64f - num2) < Mathf.Min(64f - num, num2)) ? val2 : val3);
					}
					else if (num8 < 8f)
					{
						val8 = val4;
					}
					else if (num8 < 10.5f)
					{
						val8 = val5;
					}
					else
					{
						float num9 = Mathf.Clamp01(Mathf.Sqrt((num - 32f) * (num - 32f) + (num2 - 32f) * (num2 - 32f)) / 26.88f);
						val8 = Color.Lerp(val6, val7, num9);
					}
					val8.a = Mathf.Clamp01(0.5f - num7);
					val.SetPixel(j, i, val8);
				}
			}
			val.Apply(false, false);
			Sprite obj = Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 100f);
			((Object)obj).hideFlags = (HideFlags)61;
			return obj;
		}

		private static Sprite RoundBox()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)roundSprite != (Object)null)
			{
				return roundSprite;
			}
			Texture2D val = new Texture2D(32, 32, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)1,
				hideFlags = (HideFlags)61
			};
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.34f, 0.34f, 0.34f, 1f);
			for (int i = 0; i < 32; i++)
			{
				for (int j = 0; j < 32; j++)
				{
					float num = (float)j + 0.5f;
					float num2 = (float)i + 0.5f;
					float num3 = Mathf.Abs(num - 16f) - 5f;
					float num4 = Mathf.Abs(num2 - 16f) - 5f;
					float num5 = Mathf.Max(num3, 0f);
					float num6 = Mathf.Max(num4, 0f);
					float num7 = Mathf.Sqrt(num5 * num5 + num6 * num6) + Mathf.Min(Mathf.Max(num3, num4), 0f) - 11f;
					Color val3 = val2;
					val3.a = Mathf.Clamp01(0.5f - num7);
					val.SetPixel(j, i, val3);
				}
			}
			val.Apply(false, false);
			roundSprite = Sprite.Create(val, new Rect(0f, 0f, 32f, 32f), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0, new Vector4(11f, 11f, 11f, 11f))