Decompiled source of RapidLoadouts v1.0.9

RapidLoadouts.dll

Decompiled 4 months ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using RapidLoadouts;
using RapidLoadouts.UI;
using RapidLoadouts.YAMLStuff;
using ServerSync;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Core.Tokens;
using YamlDotNet.Helpers;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.BufferedDeserialization;
using YamlDotNet.Serialization.BufferedDeserialization.TypeDiscriminators;
using YamlDotNet.Serialization.Converters;
using YamlDotNet.Serialization.EventEmitters;
using YamlDotNet.Serialization.NamingConventions;
using YamlDotNet.Serialization.NodeDeserializers;
using YamlDotNet.Serialization.NodeTypeResolvers;
using YamlDotNet.Serialization.ObjectFactories;
using YamlDotNet.Serialization.ObjectGraphTraversalStrategies;
using YamlDotNet.Serialization.ObjectGraphVisitors;
using YamlDotNet.Serialization.Schemas;
using YamlDotNet.Serialization.TypeInspectors;
using YamlDotNet.Serialization.TypeResolvers;
using YamlDotNet.Serialization.Utilities;
using YamlDotNet.Serialization.ValueDeserializers;

[assembly: AssemblyFileVersion("1.0.9")]
[assembly: Guid("4358610B-F3F4-4843-B7AF-98B7BC60DCDE")]
[assembly: ComVisible(false)]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyProduct("RapidLoadouts")]
[assembly: AssemblyCompany("Azumatt")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyTitle("RapidLoadouts")]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.9.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[<69be36b2-3ccc-45a2-847c-5d774d1ac5fb>Embedded]
	internal sealed class <69be36b2-3ccc-45a2-847c-5d774d1ac5fb>EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[<69be36b2-3ccc-45a2-847c-5d774d1ac5fb>Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class <b19be342-00b0-41d8-bd29-597b2490c5db>NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public <b19be342-00b0-41d8-bd29-597b2490c5db>NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public <b19be342-00b0-41d8-bd29-597b2490c5db>NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[<69be36b2-3ccc-45a2-847c-5d774d1ac5fb>Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class <17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public <17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace Recycle_N_Reclaim.GamePatches
{
	[HarmonyPatch(typeof(ZNet), "OnNewConnection")]
	public static class RegisterAndCheckVersion
	{
		[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(1)]
		private static void Prefix(ZNetPeer peer, ref ZNet __instance)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			RapidLoadoutsPlugin.RapidLoadoutsLogger.LogDebugIfDebug("Registering version RPC handler");
			peer.m_rpc.Register<ZPackage>("RapidLoadouts_VersionCheck", (Action<ZRpc, ZPackage>)RpcHandlers.RPC_Recycle_N_Reclaim_Version);
			RapidLoadoutsPlugin.RapidLoadoutsLogger.LogInfo((object)"Invoking version check");
			ZPackage val = new ZPackage();
			val.Write("1.0.9");
			val.Write(RpcHandlers.ComputeHashForMod().Replace("-", ""));
			peer.m_rpc.Invoke("RapidLoadouts_VersionCheck", new object[1] { val });
		}
	}
	[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(1)]
	[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(0)]
	[HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")]
	public static class VerifyClient
	{
		private static bool Prefix(ZRpc rpc, ZPackage pkg, ref ZNet __instance)
		{
			if (!__instance.IsServer() || RpcHandlers.ValidatedPeers.Contains(rpc))
			{
				return true;
			}
			RapidLoadoutsPlugin.RapidLoadoutsLogger.LogWarning((object)("Peer (" + rpc.m_socket.GetHostName() + ") never sent version or couldn't due to previous disconnect, disconnecting"));
			rpc.Invoke("Error", new object[1] { 3 });
			return false;
		}

		private static void Postfix(ZNet __instance)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "RapidLoadouts_RequestAdminSync", new object[1] { (object)new ZPackage() });
		}
	}
	[HarmonyPatch(typeof(FejdStartup), "ShowConnectError")]
	public class ShowConnectionError
	{
		[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(1)]
		private static void Postfix(FejdStartup __instance)
		{
			if (__instance.m_connectionFailedPanel.activeSelf)
			{
				__instance.m_connectionFailedError.fontSizeMax = 25f;
				__instance.m_connectionFailedError.fontSizeMin = 15f;
				TMP_Text connectionFailedError = __instance.m_connectionFailedError;
				connectionFailedError.text = connectionFailedError.text + "\n" + RapidLoadoutsPlugin.ConnectionError;
			}
		}
	}
	[HarmonyPatch(typeof(ZNet), "Disconnect")]
	public static class RemoveDisconnectedPeerFromVerified
	{
		[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(1)]
		private static void Prefix(ZNetPeer peer, ref ZNet __instance)
		{
			if (__instance.IsServer())
			{
				RapidLoadoutsPlugin.RapidLoadoutsLogger.LogInfo((object)("Peer (" + peer.m_rpc.m_socket.GetHostName() + ") disconnected, removing from validated list"));
				RpcHandlers.ValidatedPeers.Remove(peer.m_rpc);
			}
		}
	}
	[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(1)]
	[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(0)]
	public static class RpcHandlers
	{
		public static readonly List<ZRpc> ValidatedPeers = new List<ZRpc>();

		public static void RPC_Recycle_N_Reclaim_Version(ZRpc rpc, ZPackage pkg)
		{
			string text = pkg.ReadString();
			string text2 = pkg.ReadString();
			string text3 = ComputeHashForMod().Replace("-", "");
			RapidLoadoutsPlugin.RapidLoadoutsLogger.LogInfo((object)("Hash/Version check, local: 1.0.9 " + text3 + " remote: " + text + " " + text2));
			if (text2 != text3 || text != "1.0.9")
			{
				RapidLoadoutsPlugin.ConnectionError = "RapidLoadouts Installed: 1.0.9 " + text3 + "\n Needed: " + text + " " + text2;
				if (ZNet.instance.IsServer())
				{
					RapidLoadoutsPlugin.RapidLoadoutsLogger.LogWarning((object)("Peer (" + rpc.m_socket.GetHostName() + ") has incompatible version, disconnecting..."));
					rpc.Invoke("Error", new object[1] { 3 });
				}
			}
			else if (!ZNet.instance.IsServer())
			{
				RapidLoadoutsPlugin.RapidLoadoutsLogger.LogInfo((object)"Received same version from server!");
			}
			else
			{
				RapidLoadoutsPlugin.RapidLoadoutsLogger.LogInfo((object)("Adding peer (" + rpc.m_socket.GetHostName() + ") to validated list"));
				ValidatedPeers.Add(rpc);
			}
		}

		public static string ComputeHashForMod()
		{
			using SHA256 sHA = SHA256.Create();
			byte[] array = sHA.ComputeHash(File.ReadAllBytes(Assembly.GetExecutingAssembly().Location));
			StringBuilder stringBuilder = new StringBuilder();
			byte[] array2 = array;
			foreach (byte b in array2)
			{
				stringBuilder.Append(b.ToString("X2"));
			}
			return stringBuilder.ToString();
		}
	}
}
namespace RapidLoadouts
{
	[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(1)]
	[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(0)]
	[PublicAPI]
	public class Localizer
	{
		private static readonly Dictionary<string, Dictionary<string, Func<string>>> PlaceholderProcessors;

		private static readonly Dictionary<string, Dictionary<string, string>> loadedTexts;

		private static readonly ConditionalWeakTable<Localization, string> localizationLanguage;

		private static readonly List<WeakReference<Localization>> localizationObjects;

		[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(2)]
		private static BaseUnityPlugin _plugin;

		private static readonly List<string> fileExtensions;

		private static BaseUnityPlugin plugin
		{
			get
			{
				//IL_009b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a5: Expected O, but got Unknown
				if (_plugin == null)
				{
					IEnumerable<TypeInfo> source;
					try
					{
						source = Assembly.GetExecutingAssembly().DefinedTypes.ToList();
					}
					catch (ReflectionTypeLoadException ex)
					{
						source = from t in ex.Types
							where t != null
							select t.GetTypeInfo();
					}
					_plugin = (BaseUnityPlugin)Chainloader.ManagerObject.GetComponent((Type)source.First([<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(0)] (TypeInfo t) => t.IsClass && typeof(BaseUnityPlugin).IsAssignableFrom(t)));
				}
				return _plugin;
			}
		}

		private static void UpdatePlaceholderText(Localization localization, string key)
		{
			localizationLanguage.TryGetValue(localization, out var value);
			string text = loadedTexts[value][key];
			if (PlaceholderProcessors.TryGetValue(key, out var value2))
			{
				text = value2.Aggregate(text, [<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(0)] (string current, KeyValuePair<string, Func<string>> kv) => current.Replace("{" + kv.Key + "}", kv.Value()));
			}
			localization.AddWord(key, text);
		}

		public static void AddPlaceholder<T>(string key, string placeholder, ConfigEntry<T> config, [<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(new byte[] { 2, 1, 1 })] Func<T, string> convertConfigValue = null)
		{
			if (convertConfigValue == null)
			{
				convertConfigValue = (T val) => val.ToString();
			}
			if (!PlaceholderProcessors.ContainsKey(key))
			{
				PlaceholderProcessors[key] = new Dictionary<string, Func<string>>();
			}
			config.SettingChanged += [<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(0)] (object _, EventArgs _) =>
			{
				UpdatePlaceholder();
			};
			if (loadedTexts.ContainsKey(Localization.instance.GetSelectedLanguage()))
			{
				UpdatePlaceholder();
			}
			void UpdatePlaceholder()
			{
				PlaceholderProcessors[key][placeholder] = () => convertConfigValue(config.Value);
				UpdatePlaceholderText(Localization.instance, key);
			}
		}

		public static void AddText(string key, string text)
		{
			List<WeakReference<Localization>> list = new List<WeakReference<Localization>>();
			foreach (WeakReference<Localization> localizationObject in localizationObjects)
			{
				if (localizationObject.TryGetTarget(out var target))
				{
					Dictionary<string, string> dictionary = loadedTexts[localizationLanguage.GetOrCreateValue(target)];
					if (!target.m_translations.ContainsKey(key))
					{
						dictionary[key] = text;
						target.AddWord(key, text);
					}
				}
				else
				{
					list.Add(localizationObject);
				}
			}
			foreach (WeakReference<Localization> item in list)
			{
				localizationObjects.Remove(item);
			}
		}

		public static void Load()
		{
			LoadLocalization(Localization.instance, Localization.instance.GetSelectedLanguage());
		}

		private static void LoadLocalization(Localization __instance, string language)
		{
			if (!localizationLanguage.Remove(__instance))
			{
				localizationObjects.Add(new WeakReference<Localization>(__instance));
			}
			localizationLanguage.Add(__instance, language);
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			foreach (string item in from f in Directory.GetFiles(Path.GetDirectoryName(Paths.PluginPath), plugin.Info.Metadata.Name + ".*", SearchOption.AllDirectories)
				where fileExtensions.IndexOf(Path.GetExtension(f)) >= 0
				select f)
			{
				string text = Path.GetFileNameWithoutExtension(item).Split(new char[1] { '.' })[1];
				if (dictionary.ContainsKey(text))
				{
					Debug.LogWarning((object)("Duplicate key " + text + " found for " + plugin.Info.Metadata.Name + ". The duplicate file found at " + item + " will be skipped."));
				}
				else
				{
					dictionary[text] = item;
				}
			}
			byte[] array = LoadTranslationFromAssembly("English");
			if (array == null)
			{
				throw new Exception("Found no English localizations in mod " + plugin.Info.Metadata.Name + ". Expected an embedded resource translations/English.json or translations/English.yml.");
			}
			Dictionary<string, string> dictionary2 = new DeserializerBuilder().IgnoreFields().Build().Deserialize<Dictionary<string, string>>(Encoding.UTF8.GetString(array));
			if (dictionary2 == null)
			{
				throw new Exception("Localization for mod " + plugin.Info.Metadata.Name + " failed: Localization file was empty.");
			}
			string text2 = null;
			if (language != "English")
			{
				if (dictionary.ContainsKey(language))
				{
					text2 = File.ReadAllText(dictionary[language]);
				}
				else
				{
					byte[] array2 = LoadTranslationFromAssembly(language);
					if (array2 != null)
					{
						text2 = Encoding.UTF8.GetString(array2);
					}
				}
			}
			if (text2 == null && dictionary.ContainsKey("English"))
			{
				text2 = File.ReadAllText(dictionary["English"]);
			}
			if (text2 != null)
			{
				foreach (KeyValuePair<string, string> item2 in new DeserializerBuilder().IgnoreFields().Build().Deserialize<Dictionary<string, string>>(text2) ?? new Dictionary<string, string>())
				{
					dictionary2[item2.Key] = item2.Value;
				}
			}
			loadedTexts[language] = dictionary2;
			foreach (KeyValuePair<string, string> item3 in dictionary2)
			{
				UpdatePlaceholderText(__instance, item3.Key);
			}
		}

