Decompiled source of SuitWardrobeSimple v0.1.0

SuitWardrobeSimple.dll

Decompiled 4 hours 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 Microsoft.CodeAnalysis;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
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.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("SuitWardrobeSimple")]
[assembly: AssemblyTitle("SuitWardrobeSimple")]
[assembly: AssemblyVersion("0.1.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 void Init(ConfigFile config)
		{
			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.");
		}
	}
	[BepInPlugin("dev.davesco.SuitWardrobeSimple", "SuitWardrobeSimple", "0.1.0")]
	[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.1.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 float _nextFit;

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

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

		private void OnEnable()
		{
			_instance = this;
			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)
		{
			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;
				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>();
				for (int num = 0; num < componentsInChildren.Length; num++)
				{
					componentsInChildren[num].enabled = false;
				}
				InteractTrigger component = ((Component)item).GetComponent<InteractTrigger>();
				if ((Object)(object)component != (Object)null)
				{
					((Behaviour)component).enabled = false;
					component.interactable = false;
				}
			}
		}

		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;
			Renderer[] componentsInChildren = ((Component)suit).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (flag)
				{
					if (val.enabled)
					{
						val.enabled = false;
						_hidden.Add(val);
					}
				}
				else if (_hidden.Remove(val))
				{
					val.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)
			{
				if ((Object)(object)_pageLabel == (Object)null)
				{
					_pageLabel = GameObject.Find("TooManySuitsPageLabel");
				}
				_pageLabelHidden = Show(_pageLabel, !Settings.HidePageButtons.Value, _pageLabelHidden);
			}
			if ((Object)(object)_boots == (Object)null)
			{
				_boots = GameObject.Find("ScavengerModelSuitParts");
			}
			_bootsHidden = Show(_boots, Settings.ShowBoots.Value, _bootsHidden);
		}

		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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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_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_00ad: 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)
			if ((Object)(object)_pageLabel == (Object)null)
			{
				_pageLabel = GameObject.Find("TooManySuitsPageLabel");
			}
			if ((Object)(object)_pageLabel == (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))));
			}
		}
	}
	internal sealed class SuitEntry
	{
		internal int Id;

		internal string Name;

		internal string Source;

		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];
					list2.Add(new SuitEntry
					{
						Id = value,
						Name = val.unlockableName,
						Source = SuitSources.SourceOf(val.unlockableName),
						Hanger = item
					});
				}
			}
			return list2;
		}
	}
	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 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 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);

		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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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).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_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: 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).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 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;
		}
	}
	internal sealed class WardrobeMenu : MonoBehaviour
	{
		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 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 string _lastWait;

		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;
			}
		}

		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 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();
			_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);
				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();
				return;
			}
			if (_player.isPlayerDead || !_player.isPlayerControlled)
			{
				Hide(wear: false);
				return;
			}
			if (Keyboard.current != null && ((ButtonControl)Keyboard.current.escapeKey).wasPressedThisFrame)
			{
				Hide(wear: false);
				return;
			}
			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.Source).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.Source == 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.Source == _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();
			List<SuitEntry> list = 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_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Expected O, but got Unknown
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: 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);
			((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" : "Wear");
		}

		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)
			{
				string text = WaitReason(_subject);
				if (text != null)
				{
					Plugin.mlg.LogInfo((object)("Wardrobe pictures paused: " + text + ". The rest are taken later."));
					StopBackground();
				}
				else if (!TakePhotos())
				{
					Plugin.mlg.LogInfo((object)"Wardrobe pictures done.");
					StopBackground();
				}
			}
			else
			{
				if (Time.time < _nextCalmCheck)
				{
					return;
				}
				_nextCalmCheck = Time.time + 1f;
				PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
				string text2 = WaitReason(val);
				if (text2 != _lastWait && text2 != null)
				{
					Plugin.mlg.LogDebug((object)("Wardrobe pictures waiting: " + text2 + "."));
				}
				_lastWait = text2;
				if (text2 == null && !(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)
					{
						Plugin.mlg.LogInfo((object)$"Taking pictures of {list.Count} suit(s) for the wardrobe.");
						_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 string WaitReason(PlayerControllerB player)
		{
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)player == (Object)null || (Object)(object)instance == (Object)null)
			{
				return "no local player yet";
			}
			if (!player.isPlayerControlled || player.isPlayerDead)
			{
				return "player not in control";
			}
			if (player.inTerminalMenu || player.inSpecialInteractAnimation)
			{
				return "player busy";
			}
			if (!instance.inShipPhase || instance.travellingToNewLevel || instance.shipIsLeaving)
			{
				return "not in orbit";
			}
			return null;
		}

		private void StopBackground()
		{
			if (_inBackground)
			{
				_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)
			TextMeshProUGUI obj = Ui.Label(panel, "Title", "WARDROBE", 44f, (TextAlignmentOptions)4097);
			((Graphic)obj).color = Ui.Accent;
			Ui.Box(((TMP_Text)obj).rectTransform, 24f, 20f, 360f, 56f);
			_search = Ui.InputField(panel, "Search", "Search suits...", 24f);
			Ui.Box((RectTransform)((Component)_search).transform, 758f, 26f, 360f, 46f);
			((UnityEvent<string>)(object)_search.onValueChanged).AddListener((UnityAction<string>)delegate
			{
				Refresh();
			});
			_tabs = Ui.Scroll(panel, "Tabs", vertical: true, out var scroll);
			Ui.Column((RectTransform)((Component)scroll).transform, 24f, 90f, 220f, 24f);
			VerticalLayoutGroup obj2 = ((Component)_tabs).gameObject.AddComponent<VerticalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)obj2).spacing = 6f;
			((LayoutGroup)obj2).padding = new RectOffset(0, 0, 0, 8);
			((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = false;
			_grid = Ui.Scroll(panel, "Suits", vertical: true, out _gridScroll);
			Ui.Column((RectTransform)((Component)_gridScroll).transform, 258f, 90f, 860f, 56f);
			GridLayoutGroup obj3 = ((Component)_grid).gameObject.AddComponent<GridLayoutGroup>();
			obj3.cellSize = new Vector2(278f, 76f);
			obj3.spacing = new Vector2(8f, 8f);
			((LayoutGroup)obj3).padding = new RectOffset(5, 5, 0, 8);
			obj3.constraint = (Constraint)1;
			obj3.constraintCount = 3;
			_count = Ui.Label(panel, "Count", string.Empty, 18f, (TextAlignmentOptions)4097);
			((Graphic)_count).color = Ui.Muted;
			RectTransform rectTransform = ((TMP_Text)_count).rectTransform;
			RectTransform rectTransform2 = ((TMP_Text)_count).rectTransform;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 0f);
			rectTransform2.anchorMax = val;
			rectTransform.anchorMin = val;
			((TMP_Text)_count).rectTransform.pivot = new Vector2(0f, 0f);
			((TMP_Text)_count).rectTransform.anchoredPosition = new Vector2(258f, 20f);
			((TMP_Text)_count).rectTransform.sizeDelta = new Vector2(860f, 28f);
		}

		private void BuildSide(Transform panel)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: 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_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Expected O, but got Unknown
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Expected O, but got Unknown
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Expected O, but got Unknown
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Expected O, but got Unknown
			Image val = Ui.Image(panel, "Preview", Ui.Inset);
			Ui.Box(((Graphic)val).rectTransform, 1142f, 24f, 468f, 560f);
			_previewImage = ((Component)Ui.Rect("View", ((Component)val).transform)).gameObject.AddComponent<RawImage>();
			Ui.Fill(((Graphic)_previewImage).rectTransform, 4f);
			AspectRatioFitter obj = ((Component)_previewImage).gameObject.AddComponent<AspectRatioFitter>();
			obj.aspectMode = (AspectMode)3;
			obj.aspectRatio = 0.72727275f;
			((Component)_previewImage).gameObject.AddComponent<PreviewDrag>().Camera = _preview;
			TextMeshProUGUI obj2 = Ui.Label(((Component)val).transform, "Hint", "Drag to turn, scroll to zoom", 16f, (TextAlignmentOptions)514);
			((Graphic)obj2).color = Ui.Muted;
			((TMP_Text)obj2).rectTransform.anchorMin = new Vector2(0f, 0f);
			((TMP_Text)obj2).rectTransform.anchorMax = new Vector2(1f, 0f);
			((TMP_Text)obj2).rectTransform.pivot = new Vector2(0.5f, 0f);
			((TMP_Text)obj2).rectTransform.anchoredPosition = new Vector2(0f, 10f);
			((TMP_Text)obj2).rectTransform.sizeDelta = new Vector2(0f, 24f);
			_photoProgress = Ui.Label(((Component)val).transform, "Photos", string.Empty, 18f, (TextAlignmentOptions)514);
			((Graphic)_photoProgress).color = Ui.Accent;
			((TMP_Text)_photoProgress).rectTransform.anchorMin = new Vector2(0f, 1f);
			((TMP_Text)_photoProgress).rectTransform.anchorMax = new Vector2(1f, 1f);
			((TMP_Text)_photoProgress).rectTransform.pivot = new Vector2(0.5f, 1f);
			((TMP_Text)_photoProgress).rectTransform.anchoredPosition = new Vector2(0f, -10f);
			((TMP_Text)_photoProgress).rectTransform.sizeDelta = new Vector2(0f, 48f);
			_selectedName = Ui.Label(panel, "Selected", string.Empty, 32f, (TextAlignmentOptions)4097);
			Ui.Box(((TMP_Text)_selectedName).rectTransform, 1142f, 596f, 468f, 42f);
			_selectedSource = Ui.Label(panel, "SelectedSource", string.Empty, 20f, (TextAlignmentOptions)4097);
			((Graphic)_selectedSource).color = Ui.Muted;
			Ui.Box(((TMP_Text)_selectedSource).rectTransform, 1142f, 638f, 468f, 28f);
			_wear = Ui.Button(panel, "Wear", "Wear", 30f, Ui.AccentDark, (UnityAction)delegate
			{
				Hide(wear: true);
			});
			_wearLabel = ((Component)_wear).GetComponentInChildren<TextMeshProUGUI>();
			Ui.Box((RectTransform)((Component)_wear).transform, 1142f, 712f, 288f, 64f);
			Ui.Box((RectTransform)((Component)Ui.Button(panel, "Close", "Close", 26f, Ui.Raised, (UnityAction)delegate
			{
				Hide(wear: false);
			})).transform, 1442f, 712f, 168f, 64f);
		}
	}
	internal sealed class PreviewDrag : MonoBehaviour, IDragHandler, IEventSystemHandler, IScrollHandler
	{
		internal PreviewCamera Camera;

		public void OnDrag(PointerEventData eventData)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			if (Camera != null)
			{
				Camera.Yaw += eventData.delta.x * 0.5f;
			}
		}

		public void OnScroll(PointerEventData eventData)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if (Camera != null && eventData.scrollDelta.y != 0f)
			{
				Camera.Zoom(Mathf.Sign(eventData.scrollDelta.y));
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "SuitWardrobeSimple";

		public const string PLUGIN_NAME = "SuitWardrobeSimple";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}
