Decompiled source of VanityOutfit v1.0.7

VKTR_VanityOutfit.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;
using Valheim.SettingsGui;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace VKTR.VanityOutfit;

internal static class Headgear
{
	private const float Delay = 0.75f;

	internal static bool Sheltered;

	private static bool s_raw;

	private static float s_since;

	private static float s_next;

	internal static void Update()
	{
		Player localPlayer = Player.m_localPlayer;
		if (!Object.op_Implicit((Object)(object)localPlayer))
		{
			Sheltered = (s_raw = false);
		}
		else
		{
			if (Time.time < s_next)
			{
				return;
			}
			s_next = Time.time + 0.25f;
			bool flag = localPlayer.InShelter();
			if (flag != s_raw)
			{
				s_raw = flag;
				s_since = Time.time;
			}
			if (flag != Sheltered && !(Time.time - s_since < 0.75f))
			{
				Sheltered = flag;
				if (Vanity.ContextualHelm)
				{
					Vanity.Refresh();
				}
			}
		}
	}
}
internal static class Home
{
	internal const string HomeId = "home";

	private const string Stash = "stash";

	private static float s_since;

	private static bool s_lastState;

	private static float s_nextCheck;

	private static bool s_skipVisit;

	private static bool s_hasArea;

	private static Vector3 s_center;

	private static bool s_locResolved;

	private static Func<bool> s_locInHome;

	private static readonly List<Piece> s_pieces = new List<Piece>();

	private static bool HasLocationIntro()
	{
		if (!s_locResolved)
		{
			s_locResolved = true;
			try
			{
				if (Chainloader.PluginInfos.ContainsKey("vktr.locationintro"))
				{
					Type type = AccessTools.TypeByName("VKTR.LocationIntro.State");
					MethodInfo methodInfo = ((type != null) ? AccessTools.PropertyGetter(type, "InHome") : null);
					if (methodInfo != null)
					{
						s_locInHome = AccessTools.MethodDelegate<Func<bool>>(methodInfo, (object)null, true);
					}
				}
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[VKTR_VanityOutfit] LocationIntro: " + ex));
			}
		}
		return s_locInHome != null;
	}

	private static bool LocationIntroInHome()
	{
		try
		{
			return s_locInHome();
		}
		catch
		{
			s_locInHome = null;
			return false;
		}
	}

	private static bool OwnBedNear(Player p)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		long playerID = p.GetPlayerID();
		s_pieces.Clear();
		Piece.GetAllPiecesInRadius(((Component)p).transform.position, Plugin.HomeRadius.Value, s_pieces);
		foreach (Piece s_piece in s_pieces)
		{
			Bed val = (Object.op_Implicit((Object)(object)s_piece) ? ((Component)s_piece).GetComponent<Bed>() : null);
			if (Object.op_Implicit((Object)(object)val) && R.BedOwner(val) == playerID)
			{
				return true;
			}
		}
		return false;
	}

	private static Vector3 AreaCenter(Player p)
	{
		//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_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Invalid comparison between Unknown and I4
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: 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_0098: Unknown result type (might be due to invalid IL or missing references)
		Vector3 position = ((Component)p).transform.position;
		Vector3 result = position;
		float num = Plugin.HomeRadius.Value;
		Minimap instance = Minimap.instance;
		List<PinData> list = (Object.op_Implicit((Object)(object)instance) ? R.Pins.Invoke(instance) : null);
		if (list != null)
		{
			foreach (PinData item in list)
			{
				if (item != null && (int)item.m_type == 1)
				{
					float num2 = Utils.DistanceXZ(item.m_pos, position);
					if (num2 <= num)
					{
						num = num2;
						result = new Vector3(item.m_pos.x, position.y, item.m_pos.z);
					}
				}
			}
		}
		return result;
	}

	private static bool IsResting(Player p)
	{
		SEMan sEMan = ((Character)p).GetSEMan();
		if (sEMan != null)
		{
			return sEMan.HaveStatusEffect(SEMan.s_statusEffectResting);
		}
		return false;
	}

	private static bool Inside(Player p)
	{
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		if (HasLocationIntro())
		{
			if (!LocationIntroInHome())
			{
				return false;
			}
			if (!s_lastState)
			{
				return OwnBedNear(p);
			}
			return true;
		}
		if (!s_hasArea)
		{
			if ((!IsResting(p) && !Vanity.HomeMode) || !OwnBedNear(p))
			{
				return false;
			}
			s_center = AreaCenter(p);
			s_hasArea = true;
		}
		return Vector3.Distance(((Component)p).transform.position, s_center) <= Plugin.HomeRadius.Value;
	}

	internal static void Update()
	{
		Player localPlayer = Player.m_localPlayer;
		if (!Object.op_Implicit((Object)(object)localPlayer) || ((Character)localPlayer).IsDead() || !Plugin.HomeOutfit.Value || Outfit.Active || Time.time < s_nextCheck)
		{
			return;
		}
		s_nextCheck = Time.time + 0.25f;
		bool flag = Inside(localPlayer);
		if (flag != s_lastState)
		{
			s_lastState = flag;
			s_since = Time.time;
		}
		if (Time.time - s_since < Plugin.HomeDelay.Value)
		{
			return;
		}
		if (!flag)
		{
			s_skipVisit = false;
			s_hasArea = false;
		}
		if (flag && !Vanity.HomeMode)
		{
			if (!s_skipVisit && Vanity.PresetExists("home") && !Vanity.MatchesPreset("home"))
			{
				Vanity.DeletePreset("stash");
				Vanity.CopyCurrentTo("stash", withOff: true);
				Vanity.LoadPreset("home");
				Vanity.HomeMode = true;
			}
		}
		else if (!flag && Vanity.HomeMode)
		{
			if (Vanity.PresetExists("stash"))
			{
				Vanity.LoadPreset("stash");
			}
			Vanity.DeletePreset("stash");
			Vanity.HomeMode = false;
		}
	}

	internal static void CancelAuto()
	{
		if (s_lastState)
		{
			s_skipVisit = true;
		}
		if (Vanity.HomeMode)
		{
			Vanity.DeletePreset("stash");
			Vanity.HomeMode = false;
		}
	}
}
internal static class Hotkey
{
	internal static void Update()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		KeyboardShortcut value = Plugin.CycleKey.Value;
		if (((KeyboardShortcut)(ref value)).IsDown())
		{
			Player localPlayer = Player.m_localPlayer;
			if (Object.op_Implicit((Object)(object)localPlayer) && !((Character)localPlayer).IsDead() && !Outfit.Active && (!Object.op_Implicit((Object)(object)Chat.instance) || !Chat.instance.HasFocus()) && !Console.IsVisible() && !TextInput.IsVisible() && !Menu.IsVisible())
			{
				Cycle();
			}
		}
	}

	private static void Cycle()
	{
		List<int> list = new List<int>();
		for (int i = 0; i < 4; i++)
		{
			if (Vanity.PresetExists(i))
			{
				list.Add(i);
			}
		}
		int num = 0;
		if (!Vanity.Off)
		{
			num = list.FindIndex((int n) => Vanity.MatchesPreset(n)) + 1;
		}
		Home.CancelAuto();
		string text;
		if (num < list.Count)
		{
			int num2 = list[num];
			Vanity.LoadPreset(num2);
			text = Vanity.PresetName(num2);
			if (string.IsNullOrEmpty(text))
			{
				text = Loc.Get("preset", (num2 + 1).ToString());
			}
		}
		else if (!Vanity.Off)
		{
			Vanity.Off = true;
			text = Loc.Get("real_gear");
		}
		else
		{
			Vanity.Off = false;
			text = Loc.Get("title");
		}
		if (Object.op_Implicit((Object)(object)MessageHud.instance))
		{
			MessageHud.instance.ShowMessage((MessageType)2, text, 0, (Sprite)null, false, true);
		}
	}
}
internal static class Lights
{
	private static readonly Dictionary<int, bool> s_cache = new Dictionary<int, bool>();

	private static bool s_logged;

	private static bool s_scanned;

	private static readonly HashSet<ItemType> s_holsterable = new HashSet<ItemType>
	{
		(ItemType)3,
		(ItemType)4,
		(ItemType)5,
		(ItemType)14,
		(ItemType)22,
		(ItemType)15,
		(ItemType)19,
		(ItemType)20
	};

	internal static bool Has(string prefab)
	{
		if (!string.IsNullOrEmpty(prefab))
		{
			return Has(StringExtensionMethods.GetStableHashCode(prefab));
		}
		return false;
	}

	internal static void LogAll()
	{
		if (s_logged || !Object.op_Implicit((Object)(object)ObjectDB.instance))
		{
			return;
		}
		s_logged = true;
		List<string> list = new List<string>();
		foreach (GameObject item in ObjectDB.instance.m_items)
		{
			ItemDrop val = (Object.op_Implicit((Object)(object)item) ? item.GetComponent<ItemDrop>() : null);
			if (Object.op_Implicit((Object)(object)val) && Vanity.SlotFor(val.m_itemData) >= 0 && Has(((Object)item).name))
			{
				list.Add(((Object)item).name);
			}
		}
		Debug.Log((object)("[VKTR_VanityOutfit] Light-emitting pieces excluded from outfits: " + ((list.Count > 0) ? string.Join(", ", list) : "none")));
	}

	internal static bool Has(int hash)
	{
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Expected O, but got Unknown
		if (hash == 0)
		{
			return false;
		}
		if (s_cache.TryGetValue(hash, out var value))
		{
			return value;
		}
		ObjectDB instance = ObjectDB.instance;
		GameObject val = (Object.op_Implicit((Object)(object)instance) ? instance.GetItemPrefab(hash) : null);
		if (!Object.op_Implicit((Object)(object)val))
		{
			return false;
		}
		value = false;
		foreach (Transform item in val.transform)
		{
			Transform val2 = item;
			if (((Object)val2).name.StartsWith("attach") && ((Component)val2).GetComponentsInChildren<Light>(true).Length != 0)
			{
				value = true;
				break;
			}
		}
		s_cache[hash] = value;
		return value;
	}