		static Localizer()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			PlaceholderProcessors = new Dictionary<string, Dictionary<string, Func<string>>>();
			loadedTexts = new Dictionary<string, Dictionary<string, string>>();
			localizationLanguage = new ConditionalWeakTable<Localization, string>();
			localizationObjects = new List<WeakReference<Localization>>();
			fileExtensions = new List<string> { ".json", ".yml" };
			new Harmony("org.bepinex.helpers.LocalizationManager").Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Localization), "LoadCSV", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Localizer), "LoadLocalization", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		[return: <b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(2)]
		private static byte[] LoadTranslationFromAssembly(string language)
		{
			foreach (string fileExtension in fileExtensions)
			{
				byte[] array = ReadEmbeddedFileBytes("translations." + language + fileExtension);
				if (array != null)
				{
					return array;
				}
			}
			return null;
		}

		[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(2)]
		public static byte[] ReadEmbeddedFileBytes([<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(1)] string resourceFileName, Assembly containingAssembly = null)
		{
			using MemoryStream memoryStream = new MemoryStream();
			if ((object)containingAssembly == null)
			{
				containingAssembly = Assembly.GetCallingAssembly();
			}
			string text = containingAssembly.GetManifestResourceNames().FirstOrDefault([<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(0)] (string str) => str.EndsWith(resourceFileName, StringComparison.Ordinal));
			if (text != null)
			{
				containingAssembly.GetManifestResourceStream(text)?.CopyTo(memoryStream);
			}
			return (memoryStream.Length == 0L) ? null : memoryStream.ToArray();
		}
	}
	[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(0)]
	[BepInPlugin("Azumatt.RapidLoadouts", "RapidLoadouts", "1.0.9")]
	[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(1)]
	public class RapidLoadoutsPlugin : BaseUnityPlugin
	{
		[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(0)]
		public enum Toggle
		{
			On = 1,
			Off = 0
		}

		[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(0)]
		private class ConfigurationManagerAttributes
		{
			public bool? Browsable = false;
		}

		[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(0)]
		private class AcceptableShortcuts : AcceptableValueBase
		{
			public AcceptableShortcuts()
				: base(typeof(KeyboardShortcut))
			{
			}

			public override object Clamp(object value)
			{
				return value;
			}

			public override bool IsValid(object value)
			{
				return true;
			}

			public override string ToDescriptionString()
			{
				return "# Acceptable values: " + string.Join(", ", UnityInput.Current.SupportedKeyCodes);
			}
		}

		internal const string ModName = "RapidLoadouts";

		internal const string ModVersion = "1.0.9";

		internal const string Author = "Azumatt";

		private const string ModGUID = "Azumatt.RapidLoadouts";

		private static string ConfigFileName = "Azumatt.RapidLoadouts.cfg";

		private static string ConfigFileFullPath;

		public static bool HasAuga;

		internal static string ConnectionError;

		private readonly Harmony _harmony = new Harmony("Azumatt.RapidLoadouts");

		private LoadoutsButtonHolder _loadoutsButton;

		public static readonly ManualLogSource RapidLoadoutsLogger;

		private static readonly ConfigSync ConfigSync;

		internal static readonly string yamlFileName;

		internal static readonly string yamlPath;

		internal static readonly CustomSyncedValue<string> AzuRL_yamlData;

		[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(new byte[] { 1, 2 })]
		internal static List<ItemSet> RL_yamlData;

		private static ConfigEntry<Toggle> _serverConfigLocked;

		public static ConfigEntry<string> loadoutCostPrefab;

		public static ConfigEntry<Vector3> InventoryLoadoutButtonPosition;

		public static ConfigEntry<Vector3> LoadoutWindow;

		public void Awake()
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			Localizer.Load();
			_serverConfigLocked = config("1 - General", "Lock Configuration", Toggle.On, "If on, the configuration is locked and can be changed by server admins only.");
			ConfigSync.AddLockingConfigEntry<Toggle>(_serverConfigLocked);
			loadoutCostPrefab = config("1 - General", "LoadoutCostPrefab", "Coins", "Default Currency. This is the fallback currency that will be used when buying Loadouts from the Loadout Window.");
			InventoryLoadoutButtonPosition = config<Vector3>("2 - UI", "LoadoutButtonPosition", new Vector3(63f, -316f, -1f), "The last saved Loadout Button's screen position.");
			LoadoutWindow = config<Vector3>("2 - UI", "LoadoutWindow", new Vector3(428f, -276f, -1f), "The last saved Loadout Window's screen position.");
			if (!File.Exists(yamlPath))
			{
				YAMLUtils.WriteConfigFileFromResource(yamlPath);
			}
			AzuRL_yamlData.ValueChanged += OnValChangedUpdate;
			AzuRL_yamlData.AssignLocalValue(File.ReadAllText(yamlPath));
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			_harmony.PatchAll(executingAssembly);
			SetupWatcher();
		}

		private void Start()
		{
			_loadoutsButton = ((Component)this).gameObject.AddComponent<LoadoutsButtonHolder>();
			if (Chainloader.PluginInfos.ContainsKey("randyknapp.mods.auga"))
			{
				HasAuga = true;
			}
		}

		public static string SanitizeFileName(string fileName)
		{
			return Path.GetInvalidFileNameChars().Aggregate(fileName, [<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(0)] (string current, char c) => current.Replace(c.ToString(), string.Empty));
		}

		private void OnDestroy()
		{
			((BaseUnityPlugin)this).Config.Save();
		}

		private void AutoDoc()
		{
		}

		private void SetupWatcher()
		{
			FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName);
			fileSystemWatcher.Changed += ReadConfigValues;
			fileSystemWatcher.Created += ReadConfigValues;
			fileSystemWatcher.Renamed += ReadConfigValues;
			fileSystemWatcher.IncludeSubdirectories = true;
			fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			fileSystemWatcher.EnableRaisingEvents = true;
			FileSystemWatcher fileSystemWatcher2 = new FileSystemWatcher(Paths.ConfigPath, yamlFileName);
			fileSystemWatcher2.Changed += ReadYamlFiles;
			fileSystemWatcher2.Created += ReadYamlFiles;
			fileSystemWatcher2.Renamed += ReadYamlFiles;
			fileSystemWatcher2.IncludeSubdirectories = true;
			fileSystemWatcher2.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			fileSystemWatcher2.EnableRaisingEvents = true;
		}

		private void ReadConfigValues(object sender, FileSystemEventArgs e)
		{
			if (!File.Exists(ConfigFileFullPath))
			{
				return;
			}
			try
			{
				RapidLoadoutsLogger.LogDebugIfDebug("ReadConfigValues called");
				((BaseUnityPlugin)this).Config.Reload();
			}
			catch
			{
				RapidLoadoutsLogger.LogError((object)("There was an issue loading your " + ConfigFileName));
				RapidLoadoutsLogger.LogError((object)"Please check your config entries for spelling and format!");
			}
		}

		private void ReadYamlFiles(object sender, FileSystemEventArgs e)
		{
			if (!File.Exists(yamlPath))
			{
				return;
			}
			try
			{
				RapidLoadoutsLogger.LogDebugIfDebug("ReadConfigValues called");
				AzuRL_yamlData.AssignLocalValue(File.ReadAllText(yamlPath));
			}
			catch
			{
				RapidLoadoutsLogger.LogError((object)("There was an issue loading your " + yamlFileName));
				RapidLoadoutsLogger.LogError((object)"Please check your entries for spelling and format!");
			}
		}

		private static void OnValChangedUpdate()
		{
			RapidLoadoutsLogger.LogDebugIfDebug("OnValChanged called");
			try
			{
				YAMLUtils.ReadYaml(AzuRL_yamlData.Value);
				ItemSetHelper.AddCreateLoadout(((Object)(object)ItemSets.instance != (Object)null) ? ItemSets.instance : null);
				if ((Object)(object)Player.m_localPlayer != (Object)null && (Object)(object)ItemSets.instance != (Object)null)
				{
					PurchasableLoadoutGui.FillList();
				}
			}
			catch (Exception arg)
			{
				RapidLoadoutsLogger.LogError((object)$"Failed to deserialize {yamlFileName}: {arg}");
			}
		}

		private ConfigEntry<T> config<[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(2)] T>(string group, string name, T value, ConfigDescription description, bool synchronizedSetting = true)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			ConfigDescription val = new ConfigDescription(description.Description + (synchronizedSetting ? " [Synced with Server]" : " [Not Synced with Server]"), description.AcceptableValues, description.Tags);
			ConfigEntry<T> val2 = ((BaseUnityPlugin)this).Config.Bind<T>(group, name, value, val);
			ConfigSync.AddConfigEntry<T>(val2).SynchronizedConfig = synchronizedSetting;
			return val2;
		}

		private ConfigEntry<T> config<[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(2)] T>(string group, string name, T value, string description, bool synchronizedSetting = true)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			return config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()), synchronizedSetting);
		}

		static RapidLoadoutsPlugin()
		{
			string configPath = Paths.ConfigPath;
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName;
			ConnectionError = "";
			RapidLoadoutsLogger = Logger.CreateLogSource("RapidLoadouts");
			ConfigSync = new ConfigSync("Azumatt.RapidLoadouts")
			{
				DisplayName = "RapidLoadouts",
				CurrentVersion = "1.0.9",
				MinimumRequiredVersion = "1.0.9"
			};
			yamlFileName = SanitizeFileName("Azumatt.RapidLoadouts_Loadouts.yml");
			string configPath2 = Paths.ConfigPath;
			directorySeparatorChar = Path.DirectorySeparatorChar;
			yamlPath = configPath2 + directorySeparatorChar + yamlFileName;
			AzuRL_yamlData = new CustomSyncedValue<string>(ConfigSync, "AzuRL_yamlData", "");
			RL_yamlData = new List<ItemSet>();
			_serverConfigLocked = null;
			loadoutCostPrefab = null;
			InventoryLoadoutButtonPosition = null;
			LoadoutWindow = null;
		}
	}
	[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(0)]
	[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(1)]
	public static class LoggerExtensions
	{
		public static void LogDebugIfDebug(this ManualLogSource logger, string message)
		{
		}

		public static void LogErrorIfDebug(this ManualLogSource logger, string message)
		{
		}

		public static void LogWarningIfDebug(this ManualLogSource logger, string message)
		{
		}
	}
}
namespace RapidLoadouts.YAMLStuff
{
	[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(1)]
	[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(0)]
	public static class ItemSetHelper
	{
		[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(2)]
		public static void AddCreateLoadout(ItemSets __instance)
		{
			if ((Object)(object)__instance == (Object)null)
			{
				return;
			}
			Dictionary<string, ItemSet> dictionary = ConvertToGameItemSets(RapidLoadoutsPlugin.RL_yamlData).ToDictionary([<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(0)] (ItemSet set) => set.m_name, [<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(0)] (ItemSet set) => set);
			for (int i = 0; i < __instance.m_sets.Count; i++)
			{
				ItemSet val = __instance.m_sets[i];
				if (dictionary.ContainsKey(val.m_name))
				{
					__instance.m_sets[i] = dictionary[val.m_name];
					dictionary.Remove(val.m_name);
				}
			}
			__instance.m_sets.AddRange(dictionary.Values);
		}

