Decompiled source of Custom Holsters v1.2.0

Mods/CustomHolsters.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using BoneLib;
using BoneLib.BoneMenu;
using BoneLib.Notifications;
using CustomHolsters;
using CustomHolsters.Compat;
using CustomHolsters.Holsters;
using CustomHolsters.Layouts;
using CustomHolsters.Menu;
using CustomHolsters.Preview;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.Interaction;
using Il2CppSLZ.Marrow.Warehouse;
using Il2CppSLZ.VRMK;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "Custom Holsters", "1.2.0", "TMLMedia", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: MelonOptionalDependencies(new string[] { "LabFusion" })]
[assembly: AssemblyCompany("CustomHolsters")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0")]
[assembly: AssemblyProduct("Custom Holsters")]
[assembly: AssemblyTitle("Custom Holsters")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CustomHolsters
{
	public class Core : MelonMod
	{
		private object _setupRoutine;

		private float _nextLobbyCheck;

		private bool _wasInLobby;

		public static Core Instance { get; private set; }

		public static Instance Log => ((MelonBase)Instance).LoggerInstance;

		public override void OnInitializeMelon()
		{
			Instance = this;
			Settings.Init();
			LayoutManager.Init();
			Hooking.OnLevelLoaded += OnLevelLoaded;
			Hooking.OnLevelUnloaded += OnLevelUnloaded;
			LayoutManager.LayoutSwitched += ExtraHolsters.Sync;
			Log.Msg("Custom Holsters 1.2.0 loaded. Layouts: " + LayoutManager.LayoutDir);
		}

		public override void OnLateInitializeMelon()
		{
			FusionCompat.Init();
			FusionShare.Init(((MelonBase)this).HarmonyInstance);
			BuildMenuSafe();
		}

		private static void BuildMenuSafe()
		{
			try
			{
				HolsterMenu.Build();
			}
			catch (Exception ex)
			{
				Log.Error("Failed to build BoneMenu page: " + ex);
			}
		}

		private void OnLevelLoaded(LevelInfo info)
		{
			BuildMenuSafe();
			ScheduleSetup(avatarChanged: false);
		}

		private void OnLevelUnloaded()
		{
			LayoutManager.FlushPendingSave();
			AvatarPreview.Destroy();
			HolsterApplier.ClearQueue();
			HolsterRegistry.Clear(restore: false);
			AnchorResolver.Clear();
		}

		internal static void OnLocalAvatarSwitched()
		{
			if (Instance != null)
			{
				Instance.ScheduleSetup(avatarChanged: true);
			}
		}

		public void ScheduleSetup(bool avatarChanged)
		{
			if (_setupRoutine != null)
			{
				MelonCoroutines.Stop(_setupRoutine);
			}
			_setupRoutine = MelonCoroutines.Start(SetupRoutine(avatarChanged));
		}

		private IEnumerator SetupRoutine(bool avatarChanged)
		{
			HolsterApplier.Suspended = true;
			for (int i = 0; i < 3; i++)
			{
				yield return null;
			}
			float until = Time.realtimeSinceStartup + 0.35f;
			while (Time.realtimeSinceStartup < until)
			{
				yield return null;
			}
			RigManager rigManager = Player.RigManager;
			if ((Object)(object)rigManager == (Object)null)
			{
				HolsterApplier.Suspended = false;
				_setupRoutine = null;
				yield break;
			}
			try
			{
				if ((Object)(object)HolsterRegistry.Rig != (Object)(object)rigManager)
				{
					HolsterRegistry.Scan(rigManager);
				}
				else
				{
					foreach (HolsterSlot slot in HolsterRegistry.Slots)
					{
						if (slot.IsValid && slot.Overridden)
						{
							slot.RestoreVanilla();
						}
					}
					try
					{
						if ((Object)(object)rigManager.avatar != (Object)null && (Object)(object)rigManager.physicsRig != (Object)null)
						{
							rigManager.physicsRig.SetBodySlot(rigManager.avatar);
						}
					}
					catch (Exception)
					{
					}
					HolsterRegistry.RecaptureVanilla();
				}
				AnchorResolver.Calibrate(rigManager);
				if (!HolsterRegistry.NamesAssigned)
				{
					HolsterRegistry.AssignLocationNames();
					if (HolsterRegistry.Migrate(LayoutManager.Current))
					{
						LayoutManager.Save();
					}
				}
				string text = "";
				string title = "";
				try
				{
					text = ((ScannableReference)rigManager.AvatarCrate).Barcode.ID;
					title = (((Object)(object)((CrateReferenceT<AvatarCrate>)(object)rigManager.AvatarCrate).Crate != (Object)null) ? ((Scannable)((CrateReferenceT<AvatarCrate>)(object)rigManager.AvatarCrate).Crate).Title : text);
				}
				catch (Exception)
				{
				}
				LayoutManager.OnAvatarChanged(text, title);
				ExtraHolsters.Sync();
				HolsterApplier.OnLayoutReplaced();
				if (avatarChanged)
				{
					AnnounceFit(title);
				}
			}
			catch (Exception ex3)
			{
				Log.Error("Holster setup failed: " + ex3);
			}
			HolsterApplier.Suspended = false;
			HolsterMenu.OnRigReady();
			if (AvatarPreview.IsVisible)
			{
				AvatarPreview.Rebuild();
			}
			_setupRoutine = null;
		}

		private static void AnnounceFit(string title)
		{
			if (!Settings.NotifyAvatarFit.Value || !Settings.Enabled.Value || LayoutManager.Current == null)
			{
				return;
			}
			int num = 0;
			foreach (HolsterSlot slot in HolsterRegistry.Slots)
			{
				HolsterPlacement holsterPlacement = LayoutManager.Current.Get(slot.Id);
				if (holsterPlacement != null && holsterPlacement.Moved)
				{
					num++;
				}
			}
			if (num != 0)
			{
				string text = (BodyFit.FitActive ? "Fitted " : "Scaled ");
				HolsterMenu.Notify(text + num + " holster" + ((num == 1) ? "" : "s") + " to " + (string.IsNullOrEmpty(title) ? "this avatar" : title) + $" ({BodyFit.AvatarHeight:0.00} m)", warning: false);
			}
		}

		public override void OnUpdate()
		{
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			if (realtimeSinceStartup >= _nextLobbyCheck)
			{
				_nextLobbyCheck = realtimeSinceStartup + 0.5f;
				bool inLobby = FusionCompat.InLobby;
				if (inLobby != _wasInLobby)
				{
					_wasInLobby = inLobby;
					foreach (HolsterSlot slot in HolsterRegistry.Slots)
					{
						slot.NetHidden = false;
					}
					ExtraHolsters.Sync();
					HolsterApplier.OnLayoutReplaced();
				}
			}
			RigManager rigManager = Player.RigManager;
			if ((Object)(object)rigManager != (Object)null && (Object)(object)rigManager != (Object)(object)HolsterRegistry.Rig && _setupRoutine == null)
			{
				HolsterRegistry.Clear(restore: false);
				ScheduleSetup(avatarChanged: false);
			}
			HolsterApplier.Tick(processQueue: true);
			LayoutManager.Tick();
			HolsterMenu.Tick();
		}

		public override void OnFixedUpdate()
		{
			HolsterApplier.Tick(processQueue: false);
		}

		public override void OnLateUpdate()
		{
			HolsterApplier.Tick(processQueue: false);
			AvatarPreview.Tick();
		}

		public override void OnApplicationQuit()
		{
			LayoutManager.FlushPendingSave();
		}
	}
	public static class ModInfo
	{
		public const string Name = "Custom Holsters";

		public const string InternalName = "CustomHolsters";

		public const string Version = "1.2.0";

		public const string Author = "TMLMedia";

		public const string DataFolderName = "CustomHolsters";
	}
	public static class Settings
	{
		public const int CurrentConfigVersion = 3;

		private static MelonPreferences_Category _category;

		public static MelonPreferences_Entry<bool> Enabled;

		public static MelonPreferences_Entry<string> DefaultLayout;

		public static MelonPreferences_Entry<bool> AutoLoadAvatarLayouts;

		public static MelonPreferences_Entry<bool> AutoSave;

		public static MelonPreferences_Entry<bool> ReseatHolsteredItems;

		public static MelonPreferences_Entry<bool> ShowLiveGizmo;

		public static MelonPreferences_Entry<bool> CopyHandRotation;

		public static MelonPreferences_Entry<float> PreviewHeight;

		public static MelonPreferences_Entry<bool> ExtrasInFusion;

		public static MelonPreferences_Entry<bool> ShareWithEveryone;

		public static MelonPreferences_Entry<bool> NotifyAvatarFit;

		public static MelonPreferences_Entry<int> ConfigVersion;

		public static void Init()
		{
			_category = MelonPreferences.CreateCategory("CustomHolsters", "Custom Holsters");
			Enabled = _category.CreateEntry<bool>("Enabled", true, "Enabled", "Master switch. When off, every holster returns to its vanilla BONELAB position and added holsters are removed.", false, false, (ValueValidator)null, (string)null);
			DefaultLayout = _category.CreateEntry<string>("DefaultLayout", "Default", "Default Layout", "Layout used for any avatar that has no layout bound to it.", false, false, (ValueValidator)null, (string)null);
			AutoLoadAvatarLayouts = _category.CreateEntry<bool>("AutoLoadAvatarLayouts", true, "Auto-Load Avatar Layouts", "Automatically switch to the layout bound to an avatar when you change into it.", false, false, (ValueValidator)null, (string)null);
			AutoSave = _category.CreateEntry<bool>("AutoSave", true, "Auto-Save", "Save the active layout automatically a moment after each edit.", false, false, (ValueValidator)null, (string)null);
			ReseatHolsteredItems = _category.CreateEntry<bool>("ReseatHolsteredItems", true, "Re-seat Holstered Items", "After moving a holster, re-insert whatever it holds so the item jumps to the new spot. Inside Fusion lobbies the mod re-seats only when needed for sharing.", false, false, (ValueValidator)null, (string)null);
			ShowLiveGizmo = _category.CreateEntry<bool>("ShowLiveGizmo", true, "Show Live Gizmo", "Show a yellow pin above the real holster you are editing.", false, false, (ValueValidator)null, (string)null);
			CopyHandRotation = _category.CreateEntry<bool>("CopyHandRotation", false, "Copy Hand Rotation", "When placing a holster at your hand, also copy the hand's rotation.", false, false, (ValueValidator)null, (string)null);
			PreviewHeight = _category.CreateEntry<float>("PreviewHeight", 0.6f, "Preview Height", "Height in meters of the 3D avatar preview figure.", false, false, (ValueValidator)null, (string)null);
			ExtrasInFusion = _category.CreateEntry<bool>("ExtrasInFusion", true, "Added Holsters In Fusion", "Keep holsters you added working inside Fusion lobbies. Everyone (with or without the mod) sees what's in them.", false, false, (ValueValidator)null, (string)null);
			ShareWithEveryone = _category.CreateEntry<bool>("ShareWithEveryone", true, "Show Holsters To Everyone", "In Fusion lobbies, players WITHOUT Custom Holsters also see items in your moved holsters where you put them.", false, false, (ValueValidator)null, (string)null);
			NotifyAvatarFit = _category.CreateEntry<bool>("NotifyAvatarFit", true, "Avatar Fit Popup", "Show a popup when your holsters are re-fitted to a new avatar.", false, false, (ValueValidator)null, (string)null);
			ConfigVersion = _category.CreateEntry<int>("ConfigVersion", 3, "Config Version", "Used by the mod to update old settings. Don't change.", false, false, (ValueValidator)null, (string)null);
			if (ConfigVersion.Value < 3)
			{
				ShareWithEveryone.Value = true;
				ConfigVersion.Value = 3;
				Save();
			}
		}

		public static void Save()
		{
			if (_category != null)
			{
				_category.SaveToFile(false);
			}
		}
	}
	[HarmonyPatch(typeof(RigManager), "SwitchAvatar")]
	internal static class SwitchAvatarPatch
	{
		[HarmonyPostfix]
		private static void Postfix(RigManager __instance)
		{
			try
			{
				if ((Object)(object)__instance != (Object)null && (Object)(object)__instance == (Object)(object)Player.RigManager)
				{
					Core.OnLocalAvatarSwitched();
				}
			}
			catch (Exception)
			{
			}
		}
	}
}
namespace CustomHolsters.Preview
{
	public static class AvatarPreview
	{
		private sealed class Marker
		{
			public GameObject Root;

			public Renderer Ball;

			public int ColorKey = -1;
		}

		private static readonly Color SelectedColor = new Color(1f, 0.85f, 0.1f, 1f);

		private static readonly Color MovedColor = new Color(0.1f, 0.85f, 1f, 1f);

		private static readonly Color VanillaColor = new Color(0.85f, 0.85f, 0.85f, 1f);

		private static readonly Color AmmoColor = new Color(1f, 0.5f, 0.15f, 1f);

		private static readonly Color ExtraColor = new Color(0.3f, 1f, 0.4f, 1f);

		private static readonly Color DiscColor = new Color(0.15f, 0.17f, 0.2f, 1f);

		private static GameObject _root;

		private static Transform _turntable;

		private static Transform _model;

		private static GameObject _liveGizmo;

		private static Transform _liveGizmoTarget;

		private static readonly List<Mesh> _bakedMeshes = new List<Mesh>();

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

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

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

		private static readonly int AnchorCount = Enum.GetValues(typeof(BodyAnchor)).Length;

		private static readonly Vector3[] _anchorPos = (Vector3[])(object)new Vector3[AnchorCount];

		private static readonly Quaternion[] _anchorRot = (Quaternion[])(object)new Quaternion[AnchorCount];

		private static readonly bool[] _anchorValid = new bool[AnchorCount];

		private static float _avatarHeight = 1.76f;

		private static float _modelScale = 1f;

		private static float _yaw;

		private static float _pitch;

		public static bool AutoSpin;

		public static string SelectedId;

		public static bool IsVisible => (Object)(object)_root != (Object)null;

		public static float Yaw => _yaw;

		public static void SetVisible(bool visible)
		{
			if (visible)
			{
				Rebuild();
			}
			else
			{
				Destroy();
			}
		}

		public static void Rebuild()
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			Destroy();
			RigManager rigManager = Player.RigManager;
			Avatar val = (((Object)(object)rigManager != (Object)null) ? rigManager.avatar : null);
			if ((Object)(object)val == (Object)null || !AnchorResolver.IsCalibrated)
			{
				HolsterMenuNotify("Load into a level with an avatar first.");
				return;
			}
			try
			{
				Transform transform = ((Component)val).transform;
				_avatarHeight = ((val.height > 0.1f) ? val.height : 1.76f);
				_root = new GameObject("[Custom Holsters] Preview");
				_turntable = new GameObject("Turntable").transform;
				_turntable.SetParent(_root.transform, false);
				_model = new GameObject("Model").transform;
				_model.SetParent(_turntable, false);
				BakeRenderers(transform);
				BakeAnchorsAndVanilla(transform);
				BuildDisc();
				BuildMarkers();
				_modelScale = Mathf.Clamp(Settings.PreviewHeight.Value, 0.15f, 2.5f) / _avatarHeight;
				_model.localScale = Vector3.one * _modelScale;
				_model.localPosition = new Vector3(0f, (0f - _avatarHeight) * 0.5f * _modelScale, 0f);
				Recenter();
				ApplyRotation();
				UpdateMarkers();
			}
			catch (Exception ex)
			{
				Core.Log.Error("Failed to build avatar preview: " + ex);
				Destroy();
			}
		}

		public static void Destroy()
		{
			if ((Object)(object)_root != (Object)null)
			{
				Object.Destroy((Object)(object)_root);
			}
			_root = null;
			_turntable = null;
			_model = null;
			foreach (Mesh bakedMesh in _bakedMeshes)
			{
				if ((Object)(object)bakedMesh != (Object)null)
				{
					Object.Destroy((Object)(object)bakedMesh);
				}
			}
			_bakedMeshes.Clear();
			_markers.Clear();
			_vanillaPos.Clear();
			_vanillaRot.Clear();
			DestroyLiveGizmo();
		}

		public static void Recenter()
		{
			//IL_0027: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_004c: 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_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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_root == (Object)null))
			{
				Transform head = Player.Head;
				Vector3 val = (((Object)(object)head != (Object)null) ? head.position : Vector3.zero);
				Vector3 val2 = (((Object)(object)head != (Object)null) ? Vector3.ProjectOnPlane(head.forward, Vector3.up) : Vector3.forward);
				if (((Vector3)(ref val2)).sqrMagnitude < 0.0001f)
				{
					val2 = Vector3.forward;
				}
				((Vector3)(ref val2)).Normalize();
				Vector3 val3 = val + val2 * 0.6f + Vector3.down * 0.3f;
				_root.transform.SetPositionAndRotation(val3, Quaternion.LookRotation(-val2, Vector3.up));
			}
		}

		public static void Rotate(float degrees)
		{
			_yaw = HolsterApplier.Wrap(_yaw + degrees);
			ApplyRotation();
		}

		public static void Tilt(float degrees)
		{
			_pitch = Mathf.Clamp(_pitch + degrees, -75f, 75f);
			ApplyRotation();
		}

		public static void SetView(float yaw)
		{
			_yaw = yaw;
			_pitch = 0f;
			ApplyRotation();
		}

		public static void Tick()
		{
			if ((Object)(object)_root == (Object)null)
			{
				DestroyLiveGizmo();
				return;
			}
			if (AutoSpin)
			{
				_yaw = HolsterApplier.Wrap(_yaw + 30f * Time.deltaTime);
				ApplyRotation();
			}
			try
			{
				UpdateMarkers();
				UpdateLiveGizmo();
			}
			catch (Exception)
			{
				Destroy();
			}
		}

		private static void BakeRenderers(Transform src)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_0012: 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_0052: Expected O, but got Unknown
			//IL_0087: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0141: 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_0149: 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_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_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: 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)
			Quaternion val = Quaternion.Inverse(src.rotation);
			Vector3 position = src.position;
			foreach (SkinnedMeshRenderer componentsInChild in ((Component)src).GetComponentsInChildren<SkinnedMeshRenderer>(false))
			{
				if (!((Object)(object)componentsInChild == (Object)null) && ((Renderer)componentsInChild).enabled && !((Object)(object)componentsInChild.sharedMesh == (Object)null))
				{
					Mesh val2 = new Mesh();
					componentsInChild.BakeMesh(val2, true);
					_bakedMeshes.Add(val2);
					Transform transform = ((Component)componentsInChild).transform;
					AddStatic("Baked " + ((Object)componentsInChild).name, val2, ((Renderer)componentsInChild).sharedMaterials, val * (transform.position - position), val * transform.rotation, Vector3.one);
				}
			}
			foreach (MeshRenderer componentsInChild2 in ((Component)src).GetComponentsInChildren<MeshRenderer>(false))
			{
				if (!((Object)(object)componentsInChild2 == (Object)null) && ((Renderer)componentsInChild2).enabled)
				{
					MeshFilter component = ((Component)componentsInChild2).GetComponent<MeshFilter>();
					if (!((Object)(object)component == (Object)null) && !((Object)(object)component.sharedMesh == (Object)null))
					{
						Transform transform2 = ((Component)componentsInChild2).transform;
						AddStatic("Static " + ((Object)componentsInChild2).name, component.sharedMesh, ((Renderer)componentsInChild2).sharedMaterials, val * (transform2.position - position), val * transform2.rotation, transform2.lossyScale);
					}
				}
			}
		}

		private static void AddStatic(string name, Mesh mesh, Il2CppReferenceArray<Material> materials, Vector3 localPos, Quaternion localRot, Vector3 localScale)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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)
			//IL_0023: 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_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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(_model, false);
			val.transform.localPosition = localPos;
			val.transform.localRotation = localRot;
			val.transform.localScale = localScale;
			val.layer = 0;
			val.AddComponent<MeshFilter>().sharedMesh = mesh;
			MeshRenderer obj = val.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterials = materials;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).receiveShadows = false;
			if (materials != null && ((Il2CppArrayBase<Material>)(object)materials).Length > 0 && (Object)(object)((Il2CppArrayBase<Material>)(object)materials)[0] != (Object)null)
			{
				PreviewMaterials.SetFallbackShader(((Il2CppArrayBase<Material>)(object)materials)[0].shader);
			}
		}

		private static void BakeAnchorsAndVanilla(Transform src)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_0012: 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_005d: 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_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_006a: 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_0077: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: 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_00db: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			Quaternion val = Quaternion.Inverse(src.rotation);
			Vector3 position = src.position;
			foreach (BodyAnchor value in Enum.GetValues(typeof(BodyAnchor)))
			{
				int num = (int)value;
				_anchorValid[num] = AnchorResolver.TryGetFrame(value, out var position2, out var rotation);
				if (_anchorValid[num])
				{
					_anchorPos[num] = val * (position2 - position);
					_anchorRot[num] = val * rotation;
				}
			}
			foreach (HolsterSlot slot in HolsterRegistry.Slots)
			{
				if (slot.IsValid)
				{
					_vanillaPos[slot.Id] = val * (slot.VanillaWorldPosition - position);
					_vanillaRot[slot.Id] = val * slot.VanillaWorldRotation;
				}
			}
		}

		private static void BuildDisc()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = Primitive((PrimitiveType)2, "Turntable Disc", _model);
			float num = _avatarHeight * 0.45f;
			obj.transform.localPosition = new Vector3(0f, -0.01f, 0f);
			obj.transform.localScale = new Vector3(num, 0.008f, num);
			SetColor(obj.GetComponent<Renderer>(), DiscColor);
			GameObject obj2 = Primitive((PrimitiveType)3, "Front Notch", _model);
			obj2.transform.localPosition = new Vector3(0f, 0f, num * 0.5f);
			obj2.transform.localScale = new Vector3(0.04f, 0.012f, 0.06f) * (_avatarHeight / 1.76f);
			SetColor(obj2.GetComponent<Renderer>(), SelectedColor);
		}

		private static void BuildMarkers()
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			foreach (HolsterSlot slot in HolsterRegistry.Slots)
			{
				if (slot.IsValid && !_markers.ContainsKey(slot.Id))
				{
					Marker marker = new Marker();
					marker.Root = new GameObject("Marker " + slot.Id);
					marker.Root.transform.SetParent(_model, false);
					GameObject val = Primitive((PrimitiveType)0, "Ball", marker.Root.transform);
					marker.Ball = val.GetComponent<Renderer>();
					AddAxis(marker.Root.transform, Vector3.right, new Color(1f, 0.25f, 0.25f, 1f));
					AddAxis(marker.Root.transform, Vector3.up, new Color(0.3f, 1f, 0.3f, 1f));
					AddAxis(marker.Root.transform, Vector3.forward, new Color(0.3f, 0.5f, 1f, 1f));
					_markers[slot.Id] = marker;
				}
			}
		}

		private static void AddAxis(Transform parent, Vector3 dir, Color color)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = Primitive((PrimitiveType)3, "Axis", parent);
			obj.transform.localPosition = dir * 0.9f;
			Vector3 localScale = default(Vector3);
			((Vector3)(ref localScale))..ctor(0.15f, 0.15f, 0.15f);
			if (dir.x != 0f)
			{
				localScale.x = 1.8f;
			}
			if (dir.y != 0f)
			{
				localScale.y = 1.8f;
			}
			if (dir.z != 0f)
			{
				localScale.z = 1.8f;
			}
			obj.transform.localScale = localScale;
			SetColor(obj.GetComponent<Renderer>(), color);
		}

		private static void ApplyRotation()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_turntable != (Object)null)
			{
				_turntable.localRotation = Quaternion.Euler(_pitch, _yaw, 0f);
			}
		}

		private static void UpdateMarkers()
		{
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: 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_00c9: 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_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			HolsterLayout current = LayoutManager.Current;
			float num = 0.035f * (_avatarHeight / 1.76f);
			foreach (HolsterSlot slot in HolsterRegistry.Slots)
			{
				if (_markers.TryGetValue(slot.Id, out var value) && !((Object)(object)value.Root == (Object)null))
				{
					HolsterPlacement holsterPlacement = ((current != null && Settings.Enabled.Value) ? current.Get(slot.Id) : null);
					bool flag = holsterPlacement != null && holsterPlacement.Moved && _anchorValid[(int)holsterPlacement.Anchor];
					Vector3 value2;
					Quaternion value3;
					if (flag)
					{
						int anchor = (int)holsterPlacement.Anchor;
						value2 = _anchorPos[anchor] + _anchorRot[anchor] * HolsterApplier.LocalOffset(holsterPlacement);
						value3 = _anchorRot[anchor] * Quaternion.Euler(holsterPlacement.Rotation.ToVector3());
					}
					else if (!_vanillaPos.TryGetValue(slot.Id, out value2) || !_vanillaRot.TryGetValue(slot.Id, out value3))
					{
						value.Root.SetActive(false);
						continue;
					}
					bool flag2 = slot.Id == SelectedId;
					value.Root.SetActive(true);
					value.Root.transform.localPosition = value2;
					value.Root.transform.localRotation = value3;
					value.Root.transform.localScale = Vector3.one * num * (flag2 ? 1.7f : 1f);
					Color color = (flag2 ? SelectedColor : ((!flag) ? (slot.IsAmmoPouch ? AmmoColor : VanillaColor) : MovedColor));
					if (slot.IsExtra && !flag2)
					{
						color = ExtraColor;
					}
					int num2 = ((!flag2) ? (slot.IsExtra ? 4 : (flag ? 1 : (slot.IsAmmoPouch ? 2 : 3))) : 0);
					if (value.ColorKey != num2)
					{
						value.ColorKey = num2;
						SetColor(value.Ball, color);
					}
				}
			}
		}

		private static void UpdateLiveGizmo()
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: 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_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			HolsterSlot holsterSlot = (string.IsNullOrEmpty(SelectedId) ? null : HolsterRegistry.Find(SelectedId));
			if (!Settings.ShowLiveGizmo.Value || holsterSlot == null || !holsterSlot.IsValid)
			{
				DestroyLiveGizmo();
				return;
			}
			if ((Object)(object)_liveGizmo == (Object)null || (Object)(object)_liveGizmoTarget != (Object)(object)holsterSlot.Target)
			{
				DestroyLiveGizmo();
				_liveGizmoTarget = holsterSlot.Target;
				_liveGizmo = new GameObject("[Custom Holsters] Live Gizmo");
				_liveGizmo.transform.SetParent(holsterSlot.Target, false);
				SetColor(Primitive((PrimitiveType)0, "Ball", _liveGizmo.transform).GetComponent<Renderer>(), SelectedColor);
				AddAxis(_liveGizmo.transform, Vector3.right, new Color(1f, 0.25f, 0.25f, 1f));
				AddAxis(_liveGizmo.transform, Vector3.up, new Color(0.3f, 1f, 0.3f, 1f));
				AddAxis(_liveGizmo.transform, Vector3.forward, new Color(0.3f, 0.5f, 1f, 1f));
			}
			float num = Mathf.Max(holsterSlot.Target.lossyScale.x, 0.0001f);
			_liveGizmo.transform.localPosition = Vector3.zero;
			_liveGizmo.transform.localRotation = Quaternion.identity;
			_liveGizmo.transform.localScale = Vector3.one * (0.03f / num);
		}

		private static void DestroyLiveGizmo()
		{
			if ((Object)(object)_liveGizmo != (Object)null)
			{
				Object.Destroy((Object)(object)_liveGizmo);
			}
			_liveGizmo = null;
			_liveGizmoTarget = null;
		}

		private static GameObject Primitive(PrimitiveType type, string name, Transform parent)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GameObject.CreatePrimitive(type);
			((Object)obj).name = name;
			Collider component = obj.GetComponent<Collider>();
			if ((Object)(object)component != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component);
			}
			obj.transform.SetParent(parent, false);
			obj.layer = 0;
			Renderer component2 = obj.GetComponent<Renderer>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.shadowCastingMode = (ShadowCastingMode)0;
				component2.receiveShadows = false;
			}
			return obj;
		}

		private static void SetColor(Renderer renderer, Color color)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)renderer == (Object)null))
			{
				Material val = PreviewMaterials.Get(color);
				if ((Object)(object)val != (Object)null)
				{
					renderer.sharedMaterial = val;
				}
			}
		}

		private static void HolsterMenuNotify(string message)
		{
			HolsterMenu.Notify(message, warning: true);
		}
	}
	public static class PreviewMaterials
	{
		private static readonly Dictionary<int, Material> _cache = new Dictionary<int, Material>();

		private static Shader _shader;

		private static Shader _fallback;

		private static readonly string[] ShaderNames = new string[4] { "Universal Render Pipeline/Unlit", "Universal Render Pipeline/Simple Lit", "Universal Render Pipeline/Lit", "Unlit/Color" };

		public static void SetFallbackShader(Shader shader)
		{
			if ((Object)(object)shader != (Object)null && (Object)(object)_fallback == (Object)null)
			{
				_fallback = shader;
			}
		}

		public static Material Get(Color color)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
			int key = ((int)(color.r * 255f) << 24) | ((int)(color.g * 255f) << 16) | ((int)(color.b * 255f) << 8) | (int)(color.a * 255f);
			if (_cache.TryGetValue(key, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			Shader val = FindShader();
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			value = new Material(val);
			((Object)value).hideFlags = (HideFlags)32;
			if (value.HasProperty("_BaseColor"))
			{
				value.SetColor("_BaseColor", color);
			}
			if (value.HasProperty("_Color"))
			{
				value.SetColor("_Color", color);
			}
			if (value.HasProperty("_EmissionColor"))
			{
				value.EnableKeyword("_EMISSION");
				value.SetColor("_EmissionColor", color * 0.6f);
			}
			_cache[key] = value;
			return value;
		}

		private static Shader FindShader()
		{
			if ((Object)(object)_shader != (Object)null)
			{
				return _shader;
			}
			string[] shaderNames = ShaderNames;
			for (int i = 0; i < shaderNames.Length; i++)
			{
				Shader val = Shader.Find(shaderNames[i]);
				if ((Object)(object)val != (Object)null)
				{
					_shader = val;
					return val;
				}
			}
			return _fallback;
		}
	}
}
namespace CustomHolsters.Menu
{
	public static class HolsterMenu
	{
		private enum StepSize
		{
			Fine,
			Normal,
			Coarse
		}