	internal static IEnumerator ScanBack()
	{
		if (s_scanned || !Object.op_Implicit((Object)(object)ObjectDB.instance))
		{
			yield break;
		}
		s_scanned = true;
		GameObject root = new GameObject("VKTR_VanityLightScan");
		root.transform.position = new Vector3(0f, -5000f, 0f);
		try
		{
			List<KeyValuePair<GameObject, GameObject>> items = new List<KeyValuePair<GameObject, GameObject>>();
			foreach (GameObject item in ObjectDB.instance.m_items)
			{
				ItemDrop val = (Object.op_Implicit((Object)(object)item) ? item.GetComponent<ItemDrop>() : null);
				if (!Object.op_Implicit((Object)(object)val) || !s_holsterable.Contains(val.m_itemData.m_shared.m_itemType))
				{
					continue;
				}
				Transform val2 = null;
				foreach (Transform item2 in item.transform)
				{
					Transform val3 = item2;
					if (((Object)val3).name == "attach_back" || ((Object)val3).name == "attach")
					{
						val2 = val3;
						break;
					}
				}
				if (!Object.op_Implicit((Object)(object)val2))
				{
					continue;
				}
				try
				{
					GameObject val4 = Object.Instantiate<GameObject>(((Component)val2).gameObject, root.transform, false);
					val4.SetActive(true);
					Collider[] componentsInChildren = val4.GetComponentsInChildren<Collider>(true);
					for (int i = 0; i < componentsInChildren.Length; i++)
					{
						componentsInChildren[i].enabled = false;
					}
					items.Add(new KeyValuePair<GameObject, GameObject>(item, val4));
				}
				catch (Exception ex)
				{
					Debug.LogWarning((object)("[VKTR_VanityOutfit] Light scan " + ((Object)item).name + ": " + ex.Message));
				}
			}
			yield return (object)new WaitForSeconds(1f);
			List<string> list = new List<string>();
			StringBuilder stringBuilder = new StringBuilder();
			foreach (KeyValuePair<GameObject, GameObject> item3 in items)
			{
				if (!Object.op_Implicit((Object)(object)item3.Value))
				{
					continue;
				}
				Light[] componentsInChildren2 = item3.Value.GetComponentsInChildren<Light>(true);
				if (componentsInChildren2.Length == 0)
				{
					continue;
				}
				bool flag = false;
				stringBuilder.Append("  ").Append(((Object)item3.Key).name).Append(" (")
					.Append(item3.Key.GetComponent<ItemDrop>().m_itemData.m_shared.m_itemType)
					.Append(")\n");
				Light[] array = componentsInChildren2;
				foreach (Light val5 in array)
				{
					LightLod component = ((Component)val5).GetComponent<LightLod>();
					bool num = Object.op_Implicit((Object)(object)component) && component.m_lightLod;
					float num2 = (num ? Field(component, "m_baseRange", val5.range) : val5.range);
					bool flag2 = (num ? ((Behaviour)component).enabled : ((Behaviour)val5).enabled);
					LightFlicker component2 = ((Component)val5).GetComponent<LightFlicker>();
					float num3 = (Object.op_Implicit((Object)(object)component2) ? Mathf.Max(val5.intensity, Field(component2, "m_baseIntensity", val5.intensity)) : val5.intensity);
					int num4;
					if (((Component)val5).gameObject.activeInHierarchy && flag2 && num3 > 0.001f)
					{
						Color color = val5.color;
						if (((Color)(ref color)).maxColorComponent > 0.001f)
						{
							num4 = (((int)val5.type == 1 || num2 > 0.001f) ? 1 : 0);
							goto IL_03bb;
						}
					}
					num4 = 0;
					goto IL_03bb;
					IL_03bb:
					bool flag3 = (byte)num4 != 0;
					flag = flag || flag3;
					stringBuilder.Append("    ").Append(flag3 ? "ON  " : "off ").Append(Path(((Component)val5).transform, item3.Value.transform))
						.Append(" active=")
						.Append(((Component)val5).gameObject.activeInHierarchy)
						.Append(" enabled=")
						.Append(flag2)
						.Append(" type=")
						.Append(val5.type)
						.Append(" intensity=")
						.Append(num3.ToString("0.###"))
						.Append(" range=")
						.Append(num2.ToString("0.##"))
						.Append(" color=#")
						.Append(ColorUtility.ToHtmlStringRGB(val5.color));
					if (num)
					{
						stringBuilder.Append(" lod: baseRange=").Append(num2.ToString("0.##")).Append(" distance=")
							.Append(component.m_lightDistance.ToString("0.#"));
					}
					stringBuilder.Append(" comps=");
					Component[] components = ((Component)val5).GetComponents<Component>();
					foreach (Component val6 in components)
					{
						if (Object.op_Implicit((Object)(object)val6) && !(val6 is Transform) && !(val6 is Light))
						{
							stringBuilder.Append(((object)val6).GetType().Name).Append(' ');
						}
					}
					stringBuilder.Append('\n');
				}
				if (flag)
				{
					list.Add(((Object)item3.Key).name);
				}
			}
			Debug.Log((object)("[VKTR_VanityOutfit] Holstered light scan: " + items.Count + " holsterable items, lit on the back: " + ((list.Count > 0) ? string.Join(", ", list) : "none") + "\n" + stringBuilder));
		}
		finally
		{
			Object.Destroy((Object)(object)root);
		}
	}

	private static T Field<T>(object o, string name, T fallback)
	{
		try
		{
			FieldInfo fieldInfo = AccessTools.Field(o.GetType(), name);
			return (fieldInfo != null) ? ((T)fieldInfo.GetValue(o)) : fallback;
		}
		catch
		{
			return fallback;
		}
	}

	private static string Path(Transform t, Transform root)
	{
		string text = ((Object)t).name;
		while ((Object)(object)t != (Object)(object)root && Object.op_Implicit((Object)(object)t.parent))
		{
			t = t.parent;
			text = ((Object)t).name + "/" + text;
		}
		return text;
	}
}
internal static class Loc
{
	internal static readonly string[] Keys = new string[20]
	{
		"title", "hover", "hide", "slot_helmet", "slot_chest", "slot_legs", "slot_cape", "save", "select", "delete",
		"confirm", "hidden", "preset", "empty", "name_topic", "hide_belt", "home", "real_gear", "has_light", "ctx_helm"
	};