		public static List<ItemSet> ConvertToGameItemSets([<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(new byte[] { 1, 2 })] List<ItemSet> customLoadouts)
		{
			//IL_0020: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Expected O, but got Unknown
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Expected O, but got Unknown
			List<ItemSet> list = new List<ItemSet>();
			foreach (ItemSet customLoadout in customLoadouts)
			{
				if (customLoadout == null)
				{
					continue;
				}
				ItemSet val = new ItemSet
				{
					m_name = RegexUtilities.TrimInvalidCharacters(customLoadout.m_name),
					m_items = new List<SetItem>(),
					m_skills = new List<SetSkill>()
				};
				foreach (SetItem item3 in customLoadout.m_items)
				{
					SetItem item = new SetItem
					{
						m_item = ConvertToItemDrop(item3.m_item),
						m_quality = item3.m_quality,
						m_stack = item3.m_stack,
						m_use = item3.m_use,
						m_hotbarSlot = item3.m_hotbarSlot
					};
					val.m_items.Add(item);
				}
				foreach (SetSkill skill in customLoadout.m_skills)
				{
					SetSkill item2 = new SetSkill
					{
						m_skill = ConvertToSkillType(skill.m_skill),
						m_level = skill.m_level
					};
					val.m_skills.Add(item2);
				}
				list.Add(val);
			}
			return list;
		}

		[return: <b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(2)]
		internal static ItemDrop ConvertToItemDrop(string itemName)
		{
			if ((Object)(object)ObjectDB.instance == (Object)null)
			{
				return null;
			}
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(itemName);
			if ((Object)(object)itemPrefab != (Object)null)
			{
				return itemPrefab.GetComponent<ItemDrop>();
			}
			RapidLoadoutsPlugin.RapidLoadoutsLogger.LogError((object)("ItemSetHelper.ConvertToItemDrop: Prefab for " + itemName + " not found in the ObjectDB! Can't convert to ItemDrop!"));
			return null;
		}

		internal static SkillType ConvertToSkillType(string skillName)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			if (Enum.TryParse<SkillType>(skillName, ignoreCase: true, out SkillType result))
			{
				return result;
			}
			RapidLoadoutsPlugin.RapidLoadoutsLogger.LogError((object)("ItemSetHelper.ConvertToSkillType: " + skillName + " is not a valid skill name or isn't a vanilla skill! Can't convert to Skills.SkillType!"));
			return (SkillType)0;
		}

		public static bool TryGetSet(string name, bool dropCurrentItems = false)
		{
			if ((Object)(object)Player.m_localPlayer == (Object)null || !ItemSets.instance.GetSetDictionary().TryGetValue(name, out var value))
			{
				return false;
			}
			if (dropCurrentItems)
			{
				DropCurrentItems();
			}
			PopulateInventoryWithSetItems(value);
			ResetAndRaiseSkills(value);
			return true;
		}

		private static void DropCurrentItems()
		{
			Skills skills = ((Character)Player.m_localPlayer).GetSkills();
			Player.m_localPlayer.CreateTombStone();
			Player.m_localPlayer.ClearFood();
			Player.m_localPlayer.ClearHardDeath();
			((Character)Player.m_localPlayer).GetSEMan().RemoveAllStatusEffects(false);
			foreach (SkillDef skill in skills.m_skills)
			{
				skills.CheatResetSkill(((object)(SkillType)(ref skill.m_skill)).ToString());
			}
		}

		private static void PopulateInventoryWithSetItems(ItemSet itemSet)
		{
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			Inventory inventory = ((Humanoid)Player.m_localPlayer).GetInventory();
			InventoryGui.instance.m_playerGrid.UpdateInventory(inventory, Player.m_localPlayer, (ItemData)null);
			foreach (SetItem item in itemSet.m_items)
			{
				if ((Object)(object)item.m_item == (Object)null || (item.m_item.m_itemData.m_shared.m_dlc.Length > 0 && !DLCMan.instance.IsDLCInstalled(item.m_item.m_itemData.m_shared.m_dlc)))
				{
					continue;
				}
				int num = Math.Max(1, item.m_stack);
				ItemData val = inventory.AddItem(((Object)((Component)item.m_item).gameObject).name, num, Math.Max(1, item.m_quality), 0, 0L, "Thor", false);
				if (val != null)
				{
					if (item.m_use)
					{
						((Humanoid)Player.m_localPlayer).UseItem(inventory, val, false);
					}
					if (item.m_hotbarSlot > 0)
					{
						InventoryGui.instance.m_playerGrid.DropItem(inventory, val, num, new Vector2i(item.m_hotbarSlot - 1, 0));
					}
				}
			}
		}

		internal static void SetAnyGuardianPower(string setEffect)
		{
			RapidLoadoutsPlugin.RapidLoadoutsLogger.LogDebugIfDebug("Setting effect to " + setEffect);
			Player.m_localPlayer.SetGuardianPower(setEffect);
			Player.m_localPlayer.m_guardianPowerCooldown = 0f;
		}

		private static void ResetAndRaiseSkills(ItemSet itemSet)
		{
			Skills skills = ((Character)Player.m_localPlayer).GetSkills();
			foreach (SetSkill skill in itemSet.m_skills)
			{
				skills.CheatResetSkill(((object)(SkillType)(ref skill.m_skill)).ToString());
				((Character)Player.m_localPlayer).GetSkills().CheatRaiseSkill(((object)(SkillType)(ref skill.m_skill)).ToString(), (float)skill.m_level, true);
			}
		}

		public static string Repeat(string value, int count)
		{
			return new StringBuilder(value.Length * count).Insert(0, value, count).ToString();
		}
	}
	[Serializable]
	[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(1)]
	[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(0)]
	public class ItemSet
	{
		[YamlMember(Alias = "name")]
		public string m_name;

		[YamlMember(Alias = "items")]
		[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(new byte[] { 2, 1 })]
		public List<SetItem> m_items = new List<SetItem>();

		[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(2)]
		[YamlMember(Alias = "skills")]
		public List<SetSkill> m_skills = new List<SetSkill>();

		[YamlMember(Alias = "dropCurrent")]
		public bool m_dropCurrent;

		[YamlMember(Alias = "price")]
		public int m_price;

		[YamlMember(Alias = "costPrefab")]
		public string m_prefabCost;

		[YamlMember(Alias = "setEffect")]
		public string m_setEffect;

		[YamlMember(Alias = "setEffectAsGP")]
		public bool m_setEffectAsGP;

		[YamlMember(Alias = "requiredGlobalKey")]
		public string m_requiredGlobalKey = "";
	}
	[Serializable]
	public class SetItem
	{
		[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(1)]
		[YamlMember(Alias = "item")]
		public string m_item;

		[YamlMember(Alias = "quality")]
		public int m_quality = 1;

		[YamlMember(Alias = "stack")]
		public int m_stack = 1;

		[YamlMember(Alias = "use")]
		public bool m_use = true;

		[YamlMember(Alias = "hotbarSlot")]
		public int m_hotbarSlot;
	}
	[Serializable]
	public class SetSkill
	{
		[YamlMember(Alias = "skill")]
		[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(1)]
		public string m_skill;

		[YamlMember(Alias = "level")]
		public int m_level;
	}
	[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(0)]
	[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(1)]
	public class YAMLUtils
	{
		internal static void WriteConfigFileFromResource(string configFilePath)
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string text = "RapidLoadouts.YAMLStuff.Example.yml";
			using Stream stream = executingAssembly.GetManifestResourceStream(text);
			if (stream == null)
			{
				throw new FileNotFoundException("Resource '" + text + "' not found in the assembly.");
			}
			using StreamReader streamReader = new StreamReader(stream);
			string contents = streamReader.ReadToEnd();
			File.WriteAllText(configFilePath, contents);
		}

		internal static void ReadYaml(string yamlInput)
		{
			RapidLoadoutsPlugin.RL_yamlData = new DeserializerBuilder().Build().Deserialize<List<ItemSet>>(yamlInput);
			RapidLoadoutsPlugin.RapidLoadoutsLogger.LogDebugIfDebug("yamlData:\n" + yamlInput);
		}

		internal static void WriteYaml(string yamlPath)
		{
			string contents = new SerializerBuilder().Build().Serialize(RapidLoadoutsPlugin.RL_yamlData);
			File.WriteAllText(yamlPath, contents);
		}

		internal void LoadCustomLoadouts()
		{
			if (!File.Exists(RapidLoadoutsPlugin.yamlPath))
			{
				RapidLoadoutsPlugin.RapidLoadoutsLogger.LogWarning((object)("Could not find " + RapidLoadoutsPlugin.yamlFileName + " at " + RapidLoadoutsPlugin.yamlPath));
				return;
			}
			try
			{
				new DeserializerBuilder().WithNamingConvention(UnderscoredNamingConvention.Instance).Build().Deserialize<List<ItemSet>>(File.ReadAllText(RapidLoadoutsPlugin.yamlPath));
			}
			catch (Exception ex)
			{
				RapidLoadoutsPlugin.RapidLoadoutsLogger.LogError((object)("Failed to load custom item sets: " + ex.Message));
			}
		}
	}
	[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(0)]
	[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(1)]
	public static class RegexUtilities
	{
		private static readonly Regex AlphanumericRegex = new Regex("[^a-zA-Z0-9]", RegexOptions.Compiled);

		public static string TrimInvalidCharacters(string input)
		{
			return AlphanumericRegex.Replace(input, string.Empty);
		}
	}
}
namespace RapidLoadouts.UI
{
	[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(1)]
	[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(0)]
	public class LoadoutsButtonHolder : MonoBehaviour
	{
		private Button _itemSetsButton;

		private TMP_Text _textComponent;

		private void Start()
		{
			((MonoBehaviour)this).InvokeRepeating("EnsureRecyclingButtonExistsIfPossible", 0f, 5f);
		}

		public void EnsureRecyclingButtonExistsIfPossible()
		{
			if (!((Object)(object)InventoryGui.instance == (Object)null))
			{
				if ((Object)(object)_itemSetsButton == (Object)null)
				{
					SetupButton();
				}
				Button itemSetsButton = _itemSetsButton;
				if (itemSetsButton != null)
				{
					((Component)itemSetsButton).gameObject.SetActive(true);
				}
			}
		}

		private void OnDestroy()
		{
			try
			{
				Object.Destroy((Object)(object)((Component)_itemSetsButton).gameObject);
			}
			catch
			{
			}
		}

		private void SetupButton()
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Expected O, but got Unknown
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Expected O, but got Unknown
			if (!((Object)(object)_itemSetsButton != (Object)null))
			{
				if (RapidLoadoutsPlugin.HasAuga)
				{
					_itemSetsButton = Object.Instantiate<Button>(((Component)((Transform)InventoryGui.instance.m_container).Find("TakeAll")).GetComponent<Button>(), ((Component)InventoryGui.instance.m_player).transform);
				}
				else
				{
					_itemSetsButton = Object.Instantiate<Button>(InventoryGui.instance.m_takeAllButton, ((Component)InventoryGui.instance.m_player).transform);
				}
				((Component)_itemSetsButton).transform.SetParent(((Component)InventoryGui.instance.m_player).transform);
				((Object)_itemSetsButton).name = "ItemSetsButton";
				Vector3 savedButtonPosition = GetSavedButtonPosition();
				((Component)_itemSetsButton).transform.localPosition = savedButtonPosition;
				_itemSetsButton.onClick = new ButtonClickedEvent();
				((UnityEvent)_itemSetsButton.onClick).AddListener(new UnityAction(PurchasableLoadoutGui.ToggleUI));
				((UnityEvent)_itemSetsButton.onClick).AddListener(new UnityAction(PersonalLoadoutGui.ToggleUI));
				_textComponent = ((Component)_itemSetsButton).GetComponentInChildren<TMP_Text>();
				_textComponent.text = Localization.instance.Localize("$azu_rl_loadouts");
				((Component)_itemSetsButton).gameObject.AddComponent<UIDragger>().OnUIDropped += delegate(object source, Vector3 position)
				{
					//IL_0005: Unknown result type (might be due to invalid IL or missing references)
					RapidLoadoutsPlugin.InventoryLoadoutButtonPosition.Value = position;
				};
			}
		}

