Decompiled source of GearManners v0.9.0

plugins/GearManners.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.UI;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace GearManners
{
	internal static class AutoHolster
	{
		private enum Reason
		{
			None,
			Bed,
			Crafting,
			Chair,
			Ground,
			Steering,
			Riding,
			Emote
		}

		private sealed class Hands
		{
			public ItemData Right;

			public ItemData Left;

			public float Since;
		}

		private sealed class NpcState
		{
			public bool WasSitting;

			public bool WeHid;

			public float NextTry;
		}

		private static Reason _current;

		private static bool _handsWereFull;

		private static bool _restoreOnEnd;

		private static MethodInfo _showHandItems;

		private static FieldRef<Humanoid, ItemData> _hiddenRight;

		private static FieldRef<Humanoid, ItemData> _hiddenLeft;

		private static FieldRef<Humanoid, float> _sinceSwing;

		private static readonly Dictionary<Humanoid, Hands> _hands = new Dictionary<Humanoid, Hands>();

		private static readonly Dictionary<Humanoid, NpcState> _npcs = new Dictionary<Humanoid, NpcState>();

		private static readonly List<Humanoid> _gone = new List<Humanoid>();

		public static void Init()
		{
			_showHandItems = AccessTools.Method(typeof(Humanoid), "ShowHandItems", (Type[])null, (Type[])null);
			_hiddenRight = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_hiddenRightItem");
			_hiddenLeft = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_hiddenLeftItem");
			_sinceSwing = AccessTools.FieldRefAccess<Humanoid, float>("m_lastCombatTimer");
		}

		private static bool Sheathable(Humanoid h, out bool rightOnly)
		{
			ItemData val = Game.RightItem.Invoke(h);
			ItemData val2 = Game.LeftItem.Invoke(h);
			rightOnly = false;
			Kind kind = ((val != null) ? Slots.KindOf(val.m_shared) : Kind.None);
			Kind kind2 = ((val2 != null) ? Slots.KindOf(val2.m_shared) : Kind.None);
			bool flag = val != null && kind != Kind.Tool && kind != Kind.None;
			bool flag2 = val2 != null && kind2 != Kind.Tool && kind2 != Kind.None;
			if (val != null && !flag)
			{
				return false;
			}
			if (!flag && !flag2)
			{
				return false;
			}
			rightOnly = val2 != null && !flag2;
			return true;
		}

		private static void TickCalm(Humanoid h, float now)
		{
			if (!_hands.TryGetValue(h, out var value))
			{
				Dictionary<Humanoid, Hands> hands = _hands;
				Hands obj = new Hands
				{
					Since = now
				};
				value = obj;
				hands[h] = obj;
			}
			ItemData val = Game.RightItem.Invoke(h);
			ItemData val2 = Game.LeftItem.Invoke(h);
			if (val != value.Right || val2 != value.Left)
			{
				value.Right = val;
				value.Left = val2;
				value.Since = now;
			}
			else if (Settings.SheatheCalm.Value && (val != null || val2 != null))
			{
				float value2 = Settings.SheatheCalmSeconds.Value;
				if (!(now - value.Since < value2) && !((Character)h).InAttack() && !((Character)h).IsBlocking() && !(_sinceSwing.Invoke(h) < value2) && !LocalHolster.Fighting(h, value2) && Sheathable(h, out var rightOnly))
				{
					h.HideHandItems(rightOnly, true);
					value.Since = now;
				}
			}
		}

		private static void CompanionsFollow(Player p)
		{
			//IL_0074: 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)
			foreach (HolsterVisual item in HolsterVisual.All)
			{
				Humanoid val = (((Object)(object)item != (Object)null) ? item.Humanoid : null);
				if (!((Object)(object)val == (Object)null) && !(val is Player) && !((Character)val).IsDead() && !((Object)(object)item.NView == (Object)null) && item.NView.IsValid() && item.NView.IsOwner() && !(Vector3.Distance(((Component)val).transform.position, ((Component)p).transform.position) > 30f) && !((Character)val).InAttack() && !LocalHolster.Fighting(val, 5f) && Sheathable(val, out var rightOnly))
				{
					val.HideHandItems(rightOnly, true);
				}
			}
		}

		private static bool PressedSheathe()
		{
			if (InventoryGui.IsVisible() || Marking.TypingSomewhere())
			{
				return false;
			}
			if (!ZInput.GetButtonDown("Hide"))
			{
				return ZInput.GetButtonDown("JoyHide");
			}
			return true;
		}

		public static void Tick()
		{
			TickLocal();
			TickCompanions();
		}

		private static void TickCompanions()
		{
			float time = Time.time;
			foreach (HolsterVisual item in HolsterVisual.All)
			{
				Humanoid val = (((Object)(object)item != (Object)null) ? item.Humanoid : null);
				if ((Object)(object)val == (Object)null || val is Player || (Object)(object)item.NView == (Object)null || !item.NView.IsValid() || !item.NView.IsOwner())
				{
					continue;
				}
				if (!_npcs.TryGetValue(val, out var value))
				{
					value = (_npcs[val] = new NpcState());
				}
				int num;
				int num2;
				if (Settings.Enabled.Value && !((Character)val).IsDead())
				{
					num = (Game.Sleeping(val) ? 1 : 0);
					if (num != 0)
					{
						num2 = 1;
						goto IL_00da;
					}
				}
				else
				{
					num = 0;
				}
				num2 = ((Settings.Enabled.Value && !((Character)val).IsDead() && ((Character)val).IsSitting()) ? 1 : 0);
				goto IL_00da;
				IL_00da:
				bool flag = (byte)num2 != 0;
				bool flag2 = num != 0 || Settings.PutAwayGround.Value || Settings.PutAwayChair.Value;
				bool flag3 = Game.RightItem.Invoke(val) != null || Game.LeftItem.Invoke(val) != null;
				if (flag && flag2 && flag3 && !((Character)val).InAttack() && time >= value.NextTry)
				{
					val.HideHandItems(false, false);
					value.WeHid = true;
					value.NextTry = time + 1f;
				}
				else if (!flag && value.WasSitting)
				{
					if (value.WeHid && Settings.DrawAfter.Value && !flag3 && HasHidden(val) && !((Character)val).IsSwimming())
					{
						Show(val);
					}
					value.WeHid = false;
				}
				value.WasSitting = flag;
				if (!flag && Settings.Enabled.Value && !((Character)val).IsDead())
				{
					TickCalm(val, time);
				}
			}
			_gone.Clear();
			foreach (KeyValuePair<Humanoid, NpcState> npc in _npcs)
			{
				if ((Object)(object)npc.Key == (Object)null)
				{
					_gone.Add(npc.Key);
				}
			}
			foreach (Humanoid item2 in _gone)
			{
				_npcs.Remove(item2);
			}
			_gone.Clear();
			foreach (KeyValuePair<Humanoid, Hands> hand in _hands)
			{
				if ((Object)(object)hand.Key == (Object)null)
				{
					_gone.Add(hand.Key);
				}
			}
			foreach (Humanoid item3 in _gone)
			{
				_hands.Remove(item3);
			}
		}

		private static void TickLocal()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || !Settings.Enabled.Value || ((Character)localPlayer).IsDead())
			{
				_current = Reason.None;
				_restoreOnEnd = false;
				return;
			}
			bool flag = Game.RightItem.Invoke((Humanoid)(object)localPlayer) != null || Game.LeftItem.Invoke((Humanoid)(object)localPlayer) != null;
			Reason reason = CurrentReason(localPlayer);
			if (reason != Reason.None && reason != _current)
			{
				if (_current == Reason.None)
				{
					_restoreOnEnd = false;
				}
				_restoreOnEnd |= _handsWereFull;
				if (flag && Wanted(reason) && !((Character)localPlayer).InAttack())
				{
					bool flag2 = reason != Reason.Ground && reason != Reason.Emote;
					((Humanoid)localPlayer).HideHandItems(false, flag2);
				}
			}
			else if (reason == Reason.None && _current != Reason.None)
			{
				if (_restoreOnEnd && Settings.DrawAfter.Value && !flag && HasHidden((Humanoid)(object)localPlayer) && !((Character)localPlayer).IsSwimming())
				{
					Show((Humanoid)(object)localPlayer);
				}
				_restoreOnEnd = false;
			}
			if (Settings.CompanionsFollow.Value && _handsWereFull && PressedSheathe())
			{
				CompanionsFollow(localPlayer);
			}
			if (reason == Reason.None)
			{
				TickCalm((Humanoid)(object)localPlayer, Time.time);
			}
			_current = reason;
			_handsWereFull = Game.RightItem.Invoke((Humanoid)(object)localPlayer) != null || Game.LeftItem.Invoke((Humanoid)(object)localPlayer) != null;
		}

		private static Reason CurrentReason(Player p)
		{
			if (((Character)p).InBed())
			{
				return Reason.Bed;
			}
			if ((Object)(object)p.GetCurrentCraftingStation() != (Object)null)
			{
				return Reason.Crafting;
			}
			if (((Character)p).IsAttached())
			{
				IDoodadController doodadController = p.GetDoodadController();
				if (doodadController is ShipControlls)
				{
					return Reason.Steering;
				}
				if (doodadController is Sadle)
				{
					return Reason.Riding;
				}
				if (doodadController != null)
				{
					return Reason.Riding;
				}
				return Reason.Chair;
			}
			if (((Character)p).IsSitting())
			{
				return Reason.Ground;
			}
			if (((Character)p).InEmote())
			{
				return Reason.Emote;
			}
			return Reason.None;
		}

		private static bool Wanted(Reason r)
		{
			return r switch
			{
				Reason.Chair => Settings.PutAwayChair.Value, 
				Reason.Ground => Settings.PutAwayGround.Value, 
				Reason.Steering => Settings.PutAwaySteering.Value, 
				Reason.Riding => Settings.PutAwayRiding.Value, 
				Reason.Emote => Settings.PutAwayEmote.Value, 
				_ => false, 
			};
		}

		private static bool HasHidden(Humanoid p)
		{
			if (_hiddenRight.Invoke(p) == null)
			{
				return _hiddenLeft.Invoke(p) != null;
			}
			return true;
		}

		private static void Show(Humanoid p)
		{
			if (!(_showHandItems == null))
			{
				ParameterInfo[] parameters = _showHandItems.GetParameters();
				object[] array = new object[parameters.Length];
				for (int i = 0; i < parameters.Length; i++)
				{
					array[i] = ((parameters[i].Name == "animation") ? ((object)true) : (parameters[i].HasDefaultValue ? parameters[i].DefaultValue : ((object)false)));
				}
				_showHandItems.Invoke(p, array);
			}
		}
	}
	internal static class Game
	{
		public static FieldRef<Humanoid, ItemData> RightItem;

		public static FieldRef<Humanoid, ItemData> LeftItem;

		public static FieldRef<VisEquipment, int> CurrentLeftBackHash;

		public static FieldRef<VisEquipment, int> CurrentRightBackHash;

		public static FieldRef<InventoryGrid, List<InventoryElement>> GridElements;

		public static FieldRef<VisEquipment, int> CurrentHelmetHash;

		private static MethodInfo _attachItem;

		public static void Init()
		{
			RightItem = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_rightItem");
			LeftItem = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_leftItem");
			CurrentLeftBackHash = AccessTools.FieldRefAccess<VisEquipment, int>("m_currentLeftBackItemHash");
			CurrentRightBackHash = AccessTools.FieldRefAccess<VisEquipment, int>("m_currentRightBackItemHash");
			GridElements = AccessTools.FieldRefAccess<InventoryGrid, List<InventoryElement>>("m_elements");
			CurrentHelmetHash = AccessTools.FieldRefAccess<VisEquipment, int>("m_currentHelmetItemHash");
			_attachItem = AccessTools.Method(typeof(VisEquipment), "AttachItem", (Type[])null, (Type[])null);
			if (_attachItem == null)
			{
				Plugin.Log.LogError((object)"VisEquipment.AttachItem not found - nothing will be drawn.");
			}
		}

		public static GameObject AttachItem(VisEquipment vis, int hash, int variant, int quality, Transform joint)
		{
			if (_attachItem == null || (Object)(object)joint == (Object)null)
			{
				return null;
			}
			ParameterInfo[] parameters = _attachItem.GetParameters();
			object[] array = new object[parameters.Length];
			for (int i = 0; i < parameters.Length; i++)
			{
				switch (parameters[i].Name)
				{
				case "itemHash":
					array[i] = hash;
					break;
				case "variant":
					array[i] = variant;
					break;
				case "joint":
					array[i] = joint;
					break;
				case "enableEquipEffects":
					array[i] = false;
					break;
				case "backAttach":
					array[i] = true;
					break;
				case "quality":
					array[i] = quality;
					break;
				default:
					array[i] = (parameters[i].HasDefaultValue ? parameters[i].DefaultValue : (parameters[i].ParameterType.IsValueType ? Activator.CreateInstance(parameters[i].ParameterType) : null));
					break;
				}
			}
			try
			{
				object? obj = _attachItem.Invoke(vis, array);
				return (GameObject)((obj is GameObject) ? obj : null);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)$"Could not attach item {hash}: {ex.InnerException?.Message ?? ex.Message}");
				return null;
			}
		}

		public static void RefreshVanillaBack(VisEquipment vis)
		{
			if (!((Object)(object)vis == (Object)null))
			{
				CurrentLeftBackHash.Invoke(vis) = -1;
				CurrentRightBackHash.Invoke(vis) = -1;
			}
		}

		public static void RefreshHelmet(VisEquipment vis)
		{
			if ((Object)(object)vis != (Object)null)
			{
				CurrentHelmetHash.Invoke(vis) = -1;
			}
		}

		public static bool Sleeping(Humanoid h)
		{
			if ((Object)(object)h == (Object)null)
			{
				return false;
			}
			Player val = (Player)(object)((h is Player) ? h : null);
			if (val != null)
			{
				if (!((Character)val).InBed())
				{
					return val.IsSleeping();
				}
				return true;
			}
			ZNetView component = ((Component)h).GetComponent<ZNetView>();
			if ((Object)(object)component != (Object)null && component.IsValid() && component.GetZDO().GetBool(ZDOVars.s_inBed, false))
			{
				return true;
			}
			BaseAI component2 = ((Component)h).GetComponent<BaseAI>();
			if ((Object)(object)component2 != (Object)null)
			{
				return component2.IsSleeping();
			}
			return false;
		}

		public static int Hash(ItemData item)
		{
			if (!((Object)(object)item?.m_dropPrefab != (Object)null))
			{
				return 0;
			}
			return StringExtensionMethods.GetStableHashCode(((Object)item.m_dropPrefab).name);
		}

		public static string PrefabName(ItemData item)
		{
			if (!((Object)(object)item?.m_dropPrefab != (Object)null))
			{
				return null;
			}
			return ((Object)item.m_dropPrefab).name;
		}

		public static SharedDataInfo Info(int hash)
		{
			GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(hash) : null);
			return new SharedDataInfo((((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null)?.m_itemData?.m_shared, ((Object)(object)val != (Object)null) ? ((Object)val).name : null);
		}
	}
	internal readonly struct SharedDataInfo
	{
		public readonly SharedData Shared;

		public readonly string PrefabName;

		public SharedDataInfo(SharedData s, string name)
		{
			Shared = s;
			PrefabName = name;
		}
	}
	public class HolsterVisual : MonoBehaviour
	{
		private static readonly Dictionary<VisEquipment, HolsterVisual> _byVis = new Dictionary<VisEquipment, HolsterVisual>();

		private VisEquipment _vis;

		private ZNetView _nview;

		private float _timer;

		private string _data;

		private int _layoutRev = -1;

		private int _offsetRev = -1;

		private bool _hidden;

		private bool _initialized;

		private readonly List<Piece> _pieces = new List<Piece>();

		private readonly List<Entry> _entries = new List<Entry>();

		private readonly HashSet<int> _rendered = new HashSet<int>();

		private readonly Dictionary<Slot, Mount> _mounts = new Dictionary<Slot, Mount>();

		private readonly Dictionary<int, float> _recentlyInHand = new Dictionary<int, float>();

		private readonly List<KeyValuePair<int, float>> _pendingDraw = new List<KeyValuePair<int, float>>();

		private const float SoundWindow = 1.5f;

		private static bool _errorLogged;

		internal static IEnumerable<HolsterVisual> All => _byVis.Values;

		internal Humanoid Humanoid { get; private set; }

		internal bool HelmetHidden { get; private set; }

		internal ZNetView NView => _nview;

		internal static HolsterVisual For(VisEquipment vis)
		{
			if (!((Object)(object)vis != (Object)null) || !_byVis.TryGetValue(vis, out var value))
			{
				return null;
			}
			return value;
		}

		internal bool Renders(int hash)
		{
			if (hash != 0)
			{
				return _rendered.Contains(hash);
			}
			return false;
		}

		private void Awake()
		{
			_vis = ((Component)this).GetComponent<VisEquipment>();
			_nview = ((Component)this).GetComponent<ZNetView>();
			Humanoid = ((Component)this).GetComponent<Humanoid>();
			if ((Object)(object)_vis != (Object)null)
			{
				_byVis[_vis] = this;
			}
		}

		private void OnDestroy()
		{
			if ((Object)(object)_vis != (Object)null)
			{
				_byVis.Remove(_vis);
			}
			Clear();
		}

		private void Update()
		{
			try
			{
				Tick();
			}
			catch (Exception ex)
			{
				if (!_errorLogged)
				{
					_errorLogged = true;
					Plugin.Log.LogError((object)("HolsterVisual: " + ex));
				}
			}
		}

		private void Tick()
		{
			if ((Object)(object)_vis == (Object)null || (Object)(object)_nview == (Object)null || !_nview.IsValid() || (Object)(object)ObjectDB.instance == (Object)null)
			{
				if (_pieces.Count > 0)
				{
					Clear();
					_data = null;
				}
				return;
			}
			ZDO zDO = _nview.GetZDO();
			TrackHands(zDO);
			_timer -= Time.deltaTime;
			if (_timer > 0f)
			{
				return;
			}
			_timer = (_nview.IsOwner() ? 0.05f : 0.2f);
			bool value = Settings.Enabled.Value;
			string text = (value ? zDO.GetString("GearManners.Items", "") : "");
			bool flag = false;
			foreach (Piece piece in _pieces)
			{
				if ((Object)(object)piece.Go == (Object)null)
				{
					flag = true;
					break;
				}
			}
			if (text != _data || _layoutRev != Settings.LayoutRevision || flag)
			{
				Rebuild(text);
			}
			else if (_offsetRev != Settings.OffsetRevision)
			{
				_offsetRev = Settings.OffsetRevision;
				foreach (Piece piece2 in _pieces)
				{
					Pose.ApplyOffsets(piece2, ((Component)this).transform);
				}
			}
			bool flag2 = value && zDO.GetBool("GearManners.HelmetOff", false);
			if (flag2 != HelmetHidden)
			{
				HelmetHidden = flag2;
				Game.RefreshHelmet(_vis);
			}
			bool flag3 = value && zDO.GetBool("GearManners.Hide", false);
			if (flag3 == _hidden)
			{
				return;
			}
			_hidden = flag3;
			foreach (Piece piece3 in _pieces)
			{
				if ((Object)(object)piece3.Go != (Object)null)
				{
					piece3.Go.SetActive(!flag3);
				}
			}
		}

		private void Rebuild(string data)
		{
			List<int> before = new List<int>(_rendered);
			_data = data;
			_layoutRev = Settings.LayoutRevision;
			_offsetRev = Settings.OffsetRevision;
			Clear();
			LocalHolster.Parse(data, _entries);
			foreach (Entry entry in _entries)
			{
				SharedDataInfo sharedDataInfo = Game.Info(entry.Hash);
				Kind kind = Slots.KindOf(sharedDataInfo.Shared);
				if (kind == Kind.None)
				{
					continue;
				}
				Mount mount = GetMount(entry.Slot);
				if (mount == null)
				{
					continue;
				}
				GameObject val = Game.AttachItem(_vis, entry.Hash, entry.Variant, entry.Quality, mount.Joint);
				if (!((Object)(object)val == (Object)null))
				{
					Piece piece = new Piece
					{
						Go = val,
						Hash = entry.Hash,
						Slot = entry.Slot,
						Kind = kind,
						Prefab = sharedDataInfo.PrefabName,
						Group = Slots.GroupFor(entry.Slot, kind),
						Mount = mount
					};
					Pose.SetBase(piece, ((Component)this).transform);
					Pose.ApplyOffsets(piece, ((Component)this).transform);
					if (_hidden)
					{
						val.SetActive(false);
					}
					_pieces.Add(piece);
					_rendered.Add(entry.Hash);
				}
			}
			Game.RefreshVanillaBack(_vis);
			if (_initialized)
			{
				QueueSounds(before);
			}
			_initialized = true;
		}

		private Mount GetMount(Slot slot)
		{
			if (_mounts.TryGetValue(slot, out var value) && value != null && (Object)(object)value.Joint != (Object)null)
			{
				return value;
			}
			value = Rig.Resolve(_vis, slot);
			_mounts[slot] = value;
			return value;
		}

		private void Clear()
		{
			foreach (Piece piece in _pieces)
			{
				if ((Object)(object)piece.Go != (Object)null)
				{
					Object.Destroy((Object)(object)piece.Go);
				}
			}
			_pieces.Clear();
			_rendered.Clear();
		}

		private void TrackHands(ZDO zdo)
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			float time = Time.time;
			int num = zdo.GetInt(ZDOVars.s_rightItem, 0);
			int num2 = zdo.GetInt(ZDOVars.s_leftItem, 0);
			if (num != 0)
			{
				_recentlyInHand[num] = time;
			}
			if (num2 != 0)
			{
				_recentlyInHand[num2] = time;
			}
			for (int num3 = _pendingDraw.Count - 1; num3 >= 0; num3--)
			{
				KeyValuePair<int, float> keyValuePair = _pendingDraw[num3];
				if (keyValuePair.Key == num || keyValuePair.Key == num2)
				{
					_pendingDraw.Clear();
					Sounds.Play(((Component)this).transform.position, draw: true);
					break;
				}
				if (time > keyValuePair.Value)
				{
					_pendingDraw.RemoveAt(num3);
				}
			}
		}

		private void QueueSounds(List<int> before)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			if (!Settings.SoundsEnabled.Value)
			{
				return;
			}
			float time = Time.time;
			List<int> list = new List<int>(_rendered);
			foreach (int item in list)
			{
				if (!before.Contains(item) && _recentlyInHand.TryGetValue(item, out var value) && time - value < 1.5f)
				{
					Sounds.Play(((Component)this).transform.position, draw: false);
					break;
				}
			}
			foreach (int item2 in before)
			{
				if (!list.Contains(item2))
				{
					_pendingDraw.Add(new KeyValuePair<int, float>(item2, time + 1.5f));
				}
			}
		}
	}
	internal struct Entry
	{
		public Slot Slot;

		public int Hash;

		public int Variant;

		public int Quality;
	}
	internal static class LocalHolster
	{
		public const string ItemsKey = "GearManners.Items";

		public const string HideKey = "GearManners.Hide";

		public const string HelmetKey = "GearManners.HelmetOff";

		private const string Version = "1|";

		private static float _timer;

		private static readonly List<Entry> _entries = new List<Entry>();

		private static readonly HashSet<Slot> _used = new HashSet<Slot>();

		private static readonly List<HolsterVisual> _owned = new List<HolsterVisual>();

		private static bool _publishErrorLogged;

		internal static float LastAlertedTime = -999f;

		private static readonly Dictionary<Humanoid, float> _lastFight = new Dictionary<Humanoid, float>();

		public static void MarkDirty()
		{
			_timer = 0f;
		}

		public static void Tick()
		{
			if ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				return;
			}
			_timer -= Time.deltaTime;
			if (_timer > 0f)
			{
				return;
			}
			_timer = 0.1f;
			_owned.Clear();
			foreach (HolsterVisual item in HolsterVisual.All)
			{
				if (!((Object)(object)item == (Object)null) && !((Object)(object)item.Humanoid == (Object)null) && !((Object)(object)item.NView == (Object)null) && item.NView.IsValid() && item.NView.IsOwner())
				{
					_owned.Add(item);
				}
			}
			foreach (HolsterVisual item2 in _owned)
			{
				try
				{
					Publish(item2.Humanoid, item2.NView.GetZDO());
				}
				catch (Exception arg)
				{
					if (!_publishErrorLogged)
					{
						_publishErrorLogged = true;
						Plugin.Log.LogError((object)$"Could not update {((Object)item2).name}: {arg}");
					}
				}
			}
		}

		private static void Publish(Humanoid h, ZDO zdo)
		{
			if (zdo != null)
			{
				string text = (Settings.Enabled.Value ? Compute(h) : "");
				if (zdo.GetString("GearManners.Items", "") != text)
				{
					zdo.Set("GearManners.Items", text);
				}
				bool flag = Settings.Enabled.Value && ShouldHide(h);
				if (zdo.GetBool("GearManners.Hide", false) != flag)
				{
					zdo.Set("GearManners.Hide", flag);
				}
				bool flag2 = Settings.Enabled.Value && Settings.HideHelmetCalm.Value && !InCombat(h);
				if (zdo.GetBool("GearManners.HelmetOff", false) != flag2)
				{
					zdo.Set("GearManners.HelmetOff", flag2);
				}
			}
		}

		internal static void MarkFight(Character c)
		{
			Humanoid val = (Humanoid)(object)((c is Humanoid) ? c : null);
			if (val == null || (Object)(object)HolsterVisual.For(((Component)val).GetComponent<VisEquipment>()) == (Object)null)
			{
				return;
			}
			if (_lastFight.Count > 32)
			{
				foreach (Humanoid item in _lastFight.Keys.Where((Humanoid k) => (Object)(object)k == (Object)null).ToList())
				{
					_lastFight.Remove(item);
				}
			}
			_lastFight[val] = Time.time;
		}

		internal static bool Fighting(Humanoid h, float window)
		{
			if ((Object)(object)h == (Object)null)
			{
				return false;
			}
			float time = Time.time;
			if (_lastFight.TryGetValue(h, out var value) && time - value < window)
			{
				return true;
			}
			if ((Object)(object)h == (Object)(object)Player.m_localPlayer)
			{
				return time - LastAlertedTime < window;
			}
			BaseAI component = ((Component)h).GetComponent<BaseAI>();
			if ((Object)(object)component != (Object)null)
			{
				return component.IsAlerted();
			}
			return false;
		}

		private static bool InCombat(Humanoid h)
		{
			float value = Settings.HelmetCalmSeconds.Value;
			if (Fighting(h, value) || ((Character)h).IsBlocking())
			{
				return true;
			}
			if (Settings.HelmetWhileArmed.Value)
			{
				ItemData val = Game.RightItem.Invoke(h);
				ItemData val2 = Game.LeftItem.Invoke(h);
				if ((val != null && val.IsWeapon()) || (val2 != null && val2.IsWeapon()))
				{
					return true;
				}
			}
			return false;
		}

		private static string Compute(Humanoid p)
		{
			Inventory inventory = p.GetInventory();
			if (inventory == null)
			{
				return "";
			}
			ItemData right = Game.RightItem.Invoke(p);
			ItemData left = Game.LeftItem.Invoke(p);
			List<ItemData> list = (from i in inventory.GetAllItems()
				where i != right && i != left && Marking.IsWorn(i) && Game.Hash(i) != 0 && Slots.KindOf(i.m_shared) != Kind.None
				orderby i.m_gridPos.y, i.m_gridPos.x
				select i).ToList();
			_entries.Clear();
			_used.Clear();
			HashSet<ItemData> hashSet = new HashSet<ItemData>();
			foreach (ItemData item in list)
			{
				Slot slot = Marking.GetSlot(item);
				if (slot != Slot.Auto && !_used.Contains(slot))
				{
					Place(item, slot);
					hashSet.Add(item);
				}
			}
			foreach (ItemData item2 in list)
			{
				if (hashSet.Contains(item2))
				{
					continue;
				}
				foreach (Slot item3 in Slots.AutoOrder(Slots.KindOf(item2.m_shared)))
				{
					if (!_used.Contains(item3))
					{
						Place(item2, item3);
						hashSet.Add(item2);
						break;
					}
				}
				if (!hashSet.Contains(item2) && Settings.DebugLog.Value)
				{
					Plugin.Log.LogInfo((object)("No free spot for " + item2.m_shared.m_name + "."));
				}
			}
			return Write(_entries);
		}

		private static void Place(ItemData item, Slot slot)
		{
			_used.Add(slot);
			_entries.Add(new Entry
			{
				Slot = slot,
				Hash = Game.Hash(item),
				Variant = item.m_variant,
				Quality = item.m_quality
			});
		}

		private static bool ShouldHide(Humanoid h)
		{
			Player val = (Player)(object)((h is Player) ? h : null);
			bool flag = Game.Sleeping(h);
			if (Settings.HideSleeping.Value && flag)
			{
				return true;
			}
			if (Settings.HideSitting.Value && !flag && (((Character)h).IsSitting() || ((Character)h).IsAttached()))
			{
				return true;
			}
			if (Settings.HideSwimming.Value && ((Character)h).IsSwimming())
			{
				return true;
			}
			if (Settings.HideIndoors.Value && (Object)(object)val != (Object)null && val.InShelter())
			{
				return true;
			}
			if (Settings.HideInDungeons.Value && ((Character)h).InInterior())
			{
				return true;
			}
			return false;
		}

		private static string Write(List<Entry> entries)
		{
			StringBuilder stringBuilder = new StringBuilder("1|");
			for (int i = 0; i < entries.Count; i++)
			{
				if (i > 0)
				{
					stringBuilder.Append(';');
				}
				Entry entry = entries[i];
				stringBuilder.Append((int)entry.Slot).Append(':').Append(entry.Hash)
					.Append(':')
					.Append(entry.Variant)
					.Append(':')
					.Append(entry.Quality);
			}
			return stringBuilder.ToString();
		}

		public static void Parse(string data, List<Entry> into)
		{
			into.Clear();
			if (string.IsNullOrEmpty(data) || !data.StartsWith("1|"))
			{
				return;
			}
			string[] array = data.Substring("1|".Length).Split(';');
			for (int i = 0; i < array.Length; i++)
			{
				string[] array2 = array[i].Split(':');
				if (array2.Length >= 4 && int.TryParse(array2[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result) && int.TryParse(array2[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result2))
				{
					int.TryParse(array2[2], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result3);
					int.TryParse(array2[3], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result4);
					if (result > 0 && result <= 9 && result2 != 0)
					{
						into.Add(new Entry
						{
							Slot = (Slot)result,
							Hash = result2,
							Variant = result3,
							Quality = result4
						});
					}
				}
			}
		}
	}
	internal static class Marking
	{
		private const string Key = "GearManners.Slot";

		private const string OldKey = "Sheathed.Slot";

		public static bool IsWorn(ItemData item)
		{
			string value;
			return Get(item, out value);
		}

		private static bool Get(ItemData item, out string value)
		{
			value = null;
			Dictionary<string, string> dictionary = item?.m_customData;
			if (dictionary == null)
			{
				return false;
			}
			if (dictionary.TryGetValue("GearManners.Slot", out value))
			{
				return true;
			}
			if (!dictionary.TryGetValue("Sheathed.Slot", out value))
			{
				return false;
			}
			dictionary["GearManners.Slot"] = value;
			dictionary.Remove("Sheathed.Slot");
			return true;
		}

		public static Slot GetSlot(ItemData item)
		{
			if (!Get(item, out var value))
			{
				return Slot.Auto;
			}
			if (!Enum.TryParse<Slot>(value, out var result) || result < Slot.Auto || result > Slot.Shield)
			{
				return Slot.Auto;
			}
			return result;
		}

		public static void SetWorn(ItemData item, bool worn, Slot slot = Slot.Auto)
		{
			if (item?.m_customData != null)
			{
				if (worn)
				{
					item.m_customData["GearManners.Slot"] = slot.ToString();
				}
				else
				{
					item.m_customData.Remove("GearManners.Slot");
				}
				LocalHolster.MarkDirty();
			}
		}

		public static void Tick()
		{
			//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_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)
			if (!Settings.Enabled.Value)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || TypingSomewhere())
			{
				return;
			}
			KeyboardShortcut value = Settings.MarkKey.Value;
			bool flag = ((KeyboardShortcut)(ref value)).IsDown();
			value = Settings.SlotKey.Value;
			bool flag2 = ((KeyboardShortcut)(ref value)).IsDown();
			if (!flag && !flag2)
			{
				return;
			}
			bool flag3 = InventoryGui.IsVisible();
			Inventory owner = null;
			ItemData val = (flag3 ? HoveredItem(out owner) : HandItem(localPlayer));
			if (val == null)
			{
				if (!flag3)
				{
					Message(localPlayer, "Nothing in your hands to holster.");
				}
				return;
			}
			string text = ((Localization.instance != null) ? Localization.instance.Localize(val.m_shared.m_name) : val.m_shared.m_name);
			if (Slots.KindOf(val.m_shared) == Kind.None)
			{
				Message(localPlayer, text + " can't be holstered.");
				return;
			}
			if (flag)
			{
				bool flag4 = !IsWorn(val);
				SetWorn(val, flag4);
				Message(localPlayer, flag4 ? ("Holstered: " + text + " (" + Slots.Label(Slot.Auto) + ")") : ("Not holstered: " + text));
			}
			else
			{
				Slot slot = (IsWorn(val) ? Slots.Next(GetSlot(val)) : Slot.Auto);
				SetWorn(val, worn: true, slot);
				Message(localPlayer, text + ": " + Slots.Label(slot));
			}
			if (owner != null && owner != ((Humanoid)localPlayer).GetInventory())
			{
				owner.m_onChanged?.Invoke();
			}
		}

		private static ItemData HandItem(Player p)
		{
			return Game.RightItem.Invoke((Humanoid)(object)p) ?? Game.LeftItem.Invoke((Humanoid)(object)p);
		}

		private static ItemData HoveredItem(out Inventory owner)
		{
			owner = null;
			InventoryGui instance = InventoryGui.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return null;
			}
			return HoveredIn(instance.m_playerGrid, ref owner) ?? HoveredIn(instance.ContainerGrid, ref owner);
		}

		private static ItemData HoveredIn(InventoryGrid grid, ref Inventory owner)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			Inventory val = (((Object)(object)grid != (Object)null && ((Component)grid).gameObject.activeInHierarchy) ? grid.GetInventory() : null);
			if (val == null)
			{
				return null;
			}
			owner = val;
			List<InventoryElement> list = Game.GridElements.Invoke(grid);
			if (list == null)
			{
				return null;
			}
			int width = val.GetWidth();
			Vector2 val2 = Vector2.op_Implicit(Input.mousePosition);
			foreach (ItemData allItem in val.GetAllItems())
			{
				int num = allItem.m_gridPos.y * width + allItem.m_gridPos.x;
				if (num < 0 || num >= list.Count || (Object)(object)list[num] == (Object)null)
				{
					continue;
				}
				RectTransform elementRectTransform = list[num].GetElementRectTransform();
				if ((Object)(object)elementRectTransform != (Object)null)
				{
					Rect rect = elementRectTransform.rect;
					if (((Rect)(ref rect)).Contains(((Transform)elementRectTransform).InverseTransformPoint(Vector2.op_Implicit(val2))))
					{
						return allItem;
					}
				}
			}
			return null;
		}

		internal static bool TypingSomewhere()
		{
			if ((!((Object)(object)Chat.instance != (Object)null) || !Chat.instance.HasFocus()) && !Console.IsVisible() && !TextInput.IsVisible() && !Menu.IsVisible())
			{
				if ((Object)(object)Minimap.instance != (Object)null)
				{
					return Minimap.IsOpen();
				}
				return false;
			}
			return true;
		}

		private static void Message(Player p, string text)
		{
			((Character)p).Message((MessageType)2, text, 0, (Sprite)null, false);
		}
	}
	[HarmonyPatch(typeof(VisEquipment), "Awake")]
	internal static class VisEquipment_Awake_Patch
	{
		private static void Postfix(VisEquipment __instance)
		{
			if (__instance.m_isPlayer && (Object)(object)((Component)__instance).GetComponent<Humanoid>() != (Object)null && (Object)(object)((Component)__instance).GetComponent<HolsterVisual>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<HolsterVisual>();
			}
		}
	}
	[HarmonyPatch(typeof(VisEquipment), "SetBackEquipped")]
	internal static class VisEquipment_SetBackEquipped_Patch
	{
		private static void Prefix(VisEquipment __instance, ref int leftItem, ref int rightItem)
		{
			if (!Settings.Enabled.Value)
			{
				return;
			}
			HolsterVisual holsterVisual = HolsterVisual.For(__instance);
			if (!((Object)(object)holsterVisual == (Object)null))
			{
				bool value = Settings.HideUnworn.Value;
				if (value || holsterVisual.Renders(leftItem))
				{
					leftItem = 0;
				}
				if (value || holsterVisual.Renders(rightItem))
				{
					rightItem = 0;
				}
			}
		}
	}
	[HarmonyPatch(typeof(VisEquipment), "SetHelmetEquipped")]
	internal static class VisEquipment_SetHelmetEquipped_Patch
	{
		private static void Prefix(VisEquipment __instance, ref int hash)
		{
			if (hash != 0 && Settings.Enabled.Value)
			{
				HolsterVisual holsterVisual = HolsterVisual.For(__instance);
				if ((Object)(object)holsterVisual != (Object)null && holsterVisual.HelmetHidden)
				{
					hash = 0;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Player), "RPC_OnTargeted")]
	internal static class Player_RPC_OnTargeted_Patch
	{
		private static void Postfix(Player __instance, bool alerted)
		{
			if (alerted && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				LocalHolster.LastAlertedTime = Time.time;
			}
		}
	}
	[HarmonyPatch(typeof(Character), "Damage")]
	internal static class Character_Damage_Patch
	{
		private static void Prefix(Character __instance, HitData hit)
		{
			Character val = ((hit != null) ? hit.GetAttacker() : null);
			if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)__instance)
			{
				LocalHolster.MarkFight(val);
			}
		}
	}
	[HarmonyPatch(typeof(Character), "RPC_Damage")]
	internal static class Character_RPC_Damage_Patch
	{
		private static void Postfix(Character __instance, HitData hit)
		{
			Character val = ((hit != null) ? hit.GetAttacker() : null);
			if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)__instance)
			{
				LocalHolster.MarkFight(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGrid), "UpdateGui")]
	internal static class InventoryGrid_UpdateGui_Patch
	{
		private const string BadgeName = "GearMannersBadge";

		private static readonly Color Orange = new Color(1f, 0.6f, 0.15f, 1f);

		private static void Postfix(InventoryGrid __instance)
		{
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: 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)
			InventoryGui instance = InventoryGui.instance;
			if ((Object)(object)instance == (Object)null || ((Object)(object)__instance != (Object)(object)instance.m_playerGrid && (Object)(object)__instance != (Object)(object)instance.ContainerGrid))
			{
				return;
			}
			List<InventoryElement> list = Game.GridElements.Invoke(__instance);
			Inventory inventory = __instance.GetInventory();
			if (list == null || inventory == null)
			{
				return;
			}
			bool flag = Settings.Enabled.Value && Settings.InventoryBadges.Value;
			foreach (InventoryElement item in list)
			{
				Transform val = (((Object)(object)item != (Object)null) ? ((Component)item).transform.Find("GearMannersBadge") : null);
				if ((Object)(object)val != (Object)null)
				{
					((Component)val).gameObject.SetActive(false);
				}
			}
			if (!flag)
			{
				return;
			}
			int width = inventory.GetWidth();
			foreach (ItemData allItem in inventory.GetAllItems())
			{
				if (!Marking.IsWorn(allItem))
				{
					continue;
				}
				int num = allItem.m_gridPos.y * width + allItem.m_gridPos.x;
				if (num < 0 || num >= list.Count || (Object)(object)list[num] == (Object)null)
				{
					continue;
				}
				TMP_Text badge = GetBadge(list[num]);
				if (!((Object)(object)badge == (Object)null))
				{
					badge.text = Slots.Badge(Marking.GetSlot(allItem));
					((Behaviour)badge).enabled = true;
					((Component)badge).gameObject.SetActive(true);
					Transform transform = badge.transform;
					if (transform.localScale != Vector3.one)
					{
						transform.localScale = Vector3.one;
					}
					if (transform.GetSiblingIndex() != transform.parent.childCount - 1)
					{
						transform.SetAsLastSibling();
					}
				}
			}
		}

		private static TMP_Text GetBadge(InventoryElement el)
		{
			//IL_0058: 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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_009d: 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)
			Transform val = ((Component)el).transform.Find("GearMannersBadge");
			if ((Object)(object)val != (Object)null)
			{
				return ((Component)val).GetComponent<TMP_Text>();
			}
			if ((Object)(object)el.m_amount == (Object)null)
			{
				return null;
			}
			GameObject obj = Object.Instantiate<GameObject>(((Component)el.m_amount).gameObject, ((Component)el).transform);
			((Object)obj).name = "GearMannersBadge";
			RectTransform val2 = (RectTransform)obj.transform;
			((Transform)val2).localScale = Vector3.one;
			val2.anchorMin = Vector2.zero;
			val2.anchorMax = Vector2.one;
			val2.offsetMin = new Vector2(4f, 2f);
			val2.offsetMax = new Vector2(-4f, -2f);
			TMP_Text component = obj.GetComponent<TMP_Text>();
			component.alignment = (TextAlignmentOptions)1025;
			((Graphic)component).color = Orange;
			((Graphic)component).raycastTarget = false;
			component.textWrappingMode = (TextWrappingModes)0;
			return component;
		}
	}
	[BepInPlugin("gearmanners.valheim", "GearManners", "0.9.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "gearmanners.valheim";

		public const string Name = "GearManners";

		public const string Version = "0.9.0";

		internal static Plugin Instance;

		internal static ManualLogSource Log;

		private Harmony _harmony;

		private readonly bool[] _errorLogged = new bool[4];

		private void Awake()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
			Settings.Bind(((BaseUnityPlugin)this).Config);
			Game.Init();
			AutoHolster.Init();
			Sounds.Load(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location));
			_harmony = new Harmony("gearmanners.valheim");
			_harmony.PatchAll(typeof(Plugin).Assembly);
			Log.LogInfo((object)"GearManners 0.9.0 loaded.");
		}

		private void Update()
		{
			Safe(Marking.Tick, 0);
			Safe(LocalHolster.Tick, 1);
			Safe(AutoHolster.Tick, 2);
		}

		private void OnApplicationQuit()
		{
			try
			{
				((BaseUnityPlugin)this).Config.Save();
			}
			catch
			{
			}
		}

		private void Safe(Action a, int id)
		{
			try
			{
				a();
			}
			catch (Exception arg)
			{
				if (!_errorLogged[id])
				{
					_errorLogged[id] = true;
					Log.LogError((object)$"{a.Method.Name}: {arg}");
				}
			}
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	internal sealed class Piece
	{
		public GameObject Go;

		public int Hash;

		public Slot Slot;

		public Kind Kind;

		public PoseGroup Group;

		public string Prefab;

		public Mount Mount;

		public Vector3 BasePos;

		public Quaternion BaseRot;
	}
	internal static class Pose
	{
		public static void SetBase(Piece piece, Transform character)
		{
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_00bd: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = piece.Go.transform;
			if (Slots.IsHip(piece.Slot) && piece.Kind != Kind.Tool && TryBladeAxes(piece.Go, out var blade, out var edge, out var length))
			{
				Quaternion frame = piece.Mount.Frame;
				Vector3 val = frame * Vector3.up;
				Vector3 val2 = frame * Vector3.forward;
				bool num = piece.Group == PoseGroup.HipHeadUp;
				Vector3 val3 = transform.localRotation * blade;
				Vector3 val4 = Vector3.ProjectOnPlane(transform.localRotation * edge, val3);
				if (((Vector3)(ref val4)).sqrMagnitude < 1E-06f)
				{
					val4 = Vector3.ProjectOnPlane(val2, val3);
				}
				Vector3 val5 = (num ? val : (-val));
				transform.localRotation = Quaternion.LookRotation(val5, val2) * Quaternion.Inverse(Quaternion.LookRotation(val3, val4)) * transform.localRotation;
				transform.localPosition = Vector3.zero;
				if (num)
				{
					float num2 = length * Mathf.Abs(transform.localScale.x);
					transform.localPosition = -val * (num2 * 0.75f);
				}
			}
			piece.BasePos = transform.localPosition;
			piece.BaseRot = transform.localRotation;
		}

		public static void ApplyOffsets(Piece piece, Transform character)
		{
			//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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0071: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = piece.Go.transform;
			OffsetSliders offsetSliders = Settings.For(piece.Group);
			Vector3 position = offsetSliders.Position;
			Vector3 euler = offsetSliders.Euler;
			if (piece.Mount.Mirrored)
			{
				position.x = 0f - position.x;
				euler.y = 0f - euler.y;
				euler.z = 0f - euler.z;
			}
			Quaternion frame = piece.Mount.Frame;
			float num = Mathf.Max(Mathf.Abs(piece.Mount.Joint.lossyScale.x), 0.0001f);
			float num2 = Mathf.Abs(character.lossyScale.x);
			transform.localPosition = piece.BasePos + frame * position * (num2 / num);
			transform.localRotation = frame * Quaternion.Euler(euler) * Quaternion.Inverse(frame) * piece.BaseRot;
		}

		private static bool TryBladeAxes(GameObject go, out Vector3 blade, out Vector3 edge, out float length)
		{
			//IL_0008: 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_000e: 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_006d: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: 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_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: 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)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: 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)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = (blade = (edge = Vector3.zero));
			length = 0f;
			Transform transform = go.transform;
			List<Vector3> list = new List<Vector3>(64);
			MeshFilter[] componentsInChildren = go.GetComponentsInChildren<MeshFilter>(false);
			foreach (MeshFilter val2 in componentsInChildren)
			{
				if (!((Object)(object)val2.sharedMesh == (Object)null) && !((Object)(object)((Component)val2).GetComponent<MeshRenderer>() == (Object)null))
				{
					AddCorners(list, val2.sharedMesh.bounds, ((Component)val2).transform, transform);
				}
			}
			SkinnedMeshRenderer[] componentsInChildren2 = go.GetComponentsInChildren<SkinnedMeshRenderer>(false);
			foreach (SkinnedMeshRenderer val3 in componentsInChildren2)
			{
				if (!((Object)(object)val3.sharedMesh == (Object)null))
				{
					AddCorners(list, val3.sharedMesh.bounds, ((Component)val3).transform, transform);
				}
			}
			if (list.Count < 8)
			{
				return false;
			}
			Vector3 val4 = Vector3.zero;
			foreach (Vector3 item in list)
			{
				val4 += item;
			}
			val4 /= (float)list.Count;
			float xx = 0f;
			float xy = 0f;
			float xz = 0f;
			float yy = 0f;
			float yz = 0f;
			float zz = 0f;
			foreach (Vector3 item2 in list)
			{
				Vector3 val5 = item2 - val4;
				xx += val5.x * val5.x;
				xy += val5.x * val5.y;
				xz += val5.x * val5.z;
				yy += val5.y * val5.y;
				yz += val5.y * val5.z;
				zz += val5.z * val5.z;
			}
			Vector3 e1 = PowerIterate(Mul, new Vector3(0.3f, 1f, 0.2f));
			float l1 = Vector3.Dot(e1, Mul(e1));
			Vector3 val6 = PowerIterate((Vector3 v) => Mul(v) - e1 * (l1 * Vector3.Dot(e1, v)), Vector3.Cross(e1, new Vector3(0.2f, 0.1f, 1f)));
			val = Vector3.ProjectOnPlane(val6, e1);
			val6 = ((Vector3)(ref val)).normalized;
			if (((Vector3)(ref e1)).sqrMagnitude < 0.5f || ((Vector3)(ref val6)).sqrMagnitude < 0.5f)
			{
				return false;
			}
			float num = float.MinValue;
			float num2 = float.MaxValue;
			float num3 = float.MinValue;
			float num4 = float.MaxValue;
			foreach (Vector3 item3 in list)
			{
				float num5 = Vector3.Dot(item3, e1);
				float num6 = Vector3.Dot(item3, val6);
				num = Mathf.Max(num, num5);
				num2 = Mathf.Min(num2, num5);
				num3 = Mathf.Max(num3, num6);
				num4 = Mathf.Min(num4, num6);
			}
			blade = ((num >= 0f - num2) ? e1 : (-e1));
			length = Mathf.Max(num, 0f - num2);
			edge = ((num3 >= 0f - num4) ? val6 : (-val6));
			return length > 0.0001f;
			Vector3 Mul(Vector3 v)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_002f: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0058: 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_0073: Unknown result type (might be due to invalid IL or missing references)
				//IL_007b: Unknown result type (might be due to invalid IL or missing references)
				return new Vector3(xx * v.x + xy * v.y + xz * v.z, xy * v.x + yy * v.y + yz * v.z, xz * v.x + yz * v.y + zz * v.z);
			}
		}

		private static Vector3 PowerIterate(Func<Vector3, Vector3> mul, Vector3 v)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			((Vector3)(ref v)).Normalize();
			for (int i = 0; i < 40; i++)
			{
				Vector3 val = mul(v);
				if (((Vector3)(ref val)).sqrMagnitude < 1E-12f)
				{
					break;
				}
				v = ((Vector3)(ref val)).normalized;
			}
			return v;
		}

		private static void AddCorners(List<Vector3> pts, Bounds b, Transform from, Transform root)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			Vector3 center = ((Bounds)(ref b)).center;
			Vector3 extents = ((Bounds)(ref b)).extents;
			Vector3 val = default(Vector3);
			for (int i = 0; i < 8; i++)
			{
				((Vector3)(ref val))..ctor(center.x + (((i & 1) != 0) ? extents.x : (0f - extents.x)), center.y + (((i & 2) != 0) ? extents.y : (0f - extents.y)), center.z + (((i & 4) != 0) ? extents.z : (0f - extents.z)));
				pts.Add(root.InverseTransformPoint(from.TransformPoint(val)));
			}
		}
	}
	internal sealed class Mount
	{
		public Transform Joint;

		public Quaternion Frame;

		public bool Mirrored;
	}
	internal static class Rig
	{
		private const string Prefix = "GearManners_";

		private const float CrossBackOffset = 0.04f;

		private static readonly Dictionary<int, Quaternion[]> _restCache = new Dictionary<int, Quaternion[]>();

		public static Transform Anchor(VisEquipment vis, Slot slot)
		{
			switch (slot)
			{
			case Slot.HipLeft:
			case Slot.HipRight:
				return vis.m_backTool;
			case Slot.Back:
				return vis.m_backMelee;
			case Slot.BackBig:
			case Slot.BackBigCross:
				return vis.m_backTwohandedMelee;
			case Slot.BackSpear:
			case Slot.BackSpearCross:
				return vis.m_backAtgeir;
			case Slot.Bow:
				return vis.m_backBow;
			case Slot.Shield:
				return vis.m_backShield;
			default:
				return null;
			}
		}

		public static Mount Resolve(VisEquipment vis, Slot slot)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			Transform val = Anchor(vis, slot);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Transform val2 = val;
			bool flag = Slots.IsMirrored(slot);
			if (flag)
			{
				float backOffset = ((slot == Slot.HipLeft) ? 0f : 0.04f);
				val2 = GetOrCreateMirror(vis, val, "GearManners_" + slot, backOffset);
				if ((Object)(object)val2 == (Object)null)
				{
					return null;
				}
			}
			return new Mount
			{
				Joint = val2,
				Frame = CharFrameIn(vis, val2),
				Mirrored = flag
			};
		}

		public static Quaternion CharFrameIn(VisEquipment vis, Transform t)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			return Quaternion.Inverse(RestInChar(vis, t));
		}

		private static Quaternion RestInChar(VisEquipment vis, Transform t)
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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_002b: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)vis).transform;
			List<Transform> list = new List<Transform>();
			Transform val = t;
			while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)transform)
			{
				if (TryBoneRest(vis, val, out var restInChar))
				{
					Quaternion val2 = restInChar;
					for (int num = list.Count - 1; num >= 0; num--)
					{
						val2 *= list[num].localRotation;
					}
					return val2;
				}
				list.Add(val);
				val = val.parent;
			}
			return Quaternion.Inverse(transform.rotation) * t.rotation;
		}

		private static bool TryBoneRest(VisEquipment vis, Transform bone, out Quaternion restInChar)
		{
			//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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00e0: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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)
			restInChar = Quaternion.identity;
			SkinnedMeshRenderer bodyModel = vis.m_bodyModel;
			if ((Object)(object)bodyModel == (Object)null || (Object)(object)bodyModel.sharedMesh == (Object)null)
			{
				return false;
			}
			int num = Array.IndexOf(bodyModel.bones, bone);
			if (num < 0)
			{
				return false;
			}
			int instanceID = ((Object)bodyModel.sharedMesh).GetInstanceID();
			if (!_restCache.TryGetValue(instanceID, out var value))
			{
				try
				{
					Matrix4x4[] bindposes = bodyModel.sharedMesh.bindposes;
					value = (Quaternion[])(object)new Quaternion[bindposes.Length];
					for (int i = 0; i < bindposes.Length; i++)
					{
						Quaternion[] array = value;
						int num2 = i;
						Matrix4x4 inverse = ((Matrix4x4)(ref bindposes[i])).inverse;
						array[num2] = ((Matrix4x4)(ref inverse)).rotation;
					}
				}
				catch
				{
					value = null;
				}
				_restCache[instanceID] = value;
			}
			if (value == null || num >= value.Length)
			{
				return false;
			}
			Quaternion val = Quaternion.Inverse(((Component)vis).transform.rotation) * ((Component)bodyModel).transform.rotation;
			restInChar = val * value[num];
			return true;
		}

		private static Transform GetOrCreateMirror(VisEquipment vis, Transform anchor, string name, float backOffset)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_0033: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_0099: 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_00a5: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: 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_0170: 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_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: 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_018c: 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_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: 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_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: 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)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			Transform val = anchor.Find(name);
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			Transform parent = anchor.parent;
			if ((Object)(object)parent == (Object)null)
			{
				return null;
			}
			Quaternion val2 = CharFrameIn(vis, parent);
			Vector3 val3 = val2 * Vector3.right;
			Vector3 normalized = ((Vector3)(ref val3)).normalized;
			float num = CentreLine(parent, normalized);
			Vector3 localPosition = anchor.localPosition;
			Vector3 val4 = localPosition - 2f * (Vector3.Dot(localPosition, normalized) - num) * normalized;
			Quaternion localRotation = anchor.localRotation;
			Vector3 val5 = default(Vector3);
			((Vector3)(ref val5))..ctor(localRotation.x, localRotation.y, localRotation.z);
			Vector3 val6 = -val5 + 2f * Vector3.Dot(val5, normalized) * normalized;
			Quaternion val7 = default(Quaternion);
			((Quaternion)(ref val7))..ctor(val6.x, val6.y, val6.z, localRotation.w);
			if (backOffset != 0f)
			{
				float num2 = Mathf.Max(Mathf.Abs(parent.lossyScale.x), 0.0001f);
				val4 += val2 * Vector3.back * (backOffset * Mathf.Abs(((Component)vis).transform.lossyScale.x) / num2);
			}
			float num3 = Mathf.Max(Mathf.Abs(anchor.localScale.x), 0.0001f);
			Transform transform = new GameObject(name).transform;
			transform.SetParent(anchor, false);
			transform.localPosition = Quaternion.Inverse(localRotation) * (val4 - localPosition) / num3;
			transform.localRotation = Quaternion.Inverse(localRotation) * val7;
			transform.localScale = Vector3.one;
			if (Settings.DebugLog.Value)
			{
				Plugin.Log.LogInfo((object)$"Created mirrored joint {name} under {((Object)anchor).name} (parent bone {((Object)parent).name}, centre offset {num:0.###}).");
			}
			return transform;
		}

		private static float CentreLine(Transform bone, Vector3 n)
		{
			//IL_0080: 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_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < bone.childCount; i++)
			{
				Transform child = bone.GetChild(i);
				int num = ((Object)child).name.IndexOf("Left", StringComparison.OrdinalIgnoreCase);
				if (num < 0 || ((Object)child).name.StartsWith("GearManners_"))
				{
					continue;
				}
				string b = ((Object)child).name.Substring(0, num) + "Right" + ((Object)child).name.Substring(num + 4);
				for (int j = 0; j < bone.childCount; j++)
				{
					Transform child2 = bone.GetChild(j);
					if (string.Equals(((Object)child2).name, b, StringComparison.OrdinalIgnoreCase))
					{
						return Vector3.Dot((child.localPosition + child2.localPosition) * 0.5f, n);
					}
				}
			}
			return 0f;
		}
	}
	internal enum PoseGroup
	{
		HipBlade,
		HipHeadUp,
		HipTool,
		BackOneHand,
		BackBig,
		BackSpear,
		Bow,
		Shield
	}
	internal sealed class OffsetSliders
	{
		public ConfigEntry<bool> Adjust;

		public ConfigEntry<float> Right;

		public ConfigEntry<float> Up;

		public ConfigEntry<float> Forward;

		public ConfigEntry<float> Tilt;

		public ConfigEntry<float> Turn;

		public ConfigEntry<float> Lean;

		public readonly List<ConfigurationManagerAttributes> SliderAttrs = new List<ConfigurationManagerAttributes>();

		public Vector3 Position => new Vector3(Right.Value, Up.Value, Forward.Value);

		public Vector3 Euler => new Vector3(Tilt.Value, Turn.Value, Lean.Value);

		public IEnumerable<ConfigEntry<float>> All()
		{
			yield return Right;
			yield return Up;
			yield return Forward;
			yield return Tilt;
			yield return Turn;
			yield return Lean;
		}
	}
	internal static class Settings
	{
		private const float MoveRange = 0.6f;

		private const float TurnRange = 180f;

		private static ConfigFile _cfg;

		public static ConfigEntry<bool> Enabled;

		public static ConfigEntry<KeyboardShortcut> MarkKey;

		public static ConfigEntry<KeyboardShortcut> SlotKey;

		public static ConfigEntry<bool> InventoryBadges;

		public static ConfigEntry<bool> DebugLog;

		public static ConfigEntry<bool> AxesHeadUp;

		public static ConfigEntry<bool> HideUnworn;

		public static ConfigEntry<bool> PutAwayChair;

		public static ConfigEntry<bool> PutAwayGround;

		public static ConfigEntry<bool> PutAwaySteering;

		public static ConfigEntry<bool> PutAwayRiding;

		public static ConfigEntry<bool> PutAwayEmote;

		public static ConfigEntry<bool> DrawAfter;

		public static ConfigEntry<bool> SheatheCalm;

		public static ConfigEntry<bool> CompanionsFollow;

		public static ConfigEntry<float> SheatheCalmSeconds;

		public static ConfigEntry<bool> SoundsEnabled;

		public static ConfigEntry<float> SoundVolume;

		public static ConfigEntry<float> SoundPitchVariation;

		public static ConfigEntry<bool> HideSitting;

		public static ConfigEntry<bool> HideSleeping;

		public static ConfigEntry<bool> HideSwimming;

		public static ConfigEntry<bool> HideIndoors;

		public static ConfigEntry<bool> HideInDungeons;

		public static ConfigEntry<bool> HideHelmetCalm;

		public static ConfigEntry<bool> HelmetWhileArmed;

		public static ConfigEntry<float> HelmetCalmSeconds;

		private static readonly Dictionary<PoseGroup, OffsetSliders> _groups = new Dictionary<PoseGroup, OffsetSliders>();

		public static int OffsetRevision { get; private set; }

		public static int LayoutRevision { get; private set; }

		public static void Bind(ConfigFile cfg)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0449: Unknown result type (might be due to invalid IL or missing references)
			//IL_045d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0481: Unknown result type (might be due to invalid IL or missing references)
			//IL_0495: Unknown result type (might be due to invalid IL or missing references)
			//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_04af: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04de: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0512: Unknown result type (might be due to invalid IL or missing references)
			//IL_0517: Unknown result type (might be due to invalid IL or missing references)
			//IL_052c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0531: Unknown result type (might be due to invalid IL or missing references)
			_cfg = cfg;
			Enabled = cfg.Bind<bool>("01 - General", "Enabled", true, Desc("Turn the whole mod on or off.", 100));
			MarkKey = cfg.Bind<KeyboardShortcut>("01 - General", "Holster key", new KeyboardShortcut((KeyCode)107, Array.Empty<KeyCode>()), Desc("Choose an item to carry on your body.\nIn the inventory: point at an item and press this key.\nOutside the inventory: works on the item in your hands.\nPress again to stop. Works for weapons, shields, bows and tools. Nothing is holstered until you choose.", 99));
			SlotKey = cfg.Bind<KeyboardShortcut>("01 - General", "Change spot key", new KeyboardShortcut((KeyCode)111, Array.Empty<KeyCode>()), Desc("Point at a holstered item and press this key to change where it goes on your body: Auto, left hip, right hip, back, big back, big back crossed, spear back, spear back crossed, bow, shield.", 98));
			InventoryBadges = cfg.Bind<bool>("01 - General", "Show tags in inventory", true, Desc("Show a small orange tag on holstered items in the inventory. It tells which spot they use.", 97));
			DebugLog = cfg.Bind<bool>("01 - General", "Debug log", false, Desc("Write extra details to the BepInEx log.", 0, null, advanced: true));
			AxesHeadUp = cfg.Bind<bool>("02 - Holster", "Axes and maces: head up", true, Desc("Items you carry on your body (Holster key).\n\nOn: axes, maces and clubs on the hip hang with the head up, like in a belt loop.\nOff: they hang head down, like swords.", 100));
			HideUnworn = cfg.Bind<bool>("02 - Holster", "Not holstered: vanish when sheathed", true, Desc("On: when you sheathe (R) an item that is not holstered, it vanishes.\nOff: the game puts it on your back, like without the mod.", 99));
			PutAwayChair = cfg.Bind<bool>("03 - Sheathe", "When sitting on a chair", true, Desc("Empty your hands: the weapon goes to its holster, or vanishes.\n\nSheathe when you sit on a chair, bench or throne (also on ships). Companions too.", 100));
			PutAwayGround = cfg.Bind<bool>("03 - Sheathe", "When sitting on the ground", true, Desc("Sheathe when you sit on the ground (sit emote / X). Companions too.", 99));
			PutAwaySteering = cfg.Bind<bool>("03 - Sheathe", "When steering a ship", true, Desc("Sheathe when you take the ship's rudder.", 98));
			PutAwayRiding = cfg.Bind<bool>("03 - Sheathe", "When riding", false, Desc("Sheathe when you get on a saddle (lox, or modded mounts).", 97));
			PutAwayEmote = cfg.Bind<bool>("03 - Sheathe", "When doing an emote", false, Desc("Sheathe when you start an emote (wave, dance...).", 96));
			SheatheCalm = cfg.Bind<bool>("03 - Sheathe", "When calm", false, Desc("Sheathe a weapon nobody has used for a while: no fighting, no swinging (chopping, mining...), no enemy alerted. Tools (hammer, hoe, pickaxe, torch...) are never sheathed. For you and your companions. Companions draw again by themselves when a fight starts.", 94));
			SheatheCalmSeconds = cfg.Bind<float>("03 - Sheathe", "When calm: seconds", 30f, Desc("How many calm seconds before sheathing.", 93, (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 120f)));
			CompanionsFollow = cfg.Bind<bool>("03 - Sheathe", "Companions sheathe with you", true, Desc("When you sheathe with R, your companions nearby sheathe their weapons too (not their tools). They draw again by themselves when a fight starts.", 92));
			DrawAfter = cfg.Bind<bool>("03 - Sheathe", "Draw again after", true, Desc("When you stand up (or stop steering, riding...), draw the weapons you had in your hands.\nAlso after leaving a bed or a crafting station. The game sheathes for those itself, but never draws again.", 95));
			SoundsEnabled = cfg.Bind<bool>("03 - Sheathe", "Sounds", true, Desc("Play a sound when you draw or sheathe a holstered item.\nTo change them, replace the .wav files in the mod's 'sounds' folder (draw*.wav, sheathe*.wav).", 90));
			SoundVolume = cfg.Bind<float>("03 - Sheathe", "Sound volume", 0.6f, Desc("How loud the sounds are.", 89, (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f)));
			SoundPitchVariation = cfg.Bind<float>("03 - Sheathe", "Sound pitch variation", 0.08f, Desc("Small random pitch change each time, so it doesn't sound the same. 0 = always the same.", 88, (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 0.3f), advanced: true));
			HideSitting = cfg.Bind<bool>("04 - Hide", "Holstered items: when sitting", true, Desc("Only visual: nothing moves, it just isn't shown.\n\nDon't show holstered items while sitting or riding.", 100));
			HideSleeping = cfg.Bind<bool>("04 - Hide", "Holstered items: when sleeping", true, Desc("Don't show holstered items while in bed.", 99));
			HideSwimming = cfg.Bind<bool>("04 - Hide", "Holstered items: when swimming", false, Desc("Don't show holstered items while swimming.", 98));
			HideIndoors = cfg.Bind<bool>("04 - Hide", "Holstered items: when indoors", false, Desc("Don't show holstered items while under a roof.", 97));
			HideInDungeons = cfg.Bind<bool>("04 - Hide", "Holstered items: in dungeons", false, Desc("Don't show holstered items in crypts, caves and other dungeons.", 96));
			HideHelmetCalm = cfg.Bind<bool>("04 - Hide", "Helmet: out of combat", true, Desc("Don't show your helmet when you are not fighting. You still wear it (armor and effects count), and your hair shows. It comes back when you hit a creature, a creature hits you, you block, or an enemy is alerted to you. Chopping trees or mining doesn't count.", 90));
			HelmetCalmSeconds = cfg.Bind<float>("04 - Hide", "Helmet: seconds before hiding", 10f, Desc("How many seconds after the fighting stops before the helmet hides again.", 89, (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 60f)));
			HelmetWhileArmed = cfg.Bind<bool>("04 - Hide", "Helmet: show while weapon drawn", false, Desc("Always show the helmet when you have a weapon in your hands.", 88));
			Group(PoseGroup.HipBlade, "05 - Position - Hip: swords and knives", "Swords and knives on the hip, blade down. The left hip is a mirror of the right.", new Vector3(0f, 0.14f, 0.01f), new Vector3(0.5f, 0f, 1.7f));
			Group(PoseGroup.HipHeadUp, "06 - Position - Hip: axes and maces", "Axes, maces and clubs on the hip. The left hip is a mirror of the right.", new Vector3(0f, 0.12f, 0f), new Vector3(-10f, 0f, 0f));
			Group(PoseGroup.HipTool, "07 - Position - Hip: tools", "Hammer, pickaxe, hoe, cultivator, torch... on the hip. 0 = where the game normally puts tools.", Vector3.zero, Vector3.zero);
			Group(PoseGroup.BackOneHand, "08 - Position - Back: one-handed", "One-handed weapons on the back.", Vector3.zero, Vector3.zero);
			Group(PoseGroup.BackBig, "09 - Position - Back: big weapons", "Two-handed swords, axes and sledges. The crossed spot is a mirror of this one.", Vector3.zero, Vector3.zero);
			Group(PoseGroup.BackSpear, "10 - Position - Back: spears and staffs", "Atgeirs, spears and staffs. The crossed spot is a mirror of this one.", Vector3.zero, Vector3.zero);
			Group(PoseGroup.Bow, "11 - Position - Back: bow", "Bows and crossbows.", Vector3.zero, Vector3.zero);
			Group(PoseGroup.Shield, "12 - Position - Back: shield", "Shields.", Vector3.zero, Vector3.zero);
			foreach (OffsetSliders value in _groups.Values)
			{
				foreach (ConfigEntry<float> item in value.All())
				{
					item.SettingChanged += delegate
					{
						OffsetRevision++;
					};
				}
			}
			Enabled.SettingChanged += delegate
			{
				LayoutRevision++;
			};
			AxesHeadUp.SettingChanged += delegate
			{
				LayoutRevision++;
			};
			HideUnworn.SettingChanged += delegate
			{
				LayoutRevision++;
			};
			DropOldEntries(cfg);
		}

		public static OffsetSliders For(PoseGroup group)
		{
			return _groups[group];
		}

		private static void DropOldEntries(ConfigFile cfg)
		{
			try
			{
				if (AccessTools.Property(typeof(ConfigFile), "OrphanedEntries")?.GetValue(cfg) is IDictionary { Count: >0 } dictionary)
				{
					dictionary.Clear();
					cfg.Save();
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not tidy old config entries: " + ex.Message));
			}
		}

		private static void Group(PoseGroup group, string section, string about, Vector3 pos, Vector3 euler)
		{
			//IL_008d: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			AcceptableValueRange<float> r = new AcceptableValueRange<float>(-0.6f, 0.6f);
			AcceptableValueRange<float> r2 = new AcceptableValueRange<float>(-180f, 180f);
			OffsetSliders o = new OffsetSliders();
			o.Adjust = _cfg.Bind<bool>(section, "Adjust", false, Desc("Move a spot on your body.\n\n" + about + "\n\nTick to show the sliders. Untick to hide them again (your values are kept).", 101));
			bool show = o.Adjust.Value;
			o.Right = _cfg.Bind<float>(section, "Move right (-left)", pos.x, Slider("Metres towards the character's right. Negative = left. (Mirrored on the left side.)", 100, (AcceptableValueBase)(object)r));
			o.Up = _cfg.Bind<float>(section, "Move up (-down)", pos.y, Slider("Metres up. Negative = down.", 99, (AcceptableValueBase)(object)r));
			o.Forward = _cfg.Bind<float>(section, "Move forward (-back)", pos.z, Slider("Metres forward. Negative = towards the back.", 98, (AcceptableValueBase)(object)r));
			o.Tilt = _cfg.Bind<float>(section, "Tilt forward (-back)", euler.x, Slider("Degrees of tilt around the left-right axis.", 97, (AcceptableValueBase)(object)r2));
			o.Turn = _cfg.Bind<float>(section, "Turn right (-left)", euler.y, Slider("Degrees of turn around the up axis. (Mirrored on the left side.)", 96, (AcceptableValueBase)(object)r2));
			o.Lean = _cfg.Bind<float>(section, "Lean sideways", euler.z, Slider("Degrees of lean around the front-back axis. (Mirrored on the left side.)", 95, (AcceptableValueBase)(object)r2));
			o.Adjust.SettingChanged += delegate
			{
				foreach (ConfigurationManagerAttributes sliderAttr in o.SliderAttrs)
				{
					sliderAttr.Browsable = o.Adjust.Value;
				}
				ConfigManagerUi.Refresh();
			};
			_groups[group] = o;
			ConfigDescription Slider(string text, int order, AcceptableValueBase val)
			{
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Expected O, but got Unknown
				ConfigurationManagerAttributes configurationManagerAttributes = new ConfigurationManagerAttributes
				{
					Order = order,
					Browsable = show
				};
				o.SliderAttrs.Add(configurationManagerAttributes);
				return new ConfigDescription(text, val, new object[1] { configurationManagerAttributes });
			}
		}

		private static ConfigDescription Desc(string text, int order, AcceptableValueBase range = null, bool advanced = false)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			return new ConfigDescription(text, range, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = order,
					IsAdvanced = (advanced ? new bool?(true) : ((bool?)null))
				}
			});
		}
	}
	internal static class ConfigManagerUi
	{
		private static object _instance;

		private static MethodInfo _rebuild;

		private static bool _searched;

		public static void Refresh()
		{
			try
			{
				if (!_searched)
				{
					_searched = true;
					foreach (PluginInfo value in Chainloader.PluginInfos.Values)
					{
						if (!((Object)(object)((value != null) ? value.Instance : null) == (Object)null))
						{
							MethodInfo methodInfo = AccessTools.Method(((object)value.Instance).GetType(), "BuildSettingList", (Type[])null, (Type[])null);
							if (!(methodInfo == null) && methodInfo.GetParameters().Length == 0)
							{
								_instance = value.Instance;
								_rebuild = methodInfo;
								break;
							}
						}
					}
				}
				_rebuild?.Invoke(_instance, null);
			}
			catch (Exception ex)
			{
				if (Settings.DebugLog.Value)
				{
					Plugin.Log.LogInfo((object)("Configuration Manager refresh failed: " + ex.Message));
				}
			}
		}
	}
	internal sealed class ConfigurationManagerAttributes
	{
		public bool? ShowRangeAsPercent;

		public Action<ConfigEntryBase> CustomDrawer;

		public bool? Browsable;

		public string Category;

		public object DefaultValue;

		public bool? HideDefaultButton;

		public bool? HideSettingName;

		public string Description;

		public string DispName;

		public int? Order;

		public bool? ReadOnly;

		public bool? IsAdvanced;
	}
	internal enum Slot
	{
		Auto,
		HipLeft,
		HipRight,
		Back,
		BackBig,
		BackBigCross,
		BackSpear,
		BackSpearCross,
		Bow,
		Shield
	}
	internal enum Kind
	{
		None,
		OneHandBlade,
		OneHandHeavy,
		Tool,
		BigWeapon,
		Spear,
		Bow,
		Shield
	}
	internal static class Slots
	{
		public const Slot Max = Slot.Shield;

		private static readonly Slot[] CycleOrder = new Slot[10]
		{
			Slot.Auto,
			Slot.HipLeft,
			Slot.HipRight,
			Slot.Back,
			Slot.BackBig,
			Slot.BackBigCross,
			Slot.BackSpear,
			Slot.BackSpearCross,
			Slot.Bow,
			Slot.Shield
		};

		public static Slot Next(Slot s)
		{
			int num = Array.IndexOf(CycleOrder, s);
			return CycleOrder[(num + 1) % CycleOrder.Length];
		}

		public static Kind KindOf(SharedData s)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Invalid comparison between Unknown and I4
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Invalid comparison between Unknown and I4
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Invalid comparison between Unknown and I4
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Invalid comparison between Unknown and I4
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Invalid comparison between Unknown and I4
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Invalid comparison between Unknown and I4
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Invalid comparison between Unknown and I4
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Invalid comparison between Unknown and I4
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Invalid comparison between Unknown and I4
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Invalid comparison between Unknown and I4
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Invalid comparison between Unknown and I4
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Invalid comparison between Unknown and I4
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Invalid comparison between Unknown and I4
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Invalid comparison between Unknown and I4
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Invalid comparison between Unknown and I4
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Invalid comparison between Unknown and I4
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Invalid comparison between Unknown and I4
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Invalid comparison between Unknown and I4
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Invalid comparison between Unknown and I4
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Invalid comparison between Unknown and I4
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Invalid comparison between Unknown and I4
			if (s == null)
			{
				return Kind.None;
			}
			ItemType val = (((int)s.m_attachOverride != 0) ? s.m_attachOverride : s.m_itemType);
			SkillType skillType = s.m_skillType;
			if ((int)skillType == 2 && ((int)s.m_itemType == 3 || (int)s.m_itemType == 14 || (int)s.m_itemType == 22))
			{
				return Kind.OneHandBlade;
			}
			if ((int)val <= 5)
			{
				if ((int)val == 4)
				{
					return Kind.Bow;
				}
				if ((int)val == 5)
				{
					return Kind.Shield;
				}
			}
			else
			{
				if ((int)val == 15 || (int)val == 19)
				{
					return Kind.Tool;
				}
				if ((int)val == 20)
				{
					return Kind.Spear;
				}
			}
			if ((int)skillType == 12 || (int)skillType == 104)
			{
				return Kind.Tool;
			}
			if ((int)skillType == 14)
			{
				return Kind.Bow;
			}
			if ((int)skillType == 4 || (int)skillType == 5 || (int)skillType == 9 || (int)skillType == 10)
			{
				return Kind.Spear;
			}
			if ((int)val != 3)
			{
				if ((int)val == 14 || (int)val == 22)
				{
					return Kind.BigWeapon;
				}
				return Kind.None;
			}
			if ((int)skillType == 11)
			{
				return Kind.None;
			}
			if ((int)skillType != 7 && (int)skillType != 3)
			{
				return Kind.OneHandBlade;
			}
			return Kind.OneHandHeavy;
		}

		public static IReadOnlyList<Slot> AutoOrder(Kind k)
		{
			return k switch
			{
				Kind.OneHandBlade => new Slot[3]
				{
					Slot.HipLeft,
					Slot.HipRight,
					Slot.Back
				}, 
				Kind.OneHandHeavy => new Slot[3]
				{
					Slot.HipRight,
					Slot.HipLeft,
					Slot.Back
				}, 
				Kind.Tool => new Slot[3]
				{
					Slot.HipRight,
					Slot.HipLeft,
					Slot.Back
				}, 
				Kind.BigWeapon => new Slot[4]
				{
					Slot.BackBig,
					Slot.BackBigCross,
					Slot.BackSpear,
					Slot.BackSpearCross
				}, 
				Kind.Spear => new Slot[4]
				{
					Slot.BackSpear,
					Slot.BackSpearCross,
					Slot.BackBig,
					Slot.BackBigCross
				}, 
				Kind.Bow => new Slot[3]
				{
					Slot.Bow,
					Slot.BackBigCross,
					Slot.BackSpearCross
				}, 
				Kind.Shield => new Slot[1] { Slot.Shield }, 
				_ => Array.Empty<Slot>(), 
			};
		}

		public static bool IsHip(Slot s)
		{
			if (s != Slot.HipLeft)
			{
				return s == Slot.HipRight;
			}
			return true;
		}

		public static bool IsMirrored(Slot s)
		{
			if (s != Slot.HipLeft && s != Slot.BackBigCross)
			{
				return s == Slot.BackSpearCross;
			}
			return true;
		}

		public static PoseGroup GroupFor(Slot slot, Kind kind)
		{
			switch (slot)
			{
			case Slot.HipLeft:
			case Slot.HipRight:
				switch (kind)
				{
				case Kind.Tool:
					return PoseGroup.HipTool;
				case Kind.OneHandHeavy:
					if (Settings.AxesHeadUp.Value)
					{
						return PoseGroup.HipHeadUp;
					}
					break;
				}
				return P