Decompiled source of SmartShield v1.0.19

Cjayride.SmartShield.dll

Decompiled 4 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_utils")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: AssemblyCompany("Cjayride.SmartShield")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.19.0")]
[assembly: AssemblyInformationalVersion("1.0.19+571f7c85f4f45714271c67e97eba16708f2a393b")]
[assembly: AssemblyProduct("Cjayride.SmartShield")]
[assembly: AssemblyTitle("Cjayride.SmartShield")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.19.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Cjayride.SmartShield
{
	[HarmonyPatch(typeof(GameCamera), "UpdateMouseCapture")]
	internal static class PatchMouseCapture
	{
		private static void Postfix()
		{
			if (OptionsMenu.IsOpen)
			{
				ZCursor.LockState = (CursorLockMode)0;
				ZCursor.Show();
			}
		}
	}
	[HarmonyPatch(typeof(Player), "TakeInput")]
	internal static class PatchPlayerTakeInput
	{
		private static void Postfix(ref bool __result)
		{
			if (OptionsMenu.IsOpen)
			{
				__result = false;
			}
		}
	}
	[HarmonyPatch(typeof(PlayerController), "TakeInput", new Type[] { typeof(bool) })]
	internal static class PatchControllerTakeInput
	{
		private static void Postfix(ref bool __result)
		{
			if (OptionsMenu.IsOpen)
			{
				__result = false;
			}
		}
	}
	[HarmonyPatch(typeof(PlayerController), "InInventoryEtc")]
	internal static class PatchControllerInInventoryEtc
	{
		private static void Postfix(ref bool __result)
		{
			if (OptionsMenu.IsOpen)
			{
				__result = true;
			}
		}
	}
	internal static class MenuIcons
	{
		internal static Texture2D Shield;

		internal static Texture2D SwordShield;

		internal static Texture2D Axe;

		internal static Texture2D ButcherKnife;

		internal static Texture2D Bow;

		internal static Texture2D TwoHand;

		internal static Texture2D Sheath;

		internal static Texture2D Hotbar;

		internal static Texture2D CheckOff;

		internal static Texture2D CheckOn;

		private static bool _ready;

		private static GUIStyle _box;

		internal static GUIStyle BoxStyle
		{
			get
			{
				Ensure();
				return _box;
			}
		}

		internal static void Ensure()
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			//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_009b: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected O, but got Unknown
			if (!_ready)
			{
				Shield = PaintShield();
				SwordShield = PaintSwordShield();
				Axe = PaintAxe();
				ButcherKnife = PaintButcherKnife();
				Bow = PaintBow();
				TwoHand = PaintTwoHand();
				Sheath = PaintSheath();
				Hotbar = PaintHotbar();
				CheckOff = PaintCheck(on: false);
				CheckOn = PaintCheck(on: true);
				_box = new GUIStyle(GUI.skin.label)
				{
					padding = new RectOffset(0, 0, 0, 0),
					margin = new RectOffset(0, 8, 2, 2),
					alignment = (TextAnchor)4,
					stretchWidth = false,
					stretchHeight = false
				};
				_box.normal.background = null;
				_ready = true;
			}
		}

		private static Texture2D PaintShield()
		{
			//IL_010f: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			int s = 32;
			Color[] px = Clear(s);
			Color val = default(Color);
			((Color)(ref val))..ctor(0.78f, 0.66f, 0.38f, 1f);
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.28f, 0.22f, 0.12f, 1f);
			Color c = default(Color);
			((Color)(ref c))..ctor(0.9f, 0.78f, 0.48f, 1f);
			for (int i = 3; i <= 28; i++)
			{
				float num = (float)(i - 3) / 25f;
				float num2 = ((i < 18) ? 10f : (10f * (1f - (num - 0.6f) / 0.55f)));
				if (num2 < 2f)
				{
					num2 = 2f;
				}
				int num3 = 16 - (int)num2;
				int num4 = 16 + (int)num2;
				for (int j = num3; j <= num4; j++)
				{
					bool flag = j == num3 || j == num4 || i == 3 || i == 28;
					Put(px, s, j, i, flag ? val : val2);
				}
			}
			FillCircle(px, s, 16, 13, 3, c);
			return Bake(s, px);
		}

		private static Texture2D PaintSwordShield()
		{
			//IL_0113: 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_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			int s = 32;
			Color[] px = Clear(s);
			Color c = default(Color);
			((Color)(ref c))..ctor(0.72f, 0.72f, 0.78f, 1f);
			Color c2 = default(Color);
			((Color)(ref c2))..ctor(0.55f, 0.38f, 0.18f, 1f);
			Color val = default(Color);
			((Color)(ref val))..ctor(0.78f, 0.66f, 0.38f, 1f);
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.28f, 0.22f, 0.12f, 1f);
			for (int i = 8; i <= 28; i++)
			{
				float num = ((i < 18) ? 7f : (7f * (1f - (float)(i - 18) / 14f)));
				int num2 = 20 - (int)num;
				int num3 = 20 + (int)num;
				for (int j = Mathf.Max(14, num2); j <= num3; j++)
				{
					bool flag = j == num2 || j == num3 || i == 8;
					Put(px, s, j, i, flag ? val : val2);
				}
			}
			for (int k = 3; k <= 24; k++)
			{
				Put(px, s, 9, k, c);
				Put(px, s, 10, k, c);
			}
			for (int l = 6; l <= 13; l++)
			{
				Put(px, s, l, 22, c2);
			}
			Put(px, s, 9, 25, c2);
			Put(px, s, 10, 25, c2);
			Put(px, s, 9, 26, c2);
			Put(px, s, 10, 26, c2);
			return Bake(s, px);
		}

		private static Texture2D PaintAxe()
		{
			//IL_004b: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			int s = 32;
			Color[] px = Clear(s);
			Color c = default(Color);
			((Color)(ref c))..ctor(0.5f, 0.32f, 0.14f, 1f);
			Color c2 = default(Color);
			((Color)(ref c2))..ctor(0.7f, 0.72f, 0.78f, 1f);
			for (int i = 4; i <= 28; i++)
			{
				Put(px, s, 11, i, c);
				Put(px, s, 12, i, c);
			}
			for (int j = 5; j <= 14; j++)
			{
				int num = 4 + (14 - j) / 2;
				for (int k = 13; k <= 13 + num; k++)
				{
					Put(px, s, k, j, c2);
				}
			}
			return Bake(s, px);
		}

		private static Texture2D PaintButcherKnife()
		{
			//IL_004b: 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_007b: 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_00a5: 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)
			int s = 32;
			Color[] px = Clear(s);
			Color c = default(Color);
			((Color)(ref c))..ctor(0.72f, 0.74f, 0.8f, 1f);
			Color c2 = default(Color);
			((Color)(ref c2))..ctor(0.45f, 0.3f, 0.14f, 1f);
			for (int i = 6; i <= 24; i++)
			{
				Put(px, s, 12, i, c);
				Put(px, s, 13, i, c);
			}
			for (int j = 4; j <= 11; j++)
			{
				Put(px, s, 14 + (j - 4) / 2, j, c);
			}
			for (int k = 22; k <= 28; k++)
			{
				Put(px, s, 11, k, c2);
				Put(px, s, 12, k, c2);
				Put(px, s, 13, k, c2);
			}
			return Bake(s, px);
		}

		private static Texture2D PaintBow()
		{
			//IL_006d: 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_0087: 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)
			int s = 32;
			Color[] px = Clear(s);
			Color c = default(Color);
			((Color)(ref c))..ctor(0.55f, 0.38f, 0.16f, 1f);
			Color c2 = default(Color);
			((Color)(ref c2))..ctor(0.85f, 0.82f, 0.7f, 1f);
			for (int i = 3; i <= 28; i++)
			{
				float num = ((float)i - 15.5f) / 13f;
				int num2 = 10 + (int)(num * num * 10f);
				Put(px, s, num2, i, c);
				Put(px, s, num2 + 1, i, c);
				Put(px, s, 22, i, c2);
			}
			for (int j = 12; j <= 21; j++)
			{
				Put(px, s, j, 15, new Color(0.72f, 0.72f, 0.76f, 1f));
			}
			return Bake(s, px);
		}

		private static Texture2D PaintTwoHand()
		{
			//IL_004b: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			int s = 32;
			Color[] px = Clear(s);
			Color c = default(Color);
			((Color)(ref c))..ctor(0.7f, 0.72f, 0.78f, 1f);
			Color c2 = default(Color);
			((Color)(ref c2))..ctor(0.45f, 0.3f, 0.14f, 1f);
			for (int i = 2; i <= 22; i++)
			{
				Put(px, s, 15, i, c);
				Put(px, s, 16, i, c);
				if (i < 10)
				{
					Put(px, s, 14, i, c);
					Put(px, s, 17, i, c);
				}
			}
			for (int j = 10; j <= 21; j++)
			{
				Put(px, s, j, 21, c2);
			}
			for (int k = 22; k <= 28; k++)
			{
				Put(px, s, 15, k, c2);
				Put(px, s, 16, k, c2);
			}
			return Bake(s, px);
		}

		private static Texture2D PaintSheath()
		{
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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)
			int s = 32;
			Color[] px = Clear(s);
			Color val = default(Color);
			((Color)(ref val))..ctor(0.22f, 0.18f, 0.12f, 1f);
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.78f, 0.66f, 0.38f, 1f);
			Color c = default(Color);
			((Color)(ref c))..ctor(0.45f, 0.32f, 0.16f, 1f);
			for (int i = 6; i <= 26; i++)
			{
				for (int j = 10; j <= 22; j++)
				{
					bool flag = j == 10 || j == 22 || i == 6 || i == 26;
					Put(px, s, j, i, flag ? val2 : val);
				}
			}
			for (int k = 4; k <= 28; k++)
			{
				Put(px, s, 8, k, c);
				Put(px, s, 9, k, c);
			}
			FillCircle(px, s, 16, 14, 4, val2);
			FillCircle(px, s, 16, 14, 2, new Color(0.3f, 0.24f, 0.12f, 1f));
			return Bake(s, px);
		}

		private static Texture2D PaintHotbar()
		{
			//IL_00bb: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			int s = 32;
			Color[] px = Clear(s);
			Color val = default(Color);
			((Color)(ref val))..ctor(0.18f, 0.14f, 0.08f, 1f);
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.78f, 0.66f, 0.38f, 1f);
			Color val3 = default(Color);
			((Color)(ref val3))..ctor(0.1f, 0.08f, 0.05f, 1f);
			int[] array = new int[3] { 3, 12, 21 };
			for (int i = 0; i < array.Length; i++)
			{
				int num = array[i];
				for (int j = 10; j <= 22; j++)
				{
					for (int k = num; k <= num + 8; k++)
					{
						bool flag = k == num || k == num + 8 || j == 10 || j == 22;
						Put(px, s, k, j, flag ? val2 : ((i == 1) ? val : val3));
					}
				}
			}
			return Bake(s, px);
		}

		private static Texture2D PaintCheck(bool on)
		{
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			int s = 32;
			Color[] px = Clear(s);
			Color val = default(Color);
			((Color)(ref val))..ctor(0.78f, 0.66f, 0.38f, 1f);
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.1f, 0.08f, 0.04f, 1f);
			Color c = default(Color);
			((Color)(ref c))..ctor(0.86f, 0.75f, 0.48f, 1f);
			for (int i = 2; i <= 29; i++)
			{
				for (int j = 2; j <= 29; j++)
				{
					bool flag = j <= 4 || j >= 27 || i <= 4 || i >= 27;
					Put(px, s, j, i, flag ? val : val2);
				}
			}
			if (on)
			{
				for (int k = 0; k < 9; k++)
				{
					Put(px, s, 8 + k, 16 + k / 2, c);
					Put(px, s, 9 + k, 16 + k / 2, c);
				}
				for (int l = 0; l < 14; l++)
				{
					Put(px, s, 16 + l, 20 - l, c);
					Put(px, s, 17 + l, 20 - l, c);
				}
			}
			return Bake(s, px);
		}

		private static Color[] Clear(int s)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			Color[] array = (Color[])(object)new Color[s * s];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = Color.clear;
			}
			return array;
		}

		private static void Put(Color[] px, int s, int x, int y, Color c)
		{
			//IL_0013: 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)
			if ((uint)x < (uint)s && (uint)y < (uint)s)
			{
				px[(s - 1 - y) * s + x] = c;
			}
		}

		private static void FillCircle(Color[] px, int s, int cx, int cy, int r, Color c)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			int num = r * r;
			for (int i = cy - r; i <= cy + r; i++)
			{
				for (int j = cx - r; j <= cx + r; j++)
				{
					int num2 = j - cx;
					int num3 = i - cy;
					if (num2 * num2 + num3 * num3 <= num)
					{
						Put(px, s, j, i, c);
					}
				}
			}
		}

		private static Texture2D Bake(int s, Color[] px)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			Texture2D val = new Texture2D(s, s, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)0,
				wrapMode = (TextureWrapMode)1,
				hideFlags = (HideFlags)61
			};
			val.SetPixels(px);
			val.Apply();
			return val;
		}
	}
	internal static class ModConfig
	{
		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<bool> AutoEquipOnOneHanded;

		internal static ConfigEntry<bool> EquipAfterRanged;

		internal static ConfigEntry<bool> UnequipOnTwoHanded;

		internal static ConfigEntry<bool> UnequipOnSheath;

		internal static ConfigEntry<bool> UnequipOnHotbarDeselect;

		internal static ConfigEntry<bool> EquipShieldWithButcherKnife;

		internal static ConfigEntry<string> SelectionMode;

		internal static ConfigEntry<string> PreferredShield;

		internal static ConfigEntry<bool> EquipShieldWithAxe;

		internal static ConfigEntry<KeyboardShortcut> MenuHotkey;

		internal static ConfigEntry<string> AllowedWeaponTypes;

		internal static ConfigEntry<string> BlacklistShields;

		internal static string[] AllowedWeaponTokens = Array.Empty<string>();

		internal static HashSet<string> BlacklistSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

		internal static string SelectionModeNormalized = "First";

		internal static string PreferredShieldNormalized = "";

		internal static void Bind(ConfigFile config)
		{
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			Enabled = config.Bind<bool>("General", "Enabled", true, "Master switch. No messages are ever shown.");
			AutoEquipOnOneHanded = config.Bind<bool>("Behavior", "AutoEquipOnOneHanded", true, "Equip a shield whenever a one-handed weapon is equipped.");
			EquipAfterRanged = config.Bind<bool>("Behavior", "EquipAfterRanged", true, "Also equip a shield after switching from a bow/crossbow (or other ranged) to a one-handed weapon.");
			UnequipOnTwoHanded = config.Bind<bool>("Behavior", "UnequipOnTwoHanded", true, "Unequip the shield when a two-handed or ranged weapon is equipped.");
			UnequipOnSheath = config.Bind<bool>("Behavior", "UnequipOnSheath", false, "When true, stow the shield in inventory on R-sheath (weapon-only on your back). When false, vanilla dual back display (weapon + shield).");
			UnequipOnHotbarDeselect = config.Bind<bool>("Behavior", "UnequipOnHotbarDeselect", true, "Unequip the shield when you deselect a one-handed weapon on the hotbar (press the same slot again). Does not unequip if you manually equip a shield alone.");
			EquipShieldWithButcherKnife = config.Bind<bool>("Behavior", "EquipShieldWithButcherKnife", false, "When false, do not auto-equip a shield with a butcher knife (skinning tamed animals).");
			SelectionMode = config.Bind<string>("ShieldSelection", "SelectionMode", "First", "Best = highest block power. First = first shield in inventory. Preferred = use PreferredShield.");
			PreferredShield = config.Bind<string>("ShieldSelection", "PreferredShield", "", "Prefab name used when SelectionMode is Preferred (example: ShieldWood).");
			EquipShieldWithAxe = config.Bind<bool>("ShieldSelection", "EquipShieldWithAxe", false, "When false, do not auto-equip a shield with a one-handed axe (tree chopping).");
			MenuHotkey = config.Bind<KeyboardShortcut>("UI", "MenuHotkey", new KeyboardShortcut((KeyCode)115, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }), "Opens the SmartShield popup (selection mode and axe shield toggle). Default Alt+S.");
			AllowedWeaponTypes = config.Bind<string>("Filters", "AllowedWeaponTypes", "", "Comma-separated ItemType, skill, or prefab names. Empty = all one-handed weapons.");
			BlacklistShields = config.Bind<string>("Filters", "BlacklistShields", "", "Comma-separated shield prefab names that must never be auto-equipped.");
			AllowedWeaponTypes.SettingChanged += delegate
			{
				RebuildCaches();
			};
			BlacklistShields.SettingChanged += delegate
			{
				RebuildCaches();
			};
			SelectionMode.SettingChanged += delegate
			{
				RebuildCaches();
			};
			PreferredShield.SettingChanged += delegate
			{
				RebuildCaches();
			};
			RebuildCaches();
		}

		internal static void RebuildCaches()
		{
			AllowedWeaponTokens = SplitList(AllowedWeaponTypes.Value);
			BlacklistSet = new HashSet<string>(SplitList(BlacklistShields.Value), StringComparer.OrdinalIgnoreCase);
			SelectionModeNormalized = (SelectionMode.Value ?? "Best").Trim();
			PreferredShieldNormalized = (PreferredShield.Value ?? "").Trim();
		}

		internal static string[] SplitList(string raw)
		{
			if (string.IsNullOrWhiteSpace(raw))
			{
				return Array.Empty<string>();
			}
			string[] array = raw.Split(new char[2] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
			int num = 0;
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = array[i].Trim();
				if (array[i].Length > 0)
				{
					num++;
				}
			}
			if (num == 0)
			{
				return Array.Empty<string>();
			}
			if (num == array.Length)
			{
				return array;
			}
			string[] array2 = new string[num];
			int num2 = 0;
			for (int j = 0; j < array.Length; j++)
			{
				if (array[j].Length > 0)
				{
					array2[num2++] = array[j];
				}
			}
			return array2;
		}
	}
	internal static class OptionsMenu
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static WindowFunction <0>__DrawWindow;
		}

		private static readonly string[] ModeLabels = new string[3] { "Best in inventory", "First in inventory", "Preferred shield" };

		private static readonly int WindowId = 1397248836;

		private static readonly Color Plate = new Color(0.07f, 0.05f, 0.03f, 0.94f);

		private static readonly Color PlateInner = new Color(0.12f, 0.09f, 0.05f, 0.96f);

		private static readonly Color GoldLine = new Color(0.93f, 0.82f, 0.52f, 1f);

		private static readonly Color TitleGold = new Color(0.9f, 0.78f, 0.48f, 1f);

		private static readonly Color BodyGold = new Color(0.86f, 0.75f, 0.48f, 0.95f);

		private static readonly Color DimGold = new Color(0.75f, 0.68f, 0.55f, 1f);

		private static readonly Color FillGold = new Color(1f, 0.86f, 0.25f, 0.95f);

		private static readonly Color MuteGold = new Color(0.42f, 0.34f, 0.18f, 1f);

		private static readonly Color SelectRow = new Color(0.26f, 0.2f, 0.1f, 1f);

		private static readonly Color DropPanel = new Color(0.04f, 0.03f, 0.02f, 0.98f);

		private static readonly Color Overlay = new Color(0f, 0f, 0f, 0.45f);

		private static bool _open;

		private static bool _dropdownOpen;

		private static bool _centered;

		private static Rect _window = new Rect(0f, 0f, 640f, 720f);

		private static Vector2 _scroll;

		private static string _preferredDraft = "";

		private static string _allowedDraft = "";

		private static string _blacklistDraft = "";

		private static bool _draftsLoaded;

		private static Texture2D _white;

		private static GUIStyle _windowStyle;

		private static GUIStyle _titleStyle;

		private static GUIStyle _sectionStyle;

		private static GUIStyle _labelStyle;

		private static GUIStyle _toggleStyle;

		private static GUIStyle _buttonStyle;

		private static GUIStyle _dropStyle;

		private static GUIStyle _fieldStyle;

		private static GUIStyle _hintStyle;

		private static GUIStyle _closeStyle;

		private static GUIStyle _dropItemStyle;

		private static GUIStyle _dropItemSelectedStyle;

		private static GUIStyle _dropBoxStyle;

		private static GUIStyle _titleLeftStyle;

		internal static bool IsOpen => _open;

		internal static void Tick()
		{
			//IL_0023: 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_0028: 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)
			KeyboardShortcut val = (KeyboardShortcut)((ModConfig.MenuHotkey != null) ? ModConfig.MenuHotkey.Value : new KeyboardShortcut((KeyCode)115, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }));
			if ((int)((KeyboardShortcut)(ref val)).MainKey != 0 && !TextInputBlocked() && ((KeyboardShortcut)(ref val)).IsDown())
			{
				SetOpen(!_open);
			}
			else if (_open && Input.GetKeyDown((KeyCode)27))
			{
				SetOpen(open: false);
			}
		}

		internal static void Draw()
		{
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Invalid comparison between Unknown and I4
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Expected O, but got Unknown
			if (_open)
			{
				EnsureStyles();
				if (!_centered)
				{
					((Rect)(ref _window)).width = Mathf.Clamp((float)Screen.width * 0.42f, 560f, 760f);
					((Rect)(ref _window)).height = Mathf.Clamp((float)Screen.height * 0.78f, 560f, 900f);
					((Rect)(ref _window)).x = ((float)Screen.width - ((Rect)(ref _window)).width) * 0.5f;
					((Rect)(ref _window)).y = ((float)Screen.height - ((Rect)(ref _window)).height) * 0.12f;
					_centered = true;
				}
				if ((int)Event.current.type == 7)
				{
					Color color = GUI.color;
					GUI.color = Overlay;
					GUI.DrawTexture(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), (Texture)(object)_white);
					GUI.color = color;
				}
				int windowId = WindowId;
				Rect window = _window;
				object obj = <>O.<0>__DrawWindow;
				if (obj == null)
				{
					WindowFunction val = DrawWindow;
					<>O.<0>__DrawWindow = val;
					obj = (object)val;
				}
				_window = GUI.Window(windowId, window, (WindowFunction)obj, "", _windowStyle);
			}
		}

		private static void SetOpen(bool open)
		{
			_open = open;
			_dropdownOpen = false;
			if (open)
			{
				LoadDrafts();
				_centered = false;
				ZCursor.LockState = (CursorLockMode)0;
				ZCursor.Show();
			}
			else
			{
				CommitDrafts();
				_draftsLoaded = false;
			}
		}

		private static void LoadDrafts()
		{
			_preferredDraft = ((ModConfig.PreferredShield != null) ? (ModConfig.PreferredShield.Value ?? "") : "");
			_allowedDraft = ((ModConfig.AllowedWeaponTypes != null) ? (ModConfig.AllowedWeaponTypes.Value ?? "") : "");
			_blacklistDraft = ((ModConfig.BlacklistShields != null) ? (ModConfig.BlacklistShields.Value ?? "") : "");
			_draftsLoaded = true;
		}

		private static void CommitDrafts()
		{
			if (_draftsLoaded)
			{
				SetString(ModConfig.PreferredShield, _preferredDraft);
				SetString(ModConfig.AllowedWeaponTypes, _allowedDraft);
				SetString(ModConfig.BlacklistShields, _blacklistDraft);
			}
		}

		private static void DrawWindow(int id)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_044c: Unknown result type (might be due to invalid IL or missing references)
			if ((int)Event.current.type == 7)
			{
				DrawBorder(new Rect(0f, 0f, ((Rect)(ref _window)).width, ((Rect)(ref _window)).height), GoldLine, 2f);
			}
			GUILayout.Space(10f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.FlexibleSpace();
			GUILayout.Box((Texture)(object)MenuIcons.Shield, MenuIcons.BoxStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(36f),
				GUILayout.Height(36f)
			});
			GUILayout.Space(10f);
			GUILayout.Label("SMART SHIELD", _titleLeftStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(36f) });
			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
			GUILayout.Label("Alt+S to toggle  ·  Esc to close  ·  drag the title to move", _hintStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Space(8f);
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(18f, 88f, ((Rect)(ref _window)).width - 36f, ((Rect)(ref _window)).height - 160f);
			Rect val2 = default(Rect);
			((Rect)(ref val2))..ctor(0f, 0f, ((Rect)(ref val)).width - 22f, _dropdownOpen ? 1080f : 860f);
			_scroll = GUI.BeginScrollView(val, _scroll, val2);
			GUILayout.BeginArea(val2);
			GUILayout.Label("GENERAL", _sectionStyle, Array.Empty<GUILayoutOption>());
			Toggle(ModConfig.Enabled, "Enable SmartShield");
			GUILayout.Space(14f);
			GUILayout.Label("SHIELD SELECTION", _sectionStyle, Array.Empty<GUILayoutOption>());
			DrawModeDropdown();
			GUILayout.Space(16f);
			GUILayout.Label("Preferred shield prefab (used when mode is Preferred)", _labelStyle, Array.Empty<GUILayoutOption>());
			_preferredDraft = GUILayout.TextField(_preferredDraft ?? "", _fieldStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) });
			GUILayout.Label("Example: ShieldWood  ·  leave empty to fall back to Best", _hintStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Space(14f);
			GUILayout.Label("BEHAVIOR", _sectionStyle, Array.Empty<GUILayoutOption>());
			Toggle(ModConfig.AutoEquipOnOneHanded, "Auto-equip shield with a one-handed weapon", MenuIcons.SwordShield);
			Toggle(ModConfig.EquipShieldWithAxe, "Equip shield with a 1H axe (uncheck for tree chopping)", MenuIcons.Axe);
			Toggle(ModConfig.EquipShieldWithButcherKnife, "Equip shield with a butcher knife (uncheck for skinning)", MenuIcons.ButcherKnife);
			Toggle(ModConfig.EquipAfterRanged, "Also equip after switching from bow / crossbow", MenuIcons.Bow);
			Toggle(ModConfig.UnequipOnTwoHanded, "Unequip shield when using two-handed or ranged", MenuIcons.TwoHand);
			Toggle(ModConfig.UnequipOnSheath, "Stow shield on R-sheath (weapon only on your back)", MenuIcons.Sheath);
			Toggle(ModConfig.UnequipOnHotbarDeselect, "Unequip shield when you deselect a 1H weapon on the hotbar", MenuIcons.Hotbar);
			GUILayout.Space(14f);
			GUILayout.Label("FILTERS", _sectionStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Label("Allowed weapon types / skills / prefabs (empty = all 1H)", _labelStyle, Array.Empty<GUILayoutOption>());
			_allowedDraft = GUILayout.TextField(_allowedDraft ?? "", _fieldStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) });
			GUILayout.Label("Comma-separated. Example: Swords, Knives, SpearBronze", _hintStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Space(8f);
			GUILayout.Label("Blacklisted shield prefabs (never auto-equipped)", _labelStyle, Array.Empty<GUILayoutOption>());
			_blacklistDraft = GUILayout.TextField(_blacklistDraft ?? "", _fieldStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) });
			GUILayout.Label("Comma-separated. Example: ShieldWood, ShieldBone", _hintStyle, Array.Empty<GUILayoutOption>());
			GUILayout.EndArea();
			GUI.EndScrollView();
			GUILayout.BeginArea(new Rect(18f, ((Rect)(ref _window)).height - 58f, ((Rect)(ref _window)).width - 36f, 46f));
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Apply", _buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(40f) }))
			{
				CommitDrafts();
				ShieldService.ReapplyFromMenu();
			}
			GUILayout.Space(12f);
			if (GUILayout.Button("Close", _closeStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(40f) }))
			{
				SetOpen(open: false);
			}
			GUILayout.EndHorizontal();
			GUILayout.EndArea();
			GUI.DragWindow(new Rect(0f, 0f, ((Rect)(ref _window)).width, 56f));
		}

		private static void DrawModeDropdown()
		{
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Invalid comparison between Unknown and I4
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.Label("How to pick a shield", _labelStyle, Array.Empty<GUILayoutOption>());
			int num = ModeIndex();
			if (GUILayout.Button(ModeLabels[num] + (_dropdownOpen ? "   ▲" : "   ▼"), _dropStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(36f) }))
			{
				_dropdownOpen = !_dropdownOpen;
			}
			if (!_dropdownOpen)
			{
				return;
			}
			GUILayout.Space(6f);
			GUILayout.BeginVertical(_dropBoxStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Space(8f);
			for (int i = 0; i < ModeLabels.Length; i++)
			{
				GUIStyle val = ((i == num) ? _dropItemSelectedStyle : _dropItemStyle);
				if (GUILayout.Button(ModeLabels[i], val, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) }))
				{
					string text = i switch
					{
						1 => "First", 
						2 => "Preferred", 
						_ => "Best", 
					};
					if (ModConfig.SelectionMode.Value != text)
					{
						ModConfig.SelectionMode.Value = text;
						ShieldService.ReapplyFromMenu();
					}
					_dropdownOpen = false;
				}
				if (i < ModeLabels.Length - 1)
				{
					GUILayout.Space(6f);
				}
			}
			GUILayout.Space(8f);
			GUILayout.EndVertical();
			if ((int)Event.current.type == 7)
			{
				DrawBorder(GUILayoutUtility.GetLastRect(), GoldLine, 2f);
			}
		}

		private static int ModeIndex()
		{
			string selectionModeNormalized = ModConfig.SelectionModeNormalized;
			if (selectionModeNormalized.Equals("First", StringComparison.OrdinalIgnoreCase))
			{
				return 1;
			}
			if (selectionModeNormalized.Equals("Preferred", StringComparison.OrdinalIgnoreCase))
			{
				return 2;
			}
			return 0;
		}

		private static void Toggle(ConfigEntry<bool> entry, string label, Texture2D icon = null)
		{
			//IL_007a: 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_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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Invalid comparison between Unknown and I4
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			if (entry != null)
			{
				GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(40f) });
				if ((Object)(object)icon != (Object)null)
				{
					GUILayout.Box((Texture)(object)icon, MenuIcons.BoxStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
					{
						GUILayout.Width(32f),
						GUILayout.Height(32f)
					});
				}
				Rect rect = GUILayoutUtility.GetRect(28f, 28f, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(28f),
					GUILayout.Height(28f)
				});
				GUILayout.Space(10f);
				GUILayout.Label(label, _toggleStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) });
				GUILayout.EndHorizontal();
				Rect lastRect = GUILayoutUtility.GetLastRect();
				GUILayout.Space(6f);
				Event current = Event.current;
				if ((int)current.type == 7)
				{
					GUI.DrawTexture(rect, (Texture)(object)(entry.Value ? MenuIcons.CheckOn : MenuIcons.CheckOff));
				}
				else if ((int)current.type == 0 && current.button == 0 && ((Rect)(ref lastRect)).Contains(current.mousePosition))
				{
					entry.Value = !entry.Value;
					current.Use();
					ShieldService.ReapplyFromMenu();
				}
			}
		}

		private static void SetString(ConfigEntry<string> entry, string value)
		{
			if (entry != null)
			{
				string text = value ?? "";
				if (entry.Value != text)
				{
					entry.Value = text;
				}
			}
		}

		private static void DrawBorder(Rect rect, Color color, float t)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_white == (Object)null))
			{
				Color color2 = GUI.color;
				GUI.color = color;
				GUI.DrawTexture(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width, t), (Texture)(object)_white);
				GUI.DrawTexture(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).yMax - t, ((Rect)(ref rect)).width, t), (Texture)(object)_white);
				GUI.DrawTexture(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, t, ((Rect)(ref rect)).height), (Texture)(object)_white);
				GUI.DrawTexture(new Rect(((Rect)(ref rect)).xMax - t, ((Rect)(ref rect)).y, t, ((Rect)(ref rect)).height), (Texture)(object)_white);
				GUI.color = color2;
			}
		}

		private static void EnsureStyles()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_002a: 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_005a: 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_0092: 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_00bc: 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_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: 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_0108: Expected O, but got Unknown
			//IL_010d: Expected O, but got Unknown
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Expected O, but got Unknown
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Expected O, but got Unknown
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Expected O, but got Unknown
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Expected O, but got Unknown
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Expected O, but got Unknown
			//IL_024c: 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_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Expected O, but got Unknown
			//IL_0293: Expected O, but got Unknown
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_036a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Expected O, but got Unknown
			//IL_037e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_038a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Expected O, but got Unknown
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a3: Expected O, but got Unknown
			//IL_03a8: Expected O, but got Unknown
			//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03eb: Expected O, but got Unknown
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0401: Unknown result type (might be due to invalid IL or missing references)
			//IL_0428: Unknown result type (might be due to invalid IL or missing references)
			//IL_0432: Expected O, but got Unknown
			//IL_043c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0450: Unknown result type (might be due to invalid IL or missing references)
			//IL_0464: Unknown result type (might be due to invalid IL or missing references)
			//IL_0469: Unknown result type (might be due to invalid IL or missing references)
			//IL_0471: Unknown result type (might be due to invalid IL or missing references)
			//IL_0476: Unknown result type (might be due to invalid IL or missing references)
			//IL_0480: Expected O, but got Unknown
			//IL_0485: Expected O, but got Unknown
			//IL_048f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
			if (_windowStyle == null || !((Object)(object)_white != (Object)null))
			{
				_white = new Texture2D(1, 1, (TextureFormat)4, false);
				_white.SetPixel(0, 0, Color.white);
				_white.Apply();
				((Object)_white).hideFlags = (HideFlags)61;
				MenuIcons.Ensure();
				Texture2D background = Solid(Plate);
				Texture2D val = Solid(PlateInner);
				Texture2D bg = Solid(MuteGold);
				Texture2D bg2 = Solid(new Color(GoldLine.r, GoldLine.g, GoldLine.b, 0.28f));
				Texture2D background2 = Solid(DropPanel);
				Texture2D bg3 = Solid(new Color(0.1f, 0.08f, 0.05f, 1f));
				Texture2D bg4 = Solid(SelectRow);
				_windowStyle = new GUIStyle(GUI.skin.window)
				{
					fontSize = 22,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)0,
					padding = new RectOffset(0, 0, 0, 0)
				};
				_windowStyle.normal.background = background;
				_windowStyle.onNormal.background = background;
				_windowStyle.normal.textColor = Color.clear;
				_windowStyle.onNormal.textColor = Color.clear;
				_titleStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 26,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)4
				};
				_titleStyle.normal.textColor = TitleGold;
				_titleLeftStyle = new GUIStyle(_titleStyle)
				{
					alignment = (TextAnchor)3,
					fontSize = 26
				};
				_sectionStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 20,
					fontStyle = (FontStyle)1
				};
				_sectionStyle.normal.textColor = TitleGold;
				_labelStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 18,
					wordWrap = true
				};
				_labelStyle.normal.textColor = BodyGold;
				_hintStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 15,
					wordWrap = true
				};
				_hintStyle.normal.textColor = DimGold;
				_hintStyle.alignment = (TextAnchor)4;
				_toggleStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 18,
					wordWrap = true,
					padding = new RectOffset(4, 4, 6, 4)
				};
				_toggleStyle.normal.textColor = BodyGold;
				_toggleStyle.onNormal.textColor = TitleGold;
				_toggleStyle.hover.textColor = GoldLine;
				_toggleStyle.onHover.textColor = TitleGold;
				_toggleStyle.focused.textColor = BodyGold;
				_toggleStyle.onFocused.textColor = TitleGold;
				_buttonStyle = Button(bg, TitleGold, 20);
				_buttonStyle.hover.textColor = BodyGold;
				_closeStyle = Button(bg2, TitleGold, 20);
				_dropStyle = Button(val, BodyGold, 18);
				_dropStyle.alignment = (TextAnchor)3;
				_dropStyle.padding = new RectOffset(12, 12, 6, 6);
				_dropBoxStyle = new GUIStyle(GUI.skin.box)
				{
					padding = new RectOffset(10, 10, 4, 4),
					margin = new RectOffset(0, 0, 0, 0)
				};
				_dropBoxStyle.normal.background = background2;
				_dropItemStyle = Button(bg3, BodyGold, 17);
				_dropItemStyle.alignment = (TextAnchor)3;
				_dropItemStyle.padding = new RectOffset(12, 12, 4, 4);
				_dropItemStyle.hover.textColor = TitleGold;
				_dropItemSelectedStyle = Button(bg4, TitleGold, 17);
				_dropItemSelectedStyle.alignment = (TextAnchor)3;
				_dropItemSelectedStyle.padding = new RectOffset(12, 12, 4, 4);
				_dropItemSelectedStyle.normal.textColor = TitleGold;
				_dropItemSelectedStyle.hover.textColor = BodyGold;
				_fieldStyle = new GUIStyle(GUI.skin.textField)
				{
					fontSize = 18,
					padding = new RectOffset(8, 8, 6, 6)
				};
				_fieldStyle.normal.textColor = BodyGold;
				_fieldStyle.focused.textColor = FillGold;
				_fieldStyle.normal.background = val;
				_fieldStyle.focused.background = val;
			}
		}

		private static GUIStyle Button(Texture2D bg, Color text, int size)
		{
			//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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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_0060: 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_0070: 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_0081: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(GUI.skin.button)
			{
				fontSize = size,
				fontStyle = (FontStyle)1,
				alignment = (TextAnchor)4
			};
			val.normal.background = bg;
			val.hover.background = bg;
			val.active.background = bg;
			val.onNormal.background = bg;
			val.normal.textColor = text;
			val.hover.textColor = TitleGold;
			val.active.textColor = TitleGold;
			return val;
		}

		private static Texture2D Solid(Color color)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false);
			val.SetPixel(0, 0, color);
			val.Apply();
			((Object)val).hideFlags = (HideFlags)61;
			return val;
		}

		private static bool TextInputBlocked()
		{
			if ((Object)(object)Console.instance != (Object)null && Console.IsVisible())
			{
				return true;
			}
			if ((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus())
			{
				return true;
			}
			if (TextInput.IsVisible())
			{
				return true;
			}
			return false;
		}
	}
	[BepInPlugin("cjayride.smartshield", "SmartShield", "1.0.19")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGUID = "cjayride.smartshield";

		public const string PluginName = "SmartShield";

		public const string PluginVersion = "1.0.19";

		internal static Plugin Instance;

		internal static Harmony Harmony;

		private float _seenPlayerAt = -1f;

		private float _nextPoll;

		private bool _baselined;

		private int _catchUpPolls;

		internal static ManualLogSource Log => ((BaseUnityPlugin)Instance).Logger;

		private void Awake()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			Instance = this;
			ModConfig.Bind(((BaseUnityPlugin)this).Config);
			Harmony = new Harmony("cjayride.smartshield");
			Harmony.PatchAll(typeof(PatchHideHandItems));
			Harmony.PatchAll(typeof(PatchShowHandItems));
			Harmony.PatchAll(typeof(PatchEquipItem));
			Harmony.PatchAll(typeof(PatchUnequipItem));
			Harmony.PatchAll(typeof(PatchOnAttackTrigger));
			Harmony.PatchAll(typeof(PatchPlayerTakeInput));
			Harmony.PatchAll(typeof(PatchControllerTakeInput));
			Harmony.PatchAll(typeof(PatchControllerInInventoryEtc));
			Harmony.PatchAll(typeof(PatchMouseCapture));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"SmartShield 1.0.19 loaded.");
		}

		private void Update()
		{
			OptionsMenu.Tick();
			if (!ModConfig.Enabled.Value)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead())
			{
				_seenPlayerAt = -1f;
				_baselined = false;
				_catchUpPolls = 0;
			}
			else if (_seenPlayerAt < 0f)
			{
				_seenPlayerAt = Time.unscaledTime;
			}
			else
			{
				if (Time.unscaledTime < _seenPlayerAt + 1.5f)
				{
					return;
				}
				if (!_baselined)
				{
					ShieldService.Baseline(localPlayer);
					_baselined = true;
					ShieldService.Apply();
					_catchUpPolls = 3;
					_nextPoll = Time.unscaledTime + 0.25f;
				}
				else if (_catchUpPolls > 0)
				{
					if (!(Time.unscaledTime < _nextPoll))
					{
						_nextPoll = Time.unscaledTime + 0.25f;
						_catchUpPolls--;
						ShieldService.Tick(localPlayer);
					}
				}
				else if (!(Time.unscaledTime < _nextPoll))
				{
					_nextPoll = Time.unscaledTime + 0.75f;
					ShieldService.Tick(localPlayer);
				}
			}
		}

		private void OnGUI()
		{
			OptionsMenu.Draw();
		}
	}
	internal static class PatchHelpers
	{
		internal static bool IsLocal(Humanoid humanoid)
		{
			if ((Object)(object)humanoid != (Object)null && (Object)(object)Player.m_localPlayer != (Object)null)
			{
				return (Object)(object)humanoid == (Object)(object)Player.m_localPlayer;
			}
			return false;
		}

		internal static bool ModEnabled()
		{
			if (ModConfig.Enabled != null)
			{
				return ModConfig.Enabled.Value;
			}
			return false;
		}

		internal static bool SheathUnequipEnabled()
		{
			if (ModEnabled() && ModConfig.UnequipOnSheath != null)
			{
				return ModConfig.UnequipOnSheath.Value;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Humanoid), "HideHandItems")]
	internal static class PatchHideHandItems
	{
		private static void Postfix(Humanoid __instance, bool onlyRightHand)
		{
			if (!onlyRightHand && PatchHelpers.IsLocal(__instance) && PatchHelpers.SheathUnequipEnabled())
			{
				ShieldService.RetractShieldWhileSheathed(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(Humanoid), "ShowHandItems")]
	internal static class PatchShowHandItems
	{
		private static void Prefix(Humanoid __instance, bool onlyRightHand)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Invalid comparison between Unknown and I4
			if (!onlyRightHand && PatchHelpers.IsLocal(__instance) && PatchHelpers.SheathUnequipEnabled())
			{
				ItemData hiddenLeftItem = __instance.m_hiddenLeftItem;
				if (hiddenLeftItem?.m_shared != null && (int)hiddenLeftItem.m_shared.m_itemType == 5)
				{
					__instance.m_hiddenLeftItem = null;
				}
			}
		}

		private static void Postfix(Humanoid __instance, bool onlyRightHand)
		{
			if (!onlyRightHand && PatchHelpers.IsLocal(__instance) && PatchHelpers.ModEnabled())
			{
				ShieldService.NotifyHandsShown();
				ShieldService.Apply();
			}
		}
	}
	[HarmonyPatch(typeof(Humanoid), "EquipItem")]
	internal static class PatchEquipItem
	{
		private static void Postfix(Humanoid __instance)
		{
			ShieldService.OnLocalEquipmentChanged(__instance);
		}
	}
	[HarmonyPatch(typeof(Humanoid), "UnequipItem")]
	internal static class PatchUnequipItem
	{
		private static void Prefix(Humanoid __instance, ItemData item)
		{
			if (!ShieldService.InternalChange && PatchHelpers.ModEnabled() && PatchHelpers.IsLocal(__instance) && IsThrowableOneHander(item))
			{
				Attack currentAttack = __instance.m_currentAttack;
				if (((Character)__instance).InAttack() || (currentAttack != null && currentAttack.m_weapon == item))
				{
					ShieldService.NotifyThrownWeapon();
				}
			}
		}

		private static void Postfix(Humanoid __instance)
		{
			ShieldService.OnLocalEquipmentChanged(__instance);
		}

		private static bool IsThrowableOneHander(ItemData item)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Invalid comparison between Unknown and I4
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Invalid comparison between Unknown and I4
			if (item?.m_shared == null || (int)item.m_shared.m_itemType != 3)
			{
				return false;
			}
			if ((int)item.m_shared.m_skillType == 5)
			{
				return true;
			}
			if (!HasProjectile(item.m_shared.m_attack))
			{
				return HasProjectile(item.m_shared.m_secondaryAttack);
			}
			return true;
		}

		private static bool HasProjectile(Attack attack)
		{
			if (attack != null)
			{
				return (Object)(object)attack.m_attackProjectile != (Object)null;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Attack), "OnAttackTrigger")]
	internal static class PatchOnAttackTrigger
	{
		private static void Prefix(Attack __instance)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Invalid comparison between Unknown and I4
			if (__instance != null && PatchHelpers.ModEnabled() && !((Object)(object)__instance.m_attackProjectile == (Object)null) && PatchHelpers.IsLocal(__instance.m_character))
			{
				ItemData weapon = __instance.m_weapon;
				if (weapon?.m_shared != null && (int)weapon.m_shared.m_itemType == 3)
				{
					ShieldService.NotifyThrownWeapon();
				}
			}
		}
	}
	internal static class ShieldService
	{
		internal static bool InternalChange;

		private static bool _previousWasRangedOrTwoHanded;

		private static ItemData _lastRight;

		private static bool _wasSheathed;

		private static float _ignoreHotbarUnequipUntil;

		internal static void Baseline(Player player)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			ItemData val = (_lastRight = ((Humanoid)player).GetRightItem());
			_wasSheathed = IsSheathed((Humanoid)(object)player);
			_previousWasRangedOrTwoHanded = val?.m_shared != null && IsRangedOrTwoHanded(val.m_shared.m_itemType);
		}

		internal static void NotifyHandsShown()
		{
			_ignoreHotbarUnequipUntil = Time.unscaledTime + 0.35f;
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer != (Object)null)
			{
				_lastRight = ((Humanoid)localPlayer).GetRightItem();
				_wasSheathed = IsSheathed((Humanoid)(object)localPlayer);
			}
		}

		internal static void NotifyThrownWeapon()
		{
			_ignoreHotbarUnequipUntil = Time.unscaledTime + 1f;
		}

		internal static void OnLocalEquipmentChanged(Humanoid humanoid)
		{
			if (!InternalChange && PatchHelpers.ModEnabled() && PatchHelpers.IsLocal(humanoid))
			{
				Player val = (Player)(object)((humanoid is Player) ? humanoid : null);
				if (!((Object)(object)val == (Object)null))
				{
					Tick(val);
				}
			}
		}

		internal static void Tick(Player player)
		{
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Invalid comparison between Unknown and I4
			ItemData lastRight = _lastRight;
			ItemData rightItem = ((Humanoid)player).GetRightItem();
			ItemData leftItem = ((Humanoid)player).GetLeftItem();
			bool flag = IsSheathed((Humanoid)(object)player);
			if (ModConfig.UnequipOnSheath.Value && flag && ShieldStillAttachedWhileSheathed((Humanoid)(object)player))
			{
				_lastRight = rightItem;
				_wasSheathed = true;
				Apply();
				return;
			}
			bool num = rightItem != lastRight;
			bool flag2 = flag != _wasSheathed;
			if (!num && !flag2)
			{
				return;
			}
			if (ModConfig.UnequipOnHotbarDeselect.Value && Time.unscaledTime >= _ignoreHotbarUnequipUntil && rightItem == null && !flag && lastRight != null && IsOneHandedWeapon(lastRight) && leftItem?.m_shared != null && (int)leftItem.m_shared.m_itemType == 5)
			{
				_lastRight = rightItem;
				_wasSheathed = flag;
				UnequipSilent((Humanoid)(object)player, leftItem);
				return;
			}
			if (rightItem?.m_shared != null && IsRangedOrTwoHanded(rightItem.m_shared.m_itemType))
			{
				_previousWasRangedOrTwoHanded = true;
			}
			_lastRight = rightItem;
			_wasSheathed = flag;
			Apply();
		}

		internal static void ReapplyFromMenu()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Invalid comparison between Unknown and I4
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null) && !((Character)localPlayer).IsDead())
			{
				ItemData leftItem = ((Humanoid)localPlayer).GetLeftItem();
				if (leftItem?.m_shared != null && (int)leftItem.m_shared.m_itemType == 5)
				{
					UnequipSilent((Humanoid)(object)localPlayer, leftItem);
				}
				Apply();
			}
		}

		internal static void Apply()
		{
			if (!ModConfig.Enabled.Value || InternalChange)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead())
			{
				return;
			}
			try
			{
				ApplyInner(localPlayer);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("SmartShield apply failed: " + ex.Message));
			}
		}

		private static void ApplyInner(Player player)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Invalid comparison between Unknown and I4
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Invalid comparison between Unknown and I4
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Invalid comparison between Unknown and I4
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Invalid comparison between Unknown and I4
			ItemData rightItem = ((Humanoid)player).GetRightItem();
			ItemData leftItem = ((Humanoid)player).GetLeftItem();
			bool previousWasRangedOrTwoHanded = _previousWasRangedOrTwoHanded;
			_previousWasRangedOrTwoHanded = rightItem?.m_shared != null && IsRangedOrTwoHanded(rightItem.m_shared.m_itemType);
			if (IsSheathed((Humanoid)(object)player))
			{
				if (ModConfig.UnequipOnSheath.Value)
				{
					RetractShieldWhileSheathed((Humanoid)(object)player);
				}
			}
			else
			{
				if (rightItem == null)
				{
					return;
				}
				ItemType itemType = rightItem.m_shared.m_itemType;
				if (IsRangedOrTwoHanded(itemType))
				{
					if (ModConfig.UnequipOnTwoHanded.Value && leftItem?.m_shared != null && (int)leftItem.m_shared.m_itemType == 5)
					{
						UnequipSilent((Humanoid)(object)player, leftItem);
					}
				}
				else
				{
					if ((int)itemType != 3 || !WeaponAllowed(rightItem))
					{
						return;
					}
					if (!ModConfig.EquipShieldWithAxe.Value && IsOneHandedAxe(rightItem))
					{
						if (leftItem?.m_shared != null && (int)leftItem.m_shared.m_itemType == 5)
						{
							UnequipSilent((Humanoid)(object)player, leftItem);
						}
						return;
					}
					if (!ModConfig.EquipShieldWithButcherKnife.Value && IsButcherKnife(rightItem))
					{
						if (leftItem?.m_shared != null && (int)leftItem.m_shared.m_itemType == 5)
						{
							UnequipSilent((Humanoid)(object)player, leftItem);
						}
						return;
					}
					bool flag = ModConfig.AutoEquipOnOneHanded.Value;
					if (!flag && ModConfig.EquipAfterRanged.Value && previousWasRangedOrTwoHanded)
					{
						flag = true;
					}
					if (flag && leftItem == null)
					{
						ItemData val = SelectShield(player);
						if (val != null)
						{
							EquipSilent((Humanoid)(object)player, val);
						}
					}
				}
			}
		}

		internal static bool IsSheathed(Humanoid humanoid)
		{
			if ((Object)(object)humanoid != (Object)null && humanoid.GetRightItem() == null)
			{
				return humanoid.m_hiddenRightItem != null;
			}
			return false;
		}

		internal static bool ShieldStillAttachedWhileSheathed(Humanoid humanoid)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Invalid comparison between Unknown and I4
			if (!IsSheathed(humanoid))
			{
				return false;
			}
			ItemData leftItem = humanoid.GetLeftItem();
			if (leftItem?.m_shared != null && (int)leftItem.m_shared.m_itemType == 5)
			{
				return true;
			}
			ItemData hiddenLeftItem = humanoid.m_hiddenLeftItem;
			if (hiddenLeftItem?.m_shared != null && (int)hiddenLeftItem.m_shared.m_itemType == 5)
			{
				return true;
			}
			VisEquipment visEquipment = humanoid.m_visEquipment;
			if ((Object)(object)visEquipment != (Object)null)
			{
				if (!((Object)(object)visEquipment.m_leftBackItemInstance != (Object)null))
				{
					return visEquipment.m_currentLeftBackItemHash != 0;
				}
				return true;
			}
			return false;
		}

		internal static void RetractShieldWhileSheathed(Humanoid humanoid)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Invalid comparison between Unknown and I4
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Invalid comparison between Unknown and I4
			if ((Object)(object)humanoid == (Object)null)
			{
				return;
			}
			bool flag = false;
			ItemData leftItem = humanoid.GetLeftItem();
			if (leftItem?.m_shared != null && (int)leftItem.m_shared.m_itemType == 5)
			{
				UnequipSilent(humanoid, leftItem);
				flag = true;
			}
			ItemData hiddenLeftItem = humanoid.m_hiddenLeftItem;
			if (hiddenLeftItem?.m_shared != null && (int)hiddenLeftItem.m_shared.m_itemType == 5)
			{
				humanoid.m_hiddenLeftItem = null;
				flag = true;
			}
			VisEquipment visEquipment = humanoid.m_visEquipment;
			if ((Object)(object)visEquipment == (Object)null)
			{
				return;
			}
			bool flag2 = (Object)(object)visEquipment.m_leftBackItemInstance != (Object)null || visEquipment.m_currentLeftBackItemHash != 0;
			if (flag || flag2)
			{
				visEquipment.SetLeftBackItem(0, 0, 0);
				if ((Object)(object)visEquipment.m_leftBackItemInstance != (Object)null)
				{
					Object.Destroy((Object)(object)visEquipment.m_leftBackItemInstance);
					visEquipment.m_leftBackItemInstance = null;
				}
				visEquipment.m_currentLeftBackItemHash = 0;
				visEquipment.m_currentLeftBackItemVariant = 0;
				visEquipment.m_currentLeftBackItemQuality = 0;
				visEquipment.UpdateEquipmentVisuals();
			}
		}

		private static bool IsOneHandedWeapon(ItemData item)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Invalid comparison between Unknown and I4
			if (item?.m_shared != null)
			{
				return (int)item.m_shared.m_itemType == 3;
			}
			return false;
		}

		private static bool IsOneHandedAxe(ItemData item)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Invalid comparison between Unknown and I4
			if (item?.m_shared != null)
			{
				return (int)item.m_shared.m_skillType == 7;
			}
			return false;
		}

		private static bool IsButcherKnife(ItemData item)
		{
			return PrefabName(item).Equals("KnifeButcher", StringComparison.OrdinalIgnoreCase);
		}

		private static bool IsRangedOrTwoHanded(ItemType type)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Invalid comparison between Unknown and I4
			if ((int)type != 4 && (int)type != 14 && (int)type != 22)
			{
				return (int)type == 20;
			}
			return true;
		}

		private static bool WeaponAllowed(ItemData weapon)
		{
			string[] allowedWeaponTokens = ModConfig.AllowedWeaponTokens;
			if (allowedWeaponTokens.Length == 0)
			{
				return true;
			}
			string value = PrefabName(weapon);
			string value2 = ((object)Unsafe.As<ItemType, ItemType>(ref weapon.m_shared.m_itemType)/*cast due to .constrained prefix*/).ToString();
			string value3 = ((object)Unsafe.As<SkillType, SkillType>(ref weapon.m_shared.m_skillType)/*cast due to .constrained prefix*/).ToString();
			foreach (string text in allowedWeaponTokens)
			{
				if (text.Equals(value2, StringComparison.OrdinalIgnoreCase) || text.Equals(value3, StringComparison.OrdinalIgnoreCase) || text.Equals(value, StringComparison.OrdinalIgnoreCase))
				{
					return true;
				}
			}
			return false;
		}

		private static ItemData SelectShield(Player player)
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Invalid comparison between Unknown and I4
			Inventory inventory = ((Humanoid)player).GetInventory();
			if (inventory == null)
			{
				return null;
			}
			List<ItemData> inventory2 = inventory.m_inventory;
			if (inventory2 == null || inventory2.Count == 0)
			{
				return null;
			}
			HashSet<string> blacklistSet = ModConfig.BlacklistSet;
			bool flag = blacklistSet != null && blacklistSet.Count > 0;
			string selectionModeNormalized = ModConfig.SelectionModeNormalized;
			string preferredShieldNormalized = ModConfig.PreferredShieldNormalized;
			bool flag2 = selectionModeNormalized.Equals("Preferred", StringComparison.OrdinalIgnoreCase) && preferredShieldNormalized.Length > 0;
			bool flag3 = selectionModeNormalized.Equals("First", StringComparison.OrdinalIgnoreCase);
			ItemData val = null;
			float num = float.MinValue;
			for (int i = 0; i < inventory2.Count; i++)
			{
				ItemData val2 = inventory2[i];
				if (val2?.m_shared == null || (int)val2.m_shared.m_itemType != 5)
				{
					continue;
				}
				string text = PrefabName(val2);
				if (flag && blacklistSet.Contains(text))
				{
					continue;
				}
				if (flag2)
				{
					if (text.Equals(preferredShieldNormalized, StringComparison.OrdinalIgnoreCase))
					{
						return val2;
					}
					continue;
				}
				if (flag3)
				{
					return val2;
				}
				float num2 = val2.m_shared.m_blockPower + val2.m_shared.m_timedBlockBonus;
				if (val == null || num2 > num)
				{
					val = val2;
					num = num2;
				}
			}
			if (val == null && flag2)
			{
				return SelectFallbackBest(inventory2, blacklistSet, flag);
			}
			return val;
		}

		private static ItemData SelectFallbackBest(List<ItemData> items, HashSet<string> banned, bool hasBan)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			ItemData val = null;
			float num = float.MinValue;
			for (int i = 0; i < items.Count; i++)
			{
				ItemData val2 = items[i];
				if (val2?.m_shared != null && (int)val2.m_shared.m_itemType == 5 && (!hasBan || !banned.Contains(PrefabName(val2))))
				{
					float num2 = val2.m_shared.m_blockPower + val2.m_shared.m_timedBlockBonus;
					if (val == null || num2 > num)
					{
						val = val2;
						num = num2;
					}
				}
			}
			return val;
		}

		private static void EquipSilent(Humanoid player, ItemData item)
		{
			InternalChange = true;
			try
			{
				player.EquipItem(item, false);
			}
			finally
			{
				InternalChange = false;
			}
		}

		private static void UnequipSilent(Humanoid player, ItemData item)
		{
			InternalChange = true;
			try
			{
				player.UnequipItem(item, false);
			}
			finally
			{
				InternalChange = false;
			}
		}

		private static string PrefabName(ItemData item)
		{
			if ((Object)(object)item.m_dropPrefab != (Object)null)
			{
				return ((Object)item.m_dropPrefab).name;
			}
			return item.m_shared.m_name ?? "";
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}