	private static readonly Dictionary<string, string[]> T = new Dictionary<string, string[]>
	{
		["English"] = new string[20]
		{
			"Outfit", "Hold: Outfit", "Hide", "Helmet", "Chest", "Legs", "Cape", "Save", "Wear", "Delete",
			"Sure?", "Hidden", "Preset {0}", "Empty", "Outfit name", "Hide {0}", "Home", "Real equipment", "Emits light: not usable in outfits", "Contextual headgear"
		},
		["Swedish"] = new string[20]
		{
			"Utstyrsel", "Håll: Utstyrsel", "Dölj", "Hjälm", "Bröst", "Ben", "Mantel", "Spara", "Ta på", "Radera",
			"Säker?", "Dold", "Förval {0}", "Tom", "Namn på utstyrsel", "Dölj {0}", "Hemma", "Verklig utrustning", "Avger ljus: kan inte användas i utstyrslar", "Situationsanpassad hjälm"
		},
		["French"] = new string[20]
		{
			"Tenue", "Maintenir : Tenue", "Masquer", "Casque", "Torse", "Jambes", "Cape", "Enregistrer", "Porter", "Supprimer",
			"Sûr ?", "Masqué", "Préréglage {0}", "Vide", "Nom de la tenue", "Masquer {0}", "Maison", "Équipement réel", "Émet de la lumière : inutilisable dans une tenue", "Casque contextuel"
		},
		["Italian"] = new string[20]
		{
			"Outfit", "Tieni premuto: Outfit", "Nascondi", "Elmo", "Petto", "Gambe", "Mantello", "Salva", "Indossa", "Elimina",
			"Sicuro?", "Nascosto", "Preset {0}", "Vuoto", "Nome outfit", "Nascondi {0}", "Casa", "Equipaggiamento reale", "Emette luce: non usabile negli outfit", "Elmo contestuale"
		},
		["German"] = new string[20]
		{
			"Outfit", "Halten: Outfit", "Verbergen", "Helm", "Brust", "Beine", "Umhang", "Speichern", "Anziehen", "Löschen",
			"Sicher?", "Verborgen", "Vorlage {0}", "Leer", "Name des Outfits", "{0} verbergen", "Zuhause", "Echte Ausrüstung", "Leuchtet: nicht für Outfits nutzbar", "Kontextabhängiger Helm"
		},
		["Spanish"] = new string[20]
		{
			"Atuendo", "Mantener: Atuendo", "Ocultar", "Casco", "Pecho", "Piernas", "Capa", "Guardar", "Vestir", "Borrar",
			"¿Seguro?", "Oculto", "Preajuste {0}", "Vacío", "Nombre del atuendo", "Ocultar {0}", "Casa", "Equipo real", "Emite luz: no se puede usar en atuendos", "Casco contextual"
		},
		["Russian"] = new string[20]
		{
			"Облик", "Удерживать: Облик", "Скрыть", "Шлем", "Грудь", "Ноги", "Плащ", "Сохранить", "Надеть", "Удалить",
			"Точно?", "Скрыто", "Набор {0}", "Пусто", "Название облика", "Скрыть {0}", "Дом", "Настоящая экипировка", "Излучает свет: нельзя использовать в облике", "Шлем по ситуации"
		},
		["Romanian"] = new string[20]
		{
			"Ținută", "Ține apăsat: Ținută", "Ascunde", "Coif", "Piept", "Picioare", "Mantie", "Salvează", "Îmbracă", "Șterge",
			"Sigur?", "Ascuns", "Set {0}", "Gol", "Numele ținutei", "Ascunde {0}", "Acasă", "Echipament real", "Emite lumină: nu poate fi folosit în ținute", "Coif contextual"
		},
		["Bulgarian"] = new string[20]
		{
			"Облекло", "Задръж: Облекло", "Скрий", "Шлем", "Гърди", "Крака", "Наметало", "Запази", "Облечи", "Изтрий",
			"Сигурен?", "Скрито", "Комплект {0}", "Празно", "Име на облеклото", "Скрий {0}", "Вкъщи", "Истинска екипировка", "Излъчва светлина: не може да се ползва в облекла", "Шлем според мястото"
		},
		["Macedonian"] = new string[20]
		{
			"Облека", "Задржи: Облека", "Скриј", "Шлем", "Гради", "Нозе", "Наметка", "Зачувај", "Облечи", "Избриши",
			"Сигурно?", "Скриено", "Комплет {0}", "Празно", "Име на облеката", "Скриј {0}", "Дома", "Вистинска опрема", "Емитува светлина: не може да се користи во облека", "Шлем според местото"
		},
		["Finnish"] = new string[20]
		{
			"Asu", "Pidä pohjassa: Asu", "Piilota", "Kypärä", "Rinta", "Jalat", "Viitta", "Tallenna", "Pue päälle", "Poista",
			"Varma?", "Piilotettu", "Asu {0}", "Tyhjä", "Asun nimi", "Piilota {0}", "Koti", "Todellinen varustus", "Hohtaa valoa: ei käytettävissä asuissa", "Tilannekohtainen kypärä"
		},
		["Danish"] = new string[20]
		{
			"Påklædning", "Hold: Påklædning", "Skjul", "Hjelm", "Bryst", "Ben", "Kappe", "Gem", "Tag på", "Slet",
			"Sikker?", "Skjult", "Sæt {0}", "Tom", "Navn på påklædning", "Skjul {0}", "Hjemme", "Rigtigt udstyr", "Udsender lys: kan ikke bruges i outfits", "Situationsbestemt hjelm"
		},
		["Norwegian"] = new string[20]
		{
			"Antrekk", "Hold: Antrekk", "Skjul", "Hjelm", "Bryst", "Bein", "Kappe", "Lagre", "Ta på", "Slett",
			"Sikker?", "Skjult", "Sett {0}", "Tom", "Navn på antrekk", "Skjul {0}", "Hjemme", "Ekte utstyr", "Gir lys: kan ikke brukes i antrekk", "Situasjonsbestemt hjelm"
		},
		["Icelandic"] = new string[20]
		{
			"Klæðnaður", "Haltu inni: Klæðnaður", "Fela", "Hjálmur", "Bringa", "Fætur", "Skikkja", "Vista", "Klæðast", "Eyða",
			"Viss?", "Falið", "Sett {0}", "Tómt", "Heiti klæðnaðar", "Fela {0}", "Heima", "Raunverulegur búnaður", "Gefur frá sér ljós: ekki hægt að nota í klæðnaði", "Hjálmur eftir aðstæðum"
		},
		["Turkish"] = new string[20]
		{
			"Kıyafet", "Basılı tut: Kıyafet", "Gizle", "Miğfer", "Göğüs", "Bacak", "Pelerin", "Kaydet", "Giy", "Sil",
			"Emin misin?", "Gizli", "Set {0}", "Boş", "Kıyafet adı", "{0} öğesini gizle", "Ev", "Gerçek teçhizat", "Işık yayar: kıyafetlerde kullanılamaz", "Duruma göre miğfer"
		},
		["Lithuanian"] = new string[20]
		{
			"Apranga", "Laikyti: Apranga", "Slėpti", "Šalmas", "Krūtinė", "Kojos", "Apsiaustas", "Išsaugoti", "Apsivilkti", "Ištrinti",
			"Tikrai?", "Paslėpta", "Rinkinys {0}", "Tuščia", "Aprangos pavadinimas", "Slėpti {0}", "Namai", "Tikra ekipuotė", "Skleidžia šviesą: negalima naudoti aprangoje", "Situacinis šalmas"
		},
		["Czech"] = new string[20]
		{
			"Oblečení", "Podržet: Oblečení", "Skrýt", "Helma", "Hruď", "Nohy", "Plášť", "Uložit", "Obléct", "Smazat",
			"Jistě?", "Skryto", "Sada {0}", "Prázdné", "Název oblečení", "Skrýt {0}", "Doma", "Skutečná výstroj", "Vyzařuje světlo: nelze použít v oblečení", "Helma podle situace"
		},
		["Hungarian"] = new string[20]
		{
			"Öltözet", "Tartsd lenyomva: Öltözet", "Elrejt", "Sisak", "Mellvért", "Lábvért", "Köpeny", "Mentés", "Felvétel", "Törlés",
			"Biztos?", "Rejtett", "Szett {0}", "Üres", "Öltözet neve", "{0} elrejtése", "Otthon", "Valódi felszerelés", "Fényt bocsát ki: öltözékben nem használható", "Helyzetfüggő sisak"
		},
		["Slovak"] = new string[20]
		{
			"Oblečenie", "Podržať: Oblečenie", "Skryť", "Prilba", "Hruď", "Nohy", "Plášť", "Uložiť", "Obliecť", "Zmazať",
			"Isto?", "Skryté", "Sada {0}", "Prázdne", "Názov oblečenia", "Skryť {0}", "Doma", "Skutočná výstroj", "Vyžaruje svetlo: nedá sa použiť v oblečení", "Prilba podľa situácie"
		},
		["Polish"] = new string[20]
		{
			"Strój", "Przytrzymaj: Strój", "Ukryj", "Hełm", "Tors", "Nogi", "Peleryna", "Zapisz", "Załóż", "Usuń",
			"Na pewno?", "Ukryte", "Zestaw {0}", "Pusty", "Nazwa stroju", "Ukryj {0}", "Dom", "Prawdziwy ekwipunek", "Emituje światło: nie można użyć w stroju", "Hełm zależny od miejsca"
		},
		["Dutch"] = new string[20]
		{
			"Outfit", "Ingedrukt houden: Outfit", "Verbergen", "Helm", "Borst", "Benen", "Cape", "Opslaan", "Aantrekken", "Wissen",
			"Zeker?", "Verborgen", "Set {0}", "Leeg", "Naam van outfit", "{0} verbergen", "Thuis", "Echte uitrusting", "Geeft licht: niet bruikbaar in outfits", "Contextuele helm"
		},
		["Portuguese_European"] = new string[20]
		{
			"Traje", "Manter premido: Traje", "Ocultar", "Elmo", "Peito", "Pernas", "Capa", "Guardar", "Vestir", "Apagar",
			"Certeza?", "Oculto", "Conjunto {0}", "Vazio", "Nome do traje", "Ocultar {0}", "Casa", "Equipamento real", "Emite luz: não pode ser usado em trajes", "Elmo contextual"
		},
		["Portuguese_Brazilian"] = new string[20]
		{
			"Visual", "Segurar: Visual", "Ocultar", "Capacete", "Peito", "Pernas", "Capa", "Salvar", "Vestir", "Excluir",
			"Certeza?", "Oculto", "Conjunto {0}", "Vazio", "Nome do visual", "Ocultar {0}", "Casa", "Equipamento real", "Emite luz: não pode ser usado em trajes", "Capacete contextual"
		},
		["Chinese"] = new string[20]
		{
			"外观", "长按:外观", "隐藏", "头盔", "胸甲", "腿甲", "披风", "保存", "穿戴", "删除",
			"确定?", "已隐藏", "预设 {0}", "空", "外观名称", "隐藏{0}", "居家", "真实装备", "会发光:无法用于外观", "情境头盔"
		},
		["Chinese_Trad"] = new string[20]
		{
			"外觀", "長按:外觀", "隱藏", "頭盔", "胸甲", "腿甲", "披風", "儲存", "穿戴", "刪除",
			"確定?", "已隱藏", "預設 {0}", "空", "外觀名稱", "隱藏{0}", "居家", "真實裝備", "會發光:無法用於外觀", "情境頭盔"
		},
		["Japanese"] = new string[20]
		{
			"衣装", "長押し:衣装", "非表示", "頭", "胴", "脚", "マント", "保存", "着用", "削除",
			"本当に?", "非表示", "プリセット{0}", "空き", "衣装名", "{0}を非表示", "自宅", "実際の装備", "光を放つ:コーデには使えません", "状況に応じた頭装備"
		},
		["Korean"] = new string[20]
		{
			"외형", "길게 누르기: 외형", "숨기기", "투구", "상의", "하의", "망토", "저장", "착용", "삭제",
			"확실한가요?", "숨김", "프리셋 {0}", "비어 있음", "외형 이름", "{0} 숨기기", "집", "실제 장비", "빛을 냄: 외형에 사용할 수 없음", "상황별 투구"
		},
		["Hindi"] = new string[20]
		{
			"प\u094bश\u093eक", "दब\u093eए रख\u0947\u0902: प\u094bश\u093eक", "छ\u093fप\u093eए\u0901", "ह\u0947लम\u0947ट", "छ\u093eत\u0940", "प\u0948र", "लब\u093eद\u093e", "सह\u0947ज\u0947\u0902", "पहन\u0947\u0902", "हट\u093eए\u0901",
			"पक\u094dक\u093e?", "छ\u093fप\u093e ह\u0941आ", "प\u094dर\u0940स\u0947ट {0}", "ख\u093eल\u0940", "प\u094bश\u093eक क\u093e न\u093eम", "{0} छ\u093fप\u093eए\u0901", "घर", "असल\u0940 उपकरण", "र\u094bशन\u0940 द\u0947त\u093e ह\u0948: प\u094bश\u093eक म\u0947\u0902 उपय\u094bग नह\u0940\u0902 ह\u094b सकत\u093e", "पर\u093fस\u094dथ\u093fत\u093f अन\u0941स\u093eर ह\u0947लम\u0947ट"
		},
		["Thai"] = new string[20]
		{
			"ช\u0e38ดแต\u0e48งกาย", "กดค\u0e49าง: ช\u0e38ดแต\u0e48งกาย", "ซ\u0e48อน", "หมวก", "เส\u0e37\u0e49อ", "กางเกง", "ผ\u0e49าคล\u0e38ม", "บ\u0e31นท\u0e36ก", "สวมใส\u0e48", "ลบ",
			"แน\u0e48ใจ?", "ซ\u0e48อนอย\u0e39\u0e48", "ช\u0e38ดท\u0e35\u0e48 {0}", "ว\u0e48าง", "ช\u0e37\u0e48อช\u0e38ด", "ซ\u0e48อน{0}", "บ\u0e49าน", "อ\u0e38ปกรณ\u0e4cจร\u0e34ง", "เปล\u0e48งแสง: ใช\u0e49เป\u0e47นช\u0e38ดแต\u0e48งไม\u0e48ได\u0e49", "หมวกตามสถานการณ\u0e4c"
		},
		["Croatian"] = new string[20]
		{
			"Odjeća", "Drži: Odjeća", "Sakrij", "Kaciga", "Prsa", "Noge", "Plašt", "Spremi", "Odjeni", "Obriši",
			"Sigurno?", "Skriveno", "Komplet {0}", "Prazno", "Naziv odjeće", "Sakrij {0}", "Dom", "Prava oprema", "Svijetli: ne može se koristiti u odjeći", "Kaciga prema situaciji"
		},
		["Georgian"] = new string[20]
		{
			"სამოსი", "ხანგრძლივად: სამოსი", "დამალვა", "ჩაფხუტი", "მკერდი", "ფეხები", "მოსასხამი", "შენახვა", "ჩაცმა", "წაშლა",
			"დარწმუნებული ხარ?", "დამალული", "ნაკრები {0}", "ცარიელი", "სამოსის სახელი", "{0}-ის დამალვა", "სახლი", "ნამდვილი აღჭურვილობა", "ასხივებს სინათლეს: სამოსში ვერ გამოიყენება", "სიტუაციური ჩაფხუტი"
		},
		["Greek"] = new string[20]
		{
			"Ενδυμασία", "Κράτα πατημένο: Ενδυμασία", "Απόκρυψη", "Κράνος", "Στήθος", "Πόδια", "Κάπα", "Αποθήκευση", "Φόρεσε", "Διαγραφή",
			"Σίγουρα;", "Κρυφό", "Σετ {0}", "Κενό", "Όνομα ενδυμασίας", "Απόκρυψη {0}", "Σπίτι", "Πραγματικός εξοπλισμός", "Εκπέμπει φως: δεν χρησιμοποιείται σε εμφάνιση", "Κράνος ανάλογα με την περίσταση"
		},
		["Serbian"] = new string[20]
		{
			"Одећа", "Држи: Одећа", "Сакриј", "Кацига", "Груди", "Ноге", "Плашт", "Сачувај", "Обуци", "Обриши",
			"Сигурно?", "Скривено", "Комплет {0}", "Празно", "Назив одеће", "Сакриј {0}", "Дом", "Права опрема", "Светли: не може се користити у одећи", "Кацига према ситуацији"
		},
		["Ukrainian"] = new string[20]
		{
			"Вбрання", "Утримуй: Вбрання", "Сховати", "Шолом", "Груди", "Ноги", "Плащ", "Зберегти", "Вдягнути", "Видалити",
			"Точно?", "Приховано", "Набір {0}", "Порожньо", "Назва вбрання", "Сховати {0}", "Дім", "Справжнє спорядження", "Випромінює світло: не можна використати в образі", "Шолом за ситуацією"
		},
		["Latvian"] = new string[20]
		{
			"Tērps", "Turēt: Tērps", "Paslēpt", "Ķivere", "Krūtis", "Kājas", "Apmetnis", "Saglabāt", "Uzvilkt", "Dzēst",
			"Droši?", "Paslēpts", "Komplekts {0}", "Tukšs", "Tērpa nosaukums", "Paslēpt {0}", "Mājas", "Īstais ekipējums", "Izstaro gaismu: nav izmantojams tērpos", "Situatīvā ķivere"
		}
	};

	private static string s_loaded;

	private static readonly Action<Localization, string, string> AddWord = AccessTools.MethodDelegate<Action<Localization, string, string>>(AccessTools.Method(typeof(Localization), "AddWord", (Type[])null, (Type[])null), (object)null, true);

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

	internal static void Load(Localization loc, string language)
	{
		if (loc != null)
		{
			if (language == null || !T.TryGetValue(language, out var value))
			{
				value = T["English"];
			}
			for (int i = 0; i < Keys.Length; i++)
			{
				AddWord(loc, "vktr_vanity_" + Keys[i], value[i]);
				s_words[Keys[i]] = value[i];
			}
			s_loaded = language;
		}
	}

	internal static string Get(string key)
	{
		Localization instance = Localization.instance;
		if (instance == null)
		{
			return key;
		}
		string selectedLanguage = instance.GetSelectedLanguage();
		if (s_loaded != selectedLanguage)
		{
			Load(instance, selectedLanguage);
		}
		if (!s_words.TryGetValue(key, out var value))
		{
			return key;
		}
		return value;
	}