		private Vector3 GetSavedButtonPosition()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return RapidLoadoutsPlugin.InventoryLoadoutButtonPosition.Value;
		}
	}
	[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(1)]
	[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(0)]
	public class PurchasableLoadoutGui : MonoBehaviour
	{
		[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(2)]
		public static PurchasableLoadoutGui m_instance = null;

		public static GameObject m_rootPanel = null;

		public Button m_chooseButton;

		public Button m_sellButton;

		public static RectTransform m_listRoot = null;

		public static GameObject m_listElement = null;

		public Scrollbar m_listScroll;

		public static ScrollRectEnsureVisible m_itemEnsureVisible = null;

		public TMP_Text m_coinText;

		public Image m_coinIcon;

		public TMP_Text m_topicText;

		public EffectList m_buyEffects = new EffectList();

		public EffectList m_sellEffects = new EffectList();

		public float m_hideDistance = 5f;

		public static float m_itemSpacing = 64f;

		public static ItemDrop m_coinPrefab = null;

		public static List<GameObject> m_itemList = new List<GameObject>();

		[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(2)]
		public static ItemSet m_selectedItem;

		[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(2)]
		public static Player m_LocalPlayerRef;

		public static float m_itemlistBaseSize;

		public List<ItemData> m_tempItems = new List<ItemData>();

		[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(new byte[] { 1, 2 })]
		private static List<ItemSet> availableSets = new List<ItemSet>();

		public static bool PanelActive;

		[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(2)]
		public static PurchasableLoadoutGui instance
		{
			[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(2)]
			get
			{
				return m_instance;
			}
		}

		public void Awake()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			m_instance = this;
			if ((Object)(object)m_rootPanel != (Object)null)
			{
				m_rootPanel.SetActive(false);
			}
			if ((Object)(object)m_listRoot != (Object)null)
			{
				Rect rect = m_listRoot.rect;
				m_itemlistBaseSize = ((Rect)(ref rect)).height;
			}
			m_chooseButton.onClick = new ButtonClickedEvent();
			((UnityEvent)m_chooseButton.onClick).AddListener(new UnityAction(OnChooseLoadout));
			m_sellButton.onClick = new ButtonClickedEvent();
			m_topicText.text = Localization.instance.Localize("$azu_rl_loadouts_purchasable");
		}

		public void OnDestroy()
		{
			if ((Object)(object)m_instance == (Object)(object)this)
			{
				m_instance = null;
			}
		}

		private void Update()
		{
			if (m_rootPanel.activeSelf && PanelActive)
			{
				if (ShouldHide() || ShouldClose())
				{
					Hide();
				}
				else
				{
					UpdateUI();
				}
			}
		}

		private bool ShouldHide()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead() || ((Character)localPlayer).InCutscene())
			{
				return true;
			}
			if (!InventoryGui.IsVisible() || Minimap.IsOpen())
			{
				return true;
			}
			return false;
		}

		private static bool ShouldClose()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus()) || Console.IsVisible() || Menu.IsVisible() || ((Object)(object)TextViewer.instance != (Object)null && TextViewer.instance.IsVisible()) || ((Character)localPlayer).InCutscene()) && (ZInput.GetButtonDown("JoyButtonB") || Input.GetKeyDown((KeyCode)27) || ZInput.GetButtonDown("Use")))
			{
				ZInput.ResetButtonStatus("JoyButtonB");
				return true;
			}
			return false;
		}

		private void UpdateUI()
		{
			UpdateBuyButton();
			UpdateRecipeGamepadInput();
			m_coinText.text = GetPlayerCoins().ToString();
			try
			{
				m_coinPrefab = ObjectDB.instance.GetItemPrefab(m_selectedItem?.m_prefabCost).GetComponent<ItemDrop>();
			}
			catch
			{
				m_coinPrefab = ObjectDB.instance.GetItemPrefab(RapidLoadoutsPlugin.loadoutCostPrefab.Value).GetComponent<ItemDrop>();
			}
			m_coinIcon.sprite = m_coinPrefab.m_itemData.GetIcon();
		}

		public static void Show()
		{
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Player.m_localPlayer == (Object)null || IsVisible())
			{
				return;
			}
			m_LocalPlayerRef = Player.m_localPlayer;
			((Component)InventoryGui.instance.m_dropButton).gameObject.SetActive(false);
			if (!RapidLoadoutsPlugin.HasAuga)
			{
				if ((Object)(object)((Component)Utils.FindChild(m_rootPanel.transform, "border (1)", (IterativeSearchType)0)).GetComponent<Image>() != (Object)(object)((Component)Utils.FindChild(((Component)StoreGui.instance).transform, "border (1)", (IterativeSearchType)0)).GetComponent<Image>().sprite)
				{
					((Component)Utils.FindChild(m_rootPanel.transform, "border (1)", (IterativeSearchType)0)).GetComponent<Image>().sprite = ((Component)Utils.FindChild(((Component)StoreGui.instance).transform, "border (1)", (IterativeSearchType)0)).GetComponent<Image>().sprite;
				}
				((Graphic)((Component)Utils.FindChild(m_rootPanel.transform, "border (1)", (IterativeSearchType)0)).GetComponent<Image>()).color = ((Graphic)((Component)Utils.FindChild(((Component)InventoryGui.instance.m_player).transform, "bkg", (IterativeSearchType)0)).GetComponent<Image>()).color;
			}
			m_rootPanel.SetActive(true);
			PanelActive = true;
			RapidLoadoutsPlugin.RapidLoadoutsLogger.LogDebugIfDebug("Showing Item Set GUI");
			FillList();
		}

		public static void Hide()
		{
			RapidLoadoutsPlugin.RapidLoadoutsLogger.LogDebugIfDebug("Hiding Item Set GUI");
			m_LocalPlayerRef = null;
			m_rootPanel.SetActive(false);
			PanelActive = false;
			((Component)InventoryGui.instance.m_dropButton).gameObject.SetActive(true);
		}

		public static void ToggleUI()
		{
			if (IsVisible())
			{
				Hide();
			}
			else
			{
				Show();
			}
		}

		public static bool IsVisible()
		{
			if (!Object.op_Implicit((Object)(object)m_instance) || !m_rootPanel.activeSelf)
			{
				return PanelActive;
			}
			return true;
		}

		public void OnChooseLoadout()
		{
			BuySelectedLoadout();
		}

		public void BuySelectedLoadout()
		{
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			if (m_selectedItem == null || !CanAfford(m_selectedItem))
			{
				return;
			}
			ItemSetHelper.TryGetSet(RegexUtilities.TrimInvalidCharacters(m_selectedItem.m_name), m_selectedItem.m_dropCurrent);
			if (!string.IsNullOrEmpty(m_selectedItem.m_setEffect))
			{
				if (m_selectedItem.m_setEffectAsGP)
				{
					ItemSetHelper.SetAnyGuardianPower(m_selectedItem.m_setEffect);
				}
				else
				{
					((Character)Player.m_localPlayer).m_seman.AddStatusEffect(StringExtensionMethods.GetStableHashCode(m_selectedItem.m_setEffect), false, 0, 0f);
				}
			}
			if (!Player.m_localPlayer.NoCostCheat())
			{
				((Humanoid)Player.m_localPlayer).GetInventory().RemoveItem(m_coinPrefab.m_itemData.m_shared.m_name, m_selectedItem.m_price, -1, true);
			}
			m_buyEffects.Create(((Component)this).transform.position, Quaternion.identity, (Transform)null, 1f, -1);
			FillList();
		}

		public static int GetPlayerCoins()
		{
			return ((Humanoid)Player.m_localPlayer).GetInventory().CountItems(m_coinPrefab.m_itemData.m_shared.m_name, -1, true);
		}

		[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(2)]
		public bool CanAfford(ItemSet item)
		{
			int playerCoins = GetPlayerCoins();
			if (item != null)
			{
				if (item.m_price > playerCoins)
				{
					return Player.m_localPlayer.NoCostCheat();
				}
				return true;
			}
			return false;
		}

		[return: <b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(new byte[] { 1, 2 })]
		public static List<ItemSet> GetAvailableSets()
		{
			availableSets.Clear();
			if (availableSets.Any())
			{
				return availableSets;
			}
			if (RapidLoadoutsPlugin.RL_yamlData != null)
			{
				availableSets.AddRange(RapidLoadoutsPlugin.RL_yamlData);
			}
			return availableSets.Where([<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(0)] (ItemSet x) => x != null && (string.IsNullOrEmpty(x.m_requiredGlobalKey) || ZoneSystem.instance.GetGlobalKey(x.m_requiredGlobalKey))).ToList();
		}

		public static void FillList()
		{
			//IL_0551: Unknown result type (might be due to invalid IL or missing references)
			//IL_055b: Expected O, but got Unknown
			//IL_052e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: 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_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			int playerCoins = GetPlayerCoins();
			int num = GetSelectedItemIndex();
			List<ItemSet> list = GetAvailableSets();
			foreach (GameObject item in m_itemList)
			{
				Object.Destroy((Object)(object)item);
			}
			m_itemList.Clear();
			m_listRoot.SetSizeWithCurrentAnchors((Axis)1, Mathf.Max(m_itemlistBaseSize, (float)list.Count * m_itemSpacing));
			for (int i = 0; i < list.Count; i++)
			{
				ItemSet itemSet = list[i];
				GameObject element = Object.Instantiate<GameObject>(m_listElement, (Transform)(object)m_listRoot);
				element.SetActive(true);
				Transform transform = element.transform;
				((RectTransform)((transform is RectTransform) ? transform : null)).anchoredPosition = new Vector2(0f, (float)i * (0f - m_itemSpacing));
				int num2 = 0;
				if (itemSet != null && itemSet.m_price != 0)
				{
					num2 = itemSet.m_price;
				}
				bool flag = num2 <= playerCoins || Player.m_localPlayer.NoCostCheat();
				Image component = ((Component)element.transform.Find("icon")).GetComponent<Image>();
				if (itemSet?.m_items == null || itemSet.m_items.Count == 0 || (Object)(object)ItemSetHelper.ConvertToItemDrop(itemSet.m_items[0].m_item) == (Object)null)
				{
					component.sprite = ObjectDB.instance.GetItemPrefab("YagluthDrop").GetComponent<ItemDrop>().m_itemData.m_shared.m_icons[0];
				}
				else
				{
					ItemDrop obj = ItemSetHelper.ConvertToItemDrop(itemSet.m_items[0].m_item);
					object sprite;
					if (obj == null)
					{
						sprite = null;
					}
					else
					{
						ItemData itemData = obj.m_itemData;
						if (itemData == null)
						{
							sprite = null;
						}
						else
						{
							SharedData shared = itemData.m_shared;
							sprite = ((shared != null) ? shared.m_icons[0] : null);
						}
					}
					component.sprite = (Sprite)sprite;
				}
				((Graphic)component).color = (Color)(flag ? Color.white : new Color(1f, 0f, 1f, 0f));
				string text = Localization.instance.Localize(itemSet?.m_name ?? "Unknown Item Set");
				TMP_Text component2 = ((Component)element.transform.Find("name")).GetComponent<TMP_Text>();
				component2.text = text;
				((Graphic)component2).color = (flag ? Color.white : Color.grey);
				UITooltip component3 = element.GetComponent<UITooltip>();
				component3.m_topic = itemSet?.m_name ?? "Unknown Item Set";
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append($"Drop Current Items: {itemSet?.m_dropCurrent ?? false}");
				stringBuilder.Append(Environment.NewLine + "Skills: ");
				if (itemSet != null)
				{
					List<SetSkill> skills = itemSet.m_skills;
					if (skills != null && skills.Count > 0)
					{
						foreach (SetSkill skill in itemSet.m_skills)
						{
							stringBuilder.Append($"{skill.m_skill} {skill.m_level}{Environment.NewLine}");
						}
					}
				}
				if (itemSet?.m_items != null && itemSet.m_items.Count > 0)
				{
					foreach (SetItem item2 in itemSet.m_items)
					{
						string text2 = ItemSetHelper.ConvertToItemDrop(item2.m_item)?.m_itemData?.m_shared?.m_name;
						if (!string.IsNullOrEmpty(text2))
						{
							stringBuilder.Append(Environment.NewLine + Localization.instance.Localize(text2) + " x" + ItemSetHelper.Repeat("★", item2.m_quality));
						}
					}
				}
				if (!string.IsNullOrEmpty(itemSet?.m_setEffect))
				{
					stringBuilder.Append(Environment.NewLine + "Set Effect: " + itemSet?.m_setEffect);
				}
				component3.m_text = stringBuilder.ToString();
				TMP_Text component4 = ((Component)Utils.FindChild(element.transform, "price", (IterativeSearchType)0)).GetComponent<TMP_Text>();
				component4.text = (Player.m_localPlayer.NoCostCheat() ? "Free" : itemSet?.m_price.ToString());
				try
				{
					((Component)Utils.FindChild(element.transform, "coin icon", (IterativeSearchType)0)).GetComponent<Image>().sprite = ObjectDB.instance.GetItemPrefab(itemSet?.m_prefabCost).GetComponent<ItemDrop>().m_itemData.GetIcon();
				}
				catch
				{
					((Component)Utils.FindChild(element.transform, "coin icon", (IterativeSearchType)0)).GetComponent<Image>().sprite = ObjectDB.instance.GetItemPrefab(RapidLoadoutsPlugin.loadoutCostPrefab.Value).GetComponent<ItemDrop>().m_itemData.GetIcon();
				}
				if (!flag)
				{
					((Graphic)component4).color = Color.grey;
				}
				((UnityEvent)element.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
				{
					OnSelectedItem(element);
				});
				m_itemList.Add(element);
			}
			if (num < 0)
			{
				num = 0;
			}
			SelectItem(num, center: false);
		}

		public static void OnSelectedItem(GameObject button)
		{
			SelectItem(FindSelectedRecipe(button), center: false);
		}

		public static int FindSelectedRecipe(GameObject button)
		{
			for (int i = 0; i < m_itemList.Count; i++)
			{
				if ((Object)(object)m_itemList[i] == (Object)(object)button)
				{
					return i;
				}
			}
			return -1;
		}

		public static void SelectItem(int index, bool center)
		{
			RapidLoadoutsPlugin.RapidLoadoutsLogger.LogDebugIfDebug("Setting selected recipe " + index);
			for (int i = 0; i < m_itemList.Count; i++)
			{
				bool active = i == index;
				((Component)m_itemList[i].transform.Find("selected")).gameObject.SetActive(active);
			}
			if (center && index >= 0)
			{
				? val = m_itemEnsureVisible;
				Transform transform = m_itemList[index].transform;
				((ScrollRectEnsureVisible)val).CenterOnItem((RectTransform)(object)((transform is RectTransform) ? transform : null));
			}
			m_selectedItem = ((index < 0) ? null : GetAvailableSets()[index]);
		}

		public static int GetSelectedItemIndex()
		{
			int result = 0;
			List<ItemSet> list = GetAvailableSets();
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i] == m_selectedItem)
				{
					result = i;
				}
			}
			return result;
		}

		public void UpdateBuyButton()
		{
			UITooltip component = ((Component)m_chooseButton).GetComponent<UITooltip>();
			if (m_selectedItem != null)
			{
				bool flag = CanAfford(m_selectedItem);
				bool flag2 = ((Humanoid)Player.m_localPlayer).GetInventory().HaveEmptySlot();
				((Selectable)m_chooseButton).interactable = flag && flag2;
				if (!flag)
				{
					component.m_text = Localization.instance.Localize("$msg_missingrequirement");
				}
				else if (!flag2)
				{
					component.m_text = Localization.instance.Localize("$inventory_full");
				}
				else
				{
					component.m_text = "";
				}
			}
			else
			{
				((Selectable)m_chooseButton).interactable = false;
				component.m_text = "";
			}
		}

		public void UpdateRecipeGamepadInput()
		{
			if (m_itemList.Count > 0)
			{
				if (ZInput.GetButtonDown("JoyLStickDown") || ZInput.GetButtonDown("JoyDPadDown"))
				{
					SelectItem(Mathf.Min(m_itemList.Count - 1, GetSelectedItemIndex() + 1), center: true);
				}
				if (ZInput.GetButtonDown("JoyLStickUp") || ZInput.GetButtonDown("JoyDPadUp"))
				{
					SelectItem(Mathf.Max(0, GetSelectedItemIndex() - 1), center: true);
				}
			}
		}
	}
	[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(0)]
	[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(1)]
	public class PersonalLoadoutGui : MonoBehaviour
	{
		[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(2)]
		public static PersonalLoadoutGui m_instance = null;

		public static GameObject m_rootPanel = null;

		public Button m_chooseButton;

		public Button m_sellButton;

		public static RectTransform m_listRoot = null;

		public static GameObject m_listElement = null;

		public Scrollbar m_listScroll;

		public static ScrollRectEnsureVisible m_itemEnsureVisible = null;

		public TMP_Text m_coinText;

		public Image m_coinIcon;

		public TMP_Text m_topicText;

		public EffectList m_buyEffects = new EffectList();

		public EffectList m_sellEffects = new EffectList();

		public float m_hideDistance = 5f;

		public static float m_itemSpacing = 64f;

		public static ItemDrop m_coinPrefab = null;

		public static List<GameObject> m_itemList = new List<GameObject>();

		[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(2)]
		public static string m_selectedItem;

		[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(2)]
		public static Player m_LocalPlayerRef;

		public static float m_itemlistBaseSize;

		public List<ItemData> m_tempItems = new List<ItemData>();

		[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(new byte[] { 1, 2 })]
		private static List<ItemSet> availableSets = new List<ItemSet>();

		public static bool PanelActive;

		[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(2)]
		public static PersonalLoadoutGui instance
		{
			[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(2)]
			get
			{
				return m_instance;
			}
		}

		public void Awake()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			m_instance = this;
			if ((Object)(object)m_rootPanel != (Object)null)
			{
				m_rootPanel.SetActive(false);
			}
			if ((Object)(object)m_listRoot != (Object)null)
			{
				Rect rect = m_listRoot.rect;
				m_itemlistBaseSize = ((Rect)(ref rect)).height;
			}
			m_chooseButton.onClick = new ButtonClickedEvent();
			((UnityEvent)m_chooseButton.onClick).AddListener(new UnityAction(OnChooseLoadout));
			m_topicText.text = Localization.instance.Localize("$azu_rl_loadouts_personal");
		}

		public void OnDestroy()
		{
			if ((Object)(object)m_instance == (Object)(object)this)
			{
				m_instance = null;
			}
		}

		private void Update()
		{
			if (m_rootPanel.activeSelf && PanelActive)
			{
				if (ShouldHide() || ShouldClose())
				{
					Hide();
				}
				else
				{
					UpdateUI();
				}
			}
		}

		private bool ShouldHide()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead() || ((Character)localPlayer).InCutscene())
			{
				return true;
			}
			if (!InventoryGui.IsVisible() || Minimap.IsOpen())
			{
				return true;
			}
			return false;
		}

		private static bool ShouldClose()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus()) || Console.IsVisible() || Menu.IsVisible() || ((Object)(object)TextViewer.instance != (Object)null && TextViewer.instance.IsVisible()) || ((Character)localPlayer).InCutscene()) && (ZInput.GetButtonDown("JoyButtonB") || Input.GetKeyDown((KeyCode)27) || ZInput.GetButtonDown("Use")))
			{
				ZInput.ResetButtonStatus("JoyButtonB");
				return true;
			}
			return false;
		}

		private void UpdateUI()
		{
			UpdateSwitchLoadoutButton();
			UpdateRecipeGamepadInput();
			m_coinText.text = GetNumberOfLoadouts().ToString();
		}

		public static void Show()
		{
			if (!((Object)(object)Player.m_localPlayer == (Object)null) && !IsVisible())
			{
				m_LocalPlayerRef = Player.m_localPlayer;
				((Component)InventoryGui.instance.m_dropButton).gameObject.SetActive(false);
				m_rootPanel.SetActive(true);
				PanelActive = true;
				RapidLoadoutsPlugin.RapidLoadoutsLogger.LogDebugIfDebug("Showing Item Set GUI");
				FillList();
			}
		}

		public static void Hide()
		{
			RapidLoadoutsPlugin.RapidLoadoutsLogger.LogDebugIfDebug("Hiding Item Set GUI");
			m_LocalPlayerRef = null;
			m_rootPanel.SetActive(false);
			PanelActive = false;
			((Component)InventoryGui.instance.m_dropButton).gameObject.SetActive(true);
		}

		public static void ToggleUI()
		{
			if (IsVisible())
			{
				Hide();
			}
			else
			{
				Show();
			}
		}

		public static bool IsVisible()
		{
			if (!Object.op_Implicit((Object)(object)m_instance) || !m_rootPanel.activeSelf)
			{
				return PanelActive;
			}
			return true;
		}

		public void OnChooseLoadout()
		{
			LoadSelectedLoadout();
		}

		public void LoadSelectedLoadout()
		{
			//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)
			if (!string.IsNullOrWhiteSpace(m_selectedItem))
			{
				LoadLoadout(m_selectedItem);
				m_buyEffects.Create(((Component)this).transform.position, Quaternion.identity, (Transform)null, 1f, -1);
				FillList();
			}
		}

		public static int GetNumberOfLoadouts()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return 0;
			}
			return localPlayer.m_customData.Keys.Count([<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(0)] (string key) => key.StartsWith("Loadout_"));
		}

		public static List<string> GetAvailableLoadouts()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return new List<string>();
			}
			List<string> list = new List<string>();
			foreach (string key in localPlayer.m_customData.Keys)
			{
				if (key.StartsWith("Loadout_"))
				{
					list.Add(key.Replace("Loadout_", ""));
				}
			}
			return list;
		}

		public static void SaveLoadout(string loadoutName)
		{
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null))
			{
				List<ItemData> equippedItems = ((Humanoid)localPlayer).GetInventory().GetEquippedItems();
				PersonalLoadout personalLoadout = new PersonalLoadout(loadoutName, equippedItems);
				localPlayer.m_customData["Loadout_" + loadoutName] = personalLoadout.Serialize();
			}
		}

		private static void SaveEquippedItems(Player player, Inventory inventory)
		{
			List<ItemData> equippedItems = ((Humanoid)player).GetInventory().GetEquippedItems();
			if (equippedItems != null && equippedItems.Count > 0)
			{
				for (int i = 0; i < equippedItems.Count; i++)
				{
					ItemData val = equippedItems[i];
					inventory.AddItem(val.Clone());
				}
			}
		}

		public static void LoadLoadout(string loadoutName)
		{
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null))
			{
				RapidLoadoutsPlugin.RapidLoadoutsLogger.LogDebugIfDebug("Loading loadout " + loadoutName);
				if (localPlayer.m_customData.TryGetValue("Loadout_" + loadoutName, out var value))
				{
					PersonalLoadout loadout = PersonalLoadout.Deserialize(loadoutName, value);
					SaveLoadout(loadoutName);
					UnequipAndRemoveCurrentItems(localPlayer);
					EquipItemsFromLoadout(localPlayer, loadout);
					((Humanoid)localPlayer).m_visEquipment.UpdateVisuals();
				}
			}
		}

		private static void EquipItemsFromLoadout(Player player, PersonalLoadout loadout)
		{
			List<ItemData> items = loadout.Items;
			int num = ((Humanoid)player).GetInventory().GetEmptySlots();
			RapidLoadoutsPlugin.RapidLoadoutsLogger.LogWarningIfDebug("Items to equip: " + string.Join(", ", items.Select([<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(0)] (ItemData i) => i.m_shared.m_name)));
			RapidLoadoutsPlugin.RapidLoadoutsLogger.LogWarningIfDebug($"Free slots in inventory: {num}");
			for (int j = 0; j < items.Count; j++)
			{
				ItemData val = items[j];
				if (val == null)
				{
					RapidLoadoutsPlugin.RapidLoadoutsLogger.LogErrorIfDebug("Encountered null item in inventory list");
					continue;
				}
				RapidLoadoutsPlugin.RapidLoadoutsLogger.LogWarningIfDebug("Preparing to equip: " + val.m_shared.m_name);
				if (num > 0)
				{
					if (((Humanoid)player).GetInventory().AddItem(val))
					{
						((Humanoid)player).EquipItem(val, true);
						RapidLoadoutsPlugin.RapidLoadoutsLogger.LogWarningIfDebug("Successfully equipped: " + val.m_shared.m_name);
					}
					else
					{
						RapidLoadoutsPlugin.RapidLoadoutsLogger.LogErrorIfDebug("Failed to move: " + val.m_shared.m_name);
					}
					num--;
				}
				else
				{
					RapidLoadoutsPlugin.RapidLoadoutsLogger.LogErrorIfDebug("Not enough inventory space to move: " + val.m_shared.m_name);
				}
			}
			List<ItemData> equippedItems = ((Humanoid)player).GetInventory().GetEquippedItems();
			RapidLoadoutsPlugin.RapidLoadoutsLogger.LogWarningIfDebug("Currently equipped items: " + string.Join(", ", equippedItems.Select([<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(0)] (ItemData i) => i.m_shared.m_name)));
		}

		private static void UnequipAndRemoveCurrentItems(Player player)
		{
			List<ItemData> equippedItems = ((Humanoid)player).GetInventory().GetEquippedItems();
			for (int i = 0; i < equippedItems.Count; i++)
			{
				ItemData val = equippedItems[i];
				((Humanoid)player).UnequipItem(val, true);
				((Humanoid)player).GetInventory().RemoveItem(val);
			}
		}

		private static void EquipItemsFromInventory(Player player, Inventory inventory)
		{
			List<ItemData> allItems = inventory.GetAllItems();
			int num = ((Humanoid)player).GetInventory().GetEmptySlots();
			RapidLoadoutsPlugin.RapidLoadoutsLogger.LogWarning((object)("Items to equip: " + string.Join(", ", allItems.Select([<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(0)] (ItemData i) => i.m_shared.m_name))));
			RapidLoadoutsPlugin.RapidLoadoutsLogger.LogWarning((object)$"Free slots in inventory: {num}");
			for (int j = 0; j < allItems.Count; j++)
			{
				ItemData val = allItems[j];
				if (val == null)
				{
					RapidLoadoutsPlugin.RapidLoadoutsLogger.LogError((object)"Encountered null item in inventory list");
					continue;
				}
				RapidLoadoutsPlugin.RapidLoadoutsLogger.LogWarning((object)("Preparing to equip: " + val.m_shared.m_name));
				if (num > 0)
				{
					if (((Humanoid)player).GetInventory().AddItem(val))
					{
						inventory.RemoveItem(val);
					}
					else
					{
						RapidLoadoutsPlugin.RapidLoadoutsLogger.LogError((object)("Failed to move: " + val.m_shared.m_name));
					}
					((Humanoid)player).GetInventory().Changed();
					inventory.Changed();
					num--;
					RapidLoadoutsPlugin.RapidLoadoutsLogger.LogWarning((object)("Successfully moved: " + val.m_shared.m_name));
					if (((Humanoid)player).EquipItem(val, true))
					{
						RapidLoadoutsPlugin.RapidLoadoutsLogger.LogWarning((object)("Successfully equipped: " + val.m_shared.m_name));
					}
					else
					{
						RapidLoadoutsPlugin.RapidLoadoutsLogger.LogError((object)("Failed to equip: " + val.m_shared.m_name));
					}
				}
				else
				{
					RapidLoadoutsPlugin.RapidLoadoutsLogger.LogError((object)("Not enough inventory space to move: " + val.m_shared.m_name));
				}
			}
			List<ItemData> equippedItems = ((Humanoid)player).GetInventory().GetEquippedItems();
			RapidLoadoutsPlugin.RapidLoadoutsLogger.LogWarning((object)("Currently equipped items: " + string.Join(", ", equippedItems.Select([<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(0)] (ItemData i) => i.m_shared.m_name))));
		}

		public static void FillList()
		{
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Expected O, but got Unknown
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			List<string> availableLoadouts = GetAvailableLoadouts();
			int num = GetSelectedItemIndex();
			foreach (GameObject item in m_itemList)
			{
				Object.Destroy((Object)(object)item);
			}
			m_itemList.Clear();
			m_listRoot.SetSizeWithCurrentAnchors((Axis)1, Mathf.Max(m_itemlistBaseSize, (float)availableLoadouts.Count * m_itemSpacing));
			for (int j = 0; j < availableLoadouts.Count; j++)
			{
				string text = availableLoadouts[j];
				GameObject element = Object.Instantiate<GameObject>(m_listElement, (Transform)(object)m_listRoot);
				element.SetActive(true);
				Transform transform = element.transform;
				((RectTransform)((transform is RectTransform) ? transform : null)).anchoredPosition = new Vector2(0f, (float)j * (0f - m_itemSpacing));
				Image component = ((Component)element.transform.Find("icon")).GetComponent<Image>();
				if (Player.m_localPlayer.m_customData.TryGetValue("Loadout_" + text, out var value))
				{
					PersonalLoadout personalLoadout = PersonalLoadout.Deserialize(text, value);
					if (personalLoadout.Items.Count > 0)
					{
						ItemData val = personalLoadout.Items[0];
						component.sprite = val.m_shared.m_icons[0];
					}
					else
					{
						component.sprite = null;
					}
					bool flag = personalLoadout.Items.Count > 0;
					((Graphic)component).color = (Color)(flag ? Color.white : new Color(1f, 0f, 1f, 0f));
					TMP_Text component2 = ((Component)element.transform.Find("name")).GetComponent<TMP_Text>();
					component2.text = Localization.instance.Localize("$azu_rl_loadout " + text);
					((Graphic)component2).color = (flag ? Color.white : Color.grey);
					UITooltip component3 = element.GetComponent<UITooltip>();
					component3.m_topic = text;
					component3.m_text = (flag ? ("$azu_rl_loadouts_load:\n" + string.Join("\n", personalLoadout.Items.Select([<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(0)] (ItemData i) => Localization.instance.Localize(i.m_shared.m_name)))) : "$azu_rl_loadouts_empty");
					((UnityEvent)element.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
					{
						OnSelectedLoadout(element);
					});
					TMP_Text component4 = ((Component)Utils.FindChild(element.transform, "price", (IterativeSearchType)0)).GetComponent<TMP_Text>();
					((Behaviour)((Component)Utils.FindChild(element.transform, "coin icon", (IterativeSearchType)0)).GetComponent<Image>()).enabled = false;
					string arg = ((personalLoadout.Items.Count > 1) ? "items" : "item");
					component4.text = ((personalLoadout.Items.Count >= 1) ? $"{personalLoadout.Items.Count} {arg}" : "Empty");
					if (!flag)
					{
						((Graphic)component4).color = Color.grey;
					}
					m_itemList.Add(element);
				}
			}
			if (num < 0)
			{
				num = 0;
			}
			SelectItem(num, center: false);
		}

		public static void OnSelectedLoadout(GameObject button)
		{
			SelectItem(FindSelectedLoadout(button), center: false);
		}

		public static int FindSelectedLoadout(GameObject button)
		{
			for (int i = 0; i < m_itemList.Count; i++)
			{
				if ((Object)(object)m_itemList[i] == (Object)(object)button)
				{
					return i;
				}
			}
			return -1;
		}

		public static void SelectItem(int index, bool center)
		{
			try
			{
				for (int i = 0; i < m_itemList.Count; i++)
				{
					bool active = i == index;
					((Component)m_itemList[i].transform.Find("selected")).gameObject.SetActive(active);
				}
				if (center && index >= 0)
				{
					? val = m_itemEnsureVisible;
					Transform transform = m_itemList[index].transform;
					((ScrollRectEnsureVisible)val).CenterOnItem((RectTransform)(object)((transform is RectTransform) ? transform : null));
				}
				m_selectedItem = ((index < 0) ? null : GetAvailableLoadouts()[index]);
			}
			catch
			{
				for (int j = 1; j < 11; j++)
				{
					Player.m_localPlayer.m_customData[$"Loadout_{j}"] = "";
				}
				FillList();
			}
		}

		public static int GetSelectedItemIndex()
		{
			int result = 0;
			List<string> availableLoadouts = GetAvailableLoadouts();
			for (int i = 0; i < availableLoadouts.Count; i++)
			{
				if (availableLoadouts[i] == m_selectedItem)
				{
					result = i;
				}
			}
			return result;
		}

		public void UpdateSwitchLoadoutButton()
		{
			UITooltip component = ((Component)m_chooseButton).GetComponent<UITooltip>();
			if (m_selectedItem != null)
			{
				Player localPlayer = Player.m_localPlayer;
				if (!((Object)(object)localPlayer == (Object)null) && localPlayer.m_customData.TryGetValue("Loadout_" + m_selectedItem, out var value))
				{
					bool num = PersonalLoadout.Deserialize(m_selectedItem, value).Items.Count == 0;
					bool flag = ((Humanoid)localPlayer).GetInventory().HaveEmptySlot();
					((Selectable)m_chooseButton).interactable = flag;
					string text = (num ? "$azu_rl_emptyLoadout" : "$azu_rl_swapLoadout");
					((Component)((Component)m_chooseButton).transform.Find(RapidLoadoutsPlugin.HasAuga ? "Label" : "Text")).GetComponent<TMP_Text>().text = Localization.instance.Localize(text);
					component.m_text = ((!flag) ? Localization.instance.Localize("$inventory_full") : "");
				}
			}
			else
			{
				((Selectable)m_chooseButton).interactable = false;
				component.m_text = "";
			}
		}

		public void UpdateRecipeGamepadInput()
		{
			if (m_itemList.Count > 0)
			{
				if (ZInput.GetButtonDown("JoyLStickDown") || ZInput.GetButtonDown("JoyDPadDown"))
				{
					SelectItem(Mathf.Min(m_itemList.Count - 1, GetSelectedItemIndex() + 1), center: true);
				}
				if (ZInput.GetButtonDown("JoyLStickUp") || ZInput.GetButtonDown("JoyDPadUp"))
				{
					SelectItem(Mathf.Max(0, GetSelectedItemIndex() - 1), center: true);
				}
			}
		}
	}
	[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(1)]
	[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(0)]
	public static class InventorySerializer
	{
		public static string SerializeInventory(Inventory inventory)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			ZPackage val = new ZPackage();
			inventory.Save(val);
			return val.GetBase64();
		}

		public static void DeserializeInventory(Inventory inventory, string data)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			if (!string.IsNullOrEmpty(data))
			{
				ZPackage val = new ZPackage(data);
				inventory.Load(val);
			}
		}
	}
	[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(1)]
	[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(0)]
	public class PersonalLoadout
	{
		public string LoadoutName { get; set; }

		public List<ItemData> Items { get; set; }

		public PersonalLoadout(string loadoutName, List<ItemData> items)
		{
			LoadoutName = loadoutName;
			Items = items;
		}

		public string Serialize()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			Inventory val = new Inventory("Loadout", (Sprite)null, 100, 100);
			foreach (ItemData item in Items)
			{
				val.AddItem(item.Clone());
			}
			return InventorySerializer.SerializeInventory(val);
		}

		public static PersonalLoadout Deserialize(string loadoutName, string data)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			Inventory val = new Inventory("Loadout", (Sprite)null, 100, 100);
			InventorySerializer.DeserializeInventory(val, data);
			List<ItemData> allItems = val.GetAllItems();
			return new PersonalLoadout(loadoutName, allItems);
		}
	}
	[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(1)]
	[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(0)]
	public class UIDragger : EventTrigger
	{
		[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(0)]
		public delegate void UIDroppedHandler(object source, Vector3 newLocalPosition);

		private bool _isDragging;

		public event UIDroppedHandler OnUIDropped;

		public void Update()
		{
			//IL_000f: 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_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)
			if (_isDragging)
			{
				((Component)this).transform.position = Vector2.op_Implicit(new Vector2(Input.mousePosition.x, Input.mousePosition.y));
			}
		}

		public override void OnPointerDown(PointerEventData eventData)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if ((int)eventData.button == 1 && Input.GetKey((KeyCode)306))
			{
				_isDragging = true;
			}
		}

		public override void OnPointerUp(PointerEventData eventData)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			if ((int)eventData.button == 1)
			{
				_isDragging = false;
				this.OnUIDropped?.Invoke(this, new Vector3(((Component)this).transform.localPosition.x, ((Component)this).transform.localPosition.y, -1f));
			}
		}
	}
}
namespace RapidLoadouts.Game
{
	[HarmonyPatch(typeof(ObjectDB), "Awake")]
	internal static class ObjectDBAwakePatch
	{
		[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(1)]
		private static void Postfix(ObjectDB __instance)
		{
			ItemSetHelper.AddCreateLoadout(ItemSets.instance);
		}
	}
	[<17a2b4d6-6ab3-491e-8cfe-c557ff162dd8>NullableContext(1)]
	[<b19be342-00b0-41d8-bd29-597b2490c5db>Nullable(0)]
	[HarmonyPatch(typeof(Player), "OnSpawned")]
	internal static class PlayerSpawnedPatch
	{
		private static void Postfix(Player __instance)
		{
			try
			{
				GameObject gameObject;
				if (RapidLoadoutsPlugin.HasAuga)
				{
					GameObject val = GameObject.Find("_GameMain/LoadingGUI/PixelFix/IngameGui(Clone)");
					if ((Object)(object)val == (Object)null)
					{
						RapidLoadoutsPlugin.RapidLoadoutsLogger.LogError((object)"IngameGui not found");
						return;
					}
					Transform val2 = Utils.FindChild(val.transform, "AugaStoreScreen(Clone)", (IterativeSearchType)0);
					if ((Object)(object)val2 == (Object)null)
					{
						RapidLoadoutsPlugin.RapidLoadoutsLogger.LogError((object)"AugaStoreScreen not found");
						return;
					}
					gameObject = ((Component)val2).gameObject;
				}
				else
				{
					gameObject = ((Component)StoreGui.instance).gameObject;
					if ((Object)(object)gameObject == (Object)null)
					{
						RapidLoadoutsPlugin.RapidLoadoutsLogger.LogError((object)"StoreGui.instance is null");
						return;
					}
				}
				RapidLoadoutsPlugin.RapidLoadoutsLogger.LogDebugIfDebug("Root panel: " + ((Object)gameObject).name);
				CreateMainPanel(gameObject, __instance, out var clonedRootPanel, out var gui);
				if ((Object)(object)clonedRootPanel == (Object)null || (Object)(object)gui == (Object)null)
				{
					RapidLoadoutsPlugin.RapidLoadoutsLogger.LogError((object)"Failed to create main panel, second panel not created");
					return;
				}
				CreateSecondPanel(clonedRootPanel, gui);
				RapidLoadoutsPlugin.RapidLoadoutsLogger.LogDebugIfDebug("Second panel created successfully");
			}
			catch (Exception ex)
			{
				RapidLoadoutsPlugin.RapidLoadoutsLogger.LogError((object)("Exception: " + ex));
			}
		}