		private static readonly Color Accent = new Color(0.35f, 0.85f, 1f, 1f);

		private static readonly Color Gold = new Color(1f, 0.85f, 0.2f, 1f);

		private static readonly Color Soft = new Color(0.8f, 0.8f, 0.85f, 1f);

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

		private static readonly Color Good = new Color(0.4f, 1f, 0.55f, 1f);

		private static readonly Color Danger = new Color(1f, 0.4f, 0.35f, 1f);

		private static readonly Color PosColor = new Color(0.55f, 0.9f, 1f, 1f);

		private static readonly Color RotColor = new Color(1f, 0.7f, 0.95f, 1f);

		private static bool _built;

		private static Page _root;

		private static Page _editor;

		private static Page _choose;

		private static Page _rename;

		private static Page _anchors;

		private static Page _quick;

		private static Page _extras;

		private static Page _loadouts;

		private static Page _fit;

		private static Page _fusion;

		private static Page _preview;

		private static Page _layouts;

		private static Page _load;

		private static Page _settings;

		private static FunctionElement _status;

		private static FunctionElement _selected;

		private static FunctionElement _state;

		private static FunctionElement _anchorButton;

		private static FunctionElement _stepButton;

		private static FunctionElement _renameLabel;

		private static FunctionElement _extrasLabel;