	internal static string Get(string key, string arg)
	{
		return string.Format(Get(key), arg);
	}

	internal static string Slot(int i)
	{
		if (i >= 4)
		{
			return Game("$item_trinket");
		}
		return Get(Keys[3 + i]);
	}

	internal static string Game(string text)
	{
		if (Localization.instance == null)
		{
			return text;
		}
		return Localization.instance.Localize(text);
	}
}
[HarmonyPatch(typeof(Localization), "SetupLanguage")]
internal static class SetupLanguage_Patch
{
	private static void Postfix(Localization __instance, string language)
	{
		Loc.Load(__instance, language);
	}
}
internal static class BarberHold
{
	private static Barber s_pending;

	private static float s_start;

	internal static bool Bypass;

	private static bool UseHeld()
	{
		if (!ZInput.GetButton("Use"))
		{
			return ZInput.GetButton("JoyUse");
		}
		return true;
	}

	internal static bool OnInteract(Barber barber, Humanoid human, bool hold, bool alt)
	{
		if (Bypass || alt || (Object)(object)human != (Object)(object)Player.m_localPlayer)
		{
			return false;
		}
		if (!hold)
		{
			s_pending = barber;
			s_start = Time.time;
			return true;
		}
		if ((Object)(object)s_pending == (Object)(object)barber && Time.time - s_start >= Plugin.HoldTime.Value)
		{
			s_pending = null;
			Outfit.Open(barber);
		}
		return true;
	}

	internal static void Update()
	{
		if (!Object.op_Implicit((Object)(object)s_pending) || UseHeld())
		{
			return;
		}
		Barber val = s_pending;
		s_pending = null;
		if (Time.time - s_start >= Plugin.HoldTime.Value || !Object.op_Implicit((Object)(object)Player.m_localPlayer))
		{
			return;
		}
		Bypass = true;
		try
		{
			val.Interact((Humanoid)(object)Player.m_localPlayer, false, false);
		}
		finally
		{
			Bypass = false;
		}
	}
}
[HarmonyPatch(typeof(Barber), "Interact")]
internal static class BarberInteract_Patch
{
	private static bool Prefix(Barber __instance, Humanoid __0, bool __1, bool __2, ref bool __result)
	{
		if (!BarberHold.OnInteract(__instance, __0, __1, __2))
		{
			return true;
		}
		__result = false;
		return false;
	}
}
[HarmonyPatch(typeof(Barber), "GetHoverText")]
internal static class BarberHover_Patch
{
	private static void Postfix(Barber __instance, ref string __result)
	{
		//IL_001e: 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)
		Player localPlayer = Player.m_localPlayer;
		if (Object.op_Implicit((Object)(object)localPlayer) && !string.IsNullOrEmpty(__result) && !(Vector3.Distance(((Component)localPlayer).transform.position, ((Component)__instance).transform.position) > __instance.m_useDistance + 1f))
		{
			__result = __result + Loc.Game("\n[<color=yellow><b>$KEY_Use</b></color>] ") + Loc.Get("hover");
		}
	}
}
internal static class Outfit
{
	internal static bool Active;

	private static Barber s_barber;

	private static Inventory s_inv;

	private static GameObject s_root;

	private static GameObject s_row;

	private static Toggle[] s_btns;

	private static TMP_Text[] s_txt;

	private static UIGroupHandler s_group;

	private static Action<Vector2i> s_prevLower;

	private static bool s_prevJump;

	internal static Vector3 CamDir;

	private static Quaternion s_savedYaw;

	private static bool s_dumped;

	private static float s_openTime;

	private static readonly Dictionary<Graphic, Color> s_orig = new Dictionary<Graphic, Color>();

	private static readonly Dictionary<Graphic, Material> s_origMat = new Dictionary<Graphic, Material>();

	private static readonly Dictionary<Selectable, ColorBlock> s_origColors = new Dictionary<Selectable, ColorBlock>();

	private static CanvasGroup s_craftingGroup;

	private static bool s_craftingHadGroup;

	private static readonly Dictionary<Image, Image> s_mirror = new Dictionary<Image, Image>();

	private static bool s_sized;

	private static Vector2 s_origSize;

	private const float GridTopPad = 8f;

	private static readonly HashSet<InventoryElement> s_shifted = new HashSet<InventoryElement>();

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

	private static RectTransform s_beltPanel;

	private static Toggle s_belt;

	private static TMP_Text s_beltLabel;

	internal static bool Dirty;

	private const float TogglePanelW = 240f;

	private static RectTransform s_ctxPanel;

	private static Toggle s_ctx;

	private static TMP_Text s_ctxLabel;

	internal static void Open(Barber barber)
	{
		InventoryGui instance = InventoryGui.instance;
		if (!Object.op_Implicit((Object)(object)instance) || Active)
		{
			return;
		}
		s_barber = barber;
		Active = true;
		s_openTime = Time.time;
		FacePlayerToCamera();
		Vanity.Refresh();
		Rebuild();
		instance.Show((Container)null, 1);
		try
		{
			Setup(instance);
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[VKTR_VanityOutfit] Setup UI: " + ex));
		}
	}

	internal static void Close()
	{
		//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_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_005f: Unknown result type (might be due to invalid IL or missing references)
		if (!Active)
		{
			return;
		}
		Active = false;
		s_barber = null;
		if (Dirty)
		{
			Home.CancelAuto();
		}
		Dirty = false;
		Vanity.Refresh();
		Player localPlayer = Player.m_localPlayer;
		if (Object.op_Implicit((Object)(object)localPlayer))
		{
			R.LookYaw.Invoke((Character)(object)localPlayer) = s_savedYaw;
			localPlayer.FaceLookDirection();
			((Character)localPlayer).SetLookDir(s_savedYaw * Vector3.forward, 0f);
		}
		InventoryGui instance = InventoryGui.instance;
		if (!Object.op_Implicit((Object)(object)instance))
		{
			return;
		}
		try
		{
			InventoryGrid val = R.ContainerGrid.Invoke(instance);
			val.OnMoveToLowerInventoryGrid = s_prevLower;
			R.JumpToNext.Invoke(val) = s_prevJump;
			if (Object.op_Implicit((Object)(object)s_root))
			{
				s_root.SetActive(false);
			}
			RestoreColors();
			if (Object.op_Implicit((Object)(object)s_group))
			{
				s_group.SetActive(false);
				instance.m_uiGroups = Array.FindAll(instance.m_uiGroups, (UIGroupHandler g) => (Object)(object)g != (Object)(object)s_group);
			}
			if (Object.op_Implicit((Object)(object)instance.m_takeAllButton))
			{
				((Component)instance.m_takeAllButton).gameObject.SetActive(true);
			}
			if (Object.op_Implicit((Object)(object)instance.m_stackAllButton))
			{
				((Component)instance.m_stackAllButton).gameObject.SetActive(true);
			}
			((Component)instance.m_container).gameObject.SetActive(false);
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[VKTR_VanityOutfit] Close: " + ex));
		}
	}

	internal static void Update()
	{
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: 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_0074: 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_007e: 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_008f: 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_00a7: 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_012a: Unknown result type (might be due to invalid IL or missing references)
		if (!Active)
		{
			return;
		}
		InventoryGui instance = InventoryGui.instance;
		Player localPlayer = Player.m_localPlayer;
		if (!Object.op_Implicit((Object)(object)instance) || !InventoryGui.IsVisible() || !Object.op_Implicit((Object)(object)localPlayer))
		{
			Close();
			return;
		}
		if (!Object.op_Implicit((Object)(object)s_barber) || Vector3.Distance(((Component)localPlayer).transform.position, ((Component)s_barber).transform.position) > Plugin.CloseDistance.Value)
		{
			instance.Hide();
			return;
		}
		Quaternion val = Quaternion.LookRotation(CamDir, Vector3.up);
		if (Quaternion.Angle(R.LookYaw.Invoke((Character)(object)localPlayer), val) > 0.5f)
		{
			R.LookYaw.Invoke((Character)(object)localPlayer) = val;
			localPlayer.FaceLookDirection();
		}
		((Character)localPlayer).SetLookDir(CamDir, 0f);
		if (Object.op_Implicit((Object)(object)s_group) && s_group.IsActive && Object.op_Implicit((Object)(object)SelectedButton()) && !TextInput.IsVisible() && (ZInput.GetButtonDown("JoyDPadUp") || ZInput.GetButtonDown("JoyLStickUp")))
		{
			int num = Math.Max(0, Array.IndexOf(s_btns, SelectedButton()));
			R.ContainerGrid.Invoke(instance).SetGamepadSelection(new Vector2i(num, 0));
			R.SetActiveGroup(instance, 0, arg3: true);
		}
		if (Plugin.LogMenuLayout.Value && !s_dumped && Time.time - s_openTime > 0.5f)
		{
			s_dumped = true;
			DumpLayout(instance);
		}
	}

	private static void DumpLayout(InventoryGui ig)
	{
		try
		{
			StringBuilder stringBuilder = new StringBuilder("[VKTR_VanityOutfit] Outfit menu layout\n");
			DumpNode((Transform)(object)ig.m_player, 0, 2, stringBuilder);
			DumpNode((Transform)(object)ig.m_container, 0, 4, stringBuilder);
			if (Object.op_Implicit((Object)(object)s_root))
			{
				DumpNode(s_root.transform, 0, 4, stringBuilder);
			}
			Debug.Log((object)stringBuilder.ToString());
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[VKTR_VanityOutfit] LogMenuLayout: " + ex));
		}
	}