		private static void CreateMainPanel(GameObject rootPanel, Player player, out GameObject clonedRootPanel, out PurchasableLoadoutGui gui)
		{
			//IL_0060: 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_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(rootPanel, ((Component)InventoryGui.instance.m_player).transform, false);
			((Object)val).name = "AzuRapidLoadoutsRootPanel";
			((Component)Utils.FindChild(val.transform, "border (1)", (IterativeSearchType)0)).gameObject.GetComponent<Image>().sprite = ((Humanoid)player).m_inventory.GetBkg();
			clonedRootPanel = val;
			val.GetComponent<RectTransform>().anchoredPosition = new Vector2(550f, 150f);
			((Transform)val.GetComponent<RectTransform>()).localPosition = RapidLoadoutsPlugin.LoadoutWindow.Value;
			PurchasableLoadoutGui purchasableLoadoutGui = val.AddComponent<PurchasableLoadoutGui>();
			if ((Object)(object)purchasableLoadoutGui == (Object)null)
			{
				RapidLoadoutsPlugin.RapidLoadoutsLogger.LogDebugIfDebug("PurchasableLoadoutGui component not found on newRootPanel");
				gui = null;
				return;
			}
			gui = purchasableLoadoutGui;
			RapidLoadoutsPlugin.RapidLoadoutsLogger.LogDebugIfDebug("PurchasableLoadoutGui component found on newRootPanel");
			PurchasableLoadoutGui.m_rootPanel = ((Component)Utils.FindChild(val.transform, "Store", (IterativeSearchType)0)).gameObject;
			purchasableLoadoutGui.m_chooseButton = ((Component)Utils.FindChild(val.transform, "BuyButton", (IterativeSearchType)0)).GetComponent<Button>();
			((Component)((Component)purchasableLoadoutGui.m_chooseButton).transform.Find(RapidLoadoutsPlugin.HasAuga ? "Label" : "Text")).GetComponent<TMP_Text>().text = Localization.instance.Localize("$azu_rl_buyLoadout");
			purchasableLoadoutGui.m_sellButton = ((Component)Utils.FindChild(val.transform, "SellButton", (IterativeSearchType)0)).GetComponent<Button>();
			((Component)purchasableLoadoutGui.m_sellButton).GetComponent<UITooltip>().m_text = (RapidLoadoutsPlugin.HasAuga ? "Not implemented, couldn't hide this button without making the UI look unbalanced and ugly. Plus side? It makes a cool coin sound at least. Figured I'd leave the sound in." : Localization.instance.Localize("$azu_rl_equipSelected"));
			((Component)((Component)purchasableLoadoutGui.m_sellButton).transform.Find("Image")).gameObject.SetActive(false);
			if (!RapidLoadoutsPlugin.HasAuga)
			{
				((Component)((Component)purchasableLoadoutGui.m_sellButton).transform.Find("Image (1)")).gameObject.SetActive(true);
				((Component)((Component)purchasableLoadoutGui.m_sellButton).transform.parent).gameObject.SetActive(false);
			}
			PurchasableLoadoutGui.m_listRoot = ((Component)Utils.FindChild(val.transform, "ListRoot", (IterativeSearchType)0)).GetComponent<RectTransform>();
			PurchasableLoadoutGui.m_listElement = ((Component)Utils.FindChild(val.transform, "ItemElement", (IterativeSearchType)0)).gameObject;
			purchasableLoadoutGui.m_listScroll = ((Component)Utils.FindChild(val.transform, RapidLoadoutsPlugin.HasAuga ? "ScrollBar" : "ItemScroll", (IterativeSearchType)0)).GetComponent<Scrollbar>();
			PurchasableLoadoutGui.m_itemEnsureVisible = ((Component)Utils.FindChild(val.transform, RapidLoadoutsPlugin.HasAuga ? "ItemListBkg" : "Items", (IterativeSearchType)0)).GetComponent<ScrollRectEnsureVisible>();
			purchasableLoadoutGui.m_coinText = ((Component)val.transform.Find("Store/" + (RapidLoadoutsPlugin.HasAuga ? "DividerMedium/" : "") + "coins/coins")).GetComponent<TMP_Text>();
			purchasableLoadoutGui.m_coinIcon = ((Component)val.transform.Find("Store/" + (RapidLoadoutsPlugin.HasAuga ? "DividerMedium/" : "") + "coins/coin icon" + (RapidLoadoutsPlugin.HasAuga ? "/coin icon" : ""))).GetComponent<Image>();
			if (!RapidLoadoutsPlugin.HasAuga)
			{
				RectTransform component = ((Component)val.transform.Find("Store/coins/coin icon")).GetComponent<RectTransform>();
				component.anchoredPosition += new Vector2(0f, 5f);
				RectTransform component2 = ((Component)val.transform.Find("Store/coins")).GetComponent<RectTransform>();
				component2.anchoredPosition += new Vector2(35f, 0f);
			}
			purchasableLoadoutGui.m_topicText = ((Component)Utils.FindChild(val.transform, RapidLoadoutsPlugin.HasAuga ? "Topic" : "topic", (IterativeSearchType)0)).GetComponent<TMP_Text>();
			purchasableLoadoutGui.m_buyEffects = val.GetComponent<StoreGui>().m_buyEffects;
			purchasableLoadoutGui.m_sellEffects = val.GetComponent<StoreGui>().m_sellEffects;
			purchasableLoadoutGui.m_hideDistance = val.GetComponent<StoreGui>().m_hideDistance;
			PurchasableLoadoutGui.m_itemSpacing = val.GetComponent<StoreGui>().m_itemSpacing;
			PurchasableLoadoutGui.m_coinPrefab = val.GetComponent<StoreGui>().m_coinPrefab;
			PurchasableLoadoutGui.m_itemlistBaseSize = val.GetComponent<StoreGui>().m_itemlistBaseSize;
			Object.DestroyImmediate((Object)(object)val.GetComponent<StoreGui>());
			val.AddComponent<UIDragger>().OnUIDropped += delegate(object source, Vector3 position)
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				RapidLoadoutsPlugin.LoadoutWindow.Value = position;
			};
			RapidLoadoutsPlugin.RapidLoadoutsLogger.LogDebugIfDebug("PurchasableLoadoutGui created successfully");
		}