		private static FunctionElement _fitLabel;

		private static FunctionElement _layoutLabel;

		private static FunctionElement _avatarLabel;

		private static FunctionElement _fusionLabel;

		private static FunctionElement _liveLabel;

		private static FloatElement _px;

		private static FloatElement _py;

		private static FloatElement _pz;

		private static FloatElement _rx;

		private static FloatElement _ry;

		private static FloatElement _rz;

		private static FloatElement _grab;

		private static FloatElement _globalGrab;

		private static FloatElement _previewSize;

		private static BoolElement _enabled;

		private static BoolElement _scaleWithAvatar;

		private static BoolElement _fitToggle;

		private static BoolElement _shareToggle;

		private static BoolElement _extrasFusionA;

		private static BoolElement _extrasFusionB;

		private static BoolElement _previewToggle;

		private static int _selectedIndex;

		private static StepSize _step = StepSize.Normal;

		private static string _pendingName = "My Layout";

		private static string _pendingHolsterName = "";

		private static float _countdownEnd = -1f;

		private static int _countdownShown;

		private static string _countdownMessage;

		private static Action _countdownAction;

		private static float _nextStatusRefresh;

		private static HolsterSlot Selected
		{
			get
			{
				int count = HolsterRegistry.Slots.Count;
				if (count == 0)
				{
					return null;
				}
				_selectedIndex = (_selectedIndex % count + count) % count;
				HolsterSlot holsterSlot = HolsterRegistry.Slots[_selectedIndex];
				if (!holsterSlot.IsValid)
				{
					return null;
				}
				return holsterSlot;
			}
		}