namespace SuitWardrobeSimple.Patches
{
	[HarmonyPatch(typeof(StartOfRound), "PositionSuitsOnRack")]
	internal static class PositionSuitsOnRackPatch
	{
		[HarmonyPostfix]
		private static void Postfix()
		{
			RackFit.Refresh();
		}
	}
	[HarmonyPatch]
	internal static class TooManySuitsPatches
	{
		private const string PageMethod = "TooManySuits.PaginationController:DisplayCurrentPage";

		private static bool Prepare()
		{
			if (Chainloader.PluginInfos.ContainsKey("TooManySuits"))
			{
				return AccessTools.Method("TooManySuits.PaginationController:DisplayCurrentPage", (Type[])null, (Type[])null) != null;
			}
			return false;
		}

		private static MethodBase TargetMethod()
		{
			return AccessTools.Method("TooManySuits.PaginationController:DisplayCurrentPage", (Type[])null, (Type[])null);
		}

		[HarmonyPostfix]
		private static void Postfix()
		{
			RackFit.Refresh();
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal static class StartOfRoundPatches
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void RememberVanillaSuits(StartOfRound __instance)
		{
			SuitSources.RememberVanilla(__instance);
		}

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void AttachToRack(StartOfRound __instance)
		{
			RackTrigger.Attach(__instance);
			WardrobeMenu.Prepare();
		}

		[HarmonyPatch("OnDestroy")]
		[HarmonyPrefix]
		private static void CloseWardrobe()
		{
			WardrobeMenu.Dispose();
		}
	}
}