		private static void CreateSecondPanel(GameObject newRootPanel, PurchasableLoadoutGui itemsetGui)
		{
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f3: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(newRootPanel, newRootPanel.transform);
			((Object)val).name = "AzuRapidLoadoutsSecondPanel";
			Object.DestroyImmediate((Object)(object)val.GetComponent<UIDragger>());
			Object.DestroyImmediate((Object)(object)val.GetComponent<PurchasableLoadoutGui>());
			PersonalLoadoutGui personalLoadoutGui = newRootPanel.AddComponent<PersonalLoadoutGui>();
			if ((Object)(object)personalLoadoutGui == (Object)null)
			{
				RapidLoadoutsPlugin.RapidLoadoutsLogger.LogDebugIfDebug("PurchasableLoadoutGui component not found on newRootPanel");
				return;
			}
			PersonalLoadoutGui.m_rootPanel = ((Component)Utils.FindChild(val.transform, "Store", (IterativeSearchType)0)).gameObject;
			personalLoadoutGui.m_chooseButton = ((Component)Utils.FindChild(val.transform, "BuyButton", (IterativeSearchType)0)).GetComponent<Button>();
			((UnityEventBase)personalLoadoutGui.m_chooseButton.onClick).RemoveAllListeners();
			((Component)((Component)personalLoadoutGui.m_chooseButton).transform.Find(RapidLoadoutsPlugin.HasAuga ? "Label" : "Text")).GetComponent<TMP_Text>().text = Localization.instance.Localize("$azu_rl_emptyItemSet");
			personalLoadoutGui.m_sellButton = ((Component)Utils.FindChild(newRootPanel.transform, "SellButton", (IterativeSearchType)0)).GetComponent<Button>();
			((Component)personalLoadoutGui.m_sellButton).GetComponent<UITooltip>().m_text = (RapidLoadoutsPlugin.HasAuga ? "Not implemented, couldn't hide this button without making the UI look unbalanced and ugly. Plus side? It makes a cool coin sound at least. Figured I'd leave the sound in." : Localization.instance.Localize("$azu_rl_equipSelected"));
			((Component)((Component)personalLoadoutGui.m_sellButton).transform.Find("Image")).gameObject.SetActive(false);
			if (!RapidLoadoutsPlugin.HasAuga)
			{
				((Component)((Component)personalLoadoutGui.m_sellButton).transform.Find("Image (1)")).gameObject.SetActive(true);
				((Component)((Component)personalLoadoutGui.m_sellButton).transform.parent).gameObject.SetActive(false);
			}
			((Transform)val.GetComponent<RectTransform>()).localPosition = new Vector3(250f, 0f, 0f);
			Object.Destroy((Object)(object)((Component)Utils.FindChild(val.transform, "SellPanel", (IterativeSearchType)0)).gameObject);
			Object.Destroy((Object)(object)((Component)Utils.FindChild(val.transform, "border (1)", (IterativeSearchType)0)).gameObject);
			Object.Destroy((Object)(object)((Component)Utils.FindChild(val.transform, "bkg", (IterativeSearchType)0)).gameObject);
			PersonalLoadoutGui.m_listRoot = ((Component)Utils.FindChild(val.transform, "ListRoot", (IterativeSearchType)0)).GetComponent<RectTransform>();
			PersonalLoadoutGui.m_listElement = ((Component)Utils.FindChild(val.transform, "ItemElement", (IterativeSearchType)0)).gameObject;
			personalLoadoutGui.m_listScroll = ((Component)Utils.FindChild(val.transform, RapidLoadoutsPlugin.HasAuga ? "ScrollBar" : "ItemScroll", (IterativeSearchType)0)).GetComponent<Scrollbar>();
			PersonalLoadoutGui.m_itemEnsureVisible = ((Component)Utils.FindChild(val.transform, RapidLoadoutsPlugin.HasAuga ? "ItemListBkg" : "Items", (IterativeSearchType)0)).GetComponent<ScrollRectEnsureVisible>();
			personalLoadoutGui.m_coinText = ((Component)val.transform.Find("Store/" + (RapidLoadoutsPlugin.HasAuga ? "DividerMedium/" : "") + "coins/coins")).GetComponent<TMP_Text>();
			personalLoadoutGui.m_coinIcon = ((Component)val.transform.Find("Store/" + (RapidLoadoutsPlugin.HasAuga ? "DividerMedium/" : "") + "coins/coin icon" + (RapidLoadoutsPlugin.HasAuga ? "/coin icon" : ""))).GetComponent<Image>();
			if (!RapidLoadoutsPlugin.HasAuga)
			{
				RectTransform component = ((Component)val.transform.Find("Store/coins/coin icon")).GetComponent<RectTransform>();
				component.anchoredPosition += new Vector2(0f, 5f);
				RectTransform component2 = ((Component)val.transform.Find("Store/coins")).GetComponent<RectTransform>();
				component2.anchoredPosition += new Vector2(35f, 0f);
			}
			personalLoadoutGui.m_topicText = ((Component)Utils.FindChild(val.transform, RapidLoadoutsPlugin.HasAuga ? "Topic" : "topic", (IterativeSearchType)0)).GetComponent<TMP_Text>();
			personalLoadoutGui.m_buyEffects = itemsetGui.m_buyEffects;
			personalLoadoutGui.m_sellEffects = itemsetGui.m_sellEffects;
			personalLoadoutGui.m_hideDistance = itemsetGui.m_hideDistance;
			PersonalLoadoutGui.m_itemSpacing = PurchasableLoadoutGui.m_itemSpacing;
			PersonalLoadoutGui.m_coinPrefab = PurchasableLoadoutGui.m_coinPrefab;
			PersonalLoadoutGui.m_itemlistBaseSize = PurchasableLoadoutGui.m_itemlistBaseSize;
			((Component)Utils.FindChild(newRootPanel.transform, "border (1)", (IterativeSearchType)0)).GetComponent<RectTransform>().anchorMax = new Vector2(2f, 1f);
		}
	}
}
namespace Microsoft.CodeAnalysis
{
	[<4d994f20-9beb-4b57-bf02-e461a8340deb>Embedded]
	[CompilerGenerated]
	internal sealed class <4d994f20-9beb-4b57-bf02-e461a8340deb>EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	[<4d994f20-9beb-4b57-bf02-e461a8340deb>Embedded]
	[CompilerGenerated]
	internal sealed class <677e2c7d-d416-433e-a0ea-eb39a549f05f>NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public <677e2c7d-d416-433e-a0ea-eb39a549f05f>NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public <677e2c7d-d416-433e-a0ea-eb39a549f05f>NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	[CompilerGenerated]
	[<4d994f20-9beb-4b57-bf02-e461a8340deb>Embedded]
	internal sealed class <50798643-82e9-4a2b-a8b0-55a78b580a9e>NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public <50798643-82e9-4a2b-a8b0-55a78b580a9e>NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[<4d994f20-9beb-4b57-bf02-e461a8340deb>Embedded]
	[CompilerGenerated]
	[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 ServerSync
{
	[<677e2c7d-d416-433e-a0ea-eb39a549f05f>Nullable(0)]
	[PublicAPI]
	[<50798643-82e9-4a2b-a8b0-55a78b580a9e>NullableContext(1)]
	internal abstract class OwnConfigEntryBase
	{
		[<677e2c7d-d416-433e-a0ea-eb39a549f05f>Nullable(2)]
		public object LocalBaseValue;

		public bool SynchronizedConfig = true;

		public abstract ConfigEntryBase BaseConfig { get; }
	}
	[PublicAPI]
	[<677e2c7d-d416-433e-a0ea-eb39a549f05f>Nullable(0)]
	[<50798643-82e9-4a2b-a8b0-55a78b580a9e>NullableContext(1)]
	internal class SyncedConfigEntry<[<677e2c7d-d416-433e-a0ea-eb39a549f05f>Nullable(2)] T> : OwnConfigEntryBase
	{
		public readonly ConfigEntry<T> SourceConfig;

		public override ConfigEntryBase BaseConfig => (ConfigEntryBase)(object)SourceConfig;

		public T Value
		{
			get
			{
				return SourceConfig.Value;
			}
			set
			{
				SourceConfig.Value = value;
			}
		}

		public SyncedConfigEntry(ConfigEntry<T> sourceConfig)
		{
			SourceConfig = sourceConfig;
		}

		public void AssignLocalValue(T value)
		{
			if (LocalBaseValue == null)
			{
				Value = value;
			}
			else
			{
				LocalBaseValue = value;
			}
		}
	}
	[<677e2c7d-d416-433e-a0ea-eb39a549f05f>Nullable(0)]
	[<50798643-82e9-4a2b-a8b0-55a78b580a9e>NullableContext(2)]
	internal abstract class CustomSyncedValueBase
	{
		public object LocalBaseValue;

		[<677e2c7d-d416-433e-a0ea-eb39a549f05f>Nullable(1)]
		public readonly string Identifier;

		[<677e2c7d-d416-433e-a0ea-eb39a549f05f>Nullable(1)]
		public readonly Type Type;

		private object boxedValue;

		protected bool localIsOwner;

		public readonly int Priority;

		public object BoxedValue
		{
			get
			{
				return boxedValue;
			}
			set
			{
				boxedValue = value;
				this.ValueChanged?.Invoke();
			}
		}

		public event Action ValueChanged;

		[<50798643-82e9-4a2b-a8b0-55a78b580a9e>NullableContext(1)]
		protected CustomSyncedValueBase(ConfigSync configSync, string identifier, Type type, int priority)
		{
			Priority = priority;
			Identifier = identifier;
			Type = type;
			configSync.AddCustomValue(this);
			localIsOwner = configSync.IsSourceOfTruth;
			configSync.SourceOfTruthChanged += delegate(bool truth)
			{
				localIsOwner = truth;
			};
		}
	}
	[PublicAPI]
	[<677e2c7d-d416-433e-a0ea-eb39a549f05f>Nullable(0)]
	[<50798643-82e9-4a2b-a8b0-55a78b580a9e>NullableContext(1)]
	internal sealed class CustomSyncedValue<[<677e2c7d-d416-433e-a0ea-eb39a549f05f>Nullable(2)] T> : CustomSyncedValueBase
	{
		public T Value
		{
			get
			{
				return (T)base.BoxedValue;
			}
			set
			{
				base.BoxedValue = value;
			}
		}

		public CustomSyncedValue(ConfigSync configSync, string identifier, T value = default(T), int priority = 0)
			: base(configSync, identifier, typeof(T), priority)
		{
			Value = value;
		}

		public void AssignLocalValue(T value)
		{
			if (localIsOwner)
			{
				Value = value;
			}
			else
			{
				LocalBaseValue = value;
			}
		}
	}
	internal class ConfigurationManagerAttributes
	{
		[UsedImplicitly]
		public bool? ReadOnly = false;
	}
	[<50798643-82e9-4a2b-a8b0-55a78b580a9e>NullableContext(1)]
	[<677e2c7d-d416-433e-a0ea-eb39a549f05f>Nullable(0)]
	[PublicAPI]
	internal class ConfigSync
	{
		[<50798643-82e9-4a2b-a8b0-55a78b580a9e>NullableContext(0)]
		[HarmonyPatch(typeof(ZRpc), "HandlePackage")]
		private static class SnatchCurrentlyHandlingRPC
		{
			[<677e2c7d-d416-433e-a0ea-eb39a549f05f>Nullable(2)]
			public static ZRpc currentRpc;

			[<50798643-82e9-4a2b-a8b0-55a78b580a9e>NullableContext(1)]
			[HarmonyPrefix]
			private static void Prefix(ZRpc __instance)
			{
				currentRpc = __instance;
			}
		}

		[HarmonyPatch(typeof(ZNet), "Awake")]
		[<50798643-82e9-4a2b-a8b0-55a78b580a9e>NullableContext(0)]
		internal static class RegisterRPCPatch
		{
			[<50798643-82e9-4a2b-a8b0-55a78b580a9e>NullableContext(1)]
			[HarmonyPostfix]
			private static void Postfix(ZNet __instance)
			{
				isServer = __instance.IsServer();
				foreach (ConfigSync configSync2 in configSyncs)
				{
					ZRoutedRpc.instance.Register<ZPackage>(configSync2.Name + " ConfigSync", (Action<long, ZPackage>)configSync2.RPC_FromOtherClientConfigSync);
					if (isServer)
					{
						configSync2.InitialSyncDone = true;
						Debug.Log((object)("Registered '" + configSync2.Name + " ConfigSync' RPC - waiting for incoming connections"));
					}
				}
				if (isServer)
				{
					((MonoBehaviour)__instance).StartCoroutine(WatchAdminListChanges());
				}
				[<50798643-82e9-4a2b-a8b0-55a78b580a9e>NullableContext(1)]
				static void SendAdmin(List<ZNetPeer> peers, bool isAdmin)
				{
					ZPackage package = ConfigsToPackage(null, null, new PackageEntry[1]
					{
						new PackageEntry
						{
							section = "Internal",
							key = "lockexempt",
							type = typeof(bool),
							value = isAdmin
						}
					});
					ConfigSync configSync = configSyncs.First();
					if (configSync != null)
					{
						((MonoBehaviour)ZNet.instance).StartCoroutine(configSync.sendZPackage(peers, package));
					}
				}
				[<50798643-82e9-4a2b-a8b0-55a78b580a9e>NullableContext(1)]
				static IEnumerator WatchAdminListChanges()
				{
					MethodInfo listContainsId = AccessTools.DeclaredMethod(typeof(ZNet), "ListContainsId", (Type[])null, (Type[])null);
					SyncedList adminList = (SyncedList)AccessTools.DeclaredField(typeof(ZNet), "m_adminList").GetValue(ZNet.instance);
					List<string> CurrentList = new List<string>(adminList.GetList());
					while (true)
					{
						yield return (object)new WaitForSeconds(30f);
						if (!adminList.GetList().SequenceEqual(CurrentList))
						{
							CurrentList = new List<string>(adminList.GetList());
							List<ZNetPeer> adminPeer = ZNet.instance.GetPeers().Where(delegate(ZNetPeer p)
							{
								string hostName = p.m_rpc.GetSocket().GetHostName();
								return ((object)listContainsId == null) ? adminList.Contains(hostName) : ((bool)listContainsId.Invoke(ZNet.instance, new object[2] { adminList, hostName }));
							}).ToList();
							List<ZNetPeer> nonAdminPeer = ZNet.instance.GetPeers().Except(adminPeer).ToList();
							SendAdmin(nonAdminPeer, isAdmin: false);
							SendAdmin(adminPeer, isAdmin: true);
						}
					}
				}
			}
		}

		[<50798643-82e9-4a2b-a8b0-55a78b580a9e>NullableContext(0)]
		[HarmonyPatch(typeof(ZNet), "OnNewConnection")]
		private static class RegisterClientRPCPatch
		{
			[HarmonyPostfix]
			[<50798643-82e9-4a2b-a8b0-55a78b580a9e>NullableContext(1)]
			private static void Postfix(ZNet __instance, ZNetPeer peer)
			{
				if (__instance.IsServer())
				{
					return;
				}
				foreach (ConfigSync configSync in configSyncs)
				{
					peer.m_rpc.Register<ZPackage>(configSync.Name + " ConfigSync", (Action<ZRpc, ZPackage>)configSync.RPC_FromServerConfigSync);
				}
			}
		}

		[<50798643-82e9-4a2b-a8b0-55a78b580a9e>NullableContext(0)]
		private class ParsedConfigs
		{
			[<677e2c7d-d416-433e-a0ea-eb39a549f05f>Nullable(new byte[] { 1, 1, 2 })]
			public readonly Dictionary<OwnConfigEntryBase, object> configValues = new Dictionary<OwnConfigEntryBase, object>();

			[<677e2c7d-d416-433e-a0ea-eb39a549f05f>Nullable(new byte[] { 1, 1, 2 })]
			public readonly Dictionary<CustomSyncedValueBase, object> customValues = new Dictionary<CustomSyncedValueBase, object>();
		}

		[<50798643-82e9-4a2b-a8b0-55a78b580a9e>NullableContext(0)]
		[HarmonyPatch(typeof(ZNet), "Shutdown")]
		private class ResetConfigsOnShutdown
		{
			[HarmonyPostfix]
			private static void Postfix()
			{
				ProcessingServerUpdate = true;
				foreach (ConfigSync configSync in configSyncs)
				{
					configSync.resetConfigsFromServer();
					configSync.IsSourceOfTruth = true;
					configSync.InitialSyncDone = false;
				}
				ProcessingServerUpdate = false;
			}
		}

		[HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")]
		[<677e2c7d-d416-433e-a0ea-eb39a549f05f>Nullable(0)]
		private class SendConfigsAfterLogin
		{
			[<677e2c7d-d416-433e-a0ea-eb39a549f05f>Nullable(0)]
			private class BufferingSocket : ISocket
			{
				public volatile bool finished = false;

				public volatile int versionMatchQueued = -1;

				public readonly List<ZPackage> Package = new List<ZPackage>();

				public readonly ISo