		public static void Build()
		{
			//IL_0024: 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_009a: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: 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_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			if (!_built && Page.Root != null)
			{
				_built = true;
				_root = Page.Root.CreatePage("Custom Holsters", Accent, 0, true);
				TrySetLogo(_root);
				_enabled = _root.CreateBool("Enabled", Good, Settings.Enabled.Value, (Action<bool>)delegate(bool v)
				{
					Settings.Enabled.Value = v;
					Settings.Save();
					HolsterApplier.MarkGrabDirty();
					ExtraHolsters.Sync();
					HolsterApplier.OnLayoutReplaced();
				});
				((Element)_enabled).ElementTooltip = "Master switch. Off returns every holster to its vanilla spot and removes added holsters.";
				_status = _root.CreateFunction("Status: waiting for a level", Muted, (Action)delegate
				{
					RefreshStatus();
				});
				_editor = _root.CreatePage("Holster Editor", Gold, 0, true);
				_extras = _root.CreatePage("Add & Remove Holsters", Good, 0, true);
				_loadouts = _root.CreatePage("Pre-made Loadouts", Gold, 0, true);
				_fit = _root.CreatePage("Avatar Fit", Accent, 0, true);
				_preview = _root.CreatePage("3D Avatar Preview", Accent, 0, true);
				_layouts = _root.CreatePage("Layouts", Good, 0, true);
				_fusion = _root.CreatePage("Fusion Multiplayer", Accent, 0, true);
				_settings = _root.CreatePage("Settings & Resets", Soft, 0, true);
				BuildEditor();
				BuildExtras();
				BuildLoadouts();
				BuildFit();
				BuildPreview();
				BuildLayouts();
				BuildFusion();
				BuildSettings();
				LayoutManager.LayoutSwitched += delegate
				{
					RefreshAll();
					RebuildLoadList();
					RebuildChooseList();
				};
				LayoutManager.LibraryChanged += delegate
				{
					RebuildLoadList();
					RefreshLayoutLabels();
				};
				RebuildLoadList();
				RefreshAll();
			}
		}

		private static void BuildEditor()
		{
			//IL_000a: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0429: Unknown result type (might be due to invalid IL or missing references)
			//IL_0480: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_055a: Unknown result type (might be due to invalid IL or missing references)
			//IL_058e: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0505: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_062f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0663: Unknown result type (might be due to invalid IL or missing references)
			_selected = _editor.CreateFunction("Holster: (load a level)", Gold, (Action)delegate
			{
				SelectOffset(1);
			});
			((Element)_selected).ElementTooltip = "Press to cycle to the next holster.";
			_editor.CreateFunction("< Previous Holster", Soft, (Action)delegate
			{
				SelectOffset(-1);
			});
			_editor.CreateFunction("Next Holster >", Soft, (Action)delegate
			{
				SelectOffset(1);
			});
			_choose = _editor.CreatePage("Choose Holster...", Soft, 0, true);
			_rename = _editor.CreatePage("Rename This Holster...", Gold, 0, true);
			BuildRename();
			_state = _editor.CreateFunction("Now At: -", Muted, (Action)delegate
			{
			});
			((Element)_state).ElementTooltip = "Where this holster is right now. Normal Spot = where BONELAB puts it.";
			_anchors = _editor.CreatePage("Attach To (body part)", Accent, 0, false);
			foreach (BodyAnchor value in Enum.GetValues(typeof(BodyAnchor)))
			{
				BodyAnchor a = value;
				_anchors.CreateFunction(BodyAnchorUtil.Pretty(a), Soft, (Action)delegate
				{
					HolsterSlot selected = Selected;
					if (selected != null)
					{
						HolsterApplier.Reanchor(selected, a);
						RefreshEditor();
						Menu.OpenPage(_editor);
					}
				});
			}
			_anchorButton = _editor.CreateFunction("Attach To: -", Accent, (Action)delegate
			{
				Menu.OpenPage(_anchors);
			});
			((Element)_anchorButton).ElementTooltip = "Choose which body part this holster follows. The holster stays where it is; only its anchor changes.";
			_stepButton = _editor.CreateFunction("", Soft, (Action)CycleStep);
			((Element)_stepButton).ElementTooltip = "How far each +/- press moves or rotates the holster.";
			_px = _editor.CreateFloat("Left / Right (cm)", PosColor, 0f, 1f, -150f, 150f, (Action<float>)delegate(float v)
			{
				SetPosition(0, v);
			});
			_py = _editor.CreateFloat("Down / Up (cm)", PosColor, 0f, 1f, -150f, 150f, (Action<float>)delegate(float v)
			{
				SetPosition(1, v);
			});
			_pz = _editor.CreateFloat("Back / Forward (cm)", PosColor, 0f, 1f, -150f, 150f, (Action<float>)delegate(float v)
			{
				SetPosition(2, v);
			});
			_rx = _editor.CreateFloat("Pitch (deg)", RotColor, 0f, 5f, -180f, 180f, (Action<float>)delegate(float v)
			{
				SetRotation(0, v);
			});
			_ry = _editor.CreateFloat("Yaw (deg)", RotColor, 0f, 5f, -180f, 180f, (Action<float>)delegate(float v)
			{
				SetRotation(1, v);
			});
			_rz = _editor.CreateFloat("Roll (deg)", RotColor, 0f, 5f, -180f, 180f, (Action<float>)delegate(float v)
			{
				SetRotation(2, v);
			});
			((Element)_px).ElementTooltip = "Offsets are relative to the chosen body part, measured on your current avatar (scaled to 1.76 m).";
			_grab = _editor.CreateFloat("Grab Radius (x)", Good, 1f, 0.1f, 0.1f, 5f, (Action<float>)SetGrabRadius);
			((Element)_grab).ElementTooltip = "How close your hand/item must be to use this holster. 1 = vanilla.";
			_quick = _editor.CreatePage("Quick Place...", Gold, 0, true);
			foreach (string item in Presets.Groups())
			{
				Page val = _quick.CreatePage(item, Soft, 0, true);
				foreach (HolsterPreset item2 in Presets.All)
				{
					if (item2.Group != item)
					{
						continue;
					}
					HolsterPreset p = item2;
					val.CreateFunction(p.Name, Soft, (Action)delegate
					{
						HolsterSlot selected = Selected;
						if (selected != null)
						{
							Presets.Apply(selected, p);
							RefreshEditor();
							Notify(selected.Name + " -> " + p.Name, warning: false);
						}
					});
				}
			}
			_editor.CreateFunction("Place At Left Hand (3s)", Accent, (Action)delegate
			{
				StartHandPlacement(left: true);
			});
			_editor.CreateFunction("Place At Right Hand (3s)", Accent, (Action)delegate
			{
				StartHandPlacement(left: false);
			});
			_editor.CreateFunction("Mirror To Opposite Side", Accent, (Action)delegate
			{
				HolsterSlot selected = Selected;
				if (selected != null)
				{
					HolsterSlot holsterSlot = Mirroring.MirrorToOpposite(selected);
					RefreshEditor();
					Notify((holsterSlot == selected) ? ("Mirrored " + selected.Name + " in place") : ("Mirrored onto " + holsterSlot.Name), warning: false);
				}
			});
			((Element)_editor.CreateFunction("Duplicate As New Holster", Good, (Action)DuplicateSelected)).ElementTooltip = "Adds a new holster right next to this one. Use Mirror To Opposite Side on it for a matching pair.";
			_editor.CreateFunction("Toggle 3D Preview", Accent, (Action)delegate
			{
				SetPreview(!AvatarPreview.IsVisible);
			});
			_editor.CreateFunction("Reset This Holster", Danger, (Action)delegate
			{
				HolsterSlot selected = Selected;
				if (selected != null)
				{
					HolsterApplier.ResetSlot(selected, resetGrabRadius: true);
					RefreshEditor();
					Notify(selected.Name + (selected.IsExtra ? " moved back to its default spot" : " reset to vanilla"), warning: false);
				}
			});
			ApplyStep();
		}