	private static void DumpNode(Transform t, int depth, int max, StringBuilder sb)
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		sb.Append(' ', depth * 2).Append(((Object)t).name);
		if (!((Component)t).gameObject.activeSelf)
		{
			sb.Append(" (off)");
		}
		RectTransform val = (RectTransform)(object)((t is RectTransform) ? t : null);
		if (val != null)
		{
			StringBuilder stringBuilder = sb.Append(" s");
			Rect rect = val.rect;
			stringBuilder.Append(((Rect)(ref rect)).size);
		}
		CanvasGroup component = ((Component)t).GetComponent<CanvasGroup>();
		if (Object.op_Implicit((Object)(object)component))
		{
			sb.Append(" group=").Append(component.alpha);
		}
		Graphic component2 = ((Component)t).GetComponent<Graphic>();
		if (Object.op_Implicit((Object)(object)component2))
		{
			Image val2 = (Image)(object)((component2 is Image) ? component2 : null);
			sb.Append(" [").Append(((object)component2).GetType().Name).Append(((Behaviour)component2).enabled ? "" : " off")
				.Append(" sprite=")
				.Append((Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val2.sprite)) ? ((Object)val2.sprite).name : "-")
				.Append(" mat=")
				.Append(Object.op_Implicit((Object)(object)component2.material) ? ((Object)component2.material).name : "-")
				.Append(" col=")
				.Append(ColorUtility.ToHtmlStringRGBA(component2.color))
				.Append(" cr=")
				.Append(ColorUtility.ToHtmlStringRGBA(component2.canvasRenderer.GetColor()))
				.Append(']');
		}
		sb.AppendLine();
		if (depth < max)
		{
			for (int i = 0; i < t.childCount; i++)
			{
				DumpNode(t.GetChild(i), depth + 1, max, sb);
			}
		}
	}

	internal static void CycleGroups(InventoryGui ig, int dir)
	{
		if (!Object.op_Implicit((Object)(object)s_group))
		{
			return;
		}
		int num = Array.IndexOf(ig.m_uiGroups, s_group);
		if (num < 0)
		{
			return;
		}
		EventSystem current = EventSystem.current;
		int num2 = 6;
		int num3 = 0;
		if (R.ActiveGroup.Invoke(ig) == num && Object.op_Implicit((Object)(object)current) && Object.op_Implicit((Object)(object)current.currentSelectedGameObject))
		{
			int num4 = Presets.PanelOf(current.currentSelectedGameObject);
			num3 = ((num4 >= 0) ? (num4 + 1) : 0);
		}
		int num5 = (num3 + dir + num2) % num2;
		if (R.ActiveGroup.Invoke(ig) != 0 && R.ActiveGroup.Invoke(ig) != num)
		{
			num5 = ((dir <= 0) ? (num2 - 1) : 0);
		}
		if (num5 == 0)
		{
			R.SetActiveGroup(ig, 0, arg3: true);
			return;
		}
		R.SetActiveGroup(ig, num, arg3: true);
		if (Object.op_Implicit((Object)(object)current))
		{
			current.SetSelectedGameObject(((Component)Presets.WearButton(num5 - 1)).gameObject);
		}
	}

	private static void FacePlayerToCamera()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		if (Object.op_Implicit((Object)(object)localPlayer))
		{
			s_savedYaw = R.LookYaw.Invoke((Character)(object)localPlayer);
			Vector3 val = Vector3.zero;
			if (Object.op_Implicit((Object)(object)GameCamera.instance))
			{
				val = ((Component)GameCamera.instance).transform.position - ((Component)localPlayer).transform.position;
			}
			val.y = 0f;
			if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
			{
				val = -((Component)localPlayer).transform.forward;
			}
			CamDir = ((Vector3)(ref val)).normalized;
			R.LookYaw.Invoke((Character)(object)localPlayer) = Quaternion.LookRotation(CamDir, Vector3.up);
			localPlayer.FaceLookDirection();
			((Character)localPlayer).SetLookDir(CamDir, 0f);
		}
	}

	private static Toggle SelectedButton()
	{
		EventSystem current = EventSystem.current;
		GameObject val = (Object.op_Implicit((Object)(object)current) ? current.currentSelectedGameObject : null);
		if (!Object.op_Implicit((Object)(object)val))
		{
			return null;
		}
		return val.GetComponent<Toggle>();
	}

	internal static void Rebuild()
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Expected O, but got Unknown
		Player localPlayer = Player.m_localPlayer;
		s_inv = new Inventory("vanity_outfit", Object.op_Implicit((Object)(object)localPlayer) ? ((Humanoid)localPlayer).GetInventory().GetBkg() : null, 5, 1);
		for (int i = 0; i < 5; i++)
		{
			if (Vanity.TryGetItem(i, out var prefab, out var variant))
			{
				GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(prefab);
				ItemDrop val = (Object.op_Implicit((Object)(object)itemPrefab) ? itemPrefab.GetComponent<ItemDrop>() : null);
				if (Object.op_Implicit((Object)(object)val))
				{
					ItemData val2 = val.m_itemData.Clone();
					val2.m_dropPrefab = itemPrefab;
					val2.m_variant = variant;
					val2.m_stack = 1;
					val2.m_durability = val2.GetMaxDurability();
					R.AddItemAt(s_inv, val2, 1, i, 0, arg6: true);
				}
			}
		}
	}

	internal static void Tint(Graphic g, Color tint, bool temporary)
	{
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: 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_0067: 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_0069: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)g))
		{
			return;
		}
		if (temporary)
		{
			if (!s_orig.ContainsKey(g))
			{
				s_orig[g] = g.color;
			}
			if (!s_origMat.ContainsKey(g))
			{
				s_origMat[g] = g.material;
			}
		}
		Color a = (temporary ? s_orig[g] : g.color);
		g.material = null;
		g.color = Mul(a, tint);
	}

	internal static Color Mul(Color a, Color b)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: 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_001a: 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_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		return new Color(a.r * b.r, a.g * b.g, a.b * b.b, a.a * b.a);
	}

	internal static void Shade(Image bg, Image src)
	{
		//IL_0012: 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)
		if (Object.op_Implicit((Object)(object)bg))
		{
			if (!Object.op_Implicit((Object)(object)src))
			{
				((Graphic)bg).color = Color.white;
				Tint((Graphic)(object)bg, Plugin.PanelTint.Value, temporary: false);
			}
			else
			{
				s_mirror[bg] = src;
				Mirror(bg, src);
			}
		}
	}

	private static void Mirror(Image bg, Image src)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		((Graphic)bg).color = ((Graphic)src).color;
		((Graphic)bg).material = ((Graphic)src).material;
	}

	internal static List<Image> PanelBackgrounds(RectTransform panel)
	{
		List<Image> list = new List<Image>();
		if (!Object.op_Implicit((Object)(object)panel))
		{
			return list;
		}
		Image[] componentsInChildren = ((Component)panel).GetComponentsInChildren<Image>(true);
		foreach (Image val in componentsInChildren)
		{
			string text = (Object.op_Implicit((Object)(object)val.sprite) ? ((Object)val.sprite).name : "");
			string text2 = (Object.op_Implicit((Object)(object)((Graphic)val).material) ? ((Object)((Graphic)val).material).name : "");
			if (text.StartsWith("woodpanel") || text == "crafting_panel_bkg" || text2.StartsWith("litpanel"))
			{
				list.Add(val);
			}
		}
		return list;
	}

	private static void SetColor(Graphic g, Color c)
	{
		//IL_0028: 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)
		if (Object.op_Implicit((Object)(object)g))
		{
			if (!s_orig.ContainsKey(g))
			{
				s_orig[g] = g.color;
			}
			g.color = c;
		}
	}

	private static void RestoreColors()
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: 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_01e8: Unknown result type (might be due to invalid IL or missing references)
		foreach (KeyValuePair<Graphic, Color> item in s_orig)
		{
			if (Object.op_Implicit((Object)(object)item.Key))
			{
				item.Key.color = item.Value;
			}
		}
		s_orig.Clear();
		foreach (KeyValuePair<Graphic, Material> item2 in s_origMat)
		{
			if (Object.op_Implicit((Object)(object)item2.Key))
			{
				item2.Key.material = item2.Value;
			}
		}
		s_origMat.Clear();
		foreach (KeyValuePair<Selectable, ColorBlock> s_origColor in s_origColors)
		{
			if (Object.op_Implicit((Object)(object)s_origColor.Key))
			{
				s_origColor.Key.colors = s_origColor.Value;
			}
		}
		s_origColors.Clear();
		ShowCrafting(show: true);
		foreach (InventoryElement item3 in s_shifted)
		{
			if (Object.op_Implicit((Object)(object)item3))
			{
				RectTransform val = (RectTransform)((Component)item3).transform;
				val.anchoredPosition += new Vector2(0f, 8f);
			}
		}
		s_shifted.Clear();
		foreach (GameObject s_hiddenGo in s_hiddenGos)
		{
			if (Object.op_Implicit((Object)(object)s_hiddenGo))
			{
				s_hiddenGo.SetActive(true);
			}
		}
		s_hiddenGos.Clear();
		InventoryGui instance = InventoryGui.instance;
		if (s_sized && Object.op_Implicit((Object)(object)instance))
		{
			instance.m_container.sizeDelta = s_origSize;
			s_sized = false;
		}
	}

	private static void ShowCrafting(bool show)
	{
		InventoryGui instance = InventoryGui.instance;
		if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)instance.m_crafting))
		{
			return;
		}
		if (!show)
		{
			s_craftingGroup = ((Component)instance.m_crafting).GetComponent<CanvasGroup>();
			s_craftingHadGroup = Object.op_Implicit((Object)(object)s_craftingGroup);
			if (!Object.op_Implicit((Object)(object)s_craftingGroup))
			{
				s_craftingGroup = ((Component)instance.m_crafting).gameObject.AddComponent<CanvasGroup>();
			}
			s_craftingGroup.alpha = 0f;
			s_craftingGroup.interactable = false;
			s_craftingGroup.blocksRaycasts = false;
		}
		else if (Object.op_Implicit((Object)(object)s_craftingGroup))
		{
			if (s_craftingHadGroup)
			{
				s_craftingGroup.alpha = 1f;
				s_craftingGroup.interactable = true;
				s_craftingGroup.blocksRaycasts = true;
			}
			else
			{
				Object.Destroy((Object)(object)s_craftingGroup);
			}
			s_craftingGroup = null;
		}
	}

	private static void ResizePanel(InventoryGui ig)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		RectTransform container = ig.m_container;
		InventoryGrid obj = R.ContainerGrid.Invoke(ig);
		RectTransform val = (RectTransform)((Component)obj).transform;
		s_origSize = container.sizeDelta;
		Rect rect = container.rect;
		float height = ((Rect)(ref rect)).height;
		rect = val.rect;
		float height2 = ((Rect)(ref rect)).height;
		float elementSpace = obj.m_elementSpace;
		if (!(height <= 1f) && !(height2 <= elementSpace))
		{
			float num = height - height2 + elementSpace;
			float num2;
			if (s_btns == null || !Object.op_Implicit((Object)(object)s_btns[0]))
			{
				num2 = 34f;
			}
			else
			{
				rect = ((RectTransform)((Component)s_btns[0]).transform).rect;
				num2 = ((Rect)(ref rect)).height + 8f;
			}
			float num3 = num2;
			float num4 = num * 1.05f + num3 + 12f + 8f;
			if (!(num4 >= height))
			{
				container.SetSizeWithCurrentAnchors((Axis)1, num4);
				s_sized = true;
			}
		}
	}

	private static void Setup(InventoryGui ig)
	{
		//IL_001f: 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)
		foreach (Image item in PanelBackgrounds(ig.m_player))
		{
			Tint((Graphic)(object)item, Plugin.PanelTint.Value, temporary: true);
		}
		foreach (Image item2 in PanelBackgrounds(ig.m_container))
		{
			Tint((Graphic)(object)item2, Plugin.PanelTint.Value, temporary: true);
		}
		ShowCrafting(show: false);
		InventoryGrid val = R.ContainerGrid.Invoke(ig);
		s_prevLower = val.OnMoveToLowerInventoryGrid;
		s_prevJump = R.JumpToNext.Invoke(val);
		val.OnMoveToLowerInventoryGrid = OnGridDown;
		R.JumpToNext.Invoke(val) = true;
		if (!Object.op_Implicit((Object)(object)s_root))
		{
			CreateRow(ig);
		}
		foreach (KeyValuePair<Image, Image> item3 in s_mirror)
		{
			if (Object.op_Implicit((Object)(object)item3.Key) && Object.op_Implicit((Object)(object)item3.Value))
			{
				Mirror(item3.Key, item3.Value);
			}
		}
		if (!s_sized)
		{
			ResizePanel(ig);
		}
		s_root.SetActive(true);
		s_root.transform.SetAsLastSibling();
		if (Array.IndexOf(ig.m_uiGroups, s_group) < 0)
		{
			List<UIGroupHandler> list = new List<UIGroupHandler>(ig.m_uiGroups) { s_group };
			ig.m_uiGroups = list.ToArray();
		}
	}

	private static void CreateRow(InventoryGui ig)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Expected O, but got Unknown
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Expected O, but got Unknown
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_025e: Unknown result type (might be due to invalid IL or missing references)
		//IL_02af: Unknown result type (might be due to invalid IL or missing references)
		//IL_02df: Unknown result type (might be due to invalid IL or missing references)
		//IL_0295: Unknown result type (might be due to invalid IL or missing references)
		//IL_0236: Unknown result type (might be due to invalid IL or missing references)
		s_root = new GameObject("VanityOutfitUI", new Type[1] { typeof(RectTransform) });
		s_root.transform.SetParent(((Transform)ig.m_container).parent, false);
		s_root.AddComponent<LayoutElement>().ignoreLayout = true;
		s_row = new GameObject("VanityOutfitRow", new Type[1] { typeof(RectTransform) });
		s_row.transform.SetParent(s_root.transform, false);
		s_btns = (Toggle[])(object)new Toggle[5];
		s_txt = (TMP_Text[])(object)new TMP_Text[5];
		Toggle val = SettingsToggle();
		float width = Mathf.Max(40f, R.ContainerGrid.Invoke(ig).m_elementSpace - 4f);
		for (int i = 0; i < 5; i++)
		{
			int slot = i;
			Toggle val2 = (Object.op_Implicit((Object)(object)val) ? BuildToggle(ig, val, width, out s_txt[i]) : ClonePvpToggle(ig, out s_txt[i]));
			((Object)((Component)val2).gameObject).name = "VanityHide" + i;
			val2.onValueChanged = new ToggleEvent();
			val2.group = null;
			((Selectable)val2).interactable = true;
			val2.SetIsOnWithoutNotify(Vanity.IsHidden(slot));
			((UnityEvent<bool>)(object)val2.onValueChanged).AddListener((UnityAction<bool>)delegate(bool v)
			{
				Vanity.SetHidden(slot, v);
				Dirty = true;
			});
			s_btns[i] = val2;
		}
		Presets.Create(ig, s_root.transform);
		Button val3 = Presets.WearButton(0);
		CreateBeltPanel(ig, val);
		Navigation val4;
		for (int num = 0; num < 5; num++)
		{
			val4 = default(Navigation);
			((Navigation)(ref val4)).mode = (Mode)4;
			Navigation navigation = val4;
			((Navigation)(ref navigation)).selectOnLeft = (Selectable)(object)((num > 0) ? s_btns[num - 1] : null);
			((Navigation)(ref navigation)).selectOnRight = (Selectable)(object)((num < 4) ? s_btns[num + 1] : null);
			Selectable val5 = (Selectable)(object)((num < 2) ? s_belt : (Object.op_Implicit((Object)(object)s_ctx) ? s_ctx : s_belt));
			((Navigation)(ref navigation)).selectOnDown = (Selectable)(Object.op_Implicit((Object)(object)val5) ? ((object)val5) : ((object)val3));
			((Selectable)s_btns[num]).navigation = navigation;
		}
		if (Object.op_Implicit((Object)(object)s_belt))
		{
			Toggle obj = s_belt;
			val4 = default(Navigation);
			((Navigation)(ref val4)).mode = (Mode)4;
			((Navigation)(ref val4)).selectOnUp = (Selectable)(object)s_btns[0];
			((Navigation)(ref val4)).selectOnRight = (Selectable)(Object.op_Implicit((Object)(object)s_ctx) ? ((object)s_ctx) : ((object)val3));
			((Selectable)obj).navigation = val4;
		}
		if (Object.op_Implicit((Object)(object)s_ctx))
		{
			Toggle obj2 = s_ctx;
			val4 = default(Navigation);
			((Navigation)(ref val4)).mode = (Mode)4;
			((Navigation)(ref val4)).selectOnUp = (Selectable)(object)s_btns[4];
			((Navigation)(ref val4)).selectOnLeft = (Selectable)(object)s_belt;
			((Navigation)(ref val4)).selectOnRight = (Selectable)(object)val3;
			((Selectable)obj2).navigation = val4;
		}
		Presets.SetupNav((Selectable)(object)s_btns[0]);
		s_group = s_root.AddComponent<UIGroupHandler>();
		s_group.m_defaultElement = ((Component)s_btns[0]).gameObject;
		s_group.m_groupPriority = ((ig.m_uiGroups.Length != 0) ? ig.m_uiGroups[0].m_groupPriority : 0);
		s_group.m_enableWhenActiveAndGamepad = null;
	}

	private static RectTransform CreateTogglePanel(InventoryGui ig, Toggle src, string name, float width, Func<bool> get, Action<bool> set, out Toggle toggle, out TMP_Text label)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Expected O, but got Unknown
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Expected O, but got Unknown
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: 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_006f: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: 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_00e3: Expected O, but got Unknown
		//IL_00e5: 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_01a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: 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_0162: 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_0185: 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_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0236: Expected O, but got Unknown
		//IL_0273: Unknown result type (might be due to invalid IL or missing references)
		//IL_027a: Expected O, but got Unknown
		//IL_0291: Unknown result type (might be due to invalid IL or missing references)
		//IL_0298: 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_029b: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
		val.transform.SetParent(s_root.transform, false);
		RectTransform val2 = (RectTransform)val.transform;
		Vector2 val3 = default(Vector2);
		((Vector2)(ref val3))..ctor(0f, 1f);
		val2.pivot = val3;
		Vector2 anchorMin = (val2.anchorMax = val3);
		val2.anchorMin = anchorMin;
		Transform val5 = ((Transform)ig.m_container).Find("Bkg");
		Image val6 = (Object.op_Implicit((Object)(object)val5) ? ((Component)val5).GetComponent<Image>() : null);
		GameObject val7 = new GameObject("Bkg", new Type[2]
		{
			typeof(RectTransform),
			typeof(Image)
		});
		val7.transform.SetParent(val.transform, false);
		RectTransform val8 = (RectTransform)val7.transform;
		val8.anchorMin = Vector2.zero;
		val8.anchorMax = Vector2.one;
		Image component = val7.GetComponent<Image>();
		Rect rect;
		if (Object.op_Implicit((Object)(object)val6))
		{
			rect = ((Graphic)val6).rectTransform.rect;
			Vector2 size = ((Rect)(ref rect)).size;
			rect = ig.m_container.rect;
			Vector2 val9 = (size - ((Rect)(ref rect)).size) * 0.5f;
			val8.offsetMin = -val9 * 0.5f;
			val8.offsetMax = val9 * 0.5f;
			component.sprite = val6.sprite;
			component.type = val6.type;
			component.pixelsPerUnitMultiplier = val6.pixelsPerUnitMultiplier;
		}
		else
		{
			anchorMin = (val8.offsetMax = Vector2.zero);
			val8.offsetMin = anchorMin;
		}
		((Graphic)component).color = Color.white;
		Shade(component, val6);
		label = null;
		Toggle val10 = (Object.op_Implicit((Object)(object)src) ? BuildToggle(ig, src, width, out label, val.transform) : null);
		if (!Object.op_Implicit((Object)(object)val10))
		{
			val10 = ClonePvpToggle(ig, out label);
			((Component)val10).transform.SetParent(val.transform, false);
		}
		((Object)((Component)val10).gameObject).name = name + "Toggle";
		val10.onValueChanged = new ToggleEvent();
		val10.group = null;
		((Selectable)val10).interactable = true;
		val10.SetIsOnWithoutNotify(get());
		((UnityEvent<bool>)(object)val10.onValueChanged).AddListener((UnityAction<bool>)delegate(bool v)
		{
			set(v);
			Dirty = true;
		});
		RectTransform val11 = (RectTransform)((Component)val10).transform;
		((Vector2)(ref val3))..ctor(0f, 0.5f);
		val11.pivot = val3;
		anchorMin = (val11.anchorMax = val3);
		val11.anchorMin = anchorMin;
		rect = val11.rect;
		float num = Mathf.Max(28f, ((Rect)(ref rect)).height);
		val11.anchoredPosition = new Vector2(8f, 0f);
		val2.sizeDelta = new Vector2(width + 16f, num + 16f);
		toggle = val10;
		return val2;
	}

	private static void CreateBeltPanel(InventoryGui ig, Toggle src)
	{
		s_beltPanel = CreateTogglePanel(ig, src, "VanityBeltPanel", 240f, () => Vanity.BeltHidden, delegate(bool v)
		{
			Vanity.BeltHidden = v;
		}, out s_belt, out s_beltLabel);
		s_ctxPanel = CreateTogglePanel(ig, src, "VanityCtxHelmPanel", 240f, () => Vanity.ContextualHelm, delegate(bool v)
		{
			Vanity.ContextualHelm = v;
		}, out s_ctx, out s_ctxLabel);
	}

	private static void UpdateBeltPanel(InventoryGui ig)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Expected O, but got Unknown
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)s_beltPanel))
		{
			return;
		}
		Vector3[] array = (Vector3[])(object)new Vector3[4];
		ig.m_container.GetWorldCorners(array);
		RectTransform val = (RectTransform)((Transform)s_beltPanel).parent;
		((Transform)s_beltPanel).localPosition = ((Transform)val).InverseTransformPoint(array[0]) + new Vector3(6f, -14f, 0f);
		((Selectable)s_belt).interactable = true;
		s_belt.SetIsOnWithoutNotify(Vanity.BeltHidden);
		if (Object.op_Implicit((Object)(object)s_beltLabel))
		{
			s_beltLabel.text = Loc.Get("hide_belt", Loc.Game("$item_beltstrength"));
		}
		if (Object.op_Implicit((Object)(object)s_ctxPanel))
		{
			RectTransform obj = s_ctxPanel;
			Vector3 localPosition = ((Transform)s_beltPanel).localPosition;
			Rect rect = s_beltPanel.rect;
			((Transform)obj).localPosition = localPosition + new Vector3(((Rect)(ref rect)).width + 8f, 0f, 0f);
			((Selectable)s_ctx).interactable = true;
			s_ctx.SetIsOnWithoutNotify(Vanity.ContextualHelm);
			if (Object.op_Implicit((Object)(object)s_ctxLabel))
			{
				s_ctxLabel.text = Loc.Get("ctx_helm");
			}
		}
	}

	private static Toggle SettingsToggle()
	{
		try
		{
			Menu instance = Menu.instance;
			GameObject val = (Object.op_Implicit((Object)(object)instance) ? instance.m_settingsPrefab : null);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return null;
			}
			GameplaySettings componentInChildren = val.GetComponentInChildren<GameplaySettings>(true);
			Toggle val2 = (Toggle)(Object.op_Implicit((Object)(object)componentInChildren) ? /*isinst with value type is only supported in some contexts*/: null);
			if (!Object.op_Implicit((Object)(object)val2))
			{
				val2 = val.GetComponentInChildren<Toggle>(true);
			}
			return (Object.op_Implicit((Object)(object)val2) && ((Selectable)val2).targetGraphic is Image && val2.graphic is Image) ? val2 : null;
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[VKTR_VanityOutfit] Settings toggle: " + ex));
			return null;
		}
	}

	private static Toggle BuildToggle(InventoryGui ig, Toggle src, float width, out TMP_Text label, Transform parent = null)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Expected O, but got Unknown
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Expected O, but got Unknown
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: 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_00c1: 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_00ca: 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_00d2: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Expected O, but got Unknown
		//IL_014f: 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_0156: 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_016f: 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_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Expected O, but got Unknown
		//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01eb: Expected O, but got Unknown
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: Unknown result type (might be due to invalid IL or missing references)
		//IL_0220: Unknown result type (might be due to invalid IL or missing references)
		//IL_0225: Unknown result type (might be due to invalid IL or missing references)
		//IL_0242: Unknown result type (might be due to invalid IL or missing references)
		//IL_0247: Unknown result type (might be due to invalid IL or missing references)
		//IL_0256: Unknown result type (might be due to invalid IL or missing references)
		//IL_025b: Unknown result type (might be due to invalid IL or missing references)
		//IL_026b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0281: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0307: Unknown result type (might be due to invalid IL or missing references)
		//IL_0314: Unknown result type (might be due to invalid IL or missing references)
		//IL_031e: Unknown result type (might be due to invalid IL or missing references)
		//IL_038a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0396: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
		Image val = (Image)((Selectable)src).targetGraphic;
		Image val2 = (Image)src.graphic;
		Rect rect = ((Graphic)val).rectTransform.rect;
		float num = ((Rect)(ref rect)).height;
		if (num < 8f)
		{
			num = 26f;
		}
		num = Mathf.Min(num, 28f);
		GameObject val3 = new GameObject("VanityHide", new Type[3]
		{
			typeof(RectTransform),
			typeof(Image),
			typeof(Toggle)
		});
		val3.transform.SetParent(Object.op_Implicit((Object)(object)parent) ? parent : s_row.transform, false);
		RectTransform val4 = (RectTransform)val3.transform;
		Vector2 val5 = default(Vector2);
		((Vector2)(ref val5))..ctor(0.5f, 0.5f);
		val4.pivot = val5;
		Vector2 anchorMin = (val4.anchorMax = val5);
		val4.anchorMin = anchorMin;
		val4.sizeDelta = new Vector2(width, num);
		((Graphic)val3.GetComponent<Image>()).color = new Color(0f, 0f, 0f, 0f);
		GameObject val7 = new GameObject("Box", new Type[2]
		{
			typeof(RectTransform),
			typeof(Image)
		});
		val7.transform.SetParent(val3.transform, false);
		RectTransform val8 = (RectTransform)val7.transform;
		((Vector2)(ref val5))..ctor(0f, 0.5f);
		val8.pivot = val5;
		anchorMin = (val8.anchorMax = val5);
		val8.anchorMin = anchorMin;
		val8.sizeDelta = new Vector2(num, num);
		Image component = val7.GetComponent<Image>();
		CopyImage(val, component);
		GameObject val10 = new GameObject("Check", new Type[2]
		{
			typeof(RectTransform),
			typeof(Image)
		});
		val10.transform.SetParent(val7.transform, false);
		RectTransform val11 = (RectTransform)val10.transform;
		((Vector2)(ref val5))..ctor(0.5f, 0.5f);
		val11.pivot = val5;
		anchorMin = (val11.anchorMax = val5);
		val11.anchorMin = anchorMin;
		rect = ((Graphic)val).rectTransform.rect;
		float num2;
		if (!(((Rect)(ref rect)).height > 1f))
		{
			num2 = 0.7f;
		}
		else
		{
			rect = ((Graphic)val2).rectTransform.rect;
			float height = ((Rect)(ref rect)).height;
			rect = ((Graphic)val).rectTransform.rect;
			num2 = height / ((Rect)(ref rect)).height;
		}
		float num3 = num2;
		val11.sizeDelta = new Vector2(num, num) * Mathf.Clamp(num3, 0.3f, 1.2f);
		Image component2 = val10.GetComponent<Image>();
		CopyImage(val2, component2);
		GameObject val13 = Object.Instantiate<GameObject>(((Component)ig.m_containerName).gameObject, val3.transform, false);
		StripClone(val13);
		RectTransform val14 = (RectTransform)val13.transform;
		val14.anchorMin = new Vector2(0f, 0f);
		val14.anchorMax = new Vector2(1f, 1f);
		val14.pivot = new Vector2(0f, 0.5f);
		val14.offsetMin = new Vector2(num + 4f, 0f);
		val14.offsetMax = Vector2.zero;
		label = val13.GetComponent<TMP_Text>();
		if (Object.op_Implicit((Object)(object)label))
		{
			label.enableAutoSizing = true;
			label.fontSizeMax = Mathf.Min(label.fontSize, 18f);
			label.fontSizeMin = 8f;
			label.alignment = (TextAlignmentOptions)4097;
		}
		Toggle component3 = val3.GetComponent<Toggle>();
		((Selectable)component3).targetGraphic = (Graphic)(object)component;
		component3.graphic = (Graphic)(object)component2;
		((Selectable)component3).transition = ((Selectable)src).transition;
		((Selectable)component3).colors = ((Selectable)src).colors;
		((Selectable)component3).spriteState = ((Selectable)src).spriteState;
		Tint((Graphic)(object)component, Plugin.ButtonTint.Value, temporary: false);
		return component3;
	}

	private static void CopyImage(Image from, Image to)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		to.sprite = from.sprite;
		to.type = from.type;
		((Graphic)to).color = ((Graphic)from).color;
		((Graphic)to).material = ((Graphic)from).material;
		to.preserveAspect = from.preserveAspect;
		to.pixelsPerUnitMultiplier = from.pixelsPerUnitMultiplier;
	}

	private static Toggle ClonePvpToggle(InventoryGui ig, out TMP_Text label)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: 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_0047: 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_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = Object.Instantiate<GameObject>(((Component)ig.m_pvp).gameObject, s_row.transform, false);
		val.SetActive(true);
		StripClone(val);
		RectTransform val2 = (RectTransform)val.transform;
		Vector2 val3 = default(Vector2);
		((Vector2)(ref val3))..ctor(0.5f, 0.5f);
		val2.pivot = val3;
		Vector2 anchorMin = (val2.anchorMax = val3);
		val2.anchorMin = anchorMin;
		label = val.GetComponentInChildren<TMP_Text>(true);
		if (Object.op_Implicit((Object)(object)label))
		{
			label.enableAutoSizing = true;
			label.fontSizeMax = label.fontSize;
			label.fontSizeMin = 8f;
		}
		return val.GetComponent<Toggle>();
	}

	internal static void StripClone(GameObject go)
	{
		UIGamePad[] componentsInChildren = go.GetComponentsInChildren<UIGamePad>(true);
		foreach (UIGamePad val in componentsInChildren)
		{
			if (Object.op_Implicit((Object)(object)val.m_hint))
			{
				Object.Destroy((Object)(object)val.m_hint);
			}
			Object.Destroy((Object)(object)val);
		}
		MonoBehaviour[] componentsInChildren2 = go.GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val2 in componentsInChildren2)
		{
			if (Object.op_Implicit((Object)(object)val2) && ((object)val2).GetType().Name == "Localize")
			{
				Object.Destroy((Object)(object)val2);
			}
		}
	}

	private static void OnGridDown(Vector2i pos)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		InventoryGui instance = InventoryGui.instance;
		if (Active && Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)s_group))
		{
			int num = Mathf.Clamp(pos.x, 0, 4);
			R.SetActiveGroup(instance, Array.IndexOf(instance.m_uiGroups, s_group), arg3: true);
			EventSystem current = EventSystem.current;
			if (Object.op_Implicit((Object)(object)current))
			{
				current.SetSelectedGameObject(((Component)s_btns[num]).gameObject);
			}
		}
	}

	internal static void UpdatePanel(InventoryGui ig, Player player)
	{
		//IL_0059: 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_005f: 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_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Expected O, but got Unknown
		//IL_0248: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0286: Unknown result type (might be due to invalid IL or missing references)
		//IL_0297: Unknown result type (might be due to invalid IL or missing references)
		//IL_029c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0318: Unknown result type (might be due to invalid IL or missing references)
		//IL_031f: Expected O, but got Unknown
		//IL_032c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0333: Expected O, but got Unknown
		//IL_0339: Unknown result type (might be due to invalid IL or missing references)
		//IL_033e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0342: Unknown result type (might be due to invalid IL or missing references)
		//IL_0347: Unknown result type (might be due to invalid IL or missing references)
		//IL_034c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0359: Unknown result type (might be due to invalid IL or missing references)
		//IL_0365: Unknown result type (might be due to invalid IL or missing references)
		//IL_036a: Unknown result type (might be due to invalid IL or missing references)
		//IL_037b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0380: Unknown result type (might be due to invalid IL or missing references)
		//IL_0397: Unknown result type (might be due to invalid IL or missing references)
		//IL_039c: Unknown result type (might be due to invalid IL or missing references)
		InventoryGrid val = R.ContainerGrid.Invoke(ig);
		((Component)ig.m_container).gameObject.SetActive(true);
		val.UpdateInventory(s_inv, player, (ItemData)null);
		for (int i = 0; i < 5; i++)
		{
			InventoryElement val2 = R.GetElement(val, i, 0, 5);
			if (Object.op_Implicit((Object)(object)val2) && s_shifted.Add(val2))
			{
				RectTransform val3 = (RectTransform)((Component)val2).transform;
				val3.anchoredPosition += new Vector2(0f, -8f);
			}
		}
		ig.m_containerName.text = Loc.Get("title");
		if (Object.op_Implicit((Object)(object)ig.m_containerWeight))
		{
			ig.m_containerWeight.text = "";
		}
		if (Object.op_Implicit((Object)(object)ig.m_takeAllButton))
		{
			((Component)ig.m_takeAllButton).gameObject.SetActive(false);
		}
		if (Object.op_Implicit((Object)(object)ig.m_stackAllButton))
		{
			((Component)ig.m_stackAllButton).gameObject.SetActive(false);
		}
		foreach (Transform item in (Transform)ig.m_container)
		{
			Transform val4 = item;
			if (((Component)val4).gameObject.activeSelf && Object.op_Implicit((Object)(object)((Component)val4).GetComponent<Button>()) && (!Object.op_Implicit((Object)(object)ig.m_takeAllButton) || !((Object)(object)val4 == (Object)(object)((Component)ig.m_takeAllButton).transform)) && (!Object.op_Implicit((Object)(object)ig.m_stackAllButton) || !((Object)(object)val4 == (Object)(object)((Component)ig.m_stackAllButton).transform)))
			{
				((Component)val4).gameObject.SetActive(false);
				if (!s_hiddenGos.Contains(((Component)val4).gameObject))
				{
					s_hiddenGos.Add(((Component)val4).gameObject);
				}
			}
		}
		for (int j = 0; j < 5; j++)
		{
			InventoryElement val5 = R.GetElement(val, j, 0, 5);
			if (!Object.op_Implicit((Object)(object)val5))
			{
				continue;
			}
			SetColor((Graphic)((Object.op_Implicit((Object)(object)val5.m_button) && Object.op_Implicit((Object)(object)((Selectable)val5.m_button).targetGraphic)) ? ((object)((Selectable)val5.m_button).targetGraphic) : ((object)((Component)val5).GetComponent<Image>())), (s_inv.GetItemAt(j, 0) != null || Vanity.IsHidden(j)) ? Plugin.FilledSlot.Value : Plugin.EmptySlot.Value);
			if (Object.op_Implicit((Object)(object)val5.m_button) && !s_origColors.ContainsKey((Selectable)(object)val5.m_button))
			{
				s_origColors[(Selectable)(object)val5.m_button] = ((Selectable)val5.m_button).colors;
				ColorBlock colors = ((Selectable)val5.m_button).colors;
				((ColorBlock)(ref colors)).normalColor = Color.white;
				((Selectable)val5.m_button).colors = colors;
			}
			if (s_inv.GetItemAt(j, 0) == null && Object.op_Implicit((Object)(object)val5.m_amount))
			{
				((Behaviour)val5.m_amount).enabled = true;
				val5.m_amount.text = Loc.Slot(j);
			}
			if (s_btns != null && Object.op_Implicit((Object)(object)s_btns[j]))
			{
				RectTransform val6 = (RectTransform)((Component)val5).transform;
				RectTransform val7 = (RectTransform)((Component)s_btns[j]).transform;
				Rect rect = val6.rect;
				((Transform)val7).position = ((Transform)val6).TransformPoint(Vector2.op_Implicit(((Rect)(ref rect)).center));
				Vector2 anchoredPosition = val7.anchoredPosition;
				rect = val6.rect;
				float num = ((Rect)(ref rect)).height * 0.5f;
				rect = val7.rect;
				val7.anchoredPosition = anchoredPosition + new Vector2(0f, 0f - (num + ((Rect)(ref rect)).height * 0.5f + 6f));
				((Selectable)s_btns[j]).interactable = true;
				s_btns[j].SetIsOnWithoutNotify(Vanity.IsHidden(j));
				if (Object.op_Implicit((Object)(object)s_txt[j]))
				{
					s_txt[j].text = Loc.Get("hide");
				}
			}
		}
		Presets.Update(ig);
		UpdateBeltPanel(ig);
	}

	internal static bool OnClick(InventoryGui ig, InventoryGrid grid, ItemData item, bool dragging)
	{
		if ((Object)(object)grid == (Object)(object)R.ContainerGrid.Invoke(ig))
		{
			if (!dragging && item != null)
			{
				Vanity.Clear(item.m_gridPos.x);
				Dirty = true;
				Rebuild();
				Effect(ig);
			}
			return true;
		}
		if ((Object)(object)grid == (Object)(object)ig.m_playerGrid && !dragging && item != null && Vanity.SlotFor(item) >= 0)
		{
			if (!Vanity.Register(item))
			{
				Player localPlayer = Player.m_localPlayer;
				if (Object.op_Implicit((Object)(object)localPlayer))
				{
					((Character)localPlayer).Message((MessageType)2, Loc.Get("has_light"), 0, (Sprite)null, false);
				}
				return true;
			}
			Dirty = true;
			Rebuild();
			Effect(ig);
			return true;
		}
		return false;
	}

	private static void Effect(InventoryGui ig)
	{
		//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_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		if (ig.m_moveItemEffects != null)
		{
			ig.m_moveItemEffects.Create(((Component)ig).transform.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
		}
	}
}
[HarmonyPatch(typeof(InventoryGui), "UpdateContainer")]
internal static class UpdateContainer_Patch
{
	private static bool Prefix(InventoryGui __instance, Player __0)
	{
		if (!Outfit.Active)
		{
			return true;
		}
		try
		{
			Outfit.UpdatePanel(__instance, __0);
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[VKTR_VanityOutfit] UpdatePanel: " + ex));
			Outfit.Close();
		}
		return false;
	}
}
[HarmonyPatch(typeof(InventoryGui), "UpdateGamepad")]
internal static class UpdateGamepad_Patch
{
	private static bool Prefix(InventoryGui __instance)
	{
		if (!Outfit.Active)
		{
			return true;
		}
		if (!__instance.m_inventoryGroup.IsActive || ZInput.IsTouchActive() || TextInput.IsVisible())
		{
			return false;
		}
		if (ZInput.GetButtonDown("JoyTabLeft"))
		{
			Outfit.CycleGroups(__instance, -1);
		}
		else if (ZInput.GetButtonDown("JoyTabRight"))
		{
			Outfit.CycleGroups(__instance, 1);
		}
		return false;
	}
}
[HarmonyPatch(typeof(InventoryGui), "Update")]
internal static class InventoryGuiUpdate_Patch
{
	private static bool Prefix()
	{
		if (Outfit.Active)
		{
			return !TextInput.IsVisible();
		}
		return true;
	}
}
[HarmonyPatch(typeof(Hud), "UpdateCrosshair")]
internal static class Crosshair_Patch
{
	private static bool s_hidden;

