Decompiled source of BazaarLoadout v0.4.0

BazaarLoadout.dll

Decompiled 12 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using R2API;
using R2API.Networking;
using R2API.Networking.Interfaces;
using R2API.Utils;
using RoR2;
using RoR2.Skills;
using RoR2.UI;
using TMPro;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.UI;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BazaarLoadout
{
	internal class BodyGrantTracker : MonoBehaviour
	{
		public readonly Dictionary<ItemIndex, int> Attributed = new Dictionary<ItemIndex, int>();

		public readonly Dictionary<BodyIndex, Dictionary<ItemIndex, int>> Reclaimed = new Dictionary<BodyIndex, Dictionary<ItemIndex, int>>();

		public readonly List<GameObject> HudElements = new List<GameObject>();

		public int Generation;

		public bool Calibrated;

		public static BodyGrantTracker GetOrAdd(CharacterMaster master)
		{
			if (!Object.op_Implicit((Object)(object)master))
			{
				return null;
			}
			BodyGrantTracker component = ((Component)master).GetComponent<BodyGrantTracker>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				return ((Component)master).gameObject.AddComponent<BodyGrantTracker>();
			}
			return component;
		}
	}
	internal static class ClientHudCleanup
	{
		private const float AttributeDelay = 2f;

		private static readonly List<GameObject> tracked = new List<GameObject>();

		private static HashSet<GameObject> before;

		private static int generation;

		public static void OnRequestSent()
		{
			before = (Plugin.CleanUpCharacterHudElements.Value ? SwapService.CaptureHudChildren() : null);
		}

		public static void OnSwapRefused()
		{
			before = null;
		}

		public static void OnSwapConfirmed()
		{
			if (before != null)
			{
				SwapService.DestroyHudElements(tracked);
				HashSet<GameObject> snapshot = before;
				before = null;
				Plugin.RunDelayed(AttributeRoutine(snapshot, ++generation));
			}
		}

		private static IEnumerator AttributeRoutine(HashSet<GameObject> snapshot, int expected)
		{
			yield return (object)new WaitForSecondsRealtime(2f);
			if (expected == generation)
			{
				SwapService.AttributeNewHudElements(tracked, snapshot);
			}
		}
	}
	internal static class Commands
	{
		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void CCBody(ConCommandArgs args)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Invalid comparison between Unknown and I4
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			if (!HostOnly(args, "bl_body"))
			{
				return;
			}
			NetworkUser val = ResolveUser(args);
			if (!Object.op_Implicit((Object)(object)val))
			{
				Print("No player to act on.");
				return;
			}
			if (((ConCommandArgs)(ref args)).Count < 1)
			{
				Print("Usage: bl_body <bodyName|survivorName>   (see bl_list)");
				return;
			}
			string argString = ((ConCommandArgs)(ref args)).GetArgString(0);
			BodyIndex val2 = LoadoutQuery.ResolveBody(argString);
			string error;
			if ((int)val2 == -1)
			{
				Print("Unknown survivor '" + argString + "'. Try bl_list.");
			}
			else if (SwapService.SetBody(val, val2, out error))
			{
				Print("Now playing " + BodyCatalog.GetBodyName(val2) + ".");
				PrintNotice();
			}
			else
			{
				Print(error);
			}
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void CCSkill(ConCommandArgs args)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			if (!HostOnly(args, "bl_skill"))
			{
				return;
			}
			NetworkUser val = ResolveUser(args);
			if (!Object.op_Implicit((Object)(object)val))
			{
				Print("No player to act on.");
				return;
			}
			if (((ConCommandArgs)(ref args)).Count < 2)
			{
				Print("Usage: bl_skill <slot> <variant>   (see bl_skills)");
				return;
			}
			int argInt = ((ConCommandArgs)(ref args)).GetArgInt(0);
			uint argUInt = ((ConCommandArgs)(ref args)).GetArgUInt(1);
			if (SwapService.SetSkill(val, argInt, argUInt, out var error))
			{
				BodyIndex bodyIndex = CurrentBodyIndex(val);
				Print(LoadoutQuery.GetSlotLabel(bodyIndex, argInt) + " -> " + LoadoutQuery.GetVariantName(bodyIndex, argInt, (int)argUInt));
				PrintNotice();
			}
			else
			{
				Print(error);
			}
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void CCUI(ConCommandArgs args)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			if (HostOnly(args, "bl_ui"))
			{
				NetworkUser val = ResolveUser(args);
				if (!Object.op_Implicit((Object)(object)val))
				{
					Print("No player to act on.");
				}
				else
				{
					LoadoutUI.Toggle(val);
				}
			}
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void CCSkin(ConCommandArgs args)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			if (!HostOnly(args, "bl_skin"))
			{
				return;
			}
			NetworkUser val = ResolveUser(args);
			if (!Object.op_Implicit((Object)(object)val))
			{
				Print("No player to act on.");
				return;
			}
			if (((ConCommandArgs)(ref args)).Count < 1)
			{
				Print("Usage: bl_skin <index>   (see bl_skins)");
				return;
			}
			uint argUInt = ((ConCommandArgs)(ref args)).GetArgUInt(0);
			if (SwapService.SetSkin(val, argUInt, out var error))
			{
				Print("Skin -> " + LoadoutQuery.GetSkinName(CurrentBodyIndex(val), (int)argUInt));
			}
			else
			{
				Print(error);
			}
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void CCList(ConCommandArgs args)
		{
			//IL_0000: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			if (!HostOnly(args, "bl_list"))
			{
				return;
			}
			List<SurvivorDef> survivors = LoadoutQuery.GetSurvivors();
			StringBuilder stringBuilder = new StringBuilder($"{survivors.Count} survivors:\n");
			foreach (SurvivorDef item in survivors)
			{
				BodyIndex bodyIndex = LoadoutQuery.GetBodyIndex(item);
				stringBuilder.AppendLine($"  {BodyCatalog.GetBodyName(bodyIndex),-28} {LoadoutQuery.GetSurvivorName(item)}");
			}
			Print(stringBuilder.ToString());
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void CCSkills(ConCommandArgs args)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Invalid comparison between Unknown and I4
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			if (!HostOnly(args, "bl_skills"))
			{
				return;
			}
			NetworkUser val = ResolveUser(args);
			BodyIndex val2 = CurrentBodyIndex(val);
			if ((int)val2 == -1)
			{
				Print("No current body.");
				return;
			}
			int skillSlotCount = LoadoutQuery.GetSkillSlotCount(val2);
			StringBuilder stringBuilder = new StringBuilder($"{BodyCatalog.GetBodyName(val2)} has {skillSlotCount} loadout slots:\n");
			for (int i = 0; i < skillSlotCount; i++)
			{
				uint skillVariant = val.master.loadout.bodyLoadoutManager.GetSkillVariant(val2, i);
				string arg = (LoadoutQuery.IsSlotHidden(val2, i) ? "  [hidden - character-controlled]" : "");
				stringBuilder.AppendLine($"  slot {i} ({LoadoutQuery.GetSlotLabel(val2, i)}){arg}:");
				int variantCount = LoadoutQuery.GetVariantCount(val2, i);
				for (int j = 0; j < variantCount; j++)
				{
					string arg2 = ((j == skillVariant) ? "*" : " ");
					stringBuilder.AppendLine($"    {arg2} {j}  {LoadoutQuery.GetVariantName(val2, i, j)}");
				}
			}
			Print(stringBuilder.ToString());
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void CCSkins(ConCommandArgs args)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Invalid comparison between Unknown and I4
			//IL_003b: 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)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			if (!HostOnly(args, "bl_skins"))
			{
				return;
			}
			NetworkUser val = ResolveUser(args);
			BodyIndex val2 = CurrentBodyIndex(val);
			if ((int)val2 == -1)
			{
				Print("No current body.");
				return;
			}
			uint skinIndex = val.master.loadout.bodyLoadoutManager.GetSkinIndex(val2);
			int skinCount = LoadoutQuery.GetSkinCount(val2);
			StringBuilder stringBuilder = new StringBuilder(BodyCatalog.GetBodyName(val2) + " skins:\n");
			for (int i = 0; i < skinCount; i++)
			{
				string arg = ((i == skinIndex) ? "*" : " ");
				stringBuilder.AppendLine($"  {arg} {i}  {LoadoutQuery.GetSkinName(val2, i)}");
			}
			Print(stringBuilder.ToString());
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void CCStationHere(ConCommandArgs args)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			if (HostOnly(args, "bl_station_here"))
			{
				CharacterBody val = Plugin.FindAnyPlayerBody();
				if (!Object.op_Implicit((Object)(object)val))
				{
					Print("No player body.");
					return;
				}
				Vector3 val2 = StationSpawner.DropToGround(val.footPosition);
				float num = ((Component)val).transform.eulerAngles.y + 180f;
				Plugin.StationPosition.Value = Plugin.FormatVector3(val2);
				Plugin.StationYaw.Value = num;
				StationSpawner.Spawn(val2, Quaternion.Euler(0f, num, 0f));
				Print($"Station moved to {Plugin.StationPosition.Value} (yaw {num:0.#}) and saved to config.");
			}
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void CCStationClear(ConCommandArgs args)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if (HostOnly(args, "bl_station_clear"))
			{
				Plugin.StationPosition.Value = "";
				Print("Station position cleared; it will auto-place next stage.");
			}
		}

		private static bool HostOnly(ConCommandArgs args, string command)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active)
			{
				Print("BazaarLoadout console commands are host-only. Use the station in the Bazaar instead.");
				return false;
			}
			if (Object.op_Implicit((Object)(object)args.sender) && args.sender.localUser == null)
			{
				Plugin.Log.LogInfo((object)("Ignored " + command + " from " + args.sender.userName + ": console commands are host-only."));
				return false;
			}
			return true;
		}

		private static NetworkUser ResolveUser(ConCommandArgs args)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)args.sender))
			{
				return args.sender;
			}
			IList<NetworkUser> readOnlyInstancesList = NetworkUser.readOnlyInstancesList;
			if (readOnlyInstancesList == null || readOnlyInstancesList.Count <= 0)
			{
				return null;
			}
			return readOnlyInstancesList[0];
		}

		private static BodyIndex CurrentBodyIndex(NetworkUser user)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			CharacterBody val = ((Object.op_Implicit((Object)(object)user) && Object.op_Implicit((Object)(object)user.master)) ? user.master.GetBody() : null);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return (BodyIndex)(-1);
			}
			return val.bodyIndex;
		}

		private static void Print(string message)
		{
			Debug.Log((object)("[BazaarLoadout] " + message));
		}

		private static void PrintNotice()
		{
			if (!string.IsNullOrEmpty(SwapService.LastNotice))
			{
				Print(SwapService.LastNotice);
			}
		}
	}
	internal static class LoadoutQuery
	{
		public static CharacterBody GetBodyPrefabComponent(BodyIndex bodyIndex)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			if ((int)bodyIndex == -1)
			{
				return null;
			}
			return BodyCatalog.GetBodyPrefabBodyComponent(bodyIndex);
		}

		public static GenericSkill[] GetSkillSlots(BodyIndex bodyIndex)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			CharacterBody bodyPrefabComponent = GetBodyPrefabComponent(bodyIndex);
			if (!Object.op_Implicit((Object)(object)bodyPrefabComponent))
			{
				return Array.Empty<GenericSkill>();
			}
			return ((Component)bodyPrefabComponent).GetComponents<GenericSkill>();
		}

		public static int GetSkillSlotCount(BodyIndex bodyIndex)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return GetSkillSlots(bodyIndex).Length;
		}

		public static SkillFamily GetSkillFamily(BodyIndex bodyIndex, int slot)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			GenericSkill[] skillSlots = GetSkillSlots(bodyIndex);
			if (slot < 0 || slot >= skillSlots.Length || !Object.op_Implicit((Object)(object)skillSlots[slot]))
			{
				return null;
			}
			return skillSlots[slot].skillFamily;
		}

		public static int GetVariantCount(BodyIndex bodyIndex, int slot)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return (GetSkillFamily(bodyIndex, slot)?.variants?.Length).GetValueOrDefault();
		}

		public static SkillDef GetVariantSkillDef(BodyIndex bodyIndex, int slot, int variant)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			SkillFamily skillFamily = GetSkillFamily(bodyIndex, slot);
			if (skillFamily?.variants == null || variant < 0 || variant >= skillFamily.variants.Length)
			{
				return null;
			}
			return skillFamily.variants[variant].skillDef;
		}

		public static UnlockableDef GetVariantUnlockable(BodyIndex bodyIndex, int slot, int variant)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			SkillFamily skillFamily = GetSkillFamily(bodyIndex, slot);
			if (skillFamily?.variants == null || variant < 0 || variant >= skillFamily.variants.Length)
			{
				return null;
			}
			return skillFamily.variants[variant].unlockableDef;
		}

		public static string GetVariantName(BodyIndex bodyIndex, int slot, int variant)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			SkillDef variantSkillDef = GetVariantSkillDef(bodyIndex, slot, variant);
			if (!Object.op_Implicit((Object)(object)variantSkillDef))
			{
				return "<none>";
			}
			string text = Language.GetString(variantSkillDef.skillNameToken);
			if (!string.IsNullOrEmpty(text) && !(text == variantSkillDef.skillNameToken))
			{
				return text;
			}
			return variantSkillDef.skillName;
		}

		public static string GetSlotLabel(BodyIndex bodyIndex, int slot)
		{
			//IL_0000: 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)
			GenericSkill[] skillSlots = GetSkillSlots(bodyIndex);
			if (slot < 0 || slot >= skillSlots.Length)
			{
				return "slot" + slot;
			}
			CharacterBody bodyPrefabComponent = GetBodyPrefabComponent(bodyIndex);
			SkillLocator val = (Object.op_Implicit((Object)(object)bodyPrefabComponent) ? ((Component)bodyPrefabComponent).GetComponent<SkillLocator>() : null);
			if (Object.op_Implicit((Object)(object)val))
			{
				GenericSkill val2 = skillSlots[slot];
				if ((Object)(object)val.primary == (Object)(object)val2)
				{
					return "Primary";
				}
				if ((Object)(object)val.secondary == (Object)(object)val2)
				{
					return "Secondary";
				}
				if ((Object)(object)val.utility == (Object)(object)val2)
				{
					return "Utility";
				}
				if ((Object)(object)val.special == (Object)(object)val2)
				{
					return "Special";
				}
			}
			return "Extra" + slot;
		}

		public static bool IsSlotHidden(BodyIndex bodyIndex, int slot)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			GenericSkill[] skillSlots = GetSkillSlots(bodyIndex);
			if (slot >= 0 && slot < skillSlots.Length && Object.op_Implicit((Object)(object)skillSlots[slot]))
			{
				return skillSlots[slot].hideInLoadoutSelect;
			}
			return false;
		}

		public static int GetSkinCount(BodyIndex bodyIndex)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			if ((int)bodyIndex != -1)
			{
				return SkinCatalog.GetBodySkinCount(bodyIndex);
			}
			return 0;
		}

		public static string GetSkinName(BodyIndex bodyIndex, int skinIndex)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			SkinDef bodySkinDef = SkinCatalog.GetBodySkinDef(bodyIndex, skinIndex);
			if (!Object.op_Implicit((Object)(object)bodySkinDef))
			{
				return "<none>";
			}
			string text = Language.GetString(bodySkinDef.nameToken);
			if (!string.IsNullOrEmpty(text) && !(text == bodySkinDef.nameToken))
			{
				return text;
			}
			return ((Object)bodySkinDef).name;
		}

		public static List<SurvivorDef> GetSurvivors()
		{
			List<SurvivorDef> list = new List<SurvivorDef>();
			foreach (SurvivorDef orderedSurvivorDef in SurvivorCatalog.orderedSurvivorDefs)
			{
				if (Object.op_Implicit((Object)(object)orderedSurvivorDef) && Object.op_Implicit((Object)(object)orderedSurvivorDef.bodyPrefab))
				{
					list.Add(orderedSurvivorDef);
				}
			}
			return list;
		}

		public static BodyIndex GetBodyIndex(SurvivorDef def)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)def) || !Object.op_Implicit((Object)(object)def.bodyPrefab))
			{
				return (BodyIndex)(-1);
			}
			CharacterBody component = def.bodyPrefab.GetComponent<CharacterBody>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				return (BodyIndex)(-1);
			}
			return component.bodyIndex;
		}

		public static string GetSurvivorName(SurvivorDef def)
		{
			if (!Object.op_Implicit((Object)(object)def))
			{
				return "<none>";
			}
			string text = Language.GetString(def.displayNameToken);
			if (!string.IsNullOrEmpty(text) && !(text == def.displayNameToken))
			{
				return text;
			}
			return def.cachedName;
		}

		public static bool IsSurvivorUnlocked(SurvivorDef def)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Invalid comparison between Unknown and I4
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)def))
			{
				return false;
			}
			if (!Object.op_Implicit((Object)(object)def.unlockableDef))
			{
				return true;
			}
			if ((int)def.survivorIndex != -1 && SurvivorCatalog.SurvivorIsUnlockedOnThisClient(def.survivorIndex))
			{
				return true;
			}
			return HasUnlockable(def.unlockableDef);
		}

		public static bool HasUnlockable(UnlockableDef unlockable)
		{
			if (!Object.op_Implicit((Object)(object)unlockable))
			{
				return true;
			}
			foreach (LocalUser readOnlyLocalUsers in LocalUserManager.readOnlyLocalUsersList)
			{
				if (((readOnlyLocalUsers != null) ? readOnlyLocalUsers.userProfile : null) != null && readOnlyLocalUsers.userProfile.HasUnlockable(unlockable))
				{
					return true;
				}
			}
			return false;
		}

		public static bool UserHasUnlockable(NetworkUser user, UnlockableDef unlockable)
		{
			if (!Object.op_Implicit((Object)(object)unlockable))
			{
				return true;
			}
			if (!Object.op_Implicit((Object)(object)user))
			{
				return false;
			}
			LocalUser localUser = user.localUser;
			UserProfile val = ((localUser != null) ? localUser.userProfile : null);
			if (val != null)
			{
				return val.HasUnlockable(unlockable);
			}
			if (user.unlockables != null)
			{
				return user.unlockables.Contains(unlockable);
			}
			return false;
		}

		public static bool CheckUnlocksFor(NetworkUser user, BodyIndex bodyIndex, Loadout loadout, out string error)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			error = null;
			SurvivorDef survivorDef = SurvivorCatalog.GetSurvivorDef(SurvivorCatalog.GetSurvivorIndexFromBodyIndex(bodyIndex));
			if (Object.op_Implicit((Object)(object)survivorDef) && !UserHasUnlockable(user, survivorDef.unlockableDef))
			{
				error = GetSurvivorName(survivorDef) + " isn't unlocked for you.";
				return false;
			}
			if (loadout == null)
			{
				return true;
			}
			int skillSlotCount = GetSkillSlotCount(bodyIndex);
			for (int i = 0; i < skillSlotCount; i++)
			{
				int skillVariant = (int)loadout.bodyLoadoutManager.GetSkillVariant(bodyIndex, i);
				if (!UserHasUnlockable(user, GetVariantUnlockable(bodyIndex, i, skillVariant)))
				{
					error = "\"" + GetVariantName(bodyIndex, i, skillVariant) + "\" isn't unlocked for you.";
					return false;
				}
			}
			int skinIndex = (int)loadout.bodyLoadoutManager.GetSkinIndex(bodyIndex);
			SkinDef bodySkinDef = SkinCatalog.GetBodySkinDef(bodyIndex, skinIndex);
			if (Object.op_Implicit((Object)(object)bodySkinDef) && !UserHasUnlockable(user, bodySkinDef.unlockableDef))
			{
				error = "\"" + GetSkinName(bodyIndex, skinIndex) + "\" isn't unlocked for you.";
				return false;
			}
			return true;
		}

		public static bool IsSurvivorBody(BodyIndex bodyIndex)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			return (int)SurvivorCatalog.GetSurvivorIndexFromBodyIndex(bodyIndex) != -1;
		}

		public static BodyIndex ResolveBody(string query)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Invalid comparison between Unknown and I4
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Invalid comparison between Unknown and I4
			//IL_001c: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrEmpty(query))
			{
				return (BodyIndex)(-1);
			}
			string text = query.Trim();
			BodyIndex val = BodyCatalog.FindBodyIndex(text);
			if ((int)val != -1)
			{
				return val;
			}
			val = BodyCatalog.FindBodyIndex(text + "Body");
			if ((int)val != -1)
			{
				return val;
			}
			int bodyCount = BodyCatalog.bodyCount;
			for (int i = 0; i < bodyCount; i++)
			{
				string bodyName = BodyCatalog.GetBodyName((BodyIndex)i);
				if (string.Equals(bodyName, text, StringComparison.OrdinalIgnoreCase) || string.Equals(bodyName, text + "Body", StringComparison.OrdinalIgnoreCase))
				{
					return (BodyIndex)i;
				}
			}
			foreach (SurvivorDef survivor in GetSurvivors())
			{
				string survivorName = GetSurvivorName(survivor);
				if (!string.IsNullOrEmpty(survivorName) && survivorName.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return GetBodyIndex(survivor);
				}
			}
			return (BodyIndex)(-1);
		}
	}
	public class LoadoutUI : MonoBehaviour
	{
		private struct SurvivorEntry
		{
			public Image background;

			public BodyIndex bodyIndex;
		}

		private struct ChoiceEntry
		{
			public Image background;

			public int slot;

			public int index;

			public bool unlocked;
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__Close;
		}

		private static LoadoutUI instance;

		private NetworkUser user;

		private BodyIndex selectedBody = (BodyIndex)(-1);

		private BodyIndex lastBuiltBody = (BodyIndex)(-1);

		private bool awaitingHost;

		private float awaitingSince;

		private const float HostReplyTimeout = 8f;

		private RectTransform window;

		private RectTransform survivorContent;

		private RectTransform loadoutContent;

		private LayoutElement survivorAreaElement;

		private LayoutElement loadoutAreaElement;

		private TextMeshProUGUI statusText;

		private Image lockedSurvivorCheckbox;

		private Image lockedChoiceCheckbox;

		private readonly List<SurvivorEntry> survivorEntries = new List<SurvivorEntry>();

		private readonly List<ChoiceEntry> choiceEntries = new List<ChoiceEntry>();

		private const float WindowWidth = 1180f;

		private const float MaxWindowHeight = 1000f;

		private const int WindowPadding = 24;

		private const int SurvivorColumns = 6;

		private const int MaxSurvivorRows = 8;

		private const int MaxLoadoutRows = 6;

		private const int GridPadding = 8;

		private const float GridSpacing = 6f;

		private const float SurvivorCellHeight = 38f;

		private const float ChoiceSize = 48f;

		private const float ChoiceRowHeight = 60f;

		private const float RowLabelWidth = 130f;

		private const float ViewportWidth = 1132f;

		private const float Chrome = 290f;

		private static readonly float SurvivorCellWidth = Mathf.Floor(181f) - 1f;

		private static readonly float SurvivorGridWidth = 16f + 6f * SurvivorCellWidth + 30f;

		private static readonly Color WindowColor = new Color(0.07f, 0.08f, 0.1f, 0.97f);

		private static readonly Color PanelColor = new Color(0.12f, 0.13f, 0.16f, 0.9f);

		private static readonly Color RowColor = new Color(0.16f, 0.17f, 0.21f, 0.85f);

		private static readonly Color ButtonIdle = new Color(0.18f, 0.19f, 0.23f, 1f);

		private static readonly Color ButtonActive = new Color(0.9f, 0.58f, 0.16f, 1f);

		private static readonly Color ButtonLocked = new Color(0.14f, 0.14f, 0.16f, 1f);

		private static readonly Color TextColor = new Color(0.9f, 0.91f, 0.94f, 1f);

		private static readonly Color DimTextColor = new Color(0.55f, 0.56f, 0.6f, 1f);

		public static bool IsOpen => (Object)(object)instance != (Object)null;

		private static bool IsHost => NetworkServer.active;

		private static bool ShowLockedSurvivors
		{
			get
			{
				if (IsHost)
				{
					return Plugin.ShowLockedSurvivors.Value;
				}
				return false;
			}
		}

		private static bool ShowLockedChoices
		{
			get
			{
				if (IsHost)
				{
					return Plugin.ShowLockedChoices.Value;
				}
				return false;
			}
		}

		public static void Toggle(NetworkUser forUser)
		{
			if (IsOpen)
			{
				Close();
			}
			else
			{
				Open(forUser);
			}
		}

		public static void Open(NetworkUser forUser)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: 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)
			Close();
			if (Object.op_Implicit((Object)(object)forUser))
			{
				GameObject val = new GameObject("BazaarLoadoutUI");
				val.SetActive(false);
				Canvas obj = val.AddComponent<Canvas>();
				obj.renderMode = (RenderMode)0;
				obj.sortingOrder = 500;
				CanvasScaler obj2 = val.AddComponent<CanvasScaler>();
				obj2.uiScaleMode = (ScaleMode)1;
				obj2.referenceResolution = new Vector2(1920f, 1080f);
				obj2.screenMatchMode = (ScreenMatchMode)0;
				obj2.matchWidthOrHeight = 0.5f;
				val.AddComponent<GraphicRaycaster>();
				MPEventSystemProvider val2 = val.AddComponent<MPEventSystemProvider>();
				val2.fallBackToMainEventSystem = true;
				val.AddComponent<MPEventSystemLocator>();
				CursorOpener obj3 = val.AddComponent<CursorOpener>();
				LoadoutUI loadoutUI = val.AddComponent<LoadoutUI>();
				loadoutUI.user = forUser;
				CharacterBody val3 = (Object.op_Implicit((Object)(object)forUser.master) ? forUser.master.GetBody() : null);
				loadoutUI.selectedBody = (Object.op_Implicit((Object)(object)val3) ? val3.bodyIndex : forUser.bodyIndexPreference);
				loadoutUI.Build(val);
				instance = loadoutUI;
				val.SetActive(true);
				obj3.forceCursorForGamePad = true;
				LocalUser localUser = forUser.localUser;
				MPEventSystem val4 = ((localUser != null) ? localUser.eventSystem : null);
				if (Object.op_Implicit((Object)(object)val4))
				{
					val2.eventSystem = val4;
				}
			}
		}

		public static void Close()
		{
			if (Object.op_Implicit((Object)(object)instance))
			{
				Object.Destroy((Object)(object)((Component)instance).gameObject);
			}
			instance = null;
		}

		public static void OnApplyResult(NetworkUser forUser, bool success, string message)
		{
			if (Object.op_Implicit((Object)(object)instance) && !((Object)(object)instance.user != (Object)(object)forUser))
			{
				instance.awaitingHost = false;
				if (success)
				{
					Close();
				}
				else
				{
					instance.SetStatus(string.IsNullOrEmpty(message) ? "The host refused the change." : message);
				}
			}
		}

		private void OnDestroy()
		{
			if ((Object)(object)instance == (Object)(object)this)
			{
				instance = null;
			}
		}

		private void Build(GameObject root)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Expected O, but got Unknown
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Expected O, but got Unknown
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Expected O, but got Unknown
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Expected O, but got Unknown
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Expected O, but got Unknown
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			CreateStretched("Backdrop", root.transform, new Color(0f, 0f, 0f, 0.72f));
			window = CreatePanel("Window", root.transform, WindowColor);
			window.anchorMin = new Vector2(0.5f, 0.5f);
			window.anchorMax = new Vector2(0.5f, 0.5f);
			window.pivot = new Vector2(0.5f, 0.5f);
			window.anchoredPosition = Vector2.zero;
			window.sizeDelta = new Vector2(1180f, 700f);
			VerticalLayoutGroup obj = ((Component)window).gameObject.AddComponent<VerticalLayoutGroup>();
			((LayoutGroup)obj).padding = new RectOffset(24, 24, 20, 20);
			((HorizontalOrVerticalLayoutGroup)obj).spacing = 10f;
			((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false;
			CreateLabel("Title", window, "LOADOUT STATION", 34f, (FontStyles)1, 46f);
			lockedSurvivorCheckbox = CreateHeaderRow(window, "SurvivorHeader", "Survivor", "Show locked characters", new UnityAction(OnToggleShowLockedSurvivors));
			survivorContent = CreateScrollArea(window, "SurvivorArea", out survivorAreaElement, horizontal: true);
			survivorContent.sizeDelta = new Vector2(Mathf.Max(1132f, SurvivorGridWidth), survivorContent.sizeDelta.y);
			GridLayoutGroup obj2 = ((Component)survivorContent).gameObject.AddComponent<GridLayoutGroup>();
			obj2.cellSize = new Vector2(SurvivorCellWidth, 38f);
			obj2.spacing = new Vector2(6f, 6f);
			((LayoutGroup)obj2).padding = new RectOffset(8, 8, 8, 8);
			obj2.constraint = (Constraint)1;
			obj2.constraintCount = 6;
			((LayoutGroup)obj2).childAlignment = (TextAnchor)1;
			lockedChoiceCheckbox = CreateHeaderRow(window, "LoadoutHeader", "Skills and Skins", "Show locked skills & skins", new UnityAction(OnToggleShowLockedChoices));
			loadoutContent = CreateScrollArea(window, "LoadoutArea", out loadoutAreaElement, horizontal: true);
			VerticalLayoutGroup obj3 = ((Component)loadoutContent).gameObject.AddComponent<VerticalLayoutGroup>();
			((LayoutGroup)obj3).padding = new RectOffset(8, 8, 8, 8);
			((HorizontalOrVerticalLayoutGroup)obj3).spacing = 6f;
			((HorizontalOrVerticalLayoutGroup)obj3).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj3).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)obj3).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj3).childForceExpandHeight = false;
			statusText = CreateLabel("Status", window, "Pick a survivor, skills and skin, then Apply.", 18f, (FontStyles)2, 28f);
			((Graphic)statusText).color = DimTextColor;
			CreateButtonRow(window);
			UpdateCheckboxes();
			BuildSurvivorButtons();
			RebuildLoadoutRows();
		}

		private Image CreateHeaderRow(RectTransform parent, string name, string title, string caption, UnityAction onToggle)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = CreateChildRect(name, (Transform)(object)parent);
			AddFixedHeight(val, 32f);
			RectTransform obj = CreateChildRect("Label", (Transform)(object)val);
			obj.anchorMin = Vector2.zero;
			obj.anchorMax = new Vector2(0.55f, 1f);
			obj.offsetMin = Vector2.zero;
			obj.offsetMax = Vector2.zero;
			((TMP_Text)ConfigureText(obj, title, 22f, (FontStyles)1)).alignment = (TextAlignmentOptions)513;
			RectTransform val2 = CreateChildRect("Toggle", (Transform)(object)val);
			val2.anchorMin = new Vector2(0.55f, 0f);
			val2.anchorMax = Vector2.one;
			val2.offsetMin = Vector2.zero;
			val2.offsetMax = Vector2.zero;
			if (IsHost)
			{
				Image val3 = ((Component)val2).gameObject.AddComponent<Image>();
				((Graphic)val3).color = new Color(0f, 0f, 0f, 0f);
				Button obj2 = ((Component)val2).gameObject.AddComponent<Button>();
				((Selectable)obj2).targetGraphic = (Graphic)(object)val3;
				((UnityEvent)obj2.onClick).AddListener(onToggle);
			}
			RectTransform obj3 = CreatePanel("Box", (Transform)(object)val2, ButtonIdle);
			obj3.anchorMin = new Vector2(1f, 0.5f);
			obj3.anchorMax = new Vector2(1f, 0.5f);
			obj3.pivot = new Vector2(1f, 0.5f);
			obj3.sizeDelta = new Vector2(20f, 20f);
			obj3.anchoredPosition = new Vector2(-4f, 0f);
			RectTransform obj4 = CreateChildRect("Caption", (Transform)(object)val2);
			obj4.anchorMin = Vector2.zero;
			obj4.anchorMax = Vector2.one;
			obj4.offsetMin = Vector2.zero;
			obj4.offsetMax = new Vector2(-30f, 0f);
			TextMeshProUGUI obj5 = ConfigureText(obj4, IsHost ? caption : (caption + " (host only)"), 17f, (FontStyles)0);
			((TMP_Text)obj5).alignment = (TextAlignmentOptions)516;
			((Graphic)obj5).color = DimTextColor;
			return ((Component)obj3).GetComponent<Image>();
		}

		private RectTransform CreateScrollArea(RectTransform parent, string name, out LayoutElement heightElement, bool horizontal = false)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = CreateChildRect(name, (Transform)(object)parent);
			heightElement = AddFixedHeight(val, 100f);
			ScrollRect obj = ((Component)val).gameObject.AddComponent<ScrollRect>();
			obj.horizontal = horizontal;
			obj.vertical = true;
			obj.movementType = (MovementType)2;
			obj.scrollSensitivity = 30f;
			obj.verticalScrollbarVisibility = (ScrollbarVisibility)0;
			RectTransform val2 = CreatePanel("Viewport", (Transform)(object)val, PanelColor);
			val2.anchorMin = Vector2.zero;
			val2.anchorMax = Vector2.one;
			val2.offsetMin = Vector2.zero;
			val2.offsetMax = Vector2.zero;
			((Component)val2).gameObject.AddComponent<RectMask2D>();
			obj.viewport = val2;
			RectTransform val3 = CreateChildRect("Content", (Transform)(object)val2);
			if (horizontal)
			{
				val3.anchorMin = new Vector2(0f, 1f);
				val3.anchorMax = new Vector2(0f, 1f);
				val3.pivot = new Vector2(0f, 1f);
				val3.sizeDelta = new Vector2(1132f, 0f);
			}
			else
			{
				val3.anchorMin = new Vector2(0f, 1f);
				val3.anchorMax = new Vector2(1f, 1f);
				val3.pivot = new Vector2(0.5f, 1f);
			}
			val3.anchoredPosition = Vector2.zero;
			obj.content = val3;
			((Component)val3).gameObject.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
			return val3;
		}

		private void ResizeLoadoutWidth()
		{
			//IL_0090: 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)
			if (!Object.op_Implicit((Object)(object)loadoutContent))
			{
				return;
			}
			float num = 1132f;
			for (int i = 0; i < ((Transform)loadoutContent).childCount; i++)
			{
				Transform val = ((Transform)loadoutContent).GetChild(i).Find("Choices");
				if (Object.op_Implicit((Object)(object)val) && val.childCount != 0)
				{
					float num2 = 146f + (float)val.childCount * 48f + (float)(val.childCount - 1) * 6f + 8f;
					num = Mathf.Max(num, num2);
				}
			}
			loadoutContent.sizeDelta = new Vector2(num, loadoutContent.sizeDelta.y);
		}

		private void CreateButtonRow(RectTransform parent)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			RectTransform obj = CreateChildRect("Buttons", (Transform)(object)parent);
			AddFixedHeight(obj, 52f);
			HorizontalLayoutGroup obj2 = ((Component)obj).gameObject.AddComponent<HorizontalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)obj2).spacing = 12f;
			((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = true;
			CreateActionButton(obj, "Apply", ButtonActive, new UnityAction(OnApplyClicked));
			Color buttonIdle = ButtonIdle;
			object obj3 = <>O.<0>__Close;
			if (obj3 == null)
			{
				UnityAction val = Close;
				<>O.<0>__Close = val;
				obj3 = (object)val;
			}
			CreateActionButton(obj, "Close", buttonIdle, (UnityAction)obj3);
		}

		private void ApplyLayout()
		{
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.Clamp(Mathf.CeilToInt((float)survivorEntries.Count / 6f), 1, 8);
			int num2 = Mathf.Clamp((!Object.op_Implicit((Object)(object)loadoutContent)) ? 1 : ((Transform)loadoutContent).childCount, 1, 6);
			while (290f + GridHeight(num, 38f) + GridHeight(num2, 60f) > 1000f)
			{
				if (num2 > 3)
				{
					num2--;
					continue;
				}
				if (num <= 3)
				{
					break;
				}
				num--;
			}
			float num3 = GridHeight(num, 38f);
			float num4 = GridHeight(num2, 60f);
			if (Object.op_Implicit((Object)(object)survivorAreaElement))
			{
				survivorAreaElement.preferredHeight = num3;
				survivorAreaElement.minHeight = num3;
			}
			if (Object.op_Implicit((Object)(object)loadoutAreaElement))
			{
				loadoutAreaElement.preferredHeight = num4;
				loadoutAreaElement.minHeight = num4;
			}
			if (Object.op_Implicit((Object)(object)window))
			{
				window.sizeDelta = new Vector2(1180f, 290f + num3 + num4);
			}
		}

		private static float GridHeight(int rows, float cellHeight)
		{
			return 16f + (float)rows * cellHeight + (float)(rows - 1) * 6f;
		}

		private List<SurvivorDef> GetVisibleSurvivors()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Invalid comparison between Unknown and I4
			List<SurvivorDef> list = new List<SurvivorDef>();
			bool showLockedSurvivors = ShowLockedSurvivors;
			foreach (SurvivorDef survivor in LoadoutQuery.GetSurvivors())
			{
				if ((int)LoadoutQuery.GetBodyIndex(survivor) != -1 && (showLockedSurvivors || LoadoutQuery.IsSurvivorUnlocked(survivor)))
				{
					list.Add(survivor);
				}
			}
			return list;
		}

		private void BuildSurvivorButtons()
		{
			//IL_003d: 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)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: 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_010c: Expected O, but got Unknown
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			survivorEntries.Clear();
			DestroyChildren(survivorContent);
			foreach (SurvivorDef visibleSurvivor in GetVisibleSurvivors())
			{
				BodyIndex bodyIndex = LoadoutQuery.GetBodyIndex(visibleSurvivor);
				bool flag = LoadoutQuery.IsSurvivorUnlocked(visibleSurvivor);
				RectTransform obj = CreatePanel("Survivor_" + visibleSurvivor.cachedName, (Transform)(object)survivorContent, flag ? ButtonIdle : ButtonLocked);
				Image component = ((Component)obj).GetComponent<Image>();
				Button val = ((Component)obj).gameObject.AddComponent<Button>();
				((Selectable)val).targetGraphic = (Graphic)(object)component;
				string survivorName = LoadoutQuery.GetSurvivorName(visibleSurvivor);
				TextMeshProUGUI val2 = CreateLabelIn(obj, flag ? survivorName : (survivorName + " (locked)"), 16f, (FontStyles)0);
				((TMP_Text)val2).enableAutoSizing = true;
				((TMP_Text)val2).fontSizeMin = 9f;
				((TMP_Text)val2).fontSizeMax = 16f;
				if (!flag)
				{
					((Graphic)val2).color = DimTextColor;
				}
				BodyIndex captured = bodyIndex;
				((UnityEvent)val.onClick).AddListener((UnityAction)delegate
				{
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					OnSurvivorClicked(captured);
				});
				survivorEntries.Add(new SurvivorEntry
				{
					background = component,
					bodyIndex = captured
				});
			}
			ApplyLayout();
		}

		private void RebuildLoadoutRows()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Invalid comparison between Unknown and I4
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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_0151: Unknown result type (might be due to invalid IL or missing references)
			choiceEntries.Clear();
			DestroyChildren(loadoutContent);
			BodyIndex val = (lastBuiltBody = selectedBody);
			if ((int)val == -1)
			{
				ApplyLayout();
				return;
			}
			bool showLockedChoices = ShowLockedChoices;
			int skillSlotCount = LoadoutQuery.GetSkillSlotCount(val);
			for (int i = 0; i < skillSlotCount; i++)
			{
				if (LoadoutQuery.IsSlotHidden(val, i))
				{
					continue;
				}
				int variantCount = LoadoutQuery.GetVariantCount(val, i);
				if (variantCount <= 1)
				{
					continue;
				}
				RectTransform val2 = null;
				for (int j = 0; j < variantCount; j++)
				{
					bool flag = LoadoutQuery.HasUnlockable(LoadoutQuery.GetVariantUnlockable(val, i, j));
					if (flag || showLockedChoices)
					{
						val2 = val2 ?? CreateChoiceRow(LoadoutQuery.GetSlotLabel(val, i));
						SkillDef variantSkillDef = LoadoutQuery.GetVariantSkillDef(val, i, j);
						AddChoiceButton(val2, i, j, Object.op_Implicit((Object)(object)variantSkillDef) ? variantSkillDef.icon : null, LoadoutQuery.GetVariantName(val, i, j), flag);
					}
				}
			}
			int skinCount = LoadoutQuery.GetSkinCount(val);
			if (skinCount > 1)
			{
				RectTransform val3 = null;
				for (int k = 0; k < skinCount; k++)
				{
					SkinDef bodySkinDef = SkinCatalog.GetBodySkinDef(val, k);
					bool flag2 = !Object.op_Implicit((Object)(object)bodySkinDef) || LoadoutQuery.HasUnlockable(bodySkinDef.unlockableDef);
					if (flag2 || showLockedChoices)
					{
						val3 = val3 ?? CreateChoiceRow("Skin");
						AddChoiceButton(val3, -1, k, Object.op_Implicit((Object)(object)bodySkinDef) ? bodySkinDef.icon : null, LoadoutQuery.GetSkinName(val, k), flag2);
					}
				}
			}
			if (((Transform)loadoutContent).childCount == 0)
			{
				RectTransform obj = CreateChildRect("EmptyNote", (Transform)(object)loadoutContent);
				AddFixedHeight(obj, 40f);
				((Graphic)CreateLabelIn(obj, "This survivor has no selectable skills or skins.", 17f, (FontStyles)2)).color = DimTextColor;
			}
			UpdateChoiceHighlights();
			ResizeLoadoutWidth();
			ApplyLayout();
		}

		private RectTransform CreateChoiceRow(string label)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: 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_0117: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = CreatePanel("Row_" + label, (Transform)(object)loadoutContent, RowColor);
			AddFixedHeight(val, 60f);
			RectTransform obj = CreateChildRect("SlotLabel", (Transform)(object)val);
			obj.anchorMin = new Vector2(0f, 0f);
			obj.anchorMax = new Vector2(0f, 1f);
			obj.pivot = new Vector2(0f, 0.5f);
			obj.sizeDelta = new Vector2(130f, 0f);
			obj.anchoredPosition = new Vector2(10f, 0f);
			TextMeshProUGUI obj2 = ConfigureText(obj, label, 18f, (FontStyles)1);
			((TMP_Text)obj2).alignment = (TextAlignmentOptions)513;
			((TMP_Text)obj2).enableAutoSizing = true;
			((TMP_Text)obj2).fontSizeMin = 11f;
			((TMP_Text)obj2).fontSizeMax = 18f;
			((TMP_Text)obj2).overflowMode = (TextOverflowModes)1;
			RectTransform obj3 = CreateChildRect("Choices", (Transform)(object)val);
			obj3.anchorMin = Vector2.zero;
			obj3.anchorMax = Vector2.one;
			obj3.offsetMin = new Vector2(146f, 6f);
			obj3.offsetMax = new Vector2(-8f, -6f);
			HorizontalLayoutGroup obj4 = ((Component)obj3).gameObject.AddComponent<HorizontalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)obj4).spacing = 6f;
			((HorizontalOrVerticalLayoutGroup)obj4).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj4).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)obj4).childForceExpandWidth = false;
			((HorizontalOrVerticalLayoutGroup)obj4).childForceExpandHeight = true;
			((LayoutGroup)obj4).childAlignment = (TextAnchor)3;
			return obj3;
		}

		private void AddChoiceButton(RectTransform row, int slot, int index, Sprite icon, string name, bool unlocked)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Expected O, but got Unknown
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Expected O, but got Unknown
			RectTransform val = CreatePanel("Choice_" + index, (Transform)(object)row, unlocked ? ButtonIdle : ButtonLocked);
			LayoutElement obj = ((Component)val).gameObject.AddComponent<LayoutElement>();
			obj.preferredWidth = 48f;
			obj.minWidth = 48f;
			Image component = ((Component)val).GetComponent<Image>();
			if (Object.op_Implicit((Object)(object)icon))
			{
				RectTransform obj2 = CreateChildRect("Icon", (Transform)(object)val);
				obj2.anchorMin = Vector2.zero;
				obj2.anchorMax = Vector2.one;
				obj2.offsetMin = new Vector2(4f, 4f);
				obj2.offsetMax = new Vector2(-4f, -4f);
				Image obj3 = ((Component)obj2).gameObject.AddComponent<Image>();
				obj3.sprite = icon;
				((Graphic)obj3).raycastTarget = false;
				((Graphic)obj3).color = (Color)(unlocked ? Color.white : new Color(1f, 1f, 1f, 0.35f));
			}
			else
			{
				((Graphic)CreateLabelIn(val, index.ToString(), 18f, (FontStyles)1)).color = (unlocked ? TextColor : DimTextColor);
			}
			Button obj4 = ((Component)val).gameObject.AddComponent<Button>();
			((Selectable)obj4).targetGraphic = (Graphic)(object)component;
			int capturedSlot = slot;
			int capturedIndex = index;
			string capturedName = name;
			((UnityEvent)obj4.onClick).AddListener((UnityAction)delegate
			{
				OnChoiceClicked(capturedSlot, capturedIndex, capturedName, unlocked);
			});
			string hoverName = (unlocked ? name : (name + " (locked)"));
			EventTrigger obj5 = ((Component)val).gameObject.AddComponent<EventTrigger>();
			Entry val2 = new Entry
			{
				eventID = (EventTriggerType)0
			};
			((UnityEvent<BaseEventData>)(object)val2.callback).AddListener((UnityAction<BaseEventData>)delegate
			{
				SetStatus(hoverName);
			});
			obj5.triggers.Add(val2);
			choiceEntries.Add(new ChoiceEntry
			{
				background = component,
				slot = slot,
				index = index,
				unlocked = unlocked
			});
		}

		private void OnToggleShowLockedSurvivors()
		{
			if (IsHost)
			{
				Plugin.ShowLockedSurvivors.Value = !Plugin.ShowLockedSurvivors.Value;
				UpdateCheckboxes();
				BuildSurvivorButtons();
				SetStatus(Plugin.ShowLockedSurvivors.Value ? "Showing locked characters." : "Hiding locked characters.");
			}
		}

		private void OnToggleShowLockedChoices()
		{
			if (IsHost)
			{
				Plugin.ShowLockedChoices.Value = !Plugin.ShowLockedChoices.Value;
				UpdateCheckboxes();
				RebuildLoadoutRows();
				SetStatus(Plugin.ShowLockedChoices.Value ? "Showing locked skills and skins." : "Hiding locked skills and skins.");
			}
		}

		private void UpdateCheckboxes()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)lockedSurvivorCheckbox))
			{
				((Graphic)lockedSurvivorCheckbox).color = (ShowLockedSurvivors ? ButtonActive : ButtonIdle);
			}
			if (Object.op_Implicit((Object)(object)lockedChoiceCheckbox))
			{
				((Graphic)lockedChoiceCheckbox).color = (ShowLockedChoices ? ButtonActive : ButtonIdle);
			}
		}

		private void OnSurvivorClicked(BodyIndex bodyIndex)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)user))
			{
				selectedBody = bodyIndex;
				RebuildLoadoutRows();
				SetStatus("Selected " + BodyCatalog.GetBodyName(bodyIndex) + ". Press Apply to rebuild.");
			}
		}

		private void OnChoiceClicked(int slot, int index, string name, bool unlocked)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Invalid comparison between Unknown and I4
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			object obj;
			if (!Object.op_Implicit((Object)(object)user))
			{
				obj = null;
			}
			else
			{
				LocalUser localUser = user.localUser;
				obj = ((localUser != null) ? localUser.userProfile : null);
			}
			UserProfile val = (UserProfile)obj;
			BodyIndex val2 = selectedBody;
			if (val != null && (int)val2 != -1)
			{
				Loadout val3 = new Loadout();
				val.CopyLoadout(val3);
				if (slot < 0)
				{
					val3.bodyLoadoutManager.SetSkinIndex(val2, (uint)index);
				}
				else
				{
					val3.bodyLoadoutManager.SetSkillVariant(val2, slot, (uint)index);
				}
				val.SetLoadout(val3);
				UpdateChoiceHighlights();
				SetStatus(unlocked ? (name + " selected. Press Apply to rebuild.") : (name + " selected (locked). Press Apply to rebuild."));
			}
		}

		private void OnApplyClicked()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Invalid comparison between Unknown and I4
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)user))
			{
				Close();
			}
			else
			{
				if (awaitingHost)
				{
					return;
				}
				BodyIndex val = selectedBody;
				if ((int)val == -1)
				{
					SetStatus("Pick a survivor first.");
					return;
				}
				if (!IsHost)
				{
					RequestFromHost(val);
					return;
				}
				if (!SwapService.ApplyFromProfile(user, val, out var error))
				{
					SetStatus(error);
					return;
				}
				if (!string.IsNullOrEmpty(SwapService.LastNotice))
				{
					Plugin.Log.LogInfo((object)SwapService.LastNotice);
				}
				Close();
			}
		}

		private void RequestFromHost(BodyIndex target)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			LocalUser localUser = user.localUser;
			UserProfile val = ((localUser != null) ? localUser.userProfile : null);
			if (val == null)
			{
				SetStatus("No profile to read a loadout from.");
				return;
			}
			Loadout val2 = new Loadout();
			val.CopyLoadout(val2);
			ClientHudCleanup.OnRequestSent();
			StationNetwork.RequestApply(user, target, val2);
			awaitingHost = true;
			awaitingSince = Time.unscaledTime;
			SetStatus("Asking the host...");
		}

		private void SetStatus(string message)
		{
			if (Object.op_Implicit((Object)(object)statusText))
			{
				((TMP_Text)statusText).text = message;
			}
		}

		private void Update()
		{
			if (!Object.op_Implicit((Object)(object)user) || !Object.op_Implicit((Object)(object)user.master) || !Object.op_Implicit((Object)(object)user.master.GetBody()))
			{
				Close();
				return;
			}
			if (awaitingHost && Time.unscaledTime - awaitingSince > 8f)
			{
				awaitingHost = false;
				ClientHudCleanup.OnSwapRefused();
				SetStatus("No answer from the host. Everyone needs the same version of BazaarLoadout.");
			}
			if (Input.GetKeyDown((KeyCode)27))
			{
				Close();
			}
		}

		private void LateUpdate()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			BodyIndex val = selectedBody;
			if (val != lastBuiltBody)
			{
				RebuildLoadoutRows();
			}
			for (int i = 0; i < survivorEntries.Count; i++)
			{
				SurvivorEntry survivorEntry = survivorEntries[i];
				if (Object.op_Implicit((Object)(object)survivorEntry.background))
				{
					((Graphic)survivorEntry.background).color = ((survivorEntry.bodyIndex == val) ? ButtonActive : ButtonIdle);
				}
			}
		}

		private void UpdateChoiceHighlights()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Invalid comparison between Unknown and I4
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			object obj;
			if (!Object.op_Implicit((Object)(object)user))
			{
				obj = null;
			}
			else
			{
				LocalUser localUser = user.localUser;
				obj = ((localUser != null) ? localUser.userProfile : null);
			}
			UserProfile val = (UserProfile)obj;
			BodyIndex val2 = selectedBody;
			if (val == null || (int)val2 == -1)
			{
				return;
			}
			Loadout val3 = new Loadout();
			val.CopyLoadout(val3);
			for (int i = 0; i < choiceEntries.Count; i++)
			{
				ChoiceEntry choiceEntry = choiceEntries[i];
				if (Object.op_Implicit((Object)(object)choiceEntry.background))
				{
					int num = (int)((choiceEntry.slot < 0) ? val3.bodyLoadoutManager.GetSkinIndex(val2) : val3.bodyLoadoutManager.GetSkillVariant(val2, choiceEntry.slot));
					((Graphic)choiceEntry.background).color = ((choiceEntry.index == num) ? ButtonActive : (choiceEntry.unlocked ? ButtonIdle : ButtonLocked));
				}
			}
		}

		private static void DestroyChildren(RectTransform parent)
		{
			if (Object.op_Implicit((Object)(object)parent))
			{
				for (int num = ((Transform)parent).childCount - 1; num >= 0; num--)
				{
					Object.Destroy((Object)(object)((Component)((Transform)parent).GetChild(num)).gameObject);
				}
			}
		}

		private static RectTransform CreateChildRect(string name, Transform parent)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			return (RectTransform)val.transform;
		}

		private static RectTransform CreatePanel(string name, Transform parent, Color color)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			RectTransform obj = CreateChildRect(name, parent);
			((Graphic)((Component)obj).gameObject.AddComponent<Image>()).color = color;
			return obj;
		}

		private static void CreateStretched(string name, Transform parent, Color color)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			RectTransform obj = CreatePanel(name, parent, color);
			obj.anchorMin = Vector2.zero;
			obj.anchorMax = Vector2.one;
			obj.offsetMin = Vector2.zero;
			obj.offsetMax = Vector2.zero;
		}

		private static LayoutElement AddFixedHeight(RectTransform rect, float height)
		{
			LayoutElement obj = ((Component)rect).gameObject.AddComponent<LayoutElement>();
			obj.preferredHeight = height;
			obj.minHeight = height;
			return obj;
		}

		private static TextMeshProUGUI CreateLabel(string name, RectTransform parent, string text, float size, FontStyles style, float height)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			RectTransform rect = CreateChildRect(name, (Transform)(object)parent);
			AddFixedHeight(rect, height);
			return ConfigureText(rect, text, size, style);
		}

		private static TextMeshProUGUI CreateLabelIn(RectTransform parent, string text, float size, FontStyles style)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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: Unknown result type (might be due to invalid IL or missing references)
			RectTransform obj = CreateChildRect("Label", (Transform)(object)parent);
			obj.anchorMin = Vector2.zero;
			obj.anchorMax = Vector2.one;
			obj.offsetMin = new Vector2(6f, 2f);
			obj.offsetMax = new Vector2(-6f, -2f);
			return ConfigureText(obj, text, size, style);
		}

		private static TextMeshProUGUI ConfigureText(RectTransform rect, string text, float size, FontStyles style)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI obj = ((Component)rect).gameObject.AddComponent<TextMeshProUGUI>();
			((TMP_Text)obj).text = text;
			((TMP_Text)obj).fontSize = size;
			((TMP_Text)obj).fontStyle = style;
			((Graphic)obj).color = TextColor;
			((TMP_Text)obj).alignment = (TextAlignmentOptions)514;
			((Graphic)obj).raycastTarget = false;
			return obj;
		}

		private static void CreateActionButton(RectTransform parent, string text, Color color, UnityAction onClick)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = CreatePanel("Button_" + text, (Transform)(object)parent, color);
			Button obj = ((Component)val).gameObject.AddComponent<Button>();
			((Selectable)obj).targetGraphic = (Graphic)(object)((Component)val).GetComponent<Image>();
			((UnityEvent)obj.onClick).AddListener(onClick);
			CreateLabelIn(val, text, 22f, (FontStyles)1);
		}
	}
	[BepInPlugin("com.danwa.BazaarLoadout", "BazaarLoadout", "0.4.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "com.danwa.BazaarLoadout";

		public const string ModName = "BazaarLoadout";

		public const string ModVersion = "0.4.0";

		internal static ManualLogSource Log;

		internal static Plugin Instance;

		internal static ConfigEntry<bool> StationEnabled;

		internal static ConfigEntry<string> StationScenes;

		internal static ConfigEntry<string> StationPosition;

		internal static ConfigEntry<float> StationYaw;

		internal static ConfigEntry<float> StationDistance;

		internal static ConfigEntry<string> StationModelKey;

		internal static ConfigEntry<bool> StationGlow;

		internal static ConfigEntry<bool> RespectUnlocks;

		internal static ConfigEntry<bool> PreserveHealthFraction;

		internal static ConfigEntry<bool> AllowNonSurvivorBodies;

		internal static ConfigEntry<bool> ReportSpawnGrantedItems;

		internal static ConfigEntry<bool> RemoveBodyGrantedItems;

		internal static ConfigEntry<bool> ReclaimStartingCharacterItems;

		internal static ConfigEntry<bool> RestoreReclaimedKit;

		internal static ConfigEntry<bool> CleanUpCharacterHudElements;

		internal static ConfigEntry<bool> ShowLockedSurvivors;

		internal static ConfigEntry<bool> ShowLockedChoices;

		private void Awake()
		{
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			BindConfig();
			CommandHelper.AddToConsoleWhenReady();
			StationSpawner.CreatePrefab();
			StationNetwork.Register();
			Stage.onStageStartGlobal += OnStageStart;
			Log.LogInfo((object)"BazaarLoadout 0.4.0 loaded.");
		}

		private void OnDestroy()
		{
			Stage.onStageStartGlobal -= OnStageStart;
		}

		private void BindConfig()
		{
			StationEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Station", "Enabled", true, "Spawn the loadout station. Turn this off to use the console commands only.");
			StationScenes = ((BaseUnityPlugin)this).Config.Bind<string>("Station", "Scenes", "bazaar", "Comma-separated baseSceneName list the station spawns in. Combat-free scenes only - the station rebuilds your body, which is not safe mid-fight.");
			StationPosition = ((BaseUnityPlugin)this).Config.Bind<string>("Station", "Position", "", "Explicit spawn position as \"x,y,z\". Leave empty to auto-place it near the player, which survives Bazaar layout mods. Use bl_station_here in game to fill this in.");
			StationYaw = ((BaseUnityPlugin)this).Config.Bind<float>("Station", "Yaw", 0f, "Station facing in degrees. Only used when Position is set.");
			StationDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Station", "AutoPlaceDistance", 6f, "How far in front of the player to auto-place the station when Position is empty.");
			StationModelKey = ((BaseUnityPlugin)this).Config.Bind<string>("Station", "ModelAddress", "RoR2/Base/Duplicator/Duplicator.prefab", "Addressable key of a prefab whose model is borrowed for the station visual. Empty falls back to a placeholder cube.");
			StationGlow = ((BaseUnityPlugin)this).Config.Bind<bool>("Station", "Glow", true, "Give the station a soft glow and outline so it is easy to spot. Each player's own setting decides what they see.");
			RespectUnlocks = ((BaseUnityPlugin)this).Config.Bind<bool>("Rules", "RespectUnlocks", true, "Refuse choices a player has not unlocked. For the host this covers console commands; other players are checked against their own unlocks when they use the station.");
			PreserveHealthFraction = ((BaseUnityPlugin)this).Config.Bind<bool>("Rules", "PreserveHealthFraction", true, "Carry your current health percentage onto the rebuilt body. Off means you come back at the new body's default health.");
			AllowNonSurvivorBodies = ((BaseUnityPlugin)this).Config.Bind<bool>("Rules", "AllowNonSurvivorBodies", false, "Allow swapping into non-survivor bodies (monsters, drones). Mostly broken - they have no player skill families set up. For experimenting only.");
			ShowLockedSurvivors = ((BaseUnityPlugin)this).Config.Bind<bool>("Rules", "ShowLockedSurvivors", false, "Show characters you have not unlocked in the station UI. Toggled by the checkbox in the window; this is just where the choice is remembered.");
			ShowLockedChoices = ((BaseUnityPlugin)this).Config.Bind<bool>("Rules", "ShowLockedChoices", false, "Show skills and skins you have not unlocked. Toggled by the checkbox in the window.");
			RemoveBodyGrantedItems = ((BaseUnityPlugin)this).Config.Bind<bool>("Rules", "RemoveBodyGrantedItems", true, "Take back items a character gave itself when it spawned (Captain and HUNK both do this) when you swap away from it. Only items measured as granted during the swap are removed, never items you picked up. Turn off to keep everything a character hands you.");
			CleanUpCharacterHudElements = ((BaseUnityPlugin)this).Config.Bind<bool>("Rules", "CleanUpCharacterHudElements", true, "Remove HUD widgets a character added when it spawned once you swap off it. Some characters (Dante) build their own HUD and only tear it down on events a swap never raises, so they stack up. Only widgets seen appearing during a swap are removed.");
			RestoreReclaimedKit = ((BaseUnityPlugin)this).Config.Bind<bool>("Rules", "RestoreReclaimedKit", true, "Hand a character's kit back when you return to it and it grants nothing itself. Characters like HUNK and Captain provision once per run, so without this they come back empty-handed. Turn off if you would rather a returning character simply have whatever it grants itself.");
			ReclaimStartingCharacterItems = ((BaseUnityPlugin)this).Config.Bind<bool>("Rules", "ReclaimStartingCharacterItems", true, "Also reclaim items from the character you STARTED the run as. Those were granted before the mod could measure them, so the first swap of a run respawns you once as your current character to learn what it grants. Costs one extra respawn per run; turn off to skip it.");
			ReportSpawnGrantedItems = ((BaseUnityPlugin)this).Config.Bind<bool>("Diagnostics", "ReportSpawnGrantedItems", true, "Log which items a body granted itself as it spawned.");
		}

		internal static void RunDelayed(IEnumerator routine)
		{
			if (Object.op_Implicit((Object)(object)Instance))
			{
				((MonoBehaviour)Instance).StartCoroutine(routine);
			}
		}

		private void OnStageStart(Stage stage)
		{
			LoadoutUI.Close();
			StationSpawner.DespawnExisting();
			if (StationEnabled.Value && NetworkServer.active)
			{
				string text = ((Object.op_Implicit((Object)(object)stage) && Object.op_Implicit((Object)(object)stage.sceneDef)) ? stage.sceneDef.baseSceneName : null);
				if (!string.IsNullOrEmpty(text) && IsEnabledScene(text))
				{
					((MonoBehaviour)this).StartCoroutine(SpawnStationRoutine());
				}
			}
		}

		private bool IsEnabledScene(string sceneName)
		{
			string[] array = StationScenes.Value.Split(',');
			for (int i = 0; i < array.Length; i++)
			{
				if (string.Equals(array[i].Trim(), sceneName, StringComparison.OrdinalIgnoreCase))
				{
					return true;
				}
			}
			return false;
		}

		private IEnumerator SpawnStationRoutine()
		{
			if (TryParseVector3(StationPosition.Value, out var result))
			{
				StationSpawner.Spawn(result, Quaternion.Euler(0f, StationYaw.Value, 0f));
				yield break;
			}
			CharacterBody reference = null;
			for (int frame = 0; frame < 600; frame++)
			{
				if (Object.op_Implicit((Object)(object)reference))
				{
					break;
				}
				reference = FindAnyPlayerBody();
				if (!Object.op_Implicit((Object)(object)reference))
				{
					yield return null;
				}
			}
			if (!Object.op_Implicit((Object)(object)reference))
			{
				Log.LogWarning((object)"No player body found; station not placed. Set Station/Position to place it manually.");
			}
			else
			{
				StationSpawner.SpawnNear(reference, StationDistance.Value);
			}
		}

		internal static CharacterBody FindAnyPlayerBody()
		{
			foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
			{
				CharacterBody val = ((Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)instance.master)) ? instance.master.GetBody() : null);
				if (Object.op_Implicit((Object)(object)val))
				{
					return val;
				}
			}
			return null;
		}

		internal static bool TryParseVector3(string value, out Vector3 result)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			result = Vector3.zero;
			if (string.IsNullOrEmpty(value))
			{
				return false;
			}
			string[] array = value.Split(',');
			if (array.Length != 3)
			{
				return false;
			}
			if (!float.TryParse(array[0].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) || !float.TryParse(array[1].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out var result3) || !float.TryParse(array[2].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out var result4))
			{
				return false;
			}
			result = new Vector3(result2, result3, result4);
			return true;
		}

		internal static string FormatVector3(Vector3 value)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			return string.Format(CultureInfo.InvariantCulture, "{0:0.##},{1:0.##},{2:0.##}", value.x, value.y, value.z);
		}
	}
	internal static class StationNetwork
	{
		public static void Register()
		{
			NetworkingAPI.RegisterMessageType<OpenStationMessage>();
			NetworkingAPI.RegisterMessageType<ApplyRequestMessage>();
			NetworkingAPI.RegisterMessageType<ApplyResultMessage>();
		}

		public static void OpenFor(NetworkUser user)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)user))
			{
				if (user.localUser != null)
				{
					LoadoutUI.Open(user);
				}
				else
				{
					NetMessageExtensions.Send((INetMessage)(object)new OpenStationMessage(((NetworkBehaviour)user).netId), (NetworkDestination)1);
				}
			}
		}

		public static void RequestApply(NetworkUser user, BodyIndex body, Loadout profileLoadout)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			int skillSlotCount = LoadoutQuery.GetSkillSlotCount(body);
			uint[] array = new uint[skillSlotCount];
			for (int i = 0; i < skillSlotCount; i++)
			{
				array[i] = profileLoadout.bodyLoadoutManager.GetSkillVariant(body, i);
			}
			uint skinIndex = profileLoadout.bodyLoadoutManager.GetSkinIndex(body);
			NetMessageExtensions.Send((INetMessage)(object)new ApplyRequestMessage(((NetworkBehaviour)user).netId, body, array, skinIndex), (NetworkDestination)2);
		}

		internal static NetworkUser FindUser(NetworkInstanceId id)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Util.FindNetworkObject(id);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return null;
			}
			return val.GetComponent<NetworkUser>();
		}

		internal static void HandleApplyRequest(NetworkInstanceId userId, BodyIndex body, uint[] variants, uint skin)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active)
			{
				return;
			}
			NetworkUser val = FindUser(userId);
			if (!Object.op_Implicit((Object)(object)val))
			{
				Plugin.Log.LogWarning((object)"Loadout request from an unknown player was ignored.");
				return;
			}
			string error;
			bool flag = TryApplyRemote(val, body, variants, skin, out error);
			string userName = val.userName;
			if (flag)
			{
				Plugin.Log.LogInfo((object)(userName + " swapped to " + BodyCatalog.GetBodyName(body) + " at the station."));
				if (!string.IsNullOrEmpty(SwapService.LastNotice))
				{
					error = SwapService.LastNotice;
				}
			}
			else
			{
				Plugin.Log.LogInfo((object)("Refused " + userName + "'s loadout request: " + error));
			}
			NetMessageExtensions.Send((INetMessage)(object)new ApplyResultMessage(userId, flag, error ?? ""), (NetworkDestination)1);
		}

		private static bool TryApplyRemote(NetworkUser user, BodyIndex body, uint[] variants, uint skin, out string error)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)StationSpawner.Current))
			{
				error = "The loadout station isn't available here.";
				return false;
			}
			if ((int)body == -1 || !LoadoutQuery.IsSurvivorBody(body))
			{
				error = "That isn't a playable survivor.";
				return false;
			}
			CharacterMaster master = user.master;
			if (!Object.op_Implicit((Object)(object)master))
			{
				error = "No character to rebuild.";
				return false;
			}
			int skillSlotCount = LoadoutQuery.GetSkillSlotCount(body);
			if (variants == null || variants.Length != skillSlotCount)
			{
				error = "Your skill list doesn't match the host's. Everyone needs the same mods.";
				return false;
			}
			Loadout val = Loadout.RequestInstance();
			try
			{
				master.loadout.Copy(val);
				for (int i = 0; i < skillSlotCount; i++)
				{
					int variantCount = LoadoutQuery.GetVariantCount(body, i);
					if (variantCount != 0)
					{
						if (variants[i] >= (uint)variantCount)
						{
							error = "Your skill list doesn't match the host's. Everyone needs the same mods.";
							return false;
						}
						val.bodyLoadoutManager.SetSkillVariant(body, i, variants[i]);
					}
				}
				int skinCount = LoadoutQuery.GetSkinCount(body);
				if (skinCount > 0)
				{
					val.bodyLoadoutManager.SetSkinIndex(body, (skin < (uint)skinCount) ? skin : 0u);
				}
				if (Plugin.RespectUnlocks.Value && !LoadoutQuery.CheckUnlocksFor(user, body, val, out error))
				{
					return false;
				}
				return SwapService.ApplyLoadout(user, body, val, out error);
			}
			finally
			{
				Loadout.ReturnInstance(val);
			}
		}
	}
	internal class OpenStationMessage : INetMessage, ISerializableObject
	{
		private NetworkInstanceId userId;

		public OpenStationMessage()
		{
		}

		public OpenStationMessage(NetworkInstanceId userId)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			this.userId = userId;
		}

		public void Serialize(NetworkWriter writer)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			writer.Write(userId);
		}

		public void Deserialize(NetworkReader reader)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			userId = reader.ReadNetworkId();
		}

		public void OnReceived()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			NetworkUser val = StationNetwork.FindUser(userId);
			if (Object.op_Implicit((Object)(object)val) && val.localUser != null)
			{
				LoadoutUI.Open(val);
			}
		}
	}
	internal class ApplyRequestMessage : INetMessage, ISerializableObject
	{
		private const int MaxSlots = 64;

		private NetworkInstanceId userId;

		private BodyIndex body;

		private uint[] variants;

		private uint skin;

		public ApplyRequestMessage()
		{
		}

		public ApplyRequestMessage(NetworkInstanceId userId, BodyIndex body, uint[] variants, uint skin)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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)
			this.userId = userId;
			this.body = body;
			this.variants = variants;
			this.skin = skin;
		}

		public void Serialize(NetworkWriter writer)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected I4, but got Unknown
			writer.Write(userId);
			writer.Write((int)body);
			writer.Write(variants.Length);
			for (int i = 0; i < variants.Length; i++)
			{
				writer.WritePackedUInt32(variants[i]);
			}
			writer.WritePackedUInt32(skin);
		}

		public void Deserialize(NetworkReader reader)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			userId = reader.ReadNetworkId();
			body = (BodyIndex)reader.ReadInt32();
			int num = Mathf.Clamp(reader.ReadInt32(), 0, 64);
			variants = new uint[num];
			for (int i = 0; i < num; i++)
			{
				variants[i] = reader.ReadPackedUInt32();
			}
			skin = reader.ReadPackedUInt32();
		}

		public void OnReceived()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			StationNetwork.HandleApplyRequest(userId, body, variants, skin);
		}
	}
	internal class ApplyResultMessage : INetMessage, ISerializableObject
	{
		private NetworkInstanceId userId;

		private bool success;

		private string text;

		public ApplyResultMessage()
		{
		}

		public ApplyResultMessage(NetworkInstanceId userId, bool success, string text)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			this.userId = userId;
			this.success = success;
			this.text = text;
		}

		public void Serialize(NetworkWriter writer)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			writer.Write(userId);
			writer.Write(success);
			writer.Write(text ?? "");
		}

		public void Deserialize(NetworkReader reader)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			userId = reader.ReadNetworkId();
			success = reader.ReadBoolean();
			text = reader.ReadString();
		}

		public void OnReceived()
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkServer.active)
			{
				return;
			}
			NetworkUser val = StationNetwork.FindUser(userId);
			if (Object.op_Implicit((Object)(object)val) && val.localUser != null)
			{
				if (success)
				{
					ClientHudCleanup.OnSwapConfirmed();
				}
				else
				{
					ClientHudCleanup.OnSwapRefused();
				}
				if (!string.IsNullOrEmpty(text))
				{
					Plugin.Log.LogInfo((object)text);
				}
				LoadoutUI.OnApplyResult(val, success, text);
			}
		}
	}
	internal static class StationSpawner
	{
		private static readonly Color GlowColor = new Color(1f, 0.72f, 0.32f, 1f);

		private static GameObject prefab;

		private static GameObject current;

		public static GameObject Current => current;

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static void CreatePrefab()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)prefab))
			{
				prefab = PrefabAPI.CreateEmptyPrefab("BazaarLoadoutStation");
				prefab.layer = LayerIndex.defaultLayer.intVal;
				BoxCollider obj = prefab.AddComponent<BoxCollider>();
				obj.size = new Vector3(2.4f, 3f, 2.4f);
				obj.center = new Vector3(0f, 1.5f, 0f);
				prefab.AddComponent<EntityLocator>().entity = prefab;
				prefab.AddComponent<SwapStation>();
			}
		}

		public static void DespawnExisting()
		{
			if (Object.op_Implicit((Object)(object)current))
			{
				if (NetworkServer.active)
				{
					NetworkServer.Destroy(current);
				}
				else
				{
					Object.Destroy((Object)(object)current);
				}
			}
			current = null;
		}

		public static GameObject Spawn(Vector3 position, Quaternion rotation)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			DespawnExisting();
			if (!NetworkServer.active || !Object.op_Implicit((Object)(object)prefab))
			{
				return null;
			}
			GameObject obj = Object.Instantiate<GameObject>(prefab, position, rotation);
			NetworkServer.Spawn(obj);
			current = obj;
			Plugin.Log.LogInfo((object)$"Station placed at {position} (rot {((Quaternion)(ref rotation)).eulerAngles.y:0.#} deg)");
			return obj;
		}

		public static void AttachVisual(GameObject root)
		{
			if (Object.op_Implicit((Object)(object)root) && !Object.op_Implicit((Object)(object)root.transform.Find("StationVisual")))
			{
				GameObject val = CreateVisual(root);
				((Object)val).name = "StationVisual";
				if (Plugin.StationGlow.Value)
				{
					AddGlow(root, val);
				}
			}
		}

		private static GameObject CreateVisual(GameObject root)
		{
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			string value = Plugin.StationModelKey.Value;
			if (!string.IsNullOrEmpty(value))
			{
				try
				{
					GameObject val = Addressables.LoadAssetAsync<GameObject>((object)value).WaitForCompletion();
					ModelLocator val2 = (Object.op_Implicit((Object)(object)val) ? val.GetComponent<ModelLocator>() : null);
					Transform val3 = (Object.op_Implicit((Object)(object)val2) ? val2.modelTransform : null);
					if (Object.op_Implicit((Object)(object)val3))
					{
						GameObject obj = Object.Instantiate<GameObject>(((Component)val3).gameObject, root.transform);
						obj.transform.localPosition = Vector3.zero;
						obj.transform.localRotation = Quaternion.identity;
						SetLayerRecursive(obj.transform, LayerIndex.defaultLayer.intVal);
						return obj;
					}
					Plugin.Log.LogWarning((object)("No ModelLocator.modelTransform on '" + value + "'; using placeholder."));
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("Could not load station model '" + value + "' (" + ex.Message + "); using placeholder."));
				}
			}
			GameObject obj2 = GameObject.CreatePrimitive((PrimitiveType)3);
			obj2.transform.SetParent(root.transform, false);
			obj2.transform.localPosition = new Vector3(0f, 1f, 0f);
			obj2.transform.localScale = new Vector3(1.6f, 2f, 1.6f);
			SetLayerRecursive(obj2.transform, LayerIndex.defaultLayer.intVal);
			Collider component = obj2.GetComponent<Collider>();
			if (Object.op_Implicit((Object)(object)component))
			{
				Object.Destroy((Object)(object)component);
			}
			return obj2;
		}

		private static void AddGlow(GameObject root, GameObject visual)
		{
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			List<Renderer> list = new List<Renderer>();
			Renderer[] componentsInChildren = visual.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (val is MeshRenderer || val is SkinnedMeshRenderer)
				{
					list.Add(val);
				}
			}
			if (list.Count > 0)
			{
				Highlight val2 = root.GetComponent<Highlight>();
				if (!Object.op_Implicit((Object)(object)val2))
				{
					val2 = root.AddComponent<Highlight>();
				}
				val2.highlightColor = (HighlightColor)3;
				val2.CustomColor = GlowColor;
				val2.strength = 0.6f;
				val2.SetTargetRendererList(list);
				val2.isOn = true;
			}
			GameObject val3 = new GameObject("StationGlow");
			val3.transform.SetParent(root.transform, false);
			val3.transform.localPosition = new Vector3(0f, 1.6f, 0f);
			Light val4 = val3.AddComponent<Light>();
			val4.type = (LightType)2;
			val4.color = GlowColor;
			val4.range = 6f;
			val4.intensity = 2f;
			val4.shadows = (LightShadows)0;
			val3.AddComponent<GlowPulse>().target = val4;
		}

		private static void SetLayerRecursive(Transform transform, int layer)
		{
			((Component)transform).gameObject.layer = layer;
			for (int i = 0; i < transform.childCount; i++)
			{
				SetLayerRecursive(transform.GetChild(i), layer);
			}
		}

		public static GameObject SpawnNear(CharacterBody referenceBody, float distance)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be