		private static void BuildRename()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: 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)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			_renameLabel = _rename.CreateFunction("Renaming: -", Gold, (Action)delegate
			{
			});
			((Element)_rename.CreateString("Type A Name", Soft, "", (Action<string>)delegate(string v)
			{
				_pendingHolsterName = v ?? "";
			})).ElementTooltip = "Type a name, then press Apply Typed Name. Max " + 28 + " characters.";
			_rename.CreateFunction("Apply Typed Name", Good, (Action)delegate
			{
				if (string.IsNullOrWhiteSpace(_pendingHolsterName))
				{
					Notify("Type a name first", warning: true);
				}
				else
				{
					RenameSelected(_pendingHolsterName);
				}
			});
			Page val = _rename.CreatePage("Quick Names...", Soft, 0, true);
			string[] quickNames = HolsterNames.QuickNames;
			foreach (string text in quickNames)
			{
				string n = text;
				val.CreateFunction(n, Soft, (Action)delegate
				{
					RenameSelected(n);
					Menu.OpenPage(_rename);
				});
			}
			((Element)_rename.CreateFunction("Use Automatic Name", Soft, (Action)delegate
			{
				RenameSelected("");
			})).ElementTooltip = "Removes the custom name. Vanilla holsters go back to their location name.";
			_rename.CreateFunction("< Back To Editor", Muted, (Action)delegate
			{
				Menu.OpenPage(_editor);
			});
		}

		private static void BuildExtras()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: 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_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			_extrasLabel = _extras.CreateFunction("Added: 0", Muted, (Action)delegate
			{
				RefreshExtras();
			});
			((Element)_extras.CreateFunction("Add Pistol Holster", Good, (Action)delegate
			{
				AddExtra("Sidearm", null);
			})).ElementTooltip = "A new pistol holster with the hip holster model. It appears at your front belt; move it in the Holster Editor.";
			((Element)_extras.CreateFunction("Add Any-Gun Holster", Good, (Action)delegate
			{
				AddExtra("LongGun", null);
			})).ElementTooltip = "Takes rifles, shotguns and pistols, like the back slots. It appears on your back; move it in the Holster Editor.";
			((Element)_extras.CreateFunction("Duplicate Selected Holster", Accent, (Action)DuplicateSelected)).ElementTooltip = "Adds a new holster of the same type next to the one selected in the Holster Editor.";
			_extras.CreateFunction("Edit Selected In Holster Editor", Soft, (Action)delegate
			{
				Menu.OpenPage(_editor);
			});
			_extras.CreateFunction("Remove Selected Added Holster", Danger, (Action)delegate
			{
				HolsterSlot s = Selected;
				if (s == null || !s.IsExtra)
				{
					Notify("Select an added holster (+) in the Holster Editor first", warning: true);
				}
				else
				{
					string name = s.Name;
					Confirm("Remove holster?", "Remove '" + name + "'? Whatever it holds is dropped.", delegate
					{
						ExtraHolsters.Remove(s);
						Notify("Removed '" + name + "'", warning: false);
						OnHolstersChanged();
					});
				}
			});
			_extras.CreateFunction("Remove All Added Holsters", Danger, (Action)delegate
			{
				Confirm("Remove all added holsters?", "Removes every holster you added to '" + LayoutManager.Current.Name + "'. Items in them are dropped.", delegate
				{
					Notify("Removed " + ExtraHolsters.RemoveAll() + " added holster(s)", warning: false);
					OnHolstersChanged();
				});
			});
			_extrasFusionA = _extras.CreateBool("Work In Fusion Lobbies", Soft, Settings.ExtrasInFusion.Value, (Action<bool>)SetExtrasInFusion);
			((Element)_extrasFusionA).ElementTooltip = "Keep added holsters in Fusion lobbies. Everyone, with or without the mod, sees what's in them.";
			((Element)_extras.CreateFunction("Added holsters are saved per layout", Muted, (Action)delegate
			{
			})).ElementTooltip = "Each layout has its own added holsters. They are copies of your avatar's real holsters, so they look and work the same.";
		}

		private static void BuildLoadouts()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			((Element)_loadouts.CreateFunction("Each one makes a NEW layout", Muted, (Action)delegate
			{
			})).ElementTooltip = "Your current layout is kept. Switch back any time from Layouts > Load Layout.";
			foreach (Loadout item in Loadouts.All)
			{
				Loadout l = item;
				string text = ((l.AddedCount > 0) ? (" (+" + l.AddedCount + ")") : "");
				((Element)_loadouts.CreateFunction(l.Name + text, Soft, (Action)delegate
				{
					Confirm(l.Name, l.Description + " Creates a new layout; your current one is kept.", delegate
					{
						ApplyLoadout(l);
					});
				})).ElementTooltip = l.Description;
			}
		}

		private static void ApplyLoadout(Loadout loadout)
		{
			int done;
			int missed;
			string error;
			string text = Loadouts.Apply(loadout, out done, out missed, out error);
			if (text == null)
			{
				Notify(error ?? "Couldn't apply that loadout", warning: true, 4f);
				return;
			}
			OnHolstersChanged();
			RebuildLoadList();
			if (missed > 0)
			{
				Notify("Loaded '" + text + "' (" + missed + " part(s) skipped" + ((error != null) ? (": " + error) : "") + ")", warning: true, 5f);
			}
			else
			{
				Notify("Loaded '" + text + "'. Fine-tune it in the Holster Editor.", warning: false, 4f);
			}
		}

		private static void BuildFit()
		{
			//IL_000a: 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_0099: 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_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			_fitLabel = _fit.CreateFunction("Body: -", Muted, (Action)delegate
			{
				RefreshFit();
			});
			((Element)_fitLabel).ElementTooltip = "What the mod measured on your current avatar.";
			_fitToggle = _fit.CreateBool("Fit To Avatar Shape", Good, true, (Action<bool>)delegate(bool v)
			{
				LayoutManager.Current.FitToBody = v;
				HolsterApplier.NotifyAllEdited();
				RefreshEditor();
				RefreshFit();
			});
			((Element)_fitToggle).ElementTooltip = "When you change avatars, moved and added holsters keep the same distance from the body surface, so they don't sink into wide avatars or float off thin ones. Saved per layout.";
			_scaleWithAvatar = _fit.CreateBool("Scale With Avatar Height", Soft, true, (Action<bool>)delegate(bool v)
			{
				LayoutManager.Current.ScaleWithAvatar = v;
				HolsterApplier.NotifyAllEdited();
				RefreshEditor();
				RefreshFit();
			});
			((Element)_scaleWithAvatar).ElementTooltip = "On: one layout fits tall and short avatars. Off: offsets are exact meters (also turns off shape fitting). Saved per layout.";
			((Element)_fit.CreateFunction("Use This Avatar As Reference", Accent, (Action)delegate
			{
				if (!BodyFit.FitActive)
				{
					Notify("Turn on Fit To Avatar Shape first", warning: true);
				}
				else
				{
					int num = HolsterApplier.RebaseAll();
					RefreshEditor();
					Notify(num + " holster(s) now measured from this avatar", warning: false);
				}
			})).ElementTooltip = "Nothing moves now. Other avatars will be fitted starting from this avatar's body. Use it after fine-tuning a layout here.";
			_fit.CreateBool("Popup When Switching Avatars", Soft, Settings.NotifyAvatarFit.Value, (Action<bool>)delegate(bool v)
			{
				Settings.NotifyAvatarFit.Value = v;
				Settings.Save();
			});
			((Element)_fit.CreateFunction("Recalibrate (stand straight, 3s)", Soft, (Action)StartRecalibrate)).ElementTooltip = "Re-measures your avatar's body. Use if limb holsters look twisted or the fit looks off.";
		}

		private static void BuildFusion()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			_fusionLabel = _fusion.CreateFunction("Fusion: -", Muted, (Action)delegate
			{
				RefreshStatus();
			});
			_shareToggle = _fusion.CreateBool("Everyone Sees My Holsters", Good, Settings.ShareWithEveryone.Value, (Action<bool>)delegate(bool v)
			{
				Settings.ShareWithEveryone.Value = v;
				Settings.Save();
				HolsterApplier.OnLayoutReplaced();
				RefreshStatus();
			});
			((Element)_shareToggle).ElementTooltip = "Players WITHOUT Custom Holsters see the items in your moved holsters where you actually put them. Off: they see them at the vanilla spots.";
			_extrasFusionB = _fusion.CreateBool("Added Holsters In Lobbies", Soft, Settings.ExtrasInFusion.Value, (Action<bool>)SetExtrasInFusion);
			((Element)_extrasFusionB).ElementTooltip = "Keep added holsters in Fusion lobbies. Everyone sees what's in them.";
			_liveLabel = _fusion.CreateFunction("Sharing: -", Muted, (Action)delegate
			{
				RefreshStatus();
			});
			((Element)_liveLabel).ElementTooltip = "How many holstered items your game is currently streaming to the lobby.";
			_fusion.CreateFunction("How Does This Work?", Muted, (Action)delegate
			{
				Notify("Items in moved or added holsters are streamed like an item in your hand, so other players see them where your holster really is. They don't need the mod.", warning: false, 8f);
			});
		}

		private static void BuildPreview()
		{
			//IL_000a: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: 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_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: 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_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: Unknown result type (might be due to invalid IL or missing references)
			_previewToggle = _preview.CreateBool("Show Preview", Good, false, (Action<bool>)delegate(bool v)
			{
				SetPreview(v);
			});
			((Element)_previewToggle).ElementTooltip = "Shows a small figure of your current avatar in front of you with every holster marked.";
			_preview.CreateFunction("Rotate Left 15", Soft, (Action)delegate
			{
				AvatarPreview.Rotate(-15f);
			});
			_preview.CreateFunction("Rotate Right 15", Soft, (Action)delegate
			{
				AvatarPreview.Rotate(15f);
			});
			_preview.CreateFunction("Tilt Up", Soft, (Action)delegate
			{
				AvatarPreview.Tilt(-15f);
			});
			_preview.CreateFunction("Tilt Down", Soft, (Action)delegate
			{
				AvatarPreview.Tilt(15f);
			});
			_preview.CreateFunction("View Front", Soft, (Action)delegate
			{
				AvatarPreview.SetView(0f);
			});
			_preview.CreateFunction("View Back", Soft, (Action)delegate
			{
				AvatarPreview.SetView(180f);
			});
			_preview.CreateFunction("View Left Side", Soft, (Action)delegate
			{
				AvatarPreview.SetView(90f);
			});
			_preview.CreateFunction("View Right Side", Soft, (Action)delegate
			{
				AvatarPreview.SetView(-90f);
			});
			_preview.CreateBool("Auto Spin", Soft, false, (Action<bool>)delegate(bool v)
			{
				AvatarPreview.AutoSpin = v;
			});
			_preview.CreateFunction("Recenter In Front Of Me", Accent, (Action)delegate
			{
				AvatarPreview.Recenter();
			});
			((Element)_preview.CreateFunction("Refresh Pose", Accent, (Action)delegate
			{
				if (AvatarPreview.IsVisible)
				{
					AvatarPreview.Rebuild();
				}
			})).ElementTooltip = "Re-captures your avatar's current pose for the preview figure.";
			_previewSize = _preview.CreateFloat("Preview Size (m)", Soft, Settings.PreviewHeight.Value, 0.1f, 0.2f, 1.5f, (Action<float>)delegate(float v)
			{
				Settings.PreviewHeight.Value = v;
				Settings.Save();
				if (AvatarPreview.IsVisible)
				{
					AvatarPreview.Rebuild();
				}
			});
			_preview.CreateBool("Live Gizmo On Real Holster", Soft, Settings.ShowLiveGizmo.Value, (Action<bool>)delegate(bool v)
			{
				Settings.ShowLiveGizmo.Value = v;
				Settings.Save();
			});
			((Element)_preview.CreateFunction("Legend: Yellow=Editing Cyan=Moved", Muted, (Action)delegate
			{
			})).ElementTooltip = "Yellow = holster being edited, Cyan = moved, Green = added by you, White = vanilla, Orange = ammo pouch. Red/green/blue sticks = holster X/Y/Z.";
		}

		private static void BuildLayouts()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: 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_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: 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_0294: 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)
			_layoutLabel = _layouts.CreateFunction("Active: -", Gold, (Action)delegate
			{
			});
			_avatarLabel = _layouts.CreateFunction("Avatar: -", Muted, (Action)delegate
			{
			});
			((Element)_layouts.CreateString("Layout Name", Soft, _pendingName, (Action<string>)delegate(string v)
			{
				_pendingName = v;
			})).ElementTooltip = "Name used by Save As New and New Vanilla Layout.";
			_layouts.CreateFunction("Save", Good, (Action)delegate
			{
				LayoutManager.Save();
				Notify("Saved '" + LayoutManager.Current.Name + "'", warning: false);
			});
			_layouts.CreateFunction("Save As New (uses name)", Good, (Action)delegate
			{
				string text = LayoutManager.SaveAs(_pendingName);
				Notify("Saved as '" + text + "'", warning: false);
			});
			_layouts.CreateFunction("New Vanilla Layout (uses name)", Soft, (Action)delegate
			{
				string text = LayoutManager.CreateNew(_pendingName);
				Notify("Created '" + text + "'", warning: false);
			});
			_load = _layouts.CreatePage("Load Layout...", Accent, 0, true);
			_layouts.CreateFunction("Use As Default Layout", Soft, (Action)delegate
			{
				LayoutManager.SetCurrentAsDefault();
				RefreshLayoutLabels();
				Notify("'" + LayoutManager.Current.Name + "' is now the default", warning: false);
			});
			((Element)_layouts.CreateFunction("Bind Layout To This Avatar", Accent, (Action)delegate
			{
				if (string.IsNullOrEmpty(LayoutManager.CurrentAvatarBarcode))
				{
					Notify("No avatar detected yet", warning: true);
				}
				else
				{
					LayoutManager.BindCurrentAvatar();
					Notify("This avatar now uses '" + LayoutManager.Current.Name + "'", warning: false);
				}
			})).ElementTooltip = "Whenever you switch into this avatar, this layout loads automatically.";
			_layouts.CreateFunction("Unbind This Avatar", Soft, (Action)delegate
			{
				LayoutManager.UnbindCurrentAvatar();
				Notify("Avatar unbound (uses the default layout)", warning: false);
			});
			_layouts.CreateBool("Auto-Load Avatar Layouts", Soft, Settings.AutoLoadAvatarLayouts.Value, (Action<bool>)delegate(bool v)
			{
				Settings.AutoLoadAvatarLayouts.Value = v;
				Settings.Save();
			});
			_layouts.CreateBool("Auto-Save Edits", Soft, Settings.AutoSave.Value, (Action<bool>)delegate(bool v)
			{
				Settings.AutoSave.Value = v;
				Settings.Save();
			});
			_layouts.CreateFunction("Delete This Layout", Danger, (Action)delegate
			{
				string current = LayoutManager.Current.Name;
				Menu.DisplayDialog("Delete layout?", "Delete '" + current + "'? This can't be undone.", (Texture2D)null, (Action)delegate
				{
					LayoutManager.DeleteCurrent();
					Notify("Deleted '" + current + "'", warning: false);
				}, (Action)null);
			});
			_layouts.CreateFunction("Open Layouts Folder (desktop)", Muted, (Action)delegate
			{
				try
				{
					Application.OpenURL("file:///" + LayoutManager.LayoutDir.Replace('\\', '/'));
				}
				catch (Exception)
				{
					Notify(LayoutManager.LayoutDir, warning: false);
				}
			});
		}

		private static void BuildSettings()
		{
			//IL_000a: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: 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_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: 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_028f: 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)
			_globalGrab = _settings.CreateFloat("Global Grab Radius (x)", Good, 1f, 0.1f, 0.1f, 5f, (Action<float>)delegate(float v)
			{
				LayoutManager.Current.GlobalGrabRadius = v;
				HolsterApplier.MarkGrabDirty();
				LayoutManager.MarkEdited();
			});
			((Element)_globalGrab).ElementTooltip = "Multiplies every holster's grab radius. Saved per layout.";
			((Element)_settings.CreateBool("Re-seat Holstered Items", Soft, Settings.ReseatHolsteredItems.Value, (Action<bool>)delegate(bool v)
			{
				Settings.ReseatHolsteredItems.Value = v;
				Settings.Save();
			})).ElementTooltip = "After moving a holster, snap the item it holds to the new spot (offline). In Fusion lobbies the mod handles this itself.";
			_settings.CreateBool("Hand Placement Copies Rotation", Soft, Settings.CopyHandRotation.Value, (Action<bool>)delegate(bool v)
			{
				Settings.CopyHandRotation.Value = v;
				Settings.Save();
			});
			_settings.CreateFunction("Copy Left Side -> Right", Accent, (Action)delegate
			{
				int num = Mirroring.CopySide(-1);
				RefreshEditor();
				Notify("Mirrored " + num + " holster(s) to the right", warning: false);
			});
			_settings.CreateFunction("Copy Right Side -> Left", Accent, (Action)delegate
			{
				int num = Mirroring.CopySide(1);
				RefreshEditor();
				Notify("Mirrored " + num + " holster(s) to the left", warning: false);
			});
			_settings.CreateFunction("Flip Whole Layout (L <-> R)", Accent, (Action)delegate
			{
				Mirroring.FlipWholeLayout();
				RefreshEditor();
				Notify("Layout flipped", warning: false);
			});
			_settings.CreateFunction("Reset All Positions", Danger, (Action)delegate
			{
				Confirm("Reset all positions?", "Every holster goes back to its vanilla spot (added holsters to their default spot). Names and grab radius are kept.", delegate
				{
					foreach (HolsterSlot slot in HolsterRegistry.Slots)
					{
						HolsterApplier.ResetSlot(slot, resetGrabRadius: false);
					}
					RefreshEditor();
					Notify("All holsters reset", warning: false);
				});
			});
			_settings.CreateFunction("Reset All Grab Radii", Danger, (Action)delegate
			{
				LayoutManager.Current.GlobalGrabRadius = 1f;
				foreach (HolsterPlacement value in LayoutManager.Current.Holsters.Values)
				{
					if (value != null)
					{
						value.GrabRadius = 1f;
					}
				}
				HolsterApplier.NotifyAllEdited();
				RefreshAll();
				Notify("Grab radii reset", warning: false);
			});
			_settings.CreateFunction("Reset All Names", Danger, (Action)delegate
			{
				Confirm("Reset all names?", "Every holster goes back to its automatic name.", delegate
				{
					foreach (HolsterSlot slot2 in HolsterRegistry.Slots)
					{
						HolsterNames.Set(slot2, "");
					}
					OnHolstersChanged();
					Notify("Names reset", warning: false);
				});
			});
			_settings.CreateFunction("Reset Layout To Vanilla", Danger, (Action)delegate
			{
				Confirm("Reset whole layout?", "Clears every position, name, grab radius and added holster in '" + LayoutManager.Current.Name + "'.", delegate
				{
					LayoutManager.Current.Holsters.Clear();
					LayoutManager.Current.Extras.Clear();
					LayoutManager.Current.GlobalGrabRadius = 1f;
					ExtraHolsters.Sync();
					HolsterApplier.NotifyAllEdited();
					OnHolstersChanged();
					Notify("Layout reset to vanilla", warning: false);
				});
			});
			((Element)_settings.CreateFunction("Recalibrate (stand straight, 3s)", Soft, (Action)StartRecalibrate)).ElementTooltip = "Re-measures your avatar's body parts. Use if limb holsters look twisted.";
			_settings.CreateFunction("Rescan Holsters", Soft, (Action)delegate
			{
				HolsterRegistry.Clear(restore: true);
				if (Core.Instance != null)
				{
					Core.Instance.ScheduleSetup(avatarChanged: false);
				}
			});
			_settings.CreateFunction("Custom Holsters v1.2.0", Muted, (Action)delegate
			{
			});
		}

		private static void SetExtrasInFusion(bool v)
		{
			Settings.ExtrasInFusion.Value = v;
			Settings.Save();
			if (_extrasFusionA != null && _extrasFusionA.Value != v)
			{
				_extrasFusionA.Value = v;
			}
			if (_extrasFusionB != null && _extrasFusionB.Value != v)
			{
				_extrasFusionB.Value = v;
			}
			ExtraHolsters.Sync();
			RefreshExtras();
		}

		private static void StartRecalibrate()
		{
			StartCountdown("Stand straight, arms relaxed", delegate
			{
				if (Core.Instance != null)
				{
					Core.Instance.ScheduleSetup(avatarChanged: false);
				}
				Notify("Recalibrated", warning: false);
			});
		}

		private static void AddExtra(string kind, HolsterSlot copyFrom)
		{
			string error;
			HolsterSlot holsterSlot = ExtraHolsters.Add(kind, copyFrom, out error);
			if (holsterSlot == null)
			{
				Notify(error ?? "Couldn't add a holster", warning: true);
				return;
			}
			Select(holsterSlot);
			OnHolstersChanged();
			string text = HolsterNames.Location(holsterSlot);
			Notify("Added '" + holsterSlot.Name + "'" + (string.IsNullOrEmpty(text) ? "" : (" at " + text)) + ". Move or rename it here.", warning: false, 4f);
			Menu.OpenPage(_editor);
		}

		private static void DuplicateSelected()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			HolsterSlot selected = Selected;
			if (selected == null)
			{
				Notify("Select a holster in the Holster Editor first", warning: true);
			}
			else if (selected.IsAmmoPouch)
			{
				Notify("The ammo pouch can't be duplicated", warning: true);
			}
			else
			{
				AddExtra(selected.IsExtra ? selected.ExtraKind : (((selected.Accepts & 2) != 0) ? "LongGun" : "Sidearm"), selected);
			}
		}

		private static void RenameSelected(string name)
		{
			HolsterSlot selected = Selected;
			if (selected == null)
			{
				Notify("Load into a level first", warning: true);
				return;
			}
			string text = HolsterNames.Set(selected, name);
			if (text != null)
			{
				Notify(string.IsNullOrWhiteSpace(name) ? ("Using automatic name '" + text + "'") : ("Renamed to '" + text + "'"), warning: false);
				OnHolstersChanged();
			}
		}

		private static void SelectOffset(int delta)
		{
			_selectedIndex += delta;
			RefreshEditor();
		}

		private static void Select(HolsterSlot slot)
		{
			int num = HolsterRegistry.Slots.IndexOf(slot);
			if (num >= 0)
			{
				_selectedIndex = num;
			}
			RefreshEditor();
		}

		private static void SetPosition(int axis, float cm)
		{
			HolsterSlot selected = Selected;
			if (selected != null)
			{
				HolsterPlacement holsterPlacement = HolsterApplier.BeginEdit(selected);
				float num = cm / 100f;
				switch (axis)
				{
				case 0:
					holsterPlacement.Position.x = num;
					break;
				case 1:
					holsterPlacement.Position.y = num;
					break;
				default:
					holsterPlacement.Position.z = num;
					break;
				}
				HolsterApplier.NotifyEdited(selected);
				RefreshStateLabel(selected);
			}
		}

		private static void SetRotation(int axis, float degrees)
		{
			HolsterSlot selected = Selected;
			if (selected != null)
			{
				HolsterPlacement holsterPlacement = HolsterApplier.BeginEdit(selected);
				switch (axis)
				{
				case 0:
					holsterPlacement.Rotation.x = degrees;
					break;
				case 1:
					holsterPlacement.Rotation.y = degrees;
					break;
				default:
					holsterPlacement.Rotation.z = degrees;
					break;
				}
				HolsterApplier.NotifyEdited(selected);
				RefreshStateLabel(selected);
			}
		}

		private static void SetGrabRadius(float value)
		{
			HolsterSlot selected = Selected;
			if (selected != null)
			{
				LayoutManager.Current.GetOrCreate(selected.Id).GrabRadius = value;
				HolsterApplier.MarkGrabDirty();
				LayoutManager.MarkEdited();
			}
		}

		private static void CycleStep()
		{
			_step = (StepSize)((int)(_step + 1) % 3);
			ApplyStep();
		}

		private static void ApplyStep()
		{
			float incrementValue = ((_step == StepSize.Fine) ? 0.5f : ((_step == StepSize.Normal) ? 1f : 5f));
			float incrementValue2 = ((_step == StepSize.Fine) ? 1f : ((_step == StepSize.Normal) ? 5f : 15f));
			_px.IncrementValue = incrementValue;
			_py.IncrementValue = incrementValue;
			_pz.IncrementValue = incrementValue;
			_rx.IncrementValue = incrementValue2;
			_ry.IncrementValue = incrementValue2;
			_rz.IncrementValue = incrementValue2;
			((Element)_stepButton).ElementName = "Step: " + _step.ToString() + " (" + incrementValue + " cm / " + incrementValue2 + " deg)";
		}

		private static void StartHandPlacement(bool left)
		{
			HolsterSlot selected = Selected;
			if (selected == null)
			{
				return;
			}
			string id = selected.Id;
			StartCountdown("Hold your " + (left ? "left" : "right") + " hand where " + selected.Name + " should go", delegate
			{
				//IL_0057: 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)
				Hand val = (left ? Player.LeftHand : Player.RightHand);
				HolsterSlot holsterSlot = HolsterRegistry.Find(id);
				if (!((Object)(object)val == (Object)null) && holsterSlot != null)
				{
					Transform transform = ((Component)val).transform;
					Quaternion? worldRot = null;
					if (Settings.CopyHandRotation.Value)
					{
						worldRot = transform.rotation;
					}
					HolsterApplier.PlaceAt(holsterSlot, transform.position, worldRot);
					RefreshEditor();
					Notify(holsterSlot.Name + " placed", warning: false);
				}
			});
		}

		private static void StartCountdown(string message, Action action)
		{
			_countdownMessage = message;
			_countdownAction = action;
			_countdownEnd = Time.realtimeSinceStartup + 3f;
			_countdownShown = 4;
		}

		private static void Confirm(string title, string message, Action action)
		{
			Menu.DisplayDialog(title, message, (Texture2D)null, action, (Action)null);
		}

		private static void SetPreview(bool visible)
		{
			AvatarPreview.SetVisible(visible);
			if (_previewToggle != null)
			{
				_previewToggle.Value = AvatarPreview.IsVisible;
			}
			RefreshEditor();
		}

		public static void OnRigReady()
		{
			OnHolstersChanged();
		}

		public static void OnHolstersChanged()
		{
			if (_built)
			{
				RebuildChooseList();
				RefreshAll();
			}
		}

		private static void RebuildChooseList()
		{
			//IL_0059: 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)
			if (!_built)
			{
				return;
			}
			_choose.RemoveAll();
			foreach (HolsterSlot slot in HolsterRegistry.Slots)
			{
				HolsterSlot s = slot;
				if (s.IsValid)
				{
					_choose.CreateFunction(HolsterNames.ListLabel(s), HolsterNames.ListColor(s), (Action)delegate
					{
						Select(s);
						Menu.OpenPage(_editor);
					});
				}
			}
			_choose.CreateFunction("+ Add New Holster...", Good, (Action)delegate
			{
				Menu.OpenPage(_extras);
			});
		}

		private static void RefreshAll()
		{
			if (!_built)
			{
				return;
			}
			RefreshEditor();
			RefreshLayoutLabels();
			RefreshStatus();
			RefreshExtras();
			RefreshFit();
			HolsterLayout current = LayoutManager.Current;
			if (current != null)
			{
				if (_scaleWithAvatar != null && _scaleWithAvatar.Value != current.ScaleWithAvatar)
				{
					_scaleWithAvatar.Value = current.ScaleWithAvatar;
				}
				if (_fitToggle != null && _fitToggle.Value != current.FitToBody)
				{
					_fitToggle.Value = current.FitToBody;
				}
				if (_globalGrab != null)
				{
					_globalGrab.Value = current.GlobalGrabRadius;
				}
			}
		}

		private static void RefreshEditor()
		{
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: 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)
			if (!_built)
			{
				return;
			}
			HolsterSlot selected = Selected;
			AvatarPreview.SelectedId = selected?.Id;
			if (selected == null || LayoutManager.Current == null || !AnchorResolver.IsCalibrated)
			{
				((Element)_selected).ElementName = "Holster: (load a level)";
				((Element)_state).ElementName = "Now At: -";
				((Element)_anchorButton).ElementName = "Attach To: -";
				((Element)_renameLabel).ElementName = "Renaming: -";
				return;
			}
			string text = Trim(selected.Name, 26);
			((Element)_selected).ElementName = (selected.IsExtra ? "Holster: + " : "Holster: ") + text + "  (" + (_selectedIndex + 1) + "/" + HolsterRegistry.Slots.Count + ")";
			((Element)_selected).ElementColor = (selected.IsExtra ? Good : Gold);
			((Element)_renameLabel).ElementName = "Renaming: " + text;
			HolsterPlacement holsterPlacement = LayoutManager.Current.Get(selected.Id);
			HolsterPlacement holsterPlacement2;
			if (holsterPlacement == null || !holsterPlacement.Moved)
			{
				holsterPlacement2 = new HolsterPlacement();
				HolsterApplier.GetCurrentWorldPose(selected, out var position, out var rotation);
				HolsterApplier.CaptureFromWorld(holsterPlacement2, HolsterApplier.DefaultAnchorFor(selected), position, rotation);
				holsterPlacement2.GrabRadius = holsterPlacement?.GrabRadius ?? 1f;
			}
			else
			{
				holsterPlacement2 = HolsterApplier.ForDisplay(holsterPlacement);
			}
			((Element)_anchorButton).ElementName = "Attach To: " + BodyAnchorUtil.Pretty(holsterPlacement2.Anchor) + " >";
			_px.Value = Round(holsterPlacement2.Position.x * 100f);
			_py.Value = Round(holsterPlacement2.Position.y * 100f);
			_pz.Value = Round(holsterPlacement2.Position.z * 100f);
			_rx.Value = Round(holsterPlacement2.Rotation.x);
			_ry.Value = Round(holsterPlacement2.Rotation.y);
			_rz.Value = Round(holsterPlacement2.Rotation.z);
			_grab.Value = holsterPlacement2.GrabRadius;
			RefreshStateLabel(selected);
		}

		private static void RefreshStateLabel(HolsterSlot slot)
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			HolsterPlacement holsterPlacement = LayoutManager.Current.Get(slot.Id);
			bool flag = holsterPlacement?.Moved ?? false;
			string text = null;
			if (flag)
			{
				text = HolsterNames.Location(slot);
			}
			((Element)_state).ElementName = (flag ? ("Now At: " + (string.IsNullOrEmpty(text) ? "Custom Spot" : text)) : "Now At: Normal Spot");
			((Element)_state).ElementColor = (flag ? Accent : Muted);
			if (flag)
			{
				((Element)_anchorButton).ElementName = "Attach To: " + BodyAnchorUtil.Pretty(holsterPlacement.Anchor) + " >";
			}
		}

		private static void RefreshExtras()
		{
			//IL_0057: 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)
			if (_built)
			{
				string blockedReason = ExtraHolsters.BlockedReason;
				((Element)_extrasLabel).ElementName = "Added: " + ExtraHolsters.DefinedCount + ((blockedReason != null) ? (" (off: " + blockedReason + ")") : "");
				((Element)_extrasLabel).ElementColor = ((blockedReason != null) ? Danger : Muted);
			}
		}

		private static void RefreshFit()
		{
			if (_built)
			{
				HolsterLayout current = LayoutManager.Current;
				if (!BodyFit.HasMeasurement)
				{
					((Element)_fitLabel).ElementName = "Body: load into a level";
				}
				else if (current != null && !current.ScaleWithAvatar)
				{
					((Element)_fitLabel).ElementName = "Fit off (exact meters)";
				}
				else
				{
					((Element)_fitLabel).ElementName = Trim(BodyFit.Summary, 60);
				}
			}
		}

		private static void RefreshLayoutLabels()
		{
			if (_built && LayoutManager.Current != null)
			{
				string name = LayoutManager.Current.Name;
				bool flag = string.Equals(name, Settings.DefaultLayout.Value, StringComparison.OrdinalIgnoreCase);
				((Element)_layoutLabel).ElementName = "Active: " + name + (flag ? " (default)" : "");
				string currentAvatarBarcode = LayoutManager.CurrentAvatarBarcode;
				if (string.IsNullOrEmpty(currentAvatarBarcode))
				{
					((Element)_avatarLabel).ElementName = "Avatar: -";
					return;
				}
				string binding = LayoutManager.GetBinding(currentAvatarBarcode);
				string s = (string.IsNullOrEmpty(LayoutManager.CurrentAvatarTitle) ? currentAvatarBarcode : LayoutManager.CurrentAvatarTitle);
				((Element)_avatarLabel).ElementName = "Avatar: " + Trim(s, 22) + ((binding != null) ? (" -> " + binding) : " (unbound)");
			}
		}

		private static void RebuildLoadList()
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			if (!_built)
			{
				return;
			}
			_load.RemoveAll();
			foreach (string item in LayoutManager.ListLayouts())
			{
				string n = item;
				bool flag = LayoutManager.Current != null && string.Equals(n, LayoutManager.Current.Name, StringComparison.OrdinalIgnoreCase);
				_load.CreateFunction(n, flag ? Gold : Soft, (Action)delegate
				{
					if (LayoutManager.Load(n))
					{
						Notify("Loaded '" + n + "'", warning: false);
						RebuildLoadList();
					}
					else
					{
						Notify("Couldn't load '" + n + "'", warning: true);
					}
				});
			}
		}

		private static void RefreshStatus()
		{
			if (!_built)
			{
				return;
			}
			if (HolsterRegistry.Ready && LayoutManager.Current != null)
			{
				int num = 0;
				int num2 = 0;
				foreach (HolsterSlot slot in HolsterRegistry.Slots)
				{
					if (slot.IsExtra)
					{
						num2++;
						continue;
					}
					HolsterPlacement holsterPlacement = LayoutManager.Current.Get(slot.Id);
					if (holsterPlacement != null && holsterPlacement.Moved)
					{
						num++;
					}
				}
				((Element)_status).ElementName = "Status: " + num + " moved, " + num2 + " added | " + Trim(LayoutManager.Current.Name, 14);
			}
			else
			{
				((Element)_status).ElementName = "Status: waiting for a level";
			}
			((Element)_fusionLabel).ElementName = FusionCompat.Status;
			if (!FusionCompat.InLobby)
			{
				((Element)_liveLabel).ElementName = "Sharing: not in a lobby";
			}
			else if (!FusionShare.Patched)
			{
				((Element)_liveLabel).ElementName = "Sharing: unavailable (Fusion version)";
			}
			else
			{
				((Element)_liveLabel).ElementName = "Sharing: " + FusionShare.BroadcastCount + " holstered item(s) live";
			}
		}

		public static void Tick()
		{
			if (!_built)
			{
				return;
			}
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			if (_countdownEnd > 0f)
			{
				int num = Mathf.CeilToInt(_countdownEnd - realtimeSinceStartup);
				if (num < _countdownShown && num > 0)
				{
					_countdownShown = num;
					Notify(_countdownMessage + "... " + num, warning: false, 0.9f);
				}
				if (realtimeSinceStartup >= _countdownEnd)
				{
					_countdownEnd = -1f;
					Action countdownAction = _countdownAction;
					_countdownAction = null;
					try
					{
						countdownAction?.Invoke();
					}
					catch (Exception ex)
					{
						Core.Log.Error("Countdown action failed: " + ex);
					}
				}
			}
			if (realtimeSinceStartup >= _nextStatusRefresh)
			{
				_nextStatusRefresh = realtimeSinceStartup + 1.5f;
				RefreshStatus();
				RefreshExtras();
				if (_previewToggle.Value != AvatarPreview.IsVisible)
				{
					_previewToggle.Value = AvatarPreview.IsVisible;
				}
			}
		}

		public static void Notify(string message, bool warning, float seconds = 2.5f)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_002e: 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_0041: Expected O, but got Unknown
			try
			{
				Notifier.Send(new Notification
				{
					Title = NotificationText.op_Implicit("Custom Holsters"),
					Message = NotificationText.op_Implicit(message),
					Type = (NotificationType)(warning ? 1 : 0),
					PopupLength = seconds,
					ShowTitleOnPopup = true
				});
			}
			catch (Exception)
			{
				Core.Log.Msg(message);
			}
		}

		private static float Round(float v)
		{
			return Mathf.Round(v * 10f) / 10f;
		}

		private static string Trim(string s, int max)
		{
			if (string.IsNullOrEmpty(s) || s.Length <= max)
			{
				return s;
			}
			return s.Substring(0, max - 1) + "~";
		}

		private static void TrySetLogo(Page page)
		{
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			try
			{
				Assembly assembly = typeof(HolsterMenu).Assembly;
				string text = null;
				string[] manifestResourceNames = assembly.GetManifestResourceNames();
				foreach (string text2 in manifestResourceNames)
				{
					if (text2.EndsWith("icon.png", StringComparison.OrdinalIgnoreCase))
					{
						text = text2;
					}
				}
				if (text == null)
				{
					return;
				}
				byte[] array;
				using (Stream stream = assembly.GetManifestResourceStream(text))
				{
					using MemoryStream memoryStream = new MemoryStream();
					stream.CopyTo(memoryStream);
					array = memoryStream.ToArray();
				}
				Texture2D val = new Texture2D(2, 2);
				if (ImageConversion.LoadImage(val, Il2CppStructArray<byte>.op_Implicit(array)))
				{
					((Object)val).hideFlags = (HideFlags)32;
					((Object)val).name = "CustomHolsters_Icon";
					page.Logo = val;
				}
			}
			catch (Exception ex)
			{
				Core.Log.Warning("Couldn't load menu icon: " + ex.Message);
			}
		}
	}
}
namespace CustomHolsters.Layouts
{
	[Serializable]
	public class BodyShape
	{
		public float W;