	private static bool Prefix(Hud __instance)
	{
		if (!Outfit.Active)
		{
			if (s_hidden)
			{
				s_hidden = false;
				if (Object.op_Implicit((Object)(object)__instance.m_crosshair))
				{
					((Behaviour)__instance.m_crosshair).enabled = true;
				}
			}
			return true;
		}
		s_hidden = true;
		if (Object.op_Implicit((Object)(object)__instance.m_crosshair))
		{
			((Behaviour)__instance.m_crosshair).enabled = false;
		}
		if (Object.op_Implicit((Object)(object)__instance.m_crosshairBow))
		{
			((Behaviour)__instance.m_crosshairBow).enabled = false;
		}
		if (Object.op_Implicit((Object)(object)__instance.m_hoverName))
		{
			((TMP_Text)__instance.m_hoverName).text = "";
		}
		if (Object.op_Implicit((Object)(object)__instance.m_hoveredPieceAuthorWindow))
		{
			__instance.m_hoveredPieceAuthorWindow.SetActive(false);
		}
		return false;
	}
}
[HarmonyPatch(typeof(InventoryGui), "IsContainerOpen")]
internal static class IsContainerOpen_Patch
{
	private static void Postfix(ref bool __result)
	{
		if (Outfit.Active)
		{
			__result = true;
		}
	}
}
[HarmonyPatch(typeof(InventoryGui), "Hide")]
internal static class Hide_Patch
{
	private static void Postfix()
	{
		Outfit.Close();
	}
}
[HarmonyPatch(typeof(InventoryGui), "OnSelectedItem")]
internal static class OnSelectedItem_Patch
{
	[HarmonyPriority(800)]
	private static bool Prefix(InventoryGui __instance, InventoryGrid grid, ItemData item)
	{
		if (!Outfit.Active)
		{
			return true;
		}
		return !Outfit.OnClick(__instance, grid, item, Object.op_Implicit((Object)(object)R.DragGo.Invoke(__instance)));
	}
}
[HarmonyPatch(typeof(InventoryGui), "OnRightClickItem")]
internal static class OnRightClickItem_Patch
{
	[HarmonyPriority(800)]
	private static bool Prefix(InventoryGui __instance, InventoryGrid grid, ItemData item)
	{
		if (!Outfit.Active)
		{
			return true;
		}
		return !Outfit.OnClick(__instance, grid, item, Object.op_Implicit((Object)(object)R.DragGo.Invoke(__instance)));
	}
}
[HarmonyPatch(typeof(GameCamera), "LateUpdate")]
internal static class Camera_Patch
{
	private static bool s_blending;

