Decompiled source of SuitWardrobeSimple v0.3.0

SuitWardrobeSimple.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyInputUtils.Glyphs;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.DualShock;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
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("SuitWardrobeSimple")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("The suit rack opens a UI menu instead of the vanilla rack.")]
[assembly: AssemblyFileVersion("0.3.0.0")]
[assembly: AssemblyInformationalVersion("0.3.0+d64c1a285a31603759ff580675cd5c04062d98e3")]
[assembly: AssemblyProduct("SuitWardrobeSimple")]
[assembly: AssemblyTitle("SuitWardrobeSimple")]
[assembly: AssemblyVersion("0.3.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 SuitWardrobeSimple
{
	internal static class Saved
	{
		[Serializable]
		private sealed class Data
		{
			public string lastTab = string.Empty;

			public List<string> favourites = new List<string>();
		}

		private static Data _data;

		private static HashSet<string> _favourites;

		private static string FilePath => Path.Combine(Paths.ConfigPath, "SuitWardrobeSimple.state.json");

		internal static string LastTab
		{
			get
			{
				return Load().lastTab;
			}
			set
			{
				if (!(Load().lastTab == value))
				{
					_data.lastTab = value ?? string.Empty;
					Save();
				}
			}
		}

		internal static bool IsFavourite(string suit)
		{
			return Favourites().Contains(suit);
		}

		internal static void ToggleFavourite(string suit)
		{
			HashSet<string> hashSet = Favourites();
			if (!hashSet.Remove(suit))
			{
				hashSet.Add(suit);
			}
			_data.favourites = hashSet.OrderBy<string, string>((string name) => name, StringComparer.OrdinalIgnoreCase).ToList();
			Save();
		}

		private static HashSet<string> Favourites()
		{
			return _favourites ?? (_favourites = new HashSet<string>(Load().favourites, StringComparer.OrdinalIgnoreCase));
		}

		private static Data Load()
		{
			if (_data != null)
			{
				return _data;
			}
			try
			{
				if (File.Exists(FilePath))
				{
					_data = JsonUtility.FromJson<Data>(File.ReadAllText(FilePath));
				}
			}
			catch (Exception ex)
			{
				Plugin.mlg.LogWarning((object)("Could not read " + FilePath + ", starting without favourites: " + ex.Message));
			}
			if (_data == null)
			{
				_data = new Data();
			}
			Data data = _data;
			if (data.favourites == null)
			{
				data.favourites = new List<string>();
			}
			data = _data;
			if (data.lastTab == null)
			{
				data.lastTab = string.Empty;
			}
			return _data;
		}

		private static void Save()
		{
			try
			{
				File.WriteAllText(FilePath, JsonUtility.ToJson((object)_data, true));
			}
			catch (Exception ex)
			{
				Plugin.mlg.LogWarning((object)("Could not write " + FilePath + ": " + ex.Message));
			}
		}
	}
	internal static class Settings
	{
		internal static ConfigEntry<bool> HidePageButtons;

		internal static ConfigEntry<bool> ShowBoots;

		internal static ConfigEntry<bool> UnlockAllSuits;

		internal static ConfigEntry<bool> GroupSmallPacks;

		internal static ConfigEntry<int> SmallPackSize;

		internal static void Init(ConfigFile config)
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			HidePageButtons = config.Bind<bool>("Rack", "HidePageButtons", true, "Only matters with TooManySuits. Hides the page number and arrows above the rack, the rack stays on the first page. The wardrobe lists every suit anyway.");
			ShowBoots = config.Bind<bool>("Rack", "ShowBoots", true, "Show the boots under the suit rack.");
			UnlockAllSuits = config.Bind<bool>("Suits", "UnlockAllSuits", false, "Host only. Unlocks every suit for free, including the ones sold in the store. Unlocked suits are saved with the save file, turning this off later doesn't take them back.");
			GroupSmallPacks = config.Bind<bool>("Tabs", "GroupSmallPacks", false, "Puts the suits of every mod or author with SmallPackSize suits or fewer under the Other tab, instead of a tab of their own.");
			SmallPackSize = config.Bind<int>("Tabs", "SmallPackSize", 1, new ConfigDescription("How many suits or fewer count as a small pack, for GroupSmallPacks.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 50), Array.Empty<object>()));
		}
	}
	[BepInPlugin("dev.davesco.SuitWardrobeSimple", "SuitWardrobeSimple", "0.3.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string modGUID = "dev.davesco.SuitWardrobeSimple";

		public const string modName = "SuitWardrobeSimple";

		public const string modVersion = "0.3.0";

		private Harmony _harmony = new Harmony("dev.davesco.SuitWardrobeSimple");

		internal static ManualLogSource mlg = Logger.CreateLogSource("dev.davesco.SuitWardrobeSimple");

		private void Awake()
		{
			Settings.Init(((BaseUnityPlugin)this).Config);
			mlg.LogInfo((object)"Plugin SuitWardrobeSimple is loaded!");
			_harmony.PatchAll();
		}
	}
	internal sealed class PreviewCamera
	{
		private const int ModelLayer = 23;

		private const int NoPostModelLayer = 17;

		private const int Width = 512;

		private const int Height = 704;

		internal const float Aspect = 0.72727275f;

		private const float FieldOfView = 40f;

		private const float Headroom = 1.12f;

		private const float MinZoom = 0.45f;

		private const float MaxZoom = 1.6f;

		private GameObject _rig;

		private Camera _camera;

		private Light _light;

		private RenderTexture _texture;

		private PlayerControllerB _player;

		private SkinnedMeshRenderer _body;

		private int _bodyLayer;

		private ShadowCastingMode _bodyShadows;

		private bool _bodyMoved;

		private const int ArmsLayer = 4;

		internal bool HideOwnArms;

		private bool _armsHidden;

		private bool _armsWereShown;

		private int _gameplayMask;

		internal float Yaw;

		private float _zoom = 1f;

		internal RenderTexture Texture => _texture;

		internal int FramesDrawn { get; private set; }

		internal void Start(PlayerControllerB player)
		{
			_player = player;
			ResetView();
			if ((Object)(object)_rig == (Object)null)
			{
				Build(player);
			}
			Place();
			FramesDrawn = 0;
			_rig.SetActive(true);
			RenderPipelineManager.beginCameraRendering += BeforeRender;
			RenderPipelineManager.endCameraRendering += AfterRender;
		}

		internal void Stop()
		{
			RenderPipelineManager.beginCameraRendering -= BeforeRender;
			RenderPipelineManager.endCameraRendering -= AfterRender;
			TakeDown();
			ShowArms();
			if ((Object)(object)_rig != (Object)null)
			{
				_rig.SetActive(false);
			}
			_player = null;
		}

		internal void Dispose()
		{
			Stop();
			if ((Object)(object)_rig != (Object)null)
			{
				Object.Destroy((Object)(object)_rig);
			}
			if ((Object)(object)_texture != (Object)null)
			{
				_texture.Release();
			}
			_rig = null;
			_texture = null;
		}

		internal void ResetView()
		{
			Yaw = 0f;
			_zoom = 1f;
		}

		internal void Zoom(float steps)
		{
			_zoom = Mathf.Clamp(_zoom - steps * 0.1f, 0.45f, 1.6f);
		}

		internal void Place()
		{
			//IL_0032: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_rig == (Object)null) && !((Object)(object)_player == (Object)null))
			{
				float num = Mathf.Max(1f, ((Component)_player.gameplayCamera).transform.position.y - ((Component)_player).transform.position.y) + 0.25f;
				float num2 = num * 1.12f * 0.5f / Mathf.Tan(0.34906584f) * _zoom;
				Vector3 val = ((Component)_player).transform.position + Vector3.up * (num * 0.5f);
				Quaternion val2 = Quaternion.Euler(0f, ((Component)_player).transform.eulerAngles.y + Yaw, 0f);
				_rig.transform.position = val + val2 * Vector3.forward * num2 + Vector3.up * (num * 0.08f);
				_rig.transform.LookAt(val);
			}
		}

		internal Texture2D Snapshot(int size)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_0049: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			RenderTexture temporary = RenderTexture.GetTemporary(size, size, 0, (RenderTextureFormat)0);
			Graphics.Blit((Texture)(object)_texture, temporary, new Vector2(1f, 0.72727275f), new Vector2(0f, 0.27272725f));
			RenderTexture active = RenderTexture.active;
			RenderTexture.active = temporary;
			Texture2D val = new Texture2D(size, size, (TextureFormat)4, false)
			{
				name = "SuitWardrobeSimpleThumbnail"
			};
			val.ReadPixels(new Rect(0f, 0f, (float)size, (float)size), 0, 0);
			val.Apply();
			RenderTexture.active = active;
			RenderTexture.ReleaseTemporary(temporary);
			return val;
		}

		private void Build(PlayerControllerB player)
		{
			//IL_000e: 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)
			//IL_0023: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Expected O, but got Unknown
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			_texture = new RenderTexture(512, 704, 24, (RenderTextureFormat)0)
			{
				name = "SuitWardrobeSimplePreview"
			};
			_texture.Create();
			_rig = new GameObject("SuitWardrobeSimplePreviewCamera");
			_rig.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)_rig);
			_camera = _rig.AddComponent<Camera>();
			_camera.targetTexture = _texture;
			_camera.cullingMask = 8519680;
			_camera.fieldOfView = 40f;
			_camera.nearClipPlane = 0.05f;
			_camera.farClipPlane = 15f;
			_camera.depth = -10f;
			HDAdditionalCameraData val = _rig.AddComponent<HDAdditionalCameraData>();
			HDAdditionalCameraData component = ((Component)player.gameplayCamera).GetComponent<HDAdditionalCameraData>();
			if ((Object)(object)component != (Object)null)
			{
				component.CopyTo(val);
			}
			val.clearColorMode = (ClearColorMode)1;
			val.backgroundColorHDR = new Color(0.035f, 0.035f, 0.04f, 1f);
			val.customRenderingSettings = true;
			((BitArray128)(ref val.renderingPathCustomFrameSettingsOverrideMask.mask))[27u] = true;
			((FrameSettings)(ref val.renderingPathCustomFrameSettings)).SetEnabled((FrameSettingsField)27, false);
			((BitArray128)(ref val.renderingPathCustomFrameSettingsOverrideMask.mask))[28u] = true;
			((FrameSettings)(ref val.renderingPathCustomFrameSettings)).SetEnabled((FrameSettingsField)28, false);
			GameObject val2 = new GameObject("SuitWardrobeSimplePreviewLight")
			{
				layer = 23
			};
			val2.transform.SetParent(_rig.transform, false);
			val2.transform.localPosition = new Vector3(0.6f, 0.8f, 0f);
			HDAdditionalLightData obj = GameObjectExtension.AddHDLight(val2, (HDLightTypeAndShape)0);
			obj.SetIntensity(1500f, (LightUnit)0);
			obj.SetRange(12f);
			obj.affectsVolumetric = false;
			obj.EnableShadows(false);
			_light = val2.GetComponent<Light>();
			((Behaviour)_light).enabled = false;
		}

		private void BeforeRender(ScriptableRenderContext context, Camera camera)
		{
			if ((Object)(object)camera == (Object)(object)_camera)
			{
				SetUp();
				return;
			}
			TakeDown();
			if (HideOwnArms && (Object)(object)_player != (Object)null && (Object)(object)camera == (Object)(object)_player.gameplayCamera)
			{
				HideArms();
			}
		}

		private void AfterRender(ScriptableRenderContext context, Camera camera)
		{
			if ((Object)(object)camera == (Object)(object)_camera)
			{
				FramesDrawn++;
				TakeDown();
			}
			else if ((Object)(object)_player != (Object)null && (Object)(object)camera == (Object)(object)_player.gameplayCamera)
			{
				ShowArms();
			}
		}

		private void HideArms()
		{
			if (!_armsHidden)
			{
				Camera gameplayCamera = _player.gameplayCamera;
				_gameplayMask = gameplayCamera.cullingMask;
				gameplayCamera.cullingMask &= -17;
				_armsWereShown = (Object)(object)_player.thisPlayerModelArms != (Object)null && ((Renderer)_player.thisPlayerModelArms).enabled;
				if (_armsWereShown)
				{
					((Renderer)_player.thisPlayerModelArms).enabled = false;
				}
				_armsHidden = true;
			}
		}

		private void ShowArms()
		{
			if (!_armsHidden)
			{
				return;
			}
			if ((Object)(object)_player != (Object)null)
			{
				_player.gameplayCamera.cullingMask = _gameplayMask;
				if (_armsWereShown && (Object)(object)_player.thisPlayerModelArms != (Object)null)
				{
					((Renderer)_player.thisPlayerModelArms).enabled = true;
				}
			}
			_armsHidden = false;
		}

		private void SetUp()
		{
			//IL_009e: 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)
			if ((Object)(object)_player == (Object)null)
			{
				return;
			}
			if ((Object)(object)_light != (Object)null)
			{
				((Behaviour)_light).enabled = true;
			}
			if (!_bodyMoved)
			{
				_body = _player.thisPlayerModel;
				if ((Object)(object)_body == (Object)null || ((Component)_body).gameObject.layer == 23 || ((Component)_body).gameObject.layer == 17)
				{
					_body = null;
					return;
				}
				_bodyLayer = ((Component)_body).gameObject.layer;
				_bodyShadows = ((Renderer)_body).shadowCastingMode;
				((Component)_body).gameObject.layer = 23;
				((Renderer)_body).shadowCastingMode = (ShadowCastingMode)1;
				_bodyMoved = true;
			}
		}

		private void TakeDown()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_light != (Object)null)
			{
				((Behaviour)_light).enabled = false;
			}
			if (_bodyMoved)
			{
				if ((Object)(object)_body != (Object)null)
				{
					((Component)_body).gameObject.layer = _bodyLayer;
					((Renderer)_body).shadowCastingMode = _bodyShadows;
				}
				_body = null;
				_bodyMoved = false;
			}
		}
	}
	internal static class TryOn
	{
		private static int _original = -1;

		internal static int Original => _original;

		internal static void Begin(PlayerControllerB player)
		{
			_original = player.currentSuitID;
		}

		internal static void Show(PlayerControllerB player, int suitId)
		{
			if ((Object)(object)player != (Object)null && suitId >= 0 && player.currentSuitID != suitId)
			{
				UnlockableSuit.SwitchSuitForPlayer(player, suitId, false);
			}
		}

		internal static void Cancel(PlayerControllerB player)
		{
			if (_original >= 0)
			{
				Show(player, _original);
			}
			_original = -1;
		}

		internal static void Wear(PlayerControllerB player, UnlockableSuit hanger)
		{
			Cancel(player);
			if ((Object)(object)hanger != (Object)null && (Object)(object)player != (Object)null)
			{
				hanger.SwitchSuitToThis(player);
			}
		}
	}
	internal static class RackTrigger
	{
		private const string OpenTip = "Open wardrobe : [E]";

		private static InteractTrigger _trigger;

		internal static void SetBusy(string status)
		{
			if (!((Object)(object)_trigger == (Object)null))
			{
				_trigger.interactable = status == null;
				_trigger.disabledHoverTip = status ?? string.Empty;
			}
		}

		internal static void Attach(StartOfRound round)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Expected O, but got Unknown
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Expected O, but got Unknown
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Expected O, but got Unknown
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Expected O, but got Unknown
			Transform rightmostSuitPosition = round.rightmostSuitPosition;
			if ((Object)(object)rightmostSuitPosition == (Object)null)
			{
				Plugin.mlg.LogWarning((object)"No suit rack found; the wardrobe cannot be opened this lobby.");
				return;
			}
			GameObject val = new GameObject("SuitWardrobeSimpleTrigger");
			val.SetActive(false);
			val.transform.SetParent(rightmostSuitPosition, false);
			val.transform.localPosition = Vector3.zero;
			val.transform.localRotation = Quaternion.identity;
			val.tag = "InteractTrigger";
			val.layer = LayerMask.NameToLayer("InteractableObject");
			((Collider)val.AddComponent<BoxCollider>()).isTrigger = true;
			val.AddComponent<RackFit>();
			InteractTrigger obj = val.AddComponent<InteractTrigger>();
			obj.interactable = true;
			obj.oneHandedItemAllowed = true;
			obj.twoHandedItemAllowed = true;
			obj.holdInteraction = false;
			obj.interactCooldown = false;
			obj.onInteract = new InteractEvent();
			obj.onInteractEarly = new InteractEvent();
			obj.onCancelAnimation = new InteractEvent();
			obj.onStopInteract = new InteractEvent();
			obj.holdingInteractEvent = new InteractEventFloat();
			obj.hoverTip = "Open wardrobe : [E]";
			obj.disabledHoverTip = string.Empty;
			obj.hoverIcon = (obj.disabledHoverIcon = HoverIcon());
			((UnityEvent<PlayerControllerB>)(object)obj.onInteract).AddListener((UnityAction<PlayerControllerB>)delegate(PlayerControllerB player)
			{
				WardrobeMenu.Open(player);
			});
			_trigger = obj;
			val.SetActive(true);
		}

		private static Sprite HoverIcon()
		{
			Terminal val = Object.FindObjectOfType<Terminal>();
			InteractTrigger val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<InteractTrigger>() : null);
			if (!((Object)(object)val2 != (Object)null))
			{
				return null;
			}
			return val2.hoverIcon;
		}
	}
	internal sealed class RackFit : MonoBehaviour
	{
		private const float RailLength = 2.07f;

		private const string RailMesh = "NurbsPath.002";

		private const float EndClearance = 0.15f;

		private const float Margin = 0.05f;

		private const float SuitThickness = 0.12f;

		private const float SuitWidth = 0.3f;

		private const float Interval = 2f;

		private static RackFit _instance;

		private static readonly bool Paged = Chainloader.PluginInfos.ContainsKey("TooManySuits");

		private const string PageLabel = "TooManySuitsPageLabel";

		private const float ButtonGap = 0.02f;

		private BoxCollider _box;

		private Renderer _rail;

		private bool _railWarned;

		private GameObject _pageLabel;

		private bool _pageLabelHidden;

		private const string Boots = "ScavengerModelSuitParts";

		private GameObject _boots;

		private bool _bootsHidden;

		private const float SearchTime = 10f;

		private float _searchUntil;

		private float _nextFit;

		private readonly HashSet<Renderer> _hidden = new HashSet<Renderer>();

		private const string SolidName = "SuitWardrobeSimpleSolid";

		private static readonly int SolidLayer;

		private void Awake()
		{
			_box = ((Component)this).GetComponent<BoxCollider>();
		}

		private void OnEnable()
		{
			_instance = this;
			_searchUntil = Time.time + 10f;
			Settings.HidePageButtons.SettingChanged += OnSettingChanged;
			Settings.ShowBoots.SettingChanged += OnSettingChanged;
		}

		private void OnDisable()
		{
			Settings.HidePageButtons.SettingChanged -= OnSettingChanged;
			Settings.ShowBoots.SettingChanged -= OnSettingChanged;
			if ((Object)(object)_instance == (Object)(object)this)
			{
				_instance = null;
			}
		}

		private void OnSettingChanged(object sender, EventArgs e)
		{
			_searchUntil = Time.time + 10f;
			Refresh();
		}

		internal static void Refresh()
		{
			if (!((Object)(object)_instance == (Object)null))
			{
				_instance.Quiet();
				_instance.Dress();
				_instance._nextFit = 0f;
			}
		}

		private void Update()
		{
			if (!(Time.time < _nextFit))
			{
				_nextFit = Time.time + 2f;
				SuitUnlocker.Tick();
				Quiet();
				Dress();
				Fit();
			}
		}

		private void Quiet()
		{
			_hidden.RemoveWhere((Renderer mesh) => (Object)(object)mesh == (Object)null);
			foreach (UnlockableSuit item in Hangers())
			{
				Collider[] componentsInChildren = ((Component)item).GetComponentsInChildren<Collider>();
				foreach (Collider val in componentsInChildren)
				{
					if (!(((Object)((Component)val).gameObject).name == "SuitWardrobeSimpleSolid"))
					{
						if (val.enabled && !val.isTrigger)
						{
							Solid(val);
						}
						val.enabled = false;
					}
				}
				InteractTrigger component = ((Component)item).GetComponent<InteractTrigger>();
				if ((Object)(object)component != (Object)null)
				{
					component.interactable = false;
				}
			}
		}

		private static void Solid(Collider original)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			//IL_0077: 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_0095: 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)
			Transform transform = ((Component)original).transform;
			if ((Object)(object)transform.Find("SuitWardrobeSimpleSolid") != (Object)null)
			{
				return;
			}
			GameObject val = new GameObject("SuitWardrobeSimpleSolid")
			{
				layer = SolidLayer
			};
			val.transform.SetParent(transform, false);
			BoxCollider val2 = (BoxCollider)(object)((original is BoxCollider) ? original : null);
			if (val2 == null)
			{
				CapsuleCollider val3 = (CapsuleCollider)(object)((original is CapsuleCollider) ? original : null);
				if (val3 == null)
				{
					SphereCollider val4 = (SphereCollider)(object)((original is SphereCollider) ? original : null);
					if (val4 == null)
					{
						MeshCollider val5 = (MeshCollider)(object)((original is MeshCollider) ? original : null);
						if (val5 != null)
						{
							MeshCollider obj = val.AddComponent<MeshCollider>();
							obj.sharedMesh = val5.sharedMesh;
							obj.convex = val5.convex;
						}
						else
						{
							Object.Destroy((Object)(object)val);
						}
					}
					else
					{
						SphereCollider obj2 = val.AddComponent<SphereCollider>();
						obj2.center = val4.center;
						obj2.radius = val4.radius;
					}
				}
				else
				{
					CapsuleCollider obj3 = val.AddComponent<CapsuleCollider>();
					obj3.center = val3.center;
					obj3.radius = val3.radius;
					obj3.height = val3.height;
					obj3.direction = val3.direction;
				}
			}
			else
			{
				BoxCollider obj4 = val.AddComponent<BoxCollider>();
				obj4.center = val2.center;
				obj4.size = val2.size;
			}
		}

		private void HideIfPastRail(UnlockableSuit suit, float railEnd)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			bool flag = ((Component)this).transform.InverseTransformPoint(((Component)suit).transform.position).z > railEnd - 0.15f;
			Collider[] componentsInChildren = ((Component)suit).GetComponentsInChildren<Collider>(true);
			foreach (Collider val in componentsInChildren)
			{
				if (((Object)((Component)val).gameObject).name == "SuitWardrobeSimpleSolid")
				{
					val.enabled = !flag;
				}
			}
			Renderer[] componentsInChildren2 = ((Component)suit).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val2 in componentsInChildren2)
			{
				if (flag)
				{
					if (val2.enabled)
					{
						val2.enabled = false;
						_hidden.Add(val2);
					}
				}
				else if (_hidden.Remove(val2))
				{
					val2.enabled = true;
				}
			}
		}

		private void Fit()
		{
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: 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)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: 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_012c: 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_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			var (num, num2) = RailSpan();
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(-0.15f, -0.1f, num);
			Vector3 val2 = default(Vector3);
			((Vector3)(ref val2))..ctor(0.15f, 0.3f, num2);
			foreach (UnlockableSuit item in Hangers())
			{
				if (!Paged)
				{
					HideIfPastRail(item, num2);
				}
				Renderer suitRenderer = (Renderer)(object)item.suitRenderer;
				if ((Object)(object)suitRenderer == (Object)null || !suitRenderer.enabled)
				{
					continue;
				}
				Bounds bounds = suitRenderer.bounds;
				if (((Bounds)(ref bounds)).size == Vector3.zero)
				{
					continue;
				}
				Vector3 val3 = ((Component)this).transform.InverseTransformPoint(((Component)item).transform.position);
				float num3 = val3.y;
				float num4 = val3.y;
				foreach (Vector3 item2 in Corners(suitRenderer.bounds))
				{
					float y = ((Component)this).transform.InverseTransformPoint(item2).y;
					num3 = Mathf.Min(num3, y);
					num4 = Mathf.Max(num4, y);
				}
				val = Vector3.Min(val, new Vector3(val3.x - 0.3f, num3, val3.z - 0.12f));
				val2 = Vector3.Max(val2, new Vector3(val3.x + 0.3f, num4, val3.z + 0.12f));
			}
			val -= Vector3.one * 0.05f;
			val2 += Vector3.one * 0.05f;
			if (Paged && !Settings.HidePageButtons.Value)
			{
				val2.y = Mathf.Min(val2.y, BelowPageButtons());
			}
			_box.center = (val + val2) * 0.5f;
			_box.size = val2 - val;
		}

		private (float start, float end) RailSpan()
		{
			//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_00cd: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_rail == (Object)null)
			{
				Transform val = (((Object)(object)((Component)this).transform.parent != (Object)null) ? ((Component)this).transform.parent.parent : null);
				Transform val2 = (((Object)(object)val != (Object)null) ? val.Find("NurbsPath.002") : null);
				_rail = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponent<Renderer>() : null);
			}
			if ((Object)(object)_rail == (Object)null)
			{
				if (!_railWarned)
				{
					Plugin.mlg.LogWarning((object)"Suit rack rail (NurbsPath.002) not found; assuming the vanilla length.");
					_railWarned = true;
				}
				return (start: 0f, end: 2.07f);
			}
			float num = float.MaxValue;
			float num2 = float.MinValue;
			foreach (Vector3 item in Corners(_rail.bounds))
			{
				float z = ((Component)this).transform.InverseTransformPoint(item).z;
				num = Mathf.Min(num, z);
				num2 = Mathf.Max(num2, z);
			}
			return (start: num, end: num2);
		}

		private void Dress()
		{
			if (Paged && (Settings.HidePageButtons.Value || _pageLabelHidden))
			{
				_pageLabelHidden = Show(Look(ref _pageLabel, "TooManySuitsPageLabel"), !Settings.HidePageButtons.Value, _pageLabelHidden);
			}
			if (!Settings.ShowBoots.Value || _bootsHidden)
			{
				_bootsHidden = Show(Look(ref _boots, "ScavengerModelSuitParts"), Settings.ShowBoots.Value, _bootsHidden);
			}
		}

		private GameObject Look(ref GameObject part, string name)
		{
			if ((Object)(object)part != (Object)null)
			{
				return part;
			}
			if (part != null)
			{
				part = null;
				_searchUntil = Time.time + 10f;
			}
			if (Time.time <= _searchUntil)
			{
				part = GameObject.Find(name);
			}
			return part;
		}

		private static bool Show(GameObject thing, bool show, bool hidden)
		{
			if ((Object)(object)thing == (Object)null || (show && !hidden))
			{
				return false;
			}
			Renderer[] componentsInChildren = thing.GetComponentsInChildren<Renderer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].enabled = show;
			}
			Collider[] componentsInChildren2 = thing.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				componentsInChildren2[i].enabled = show;
			}
			return !show;
		}

		private float BelowPageButtons()
		{
			//IL_003e: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_0082: 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_008c: 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_009c: 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)
			if ((Object)(object)Look(ref _pageLabel, "TooManySuitsPageLabel") == (Object)null)
			{
				return float.MaxValue;
			}
			float num = float.MaxValue;
			BoxCollider[] componentsInChildren = _pageLabel.GetComponentsInChildren<BoxCollider>(true);
			foreach (BoxCollider val in componentsInChildren)
			{
				Vector3 val2 = val.size * 0.5f;
				for (int j = 0; j < 8; j++)
				{
					Vector3 val3 = val.center + Vector3.Scale(val2, new Vector3((float)(((j & 1) != 0) ? 1 : (-1)), (float)(((j & 2) != 0) ? 1 : (-1)), (float)(((j & 4) != 0) ? 1 : (-1))));
					float y = ((Component)this).transform.InverseTransformPoint(((Component)val).transform.TransformPoint(val3)).y;
					num = Mathf.Min(num, y);
				}
			}
			return num - 0.02f;
		}

		private static IEnumerable<UnlockableSuit> Hangers()
		{
			UnlockableSuit[] array = Object.FindObjectsOfType<UnlockableSuit>();
			foreach (UnlockableSuit val in array)
			{
				if ((Object)(object)val != (Object)null && ((NetworkBehaviour)val).IsSpawned)
				{
					yield return val;
				}
			}
		}

		private static IEnumerable<Vector3> Corners(Bounds bounds)
		{
			//IL_0008: 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)
			Vector3 c = ((Bounds)(ref bounds)).center;
			Vector3 e = ((Bounds)(ref bounds)).extents;
			for (int i = 0; i < 8; i++)
			{
				yield return c + Vector3.Scale(e, new Vector3((float)(((i & 1) != 0) ? 1 : (-1)), (float)(((i & 2) != 0) ? 1 : (-1)), (float)(((i & 4) != 0) ? 1 : (-1))));
			}
		}

		static RackFit()
		{
			int num = LayerMask.NameToLayer("Colliders");
			SolidLayer = ((num >= 0) ? num : 11);
		}
	}
	internal sealed class SuitEntry
	{
		internal int Id;

		internal string Name;

		internal string Source;

		internal string Tab;

		internal UnlockableSuit Hanger;
	}
	internal static class SuitCatalog
	{
		internal static List<SuitEntry> Owned()
		{
			List<UnlockableItem> list = StartOfRound.Instance?.unlockablesList?.unlockables;
			List<SuitEntry> list2 = new List<SuitEntry>();
			if (list == null)
			{
				return list2;
			}
			HashSet<int> hashSet = new HashSet<int>();
			foreach (UnlockableSuit item in from hanger in Resources.FindObjectsOfTypeAll<UnlockableSuit>()
				where (Object)(object)hanger != (Object)null && ((NetworkBehaviour)hanger).IsSpawned
				orderby hanger.syncedSuitID.Value
				select hanger)
			{
				int value = item.syncedSuitID.Value;
				if (value >= 0 && value < list.Count && hashSet.Add(value))
				{
					UnlockableItem val = list[value];
					string text = SuitSources.SourceOf(val.unlockableName);
					list2.Add(new SuitEntry
					{
						Id = value,
						Name = val.unlockableName,
						Source = text,
						Tab = text,
						Hanger = item
					});
				}
			}
			if (Settings.GroupSmallPacks.Value)
			{
				GroupSmallPacks(list2, Settings.SmallPackSize.Value);
			}
			return list2;
		}

		private static void GroupSmallPacks(List<SuitEntry> entries, int size)
		{
			HashSet<string> hashSet = new HashSet<string>(from entry in entries
				where entry.Source != "Vanilla" && entry.Source != "Other"
				group entry by entry.Source into pack
				where pack.Count() <= size
				select pack.Key);
			foreach (SuitEntry entry in entries)
			{
				if (hashSet.Contains(entry.Source))
				{
					entry.Tab = "Other";
				}
			}
		}
	}
	internal static class SuitSources
	{
		private sealed class Package
		{
			internal string Author;

			internal string Name;
		}

		internal const string Vanilla = "Vanilla";

		internal const string Other = "Other";

		private static Dictionary<string, string> _packs;

		private static HashSet<string> _vanilla;

		internal static void RememberVanilla(StartOfRound round)
		{
			if (_vanilla == null && !((Object)(object)round.unlockablesList == (Object)null))
			{
				_vanilla = new HashSet<string>(from unlockable in round.unlockablesList.unlockables
					where unlockable != null && unlockable.unlockableType == 0
					select Key(unlockable.unlockableName), StringComparer.Ordinal);
			}
		}

		internal static string SourceOf(string suitName)
		{
			string text = Key(suitName);
			if (Packs().TryGetValue(text, out var value))
			{
				return value;
			}
			if (_vanilla != null && _vanilla.Contains(text))
			{
				return "Vanilla";
			}
			return "Other";
		}

		private static string Key(string suitName)
		{
			string text = (suitName ?? string.Empty).Trim().ToLowerInvariant();
			if (!text.EndsWith(" suit"))
			{
				return text;
			}
			return text.Substring(0, text.Length - 5).TrimEnd();
		}

		private static Dictionary<string, string> Packs()
		{
			if (_packs != null)
			{
				return _packs;
			}
			_packs = new Dictionary<string, string>(StringComparer.Ordinal);
			try
			{
				List<(string Folder, Package Package)> list = (from folder in Directory.GetDirectories(Paths.PluginPath, "moresuits", SearchOption.AllDirectories)
					select (Folder: folder, Package: PackageOf(folder))).ToList();
				Dictionary<string, int> dictionary = list.Where(((string Folder, Package Package) entry) => entry.Package != null).GroupBy<(string, Package), string>(((string Folder, Package Package) entry) => entry.Package.Author, StringComparer.OrdinalIgnoreCase).ToDictionary<IGrouping<string, (string, Package)>, string, int>((IGrouping<string, (string Folder, Package Package)> group) => group.Key, (IGrouping<string, (string Folder, Package Package)> group) => group.Select(((string Folder, Package Package) entry) => entry.Package.Name).Distinct<string>(StringComparer.OrdinalIgnoreCase).Count(), StringComparer.OrdinalIgnoreCase);
				foreach (var item3 in list)
				{
					string item = item3.Folder;
					Package item2 = item3.Package;
					string value = ((item2 == null) ? "Other" : ((dictionary[item2.Author] > 1) ? Readable(item2.Author) : Readable(item2.Name)));
					string[] files = Directory.GetFiles(item, "*.png");
					for (int num = 0; num < files.Length; num++)
					{
						string key = Key(Path.GetFileNameWithoutExtension(files[num]));
						if (!_packs.ContainsKey(key))
						{
							_packs[key] = value;
						}
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.mlg.LogWarning((object)("Could not read the suit folders, every modded suit goes under Other: " + ex.Message));
			}
			return _packs;
		}

		private static Package PackageOf(string suitFolder)
		{
			string text = suitFolder.Substring(Paths.PluginPath.Length).TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar).Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)[0];
			if (text.Equals("moresuits", StringComparison.OrdinalIgnoreCase))
			{
				return null;
			}
			int num = text.IndexOf('-');
			if (num <= 0 || num >= text.Length - 1)
			{
				return new Package
				{
					Author = text,
					Name = text
				};
			}
			return new Package
			{
				Author = text.Substring(0, num),
				Name = text.Substring(num + 1)
			};
		}

		private static string Readable(string name)
		{
			return name.Replace('_', ' ').Trim();
		}
	}
	internal static class SuitUnlocker
	{
		private static readonly MethodInfo Unlock = AccessTools.Method(typeof(StartOfRound), "UnlockShipObject", (Type[])null, (Type[])null);

		internal static void Tick()
		{
			StartOfRound instance = StartOfRound.Instance;
			if (!Settings.UnlockAllSuits.Value || (Object)(object)instance == (Object)null || !((NetworkBehaviour)instance).IsServer || !instance.inShipPhase || Unlock == null)
			{
				return;
			}
			List<UnlockableItem> list = instance.unlockablesList?.unlockables;
			if (list == null)
			{
				return;
			}
			Terminal val = null;
			for (int i = 0; i < list.Count; i++)
			{
				UnlockableItem val2 = list[i];
				if (val2 != null && val2.unlockableType == 0 && !((Object)(object)val2.suitMaterial == (Object)null) && !val2.alreadyUnlocked && !val2.hasBeenUnlockedByPlayer)
				{
					if ((Object)(object)val == (Object)null)
					{
						val = Object.FindObjectOfType<Terminal>();
					}
					if ((Object)(object)val == (Object)null)
					{
						break;
					}
					instance.BuyShipUnlockableClientRpc(val.groupCredits, i);
					Unlock.Invoke(instance, new object[1] { i });
				}
			}
		}
	}
	internal static class Thumbnails
	{
		internal const int Size = 160;

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

		private static readonly HashSet<string> Missing = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

		private static string Folder => Path.Combine(Paths.CachePath, "SuitWardrobeSimple");

		internal static Texture2D Get(string suit)
		{
			if (Pictures.TryGetValue(suit, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			if (Missing.Contains(suit))
			{
				return null;
			}
			value = Load(suit);
			if ((Object)(object)value != (Object)null)
			{
				Pictures[suit] = value;
			}
			else
			{
				Missing.Add(suit);
			}
			return value;
		}

		internal static bool Has(string suit)
		{
			return (Object)(object)Get(suit) != (Object)null;
		}

		internal static void Store(string suit, Texture2D picture)
		{
			if (Pictures.TryGetValue(suit, out var value) && (Object)(object)value != (Object)null && (Object)(object)value != (Object)(object)picture)
			{
				Object.Destroy((Object)(object)value);
			}
			Pictures[suit] = picture;
			Missing.Remove(suit);
			try
			{
				Directory.CreateDirectory(Folder);
				File.WriteAllBytes(PathOf(suit), ImageConversion.EncodeToPNG(picture));
			}
			catch (Exception ex)
			{
				Plugin.mlg.LogWarning((object)("Could not save the picture of " + suit + "; it is taken again next time: " + ex.Message));
			}
		}

		private static Texture2D Load(string suit)
		{
			//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_0027: Expected O, but got Unknown
			string path = PathOf(suit);
			if (!File.Exists(path))
			{
				return null;
			}
			try
			{
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false)
				{
					name = "SuitWardrobeSimpleThumbnail"
				};
				if (ImageConversion.LoadImage(val, File.ReadAllBytes(path)))
				{
					return val;
				}
				Object.Destroy((Object)(object)val);
			}
			catch (Exception ex)
			{
				Plugin.mlg.LogWarning((object)("Could not read the picture of " + suit + ": " + ex.Message));
			}
			return null;
		}

		private static string PathOf(string suit)
		{
			char[] invalid = Path.GetInvalidFileNameChars();
			string text = new string(suit.Select((char c) => (!invalid.Contains(c)) ? c : '_').ToArray()).Trim();
			return Path.Combine(Folder, text + ".png");
		}
	}
	internal static class PadGlyphs
	{
		private static readonly bool HasInputUtils = Chainloader.PluginInfos.ContainsKey("com.rune580.LethalCompanyInputUtils");

		internal static Sprite Get(string control)
		{
			if (!HasInputUtils)
			{
				return null;
			}
			return FromInputUtils(control);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static Sprite FromInputUtils(string control)
		{
			ControllerGlyph bestMatching = ControllerGlyph.GetBestMatching();
			if (!((Object)(object)bestMatching != (Object)null))
			{
				return null;
			}
			return bestMatching["<Gamepad>/" + control];
		}
	}
	internal static class Ui
	{
		internal static readonly Color Backdrop = new Color(0f, 0f, 0f, 0.6f);

		internal static readonly Color Panel = new Color(0.06f, 0.055f, 0.05f, 0.97f);

		internal static readonly Color Inset = new Color(0.1f, 0.09f, 0.08f, 1f);

		internal static readonly Color Raised = new Color(0.16f, 0.14f, 0.12f, 1f);

		internal static readonly Color Accent = new Color(1f, 0.46f, 0.13f, 1f);

		internal static readonly Color AccentDark = new Color(0.45f, 0.19f, 0.05f, 1f);

		internal static readonly Color Text = new Color(1f, 0.88f, 0.78f, 1f);

		internal static readonly Color Muted = new Color(0.62f, 0.55f, 0.5f, 1f);

		private static readonly Navigation NoNavigation;

		internal static TMP_FontAsset Font
		{
			get
			{
				if (!((Object)(object)HUDManager.Instance != (Object)null) || !((Object)(object)HUDManager.Instance.chatText != (Object)null))
				{
					return null;
				}
				return ((TMP_Text)HUDManager.Instance.chatText).font;
			}
		}

		internal static RectTransform Rect(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;
		}

		internal static void Fill(RectTransform rect, float margin = 0f)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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)
			rect.anchorMin = Vector2.zero;
			rect.anchorMax = Vector2.one;
			rect.offsetMin = new Vector2(margin, margin);
			rect.offsetMax = new Vector2(0f - margin, 0f - margin);
		}

		internal static void Box(RectTransform rect, float left, float top, float width, float height)
		{
			//IL_0013: 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_002a: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 1f);
			rect.anchorMax = val;
			rect.anchorMin = val;
			rect.pivot = new Vector2(0f, 1f);
			rect.anchoredPosition = new Vector2(left, 0f - top);
			rect.sizeDelta = new Vector2(width, height);
		}

		internal static void Column(RectTransform rect, float left, float top, float width, float bottom)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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)
			rect.anchorMin = new Vector2(0f, 0f);
			rect.anchorMax = new Vector2(0f, 1f);
			rect.pivot = new Vector2(0f, 1f);
			rect.offsetMin = new Vector2(left, bottom);
			rect.offsetMax = new Vector2(left + width, 0f - top);
		}

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

		internal static TextMeshProUGUI Label(Transform parent, string name, string text, float size, TextAlignmentOptions alignment = (TextAlignmentOptions)4097)
		{
			//IL_0039: 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)
			TextMeshProUGUI val = ((Component)Rect(name, parent)).gameObject.AddComponent<TextMeshProUGUI>();
			if ((Object)(object)Font != (Object)null)
			{
				((TMP_Text)val).font = Font;
			}
			((TMP_Text)val).text = text;
			((TMP_Text)val).fontSize = size;
			((Graphic)val).color = Text;
			((TMP_Text)val).alignment = alignment;
			((TMP_Text)val).enableWordWrapping = false;
			((TMP_Text)val).overflowMode = (TextOverflowModes)1;
			((Graphic)val).raycastTarget = false;
			return val;
		}

		internal static Button Button(Transform parent, string name, string text, float size, Color color, UnityAction onClick)
		{
			//IL_0002: 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_002b: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
			Image val = Image(parent, name, color);
			Button val2 = ((Component)val).gameObject.AddComponent<Button>();
			((Selectable)val2).navigation = NoNavigation;
			((Selectable)val2).targetGraphic = (Graphic)(object)val;
			ColorBlock colors = default(ColorBlock);
			((ColorBlock)(ref colors)).normalColor = new Color(0.66f, 0.66f, 0.66f, 1f);
			((ColorBlock)(ref colors)).highlightedColor = Color.white;
			((ColorBlock)(ref colors)).pressedColor = new Color(0.85f, 0.85f, 0.85f, 1f);
			((ColorBlock)(ref colors)).selectedColor = new Color(0.66f, 0.66f, 0.66f, 1f);
			((ColorBlock)(ref colors)).disabledColor = new Color(0.4f, 0.4f, 0.4f, 0.6f);
			((ColorBlock)(ref colors)).colorMultiplier = 1.5f;
			((ColorBlock)(ref colors)).fadeDuration = 0.06f;
			((Selectable)val2).colors = colors;
			if (onClick != null)
			{
				((UnityEvent)val2.onClick).AddListener(onClick);
			}
			if (text != null)
			{
				Fill(((TMP_Text)Label(((Component)val).transform, "Label", text, size, (TextAlignmentOptions)514)).rectTransform);
			}
			return val2;
		}

		internal static TMP_InputField InputField(Transform parent, string name, string placeholder, float size)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = Rect(name, parent);
			((Component)val).gameObject.SetActive(false);
			Image val2 = ((Component)val).gameObject.AddComponent<Image>();
			((Graphic)val2).color = Inset;
			RectTransform val3 = Rect("Text Area", (Transform)(object)val);
			Fill(val3, 8f);
			((Component)val3).gameObject.AddComponent<RectMask2D>();
			TextMeshProUGUI val4 = Label((Transform)(object)val3, "Placeholder", placeholder, size, (TextAlignmentOptions)4097);
			((Graphic)val4).color = Muted;
			((TMP_Text)val4).fontStyle = (FontStyles)2;
			Fill(((TMP_Text)val4).rectTransform);
			TextMeshProUGUI val5 = Label((Transform)(object)val3, "Text", string.Empty, size, (TextAlignmentOptions)4097);
			Fill(((TMP_Text)val5).rectTransform);
			TMP_InputField val6 = ((Component)val).gameObject.AddComponent<TMP_InputField>();
			((Selectable)val6).navigation = NoNavigation;
			((Selectable)val6).targetGraphic = (Graphic)(object)val2;
			val6.textViewport = val3;
			val6.textComponent = (TMP_Text)(object)val5;
			val6.placeholder = (Graphic)(object)val4;
			if ((Object)(object)Font != (Object)null)
			{
				val6.fontAsset = Font;
			}
			val6.pointSize = size;
			val6.customCaretColor = true;
			val6.caretColor = Accent;
			val6.selectionColor = new Color(Accent.r, Accent.g, Accent.b, 0.35f);
			val6.lineType = (LineType)0;
			((Component)val).gameObject.SetActive(true);
			return val6;
		}

		internal static Image Icon(Transform parent, string name)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			Image obj = Image(parent, name, Color.white);
			obj.preserveAspect = true;
			((Graphic)obj).raycastTarget = false;
			((Component)obj).gameObject.SetActive(false);
			return obj;
		}

		internal static RectTransform Scroll(Transform parent, string name, bool vertical, out ScrollRect scroll)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = Rect(name, parent);
			scroll = ((Component)val).gameObject.AddComponent<ScrollRect>();
			RectTransform rectTransform = ((Graphic)Image((Transform)(object)val, "Viewport", new Color(0f, 0f, 0f, 0f))).rectTransform;
			Fill(rectTransform);
			((Component)rectTransform).gameObject.AddComponent<RectMask2D>();
			RectTransform val2 = Rect("Content", (Transform)(object)rectTransform);
			if (vertical)
			{
				val2.anchorMin = new Vector2(0f, 1f);
				val2.anchorMax = new Vector2(1f, 1f);
				val2.pivot = new Vector2(0.5f, 1f);
			}
			else
			{
				val2.anchorMin = new Vector2(0f, 0f);
				val2.anchorMax = new Vector2(0f, 1f);
				val2.pivot = new Vector2(0f, 0.5f);
			}
			val2.sizeDelta = Vector2.zero;
			ContentSizeFitter obj = ((Component)val2).gameObject.AddComponent<ContentSizeFitter>();
			obj.verticalFit = (FitMode)(vertical ? 2 : 0);
			obj.horizontalFit = (FitMode)((!vertical) ? 2 : 0);
			scroll.viewport = rectTransform;
			scroll.content = val2;
			scroll.vertical = vertical;
			scroll.horizontal = !vertical;
			scroll.movementType = (MovementType)2;
			scroll.inertia = false;
			scroll.scrollSensitivity = 45f;
			return val2;
		}

		static Ui()
		{
			//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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			Navigation noNavigation = default(Navigation);
			((Navigation)(ref noNavigation)).mode = (Mode)0;
			NoNavigation = noNavigation;
		}
	}
	internal sealed class WardrobeMenu : MonoBehaviour
	{
		private const int Columns = 3;

		private const float TileHeight = 76f;

		private const float TileGap = 8f;

		private const float RepeatDelay = 0.4f;

		private const float RepeatRate = 0.12f;

		private const float TurnSpeed = 150f;

		private const float ZoomSpeed = 6f;

		private List<SuitEntry> _visible = new List<SuitEntry>();

		private readonly Dictionary<SuitEntry, TextMeshProUGUI> _stars = new Dictionary<SuitEntry, TextMeshProUGUI>();

		private TextMeshProUGUI _hint;

		private TextMeshProUGUI _tabHint;

		private TextMeshProUGUI _favouriteHint;

		private Image[] _tabIcons;

		private Image _favouriteIcon;

		private Image _wearIcon;

		private Image _closeIcon;

		private const float HintIcon = 34f;

		private const float ButtonIcon = 38f;

		private bool _usingGamepad;

		private int _openedFrame;

		private Vector2Int _held;

		private float _nextRepeat;

		private const string AllTab = "All";

		private const string FavouritesTab = "Favourites";

		private const float PanelHeight = 800f;

		private const float Pad = 24f;

		private const float Gap = 14f;

		private const float TabsWidth = 220f;

		private const float ListLeft = 258f;

		private const float ListWidth = 860f;

		private const float SideLeft = 1142f;

		private const float SideWidth = 468f;

		private const float PanelWidth = 1634f;

		private const float ContentTop = 90f;

		private static WardrobeMenu _instance;

		private GameObject _screen;

		private TMP_InputField _search;

		private RectTransform _tabs;

		private RectTransform _grid;

		private ScrollRect _gridScroll;

		private TextMeshProUGUI _count;

		private RawImage _previewImage;

		private TextMeshProUGUI _selectedName;

		private TextMeshProUGUI _selectedSource;

		private Button _wear;

		private TextMeshProUGUI _wearLabel;

		private TextMeshProUGUI _closeLabel;

		private readonly PreviewCamera _preview = new PreviewCamera();

		private readonly Dictionary<SuitEntry, Image> _tiles = new Dictionary<SuitEntry, Image>();

		private readonly Dictionary<SuitEntry, RawImage> _pictures = new Dictionary<SuitEntry, RawImage>();

		private readonly Dictionary<string, Image> _tabButtons = new Dictionary<string, Image>();

		private readonly Dictionary<string, TextMeshProUGUI> _tabCounts = new Dictionary<string, TextMeshProUGUI>();

		private List<SuitEntry> _suits = new List<SuitEntry>();

		private string _tab = "All";

		private SuitEntry _selected;

		private PlayerControllerB _player;

		private readonly Queue<SuitEntry> _toPhotograph = new Queue<SuitEntry>();

		private PlayerControllerB _subject;

		private bool _inBackground;

		private float _nextCalmCheck;

		private float _nextSuitCheck;

		private bool _suitsChanged = true;

		private SuitEntry _posing;

		private int _posedAtFrame;

		private TextMeshProUGUI _photoProgress;

		private int _photoTotal;

		private bool _wasInSpecialMenu;

		private bool _wasTypingChat;

		private bool _wasMoveDisabled;

		private const int WarmUpFrames = 12;

		private const int PoseFrames = 6;

		private const float CalmInterval = 1f;

		private const float SuitInterval = 5f;

		internal static bool IsOpen
		{
			get
			{
				if ((Object)(object)_instance != (Object)null)
				{
					return (Object)(object)_instance._player != (Object)null;
				}
				return false;
			}
		}

		private void StartInput()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			_openedFrame = Time.frameCount;
			_held = Vector2Int.zero;
			_usingGamepad = (Object)(object)StartOfRound.Instance != (Object)null && StartOfRound.Instance.localPlayerUsingController;
			ShowHints();
		}

		private bool HandleGamepad()
		{
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: 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_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			Gamepad current = Gamepad.current;
			WatchDevice(current);
			if (current == null || Time.frameCount == _openedFrame)
			{
				return false;
			}
			if (current.buttonEast.wasPressedThisFrame || current.startButton.wasPressedThisFrame)
			{
				Hide(wear: false);
				return true;
			}
			if (current.buttonSouth.wasPressedThisFrame && ((Selectable)_wear).interactable)
			{
				Hide(wear: true);
				return true;
			}
			if (current.buttonWest.wasPressedThisFrame && _selected != null && _stars.TryGetValue(_selected, out var value))
			{
				ToggleFavourite(_selected, value);
			}
			if (current.leftShoulder.wasPressedThisFrame)
			{
				StepTab(-1);
			}
			if (current.rightShoulder.wasPressedThisFrame)
			{
				StepTab(1);
			}
			Vector2Int val = Direction(current);
			if (val != Vector2Int.zero)
			{
				MoveSelection(val);
			}
			Vector2 val2 = ((InputControl<Vector2>)(object)current.rightStick).ReadValue();
			if (Mathf.Abs(val2.x) > 0.2f)
			{
				_preview.Yaw += val2.x * 150f * Time.unscaledDeltaTime;
			}
			if (Mathf.Abs(val2.y) > 0.2f)
			{
				_preview.Zoom(val2.y * 6f * Time.unscaledDeltaTime);
			}
			return false;
		}

		private void WatchDevice(Gamepad pad)
		{
			//IL_00b0: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val;
			int num;
			if (pad != null)
			{
				if (!pad.buttonSouth.wasPressedThisFrame && !pad.buttonEast.wasPressedThisFrame && !pad.buttonWest.wasPressedThisFrame && !pad.leftShoulder.wasPressedThisFrame && !pad.rightShoulder.wasPressedThisFrame)
				{
					val = ((InputControl<Vector2>)(object)pad.dpad).ReadValue();
					if (!(((Vector2)(ref val)).sqrMagnitude > 0.25f))
					{
						val = ((InputControl<Vector2>)(object)pad.leftStick).ReadValue();
						if (!(((Vector2)(ref val)).sqrMagnitude > 0.25f))
						{
							val = ((InputControl<Vector2>)(object)pad.rightStick).ReadValue();
							num = ((((Vector2)(ref val)).sqrMagnitude > 0.25f) ? 1 : 0);
							goto IL_009e;
						}
					}
				}
				num = 1;
			}
			else
			{
				num = 0;
			}
			goto IL_009e;
			IL_00f1:
			int num2;
			bool flag = (byte)num2 != 0;
			bool flag2;
			if (flag2 != flag && flag2 != _usingGamepad)
			{
				_usingGamepad = flag2;
				if (flag2 && (Object)(object)EventSystem.current != (Object)null)
				{
					EventSystem.current.SetSelectedGameObject((GameObject)null);
				}
				ShowHints();
			}
			return;
			IL_009e:
			flag2 = (byte)num != 0;
			if (Mouse.current != null)
			{
				val = ((InputControl<Vector2>)(object)((Pointer)Mouse.current).delta).ReadValue();
				if (((Vector2)(ref val)).sqrMagnitude > 4f || Mouse.current.leftButton.wasPressedThisFrame)
				{
					num2 = 1;
					goto IL_00f1;
				}
			}
			num2 = ((Keyboard.current != null && ((ButtonControl)Keyboard.current.anyKey).wasPressedThisFrame) ? 1 : 0);
			goto IL_00f1;
		}

		private string Prompt(Image icon, string control, string xbox, string playStation)
		{
			Sprite val = (icon.sprite = ((_usingGamepad && control != null) ? PadGlyphs.Get(control) : null));
			((Component)icon).gameObject.SetActive((Object)(object)val != (Object)null);
			if (!_usingGamepad || control == null || (Object)(object)val != (Object)null)
			{
				return string.Empty;
			}
			return "[" + ((Gamepad.current is DualShockGamepad) ? playStation : xbox) + "] ";
		}

		private string ButtonPrompt(Image icon, TextMeshProUGUI label, string control, string xbox, string playStation)
		{
			//IL_0031: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			string result = Prompt(icon, control, xbox, playStation);
			bool activeSelf = ((Component)icon).gameObject.activeSelf;
			RectTransform rectTransform = ((Graphic)icon).rectTransform;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 0.5f);
			rectTransform.anchorMax = val;
			rectTransform.anchorMin = val;
			rectTransform.pivot = new Vector2(0f, 0.5f);
			rectTransform.anchoredPosition = new Vector2(14f, 0f);
			rectTransform.sizeDelta = new Vector2(38f, 38f);
			((TMP_Text)label).rectTransform.offsetMin = new Vector2(activeSelf ? 56f : 0f, 0f);
			((TMP_Text)label).rectTransform.offsetMax = new Vector2(activeSelf ? (-10f) : 0f, 0f);
			return result;
		}

		private void ShowHints()
		{
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			((TMP_Text)_hint).text = (_usingGamepad ? "Right stick to turn and zoom" : "Drag to turn, scroll to zoom");
			string text = Prompt(_tabIcons[0], "leftShoulder", "LB", "L1") + Prompt(_tabIcons[1], "rightShoulder", "RB", "R1");
			bool activeSelf = ((Component)_tabIcons[0]).gameObject.activeSelf;
			((TMP_Text)_tabHint).text = (_usingGamepad ? (text + "Tab") : string.Empty);
			((TMP_Text)_tabHint).rectTransform.anchoredPosition = new Vector2(24f + (activeSelf ? 80f : 0f), 20f);
			((TMP_Text)_favouriteHint).text = (_usingGamepad ? (Prompt(_favouriteIcon, "buttonWest", "X", "Square") + "Favourite") : string.Empty);
			if (!_usingGamepad)
			{
				Prompt(_favouriteIcon, null, null, null);
			}
			float num = 1118f - ((TMP_Text)_favouriteHint).preferredWidth;
			Ui.Box(((Graphic)_favouriteIcon).rectTransform, num - 6f - 34f, 752f, 34f, 28f);
			((TMP_Text)_closeLabel).text = ButtonPrompt(_closeIcon, _closeLabel, "buttonEast", "B", "Circle") + "Close";
			ShowSelected();
		}

		private static void FitLabel(TextMeshProUGUI label)
		{
			((TMP_Text)label).enableAutoSizing = true;
			((TMP_Text)label).fontSizeMax = ((TMP_Text)label).fontSize;
			((TMP_Text)label).fontSizeMin = 16f;
			((TMP_Text)label).overflowMode = (TextOverflowModes)0;
		}

		private Vector2Int Direction(Gamepad pad)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0025: 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_0032: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = ((InputControl<Vector2>)(object)pad.leftStick).ReadValue();
			Vector2 val2 = ((InputControl<Vector2>)(object)pad.dpad).ReadValue();
			int num = ((val2.x > 0.5f || val.x > 0.6f) ? 1 : ((val2.x < -0.5f || val.x < -0.6f) ? (-1) : 0));
			int num2 = ((val2.y > 0.5f || val.y > 0.6f) ? 1 : ((val2.y < -0.5f || val.y < -0.6f) ? (-1) : 0));
			Vector2Int val3 = default(Vector2Int);
			((Vector2Int)(ref val3))..ctor(num, num2);
			if (val3 == Vector2Int.zero || val3 != _held)
			{
				_held = val3;
				_nextRepeat = Time.unscaledTime + 0.4f;
				return val3;
			}
			if (Time.unscaledTime < _nextRepeat)
			{
				return Vector2Int.zero;
			}
			_nextRepeat = Time.unscaledTime + 0.12f;
			return val3;
		}

		private void MoveSelection(Vector2Int step)
		{
			if (_visible.Count == 0)
			{
				return;
			}
			int num = _visible.IndexOf(_selected);
			int num2 = ((num >= 0) ? (num + ((Vector2Int)(ref step)).x - ((Vector2Int)(ref step)).y * 3) : 0);
			if (num2 < 0)
			{
				return;
			}
			if (num2 >= _visible.Count)
			{
				int num3 = _visible.Count - 1;
				if (((Vector2Int)(ref step)).y >= 0 || num3 / 3 == num / 3)
				{
					return;
				}
				num2 = num3;
			}
			if (num2 != num)
			{
				Select(_visible[num2]);
				ScrollTo(num2);
			}
		}

		private void ScrollTo(int index)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_0040: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			float num = (float)(index / 3) * 84f;
			float num2 = num + 76f + 8f;
			Rect rect = _gridScroll.viewport.rect;
			float height = ((Rect)(ref rect)).height;
			Vector2 anchoredPosition = _grid.anchoredPosition;
			if (num < anchoredPosition.y)
			{
				anchoredPosition.y = num;
			}
			else if (num2 > anchoredPosition.y + height)
			{
				anchoredPosition.y = num2 - height;
			}
			float y = anchoredPosition.y;
			rect = _grid.rect;
			anchoredPosition.y = Mathf.Clamp(y, 0f, Mathf.Max(0f, ((Rect)(ref rect)).height - height));
			_grid.anchoredPosition = anchoredPosition;
		}

		private void StepTab(int direction)
		{
			List<string> list = TabNames().ToList();
			int num = (list.IndexOf(_tab) + direction + list.Count) % list.Count;
			SelectTab(list[num]);
			ScrollRect componentInParent = ((Component)_tabs).GetComponentInParent<ScrollRect>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				componentInParent.verticalNormalizedPosition = ((list.Count > 1) ? (1f - (float)num / (float)(list.Count - 1)) : 1f);
			}
		}

		internal static void Open(PlayerControllerB player)
		{
			if (!((Object)(object)player == (Object)null) && !((Object)(object)player != (Object)(object)GameNetworkManager.Instance?.localPlayerController) && !IsOpen && !player.isPlayerDead && !player.inTerminalMenu && !player.quickMenuManager.isMenuOpen)
			{
				Prepare();
				if (!_instance._inBackground)
				{
					_instance.Show(player);
				}
			}
		}

		internal static void SuitsChanged()
		{
			if ((Object)(object)_instance != (Object)null)
			{
				_instance._suitsChanged = true;
			}
		}

		internal static void Prepare()
		{
			if ((Object)(object)_instance == (Object)null)
			{
				_instance = Create();
			}
		}

		internal static void Dispose()
		{
			if (!((Object)(object)_instance == (Object)null))
			{
				_instance.Hide(wear: false);
				_instance.StopBackground();
				_instance._preview.Dispose();
				Object.Destroy((Object)(object)((Component)_instance).gameObject);
				_instance = null;
			}
		}

		private static WardrobeMenu Create()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			WardrobeMenu wardrobeMenu = new GameObject("SuitWardrobeSimpleMenu").AddComponent<WardrobeMenu>();
			wardrobeMenu.Build();
			return wardrobeMenu;
		}

		private void Show(PlayerControllerB player)
		{
			_player = player;
			_suits = SuitCatalog.Owned();
			TryOn.Begin(player);
			_selected = _suits.FirstOrDefault((SuitEntry suit) => suit.Id == player.currentSuitID);
			string lastTab = Saved.LastTab;
			_tab = (TabNames().Contains(lastTab) ? lastTab : "All");
			_search.SetTextWithoutNotify(string.Empty);
			BuildTabs();
			Refresh();
			ShowSelected();
			_preview.Start(player);
			_previewImage.texture = (Texture)(object)_preview.Texture;
			_screen.SetActive(true);
			LockPlayer();
			StartInput();
			_subject = player;
			QueuePhotos(_suits.Where((SuitEntry suit) => !Thumbnails.Has(suit.Name)));
		}

		private void Hide(bool wear)
		{
			if (!((Object)(object)_player == (Object)null))
			{
				StopPhotos(showSelected: false);
				_suitsChanged = true;
				PlayerControllerB player = _player;
				_player = null;
				_subject = null;
				if (wear && _selected != null && _selected.Id != TryOn.Original)
				{
					TryOn.Wear(player, _selected.Hanger);
				}
				else
				{
					TryOn.Cancel(player);
				}
				Saved.LastTab = _tab;
				_preview.Stop();
				_screen.SetActive(false);
				UnlockPlayer(player);
			}
		}

		private void Update()
		{
			if ((Object)(object)_player == (Object)null)
			{
				Background();
			}
			else if (_player.isPlayerDead || !_player.isPlayerControlled)
			{
				Hide(wear: false);
			}
			else if (Keyboard.current != null && ((ButtonControl)Keyboard.current.escapeKey).wasPressedThisFrame)
			{
				Hide(wear: false);
			}
			else if (!HandleGamepad())
			{
				HoldLocks();
				TakePhotos();
			}
		}

		private void LateUpdate()
		{
			if ((Object)(object)_subject != (Object)null)
			{
				_preview.Place();
			}
		}

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

		private void LockPlayer()
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			_wasInSpecialMenu = _player.inSpecialMenu;
			_wasTypingChat = _player.isTypingChat;
			_wasMoveDisabled = _player.disableMoveInput;
			HoldLocks();
			((Behaviour)_player.cursorIcon).enabled = false;
			((TMP_Text)_player.cursorTip).text = string.Empty;
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
			if ((Object)(object)HUDManager.Instance != (Object)null)
			{
				HUDManager.Instance.SetMouseCursorSprite(HUDManager.Instance.defaultCursorTex, default(Vector2));
			}
		}

		private void HoldLocks()
		{
			_player.inSpecialMenu = true;
			_player.isTypingChat = true;
			_player.disableMoveInput = true;
		}

		private void UnlockPlayer(PlayerControllerB player)
		{
			player.inSpecialMenu = _wasInSpecialMenu;
			player.isTypingChat = _wasTypingChat;
			player.disableMoveInput = _wasMoveDisabled;
			if ((Object)(object)EventSystem.current != (Object)null)
			{
				EventSystem.current.SetSelectedGameObject((GameObject)null);
			}
			Cursor.lockState = (CursorLockMode)1;
			Cursor.visible = false;
		}

		private IEnumerable<string> TabNames()
		{
			yield return "All";
			yield return "Favourites";
			IEnumerable<string> sources = _suits.Select((SuitEntry suit) => suit.Tab).Distinct().ToList();
			if (sources.Contains("Vanilla"))
			{
				yield return "Vanilla";
			}
			foreach (string item in sources.Where((string source) => source != "Vanilla" && source != "Other").OrderBy<string, string>((string source) => source, StringComparer.OrdinalIgnoreCase))
			{
				yield return item;
			}
			if (sources.Contains("Other"))
			{
				yield return "Other";
			}
		}

		private void BuildTabs()
		{
			//IL_0014: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Expected O, but got Unknown
			foreach (Transform item in (Transform)_tabs)
			{
				Object.Destroy((Object)(object)((Component)item).gameObject);
			}
			_tabButtons.Clear();
			_tabCounts.Clear();
			foreach (string item2 in TabNames())
			{
				string name = item2;
				Button val = Ui.Button((Transform)(object)_tabs, "Tab " + name, null, 0f, Ui.Raised, (UnityAction)delegate
				{
					SelectTab(name);
				});
				((Component)val).gameObject.AddComponent<LayoutElement>().preferredHeight = 40f;
				TextMeshProUGUI obj = Ui.Label(((Component)val).transform, "Name", name, 20f, (TextAlignmentOptions)4097);
				((TMP_Text)obj).rectTransform.anchorMin = Vector2.zero;
				((TMP_Text)obj).rectTransform.anchorMax = Vector2.one;
				((TMP_Text)obj).rectTransform.offsetMin = new Vector2(12f, 0f);
				((TMP_Text)obj).rectTransform.offsetMax = new Vector2(-46f, 0f);
				TextMeshProUGUI val2 = Ui.Label(((Component)val).transform, "Count", string.Empty, 18f, (TextAlignmentOptions)4100);
				((Graphic)val2).color = Ui.Muted;
				((TMP_Text)val2).rectTransform.anchorMin = new Vector2(1f, 0f);
				((TMP_Text)val2).rectTransform.anchorMax = new Vector2(1f, 1f);
				((TMP_Text)val2).rectTransform.pivot = new Vector2(1f, 0.5f);
				((TMP_Text)val2).rectTransform.anchoredPosition = new Vector2(-10f, 0f);
				((TMP_Text)val2).rectTransform.sizeDelta = new Vector2(40f, 0f);
				_tabButtons[name] = (Image)((Selectable)val).targetGraphic;
				_tabCounts[name] = val2;
			}
			CountTabs();
			PaintTabs();
		}

		private void CountTabs()
		{
			foreach (KeyValuePair<string, TextMeshProUGUI> tabCount in _tabCounts)
			{
				string tab = tabCount.Key;
				int num = ((tab == "All") ? _suits.Count : ((tab == "Favourites") ? _suits.Count((SuitEntry suit) => Saved.IsFavourite(suit.Name)) : _suits.Count((SuitEntry suit) => suit.Tab == tab)));
				((TMP_Text)tabCount.Value).text = num.ToString();
			}
		}

		private void SelectTab(string tab)
		{
			_tab = tab;
			PaintTabs();
			Refresh();
		}

		private void PaintTabs()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			foreach (KeyValuePair<string, Image> tabButton in _tabButtons)
			{
				((Graphic)tabButton.Value).color = ((tabButton.Key == _tab) ? Ui.AccentDark : Ui.Raised);
			}
		}

		private IEnumerable<SuitEntry> Visible()
		{
			string query = _search.text.Trim();
			return _suits.Where((SuitEntry suit) => (_tab == "All" || (_tab == "Favourites" && Saved.IsFavourite(suit.Name)) || suit.Tab == _tab) && (query.Length == 0 || suit.Name.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0));
		}

		private void Refresh()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			foreach (Transform item in (Transform)_grid)
			{
				Object.Destroy((Object)(object)((Component)item).gameObject);
			}
			_tiles.Clear();
			_pictures.Clear();
			_stars.Clear();
			List<SuitEntry> list = (_visible = Visible().ToList());
			foreach (SuitEntry item2 in list)
			{
				_tiles[item2] = AddTile(item2);
			}
			((TMP_Text)_count).text = ((list.Count == 1) ? "1 suit" : $"{list.Count} suits");
			if (list.Count == 0)
			{
				((TMP_Text)_count).text = ((_tab == "Favourites" && _search.text.Length == 0) ? "No favourites yet: star a suit to keep it here." : "No suits match.");
			}
			_gridScroll.verticalNormalizedPosition = 1f;
			PaintTiles();
		}

		private Image AddTile(SuitEntry suit)
		{
			//IL_0035: 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_004b: Expected O, but got Unknown
			//IL_00a6: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: 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_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Expected O, but got Unknown
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Expected O, but got Unknown
			Button obj = Ui.Button((Transform)(object)_grid, "Suit " + suit.Name, null, 0f, Ui.Raised, (UnityAction)delegate
			{
				Select(suit);
			});
			Transform transform = ((Component)obj).transform;
			RawImage val = ((Component)Ui.Rect("Thumbnail", transform)).gameObject.AddComponent<RawImage>();
			((Graphic)val).raycastTarget = false;
			ShowPicture(val, suit);
			_pictures[suit] = val;
			RectTransform rectTransform = ((Graphic)val).rectTransform;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0f, 0.5f);
			rectTransform.anchorMax = val2;
			rectTransform.anchorMin = val2;
			rectTransform.pivot = new Vector2(0f, 0.5f);
			rectTransform.anchoredPosition = new Vector2(8f, 0f);
			rectTransform.sizeDelta = new Vector2(58f, 58f);
			TextMeshProUGUI obj2 = Ui.Label(transform, "Name", suit.Name, 22f, (TextAlignmentOptions)4097);
			((TMP_Text)obj2).rectTransform.anchorMin = new Vector2(0f, 0.45f);
			((TMP_Text)obj2).rectTransform.anchorMax = new Vector2(1f, 1f);
			((TMP_Text)obj2).rectTransform.offsetMin = new Vector2(76f, 0f);
			((TMP_Text)obj2).rectTransform.offsetMax = new Vector2(-44f, -6f);
			TextMeshProUGUI obj3 = Ui.Label(transform, "Source", (suit.Id == TryOn.Original) ? "Wearing" : suit.Source, 16f, (TextAlignmentOptions)4097);
			((Graphic)obj3).color = ((suit.Id == TryOn.Original) ? Ui.Accent : Ui.Muted);
			((TMP_Text)obj3).rectTransform.anchorMin = new Vector2(0f, 0f);
			((TMP_Text)obj3).rectTransform.anchorMax = new Vector2(1f, 0.45f);
			((TMP_Text)obj3).rectTransform.offsetMin = new Vector2(76f, 6f);
			((TMP_Text)obj3).rectTransform.offsetMax = new Vector2(-44f, 0f);
			Button val3 = Ui.Button(transform, "Favourite", "*", 30f, Ui.Inset, null);
			RectTransform val4 = (RectTransform)((Component)val3).transform;
			((Vector2)(ref val2))..ctor(1f, 0.5f);
			val4.anchorMax = val2;
			val4.anchorMin = val2;
			val4.pivot = new Vector2(1f, 0.5f);
			val4.anchoredPosition = new Vector2(-8f, 0f);
			val4.sizeDelta = new Vector2(32f, 32f);
			TextMeshProUGUI starLabel = ((Component)val3).GetComponentInChildren<TextMeshProUGUI>();
			PaintStar(starLabel, suit);
			_stars[suit] = starLabel;
			((UnityEvent)val3.onClick).AddListener((UnityAction)delegate
			{
				ToggleFavourite(suit, starLabel);
			});
			return (Image)((Selectable)obj).targetGraphic;
		}

		private static void PaintStar(TextMeshProUGUI label, SuitEntry suit)
		{
			//IL_0029: 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)
			((Graphic)label).color = (Color)(Saved.IsFavourite(suit.Name) ? Ui.Accent : new Color(0.35f, 0.32f, 0.3f, 1f));
		}

		private void ToggleFavourite(SuitEntry suit, TextMeshProUGUI starLabel)
		{
			Saved.ToggleFavourite(suit.Name);
			CountTabs();
			if (_tab == "Favourites")
			{
				Refresh();
			}
			else
			{
				PaintStar(starLabel, suit);
			}
		}

		private void PaintTiles()
		{
			//IL_0033: 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)
			foreach (KeyValuePair<SuitEntry, Image> tile in _tiles)
			{
				((Graphic)tile.Value).color = ((tile.Key == _selected) ? Ui.AccentDark : Ui.Raised);
			}
		}

		private void Select(SuitEntry suit)
		{
			StopPhotos(showSelected: false);
			_selected = suit;
			TryOn.Show(_player, suit.Id);
			PaintTiles();
			ShowSelected();
		}

		private void ShowSelected()
		{
			bool flag = _selected == null || _selected.Id == TryOn.Original;
			((TMP_Text)_selectedName).text = _selected?.Name ?? string.Empty;
			((TMP_Text)_selectedSource).text = _selected?.Source ?? string.Empty;
			((Selectable)_wear).interactable = !flag;
			((TMP_Text)_wearLabel).text = (flag ? "Wearing" : (ButtonPrompt(_wearIcon, _wearLabel, "buttonSouth", "A", "Cross") + "Wear"));
			if (flag)
			{
				ButtonPrompt(_wearIcon, _wearLabel, null, null, null);
			}
		}

		private static void ShowPicture(RawImage image, SuitEntry suit)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = (Texture2D)(object)(image.texture = (Texture)(object)Thumbnails.Get(suit.Name));
			((Graphic)image).color = (((Object)(object)val != (Object)null) ? Color.white : Ui.Inset);
		}

		private void QueuePhotos(IEnumerable<SuitEntry> suits)
		{
			_toPhotograph.Clear();
			foreach (SuitEntry suit in suits)
			{
				_toPhotograph.Enqueue(suit);
			}
			_photoTotal = _toPhotograph.Count;
			_posing = null;
			UpdatePhotoProgress();
		}

		private bool TakePhotos()
		{
			if (_posing == null)
			{
				if (_toPhotograph.Count == 0)
				{
					return false;
				}
				if (_preview.FramesDrawn < 12)
				{
					return true;
				}
				_posing = _toPhotograph.Dequeue();
				_preview.ResetView();
				TryOn.Show(_subject, _posing.Id);
				_posedAtFrame = _preview.FramesDrawn;
				return true;
			}
			if (_preview.FramesDrawn - _posedAtFrame < 6)
			{
				return true;
			}
			Thumbnails.Store(_posing.Name, _preview.Snapshot(160));
			if (_pictures.TryGetValue(_posing, out var value))
			{
				ShowPicture(value, _posing);
			}
			_posing = null;
			UpdatePhotoProgress();
			if (_inBackground)
			{
				ShowBackgroundProgress();
			}
			if (_toPhotograph.Count > 0)
			{
				return true;
			}
			if ((Object)(object)_player != (Object)null)
			{
				StopPhotos(showSelected: true);
			}
			return false;
		}

		private void StopPhotos(bool showSelected)
		{
			_toPhotograph.Clear();
			_posing = null;
			UpdatePhotoProgress();
			if (showSelected && (Object)(object)_player != (Object)null)
			{
				TryOn.Show(_player, _selected?.Id ?? TryOn.Original);
			}
		}

		private void Background()
		{
			if (_inBackground)
			{
				if (!CanTakePhotos(_subject) || !TakePhotos())
				{
					StopBackground();
				}
			}
			else
			{
				if (Time.time < _nextCalmCheck)
				{
					return;
				}
				_nextCalmCheck = Time.time + 1f;
				PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
				if (_suitsChanged && CanTakePhotos(val) && !(Time.time < _nextSuitCheck))
				{
					_nextSuitCheck = Time.time + 5f;
					List<SuitEntry> list = (from suit in SuitCatalog.Owned()
						where !Thumbnails.Has(suit.Name)
						select suit).ToList();
					if (list.Count == 0)
					{
						_suitsChanged = false;
						return;
					}
					_inBackground = true;
					_subject = val;
					TryOn.Begin(val);
					_preview.HideOwnArms = true;
					_preview.Start(val);
					QueuePhotos(list);
					ShowBackgroundProgress();
				}
			}
		}

		private void ShowBackgroundProgress()
		{
			int num = _photoTotal - _toPhotograph.Count - ((_posing != null) ? 1 : 0);
			RackTrigger.SetBusy($"Preparing wardrobe... {num}/{_photoTotal}");
		}

		private static bool CanTakePhotos(PlayerControllerB player)
		{
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)player == (Object)null || (Object)(object)instance == (Object)null)
			{
				return false;
			}
			if (!player.isPlayerControlled || player.isPlayerDead)
			{
				return false;
			}
			if (player.inTerminalMenu || player.inSpecialInteractAnimation)
			{
				return false;
			}
			if (instance.inShipPhase && !instance.travellingToNewLevel)
			{
				return !instance.shipIsLeaving;
			}
			return false;
		}

		private void StopBackground()
		{
			if (_inBackground)
			{
				_suitsChanged = true;
				_inBackground = false;
				StopPhotos(showSelected: false);
				TryOn.Cancel(_subject);
				_preview.Stop();
				_preview.HideOwnArms = false;
				_subject = null;
				RackTrigger.SetBusy(null);
			}
		}

		private void UpdatePhotoProgress()
		{
			int num = _toPhotograph.Count + ((_posing != null) ? 1 : 0);
			((TMP_Text)_photoProgress).text = ((num == 0) ? string.Empty : $"Taking pictures {_photoTotal - num + 1} / {_photoTotal}\nclick a suit to skip");
		}

		private void Build()
		{
			//IL_0041: 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_00a3: 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_00cd: 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)
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			Canvas obj = ((Component)this).gameObject.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)0;
			obj.sortingOrder = 50;
			CanvasScaler obj2 = ((Component)this).gameObject.AddComponent<CanvasScaler>();
			obj2.uiScaleMode = (ScaleMode)1;
			obj2.referenceResolution = new Vector2(1920f, 1080f);
			obj2.matchWidthOrHeight = 0.5f;
			((Component)this).gameObject.AddComponent<GraphicRaycaster>();
			Image val = Ui.Image(((Component)this).transform, "Backdrop", Ui.Backdrop);
			Ui.Fill(((Graphic)val).rectTransform);
			_screen = ((Component)val).gameObject;
			Image val2 = Ui.Image(_screen.transform, "Panel", Ui.Panel);
			RectTransform rectTransform = ((Graphic)val2).rectTransform;
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0.5f, 0.5f);
			rectTransform.anchorMax = val3;
			rectTransform.anchorMin = val3;
			rectTransform.sizeDelta = new Vector2(1634f, 800f);
			Ui.Box(((Graphic)Ui.Image(((Component)val2).transform, "Stripe", Ui.Accent)).rectTransform, 0f, 0f, 1634f, 4f);
			BuildList(((Component)val2).transform);
			BuildSide(((Component)val2).transform);
			_screen.SetActive(false);
		}

		private void BuildList(Transform panel)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Expected O, but got Unknown
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Expected O, but got Unknown
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Expected O, but got Unknown
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Expected O, but got Unknown
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_038e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			//IL_03af: Unknown res