		public float Df;

		public float Db;

		public float L;

		[JsonIgnore]
		public bool IsValid
		{
			get
			{
				if (Ok(W) && Ok(Df) && Ok(Db))
				{
					return Ok(L);
				}
				return false;
			}
		}

		public BodyShape()
		{
		}

		public BodyShape(float w, float df, float db, float l)
		{
			W = Round(w);
			Df = Round(df);
			Db = Round(db);
			L = Round(l);
		}

		public BodyShape Clone()
		{
			return new BodyShape(W, Df, Db, L);
		}

		public bool Same(BodyShape o)
		{
			if (o != null && Mathf.Abs(W - o.W) < 0.002f && Mathf.Abs(Df - o.Df) < 0.002f && Mathf.Abs(Db - o.Db) < 0.002f)
			{
				return Mathf.Abs(L - o.L) < 0.002f;
			}
			return false;
		}

		private static bool Ok(float v)
		{
			if (!float.IsNaN(v) && !float.IsInfinity(v))
			{
				return v > 0.001f;
			}
			return false;
		}

		private static float Round(float v)
		{
			return Mathf.Round(v * 10000f) / 10000f;
		}
	}
	[Serializable]
	public class ExtraHolster
	{
		public string Name = "Added Holster";

		public string Kind = "Sidearm";