	private static Vector3 s_pos;

	private static Quaternion s_rot;

	private static Camera s_cam;

	private static void Postfix(GameCamera __instance)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00c3: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		//IL_0107: 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_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		if (!Outfit.Active || !Object.op_Implicit((Object)(object)localPlayer))
		{
			s_blending = false;
			return;
		}
		Transform transform = ((Component)__instance).transform;
		if (!s_blending)
		{
			s_pos = transform.position;
			s_rot = transform.rotation;
			s_blending = true;
		}
		if (!Object.op_Implicit((Object)(object)s_cam))
		{
			s_cam = ((Component)transform).GetComponentInChildren<Camera>();
		}
		float num = (Object.op_Implicit((Object)(object)s_cam) ? s_cam.fieldOfView : 65f);
		float num2 = 1f * Mathf.Max(0.5f, Plugin.CamFraming.Value) / Mathf.Tan(num * 0.5f * ((float)Math.PI / 180f));
		Vector3 val = ((Component)localPlayer).transform.position + Vector3.up * Plugin.CamHeight.Value;
		RaycastHit val2 = default(RaycastHit);
		if (Physics.Raycast(val, Outfit.CamDir, ref val2, num2, LayerMask.op_Implicit(__instance.m_blockCameraMask)))
		{
			num2 = Mathf.Max(0.8f, ((RaycastHit)(ref val2)).distance - 0.25f);
		}
		Vector3 val3 = val + Outfit.CamDir * num2;
		Quaternion val4 = Quaternion.LookRotation(val - val3, Vector3.up);
		float num3 = 1f - Mathf.Exp(-8f * Time.unscaledDeltaTime);
		s_pos = Vector3.Lerp(s_pos, val3, num3);
		s_rot = Quaternion.Slerp(s_rot, val4, num3);
		transform.SetPositionAndRotation(s_pos, s_rot);
	}
}
internal static class Presets
{
	private class Panel
	{
		public RectTransform Root;

