Decompiled source of KikisKit v1.0.0

plugins/KikisKit.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using Zorro.Core;
using Zorro.Core.Serizalization;

[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("KikisKit")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("KikisKit")]
[assembly: AssemblyTitle("KikisKit")]
[assembly: AssemblyVersion("1.0.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 KikisKit
{
	[BepInPlugin("kikiskit.peak.kit", "Kikis Kit", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private class KitItem
		{
			public int id;

			public string display;

			public string internalName;

			public Texture2D icon;

			public int rank;

			public string sortKey;
		}

		public const string PluginGuid = "kikiskit.peak.kit";

		public const string PluginName = "Kikis Kit";

		public const string PluginVersion = "1.0.0";

		internal static Plugin Instance;

		private ConfigEntry<KeyCode> _menuKey;

		private ConfigEntry<bool> _kitEnabled;

		private ConfigEntry<bool> _giveBackpack;

		private ConfigEntry<bool> _repeatCampfire;

		private ConfigEntry<bool> _rekitRevive;

		private ConfigEntry<int> _backpackKind;

		private readonly ConfigEntry<int>[] _pocketCfg = new ConfigEntry<int>[3];

		private readonly ConfigEntry<int>[] _packCfg = new ConfigEntry<int>[4];

		private static readonly string[] PackKindLabels = new string[5] { "None", "Backpack", "Fannypack", "Jetpack", "Rocketpack" };

		private const int CFG_ID0 = -1;

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

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

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

		private bool _wasOnIsland;

		private float _nextScan;

		private float _rearmAt;

		private bool _dripping;

		private const float SCAN_INTERVAL = 5f;

		private const int PER_TICK = 4;

		private const int PER_TICK_REKIT = 2;

		private const float JOIN_DELAY = 5f;

		private const float BACKLOG_INTERVAL = 0.5f;

		private const float CAMPFIRE_DELAY = 5f;

		private const float FRAME_BUDGET = 0.08f;

		private readonly List<Campfire> _litFires = new List<Campfire>();

		private static readonly MethodInfo SlotDataSetter = AccessTools.PropertySetter(typeof(ItemSlot), "data");

		private readonly HashSet<Guid> _bpSkipSeen = new HashSet<Guid>();

		private const float BACKPACK_NEARBY = 10f;

		private readonly Backpack[] _packPrefab = (Backpack[])(object)new Backpack[5];

		private readonly bool[] _packProbed = new bool[5];

		private List<KitItem> _items;

		private static readonly HashSet<int> HiddenIds = new HashSet<int>
		{
			13, 14, 31, 34, 59, 78, 95, 106, 111, 116,
			124, 125, 126, 139, 153, 156, 163, 164
		};

		private static readonly Dictionary<int, string> Renames = new Dictionary<int, string>
		{
			{ 115, "Book of Bones" },
			{ 180, "Clone Amulet" },
			{ 182, "Healing Amulet" },
			{ 179, "Stamina Amulet" },
			{ 170, "Double Jump Amulet" },
			{ 192, "Void Launcher" },
			{ 184, "Early Worm" },
			{ 176, "Auto Parachute" },
			{ 191, "Scoutmaster Soul" },
			{ 165, "Snowball" },
			{ 173, "Ritual Dagger" },
			{ 183, "Scout's Honor" },
			{ 185, "Frog Legs" },
			{ 63, "Rope Cannon" },
			{ 65, "Rope Spool" },
			{ 1, "Anti-Rope Spool" },
			{ 64, "Anti-Rope Cannon" },
			{ 88, "Cluster Shroom" },
			{ 84, "Cluster Shroom (Poison)" },
			{ 93, "Bugle Shroom" },
			{ 89, "Bugle Shroom (Poison)" },
			{ 102, "Button Shroom" },
			{ 97, "Button Shroom (Poison)" },
			{ 66, "Scout Cookies" },
			{ 157, "Scout Cookies (Vanilla)" },
			{ 100, "Rescue Claw" },
			{ 167, "Rescue Claw (Infinite)" },
			{ 113, "Cheat Compass" },
			{ 193, "Cheat Compass 2" },
			{ 177, "Raven Egg" },
			{ 91, "Blue Berrynana Peel" },
			{ 92, "Brown Berrynana Peel" },
			{ 39, "Pink Berrynana Peel" },
			{ 94, "Yellow Berrynana Peel" }
		};

		private static readonly Dictionary<string, Texture2D> IconCache = new Dictionary<string, Texture2D>(StringComparer.OrdinalIgnoreCase);

		private bool _show;

		private float _toggleAt = -10f;

		private Rect _win = new Rect(80f, 60f, 768f, 600f);

		private bool _winPlaced;

		private static readonly Color BgWindow = new Color(0.847f, 0.82f, 0.722f, 1f);

		private static readonly Color BgTitle = new Color(0.36f, 0.53f, 0.37f, 1f);

		private static readonly Color TxtTitle = new Color(0.94f, 0.93f, 0.85f, 1f);

		private static readonly Color BgRow = new Color(0.9f, 0.88f, 0.79f, 1f);

		private static readonly Color BgSlot = new Color(0.78f, 0.75f, 0.66f, 1f);

		private static readonly Color BgSlotEmpty = new Color(0.86f, 0.84f, 0.76f, 1f);

		private static readonly Color TxtLabel = new Color(0.16f, 0.17f, 0.13f, 1f);

		private static readonly Color TxtHeader = new Color(0.22f, 0.42f, 0.26f, 1f);

		private static readonly Color TxtButton = new Color(0.97f, 0.97f, 0.95f, 1f);

		private static readonly Color ColOn = new Color(0.26f, 0.68f, 0.4f);

		private static readonly Color ColOff = new Color(0.47f, 0.44f, 0.39f);

		private static readonly Color ColActive = new Color(0.3f, 0.5f, 0.33f);

		private static readonly Color ColWarn = new Color(0.75f, 0.28f, 0.24f, 1f);

		private bool _stylesReady;

		private GUIStyle _windowStyle;

		private GUIStyle _titleStyle;

		private GUIStyle _labelStyle;

		private GUIStyle _headerStyle;

		private GUIStyle _warnStyle;

		private GUIStyle _buttonStyle;

		private GUIStyle _rowStyle;

		private GUIStyle _iconStyle;

		private GUIStyle _iconEmptyStyle;

		private GUIStyle _numStyle;

		private GUIStyle _playerStyle;

		private GUIStyle _fieldStyle;

		private GUIStyle _dimStyle;

		private const float WIN_W = 768f;

		private const float BOTTOM_H = 48f;

		private const float EXTRA_H = 120f;

		private Vector2 _scroll;

		private Vector2 _pickScroll;

		private int _target = -1;

		private bool _backOpen;

		private string _filter = "";

		private float _listH = 420f;

		private float _listTop = 40f;

		private float _listW;

		private string _status;

		private float _statusUntil;

		private const float SLOT_PX = 56f;

		private const float SLOT_GAP = 8f;

		private const float BADGE_PX = 18f;

		private const int PLAYER_COLS = 10;

		private const float PLAYER_GAP = 4f;

		private const float PLAYER_H = 26f;

		private const int PICK_COLS = 14;

		private const float PICK_TILE = 54f;

		private const float PICK_GAP = 4f;

		private const float SCROLLBAR_W = 18f;

		private static Texture2D _badgeTex;

		private static Texture2D _badgeXTex;

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

		private float _fitW = -1f;

		private KeyCode MenuKey
		{
			get
			{
				//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)
				if (_menuKey == null || (int)_menuKey.Value == 0)
				{
					return (KeyCode)285;
				}
				return _menuKey.Value;
			}
		}

		internal bool MenuOpen => _show;

		private void Awake()
		{
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected O, but got Unknown
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Expected O, but got Unknown
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			_menuKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Hotkey", "Menu Key", (KeyCode)285, "Opens and closes the Kikis Kit menu.");
			_kitEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("StarterKit", "KitEnabled", true, Hidden("Hand out the starter kit (host only)."));
			_giveBackpack = ((BaseUnityPlugin)this).Config.Bind<bool>("StarterKit", "GiveBackpack", true, Hidden("Give and equip a back item. If false, the backpack slots are ignored."));
			_backpackKind = ((BaseUnityPlugin)this).Config.Bind<int>("StarterKit", "BackpackKind", 1, new ConfigDescription("Which back item: 1 = Backpack, 2 = Fannypack, 3 = Jetpack, 4 = Rocketpack. Jetpack and Rocketpack carry no items.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 4), new object[1] { "Hidden" }));
			_repeatCampfire = ((BaseUnityPlugin)this).Config.Bind<bool>("StarterKit", "RepeatOnCampfire", false, Hidden("Hand the kit out again whenever a campfire is lit."));
			_rekitRevive = ((BaseUnityPlugin)this).Config.Bind<bool>("StarterKit", "AutoRekitRevive", false, Hidden("Hand the kit out again after a revive, once the player is awake."));
			for (int i = 0; i < 3; i++)
			{
				_pocketCfg[i] = ((BaseUnityPlugin)this).Config.Bind<int>("StarterKit", "PocketSlot" + (i + 1) + "ItemID", 0, Hidden("Item id for pocket slot " + (i + 1) + " (0 = empty, -1 = Airline Food, whose real id is 0)."));
			}
			for (int j = 0; j < 4; j++)
			{
				_packCfg[j] = ((BaseUnityPlugin)this).Config.Bind<int>("StarterKit", "BackpackSlot" + (j + 1) + "ItemID", 0, Hidden("Item id for backpack slot " + (j + 1) + " (0 = empty, -1 = Airline Food, whose real id is 0)."));
			}
			Harmony h = new Harmony("kikiskit.peak.kit");
			Hook(h, AccessTools.Method(typeof(Campfire), "Light_Rpc", (Type[])null, (Type[])null), null, typeof(CampfirePatch));
			string[] array = new string[3] { "RPCA_Die", "RPCA_SetDead", "RPCA_Zombify" };
			foreach (string text in array)
			{
				Hook(h, AccessTools.Method(typeof(Character), text, (Type[])null, (Type[])null), null, typeof(DownPatch));
			}
			Hook(h, AccessTools.Method(typeof(CharacterInput), "Sample", new Type[1] { typeof(bool) }, (Type[])null), typeof(MenuInputPatch), typeof(MenuInputPatch));
			Hook(h, AccessTools.Method(typeof(CursorHandler), "Update", (Type[])null, (Type[])null), null, typeof(MenuCursorPatch));
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Kikis Kit 1.0.0 loaded. Menu key: " + ((object)MenuKey/*cast due to .constrained prefix*/).ToString()));
		}

		private static ConfigDescription Hidden(string text)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			return new ConfigDescription(text, (AcceptableValueBase)null, new object[1] { "Hidden" });
		}

		private void Hook(Harmony h, MethodInfo target, Type prefixType, Type postfixType)
		{
			//IL_0032: 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)
			if (target == null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"hook target missing - that part is off, everything else runs");
				return;
			}
			try
			{
				HarmonyMethod val = ((!(prefixType != null)) ? ((HarmonyMethod)null) : new HarmonyMethod(prefixType.GetMethod("Prefix")));
				HarmonyMethod val2 = ((!(postfixType != null)) ? ((HarmonyMethod)null) : new HarmonyMethod(postfixType.GetMethod("Postfix")));
				h.Patch((MethodBase)target, val, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("hook " + target.Name + " failed: " + ex.Message));
			}
		}

		private void Update()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown(MenuKey))
			{
				ToggleMenu();
			}
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			if (realtimeSinceStartup >= _nextScan)
			{
				_nextScan = realtimeSinceStartup + 5f;
				KitScan(realtimeSinceStartup);
			}
		}

		private void KitScan(float now)
		{
			try
			{
				if (_kitEnabled == null || !_kitEnabled.Value || !PhotonNetwork.IsMasterClient)
				{
					return;
				}
				bool flag = false;
				try
				{
					flag = GameHandler.IsOnIsland;
				}
				catch
				{
					flag = false;
				}
				if (!flag)
				{
					_wasOnIsland = false;
					return;
				}
				if (!_wasOnIsland)
				{
					_wasOnIsland = true;
					_served.Clear();
					_awaitRevive.Clear();
					((BaseUnityPlugin)this).Logger.LogInfo((object)"run started - starter kit is available to everyone");
				}
				if (_rearmAt > 0f && now >= _rearmAt)
				{
					_rearmAt = 0f;
					_dripping = true;
					_served.Clear();
				}
				if (_rearmAt > 0f)
				{
					return;
				}
				List<Character> allCharacters = Character.AllCharacters;
				if (allCharacters == null)
				{
					return;
				}
				if (_dripping && Time.unscaledDeltaTime > 0.08f)
				{
					_nextScan = now + 0.5f;
					return;
				}
				int num = (_dripping ? 2 : 4);
				int num2 = 0;
				bool flag2 = false;
				for (int i = 0; i < allCharacters.Count; i++)
				{
					Character val = allCharacters[i];
					if ((Object)(object)val == (Object)null || val.isBot || (Object)(object)val.data == (Object)null || val.data.dead || !val.data.fullyConscious || val.refs == null || (Object)(object)val.refs.view == (Object)null)
					{
						continue;
					}
					try
					{
						if ((Object)(object)val.data.carrier != (Object)null || (Object)(object)val.data.carriedPlayer != (Object)null)
						{
							continue;
						}
						goto IL_01b9;
					}
					catch
					{
						goto IL_01b9;
					}
					IL_01b9:
					int ownerActorNr = val.refs.view.OwnerActorNr;
					if (_served.Contains(ownerActorNr))
					{
						continue;
					}
					flag2 = true;
					if (!_dripping || _awaitRevive.Contains(ownerActorNr))
					{
						if (!_eligibleSince.TryGetValue(ownerActorNr, out var value))
						{
							if (_eligibleSince.Count > 200)
							{
								_eligibleSince.Clear();
							}
							_eligibleSince[ownerActorNr] = now;
							value = now;
						}
						if (now - value < 5f)
						{
							continue;
						}
					}
					if (GiveKit(val))
					{
						_served.Add(ownerActorNr);
						_awaitRevive.Remove(ownerActorNr);
					}
					if (++num2 >= num)
					{
						_nextScan = now + 0.5f;
						return;
					}
				}
				if (!flag2)
				{
					_dripping = false;
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("KitScan failed: " + ex.Message));
			}
		}

		internal void OnCampfireLit(Campfire fire, bool updateSegment)
		{
			try
			{
				if (!((Object)(object)fire == (Object)null) && !_litFires.Contains(fire))
				{
					_litFires.Add(fire);
					if (_litFires.Count > 16)
					{
						_litFires.RemoveAt(0);
					}
					if (updateSegment && _repeatCampfire.Value && _kitEnabled.Value && PhotonNetwork.IsMasterClient)
					{
						_rearmAt = Time.realtimeSinceStartup + 5f;
					}
				}
			}
			catch
			{
			}
		}

		internal void OnCharacterDown(Character c)
		{
			try
			{
				if (_rekitRevive == null || !_rekitRevive.Value || !_kitEnabled.Value || !PhotonNetwork.IsMasterClient || (Object)(object)c == (Object)null)
				{
					return;
				}
				try
				{
					if (c.isBot || c.isZombie || c.isScoutmaster)
					{
						return;
					}
				}
				catch
				{
					return;
				}
				if (!((Object)(object)c.data == (Object)null) && (c.data.dead || c.data.zombified) && c.refs != null && !((Object)(object)c.refs.view == (Object)null))
				{
					int ownerActorNr = c.refs.view.OwnerActorNr;
					_eligibleSince.Remove(ownerActorNr);
					_awaitRevive.Add(ownerActorNr);
					_served.Remove(ownerActorNr);
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("OnCharacterDown failed: " + ex.Message));
			}
		}

		private bool GiveKit(Character c)
		{
			try
			{
				Player val = (((Object)(object)c != (Object)null) ? c.player : null);
				if ((Object)(object)val == (Object)null)
				{
					return false;
				}
				bool value = _giveBackpack.Value;
				List<Item> list = new List<Item>();
				if (value)
				{
					EquipBackpack(val, c);
				}
				AddPockets(val, list);
				if (value)
				{
					AddBackpackItems(val, list);
				}
				Sync(val);
				PlaceInFront(c, list);
				((BaseUnityPlugin)this).Logger.LogInfo((object)("handed the starter kit to " + PlainName(SafeName(c)) + ((list.Count > 0) ? (" (" + list.Count + " placed in front - their slot held something else)") : "")));
				return true;
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("GiveKit failed: " + ex.Message));
				return false;
			}
		}

		private void EquipBackpack(Player p, Character c)
		{
			//IL_000e: 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_00e4: Expected O, but got Unknown
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: 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_0073: 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_0156: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (p.backpackSlot == null || (int)p.backpackSlot.backpackType != 0)
				{
					return;
				}
				Guid guid = Guid.Empty;
				try
				{
					if (((ItemSlot)p.backpackSlot).data != null)
					{
						guid = ((ItemSlot)p.backpackSlot).data.guid;
					}
				}
				catch
				{
				}
				if (guid != Guid.Empty)
				{
					Item val = WorldItemWithGuid(guid);
					if ((Object)(object)val != (Object)null)
					{
						float num = float.MaxValue;
						try
						{
							num = Vector3.Distance(val.transform.position, c.Center);
						}
						catch
						{
						}
						if (num <= 10f)
						{
							if (_bpSkipSeen.Add(guid))
							{
								((BaseUnityPlugin)this).Logger.LogInfo((object)("no backpack handed out - the last one is lying " + num.ToString("F0") + " m away"));
							}
							return;
						}
						_bpSkipSeen.Remove(guid);
					}
				}
				ItemInstanceData val2 = new ItemInstanceData(Guid.NewGuid());
				ItemInstanceDataHandler.AddInstanceData(val2);
				BackpackType want = PackType();
				Backpack val3 = PackPrefab(want);
				if ((Object)(object)val3 != (Object)null)
				{
					p.backpackSlot.backpackType = val3.backpackType;
					((ItemSlot)p.backpackSlot).SetItem((Item)(object)val3, val2);
				}
				else
				{
					if (!(SlotDataSetter != null))
					{
						return;
					}
					try
					{
						SlotDataSetter.Invoke(p.backpackSlot, new object[1] { val2 });
					}
					catch
					{
						return;
					}
					p.backpackSlot.backpackType = (BackpackType)1;
				}
				BackpackData val4 = default(BackpackData);
				if (!((ItemSlot)p.backpackSlot).data.TryGetDataEntry<BackpackData>((DataEntryKey)7, ref val4) || val4 == null)
				{
					((ItemSlot)p.backpackSlot).data.RegisterNewEntry<BackpackData>((DataEntryKey)7);
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("EquipBackpack failed: " + ex.Message));
			}
		}

		private static Item WorldItemWithGuid(Guid g)
		{
			try
			{
				if (g == Guid.Empty)
				{
					return null;
				}
				Item[] array = Object.FindObjectsByType<Item>((FindObjectsSortMode)0);
				foreach (Item val in array)
				{
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					try
					{
						if (val.data != null && val.data.guid == g)
						{
							return val;
						}
					}
					catch
					{
					}
				}
			}
			catch
			{
			}
			return null;
		}

		private unsafe Backpack PackPrefab(BackpackType want)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Expected I4, but got Unknown
			//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)
			int num = (int)want;
			if (num <= 0 || num >= _packProbed.Length)
			{
				return null;
			}
			if (_packProbed[num])
			{
				return _packPrefab[num];
			}
			_packProbed[num] = true;
			try
			{
				Item val = default(Item);
				for (int i = 0; i <= 1000; i++)
				{
					if (ItemDatabase.TryGetItem((ushort)i, ref val) && !((Object)(object)val == (Object)null))
					{
						Backpack val2 = (Backpack)(object)((val is Backpack) ? val : null);
						if ((Object)(object)val2 != (Object)null && val2.backpackType == want)
						{
							_packPrefab[num] = val2;
							break;
						}
					}
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("back item lookup failed (" + ((object)(*(BackpackType*)(&want))/*cast due to .constrained prefix*/).ToString() + "): " + ex.Message));
			}
			return _packPrefab[num];
		}

		private BackpackType PackType()
		{
			int num = ((_backpackKind == null) ? 1 : _backpackKind.Value);
			if (num < 1 || num > 4)
			{
				num = 1;
			}
			return (BackpackType)num;
		}

		private int PackSlots()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Backpack val = PackPrefab(PackType());
				return ((Object)(object)val != (Object)null) ? Mathf.Clamp(val.slotCount, 0, 4) : 4;
			}
			catch
			{
				return 4;
			}
		}

		private void ClearPackSlotsBeyondCapacity()
		{
			for (int i = PackSlots(); i < 4; i++)
			{
				if (_packCfg[i] != null && _packCfg[i].Value != 0)
				{
					_packCfg[i].Value = 0;
				}
			}
		}

		private static bool CfgItem(int cfgValue, out ushort itemId)
		{
			itemId = 0;
			if (cfgValue == -1)
			{
				return true;
			}
			if (cfgValue <= 0 || cfgValue > 65535)
			{
				return false;
			}
			itemId = (ushort)cfgValue;
			return true;
		}

		private static int ItemToCfg(int itemId)
		{
			if (itemId != 0)
			{
				return itemId;
			}
			return -1;
		}

		private static bool SameItem(ItemSlot slot, ushort itemId)
		{
			try
			{
				return slot != null && (Object)(object)slot.prefab != (Object)null && slot.prefab.itemID == itemId;
			}
			catch
			{
				return false;
			}
		}

		private void AddPockets(Player p, List<Item> inFront)
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			try
			{
				if (p.itemSlots == null)
				{
					return;
				}
				Item val = default(Item);
				for (int i = 0; i < 3; i++)
				{
					if (_pocketCfg[i] == null || !CfgItem(_pocketCfg[i].Value, out var itemId) || !ItemDatabase.TryGetItem(itemId, ref val) || (Object)(object)val == (Object)null || i >= p.itemSlots.Length)
					{
						continue;
					}
					if (!p.itemSlots[i].IsEmpty())
					{
						if (!SameItem(p.itemSlots[i], itemId))
						{
							inFront.Add(val);
						}
					}
					else
					{
						ItemInstanceData val2 = new ItemInstanceData(Guid.NewGuid());
						ItemInstanceDataHandler.AddInstanceData(val2);
						p.itemSlots[i].SetItem(val, val2);
					}
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("AddPockets failed: " + ex.Message));
			}
		}

		private void AddBackpackItems(Player p, List<Item> inFront)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Expected O, but got Unknown
			try
			{
				BackpackData val = default(BackpackData);
				if (p.backpackSlot == null || (int)p.backpackSlot.backpackType == 0 || ((ItemSlot)p.backpackSlot).data == null || !((ItemSlot)p.backpackSlot).data.TryGetDataEntry<BackpackData>((DataEntryKey)7, ref val) || val == null || val.itemSlots == null)
				{
					return;
				}
				int num = PackSlots();
				int num2 = num;
				try
				{
					Item prefab = ((ItemSlot)p.backpackSlot).prefab;
					Backpack val2 = (Backpack)(object)((prefab is Backpack) ? prefab : null);
					if ((Object)(object)val2 != (Object)null)
					{
						num2 = Mathf.Clamp(val2.slotCount, 0, 4);
					}
				}
				catch
				{
				}
				Item val3 = default(Item);
				for (byte b = 0; b < 4; b++)
				{
					if (b < num && _packCfg[b] != null && CfgItem(_packCfg[b].Value, out var itemId) && ItemDatabase.TryGetItem(itemId, ref val3) && !((Object)(object)val3 == (Object)null))
					{
						if (b >= num2 || b >= val.itemSlots.Length)
						{
							inFront.Add(val3);
						}
						else if (!val.itemSlots[b].IsEmpty())
						{
							if (!SameItem(val.itemSlots[b], itemId))
							{
								inFront.Add(val3);
							}
						}
						else
						{
							ItemInstanceData val4 = new ItemInstanceData(Guid.NewGuid());
							ItemInstanceDataHandler.AddInstanceData(val4);
							val.AddItem(val3, val4, b);
						}
					}
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("AddBackpackItems failed: " + ex.Message));
			}
		}

		private void PlaceInFront(Character c, List<Item> prefabs)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0085: 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_0094: 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_009a: 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_00a0: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: 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_00e8: 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_0028: 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_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)c == (Object)null || prefabs == null || prefabs.Count == 0 || !PhotonNetwork.IsMasterClient)
			{
				return;
			}
			Vector3 val = Vector3.forward;
			try
			{
				val = c.data.lookDirection;
			}
			catch
			{
			}
			val.y = 0f;
			if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
			{
				val = Vector3.forward;
			}
			((Vector3)(ref val)).Normalize();
			Vector3 val2 = Vector3.Cross(Vector3.up, val);
			Vector3 normalized = ((Vector3)(ref val2)).normalized;
			Vector3 val3 = c.Center + val * 1.2f + Vector3.up * 0.3f;
			Quaternion val4 = Quaternion.LookRotation(-val);
			for (int i = 0; i < prefabs.Count; i++)
			{
				try
				{
					Vector3 val5 = val3 + normalized * (((float)i - (float)(prefabs.Count - 1) * 0.5f) * 0.45f);
					GameObject val6 = PhotonNetwork.InstantiateItemRoom(((Object)((Component)prefabs[i]).gameObject).name, val5, val4, true);
					PhotonView val7 = (((Object)(object)val6 != (Object)null) ? val6.GetComponent<PhotonView>() : null);
					if ((Object)(object)val7 != (Object)null)
					{
						val7.RPC("SetKinematicRPC", (RpcTarget)3, new object[3] { true, val5, val4 });
					}
				}
				catch (Exception ex)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)("PlaceInFront failed: " + ex.Message));
				}
			}
		}

		private void Sync(Player p)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				byte[] array = IBinarySerializable.ToManagedArray<InventorySyncData>(new InventorySyncData(p.itemSlots, p.backpackSlot, p.tempFullSlot));
				((MonoBehaviourPun)p).photonView.RPC("SyncInventoryRPC", (RpcTarget)1, new object[2] { array, false });
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Sync failed: " + ex.Message));
			}
		}

		private static string SafeName(Character c)
		{
			try
			{
				string characterName = c.characterName;
				if (!string.IsNullOrEmpty(characterName))
				{
					return characterName;
				}
				Player val = null;
				try
				{
					if ((Object)(object)((MonoBehaviourPun)c).photonView != (Object)null)
					{
						val = ((MonoBehaviourPun)c).photonView.Owner;
					}
				}
				catch
				{
				}
				if (val != null)
				{
					return (!string.IsNullOrEmpty(val.NickName)) ? val.NickName : ("Actor " + val.ActorNumber);
				}
				return "Player";
			}
			catch
			{
				return "Player";
			}
		}

		private static string PlainName(string s)
		{
			if (string.IsNullOrEmpty(s))
			{
				return "";
			}
			StringBuilder stringBuilder = new StringBuilder(s.Length);
			bool flag = false;
			foreach (char c in s)
			{
				switch (c)
				{
				case '<':
					flag = true;
					continue;
				case '>':
					flag = false;
					continue;
				}
				if (!flag)
				{
					stringBuilder.Append(c);
				}
			}
			return stringBuilder.ToString().Trim();
		}

		private List<KitItem> Items()
		{
			if (_items != null)
			{
				return _items;
			}
			List<KitItem> list = new List<KitItem>();
			HashSet<string> seen = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
			List<Item> list2 = null;
			try
			{
				list2 = ((DatabaseAsset<ItemDatabase, Item>)(object)SingletonAsset<ItemDatabase>.Instance).Objects;
			}
			catch
			{
			}
			Dictionary<ushort, Item> dictionary = null;
			try
			{
				dictionary = SingletonAsset<ItemDatabase>.Instance.itemLookup;
			}
			catch
			{
			}
			if (list2 != null && list2.Count > 0)
			{
				foreach (Item item in list2)
				{
					if (!((Object)(object)item == (Object)null))
					{
						ushort id = 0;
						try
						{
							id = item.itemID;
						}
						catch
						{
						}
						AddItem(list, seen, id, item);
					}
				}
			}
			else if (dictionary != null)
			{
				List<ushort> list3 = new List<ushort>(dictionary.Keys);
				list3.Sort();
				foreach (ushort item2 in list3)
				{
					if (dictionary.TryGetValue(item2, out var value) && (Object)(object)value != (Object)null)
					{
						AddItem(list, seen, item2, value);
					}
				}
			}
			else
			{
				for (int i = 0; i <= 1023; i++)
				{
					Item val = null;
					try
					{
						if (!ItemDatabase.TryGetItem((ushort)i, ref val) || (Object)(object)val == (Object)null)
						{
							continue;
						}
						goto IL_012a;
					}
					catch
					{
					}
					continue;
					IL_012a:
					AddItem(list, seen, (ushort)i, val);
				}
			}
			Dictionary<string, int> dictionary2 = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
			foreach (KitItem item3 in list)
			{
				dictionary2.TryGetValue(item3.display, out var value2);
				dictionary2[item3.display] = value2 + 1;
			}
			foreach (KitItem item4 in list)
			{
				if (dictionary2.TryGetValue(item4.display, out var value3) && value3 > 1 && !string.IsNullOrEmpty(item4.internalName) && !string.Equals(item4.display, item4.internalName, StringComparison.OrdinalIgnoreCase))
				{
					item4.display = item4.display + " (" + item4.internalName + ")";
				}
			}
			list.Sort(delegate(KitItem a, KitItem b)
			{
				if (a.rank != b.rank)
				{
					return a.rank.CompareTo(b.rank);
				}
				int num = string.Compare(a.sortKey ?? a.internalName, b.sortKey ?? b.internalName, StringComparison.OrdinalIgnoreCase);
				return (num == 0) ? a.id.CompareTo(b.id) : num;
			});
			if (list.Count > 0)
			{
				_items = list;
			}
			return list;
		}

		private static bool Hidden(int id, string n)
		{
			if (HiddenIds.Contains(id) || string.IsNullOrEmpty(n))
			{
				return true;
			}
			if (n.StartsWith("C_Pawn", StringComparison.OrdinalIgnoreCase) || n.StartsWith("C_Rook", StringComparison.OrdinalIgnoreCase) || n.StartsWith("C_Knight", StringComparison.OrdinalIgnoreCase) || n.StartsWith("C_Bishop", StringComparison.OrdinalIgnoreCase) || n.StartsWith("C_Queen", StringComparison.OrdinalIgnoreCase) || n.StartsWith("C_King", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			return n.IndexOf("Page", StringComparison.OrdinalIgnoreCase) >= 0;
		}

		private static void AddItem(List<KitItem> list, HashSet<string> seen, ushort id, Item prefab)
		{
			try
			{
				string name = ((Object)prefab).name;
				if (Hidden(id, name) || !seen.Add(name))
				{
					return;
				}
				string display = name;
				try
				{
					if (prefab.UIData != null && !string.IsNullOrEmpty(prefab.UIData.itemName))
					{
						display = prefab.UIData.itemName;
					}
				}
				catch
				{
				}
				if (Renames.TryGetValue(id, out var value))
				{
					display = value;
				}
				KitItem kitItem = new KitItem
				{
					id = id,
					display = display,
					internalName = name,
					icon = IconFor(name, prefab)
				};
				if (Family(name, out var rank, out var key))
				{
					kitItem.rank = rank;
					kitItem.sortKey = key;
				}
				else
				{
					kitItem.rank = TagRank(prefab);
					kitItem.sortKey = name;
				}
				list.Add(kitItem);
			}
			catch
			{
			}
		}

		private static bool Family(string n, out int rank, out string key)
		{
			rank = 5;
			key = null;
			if (string.IsNullOrEmpty(n))
			{
				return false;
			}
			if (Has("Berrynana"))
			{
				rank = 2;
				key = (Has("Peel") ? "Berrynana~2~" : "Berrynana~1~") + n;
				return true;
			}
			if (Has("Beehive") || Has("Honeycomb"))
			{
				rank = 2;
				key = (Has("Honeycomb") ? "Beehive~2~" : "Beehive~1~") + n;
				return true;
			}
			if (Has("Rope"))
			{
				rank = 5;
				bool flag = Has("Anti-Rope") || Has("AntiRope") || Has("RopeShooterAnti");
				key = (flag ? "Rope~2~" : "Rope~1~") + n;
				return true;
			}
			if (Has("BounceShroom") || Has("ShelfShroom") || (Has("Bounce") && Has("Fungus")) || (Has("Shelf") && Has("Fungus")))
			{
				rank = 1;
				key = (Has("Shelf") ? "Fungus~2~" : "Fungus~1~") + n;
				return true;
			}
			return false;
			bool Has(string s)
			{
				return n.IndexOf(s, StringComparison.OrdinalIgnoreCase) >= 0;
			}
		}

		private static int TagRank(Item prefab)
		{
			//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_0007: 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_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_0028: 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_0031: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				ItemTags itemTags = prefab.itemTags;
				if ((itemTags & 2) != 0)
				{
					return 0;
				}
				if ((itemTags & 8) != 0)
				{
					return 1;
				}
				if ((itemTags & 4) != 0)
				{
					return 2;
				}
				if ((itemTags & 0x80) != 0)
				{
					return 3;
				}
				if ((itemTags & 1) != 0)
				{
					return 4;
				}
				if ((itemTags & 0x40) != 0)
				{
					return 4;
				}
				if ((itemTags & 0x100) != 0)
				{
					return 4;
				}
			}
			catch
			{
			}
			return 5;
		}

		private KitItem ItemById(int id)
		{
			List<KitItem> list = Items();
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].id == id)
				{
					return list[i];
				}
			}
			return null;
		}

		private static Texture2D IconFor(string internalName, Item prefab)
		{
			if (string.IsNullOrEmpty(internalName))
			{
				return null;
			}
			if (IconCache.TryGetValue(internalName, out var value))
			{
				return value;
			}
			try
			{
				if ((Object)(object)prefab != (Object)null && prefab.UIData != null)
				{
					try
					{
						value = prefab.UIData.GetIcon();
					}
					catch
					{
					}
					if ((Object)(object)value == (Object)null)
					{
						value = prefab.UIData.icon;
					}
				}
				if ((Object)(object)value != (Object)null && string.Equals(internalName, "Warpsketball", StringComparison.OrdinalIgnoreCase))
				{
					Texture2D val = WarpBallFromBasketball((Texture)(object)value);
					if ((Object)(object)val != (Object)null)
					{
						value = val;
					}
				}
			}
			catch
			{
			}
			IconCache[internalName] = value;
			return value;
		}

		private static Texture2D ReadableCopy(Texture src)
		{
			//IL_0053: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			if ((Object)(object)src == (Object)null || src.width <= 0 || src.height <= 0)
			{
				return null;
			}
			RenderTexture active = RenderTexture.active;
			RenderTexture temporary = RenderTexture.GetTemporary(src.width, src.height, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)0);
			try
			{
				Graphics.Blit(src, temporary);
				RenderTexture.active = temporary;
				Texture2D val = new Texture2D(src.width, src.height, (TextureFormat)4, false)
				{
					hideFlags = (HideFlags)61
				};
				val.ReadPixels(new Rect(0f, 0f, (float)src.width, (float)src.height), 0, 0);
				val.Apply();
				return val;
			}
			catch
			{
				return null;
			}
			finally
			{
				RenderTexture.active = active;
				RenderTexture.ReleaseTemporary(temporary);
			}
		}

		private static Texture2D WarpBallFromBasketball(Texture src)
		{
			//IL_0122: 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_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: 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_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: 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_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Expected O, but got Unknown
			//IL_0194: 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_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = ReadableCopy(src);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			try
			{
				int width = ((Texture)val).width;
				int height = ((Texture)val).height;
				Color[] pixels = val.GetPixels();
				float num = 1f;
				float num2 = 0f;
				int num3 = 0;
				for (int i = 0; i < pixels.Length; i++)
				{
					if (!(pixels[i].a < 0.5f))
					{
						float num4 = pixels[i].r * 0.299f + pixels[i].g * 0.587f + pixels[i].b * 0.114f;
						if (num4 < num)
						{
							num = num4;
						}
						if (num4 > num2)
						{
							num2 = num4;
						}
						num3++;
					}
				}
				if (num3 < 16 || num2 - num < 0.05f)
				{
					return null;
				}
				Color val2 = default(Color);
				((Color)(ref val2))..ctor(0.09f, 0.11f, 0.38f, 1f);
				Color val3 = default(Color);
				((Color)(ref val3))..ctor(0.2f, 0.27f, 0.68f, 1f);
				Color[] array = (Color[])(object)new Color[3]
				{
					new Color(0.45f, 1f, 0.95f, 1f),
					new Color(1f, 0.55f, 0.95f, 1f),
					new Color(0.85f, 1f, 0.5f, 1f)
				};
				Color[] array2 = (Color[])(object)new Color[pixels.Length];
				for (int j = 0; j < height; j++)
				{
					for (int k = 0; k < width; k++)
					{
						int num5 = j * width + k;
						Color val4 = pixels[num5];
						if (val4.a <= 0f)
						{
							array2[num5] = new Color(0f, 0f, 0f, 0f);
							continue;
						}
						float num6 = Mathf.Clamp01((val4.r * 0.299f + val4.g * 0.587f + val4.b * 0.114f - num) / (num2 - num));
						Color val5 = Color.Lerp(val2, val3, num6);
						float num7 = (float)j / (float)Mathf.Max(1, height - 1) * (float)array.Length;
						int num8 = Mathf.Clamp((int)num7, 0, array.Length - 1);
						Color val6 = Color.Lerp(array[num8], array[(num8 + 1) % array.Length], num7 - (float)num8);
						float num9 = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01((0.72f - num6) / 0.45f));
						Color val7 = Color.Lerp(val5, val6, num9);
						val7.a = val4.a;
						array2[num5] = val7;
					}
				}
				Texture2D val8 = new Texture2D(width, height, (TextureFormat)4, false)
				{
					hideFlags = (HideFlags)61,
					filterMode = (FilterMode)1,
					wrapMode = (TextureWrapMode)1
				};
				val8.SetPixels(array2);
				val8.Apply();
				return val8;
			}
			catch
			{
				return null;
			}
			finally
			{
				Object.Destroy((Object)(object)val);
			}
		}

		private void ToggleMenu()
		{
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			if (!(realtimeSinceStartup - _toggleAt < 0.2f))
			{
				_toggleAt = realtimeSinceStartup;
				_show = !_show;
				if (!_show)
				{
					GUIUtility.keyboardControl = 0;
					_target = -1;
					_backOpen = false;
				}
			}
		}

		private static Texture2D MakeTex(Color c)
		{
			//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_0010: 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_001f: Expected O, but got Unknown
			Texture2D val = new Texture2D(1, 1);
			val.SetPixel(0, 0, c);
			val.Apply();
			((Object)val).hideFlags = (HideFlags)61;
			return val;
		}

		private void InitStyles()
		{
			//IL_0007: 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_0027: Expected O, but got Unknown
			//IL_0032: 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_0075: Expected O, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			//IL_00ac: 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_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Expected O, but got Unknown
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Expected O, but got Unknown
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Expected O, but got Unknown
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Expected O, but got Unknown
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Expected O, but got Unknown
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Expected O, but got Unknown
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Expected O, but got Unknown
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Expected O, but got Unknown
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Expected O, but got Unknown
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Expected O, but got Unknown
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Expected O, but got Unknown
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Expected O, but got Unknown
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_037c: Expected O, but got Unknown
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Expected O, but got Unknown
			//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: Expected O, but got Unknown
			//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fd: Expected O, but got Unknown
			//IL_0408: Unknown result type (might be due to invalid IL or missing references)
			//IL_046a: Unknown result type (might be due to invalid IL or missing references)
			//IL_047a: 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_049f: Expected O, but got Unknown
			//IL_04c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cc: Expected O, but got Unknown
			//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e0: Expected O, but got Unknown
			//IL_051a: Unknown result type (might be due to invalid IL or missing references)
			//IL_052f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0539: Expected O, but got Unknown
			_stylesReady = true;
			Texture2D background = MakeTex(Color.white);
			_windowStyle = new GUIStyle(GUI.skin.window);
			_windowStyle.normal.background = MakeTex(BgWindow);
			_windowStyle.onNormal.background = _windowStyle.normal.background;
			_windowStyle.border = new RectOffset(8, 8, 8, 8);
			_windowStyle.padding = new RectOffset(10, 10, 8, 10);
			_titleStyle = new GUIStyle(GUI.skin.label);
			_titleStyle.normal.background = MakeTex(BgTitle);
			_titleStyle.normal.textColor = TxtTitle;
			_titleStyle.fontStyle = (FontStyle)1;
			_titleStyle.fontSize = 15;
			_titleStyle.alignment = (TextAnchor)4;
			_labelStyle = new GUIStyle(GUI.skin.label);
			_labelStyle.normal.textColor = TxtLabel;
			_labelStyle.fontStyle = (FontStyle)1;
			_labelStyle.fontSize = 14;
			_labelStyle.alignment = (TextAnchor)3;
			_labelStyle.clipping = (TextClipping)1;
			_headerStyle = new GUIStyle(_labelStyle);
			_headerStyle.normal.textColor = TxtHeader;
			_warnStyle = new GUIStyle(_labelStyle);
			_warnStyle.normal.textColor = ColWarn;
			_dimStyle = new GUIStyle(_labelStyle);
			_dimStyle.fontSize = 12;
			_dimStyle.normal.textColor = new Color(TxtLabel.r, TxtLabel.g, TxtLabel.b, 0.75f);
			_buttonStyle = new GUIStyle(GUI.skin.button);
			_buttonStyle.normal.background = background;
			_buttonStyle.hover.background = background;
			_buttonStyle.active.background = background;
			_buttonStyle.normal.textColor = TxtButton;
			_buttonStyle.hover.textColor = TxtButton;
			_buttonStyle.active.textColor = TxtButton;
			_buttonStyle.fontStyle = (FontStyle)1;
			_buttonStyle.fontSize = 12;
			_buttonStyle.alignment = (TextAnchor)4;
			_buttonStyle.margin = new RectOffset(3, 3, 2, 2);
			_buttonStyle.padding = new RectOffset(4, 4, 4, 4);
			_playerStyle = new GUIStyle(_buttonStyle);
			_playerStyle.fontSize = 11;
			_playerStyle.padding = new RectOffset(4, 4, 2, 2);
			_playerStyle.wordWrap = false;
			_playerStyle.clipping = (TextClipping)1;
			_rowStyle = new GUIStyle(GUI.skin.box);
			_rowStyle.normal.background = MakeTex(BgRow);
			_rowStyle.margin = new RectOffset(0, 0, 2, 2);
			_rowStyle.padding = new RectOffset(6, 6, 3, 3);
			_iconStyle = new GUIStyle(GUI.skin.box);
			_iconStyle.normal.background = MakeTex(BgSlot);
			_iconStyle.margin = new RectOffset(2, 2, 2, 2);
			_iconStyle.padding = new RectOffset(3, 3, 3, 3);
			_iconStyle.alignment = (TextAnchor)4;
			_iconStyle.fontSize = 10;
			_iconStyle.normal.textColor = TxtLabel;
			_iconEmptyStyle = new GUIStyle(_iconStyle);
			_iconEmptyStyle.normal.background = MakeTex(BgSlotEmpty);
			GUIStyle[] array = (GUIStyle[])(object)new GUIStyle[2] { _iconStyle, _iconEmptyStyle };
			foreach (GUIStyle val in array)
			{
				val.hover.background = val.normal.background;
				val.active.background = val.normal.background;
				val.hover.textColor = TxtLabel;
				val.active.textColor = TxtLabel;
			}
			_numStyle = new GUIStyle(_labelStyle);
			_numStyle.fontSize = 10;
			_numStyle.alignment = (TextAnchor)0;
			_numStyle.padding = new RectOffset(0, 0, 0, 0);
			_numStyle.margin = new RectOffset(0, 0, 0, 0);
			_numStyle.wordWrap = false;
			_numStyle.normal.textColor = new Color(TxtLabel.r, TxtLabel.g, TxtLabel.b, 0.65f);
			_fieldStyle = new GUIStyle(GUI.skin.textField);
			_fieldStyle.fontSize = 13;
			_fitCache.Clear();
			_fitW = -1f;
		}

		private static float WindowH()
		{
			return Mathf.Max(400f, (float)Screen.height - 60f);
		}

		private void OnGUI()
		{
			//IL_0130: 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_0151: Expected O, but got Unknown
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			if (_show)
			{
				if (!_stylesReady)
				{
					InitStyles();
				}
				float num = ((_target >= 0) ? PickerW() : 768f);
				float height = ((_target >= 0) ? WindowH() : Mathf.Clamp(_listTop + _listH + 48f + 120f, 240f, WindowH()));
				if (!_winPlaced)
				{
					((Rect)(ref _win)).x = Mathf.Max(0f, ((float)Screen.width - num) * 0.5f);
					((Rect)(ref _win)).y = 60f;
					_winPlaced = true;
				}
				((Rect)(ref _win)).width = num;
				((Rect)(ref _win)).height = height;
				((Rect)(ref _win)).x = Mathf.Clamp(((Rect)(ref _win)).x, 0f, Mathf.Max(0f, (float)Screen.width - num));
				((Rect)(ref _win)).y = Mathf.Clamp(((Rect)(ref _win)).y, 0f, Mathf.Max(0f, (float)Screen.height - 40f));
				_win = GUI.Window(1263225172, _win, new WindowFunction(DrawWindow), GUIContent.none, _windowStyle);
			}
		}

		private void DrawWindow(int id)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			Event current = Event.current;
			if (current != null && (int)current.type == 4 && current.keyCode == MenuKey)
			{
				ToggleMenu();
				current.Use();
			}
			GUILayout.Box("Kikis Kit", _titleStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Height(28f),
				GUILayout.ExpandWidth(true)
			});
			GUILayout.Space(6f);
			DrawKit();
			GUILayout.FlexibleSpace();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label((!string.IsNullOrEmpty(_status) && Time.realtimeSinceStartup < _statusUntil) ? _status : "", _dimStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(24f) });
			GUILayout.FlexibleSpace();
			if (Btn("Close", ColOff, 120f))
			{
				_show = false;
				GUIUtility.keyboardControl = 0;
				_target = -1;
				_backOpen = false;
			}
			GUILayout.EndHorizontal();
			GUI.DragWindow(new Rect(0f, 0f, 10000f, 34f));
		}

		private bool Btn(string label, Color col, float width)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			Color backgroundColor = GUI.backgroundColor;
			GUI.backgroundColor = col;
			bool result = GUILayout.Button(label, _buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(width),
				GUILayout.Height(24f)
			});
			GUI.backgroundColor = backgroundColor;
			return result;
		}

		private static void FillRect(Rect r, Color c)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Color color = GUI.color;
			GUI.color = c;
			GUI.DrawTexture(r, (Texture)(object)Texture2D.whiteTexture);
			GUI.color = color;
		}

		private float PickerW()
		{
			return 860f;
		}

		private int SlotCfg(int slot)
		{
			return ((slot < 3) ? _pocketCfg[slot] : _packCfg[slot - 3])?.Value ?? 0;
		}

		private void SetSlotCfg(int slot, int value)
		{
			ConfigEntry<int> val = ((slot < 3) ? _pocketCfg[slot] : _packCfg[slot - 3]);
			if (val != null)
			{
				val.Value = value;
			}
		}

		private string PackHeader()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			return "In the " + PackKindLabels[PackType()].ToLowerInvariant();
		}

		private void DrawKit()
		{
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Invalid comparison between Unknown and I4
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Invalid comparison between Unknown and I4
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			bool value = _giveBackpack.Value;
			int num = (value ? PackSlots() : 0);
			if (_target >= 3 && _target - 3 >= num)
			{
				_target = -1;
			}
			if (_target >= 0)
			{
				if (_target < 3)
				{
					GUILayout.Label("Pockets", _headerStyle, Array.Empty<GUILayoutOption>());
					SlotRow(0, 3);
				}
				else
				{
					GUILayout.Label(PackHeader(), _headerStyle, Array.Empty<GUILayoutOption>());
					SlotRow(3, num);
				}
				DrawPicker();
				return;
			}
			bool flag = _listTop + _listH + 48f <= WindowH();
			float num2 = (flag ? _listH : Mathf.Max(120f, WindowH() - 48f - _listTop));
			_scroll = GUILayout.BeginScrollView(_scroll, false, false, GUIStyle.none, flag ? GUIStyle.none : GUI.skin.verticalScrollbar, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(num2) });
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Pockets", _headerStyle, Array.Empty<GUILayoutOption>());
			SlotRow(0, 3);
			GUILayout.Space(6f);
			GUILayout.Label("Back item", _headerStyle, Array.Empty<GUILayoutOption>());
			BackRow(value);
			if (_backOpen)
			{
				BackChooser(value);
			}
			if (value && num > 0)
			{
				GUILayout.Space(6f);
				GUILayout.Label(PackHeader(), _headerStyle, Array.Empty<GUILayoutOption>());
				SlotRow(3, num);
			}
			GUILayout.Space(6f);
			GUILayout.Label("Rekit", _headerStyle, Array.Empty<GUILayoutOption>());
			ToggleRow("Hand out again at every lit campfire", _repeatCampfire);
			ToggleRow("Auto Rekit Revive", _rekitRevive);
			GUILayout.Space(6f);
			GUILayout.Label("Give kit to a player", _headerStyle, Array.Empty<GUILayoutOption>());
			bool isMasterClient = PhotonNetwork.IsMasterClient;
			if (!isMasterClient)
			{
				GUILayout.Label("Only the host can hand out kits.", _warnStyle, Array.Empty<GUILayoutOption>());
			}
			PlayerGrid(isMasterClient);
			GUILayout.EndVertical();
			if ((int)Event.current.type == 7)
			{
				Rect lastRect = GUILayoutUtility.GetLastRect();
				_listH = ((Rect)(ref lastRect)).height;
				_listW = ((Rect)(ref lastRect)).width;
			}
			GUILayout.EndScrollView();
			if ((int)Event.current.type == 7)
			{
				Rect lastRect2 = GUILayoutUtility.GetLastRect();
				_listTop = ((Rect)(ref lastRect2)).y;
			}
		}

		private void ToggleRow(string label, ConfigEntry<bool> entry)
		{
			//IL_0055: 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)
			bool value = entry.Value;
			GUILayout.BeginHorizontal(_rowStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Label(label, _labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(300f) });
			GUILayout.FlexibleSpace();
			if (Btn(value ? "ON" : "OFF", value ? ColOn : ColOff, 80f))
			{
				entry.Value = !value;
			}
			GUILayout.EndHorizontal();
		}

		private void SlotRow(int first, int count)
		{
			//IL_00a1: 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_00a8: Expected O, but got Unknown
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			for (int i = 0; i < count; i++)
			{
				if (i > 0)
				{
					GUILayout.Space(8f);
				}
				int num = first + i;
				ushort itemId;
				bool flag = CfgItem(SlotCfg(num), out itemId);
				KitItem kitItem = (flag ? ItemById(itemId) : null);
				string text = ((!flag) ? "empty" : ((kitItem != null) ? kitItem.display : ("id " + itemId)));
				GUIContent gc = ((kitItem != null && (Object)(object)kitItem.icon != (Object)null) ? new GUIContent((Texture)(object)kitItem.icon, text) : new GUIContent(flag ? Shorten(text) : "", text));
				bool flag2 = _target == num;
				switch (Tile(gc, flag, flag2, i + 1, activeBg: false, canClear: true))
				{
				case 2:
					SetSlotCfg(num, 0);
					if (flag2)
					{
						_target = -1;
					}
					break;
				case 1:
					_target = (flag2 ? (-1) : num);
					_filter = "";
					_backOpen = false;
					break;
				}
			}
			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
		}

		private void BackRow(bool give)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected I4, but got Unknown
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			GUIContent gc = (GUIContent)(give ? ((object)PackContent((int)PackType())) : ((object)new GUIContent("", "no back item")));
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			switch (Tile(gc, give, _backOpen, 0, activeBg: false, canClear: true))
			{
			case 2:
				_giveBackpack.Value = false;
				_backOpen = false;
				break;
			case 1:
				_backOpen = !_backOpen;
				break;
			}
			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
		}

		private void BackChooser(bool give)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected I4, but got Unknown
			int num = (int)PackType();
			GUILayout.BeginHorizontal(_rowStyle, Array.Empty<GUILayoutOption>());
			for (int i = 1; i <= 4; i++)
			{
				if (i > 1)
				{
					GUILayout.Space(8f);
				}
				if (Tile(PackContent(i), filled: true, picked: false, 0, give && num == i, canClear: false) == 1)
				{
					if (!give)
					{
						_giveBackpack.Value = true;
					}
					if (num != i)
					{
						_backpackKind.Value = i;
						ClearPackSlotsBeyondCapacity();
					}
					_backOpen = false;
				}
			}
			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
		}

		private GUIContent PackContent(int k)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			Texture2D val = null;
			try
			{
				Backpack val2 = PackPrefab((BackpackType)k);
				if ((Object)(object)val2 != (Object)null)
				{
					KitItem kitItem = ItemById(((Item)val2).itemID);
					if (kitItem != null)
					{
						val = kitItem.icon;
					}
				}
			}
			catch
			{
			}
			if ((Object)(object)val != (Object)null)
			{
				return new GUIContent((Texture)(object)val, PackKindLabels[k]);
			}
			return new GUIContent(Shorten(PackKindLabels[k]), PackKindLabels[k]);
		}

		private static string Shorten(string s)
		{
			if (string.IsNullOrEmpty(s))
			{
				return "?";
			}
			if (s.Length > 6)
			{
				return s.Substring(0, 6);
			}
			return s;
		}

		private int Tile(GUIContent gc, bool filled, bool picked, int number, bool activeBg, bool canClear)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Invalid comparison between Unknown and I4
			//IL_0143: 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_0110: 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_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: 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_0298: 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_02bb: 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_02d1: Unknown result type (might be due to invalid IL or missing references)
			Rect rect = GUILayoutUtility.GetRect(56f, 56f, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(56f),
				GUILayout.Height(56f)
			});
			Event current = Event.current;
			bool flag = GUI.enabled && ((Rect)(ref rect)).Contains(current.mousePosition);
			bool flag2 = canClear && filled && flag;
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((Rect)(ref rect)).xMax - 18f - 3f, ((Rect)(ref rect)).y + 3f, 18f, 18f);
			if (flag2 && (int)current.type == 0 && current.button == 0 && ((Rect)(ref val)).Contains(current.mousePosition))
			{
				current.Use();
				return 2;
			}
			int result = 0;
			Color backgroundColor = GUI.backgroundColor;
			if (activeBg)
			{
				GUI.backgroundColor = ColActive;
			}
			if (GUI.Button(rect, gc, filled ? _iconStyle : _iconEmptyStyle))
			{
				result = 1;
			}
			GUI.backgroundColor = backgroundColor;
			if ((int)current.type == 7)
			{
				if (flag && !activeBg)
				{
					FillRect(rect, new Color(1f, 1f, 1f, 0.18f));
				}
				if (number > 0)
				{
					GUI.Label(new Rect(((Rect)(ref rect)).x + 4f, ((Rect)(ref rect)).y + 2f, 18f, 14f), number.ToString(), _numStyle);
				}
				if (picked)
				{
					FillRect(new Rect(((Rect)(ref rect)).x - 3f, ((Rect)(ref rect)).y - 3f, ((Rect)(ref rect)).width + 6f, 3f), ColActive);
					FillRect(new Rect(((Rect)(ref rect)).x - 3f, ((Rect)(ref rect)).yMax, ((Rect)(ref rect)).width + 6f, 3f), ColActive);
					FillRect(new Rect(((Rect)(ref rect)).x - 3f, ((Rect)(ref rect)).y, 3f, ((Rect)(ref rect)).height), ColActive);
					FillRect(new Rect(((Rect)(ref rect)).xMax, ((Rect)(ref rect)).y, 3f, ((Rect)(ref rect)).height), ColActive);
				}
				if (flag2)
				{
					if ((Object)(object)_badgeTex == (Object)null)
					{
						int size = Mathf.RoundToInt(18f);
						_badgeTex = RenderShape(size, (float x, float y) => x * x + y * y <= 0.9216f);
						_badgeXTex = RenderShape(size, (float x, float y) => RotBox(x, y, 0.5f, 0.12f, 45f, 0.06f) || RotBox(x, y, 0.5f, 0.12f, -45f, 0.06f));
					}
					Color color = GUI.color;
					GUI.color = new Color(0.2f, 0.18f, 0.15f, 0.95f);
					GUI.DrawTexture(val, (Texture)(object)_badgeTex);
					GUI.color = Color.white;
					GUI.DrawTexture(val, (Texture)(object)_badgeXTex);
					GUI.color = color;
				}
			}
			return result;
		}

		private static Texture2D RenderShape(int size, Func<float, float, bool> inside)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(size, size, (TextureFormat)5, false);
			for (int i = 0; i < size; i++)
			{
				for (int j = 0; j < size; j++)
				{
					float num = 0f;
					for (int k = 0; k < 4; k++)
					{
						for (int l = 0; l < 4; l++)
						{
							float arg = ((float)j + 0.125f + (float)l * 0.25f) / (float)size * 2f - 1f;
							float arg2 = ((float)i + 0.125f + (float)k * 0.25f) / (float)size * 2f - 1f;
							if (inside(arg, arg2))
							{
								num += 0.0625f;
							}
						}
					}
					val.SetPixel(j, i, new Color(1f, 1f, 1f, num));
				}
			}
			val.Apply();
			((Texture)val).filterMode = (FilterMode)1;
			((Object)val).hideFlags = (HideFlags)61;
			return val;
		}

		private static bool RotBox(float x, float y, float hl, float hh, float deg, float rad)
		{
			float num = deg * (MathF.PI / 180f);
			float num2 = x * Mathf.Cos(num) + y * Mathf.Sin(num);
			float num3 = (0f - x) * Mathf.Sin(num) + y * Mathf.Cos(num);
			float num4 = Mathf.Max(Mathf.Abs(num2) - (hl - rad), 0f);
			float num5 = Mathf.Max(Mathf.Abs(num3) - (hh - rad), 0f);
			return num4 * num4 + num5 * num5 <= rad * rad;
		}

		private void DrawPicker()
		{
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: 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_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Expected O, but got Unknown
			GUILayout.Space(4f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Filter", _labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(45f) });
			_filter = GUILayout.TextField(_filter ?? "", _fieldStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(260f) });
			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
			List<KitItem> list = Items();
			if (list.Count == 0)
			{
				GUILayout.Label("The item list is not ready yet - open this again once you are in a lobby.", _warnStyle, Array.Empty<GUILayoutOption>());
				return;
			}
			string text = (_filter ?? "").Trim();
			List<KitItem> list2 = new List<KitItem>();
			for (int i = 0; i < list.Count; i++)
			{
				if (text.Length == 0 || list[i].display.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0)
				{
					list2.Add(list[i]);
				}
			}
			GUILayout.Label(list2.Count + " item(s) - click one to put it in the slot", _labelStyle, Array.Empty<GUILayoutOption>());
			float num = (float)((list2.Count + 14 - 1) / 14) * 58f + 8f;
			_pickScroll = GUILayout.BeginScrollView(_pickScroll, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(Mathf.Min(num, Mathf.Max(200f, WindowH() - 320f))) });
			for (int j = 0; j < list2.Count; j += 14)
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				for (int k = 0; k < 14 && j + k < list2.Count; k++)
				{
					KitItem kitItem = list2[j + k];
					if (GUILayout.Button(((Object)(object)kitItem.icon != (Object)null) ? new GUIContent((Texture)(object)kitItem.icon, kitItem.display) : new GUIContent(Shorten(kitItem.display), kitItem.display), _iconStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
					{
						GUILayout.Width(54f),
						GUILayout.Height(54f)
					}))
					{
						SetSlotCfg(_target, ItemToCfg(kitItem.id));
						_target = -1;
					}
				}
				GUILayout.FlexibleSpace();
				GUILayout.EndHorizontal();
			}
			GUILayout.EndScrollView();
			if (!string.IsNullOrEmpty(GUI.tooltip))
			{
				GUILayout.Label(GUI.tooltip, _labelStyle, Array.Empty<GUILayoutOption>());
			}
		}

		private void PlayerGrid(bool host)
		{
			//IL_011d: 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_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Floor((((_listW > 200f) ? _listW : 728f) - 36f) / 10f);
			int num2 = 0;
			List<Character> allCharacters = Character.AllCharacters;
			if (allCharacters != null)
			{
				for (int i = 0; i < allCharacters.Count; i++)
				{
					Character val = allCharacters[i];
					if ((Object)(object)val == (Object)null || val.isBot)
					{
						continue;
					}
					bool flag = false;
					bool flag2 = false;
					try
					{
						flag = (Object)(object)val.data == (Object)null || val.data.dead || !val.data.fullyConscious;
					}
					catch
					{
					}
					try
					{
						flag2 = (Object)(object)val.data != (Object)null && ((Object)(object)val.data.carrier != (Object)null || (Object)(object)val.data.carriedPlayer != (Object)null);
					}
					catch
					{
					}
					if (num2 == 0)
					{
						GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
					}
					else
					{
						GUILayout.Space(4f);
					}
					Rect rect = GUILayoutUtility.GetRect(num, 26f, (GUILayoutOption[])(object)new GUILayoutOption[2]
					{
						GUILayout.Width(num),
						GUILayout.Height(26f)
					});
					string plain = (val.IsLocal ? "Me" : PlainName(SafeName(val)));
					GUI.enabled = host && !flag && !flag2;
					Color backgroundColor = GUI.backgroundColor;
					GUI.backgroundColor = ColOn;
					bool num3 = GUI.Button(rect, FitName(plain, num), _playerStyle);
					GUI.backgroundColor = backgroundColor;
					GUI.enabled = true;
					if (num3)
					{
						bool flag3 = GiveKit(val);
						if (flag3)
						{
							try
							{
								_served.Add(val.refs.view.OwnerActorNr);
							}
							catch
							{
							}
						}
						_status = (flag3 ? (PlainName(SafeName(val)) + " received the kit") : "Kit failed - see the log");
						_statusUntil = Time.realtimeSinceStartup + 5f;
					}
					if (++num2 >= 10)
					{
						GUILayout.EndHorizontal();
						GUILayout.Space(4f);
						num2 = 0;
					}
				}
			}
			if (num2 > 0)
			{
				GUILayout.FlexibleSpace();
				GUILayout.EndHorizontal();
			}
		}

		private string FitName(string plain, float width)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrEmpty(plain))
			{
				return "?";
			}
			if (width != _fitW)
			{
				_fitCache.Clear();
				_fitW = width;
			}
			if (_fitCache.TryGetValue(plain, out var value))
			{
				return value;
			}
			float num = width - 2f;
			string text = plain;
			if (_playerStyle.CalcSize(new GUIContent(plain)).x > num)
			{
				int num2 = plain.Length - 1;
				while (num2 > 1)
				{
					if (char.IsHighSurrogate(plain[num2 - 1]))
					{
						num2--;
						continue;
					}
					if (_playerStyle.CalcSize(new GUIContent(plain.Substring(0, num2).TrimEnd() + "…")).x <= num)
					{
						break;
					}
					num2--;
				}
				text = plain.Substring(0, num2).TrimEnd() + "…";
			}
			if (_fitCache.Count > 200)
			{
				_fitCache.Clear();
			}
			_fitCache[plain] = text;
			return text;
		}
	}
	internal static class CampfirePatch
	{
		public static void Postfix(Campfire __instance, bool updateSegment)
		{
			try
			{
				if ((Object)(object)Plugin.Instance != (Object)null)
				{
					Plugin.Instance.OnCampfireLit(__instance, updateSegment);
				}
			}
			catch
			{
			}
		}
	}
	internal static class DownPatch
	{
		public static void Postfix(Character __instance)
		{
			try
			{
				if ((Object)(object)Plugin.Instance != (Object)null)
				{
					Plugin.Instance.OnCharacterDown(__instance);
				}
			}
			catch
			{
			}
		}
	}
	internal static class MenuInputPatch
	{
		public static void Prefix(ref bool playerMovementActive)
		{
			try
			{
				if ((Object)(object)Plugin.Instance != (Object)null && Plugin.Instance.MenuOpen)
				{
					playerMovementActive = false;
				}
			}
			catch
			{
			}
		}

		public static void Postfix(CharacterInput __instance)
		{
			try
			{
				if (!((Object)(object)__instance == (Object)null) && !((Object)(object)Plugin.Instance == (Object)null) && Plugin.Instance.MenuOpen)
				{
					__instance.interactWasPressed = false;
					__instance.interactIsPressed = false;
					__instance.interactWasReleased = false;
					__instance.emoteIsPressed = false;
				}
			}
			catch
			{
			}
		}
	}
	internal static class MenuCursorPatch
	{
		public static void Postfix()
		{
			try
			{
				if (!((Object)(object)Plugin.Instance == (Object)null) && Plugin.Instance.MenuOpen && Application.isFocused)
				{
					Cursor.lockState = (CursorLockMode)0;
					Cursor.visible = true;
				}
			}
			catch
			{
			}
		}
	}
}