		public ExtraHolster Clone()
		{
			return new ExtraHolster
			{
				Name = Name,
				Kind = Kind
			};
		}
	}
	public static class ExtraKinds
	{
		public const string Sidearm = "Sidearm";

		public const string LongGun = "LongGun";

		public static string Normalize(string kind)
		{
			if (string.IsNullOrEmpty(kind))
			{
				return "Sidearm";
			}
			switch (kind.Trim().ToLowerInvariant())
			{
			case "longgun":
			case "rifle":
			case "primary":
			case "universal":
			case "back":
			case "anygun":
				return "LongGun";
			default:
				return "Sidearm";
			}
		}

		public static string Pretty(string kind)
		{
			if (!(Normalize(kind) == "LongGun"))
			{
				return "Pistol";
			}
			return "Any-Gun";
		}

		public static string DefaultName(string kind)
		{
			if (!(Normalize(kind) == "LongGun"))
			{
				return "Pistol Holster";
			}
			return "Gun Holster";
		}
	}
	[Serializable]
	public class HolsterLayout
	{
		public const int CurrentFormat = 2;

		public int FormatVersion = 2;

		public string Name = "Default";

		public string ModVersion = "1.2.0";

		public bool ScaleWithAvatar = true;

		public bool FitToBody = true;

		public float GlobalGrabRadius = 1f;