		public TMP_Text Title;

		public Image HomeIcon;

		public InventoryElement[] Slots;

		public Graphic[] SlotBg;

		public Button[] Buttons;

		public TMP_Text[] Labels;

		public float W;

		public float H;
	}

	private class Namer : TextReceiver
	{
		private readonly object m_n;

		public Namer(object n)
		{
			m_n = n;
		}

		public string GetText()
		{
			return Vanity.PresetName(m_n);
		}

		public void SetText(string text)
		{
			if (!string.IsNullOrWhiteSpace(text) && Vanity.PresetExists(m_n))
			{
				Vanity.SetPresetName(m_n, text.Trim());
			}
		}
	}

	internal const int Count = 5;

	internal const int HomeIndex = 4;

	private const float Pad = 8f;

	private const float TitleH = 24f;

	private const float Gap = 6f;

	private const float PanelGap = 8f;

	private const float SlotScale = 0.8f;

	private const float BtnH = 34f;

	private const int Save = 0;

	private const int Wear = 1;

	private const int Delete = 2;

	private static Panel[] s_panels;

	private static int s_confirmDelete = -1;

	private static float s_confirmUntil;

	private static Sprite s_house;

	internal static object Id(int n)
	{
		if (n != 4)
		{
			return n;
		}
		return "home";
	}

	internal static Button WearButton(int n)
	{
		return s_panels[n].Buttons[1];
	}

	internal static int PanelOf(GameObject go)
	{
		if (s_panels == null || !Object.op_Implicit((Object)(object)go))
		{
			return -1;
		}
		for (int i = 0; i < 5; i++)
		{
			if (Object.op_Implicit((Object)(object)s_panels[i].Root) && go.transform.IsChildOf((Transform)(object)s_panels[i].Root))
			{
				return i;
			}
		}
		return -1;
	}

	internal static void SetupNav(Selectable above)
	{
		//IL_0049: 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_0075: 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_00ab: 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)
		for (int i = 0; i < 5; i++)
		{
			Button[] buttons = s_panels[i].Buttons;
			Selectable selectOnUp = (Selectable)((i > 0) ? ((object)s_panels[i - 1].Buttons[0]) : ((object)above));
			Selectable selectOnDown = (Selectable)(object)((i < 4) ? s_panels[i + 1].Buttons[1] : null);
			Button obj = buttons[1];
			Navigation navigation = default(Navigation);
			((Navigation)(ref navigation)).mode = (Mode)4;
			((Navigation)(ref navigation)).selectOnUp = selectOnUp;
			((Navigation)(ref navigation)).selectOnDown = (Selectable)(object)buttons[0];
			((Selectable)obj).navigation = navigation;
			Button obj2 = buttons[0];
			navigation = default(Navigation);
			((Navigation)(ref navigation)).mode = (Mode)4;
			((Navigation)(ref navigation)).selectOnUp = (Selectable)(object)buttons[1];
			((Navigation)(ref navigation)).selectOnDown = selectOnDown;
			((Navigation)(ref navigation)).selectOnRight = (Selectable)(object)buttons[2];
			((Selectable)obj2).navigation = navigation;
			Button obj3 = buttons[2];
			navigation = default(Navigation);
			((Navigation)(ref navigation)).mode = (Mode)4;
			((Navigation)(ref navigation)).selectOnUp = (Selectable)(object)buttons[1];
			((Navigation)(ref navigation)).selectOnDown = selectOnDown;
			((Navigation)(ref navigation)).selectOnLeft = (Selectable)(object)buttons[0];
			((Selectable)obj3).navigation = navigation;
		}
	}

	internal static void Create(InventoryGui ig, Transform parent)
	{
		//IL_001f: Unknown result type (might be due to in