Decompiled source of ChestLootRoll v1.0.0

Cjayride.ChestLootRoll.dll

Decompiled 27 minutes ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Cjayride.ChestLootRoll
{
	[HarmonyPatch(typeof(Container), "Interact")]
	internal static class BossChestGate
	{
		private static bool Prefix(Container __instance, Humanoid character, bool hold)
		{
			if (hold)
			{
				return true;
			}
			if (!ModConfig.OnlyPartyLeaderOpensBossChests.Value)
			{
				return true;
			}
			if (ModConfig.SoloTestMode.Value && RollServer.IsSoloServer())
			{
				return true;
			}
			if ((Object)(object)character != (Object)(object)Player.m_localPlayer)
			{
				return true;
			}
			if (!ChestUtil.IsBossLootChest(__instance))
			{
				return true;
			}
			if (PartyUtil.GetPartyId(((Object)(object)Player.m_localPlayer != (Object)null && (Object)(object)((Character)Player.m_localPlayer).m_nview != (Object)null) ? ((Character)Player.m_localPlayer).m_nview.GetZDO() : null) == 0)
			{
				return true;
			}
			if (PartyUtil.IsPartyLeader(ZNet.GetUID()))
			{
				return true;
			}
			ChestUtil.Hint("Only the party leader can open a boss loot chest.");
			return false;
		}
	}
	internal static class ChatRelay
	{
		internal static void OnChat(ZPackage pkg)
		{
			//IL_0042: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			int num = pkg.ReadInt();
			string text = pkg.ReadString();
			string text2 = pkg.ReadString();
			if (!((Object)(object)Chat.instance == (Object)null))
			{
				string text3 = (string.IsNullOrEmpty(text) ? "Loot" : text);
				bool num2 = num == 2;
				Color val = (num2 ? Color.yellow : Color.white);
				string text4 = (num2 ? text2.ToUpperInvariant() : text2);
				string text5 = "<color=orange>" + text3 + "</color>: <color=#" + ColorUtility.ToHtmlStringRGBA(val) + ">" + text4 + "</color>";
				((Terminal)Chat.instance).AddString(text5);
				Chat.instance.m_hideTimer = 0f;
			}
		}
	}
	internal static class ChestUtil
	{
		private const int BossLootMarkerHash = 186620331;

		private const int BossLootMarkBoss = 1;

		internal static Container CurrentChest()
		{
			InventoryGui instance = InventoryGui.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return null;
			}
			return instance.m_currentContainer;
		}

		internal static ItemData HoveredChestItem()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			Container val = CurrentChest();
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			InventoryGui instance = InventoryGui.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.m_containerGrid == (Object)null)
			{
				return null;
			}
			InventoryElement hoveredElement = instance.m_containerGrid.GetHoveredElement();
			if ((Object)(object)hoveredElement == (Object)null)
			{
				return null;
			}
			Vector2i elementPos = instance.m_containerGrid.GetElementPos(hoveredElement);
			Inventory inventory = val.GetInventory();
			if (inventory == null)
			{
				return null;
			}
			return inventory.GetItemAt(elementPos.x, elementPos.y);
		}

		internal static bool IsPlayerChest(Container container)
		{
			if ((Object)(object)container == (Object)null)
			{
				return false;
			}
			if ((Object)(object)container.m_wagon != (Object)null)
			{
				return true;
			}
			if (IsBossLootChest(container))
			{
				return false;
			}
			Piece component = ((Component)container).GetComponent<Piece>();
			if ((Object)(object)component != (Object)null)
			{
				return component.IsPlacedByPlayer();
			}
			return false;
		}

		internal static bool IsBossLootChest(Container container)
		{
			if ((Object)(object)container == (Object)null || (Object)(object)container.m_nview == (Object)null || !container.m_nview.IsValid())
			{
				return false;
			}
			ZDO zDO = container.m_nview.GetZDO();
			if (zDO != null)
			{
				return zDO.GetInt(186620331, 0) == 1;
			}
			return false;
		}

		internal static Container Find(ZDOID id)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ZNetScene.instance == (Object)null)
			{
				return null;
			}
			GameObject val = ZNetScene.instance.FindInstance(id);
			if (!((Object)(object)val != (Object)null))
			{
				return null;
			}
			return val.GetComponent<Container>();
		}

		internal static void Hint(string text)
		{
			if ((Object)(object)Player.m_localPlayer != (Object)null)
			{
				((Character)Player.m_localPlayer).Message((MessageType)2, text, 0, (Sprite)null, false);
			}
		}
	}
	internal static class ConfirmDialog
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__Yes;

			public static UnityAction <1>__Hide;
		}

		private static GameObject _root;

		private static Text _body;

		private static Action _onYes;

		internal static bool IsOpen
		{
			get
			{
				if ((Object)(object)_root != (Object)null)
				{
					return _root.activeSelf;
				}
				return false;
			}
		}

		internal static void Show(string message, Action onYes)
		{
			Ensure();
			_onYes = onYes;
			if ((Object)(object)_body != (Object)null)
			{
				_body.text = message ?? "";
			}
			_root.SetActive(true);
		}

		internal static void Hide()
		{
			if ((Object)(object)_root != (Object)null)
			{
				_root.SetActive(false);
			}
			_onYes = null;
		}

		internal static void Tick()
		{
			if (IsOpen)
			{
				if (Input.GetKeyDown((KeyCode)27) || Input.GetKeyDown((KeyCode)110))
				{
					Hide();
				}
				else if (Input.GetKeyDown((KeyCode)13) || Input.GetKeyDown((KeyCode)121))
				{
					Yes();
				}
			}
		}

		private static void Yes()
		{
			Action onYes = _onYes;
			Hide();
			onYes?.Invoke();
		}

		private static void Ensure()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_0088: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Expected O, but got Unknown
			//IL_00f4: 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_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: 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_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Expected O, but got Unknown
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Expected O, but got Unknown
			if (!((Object)(object)_root != (Object)null))
			{
				Font builtinResource = Resources.GetBuiltinResource<Font>("Arial.ttf");
				GameObject val = new GameObject("CLR_ConfirmCanvas");
				Object.DontDestroyOnLoad((Object)(object)val);
				Canvas obj = val.AddComponent<Canvas>();
				obj.renderMode = (RenderMode)0;
				obj.sortingOrder = 1100;
				val.AddComponent<CanvasScaler>();
				val.AddComponent<GraphicRaycaster>();
				GameObject val2 = new GameObject("CLR_Dim");
				val2.transform.SetParent(val.transform, false);
				RectTransform obj2 = val2.AddComponent<RectTransform>();
				obj2.anchorMin = Vector2.zero;
				obj2.anchorMax = Vector2.one;
				obj2.offsetMin = Vector2.zero;
				obj2.offsetMax = Vector2.zero;
				Image obj3 = val2.AddComponent<Image>();
				((Graphic)obj3).color = new Color(0f, 0f, 0f, 0.45f);
				((Graphic)obj3).raycastTarget = true;
				GameObject val3 = new GameObject("CLR_Confirm");
				val3.transform.SetParent(val.transform, false);
				RectTransform obj4 = val3.AddComponent<RectTransform>();
				obj4.sizeDelta = new Vector2(421f, 181f);
				obj4.anchoredPosition = Vector2.zero;
				((Graphic)val3.AddComponent<Image>()).color = Color.black;
				GameObject val4 = new GameObject("CLR_ConfirmPanel");
				val4.transform.SetParent(val3.transform, false);
				RectTransform obj5 = val4.AddComponent<RectTransform>();
				obj5.sizeDelta = new Vector2(420f, 180f);
				obj5.anchoredPosition = Vector2.zero;
				Image obj6 = val4.AddComponent<Image>();
				((Graphic)obj6).color = new Color(0.05f, 0.05f, 0.07f, 0.96f);
				((Graphic)obj6).raycastTarget = true;
				MakeText(val4.transform, new Vector2(0f, 58f), new Vector2(380f, 32f), builtinResource, 20, (TextAnchor)4).text = "Split remaining loot?";
				_body = MakeText(val4.transform, new Vector2(0f, 10f), new Vector2(380f, 70f), builtinResource, 16, (TextAnchor)4);
				_body.horizontalOverflow = (HorizontalWrapMode)0;
				Transform transform = val4.transform;
				Vector2 pos = new Vector2(-80f, -58f);
				Color color = new Color(0.22f, 0.45f, 0.22f, 1f);
				object obj7 = <>O.<0>__Yes;
				if (obj7 == null)
				{
					UnityAction val5 = Yes;
					<>O.<0>__Yes = val5;
					obj7 = (object)val5;
				}
				MakeBtn(transform, pos, "Yes", builtinResource, color, (UnityAction)obj7);
				Transform transform2 = val4.transform;
				Vector2 pos2 = new Vector2(80f, -58f);
				Color color2 = new Color(0.4f, 0.22f, 0.22f, 1f);
				object obj8 = <>O.<1>__Hide;
				if (obj8 == null)
				{
					UnityAction val6 = Hide;
					<>O.<1>__Hide = val6;
					obj8 = (object)val6;
				}
				MakeBtn(transform2, pos2, "No", builtinResource, color2, (UnityAction)obj8);
				_root = val;
				_root.SetActive(false);
			}
		}

		private static Text MakeText(Transform parent, Vector2 pos, Vector2 size, Font font, int fontSize, TextAnchor align)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("CLR_Text");
			val.transform.SetParent(parent, false);
			RectTransform obj = val.AddComponent<RectTransform>();
			obj.sizeDelta = size;
			obj.anchoredPosition = pos;
			Text obj2 = val.AddComponent<Text>();
			obj2.font = font;
			obj2.fontSize = fontSize;
			((Graphic)obj2).color = Color.white;
			obj2.alignment = align;
			((Graphic)obj2).raycastTarget = false;
			return obj2;
		}

		private static void MakeBtn(Transform parent, Vector2 pos, string label, Font font, Color color, UnityAction click)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//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_0032: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("CLR_Btn");
			val.transform.SetParent(parent, false);
			RectTransform obj = val.AddComponent<RectTransform>();
			obj.sizeDelta = new Vector2(120f, 40f);
			obj.anchoredPosition = pos;
			Image val2 = val.AddComponent<Image>();
			((Graphic)val2).color = color;
			Button obj2 = val.AddComponent<Button>();
			((Selectable)obj2).targetGraphic = (Graphic)(object)val2;
			((UnityEvent)obj2.onClick).AddListener(click);
			MakeText(val.transform, Vector2.zero, new Vector2(120f, 40f), font, 18, (TextAnchor)4).text = label;
		}
	}
	internal static class EpicLootInfo
	{
		internal struct Info
		{
			public bool Magic;

			public string RarityName;

			public string RarityColor;

			public string SetName;
		}

		private static readonly string[] RarityNames = new string[6] { "Magic", "Rare", "Epic", "Legendary", "Mythic", "Ancient" };

		private static readonly string[] RarityColors = new string[6] { "#4D88FF", "#FFD54A", "#C56CFF", "#4AD8C8", "#FF9A3C", "#E23B3B" };

		private const string MagicKey = "randyknapp.mods.epicloot#EpicLoot.MagicItemComponent";

		internal static bool TryRead(ItemData item, out Info info)
		{
			info = default(Info);
			if (item == null)
			{
				return false;
			}
			if (TryReadViaEpicLoot(item, out info))
			{
				return info.Magic;
			}
			if (TryReadFromJson(item, out info))
			{
				return info.Magic;
			}
			return false;
		}

		private static bool TryReadViaEpicLoot(ItemData item, out Info info)
		{
			info = default(Info);
			try
			{
				Type type = Type.GetType("EpicLoot.ItemDataExtensions, EpicLoot");
				if (type == null)
				{
					return false;
				}
				MethodInfo method = type.GetMethod("GetMagicItem", BindingFlags.Static | BindingFlags.Public);
				if (method == null)
				{
					return false;
				}
				object obj = method.Invoke(null, new object[1] { item });
				if (obj == null)
				{
					return false;
				}
				object obj2 = obj.GetType().GetField("Rarity")?.GetValue(obj);
				int rarity = ((obj2 != null) ? Convert.ToInt32(obj2) : (-1));
				string displayName = obj.GetType().GetField("SetID")?.GetValue(obj) as string;
				string color = null;
				string token = null;
				Type type2 = Type.GetType("EpicLoot.EpicLoot, EpicLoot");
				if (type2 != null && obj2 != null)
				{
					MethodInfo method2 = type2.GetMethod("GetRarityColor", BindingFlags.Static | BindingFlags.Public, null, new Type[1] { obj2.GetType() }, null);
					MethodInfo method3 = type2.GetMethod("GetRarityDisplayName", BindingFlags.Static | BindingFlags.Public, null, new Type[1] { obj2.GetType() }, null);
					if (method2 != null)
					{
						color = method2.Invoke(null, new object[1] { obj2 }) as string;
					}
					if (method3 != null)
					{
						token = method3.Invoke(null, new object[1] { obj2 }) as string;
					}
				}
				info.Magic = true;
				info.RarityName = LocalizeOrFallback(token, rarity);
				info.RarityColor = NormalizeColor(color, rarity);
				info.SetName = SetDisplayName(displayName);
				return true;
			}
			catch
			{
				return false;
			}
		}

		private static bool TryReadFromJson(ItemData item, out Info info)
		{
			info = default(Info);
			if (item.m_customData == null || !item.m_customData.TryGetValue("randyknapp.mods.epicloot#EpicLoot.MagicItemComponent", out var value) || string.IsNullOrEmpty(value))
			{
				return false;
			}
			int num = ReadIntField(value, "Rarity");
			string text = ReadStringField(value, "SetID");
			if (num < 0 && string.IsNullOrEmpty(text))
			{
				return false;
			}
			info.Magic = true;
			info.RarityName = LocalizeOrFallback(null, num);
			info.RarityColor = NormalizeColor(null, num);
			info.SetName = SetDisplayName(text);
			return true;
		}

		private static string SetDisplayName(string setId)
		{
			if (string.IsNullOrEmpty(setId))
			{
				return null;
			}
			try
			{
				if ((Type.GetType("EpicLoot.LegendarySystem.UniqueLegendaryHelper, EpicLoot")?.GetField("AllSets", BindingFlags.Static | BindingFlags.Public))?.GetValue(null) is IDictionary dictionary && dictionary.Contains(setId))
				{
					object obj = dictionary[setId];
					string text = obj?.GetType().GetField("Name")?.GetValue(obj) as string;
					if (!string.IsNullOrEmpty(text))
					{
						return Localize(text);
					}
				}
			}
			catch
			{
			}
			return setId;
		}

		private static string LocalizeOrFallback(string token, int rarity)
		{
			if (!string.IsNullOrEmpty(token))
			{
				string text = Localize(token);
				if (!string.IsNullOrEmpty(text) && text != token)
				{
					return text;
				}
				if (token.StartsWith("$", StringComparison.Ordinal))
				{
					return FallbackName(rarity);
				}
				return text;
			}
			return FallbackName(rarity);
		}

		private static string FallbackName(int rarity)
		{
			if (rarity >= 0 && rarity < RarityNames.Length)
			{
				return RarityNames[rarity];
			}
			return "Magic";
		}

		private static string NormalizeColor(string color, int rarity)
		{
			if (!string.IsNullOrEmpty(color) && color != "white")
			{
				Color val = default(Color);
				if (color[0] != '#' && ColorUtility.TryParseHtmlString(NamedToHex(color), ref val))
				{
					return NamedToHex(color);
				}
				if (color[0] == '#' || ColorUtility.TryParseHtmlString(color, ref val))
				{
					return color;
				}
			}
			if (rarity >= 0 && rarity < RarityColors.Length)
			{
				return RarityColors[rarity];
			}
			return "#FFFFFF";
		}

		private static string NamedToHex(string name)
		{
			return name switch
			{
				"Red" => "#E23B3B", 
				"Orange" => "#FF9A3C", 
				"Yellow" => "#FFD54A", 
				"Green" => "#4CAF50", 
				"Teal" => "#4AD8C8", 
				"Blue" => "#4D88FF", 
				"Indigo" => "#6C63FF", 
				"Purple" => "#C56CFF", 
				"Pink" => "#FF7AB6", 
				"Gray" => "#9E9E9E", 
				_ => name, 
			};
		}

		private static string Localize(string text)
		{
			if (string.IsNullOrEmpty(text) || Localization.instance == null)
			{
				return text;
			}
			return Localization.instance.Localize(text);
		}

		private static int ReadIntField(string json, string field)
		{
			string value = "\"" + field + "\"";
			int num = json.IndexOf(value, StringComparison.Ordinal);
			if (num < 0)
			{
				return -1;
			}
			num = json.IndexOf(':', num);
			if (num < 0)
			{
				return -1;
			}
			for (num++; num < json.Length && char.IsWhiteSpace(json[num]); num++)
			{
			}
			int num2 = num;
			for (; num < json.Length && (char.IsDigit(json[num]) || json[num] == '-'); num++)
			{
			}
			if (int.TryParse(json.Substring(num2, num - num2), NumberStyles.Integer, CultureInfo.InvariantCulture, out var result))
			{
				return result;
			}
			return -1;
		}

		private static string ReadStringField(string json, string field)
		{
			string value = "\"" + field + "\"";
			int num = json.IndexOf(value, StringComparison.Ordinal);
			if (num < 0)
			{
				return null;
			}
			num = json.IndexOf(':', num);
			if (num < 0)
			{
				return null;
			}
			num = json.IndexOf('"', num);
			if (num < 0)
			{
				return null;
			}
			num++;
			int num2 = json.IndexOf('"', num);
			if (num2 < 0)
			{
				return null;
			}
			string text = json.Substring(num, num2 - num);
			if (!string.IsNullOrEmpty(text))
			{
				return text;
			}
			return null;
		}
	}
	[HarmonyPatch(typeof(Menu), "Update")]
	internal static class EscMenuPatch
	{
		private static bool Prefix()
		{
			if (ConfirmDialog.IsOpen)
			{
				if (Input.GetKeyDown((KeyCode)27))
				{
					ConfirmDialog.Hide();
				}
				return false;
			}
			if (!RollWindow.IsOpen)
			{
				return true;
			}
			if (!Input.GetKeyDown((KeyCode)27))
			{
				return true;
			}
			RollClient.Escape();
			return false;
		}
	}
	internal static class InputHook
	{
		internal static void Tick()
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_00b9: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			if (!ModConfig.Enabled.Value || ((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus()) || Console.IsVisible() || TextInput.IsVisible())
			{
				return;
			}
			if (ConfirmDialog.IsOpen)
			{
				ConfirmDialog.Tick();
			}
			else if (RollWindow.IsOpen)
			{
				if (Input.GetKeyDown((KeyCode)27))
				{
					RollClient.Escape();
				}
				TryVoteKey(ModConfig.NeedKey.Value, 3);
				TryVoteKey(ModConfig.GreedKey.Value, 2);
				TryVoteKey(ModConfig.PassKey.Value, 1);
			}
			else if (InventoryGui.IsVisible())
			{
				if ((int)ModConfig.ShareKey.Value != 0 && Input.GetKeyDown(ModConfig.ShareKey.Value))
				{
					TryShare();
				}
				else if ((int)ModConfig.Hotkey.Value != 0 && Input.GetKeyDown(ModConfig.Hotkey.Value))
				{
					TryStart();
				}
			}
		}

		private static void TryStart()
		{
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			Container val = ChestUtil.CurrentChest();
			if ((Object)(object)val == (Object)null)
			{
				ChestUtil.Hint("Open a chest and hover an item.");
				return;
			}
			if ((Object)(object)val.m_wagon != (Object)null)
			{
				ChestUtil.Hint("You cannot roll on cart chests.");
				return;
			}
			if (!ModConfig.AllowPlayerChests.Value && ChestUtil.IsPlayerChest(val))
			{
				ChestUtil.Hint("Player-placed chests cannot be rolled.");
				return;
			}
			ItemData val2 = ChestUtil.HoveredChestItem();
			if (val2 == null)
			{
				ChestUtil.Hint("Hover an item in the chest.");
			}
			else if (ModConfig.MagicItemsOnly.Value && !ItemCodec.IsMagic(val2))
			{
				ChestUtil.Hint("Only magic items can be rolled.");
			}
			else if (!((Object)(object)val.m_nview == (Object)null) && val.m_nview.IsValid())
			{
				ZPackage val3 = new ZPackage();
				Net.WriteId(val3, val.m_nview.GetZDO().m_uid);
				val3.Write(val2.m_gridPos.x);
				val3.Write(val2.m_gridPos.y);
				ItemCodec.WriteItem(val3, val2);
				RollServer.ToServer("CLR_Req", val3);
			}
		}

		private static void TryShare()
		{
			Container val = ChestUtil.CurrentChest();
			if ((Object)(object)val == (Object)null)
			{
				ChestUtil.Hint("Open a chest first.");
			}
			else if ((Object)(object)val.m_wagon != (Object)null)
			{
				ChestUtil.Hint("You cannot share cart chests.");
			}
			else if (!ModConfig.AllowPlayerChests.Value && ChestUtil.IsPlayerChest(val))
			{
				ChestUtil.Hint("Player-placed chests cannot be shared this way.");
			}
			else
			{
				if ((Object)(object)val.m_nview == (Object)null || !val.m_nview.IsValid())
				{
					return;
				}
				Inventory inventory = val.GetInventory();
				if (inventory != null)
				{
					List<ItemData> allItems = inventory.GetAllItems();
					if (allItems == null || allItems.Count == 0)
					{
						ChestUtil.Hint("The chest is empty.");
						return;
					}
					int count = allItems.Count;
					ConfirmDialog.Show("This will split " + count + " stack" + ((count == 1) ? "" : "s") + " among the party. Stacks are divided evenly; leftover singles go round-robin.\n\nContinue?", SendShare);
				}
			}
		}

		private static void SendShare()
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			Container val = ChestUtil.CurrentChest();
			if ((Object)(object)val == (Object)null || (Object)(object)val.m_nview == (Object)null || !val.m_nview.IsValid())
			{
				ChestUtil.Hint("The chest is no longer open.");
				return;
			}
			Inventory inventory = val.GetInventory();
			if (inventory == null)
			{
				return;
			}
			List<ItemData> allItems = inventory.GetAllItems();
			if (allItems == null || allItems.Count == 0)
			{
				ChestUtil.Hint("The chest is empty.");
				return;
			}
			ZPackage val2 = new ZPackage();
			Net.WriteId(val2, val.m_nview.GetZDO().m_uid);
			val2.Write(allItems.Count);
			foreach (ItemData item in allItems)
			{
				val2.Write(ItemCodec.ToBytes(item));
			}
			RollServer.ToServer("CLR_Split", val2);
		}

		private static void TryVoteKey(KeyCode key, int choice)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			if ((int)key != 0 && Input.GetKeyDown(key))
			{
				RollClient.Vote(choice);
			}
		}
	}
	internal static class ItemCodec
	{
		private static readonly Regex PosTag = new Regex("</?pos[^>]*>", RegexOptions.IgnoreCase | RegexOptions.Compiled);

		private static readonly Regex UnsupportedTag = new Regex("</?(align|voffset|offset|indent|line-height|margin|width|sprite|link|alpha|mark|cspace|mspace|noparse|nobr|page|space|lowercase|uppercase|smallcaps)[^>]*>", RegexOptions.IgnoreCase | RegexOptions.Compiled);

		private static readonly Regex ExtraNewlines = new Regex("\n{3,}", RegexOptions.Compiled);

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

		internal static byte[] ToBytes(ItemData item)
		{
			//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_000c: Expected O, but got Unknown
			ZPackage val = new ZPackage();
			WriteItem(val, item);
			return val.GetArray();
		}

		internal static void WriteItem(ZPackage pkg, ItemData item)
		{
			pkg.Write(PrefabName(item));
			pkg.Write(item.m_stack);
			pkg.Write(item.m_durability);
			pkg.Write(item.m_quality);
			pkg.Write(item.m_variant);
			pkg.Write(item.m_crafterID);
			pkg.Write(item.m_crafterName ?? "");
			pkg.Write(item.m_worldLevel);
			pkg.Write(item.m_pickedUp);
			pkg.Write(item.m_cheated);
			pkg.Write((item.m_customData != null) ? item.m_customData.Count : 0);
			if (item.m_customData == null)
			{
				return;
			}
			foreach (KeyValuePair<string, string> customDatum in item.m_customData)
			{
				pkg.Write(customDatum.Key);
				pkg.Write(customDatum.Value ?? "");
			}
		}

		internal static ItemData ReadItem(ZPackage pkg)
		{
			string text = pkg.ReadString();
			int num = pkg.ReadInt();
			float durability = pkg.ReadSingle();
			int quality = pkg.ReadInt();
			int variant = pkg.ReadInt();
			long crafterID = pkg.ReadLong();
			string crafterName = pkg.ReadString();
			int num2 = pkg.ReadInt();
			bool pickedUp = pkg.ReadBool();
			bool cheated = pkg.ReadBool();
			int num3 = pkg.ReadInt();
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			for (int i = 0; i < num3; i++)
			{
				string text2 = pkg.ReadString();
				string value = pkg.ReadString();
				if (!string.IsNullOrEmpty(text2))
				{
					dictionary[text2] = value;
				}
			}
			if ((Object)(object)ObjectDB.instance == (Object)null)
			{
				return null;
			}
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(text);
			if ((Object)(object)itemPrefab == (Object)null)
			{
				return null;
			}
			ItemDrop component = itemPrefab.GetComponent<ItemDrop>();
			if ((Object)(object)component == (Object)null)
			{
				return null;
			}
			ItemData obj = component.m_itemData.Clone();
			obj.m_dropPrefab = itemPrefab;
			obj.m_stack = Mathf.Max(1, num);
			obj.m_durability = durability;
			obj.m_quality = quality;
			obj.m_variant = variant;
			obj.m_crafterID = crafterID;
			obj.m_crafterName = crafterName;
			obj.m_worldLevel = (byte)num2;
			obj.m_pickedUp = pickedUp;
			obj.m_cheated = cheated;
			obj.m_equipped = false;
			obj.m_customData = dictionary;
			return obj;
		}

		internal static bool SameItem(ItemData a, ItemData b)
		{
			if (a == null || b == null)
			{
				return false;
			}
			if (PrefabName(a) == PrefabName(b) && a.m_stack == b.m_stack && a.m_quality == b.m_quality)
			{
				return a.m_variant == b.m_variant;
			}
			return false;
		}

		internal static bool IsMagic(ItemData item)
		{
			if (item == null || item.m_customData == null)
			{
				return false;
			}
			foreach (string key in item.m_customData.Keys)
			{
				if (key != null && key.IndexOf("EpicLoot", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return true;
				}
				if (key == "MagicItem" || key == "epicloot")
				{
					return true;
				}
			}
			return false;
		}

		internal static string BaseName(ItemData item)
		{
			if (item == null)
			{
				return "item";
			}
			string text = ((Localization.instance != null) ? Localization.instance.Localize(item.m_shared.m_name) : item.m_shared.m_name);
			if (item.m_stack > 1)
			{
				text = text + " x" + item.m_stack;
			}
			return text;
		}

		internal static string DisplayName(ItemData item)
		{
			if (item == null)
			{
				return "item";
			}
			string text = BaseName(item);
			if (EpicLootInfo.TryRead(item, out var info) && info.Magic)
			{
				text = info.RarityName + " " + text;
				if (!string.IsNullOrEmpty(info.SetName))
				{
					text = text + " [" + info.SetName + "]";
				}
			}
			return text;
		}

		internal static string Tooltip(ItemData item)
		{
			if (item == null)
			{
				return "";
			}
			try
			{
				string text = item.GetTooltip(-1);
				if (Localization.instance != null)
				{
					text = Localization.instance.Localize(text);
				}
				return CleanTooltip(text);
			}
			catch
			{
				return DisplayName(item);
			}
		}

		internal static string CleanTooltip(string raw)
		{
			if (string.IsNullOrEmpty(raw))
			{
				return "";
			}
			string text = raw.Replace("\\n", "\n");
			text = text.Replace("<br>", "\n").Replace("<br/>", "\n").Replace("<BR>", "\n")
				.Replace("<BR/>", "\n");
			text = PosTag.Replace(text, "\n");
			text = UnsupportedTag.Replace(text, "");
			text = ExtraNewlines.Replace(text, "\n\n");
			return text.Trim();
		}
	}
	internal static class ModConfig
	{
		internal static ConfigEntry<KeyCode> Hotkey;

		internal static ConfigEntry<KeyCode> ShareKey;

		internal static ConfigEntry<KeyCode> NeedKey;

		internal static ConfigEntry<KeyCode> GreedKey;

		internal static ConfigEntry<KeyCode> PassKey;

		internal static ConfigEntry<float> Range;

		internal static ConfigEntry<bool> RequireParty;

		internal static ConfigEntry<bool> RequireRange;

		internal static ConfigEntry<int> MinPlayers;

		internal static ConfigEntry<float> TimeoutSeconds;

		internal static ConfigEntry<bool> AllowPlayerChests;

		internal static ConfigEntry<bool> MagicItemsOnly;

		internal static ConfigEntry<bool> OnlyPartyLeaderCanRoll;

		internal static ConfigEntry<bool> OnlyPartyLeaderOpensBossChests;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<bool> SoloTestMode;

		internal static void Bind(ConfigFile config)
		{
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Expected O, but got Unknown
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Expected O, but got Unknown
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Expected O, but got Unknown
			Enabled = config.Bind<bool>("General", "Enabled", true, "Turn chest loot rolls on or off.");
			SoloTestMode = config.Bind<bool>("General", "SoloTestMode", false, "DEV ONLY: skip SocialSystem party checks when you are the only player on the server. Turn off before publishing or playing for real.");
			Hotkey = config.Bind<KeyCode>("Keys", "StartRoll", (KeyCode)114, "Default R. While a chest is open, hover an item and press this to start a party Need/Greed/Pass roll.");
			ShareKey = config.Bind<KeyCode>("Keys", "ShareRest", (KeyCode)116, "Default T. While a chest is open, divide stackable items as evenly as possible among the party, then round-robin leftover singles to the next player in line. Overflow that will not fit in a bag spawns a chest at that player's feet.");
			NeedKey = config.Bind<KeyCode>("Keys", "Need", (KeyCode)0, "Hotkey for Need while the roll window is open. Default None (click the button). Suggestions: F6, Alpha1.");
			GreedKey = config.Bind<KeyCode>("Keys", "Greed", (KeyCode)0, "Hotkey for Greed while the roll window is open. Default None (click the button). Suggestions: F7, Alpha2.");
			PassKey = config.Bind<KeyCode>("Keys", "Pass", (KeyCode)0, "Hotkey for Pass while the roll window is open. Default None (click the button). Suggestions: F8, Alpha3.");
			RequireParty = config.Bind<bool>("Party", "RequireParty", true, "If on (default) and SocialSystem is installed, players must be in a party to roll or split. If SocialSystem is not installed, this is ignored and nearby players within Range are used instead. Set off to always allow Range fallback even when SocialSystem is present.");
			RequireRange = config.Bind<bool>("Party", "RequireRange", false, "If off (default) and you are in a SocialSystem party, every party member can roll or share from any distance. If on, they must be within Range metres of the chest.");
			Range = config.Bind<float>("Party", "Range", 50f, new ConfigDescription("Metres from the chest. Used when RequireRange is on, and when RequireParty is off and nobody is in a party.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 200f), Array.Empty<object>()));
			OnlyPartyLeaderCanRoll = config.Bind<bool>("Party", "OnlyPartyLeaderCanRoll", false, "If on, only the SocialSystem party leader can start a Need/Greed/Pass roll.");
			OnlyPartyLeaderOpensBossChests = config.Bind<bool>("Party", "OnlyPartyLeaderOpensBossChests", false, "If on, only the party leader can open a Boss Loot Chest (cjayride.BossLootChests). Off by default.");
			MinPlayers = config.Bind<int>("Party", "MinPlayers", 2, new ConfigDescription("A roll needs at least this many eligible party members nearby.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 10), Array.Empty<object>()));
			TimeoutSeconds = config.Bind<float>("Party", "TimeoutSeconds", 30f, new ConfigDescription("Unvoted members Pass after this many seconds.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(8f, 120f), Array.Empty<object>()));
			AllowPlayerChests = config.Bind<bool>("Chests", "AllowPlayerChests", false, "If off, chests placed by players cannot be rolled. World and dungeon chests still can.");
			MagicItemsOnly = config.Bind<bool>("Chests", "MagicItemsOnly", false, "If on and Epic Loot is installed, only magic items can be rolled.");
		}
	}
	internal static class Net
	{
		[HarmonyPatch(typeof(Game), "Start")]
		private static class RegisterPatch
		{
			private static void Postfix()
			{
				if (ZRoutedRpc.instance != null)
				{
					ZRoutedRpc.instance.Register<string>("CLR_Req", (Action<long, string>)delegate(long s, string p)
					{
						Dispatch(s, "CLR_Req", p);
					});
					ZRoutedRpc.instance.Register<string>("CLR_Removed", (Action<long, string>)delegate(long s, string p)
					{
						Dispatch(s, "CLR_Removed", p);
					});
					ZRoutedRpc.instance.Register<string>("CLR_Vote", (Action<long, string>)delegate(long s, string p)
					{
						Dispatch(s, "CLR_Vote", p);
					});
					ZRoutedRpc.instance.Register<string>("CLR_Open", (Action<long, string>)delegate(long s, string p)
					{
						Dispatch(s, "CLR_Open", p);
					});
					ZRoutedRpc.instance.Register<string>("CLR_Chat", (Action<long, string>)delegate(long s, string p)
					{
						Dispatch(s, "CLR_Chat", p);
					});
					ZRoutedRpc.instance.Register<string>("CLR_Give", (Action<long, string>)delegate(long s, string p)
					{
						Dispatch(s, "CLR_Give", p);
					});
					ZRoutedRpc.instance.Register<string>("CLR_Lock", (Action<long, string>)delegate(long s, string p)
					{
						Dispatch(s, "CLR_Lock", p);
					});
					ZRoutedRpc.instance.Register<string>("CLR_Close", (Action<long, string>)delegate(long s, string p)
					{
						Dispatch(s, "CLR_Close", p);
					});
					ZRoutedRpc.instance.Register<string>("CLR_Split", (Action<long, string>)delegate(long s, string p)
					{
						Dispatch(s, "CLR_Split", p);
					});
					ZRoutedRpc.instance.Register<string>("CLR_Cancel", (Action<long, string>)delegate(long s, string p)
					{
						Dispatch(s, "CLR_Cancel", p);
					});
				}
			}
		}

		internal const string Req = "CLR_Req";

		internal const string Removed = "CLR_Removed";

		internal const string Vote = "CLR_Vote";

		internal const string Open = "CLR_Open";

		internal const string Chat = "CLR_Chat";

		internal const string Give = "CLR_Give";

		internal const string Lock = "CLR_Lock";

		internal const string Close = "CLR_Close";

		internal const string Split = "CLR_Split";

		internal const string Cancel = "CLR_Cancel";

		internal static void Dispatch(long sender, string rpc, string payload)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			ZPackage pkg = new ZPackage(payload ?? "");
			if (rpc == null)
			{
				return;
			}
			switch (rpc.Length)
			{
			case 8:
				switch (rpc[4])
				{
				case 'V':
					if (rpc == "CLR_Vote")
					{
						RollServer.OnVote(sender, pkg);
					}
					break;
				case 'O':
					if (rpc == "CLR_Open")
					{
						RollClient.OnOpen(pkg);
					}
					break;
				case 'C':
					if (rpc == "CLR_Chat")
					{
						ChatRelay.OnChat(pkg);
					}
					break;
				case 'G':
					if (rpc == "CLR_Give")
					{
						RollClient.OnGive(pkg);
					}
					break;
				case 'L':
					if (rpc == "CLR_Lock")
					{
						RollClient.OnLock(pkg);
					}
					break;
				}
				break;
			case 9:
				switch (rpc[4])
				{
				case 'C':
					if (rpc == "CLR_Close")
					{
						RollClient.OnClose(pkg);
					}
					break;
				case 'S':
					if (rpc == "CLR_Split")
					{
						SplitLoot.OnRequest(sender, pkg);
					}
					break;
				}
				break;
			case 7:
				if (rpc == "CLR_Req")
				{
					RollServer.OnRequest(sender, pkg);
				}
				break;
			case 11:
				if (rpc == "CLR_Removed")
				{
					RollServer.OnRemoved(sender, pkg);
				}
				break;
			case 10:
				if (rpc == "CLR_Cancel")
				{
					RollServer.OnCancel(sender, pkg);
				}
				break;
			}
		}

		internal static void WriteId(ZPackage pkg, ZDOID id)
		{
			pkg.Write(((ZDOID)(ref id)).UserID);
			pkg.Write(((ZDOID)(ref id)).ID);
		}

		internal static ZDOID ReadId(ZPackage pkg)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			long num = pkg.ReadLong();
			uint num2 = pkg.ReadUInt();
			return new ZDOID(num, num2);
		}
	}
	internal static class PartyUtil
	{
		private static readonly int PartyIdHash = StringExtensionMethods.GetStableHashCode("SocialSystem_PartyId");

		private const string SocialGuid = "M2Valheim.SocialSystem";

		internal static bool SocialSystemInstalled()
		{
			try
			{
				if (Chainloader.PluginInfos != null && Chainloader.PluginInfos.ContainsKey("M2Valheim.SocialSystem"))
				{
					return true;
				}
			}
			catch
			{
			}
			if (!(Type.GetType("SocialSystem.Server.SocialServer, SocialSystem") != null))
			{
				return Type.GetType("SocialSystem.Client.SocialClient, SocialSystem") != null;
			}
			return true;
		}

		internal static bool MustBeInParty()
		{
			if (ModConfig.RequireParty.Value)
			{
				return SocialSystemInstalled();
			}
			return false;
		}

		internal static int GetPartyId(ZDO zdo)
		{
			if (zdo == null)
			{
				return 0;
			}
			return zdo.GetInt(PartyIdHash, 0);
		}

		internal static int GetPartyIdForPeer(long uid)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			if (IsLocalUid(uid))
			{
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)localPlayer != (Object)null && (Object)(object)((Character)localPlayer).m_nview != (Object)null)
				{
					return GetPartyId(((Character)localPlayer).m_nview.GetZDO());
				}
				return 0;
			}
			ZNetPeer val = (((Object)(object)ZNet.instance != (Object)null) ? ZNet.instance.GetPeer(uid) : null);
			if (val == null)
			{
				return 0;
			}
			return GetPartyId((ZDOMan.instance != null) ? ZDOMan.instance.GetZDO(val.m_characterID) : null);
		}

		internal static bool IsLocalUid(long uid)
		{
			if ((Object)(object)ZNet.instance != (Object)null)
			{
				return uid == ZNet.GetUID();
			}
			return false;
		}

		internal static string GetName(long uid)
		{
			if (IsLocalUid(uid) && (Object)(object)Player.m_localPlayer != (Object)null)
			{
				return Player.m_localPlayer.GetPlayerName();
			}
			ZNetPeer val = (((Object)(object)ZNet.instance != (Object)null) ? ZNet.instance.GetPeer(uid) : null);
			if (val != null && !string.IsNullOrEmpty(val.m_playerName))
			{
				return val.m_playerName;
			}
			return "Unknown";
		}

		internal static Vector3 GetPos(long uid)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if (IsLocalUid(uid) && (Object)(object)Player.m_localPlayer != (Object)null)
			{
				return ((Component)Player.m_localPlayer).transform.position;
			}
			return (((Object)(object)ZNet.instance != (Object)null) ? ZNet.instance.GetPeer(uid) : null)?.m_refPos ?? Vector3.zero;
		}

		internal static List<long> GetEligible(int partyId, Vector3 chestPos, bool requireRange, float range)
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			List<long> list = new List<long>();
			if ((Object)(object)ZNet.instance == (Object)null)
			{
				return list;
			}
			bool flag = partyId != 0;
			bool flag2 = !flag || requireRange;
			float num = range * range;
			Vector3 val;
			if (!ZNet.instance.IsDedicated() && (Object)(object)Player.m_localPlayer != (Object)null)
			{
				int partyId2 = GetPartyId(((Object)(object)((Character)Player.m_localPlayer).m_nview != (Object)null) ? ((Character)Player.m_localPlayer).m_nview.GetZDO() : null);
				bool num2 = !flag || partyId2 == partyId;
				Vector3 position = ((Component)Player.m_localPlayer).transform.position;
				int num3;
				if (flag2)
				{
					val = position - chestPos;
					num3 = ((((Vector3)(ref val)).sqrMagnitude <= num) ? 1 : 0);
				}
				else
				{
					num3 = 1;
				}
				bool flag3 = (byte)num3 != 0;
				if (num2 && flag3)
				{
					list.Add(ZNet.GetUID());
				}
			}
			foreach (ZNetPeer peer in ZNet.instance.GetPeers())
			{
				if (peer == null || !peer.IsReady())
				{
					continue;
				}
				ZDO zdo = ((ZDOMan.instance != null) ? ZDOMan.instance.GetZDO(peer.m_characterID) : null);
				if (flag && GetPartyId(zdo) != partyId)
				{
					continue;
				}
				if (flag2)
				{
					val = peer.m_refPos - chestPos;
					if (((Vector3)(ref val)).sqrMagnitude > num)
					{
						continue;
					}
				}
				if (!list.Contains(peer.m_uid))
				{
					list.Add(peer.m_uid);
				}
			}
			return list;
		}

		internal static bool IsPartyLeader(long netUid)
		{
			long playerId = GetPlayerId(netUid);
			if (playerId == 0L)
			{
				return false;
			}
			try
			{
				Type type = Type.GetType("SocialSystem.Server.SocialServer, SocialSystem");
				object obj = type?.GetField("Instance", BindingFlags.Static | BindingFlags.Public)?.GetValue(null);
				if (obj != null)
				{
					object obj2 = type.GetField("_parties", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(obj);
					if (obj2 != null)
					{
						MethodInfo method = obj2.GetType().GetMethod("GetParty", new Type[1] { typeof(long) });
						object obj3 = ((method != null) ? method.Invoke(obj2, new object[1] { playerId }) : null);
						if (obj3 != null)
						{
							MethodInfo method2 = obj3.GetType().GetMethod("IsLeader", new Type[1] { typeof(long) });
							if (method2 != null)
							{
								return (bool)method2.Invoke(obj3, new object[1] { playerId });
							}
						}
					}
				}
				Type type2 = Type.GetType("SocialSystem.Client.SocialClient, SocialSystem");
				object obj4 = type2?.GetField("Instance", BindingFlags.Static | BindingFlags.Public)?.GetValue(null);
				if (obj4 == null)
				{
					return false;
				}
				object obj5 = type2.GetProperty("Party")?.GetValue(obj4);
				if (obj5 == null)
				{
					return false;
				}
				MethodInfo method3 = obj5.GetType().GetMethod("IsLeader", new Type[1] { typeof(long) });
				return method3 != null && (bool)method3.Invoke(obj5, new object[1] { playerId });
			}
			catch
			{
				return false;
			}
		}

		internal static long GetPlayerId(long netUid)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			if (IsLocalUid(netUid) && (Object)(object)Game.instance != (Object)null)
			{
				return Game.instance.GetPlayerProfile().GetPlayerID();
			}
			ZNetPeer val = (((Object)(object)ZNet.instance != (Object)null) ? ZNet.instance.GetPeer(netUid) : null);
			if (val != null)
			{
				foreach (Player allPlayer in Player.GetAllPlayers())
				{
					if (!((Object)(object)allPlayer == (Object)null) && !((Object)(object)((Character)allPlayer).m_nview == (Object)null) && ((Character)allPlayer).m_nview.IsValid() && ((Character)allPlayer).m_nview.GetZDO().m_uid == val.m_characterID)
					{
						return allPlayer.GetPlayerID();
					}
				}
			}
			return 0L;
		}

		internal static void Send(long uid, string rpc, ZPackage pkg)
		{
			string @base = pkg.GetBase64();
			if (uid == 0L)
			{
				ZRoutedRpc.instance.InvokeRoutedRPC(0L, rpc, new object[1] { @base });
			}
			else if (IsLocalUid(uid))
			{
				Net.Dispatch(uid, rpc, @base);
			}
			else
			{
				ZRoutedRpc.instance.InvokeRoutedRPC(uid, rpc, new object[1] { @base });
			}
		}

		internal static void SendToMany(List<long> uids, string rpc, ZPackage pkg)
		{
			foreach (long uid in uids)
			{
				Send(uid, rpc, pkg);
			}
		}
	}
	[BepInPlugin("cjayride.ChestLootRoll", "Chest Loot Roll", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "cjayride.ChestLootRoll";

		public const string PluginName = "Chest Loot Roll";

		public const string PluginVersion = "1.0.0";

		internal static Plugin Instance;

		internal static Harmony Harmony;

		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.ChestLootRoll");
			Harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Chest Loot Roll 1.0.0 loaded.");
		}

		private void Update()
		{
			if ((Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer())
			{
				RollServer.Tick();
			}
			if ((Object)(object)ZNet.instance != (Object)null && !ZNet.instance.IsDedicated())
			{
				InputHook.Tick();
				RollWindow.Tick();
			}
		}
	}
	internal static class RollClient
	{
		internal static bool SkipLock;

		private static ZDOID _lockChest = ZDOID.None;

		private static int _lockX = -1;

		private static int _lockY = -1;

		private static bool _locked;

		internal static string CurrentRollId;

		internal static bool Voted;

		internal static bool IsStarter;

		internal static void OnLock(ZPackage pkg)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			_locked = pkg.ReadBool();
			_lockChest = Net.ReadId(pkg);
			_lockX = pkg.ReadInt();
			_lockY = pkg.ReadInt();
			if (!_locked)
			{
				_lockChest = ZDOID.None;
				_lockX = -1;
				_lockY = -1;
			}
		}

		internal static bool IsLocked(Inventory inventory, ItemData item)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			if (SkipLock || !_locked || item == null || inventory == null)
			{
				return false;
			}
			Container val = ChestUtil.Find(_lockChest);
			if ((Object)(object)val == (Object)null || val.GetInventory() != inventory)
			{
				return false;
			}
			if (item.m_gridPos.x == _lockX)
			{
				return item.m_gridPos.y == _lockY;
			}
			return false;
		}

		internal static void OnOpen(ZPackage pkg)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			CurrentRollId = pkg.ReadString();
			string starter = pkg.ReadString();
			long num = pkg.ReadLong();
			string display = pkg.ReadString();
			float timeout = pkg.ReadSingle();
			ItemData item = ItemCodec.ReadItem(new ZPackage(pkg.ReadByteArray()));
			Voted = false;
			IsStarter = num != 0L && num == ZNet.GetUID();
			RollWindow.Show(CurrentRollId, starter, display, item, timeout);
		}

		internal static void OnClose(ZPackage pkg)
		{
			if (pkg.ReadString() == CurrentRollId)
			{
				CurrentRollId = null;
				Voted = false;
				IsStarter = false;
				RollWindow.Hide();
			}
		}

		internal static void OnGive(ZPackage pkg)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_0030: 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_0045: Expected O, but got Unknown
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			switch (pkg.ReadInt())
			{
			case 2:
				ConfirmRemove(pkg);
				break;
			case 0:
				GiveToLocal(ItemCodec.ReadItem(new ZPackage(pkg.ReadByteArray())));
				break;
			case 1:
			{
				ZDOID chestId = Net.ReadId(pkg);
				ItemData item = ItemCodec.ReadItem(new ZPackage(pkg.ReadByteArray()));
				ReturnToChest(chestId, item);
				break;
			}
			case 3:
			{
				int num = pkg.ReadInt();
				List<ItemData> list = new List<ItemData>();
				for (int i = 0; i < num; i++)
				{
					ItemData val = ItemCodec.ReadItem(new ZPackage(pkg.ReadByteArray()));
					if (val != null && !TryGive(val))
					{
						list.Add(val);
					}
				}
				if (list.Count > 0)
				{
					SpawnOverflowChest(list);
				}
				break;
			}
			case 6:
				ClearChest(Net.ReadId(pkg));
				break;
			}
		}

		private static void ConfirmRemove(ZPackage pkg)
		{
			//IL_0008: 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_002b: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			string text = pkg.ReadString();
			ZDOID id = Net.ReadId(pkg);
			int num = pkg.ReadInt();
			int num2 = pkg.ReadInt();
			ItemData val = ItemCodec.ReadItem(new ZPackage(pkg.ReadByteArray()));
			Container val2 = ChestUtil.Find(id);
			bool flag = false;
			if ((Object)(object)val2 != (Object)null && val != null)
			{
				Inventory inventory = val2.GetInventory();
				ItemData val3 = ((inventory != null) ? inventory.GetItemAt(num, num2) : null);
				if (ItemCodec.SameItem(val3, val))
				{
					SkipLock = true;
					try
					{
						inventory.RemoveItem(val3);
						flag = true;
					}
					finally
					{
						SkipLock = false;
					}
				}
			}
			ZPackage val4 = new ZPackage();
			val4.Write(text);
			val4.Write(flag);
			RollServer.ToServer("CLR_Removed", val4);
		}

		private static void GiveToLocal(ItemData item)
		{
			//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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			if (item != null && !((Object)(object)Player.m_localPlayer == (Object)null) && !TryGive(item))
			{
				ItemDrop.DropItem(item, item.m_stack, ((Component)Player.m_localPlayer).transform.position + Vector3.up, Quaternion.identity);
			}
		}

		private static bool TryGive(ItemData item)
		{
			if (item == null || (Object)(object)Player.m_localPlayer == (Object)null)
			{
				return false;
			}
			SkipLock = true;
			try
			{
				return ((Humanoid)Player.m_localPlayer).GetInventory().AddItem(item);
			}
			finally
			{
				SkipLock = false;
			}
		}

		private static void ClearChest(ZDOID chestId)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			Container val = ChestUtil.Find(chestId);
			if ((Object)(object)val == (Object)null || val.GetInventory() == null)
			{
				return;
			}
			SkipLock = true;
			try
			{
				foreach (ItemData item in new List<ItemData>(val.GetInventory().GetAllItems()))
				{
					val.GetInventory().RemoveItem(item);
				}
				val.GetInventory().Changed(false, false);
			}
			finally
			{
				SkipLock = false;
			}
		}

		private static void SpawnOverflowChest(List<ItemData> items)
		{
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00d9: 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_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			if (items == null || items.Count == 0 || (Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)ZNetScene.instance == (Object)null)
			{
				return;
			}
			GameObject prefab = ZNetScene.instance.GetPrefab("piece_chest_wood");
			if ((Object)(object)prefab == (Object)null)
			{
				prefab = ZNetScene.instance.GetPrefab("piece_chest");
			}
			if ((Object)(object)prefab == (Object)null)
			{
				foreach (ItemData item in items)
				{
					ItemDrop.DropItem(item, item.m_stack, ((Component)Player.m_localPlayer).transform.position + Vector3.up, Quaternion.identity);
				}
				return;
			}
			Vector3 val = ((Component)Player.m_localPlayer).transform.position + ((Component)Player.m_localPlayer).transform.forward * 1.4f;
			Container component = Object.Instantiate<GameObject>(prefab, val, Quaternion.identity).GetComponent<Container>();
			if ((Object)(object)component == (Object)null || component.GetInventory() == null)
			{
				return;
			}
			foreach (ItemData item2 in items)
			{
				if (!component.GetInventory().AddItem(item2))
				{
					ItemDrop.DropItem(item2, item2.m_stack, val + Vector3.up, Quaternion.identity);
				}
			}
			component.GetInventory().Changed(false, false);
			ChestUtil.Hint("Your bags were full. Extra loot is in a chest at your feet.");
		}

		private static void ReturnToChest(ZDOID chestId, ItemData item)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			if (item == null)
			{
				return;
			}
			Container val = ChestUtil.Find(chestId);
			SkipLock = true;
			try
			{
				if ((!((Object)(object)val != (Object)null) || val.GetInventory() == null || !val.GetInventory().AddItem(item)) && (Object)(object)Player.m_localPlayer != (Object)null)
				{
					ItemDrop.DropItem(item, item.m_stack, ((Component)Player.m_localPlayer).transform.position + Vector3.up, Quaternion.identity);
				}
			}
			finally
			{
				SkipLock = false;
			}
		}

		internal static void Vote(int choice)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			if (!string.IsNullOrEmpty(CurrentRollId) && !Voted)
			{
				Voted = true;
				ZPackage val = new ZPackage();
				val.Write(CurrentRollId);
				val.Write(choice);
				RollServer.ToServer("CLR_Vote", val);
				RollWindow.MarkVoted();
			}
		}

		internal static void Escape()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			if (RollWindow.IsOpen && !string.IsNullOrEmpty(CurrentRollId))
			{
				if (IsStarter)
				{
					ZPackage val = new ZPackage();
					val.Write(CurrentRollId);
					RollServer.ToServer("CLR_Cancel", val);
				}
				else
				{
					Vote(1);
				}
			}
		}
	}
	internal static class RollServer
	{
		private class Roll
		{
			public string Id;

			public long Initiator;

			public int PartyId;

			public ZDOID Chest;

			public int X;

			public int Y;

			public Vector3 ChestPos;

			public byte[] ItemPayload;

			public string Display;

			public List<long> Eligible = new List<long>();

			public readonly Dictionary<long, int> Choice = new Dictionary<long, int>();

			public readonly Dictionary<long, int> Number = new Dictionary<long, int>();

			public float Deadline;

			public bool Open;
		}

		private const int Pass = 1;

		private const int Greed = 2;

		private const int Need = 3;

		private static Roll _active;

		internal static void OnRequest(long sender, ZPackage pkg)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00d1: 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_00ef: 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_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Expected O, but got Unknown
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer())
			{
				return;
			}
			if (!ModConfig.Enabled.Value)
			{
				Tell(sender, "Loot rolls are disabled.");
				return;
			}
			if (_active != null)
			{
				Tell(sender, "A loot roll is already running.");
				return;
			}
			ZDOID val = Net.ReadId(pkg);
			int num = pkg.ReadInt();
			int num2 = pkg.ReadInt();
			int pos = pkg.GetPos();
			ItemData val2 = ItemCodec.ReadItem(pkg);
			if (val2 == null)
			{
				Tell(sender, "Could not read that item.");
				return;
			}
			bool flag = ModConfig.SoloTestMode.Value && IsSoloServer();
			int partyIdForPeer = PartyUtil.GetPartyIdForPeer(sender);
			bool flag2 = PartyUtil.MustBeInParty();
			bool flag3 = partyIdForPeer == 0 && !flag2;
			if (!flag && partyIdForPeer == 0 && flag2)
			{
				Tell(sender, "Join a party before rolling on loot.");
				return;
			}
			Vector3 chestPos = PartyUtil.GetPos(sender);
			Container val3 = ChestUtil.Find(val);
			if ((Object)(object)val3 != (Object)null)
			{
				chestPos = ((Component)val3).transform.position;
			}
			if (!flag && !flag3 && ModConfig.OnlyPartyLeaderCanRoll.Value && !PartyUtil.IsPartyLeader(sender))
			{
				Tell(sender, "Only the party leader can start a loot roll.");
				return;
			}
			List<long> list = (flag ? new List<long> { sender } : PartyUtil.GetEligible(partyIdForPeer, chestPos, ModConfig.RequireRange.Value, ModConfig.Range.Value));
			int num3 = (flag ? 1 : ModConfig.MinPlayers.Value);
			if (list.Count < num3)
			{
				if (flag3)
				{
					Tell(sender, "Need " + num3 + " players within " + ModConfig.Range.Value.ToString("0") + "m of the chest (or join a SocialSystem party).");
				}
				else
				{
					Tell(sender, "Need " + num3 + " party members" + (ModConfig.RequireRange.Value ? " near the chest." : "."));
				}
				return;
			}
			if (!list.Contains(sender))
			{
				Tell(sender, (flag3 || ModConfig.RequireRange.Value) ? "You are too far from the chest." : "You are not in this party.");
				return;
			}
			byte[] array = SliceFrom(pkg, pos);
			_active = new Roll
			{
				Id = Guid.NewGuid().ToString("N"),
				Initiator = sender,
				PartyId = partyIdForPeer,
				Chest = val,
				X = num,
				Y = num2,
				ChestPos = chestPos,
				ItemPayload = array,
				Display = ItemCodec.DisplayName(val2),
				Eligible = list,
				Open = false
			};
			BroadcastLock(locked: true);
			ZPackage val4 = new ZPackage();
			val4.Write(2);
			val4.Write(_active.Id);
			Net.WriteId(val4, val);
			val4.Write(num);
			val4.Write(num2);
			val4.Write(array);
			PartyUtil.Send(sender, "CLR_Give", val4);
		}

		internal static void OnRemoved(long sender, ZPackage pkg)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			if (_active == null || sender != _active.Initiator)
			{
				return;
			}
			string text = pkg.ReadString();
			bool flag = pkg.ReadBool();
			if (!(text != _active.Id))
			{
				if (!flag)
				{
					BroadcastLock(locked: false);
					Tell(sender, "That item is no longer in the chest.");
					_active = null;
					return;
				}
				_active.Open = true;
				_active.Deadline = Time.time + ModConfig.TimeoutSeconds.Value;
				ZPackage val = new ZPackage();
				val.Write(_active.Id);
				val.Write(PartyUtil.GetName(sender));
				val.Write(_active.Initiator);
				val.Write(_active.Display);
				val.Write(ModConfig.TimeoutSeconds.Value);
				val.Write(_active.ItemPayload);
				PartyUtil.SendToMany(_active.Eligible, "CLR_Open", val);
				SayAll(_active.Initiator, PartyUtil.GetName(_active.Initiator) + " started a roll for " + _active.Display + ".");
			}
		}

		internal static void OnVote(long sender, ZPackage pkg)
		{
			if (_active == null || !_active.Open)
			{
				return;
			}
			string text = pkg.ReadString();
			int num = pkg.ReadInt();
			if (!(text != _active.Id) && _active.Eligible.Contains(sender) && (num == 1 || num == 2 || num == 3) && (_active.PartyId == 0 || PartyUtil.GetPartyIdForPeer(sender) == _active.PartyId) && !_active.Choice.ContainsKey(sender))
			{
				int value = ((num != 1) ? Random.Range(1, 101) : 0);
				_active.Choice[sender] = num;
				_active.Number[sender] = value;
				string name = PartyUtil.GetName(sender);
				string text2 = ((num == 1) ? (name + " Pass") : (name + " " + ChoiceName(num) + " " + value));
				SayAll(sender, text2);
				if (AllVoted())
				{
					Resolve();
				}
			}
		}

		internal static void OnCancel(long sender, ZPackage pkg)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_0049: 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_00a3: Expected O, but got Unknown
			if (_active != null && !(pkg.ReadString() != _active.Id) && sender == _active.Initiator)
			{
				Roll active = _active;
				_active = null;
				ZPackage val = new ZPackage();
				val.Write(1);
				Net.WriteId(val, active.Chest);
				val.Write(active.ItemPayload);
				PartyUtil.Send(active.Initiator, "CLR_Give", val);
				ChatTo(active.Initiator, 2, PartyUtil.GetName(active.Initiator) + " cancelled the roll on " + active.Display + ".", null);
				ZPackage val2 = new ZPackage();
				val2.Write(active.Id);
				PartyUtil.SendToMany(active.Eligible, "CLR_Close", val2);
				BroadcastLock(locked: false, active);
			}
		}

		internal static void Tick()
		{
			if (_active == null || !_active.Open || Time.time < _active.Deadline)
			{
				return;
			}
			foreach (long item in _active.Eligible)
			{
				if (!_active.Choice.ContainsKey(item))
				{
					_active.Choice[item] = 1;
					_active.Number[item] = 0;
					SayAll(item, PartyUtil.GetName(item) + " Pass");
				}
			}
			Resolve();
		}

		private static bool AllVoted()
		{
			foreach (long item in _active.Eligible)
			{
				if (!_active.Choice.ContainsKey(item))
				{
					return false;
				}
			}
			return true;
		}

		private static void Resolve()
		{
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Expected O, but got Unknown
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Expected O, but got Unknown
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Expected O, but got Unknown
			Roll active = _active;
			_active = null;
			int num = 0;
			foreach (KeyValuePair<long, int> item in active.Choice)
			{
				if (item.Value > num)
				{
					num = item.Value;
				}
			}
			long num2 = 0L;
			if (num >= 2)
			{
				List<long> list = new List<long>();
				int num3 = -1;
				foreach (long item2 in active.Eligible)
				{
					if (active.Choice.ContainsKey(item2) && active.Choice[item2] == num)
					{
						int num4 = active.Number[item2];
						if (num4 > num3)
						{
							num3 = num4;
							list.Clear();
							list.Add(item2);
						}
						else if (num4 == num3)
						{
							list.Add(item2);
						}
					}
				}
				while (list.Count > 1)
				{
					ChatTo(0L, 1, "Tie on " + num3 + " — rolling again.", active.Eligible);
					num3 = -1;
					List<long> list2 = new List<long>();
					foreach (long item3 in list)
					{
						int num5 = Random.Range(1, 101);
						active.Number[item3] = num5;
						ChatTo(item3, 1, PartyUtil.GetName(item3) + " " + num5, active.Eligible);
						if (num5 > num3)
						{
							num3 = num5;
							list2.Clear();
							list2.Add(item3);
						}
						else if (num5 == num3)
						{
							list2.Add(item3);
						}
					}
					list = list2;
				}
				if (list.Count == 1)
				{
					num2 = list[0];
				}
			}
			if (num2 != 0L)
			{
				ZPackage val = new ZPackage();
				val.Write(0);
				val.Write(active.ItemPayload);
				PartyUtil.Send(num2, "CLR_Give", val);
				ChatTo(num2, 2, PartyUtil.GetName(num2) + " wins " + active.Display + "!", null);
			}
			else
			{
				ZPackage val2 = new ZPackage();
				val2.Write(1);
				Net.WriteId(val2, active.Chest);
				val2.Write(active.ItemPayload);
				PartyUtil.Send(active.Initiator, "CLR_Give", val2);
				ChatTo(active.Initiator, 2, "Everyone passed on " + active.Display + ".", null);
			}
			ZPackage val3 = new ZPackage();
			val3.Write(active.Id);
			PartyUtil.SendToMany(active.Eligible, "CLR_Close", val3);
			BroadcastLock(locked: false, active);
		}

		private static void BroadcastLock(bool locked, Roll roll = null)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			Roll roll2 = roll ?? _active;
			if (roll2 != null)
			{
				ZPackage val = new ZPackage();
				val.Write(locked);
				Net.WriteId(val, roll2.Chest);
				val.Write(roll2.X);
				val.Write(roll2.Y);
				ZRoutedRpc.instance.InvokeRoutedRPC(0L, "CLR_Lock", new object[1] { val.GetBase64() });
			}
		}

		private static void SayAll(long asUid, string text)
		{
			ChatTo(asUid, 1, text, (_active != null) ? _active.Eligible : null);
		}

		private static void ChatTo(long asUid, int type, string text, List<long> to)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			ZPackage val = new ZPackage();
			val.Write(type);
			val.Write((asUid != 0L) ? PartyUtil.GetName(asUid) : "Loot");
			val.Write(text);
			if (to != null && to.Count > 0 && type == 1)
			{
				PartyUtil.SendToMany(to, "CLR_Chat", val);
				return;
			}
			ZRoutedRpc.instance.InvokeRoutedRPC(0L, "CLR_Chat", new object[1] { val.GetBase64() });
		}

		internal static void Tell(long uid, string text)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			ZPackage val = new ZPackage();
			val.Write(1);
			val.Write("Loot");
			val.Write(text);
			PartyUtil.Send(uid, "CLR_Chat", val);
		}

		private static string ChoiceName(int choice)
		{
			return choice switch
			{
				3 => "Need", 
				2 => "Greed", 
				_ => "Pass", 
			};
		}

		private static byte[] SliceFrom(ZPackage pkg, int start)
		{
			byte[] array = pkg.GetArray();
			int num = array.Length - start;
			if (num <= 0)
			{
				return Array.Empty<byte>();
			}
			byte[] array2 = new byte[num];
			Buffer.BlockCopy(array, start, array2, 0, num);
			return array2;
		}

		internal static void ToServer(string rpc, ZPackage pkg)
		{
			if ((Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer())
			{
				Net.Dispatch(ZNet.GetUID(), rpc, pkg.GetBase64());
				return;
			}
			ZNetPeer val = (((Object)(object)ZNet.instance != (Object)null) ? ZNet.instance.GetServerPeer() : null);
			if (val != null)
			{
				ZRoutedRpc.instance.InvokeRoutedRPC(val.m_uid, rpc, new object[1] { pkg.GetBase64() });
			}
		}

		internal static bool IsSoloServer()
		{
			if ((Object)(object)ZNet.instance == (Object)null)
			{
				return false;
			}
			int num = 0;
			foreach (ZNetPeer peer in ZNet.instance.GetPeers())
			{
				if (peer != null && peer.IsReady())
				{
					num++;
				}
			}
			return num == 0;
		}
	}
	internal static class RollWindow
	{
		private sealed class DragMove : MonoBehaviour, IPointerDownHandler, IEventSystemHandler, IDragHandler
		{
			public RectTransform Window;

			private bool _drag;

			public void OnPointerDown(PointerEventData eventData)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: 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_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)
				if ((Object)(object)Window == (Object)null || (int)eventData.button != 0)
				{
					_drag = false;
					return;
				}
				Canvas componentInParent = ((Component)Window).GetComponentInParent<Canvas>();
				Camera val = (((Object)(object)componentInParent != (Object)null && (int)componentInParent.renderMode != 0) ? componentInParent.worldCamera : null);
				Vector2 val2 = default(Vector2);
				if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(Window, eventData.position, val, ref val2))
				{
					_drag = false;
					return;
				}
				float y = val2.y;
				Rect rect = Window.rect;
				_drag = y > ((Rect)(ref rect)).yMax - 29f;
			}

			public void OnDrag(PointerEventData eventData)
			{
				//IL_0017: 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_002c: 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)
				if (_drag && !((Object)(object)Window == (Object)null) && (int)eventData.button == 0)
				{
					RectTransform window = Window;
					window.anchoredPosition += eventData.delta;
				}
			}
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__29_0;

			public static UnityAction <>9__29_1;

			public static UnityAction <>9__29_2;

			internal void <Ensure>b__29_0()
			{
				RollClient.Vote(3);
			}

			internal void <Ensure>b__29_1()
			{
				RollClient.Vote(2);
			}

			internal void <Ensure>b__29_2()
			{
				RollClient.Vote(1);
			}
		}

		private const float DragBarH = 29f;

		private const float TitleBand = 29f;

		private const float Width = 460f;

		private const float MinHeight = 400f;

		private const float MaxHeight = 860f;

		private static GameObject _root;

		private static RectTransform _frameRt;

		private static RectTransform _panelRt;

		private static Image _dragBar;

		private static Text _title;

		private static Text _rarity;

		private static Text _itemName;

		private static Text _set;

		private static Text _body;

		private static Text _timer;

		private static Image _icon;

		private static Image _rarityBar;

		private static Button _need;

		private static Button _greed;

		private static Button _pass;

		private static float _deadline;

		private static bool _voted;

		internal static bool IsOpen
		{
			get
			{
				if ((Object)(object)_root != (Object)null)
				{
					return _root.activeSelf;
				}
				return false;
			}
		}

		internal static void Show(string rollId, string starter, string display, ItemData item, float timeout)
		{
			Ensure();
			_voted = false;
			_deadline = Time.time + timeout;
			_title.text = starter + " started a roll";
			if ((Object)(object)_itemName != (Object)null)
			{
				_itemName.text = ((item != null) ? ItemCodec.BaseName(item) : display);
			}
			ApplyRarity(item);
			string text = ((item != null) ? ItemCodec.Tooltip(item) : display);
			if (text.Length > 2500)
			{
				text = text.Substring(0, 2500) + "...";
			}
			_body.text = text;
			Sprite val = null;
			try
			{
				if (item != null)
				{
					val = item.GetIcon();
				}
			}
			catch
			{
				val = null;
			}
			_icon.sprite = val;
			((Behaviour)_icon).enabled = (Object)(object)val != (Object)null;
			SetButtons(on: true);
			Relayout();
			_root.SetActive(true);
		}

		internal static void Hide()
		{
			if ((Object)(object)_root != (Object)null)
			{
				_root.SetActive(false);
			}
			_voted = false;
		}

		internal static void MarkVoted()
		{
			_voted = true;
			SetButtons(on: false);
		}

		internal static void Tick()
		{
			if (IsOpen && !((Object)(object)_timer == (Object)null))
			{
				float num = Mathf.Max(0f, _deadline - Time.time);
				_timer.text = (_voted ? "Waiting for others..." : (num.ToString("0") + "s"));
			}
		}

		private static void SetButtons(bool on)
		{
			if ((Object)(object)_need != (Object)null)
			{
				((Selectable)_need).interactable = on;
			}
			if ((Object)(object)_greed != (Object)null)
			{
				((Selectable)_greed).interactable = on;
			}
			if ((Object)(object)_pass != (Object)null)
			{
				((Selectable)_pass).interactable = on;
			}
		}

		private static void Ensure()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: 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_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: 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_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Expected O, but got Unknown
			//IL_0384: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Expected O, but got Unknown
			//IL_03db: Expected O, but got Unknown
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cc: Expected O, but got Unknown
			if ((Object)(object)_root != (Object)null)
			{
				return;
			}
			Font builtinResource = Resources.GetBuiltinResource<Font>("Arial.ttf");
			GameObject val = new GameObject("CLR_Canvas");
			Object.DontDestroyOnLoad((Object)(object)val);
			Canvas obj = val.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)0;
			obj.sortingOrder = 1000;
			val.AddComponent<CanvasScaler>().uiScaleMode = (ScaleMode)0;
			val.AddComponent<GraphicRaycaster>();
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(460f, 400f);
			GameObject val3 = new GameObject("CLR_Frame");
			val3.transform.SetParent(val.transform, false);
			_frameRt = val3.AddComponent<RectTransform>();
			_frameRt.sizeDelta = val2 + Vector2.one;
			_frameRt.anchoredPosition = Vector2.zero;
			Image obj2 = val3.AddComponent<Image>();
			((Graphic)obj2).color = Color.black;
			((Graphic)obj2).raycastTarget = true;
			GameObject obj3 = Panel(val3.transform, val2);
			obj3.AddComponent<DragMove>().Window = _frameRt;
			_panelRt = obj3.GetComponent<RectTransform>();
			_root = obj3;
			_root.SetActive(true);
			_dragBar = Bar(_root.transform, Vector2.zero, new Vector2(460f, 29f));
			((Graphic)_dragBar).color = Color.black;
			((Graphic)_dragBar).raycastTarget = true;
			_title = Label(_root.transform, Vector2.zero, new Vector2(420f, 26f), builtinResource, 18, (TextAnchor)4);
			_rarityBar = Bar(_root.transform, Vector2.zero, new Vector2(440f, 6f));
			_rarity = Label(_root.transform, Vector2.zero, new Vector2(420f, 32f), builtinResource, 26, (TextAnchor)4);
			_itemName = Label(_root.transform, Vector2.zero, new Vector2(420f, 28f), builtinResource, 20, (TextAnchor)4);
			_set = Label(_root.transform, Vector2.zero, new Vector2(420f, 24f), builtinResource, 18, (TextAnchor)4);
			_icon = Icon(_root.transform, Vector2.zero, 84f);
			_timer = Label(_root.transform, Vector2.zero, new Vector2(420f, 28f), builtinResource, 22, (TextAnchor)4);
			_body = Label(_root.transform, Vector2.zero, new Vector2(420f, 160f), builtinResource, 16, (TextAnchor)0);
			_body.horizontalOverflow = (HorizontalWrapMode)0;
			_body.verticalOverflow = (VerticalWrapMode)0;
			Transform transform = _root.transform;
			Vector2 pos = new Vector2(-145f, 0f);
			Sprite mark = VoteIcons.Need();
			Color color = new Color(0.22f, 0.45f, 0.22f, 1f);
			object obj4 = <>c.<>9__29_0;
			if (obj4 == null)
			{
				UnityAction val4 = delegate
				{
					RollClient.Vote(3);
				};
				<>c.<>9__29_0 = val4;
				obj4 = (object)val4;
			}
			_need = MakeButton(transform, pos, "Need", builtinResource, mark, color, (UnityAction)obj4);
			Transform transform2 = _root.transform;
			Vector2 pos2 = new Vector2(0f, 0f);
			Sprite mark2 = VoteIcons.Greed();
			Color color2 = new Color(0.5f, 0.38f, 0.1f, 1f);
			object obj5 = <>c.<>9__29_1;
			if (obj5 == null)
			{
				UnityAction val5 = delegate
				{
					RollClient.Vote(2);
				};
				<>c.<>9__29_1 = val5;
				obj5 = (object)val5;
			}
			_greed = MakeButton(transform2, pos2, "Greed", builtinResource, mark2, color2, (UnityAction)obj5);
			Transform transform3 = _root.transform;
			Vector2 pos3 = new Vector2(145f, 0f);
			Sprite mark3 = VoteIcons.Pass();
			Color color3 = new Color(0.28f, 0.28f, 0.3f, 1f);
			object obj6 = <>c.<>9__29_2;
			if (obj6 == null)
			{
				UnityAction val6 = delegate
				{
					RollClient.Vote(1);
				};
				<>c.<>9__29_2 = val6;
				obj6 = (object)val6;
			}
			_pass = MakeButton(transform3, pos3, "Pass", builtinResource, mark3, color3, (UnityAction)obj6);
			_root = val3;
			_root.SetActive(false);
		}

		private static GameObject Panel(Transform parent, Vector2 size)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			GameObject val = new GameObject("CLR_Panel");
			val.transform.SetParent(parent, false);
			RectTransform obj = val.AddComponent<RectTransform>();
			obj.sizeDelta = size;
			obj.anchoredPosition = Vector2.zero;
			Image obj2 = val.AddComponent<Image>();
			((Graphic)obj2).color = new Color(0.05f, 0.05f, 0.07f, 0.94f);
			((Graphic)obj2).raycastTarget = true;
			return val;
		}

		private static Image Bar(Transform parent, Vector2 pos, Vector2 size)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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)
			GameObject val = new GameObject("CLR_RarityBar");
			val.transform.SetParent(parent, false);
			RectTransform obj = val.AddComponent<RectTransform>();
			obj.sizeDelta = size;
			obj.anchoredPosition = pos;
			Image obj2 = val.AddComponent<Image>();
			((Graphic)obj2).color = Color.white;
			((Graphic)obj2).raycastTarget = false;
			return obj2;
		}

		private static void ApplyRarity(ItemData item)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			EpicLootInfo.Info info;
			bool flag = EpicLootInfo.TryRead(item, out info) && info.Magic;
			bool flag2 = flag && !string.IsNullOrEmpty(info.SetName);
			Color white = Color.white;
			if (flag)
			{
				ColorUtility.TryParseHtmlString(info.RarityColor, ref white);
			}
			if ((Object)(object)_rarityBar != (Object)null)
			{
				((Component)_rarityBar).gameObject.SetActive(flag);
				if (flag)
				{
					((Graphic)_rarityBar).color = white;
				}
			}
			if ((Object)(object)_rarity != (Object)null)
			{
				((Component)_rarity).gameObject.SetActive(flag);
				if (flag)
				{
					((Graphic)_rarity).color = white;
					_rarity.text = TitleCase(info.RarityName);
				}
			}
			if ((Object)(object)_itemName != (Object)null)
			{
				((Graphic)_itemName).color = (flag ? white : Color.white);
			}
			if ((Object)(object)_set != (Object)null)
			{
				((Component)_set).gameObject.SetActive(flag2);
				if (flag2)
				{
					((Graphic)_set).color = white;
					_set.text = "Set: " + info.SetName;
				}
			}
		}

		private static void Relayout()
		{
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_panelRt == (Object)null) && !((Object)(object)_frameRt == (Object)null))
			{
				bool num = (Object)(object)_rarity != (Object)null && ((Component)_rarity).gameObject.activeSelf;
				bool flag = (Object)(object)_set != (Object)null && ((Component)_set).gameObject.activeSelf;
				float num2 = 12f;
				if (num)
				{
					num2 += 50f;
				}
				num2 += 28f;
				if (flag)
				{
					num2 += 22f;
				}
				num2 += 100f;
				num2 += 50f;
				float num3 = MeasureBody();
				num2 += num3 + 16f + 44f + 16f;
				float num4 = Mathf.Clamp(29f + num2, 400f, 860f);
				_panelRt.sizeDelta = new Vector2(460f, num4);
				_frameRt.sizeDelta = new Vector2(461f, num4 + 1f);
				float num5 = num4 * 0.5f;
				Place((Component)(object)_dragBar, num5 - 14.5f);
				Place((Component)(object)_title, num5 - 14.5f);
				num5 -= 41f;
				if (num)
				{
					Place((Component)(object)_rarityBar, num5 - 3f);
					num5 -= 14f;
					Place((Component)(object)_rarity, num5 - 16f);
					num5 -= 36f;
				}
				Place((Component)(object)_itemName, num5 - 14f);
				num5 -= 28f;
				if (flag)
				{
					Place((Component)(object)_set, num5 - 12f);
					num5 -= 22f;
				}
				num5 -= 8f;
				Place((Component)(object)_icon, num5 - 42f);
				num5 -= 92f;
				Place((Component)(object)_timer, num5 - 14f);
				num5 -= 50f;
				Size((Component)(object)_body, 420f, num3);
				Place((Component)(object)_body, num5 - num3 * 0.5f);
				num5 -= num3 + 16f;
				float y = (0f - num4) * 0.5f + 36f;
				Place((Component)(object)_need, y);
				Place((Component)(object)_greed, y);
				Place((Component)(object)_pass, y);
			}
		}

		private static float MeasureBody()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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_0055: 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)
			float num = 120f;
			float num2 = 360f;
			if ((Object)(object)_body == (Object)null || string.IsNullOrEmpty(_body.text))
			{
				return 140f;
			}
			TextGenerationSettings generationSettings = _body.GetGenerationSettings(new Vector2(420f, 0f));
			generationSettings.horizontalOverflow = (HorizontalWrapMode)0;
			generationSettings.verticalOverflow = (VerticalWrapMode)1;
			return Mathf.Clamp(_body.cachedTextGeneratorForLayout.GetPreferredHeight(_body.text, generationSettings) / Mathf.Max(1f, _body.pixelsPerUnit) + 8f, num, num2);
		}

		private static void Place(Component target, float y)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)target == (Object)null))
			{
				RectTransform component = target.GetComponent<RectTransform>();
				if ((Object)(object)component != (Object)null)
				{
					component.anchoredPosition = new Vector2(component.anchoredPosition.x, y);
				}
			}
		}

		private static void Size(Component target, float w, float h)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)target == (Object)null))
			{
				RectTransform component = target.GetComponent<RectTransform>();
				if ((Object)(object)component != (Object)null)
				{
					component.sizeDelta = new Vector2(w, h);
				}
			}
		}

		private static string TitleCase(string text)
		{
			if (string.IsNullOrEmpty(text))
			{
				return text;
			}
			text = text.Trim();
			if (text.Length == 1)
			{
				return text.ToUpperInvariant();
			}
			return char.ToUpperInvariant(text[0]) + text.Substring(1).ToLowerInvariant();
		}

		private static Text Label(Transform parent, Vector2 pos, Vector2 size, Font font, int fontSize, TextAnchor align)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("CLR_Text");
			val.transform.SetParent(parent, false);
			RectTransform obj = val.AddComponent<RectTransform>();
			obj.sizeDelta = size;
			obj.anchoredPosition = pos;
			Text obj2 = val.AddComponent<Text>();
			obj2.font = font;
			obj2.fontSize = fontSize;
			((Graphic)obj2).color = Color.white;
			obj2.alignment = align;
			obj2.supportRichText = true;
			((Graphic)obj2).raycastTarget = false;
			return obj2;
		}

		private static Image Icon(Transform parent, Vector2 pos, float size)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("CLR_Icon");
			val.transform.SetParent(parent, false);
			RectTransform obj = val.AddComponent<RectTransform>();
			obj.sizeDelta = new Vector2(size, size);
			obj.anchoredPosition = pos;
			Image obj2 = val.AddComponent<Image>();
			((Graphic)obj2).color = Color.white;
			((Graphic)obj2).raycastTarget = false;
			return obj2;
		}

		private static Button MakeButton(Transform parent, Vector2 pos, string label, Font font, Sprite mark, Color color, UnityAction click)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("CLR_Btn");
			val.transform.SetParent(parent, false);
			RectTransform obj = val.AddComponent<RectTransform>();
			obj.sizeDelta = new Vector2(132f, 44f);
			obj.anchoredPosition = pos;
			Image val2 = val.AddComponent<Image>();
			((Graphic)val2).color = color;
			Button obj2 = val.AddComponent<Button>();
			((Selectable)obj2).targetGraphic = (Graphic)(object)val2;
			((UnityEvent)obj2.onClick).AddListener(click);
			GameObject val3 = new GameObject("icon");
			val3.transform.SetParent(val.transform, false);
			RectTransform obj3 = val3.AddComponent<RectTransform>();
			obj3.anchorMin = new Vector2(0f, 0.5f);
			obj3.anchorMax = new Vector2(0f, 0.5f);
			obj3.pivot = new Vector2(0f, 0.5f);
			obj3.anchoredPosition = new Vector2(8f, 0f);
			obj3.sizeDelta = new Vector2(26f, 26f);
			Image obj4 = val3.AddComponent<Image>();
			obj4.sprite = mark;
			obj4.preserveAspect = true;
			((Graphic)obj4).raycastTarget = false;
			Label(val.transform, new Vector2(12f, 0f), new Vector2(100f, 44f), font, 18, (TextAnchor)4).text = label;
			return obj2;
		}
	}
	internal static class VoteIcons
	{
		private static Sprite _need;

		private static Sprite _greed;

		private static Sprite _pass;

		internal static Sprite Need()
		{
			if (!((Object)(object)_need != (Object)null))
			{
				return _need = Make(DrawNeed);
			}
			return _need;
		}

		internal static Sprite Greed()
		{
			if (!((Object)(object)_greed != (Object)null))
			{
				return _greed = Make(DrawGreed);
			}
			return _greed;
		}

		internal static Sprite Pass()
		{
			if (!((Object)(object)_pass != (Object)null))
			{
				return _pass = Make(DrawPass);
			}
			return _pass;
		}

		private static Sprite Make(Action<Texture2D> draw)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(32, 32, (TextureFormat)5, false);
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0f, 0f, 0f, 0f);
			for (int i = 0; i < 32; i++)
			{
				for (int j = 0; j < 32; j++)
				{
					val.SetPi