		public Dictionary<string, HolsterPlacement> Holsters = new Dictionary<string, HolsterPlacement>();

		public Dictionary<string, ExtraHolster> Extras = new Dictionary<string, ExtraHolster>();

		public HolsterPlacement Get(string id)
		{
			if (id == null || !Holsters.TryGetValue(id, out var value))
			{
				return null;
			}
			return value;
		}

		public HolsterPlacement GetOrCreate(string id)
		{
			if (!Holsters.TryGetValue(id, out var value) || value == null)
			{
				value = new HolsterPlacement();
				Holsters[id] = value;
			}
			return value;
		}

		public string NextExtraId()
		{
			for (int i = 1; i < int.MaxValue; i++)
			{
				string text = "Added" + i;
				if (!Extras.ContainsKey(text) && !Holsters.ContainsKey(text))
				{
					return text;
				}
			}
			return "Added" + DateTime.Now.Ticks;
		}

		public HolsterLayout Clone(string newName)
		{
			HolsterLayout holsterLayout = new HolsterLayout
			{
				Name = newName,
				ScaleWithAvatar = ScaleWithAvatar,
				FitToBody = FitToBody,
				GlobalGrabRadius = GlobalGrabRadius
			};
			foreach (KeyValuePair<string, HolsterPlacement> holster in Holsters)
			{
				if (holster.Value != null)
				{
					holsterLayout.Holsters[holster.Key] = holster.Value.Clone();
				}
			}
			foreach (KeyValuePair<string, ExtraHolster> extra in Extras)
			{
				if (extra.Value != null)
				{
					holsterLayout.Extras[extra.Key] = extra.Value.Clone();
				}
			}
			return holsterLayout;
		}

		public void Prune()
		{
			List<string> list = new List<string>();
			foreach (KeyValuePair<string, HolsterPlacement> holster in Holsters)
			{
				if (holster.Value == null || (holster.Value.IsDefault && !Extras.ContainsKey(holster.Key)))
				{
					list.Add(holster.Key);
				}
			}
			foreach (string item in list)
			{
				Holsters.Remove(item);
			}
		}

		public void Sanitize()
		{
			if (Holsters == null)
			{
				Holsters = new Dictionary<string, HolsterPlacement>();
			}
			if (Extras == null)
			{
				Extras = new Dictionary<string, ExtraHolster>();
			}
			if (float.IsNaN(GlobalGrabRadius) || GlobalGrabRadius <= 0f)
			{
				GlobalGrabRadius = 1f;
			}
			GlobalGrabRadius = Mathf.Clamp(GlobalGrabRadius, 0.1f, 5f);
			foreach (HolsterPlacement value in Holsters.Values)
			{
				if (value == null)
				{
					continue;
				}
				if (value.Position == null)
				{
					value.Position = new Vec3();
				}
				if (value.Rotation == null)
				{
					value.Rota