Decompiled source of Pintervention v1.2.0

Pintervention.dll

Decompiled 7 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Pintervention.Core;
using Pintervention.Extensions;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Pintervention")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Pintervention")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("334130a7-42b2-4177-a221-cedf40d6899d")]
[assembly: AssemblyFileVersion("1.2.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.0.0")]
[module: UnverifiableCode]
namespace Pintervention
{
	public class PluginConfig
	{
		public static ConfigEntry<bool> IsModEnabled { get; private set; }

		public static ConfigEntry<bool> ReadPinsOnInteract { get; private set; }

		public static ConfigEntry<bool> ReadRevealedMapOnInteract { get; private set; }

		public static ConfigEntry<bool> WritePinsOnInteract { get; private set; }

		public static ConfigEntry<bool> WriteRevealedMapOnInteract { get; private set; }

		public static ConfigEntry<KeyboardShortcut> DisplayFilterPanel { get; private set; }

		public static ConfigEntry<Vector2> PlayerPinFilterSizeDelta { get; private set; }

		public static ConfigEntry<Vector2> PlayerPinFilterPosition { get; private set; }

		public static void BindConfig(ConfigFile config)
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			IsModEnabled = config.Bind<bool>("_Global", "isModEnabled", true, "Globally enable or disable this mod.");
			ReadPinsOnInteract = config.Bind<bool>("CartographyTable", "readPinsOnInteract", true, "Allows not taking pins when reading from cartography table.");
			ReadRevealedMapOnInteract = config.Bind<bool>("CartographyTable", "readRevealedMapOnInteract", true, "Allows not taking shared map data when reading from cartography table.");
			WritePinsOnInteract = config.Bind<bool>("CartographyTable", "writePinsOnInteract", true, "Allows not writing pins when writing to cartography table.");
			WriteRevealedMapOnInteract = config.Bind<bool>("CartographyTable", "writeRevealedMapOnInteract", true, "Allows not writing shared map data when writing to cartography table.");
			DisplayFilterPanel = config.Bind<KeyboardShortcut>("Hotkeys", "displayFilterPanelShortcut", new KeyboardShortcut((KeyCode)102, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), "Keyboard shortcut for the displaying filter panel with minimap open.");
			PlayerPinFilterSizeDelta = config.Bind<Vector2>("PlayerPinFilter.Panel", "playerListPanelSizeDelta", new Vector2(400f, 400f), "The value for the PlayerPinFilter.Panel sizeDelta (width/height in pixels).");
			PlayerPinFilterPosition = config.Bind<Vector2>("PlayerPinFilter.Panel", "pinFilterPanelPanelPosition", new Vector2(-25f, 0f), "The value for the PlayerPinFilter.Panel position (relative to pivot/anchors).");
		}
	}
	public static class FileUtils
	{
		public static string GetPath()
		{
			return Path.Combine(Utils.GetSaveDataPath((FileSource)1), "characters", "pinNames");
		}

		public static string GetFilename()
		{
			return Path.Combine(GetPath(), StringExtensionMethods.GetStableHashCode($"{ZNet.instance.GetWorldUID()}") + ".csv");
		}

		public static string GetFilteredFilename()
		{
			return Path.Combine(GetPath(), StringExtensionMethods.GetStableHashCode($"{ZNet.instance.GetWorldUID()}") + "_filtered.csv");
		}

		public static int HashPid(long pid)
		{
			return StringExtensionMethods.GetStableHashCode($"{pid}");
		}
	}
	public class NameManager
	{
		private static readonly string _mapPinsName = "World & Player Pins";

		private static int _unknownPlayerCount = 0;

		public static Dictionary<long, string> PlayerNamesById { get; private set; } = new Dictionary<long, string>();


		public static void LoadPlayerNames()
		{
			ReadNamesFromFile();
		}

		private static void AddLocalPlayerName()
		{
			if (Object.op_Implicit((Object)(object)Player.m_localPlayer) && !PlayerNamesById.ContainsKey(Player.m_localPlayer.GetPlayerID()))
			{
				PlayerNamesById.Add(Player.m_localPlayer.GetPlayerID(), Player.m_localPlayer.GetPlayerName());
			}
		}

		public static string GetPlayerNameById(long pid)
		{
			if (pid == 0)
			{
				return _mapPinsName;
			}
			if (pid == Player.m_localPlayer.GetPlayerID())
			{
				return Player.m_localPlayer.GetPlayerName();
			}
			if (PlayerNamesById.ContainsKey(pid))
			{
				return PlayerNamesById[pid];
			}
			return AssignNextUnknownPlayer(pid);
		}

		private static string AssignNextUnknownPlayer(long pid)
		{
			_unknownPlayerCount++;
			string text = $"Unknown Player {_unknownPlayerCount}";
			if (!PlayerNamesById.ContainsKey(pid))
			{
				PlayerNamesById.Add(pid, text);
			}
			return text;
		}

		public static void AddPlayerName(long pid, string name)
		{
			if (!PlayerNamesById.ContainsKey(pid) || PlayerNamesById[pid].Contains("Unknown"))
			{
				if (PlayerNamesById.ContainsKey(pid))
				{
					PlayerNamesById[pid] = name;
				}
				else
				{
					PlayerNamesById.Add(pid, name);
				}
			}
		}

		public static string PidNameMapToRow(int hashedPid, string name)
		{
			return string.Join(",", hashedPid.ToString(), name);
		}

		public static void WriteNamesToFile()
		{
			if (!Object.op_Implicit((Object)(object)ZNet.instance))
			{
				return;
			}
			Dictionary<long, string> namesToWrite = GetNamesToWrite();
			if (namesToWrite.Count == 0)
			{
				return;
			}
			if (!Directory.Exists(FileUtils.GetPath()))
			{
				Directory.CreateDirectory(FileUtils.GetPath());
			}
			using StreamWriter streamWriter = File.CreateText(FileUtils.GetFilename());
			streamWriter.AutoFlush = true;
			foreach (KeyValuePair<long, string> item in namesToWrite)
			{
				if (item.Key != Player.m_localPlayer.GetPlayerID() && !item.Value.StartsWith("Unknown"))
				{
					streamWriter.WriteLine(PidNameMapToRow(FileUtils.HashPid(item.Key), item.Value));
				}
			}
		}

		public static Dictionary<long, string> GetNamesToWrite()
		{
			Dictionary<long, string> dictionary = new Dictionary<long, string>();
			foreach (KeyValuePair<long, string> item in PlayerNamesById)
			{
				if (item.Key != Player.m_localPlayer.GetPlayerID() && !item.Value.StartsWith("Unknown"))
				{
					dictionary.Add(item.Key, item.Value);
				}
			}
			return dictionary;
		}

		public static void ReadNamesFromFile()
		{
			if (!Object.op_Implicit((Object)(object)ZNet.instance) || ZNet.instance.GetWorldUID().Equals(0L))
			{
				Pintervention.LogWarning("Could not read saved player names from file as ZNet instance is null.");
				return;
			}
			if (!File.Exists(FileUtils.GetFilename()))
			{
				Pintervention.Log("No saved names to load from " + FileUtils.GetFilename() + ".");
				return;
			}
			Pintervention.Log("Loading saved player names from " + FileUtils.GetFilename());
			Dictionary<int, string> dictionary = new Dictionary<int, string>();
			using (StreamReader streamReader = new StreamReader(FileUtils.GetFilename()))
			{
				while (!streamReader.EndOfStream)
				{
					string text = streamReader.ReadLine();
					string[] array = text.Split(new char[1] { ',' });
					int key = int.Parse(array[0]);
					string value = array[1];
					dictionary.Add(key, value);
				}
			}
			foreach (long foreignPinOwner in PinOwnerManager.ForeignPinOwners)
			{
				if (dictionary.ContainsKey(FileUtils.HashPid(foreignPinOwner)) && !PlayerNamesById.ContainsKey(foreignPinOwner))
				{
					PlayerNamesById.Add(foreignPinOwner, dictionary[FileUtils.HashPid(foreignPinOwner)]);
				}
			}
		}
	}
	public class PlayerFilterPanelManager
	{
		private static PlayerPinFilterPanel _filterPanel;

		public static void ToggleFilterPanel()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_009a: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)_filterPanel?.Panel))
			{
				_filterPanel = new PlayerPinFilterPanel(Minimap.m_instance.m_largeRoot.transform);
				_filterPanel.Panel.RectTransform().SetAnchorMin(new Vector2(0f, 0.5f)).SetAnchorMax(new Vector2(0f, 0.5f))
					.SetPivot(new Vector2(0f, 0.5f))
					.SetPosition(PluginConfig.PlayerPinFilterPosition.Value)
					.SetSizeDelta(PluginConfig.PlayerPinFilterSizeDelta.Value);
				PluginConfig.PlayerPinFilterPosition.OnSettingChanged(delegate(Vector2 position)
				{
					//IL_0020: Unknown result type (might be due to invalid IL or missing references)
					_filterPanel?.Panel.Ref<GameObject>()?.RectTransform().SetPosition(position);
				});
				PluginConfig.PlayerPinFilterSizeDelta.OnSettingChanged(delegate(Vector2 sizeDelta)
				{
					//IL_002b: Unknown result type (might be due to invalid IL or missing references)
					if (Object.op_Implicit((Object)(object)_filterPanel?.Panel))
					{
						_filterPanel.Panel.RectTransform().SetSizeDelta(sizeDelta);
					}
				});
				_filterPanel.PanelDragger.OnPanelEndDrag += delegate(object _, Vector3 position)
				{
					//IL_0005: Unknown result type (might be due to invalid IL or missing references)
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					PluginConfig.PlayerPinFilterPosition.Value = Vector2.op_Implicit(position);
				};
				_filterPanel.PanelResizer.OnPanelEndResize += delegate(object _, Vector2 sizeDelta)
				{
					//IL_0005: Unknown result type (might be due to invalid IL or missing references)
					PluginConfig.PlayerPinFilterSizeDelta.Value = sizeDelta;
				};
				_filterPanel.Panel.SetActive(false);
			}
			bool flag = !_filterPanel.Panel.activeSelf;
			_filterPanel.Panel.SetActive(!_filterPanel.Panel.activeSelf);
			if (flag)
			{
				_filterPanel.UpdatePanel();
			}
		}

		public static void UpdatePanel()
		{
			if (Object.op_Implicit((Object)(object)_filterPanel?.Panel))
			{
				_filterPanel.UpdatePanel();
			}
		}

		public static void UpdatePinCounts()
		{
			if (Object.op_Implicit((Object)(object)_filterPanel?.Panel))
			{
				_filterPanel.UpdatePinCounts();
			}
		}
	}
	public class PinOwnerManager
	{
		private static HashSet<PinData> _localPlayerPins = new HashSet<PinData>();

		public static List<long> ForeignPinOwners { get; private set; } = new List<long>();


		public static List<long> FilteredPinOwners { get; private set; } = new List<long>();


		public static bool Initialize()
		{
			if (!Object.op_Implicit((Object)(object)Minimap.instance) || !Object.op_Implicit((Object)(object)Player.m_localPlayer) || IsInitialized())
			{
				return false;
			}
			UpdatePinOwners();
			NameManager.LoadPlayerNames();
			LoadFilteredPinOwners();
			return true;
		}

		public static void UpdatePinOwners()
		{
			FindPinOwners();
			AddAllLocalPlayerPins();
		}

		public static void AddAllLocalPlayerPins()
		{
			if (!Object.op_Implicit((Object)(object)Minimap.instance) || !Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				return;
			}
			foreach (PinData pin in Minimap.instance.m_pins)
			{
				if (pin.m_ownerID == 0L && !IsWorldPin(pin))
				{
					AddLocalPlayerPin(pin);
				}
			}
		}

		public static void FindPinOwners()
		{
			if (Object.op_Implicit((Object)(object)Minimap.instance))
			{
				ForeignPinOwners = Minimap.instance.m_pins.Select((PinData x) => x.m_ownerID).Distinct().ToList();
				ForeignPinOwners.Add(Player.m_localPlayer.GetPlayerID());
				ForeignPinOwners.Sort();
			}
		}

		public static bool IsWorldPin(PinData pin)
		{
			if (!Object.op_Implicit((Object)(object)Minimap.instance))
			{
				return true;
			}
			if (Minimap.instance.m_locationPins.Values.Contains(pin) || Minimap.instance.m_playerPins.Contains(pin) || Minimap.instance.m_shoutPins.Contains(pin) || Minimap.instance.m_randEventPin == pin)
			{
				return true;
			}
			return false;
		}

		public static void Clear()
		{
			if (ForeignPinOwners.Any())
			{
				ForeignPinOwners.Clear();
				ForeignPinOwners = new List<long>();
			}
			if (FilteredPinOwners.Any())
			{
				FilteredPinOwners.Clear();
				FilteredPinOwners = new List<long>();
			}
		}

		public static long GetForeignPinOwnerAtIndex(int index)
		{
			return ForeignPinOwners[index];
		}

		public static Dictionary<long, ZDO> GetZDOsByPlayerId(List<long> playerIds)
		{
			//IL_003b: 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_004f: 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)
			Dictionary<ZDOID, ZDO> objectsByID = ZDOMan.s_instance.m_objectsByID;
			HashSet<long> hashSet = new HashSet<long>(playerIds);
			Dictionary<long, ZDO> dictionary = new Dictionary<long, ZDO>();
			long num = default(long);
			foreach (ZNetPeer peer in ZNet.m_instance.m_peers)
			{
				if (!(peer.m_characterID == ZDOID.None) && objectsByID.TryGetValue(peer.m_characterID, out var value) && ZDOExtraData.GetLong(value.m_uid, ZDOVars.s_playerID, ref num) && hashSet.Contains(num))
				{
					dictionary.Add(num, value);
					hashSet.Remove(num);
					if (hashSet.Count <= 0)
					{
						break;
					}
				}
			}
			return dictionary;
		}

		public static void RemoveForeignPinOwner(long pid)
		{
			if (ForeignPinOwners.Contains(pid))
			{
				ForeignPinOwners.Remove(pid);
			}
		}

		public static void FilterPins()
		{
			if (!IsInitialized())
			{
				Initialize();
			}
			if (!FilteredPinOwners.Any())
			{
				return;
			}
			foreach (long filteredPinOwner in FilteredPinOwners)
			{
				List<PinData> pinsByPid = GetPinsByPid(filteredPinOwner);
				foreach (PinData item in pinsByPid)
				{
					Minimap.instance.DestroyPinMarker(item);
				}
			}
		}

		public static void SortPinOwnersByName()
		{
			ForeignPinOwners = ForeignPinOwners.OrderBy((long x) => NameManager.GetPlayerNameById(x)).ToList();
		}

		public static List<PinData> GetPinsByPid(long pid)
		{
			if (pid == 0)
			{
				AddAllLocalPlayerPins();
				return Minimap.instance.m_pins.Where((PinData x) => x.m_ownerID == pid && !_localPlayerPins.Contains(x)).ToList();
			}
			if (pid == Player.m_localPlayer.GetPlayerID())
			{
				return _localPlayerPins.ToList();
			}
			return Minimap.instance.m_pins.Where((PinData x) => x.m_ownerID == pid).ToList();
		}

		public static bool IsFiltered(long pid)
		{
			if (!FilteredPinOwners.Contains(pid))
			{
				return false;
			}
			return true;
		}

		public static void ToggleFilter(long pid)
		{
			if (FilteredPinOwners.Contains(pid))
			{
				FilteredPinOwners.Remove(pid);
			}
			else
			{
				FilteredPinOwners.Add(pid);
			}
		}

		public static bool IsInitialized()
		{
			if (!ForeignPinOwners.Any())
			{
				return false;
			}
			return true;
		}

		public static void AddLocalPlayerPin(PinData pin)
		{
			if (!_localPlayerPins.Contains(pin))
			{
				_localPlayerPins.Add(pin);
			}
		}

		public static void RemoveLocalPlayerPin(PinData pin)
		{
			_localPlayerPins.Remove(pin);
		}

		public static string PidToRow(int hashedPid)
		{
			return string.Join(",", hashedPid.ToString());
		}

		public static void WriteFilteredPlayersToFile()
		{
			if (!FilteredPinOwners.Any())
			{
				return;
			}
			if (!Directory.Exists(FileUtils.GetPath()))
			{
				Directory.CreateDirectory(FileUtils.GetPath());
			}
			using StreamWriter streamWriter = File.CreateText(FileUtils.GetFilteredFilename());
			streamWriter.AutoFlush = true;
			foreach (long filteredPinOwner in FilteredPinOwners)
			{
				streamWriter.WriteLine(PidToRow(FileUtils.HashPid(filteredPinOwner)));
			}
		}

		public static void LoadFilteredPinOwners()
		{
			ReadFilteredPinOwnersFromFile();
		}

		public static void ReadFilteredPinOwnersFromFile()
		{
			if (!Object.op_Implicit((Object)(object)ZNet.instance) || ZNet.instance.GetWorldUID().Equals(0L))
			{
				Pintervention.LogWarning("Could not read saved filtered pin owners from file as ZNet instance is null.");
				return;
			}
			if (!File.Exists(FileUtils.GetFilteredFilename()))
			{
				Pintervention.Log("No saved filtered pin owners to load from " + FileUtils.GetFilteredFilename() + ".");
				return;
			}
			Pintervention.Log("Loading saved filter state from " + FileUtils.GetFilteredFilename());
			List<long> list = new List<long>();
			using (StreamReader streamReader = new StreamReader(FileUtils.GetFilteredFilename()))
			{
				while (!streamReader.EndOfStream)
				{
					string text = streamReader.ReadLine();
					string[] array = text.Split(new char[1] { ',' });
					int num = int.Parse(array[0]);
					list.Add(num);
				}
			}
			foreach (long foreignPinOwner in ForeignPinOwners)
			{
				if (list.Contains(FileUtils.HashPid(foreignPinOwner)) && !FilteredPinOwners.Contains(foreignPinOwner))
				{
					FilteredPinOwners.Add(foreignPinOwner);
				}
			}
		}
	}
	public static class ConfigEntryExtensions
	{
		public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action settingChangedHandler)
		{
			configEntry.SettingChanged += delegate
			{
				settingChangedHandler();
			};
		}

		public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<T> settingChangedHandler)
		{
			configEntry.SettingChanged += delegate
			{
				settingChangedHandler(configEntry.Value);
			};
		}
	}
	public static class ListExtensions
	{
		public static List<T> Add<T>(this List<T> list, params T[] items)
		{
			list.AddRange(items);
			return list;
		}
	}
	public static class ObjectExtensions
	{
		public static T Ref<T>(this T o) where T : Object
		{
			return Object.op_Implicit((Object)(object)o) ? o : default(T);
		}
	}
	[HarmonyPatch(typeof(Minimap))]
	internal static class MinimapPatch
	{
		private static int _pinCount = 999999;

		[HarmonyPostfix]
		[HarmonyPatch("Update")]
		private static void UpdatePostfix(Minimap __instance)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if (PluginConfig.IsModEnabled.Value && Minimap.IsOpen() && Object.op_Implicit((Object)(object)__instance) && Object.op_Implicit((Object)(object)__instance.m_largeRoot))
			{
				KeyboardShortcut value = PluginConfig.DisplayFilterPanel.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					PinOwnerManager.Initialize();
					PlayerFilterPanelManager.ToggleFilterPanel();
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("UpdatePins")]
		private static void UpdatePinsPostfix(Minimap __instance)
		{
			if (PluginConfig.IsModEnabled.Value && Minimap.IsOpen() && Object.op_Implicit((Object)(object)__instance) && Object.op_Implicit((Object)(object)__instance.m_largeRoot))
			{
				PinOwnerManager.FilterPins();
				PlayerFilterPanelManager.UpdatePinCounts();
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("UpdatePlayerPins")]
		private static void UpdatePlayerPinsPostfix(Minimap __instance)
		{
			if (!PluginConfig.IsModEnabled.Value || !Object.op_Implicit((Object)(object)__instance) || !Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
			}
			if (_pinCount > __instance.m_pins.Count)
			{
				_pinCount = __instance.m_pins.Count;
				PinOwnerManager.AddAllLocalPlayerPins();
				PlayerFilterPanelManager.UpdatePanel();
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("RemovePin", new Type[] { typeof(PinData) })]
		private static void RemovePinPostfix(Minimap __instance, PinData pin)
		{
			long ownerID = pin.m_ownerID;
			PinOwnerManager.RemoveLocalPlayerPin(pin);
			if (PinOwnerManager.GetPinsByPid(ownerID).Count == 0)
			{
				PinOwnerManager.RemoveForeignPinOwner(ownerID);
			}
			PlayerFilterPanelManager.UpdatePanel();
		}

		[HarmonyPostfix]
		[HarmonyPatch("ResetSharedMapData")]
		private static void ResetSharedMapData(Minimap __instance)
		{
			PinOwnerManager.ForeignPinOwners.RemoveAll((long x) => PinOwnerManager.GetPinsByPid(x).Count == 0);
			PlayerFilterPanelManager.UpdatePanel();
		}
	}
	[HarmonyPatch(typeof(ZNet))]
	internal static class ZNetPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("OnDestroy")]
		private static void OnDestroyPrefix()
		{
			if (PluginConfig.IsModEnabled.Value)
			{
				PinOwnerManager.WriteFilteredPlayersToFile();
				PinOwnerManager.Clear();
			}
		}
	}
	[BepInPlugin("bruce.valheim.comfymods.pintervention", "Pintervention", "1.2.0")]
	public class Pintervention : BaseUnityPlugin
	{
		public const string PluginGuid = "bruce.valheim.comfymods.pintervention";

		public const string PluginName = "Pintervention";

		public const string PluginVersion = "1.2.0";

		private Harmony _harmony;

		private static ManualLogSource _logger;

		private void Awake()
		{
			PluginConfig.BindConfig(((BaseUnityPlugin)this).Config);
			_logger = ((BaseUnityPlugin)this).Logger;
			_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "bruce.valheim.comfymods.pintervention");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		public static void MessageLocalPlayer(string message)
		{
			if (Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				((Character)Player.m_localPlayer).Message((MessageType)2, message, 0, (Sprite)null);
			}
		}

		public static void Log(string message)
		{
			_logger.LogInfo((object)message);
		}

		public static void LogWarning(string message)
		{
			_logger.LogWarning((object)message);
		}
	}
	public class LabelCell
	{
		public GameObject Cell { get; private set; }

		public Image Background { get; private set; }

		public TMP_Text Label { get; private set; }

		public LabelCell(Transform parentTransform)
		{
			Cell = CreateChildCell(parentTransform);
			Background = Cell.Image();
			Label = CreateChildLabel(Cell.transform);
		}

		private GameObject CreateChildCell(Transform parentTransform)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Cell", new Type[1] { typeof(RectTransform) });
			val.SetParent(parentTransform);
			val.AddComponent<HorizontalLayoutGroup>().SetChildControl(true, true).SetChildForceExpand(false, false)
				.SetPadding(4, 4, 4, 4)
				.SetSpacing(4f)
				.SetChildAlignment((TextAnchor)4);
			val.AddComponent<Image>().SetType((Type)1).SetSprite(UIBuilder.CreateRoundedCornerSprite(64, 64, 8, (FilterMode)1))
				.SetColor(new Color(0.2f, 0.2f, 0.2f, 0.5f));
			val.AddComponent<ContentSizeFitter>().SetHorizontalFit((FitMode)0).SetVerticalFit((FitMode)2);
			val.AddComponent<LayoutElement>().SetPreferred(150f, null).SetFlexible(1f);
			return val;
		}

		private TMP_Text CreateChildLabel(Transform parentTransform)
		{
			TMP_Text val = (TMP_Text)(object)UIBuilder.CreateTMPLabel(parentTransform);
			val.SetName<TMP_Text>("Label");
			val.alignment = (TextAlignmentOptions)513;
			val.text = "Label";
			((Component)val).gameObject.AddComponent<LayoutElement>().SetFlexible(1f);
			return val;
		}
	}
	public class ValueCell
	{
		private static readonly Lazy<ColorBlock> InputFieldColorBlock = new Lazy<ColorBlock>((Func<ColorBlock>)delegate
		{
			//IL_0002: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
			ColorBlock result = default(ColorBlock);
			((ColorBlock)(ref result)).normalColor = new Color(1f, 1f, 1f, 0.9f);
			((ColorBlock)(ref result)).highlightedColor = new Color(0.565f, 0.792f, 0.976f);
			((ColorBlock)(ref result)).disabledColor = new Color(0.2f, 0.2f, 0.2f, 0.8f);
			((ColorBlock)(ref result)).pressedColor = new Color(0.647f, 0.839f, 0.655f);
			((ColorBlock)(ref result)).selectedColor = new Color(1f, 0.878f, 0.51f);
			((ColorBlock)(ref result)).colorMultiplier = 1f;
			((ColorBlock)(ref result)).fadeDuration = 0.25f;
			return result;
		});

		public GameObject Cell { get; private set; }

		public Image Background { get; private set; }

		public TMP_InputField InputField { get; private set; }

		public ValueCell(Transform parentTransform)
		{
			Cell = CreateChildCell(parentTransform);
			Background = Cell.Image();
			InputField = CreateChildInputField(Cell.transform);
			((Selectable)(object)InputField).SetTargetGraphic((Graphic)(object)Background);
		}

		private GameObject CreateChildCell(Transform parentTransform)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Cell", new Type[1] { typeof(RectTransform) });
			val.SetParent(parentTransform);
			val.AddComponent<Image>().SetType((Type)1).SetSprite(UIBuilder.CreateRoundedCornerSprite(64, 64, 8, (FilterMode)1))
				.SetColor(new Color(0.5f, 0.5f, 0.5f, 0.5f));
			val.AddComponent<RectMask2D>();
			val.AddComponent<LayoutElement>();
			return val;
		}

		private TMP_InputField CreateChildInputField(Transform parentTransform)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_002e: 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_0042: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("InputField", new Type[1] { typeof(RectTransform) });
			val.SetParent(parentTransform);
			val.RectTransform().SetAnchorMin(Vector2.zero).SetAnchorMax(Vector2.one)
				.SetSizeDelta(Vector2.zero)
				.SetPosition(Vector2.zero);
			TMP_Text val2 = (TMP_Text)(object)UIBuilder.CreateTMPLabel(val.transform);
			val2.SetName<TMP_Text>("InputField.Text");
			val2.richText = false;
			val2.alignment = (TextAlignmentOptions)513;
			val2.text = "InputField.Text";
			TMP_InputField val3 = ((Component)parentTransform).gameObject.AddComponent<TMP_InputField>();
			val3.textComponent = val2;
			val3.textViewport = val.GetComponent<RectTransform>();
			((Selectable)val3).transition = (Transition)1;
			((Selectable)val3).colors = InputFieldColorBlock.Value;
			val3.onFocusSelectAll = false;
			((Selectable)(object)val3).SetNavigationMode((Mode)0);
			return val3;
		}
	}
	public class PanelDragger : MonoBehaviour, IBeginDragHandler, IEventSystemHandler, IDragHandler, IEndDragHandler
	{
		private Vector2 _lastMousePosition;

		public RectTransform TargetRectTransform;

		public event EventHandler<Vector3> OnPanelEndDrag;

		public void OnBeginDrag(PointerEventData eventData)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			_lastMousePosition = eventData.position;
		}

		public void OnDrag(PointerEventData eventData)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = eventData.position - _lastMousePosition;
			if (Object.op_Implicit((Object)(object)TargetRectTransform))
			{
				RectTransform targetRectTransform = TargetRectTransform;
				((Transform)targetRectTransform).position = ((Transform)targetRectTransform).position + new Vector3(val.x, val.y, ((Transform)TargetRectTransform).position.z);
			}
			_lastMousePosition = eventData.position;
		}

		public void OnEndDrag(PointerEventData eventData)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)TargetRectTransform))
			{
				this.OnPanelEndDrag?.Invoke(this, Vector2.op_Implicit(TargetRectTransform.anchoredPosition));
			}
		}
	}
	public class PanelResizer : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler, IBeginDragHandler, IDragHandler, IEndDragHandler
	{
		private CanvasGroup _canvasGroup;

		private float _targetAlpha = 0f;

		private Vector2 _lastMousePosition;

		private Coroutine _lerpAlphaCoroutine;

		public RectTransform TargetRectTransform;

		public event EventHandler<Vector2> OnPanelEndResize;

		private void Awake()
		{
			_canvasGroup = ((Component)this).GetComponent<CanvasGroup>();
		}

		private void SetCanvasGroupAlpha(float alpha)
		{
			if (_lerpAlphaCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(_lerpAlphaCoroutine);
				_lerpAlphaCoroutine = null;
			}
			if (_canvasGroup.alpha != alpha)
			{
				_lerpAlphaCoroutine = ((MonoBehaviour)this).StartCoroutine(LerpCanvasGroupAlpha(alpha, 0.25f));
			}
		}

		private IEnumerator LerpCanvasGroupAlpha(float targetAlpha, float lerpDuration)
		{
			float timeElapsed = 0f;
			float sourceAlpha = _canvasGroup.alpha;
			while (timeElapsed < lerpDuration)
			{
				float t2 = timeElapsed / lerpDuration;
				t2 = t2 * t2 * (3f - 2f * t2);
				_canvasGroup.SetAlpha(Mathf.Lerp(sourceAlpha, targetAlpha, t2));
				timeElapsed += Time.deltaTime;
				yield return null;
			}
			_canvasGroup.SetAlpha(targetAlpha);
		}

		public void OnPointerEnter(PointerEventData eventData)
		{
			_targetAlpha = 1f;
			SetCanvasGroupAlpha(_targetAlpha);
		}

		public void OnPointerExit(PointerEventData eventData)
		{
			_targetAlpha = 0f;
			if (!eventData.dragging)
			{
				SetCanvasGroupAlpha(_targetAlpha);
			}
		}

		public void OnBeginDrag(PointerEventData eventData)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			SetCanvasGroupAlpha(1f);
			_lastMousePosition = eventData.position;
		}

		public void OnDrag(PointerEventData eventData)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_0092: 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_0039: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = _lastMousePosition - eventData.position;
			if (Object.op_Implicit((Object)(object)TargetRectTransform))
			{
				RectTransform targetRectTransform = TargetRectTransform;
				targetRectTransform.anchoredPosition += new Vector2(0f, -0.5f * val.y);
				RectTransform targetRectTransform2 = TargetRectTransform;
				targetRectTransform2.sizeDelta += new Vector2(-1f * val.x, val.y);
			}
			SetCanvasGroupAlpha(1f);
			_lastMousePosition = eventData.position;
		}

		public void OnEndDrag(PointerEventData eventData)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			SetCanvasGroupAlpha(_targetAlpha);
			this.OnPanelEndResize?.Invoke(this, TargetRectTransform.sizeDelta);
		}
	}
	public class ParentSizeFitter : MonoBehaviour
	{
		private RectTransform _parentRectTransform;

		private RectTransform _rectTransform;

		private void Awake()
		{
			_parentRectTransform = ((Component)((Component)this).transform.parent).GetComponent<RectTransform>();
			_rectTransform = ((Component)this).GetComponent<RectTransform>();
		}

		private void OnRectTransformDimensionsChange()
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)_parentRectTransform))
			{
				_parentRectTransform = ((Component)((Component)this).transform.parent).GetComponent<RectTransform>();
			}
			if (!Object.op_Implicit((Object)(object)_rectTransform))
			{
				_rectTransform = ((Component)this).GetComponent<RectTransform>();
			}
			if (Object.op_Implicit((Object)(object)_rectTransform) && Object.op_Implicit((Object)(object)_parentRectTransform))
			{
				_rectTransform.SetSizeWithCurrentAnchors((Axis)0, _parentRectTransform.sizeDelta.x);
			}
		}
	}
	public class PointerState : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
	{
		public bool IsPointerHovered { get; private set; } = false;


		public void OnPointerEnter(PointerEventData eventData)
		{
			IsPointerHovered = true;
		}

		public void OnPointerExit(PointerEventData eventData)
		{
			IsPointerHovered = false;
		}
	}
	public static class UIBuilder
	{
		private static readonly Lazy<TextGenerator> CachedTextGenerator = new Lazy<TextGenerator>();

		private static readonly Dictionary<string, Sprite> _spriteCache = new Dictionary<string, Sprite>();

		private static readonly Color32 ColorWhite = Color32.op_Implicit(Color.white);

		private static readonly Color32 ColorClear = Color32.op_Implicit(Color.clear);

		public static TextMeshProUGUI CreateTMPLabel(Transform parentTransform)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val = Object.Instantiate<TextMeshProUGUI>(UnifiedPopup.instance.bodyText, parentTransform, false);
			((Object)val).name = "Label";
			((TMP_Text)val).text = string.Empty;
			((TMP_Text)val).fontSize = 16f;
			((Graphic)val).color = Color.white;
			((TMP_Text)val).richText = true;
			((TMP_Text)val).enableAutoSizing = false;
			return val;
		}

		public static GameObject CreateRowSpacer(Transform parentTransform)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			GameObject val = new GameObject(((Object)parentTransform).name + ".Spacer", new Type[1] { typeof(RectTransform) });
			val.SetParent(parentTransform);
			val.AddComponent<LayoutElement>().SetPreferred(20f, null);
			return val;
		}

		public static float GetPreferredWidth(this Text text)
		{
			return GetPreferredWidth(text, text.text);
		}

		public static float GetPreferredWidth(Text text, string content)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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)
			TextGenerator value = CachedTextGenerator.Value;
			Rect rect = ((Graphic)text).rectTransform.rect;
			return value.GetPreferredWidth(content, text.GetGenerationSettings(((Rect)(ref rect)).size));
		}

		public static Sprite CreateRoundedCornerSprite(int width, int height, int radius, FilterMode filterMode = 1)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			string text = $"RoundedCorner-{width}w-{height}h-{radius}r";
			if (_spriteCache.TryGetValue(text, out var value))
			{
				return value;
			}
			Texture2D val = Texture2DExtensions.SetName(new Texture2D(width, height), text).SetWrapMode((TextureWrapMode)1).SetFilterMode(filterMode);
			Color32[] array = (Color32[])(object)new Color32[width * height];
			for (int i = 0; i < height; i++)
			{
				for (int j = 0; j < width; j++)
				{
					array[i * width + j] = (IsCornerPixel(j, i, width, height, radius) ? ColorClear : ColorWhite);
				}
			}
			val.SetPixels32(array);
			val.Apply();
			int k;
			for (k = 0; k < width && !(Color32.op_Implicit(array[k]) == Color.white); k++)
			{
			}
			int l;
			for (l = 0; l < height && !(Color32.op_Implicit(array[l * width]) == Color.white); l++)
			{
			}
			value = Sprite.Create(val, new Rect(0f, 0f, (float)width, (float)height), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0, new Vector4((float)k, (float)l, (float)k, (float)l)).SetName(text);
			_spriteCache[text] = value;
			return value;
		}

		private static bool IsCornerPixel(int x, int y, int w, int h, int rad)
		{
			if (rad == 0)
			{
				return false;
			}
			int num = Math.Min(x, w - x);
			int num2 = Math.Min(y, h - y);
			if (num == 0 && num2 == 0)
			{
				return true;
			}
			if (num > rad || num2 > rad)
			{
				return false;
			}
			num = rad - num;
			num2 = rad - num2;
			return Math.Round(Math.Sqrt(num * num + num2 * num2)) > (double)rad;
		}

		public static Sprite CreateSuperellipse(int width, int height, float exponent)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_01b6: 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_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: 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_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			string text = $"Superellipse-{width}w-{height}h-{exponent}e";
			if (_spriteCache.TryGetValue(text, out var value))
			{
				return value;
			}
			Texture2D val = Texture2DExtensions.SetName(new Texture2D(width, height), text).SetWrapMode((TextureWrapMode)1).SetFilterMode((FilterMode)2);
			Color32[] array = (Color32[])(object)new Color32[width * height];
			int num = width / 2;
			int num2 = height / 2;
			float num3 = 1f;
			float num4 = num3 * ((float)width / 2f);
			float num5 = num3 * ((float)height / 2f);
			for (int i = 0; i < num; i++)
			{
				for (int j = 0; j < num2; j++)
				{
					float num6 = Mathf.Pow(Mathf.Abs((float)i / num4), exponent) + Mathf.Pow(Mathf.Abs((float)j / num5), exponent);
					Color32 val2 = Color32.op_Implicit((num6 > 1f) ? Color.clear : Color.white);
					int x2 = i + num;
					int x3 = -i + num - 1;
					int y2 = -j + num2 - 1;
					int y3 = j + num2;
					array[XYToIndex(x2, y3)] = val2;
					array[XYToIndex(x2, y2)] = val2;
					array[XYToIndex(x3, y2)] = val2;
					array[XYToIndex(x3, y3)] = val2;
				}
			}
			val.SetPixels32(array);
			val.Apply();
			int k;
			for (k = 0; k < width && !(Color32.op_Implicit(array[k]) == Color.white); k++)
			{
			}
			int l;
			for (l = 0; l < height && !(Color32.op_Implicit(array[l * width]) == Color.white); l++)
			{
			}
			value = Sprite.Create(val, new Rect(0f, 0f, (float)width, (float)height), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0, new Vector4((float)k, (float)l, (float)k, (float)l)).SetName(text);
			_spriteCache[text] = value;
			return value;
			int XYToIndex(int x, int y)
			{
				return x + y * width;
			}
		}
	}
	public static class CanvasGroupExtensions
	{
		public static CanvasGroup SetAlpha(this CanvasGroup canvasGroup, float alpha)
		{
			canvasGroup.alpha = alpha;
			return canvasGroup;
		}

		public static CanvasGroup SetBlocksRaycasts(this CanvasGroup canvasGroup, bool blocksRaycasts)
		{
			canvasGroup.blocksRaycasts = blocksRaycasts;
			return canvasGroup;
		}
	}
	public static class ColorExtensions
	{
		public static Color SetAlpha(this Color color, float alpha)
		{
			//IL_0009: 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_000d: Unknown result type (might be due to invalid IL or missing references)
			color.a = alpha;
			return color;
		}
	}
	public static class ContentSizeFitterExtensions
	{
		public static ContentSizeFitter SetHorizontalFit(this ContentSizeFitter fitter, FitMode fitMode)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			fitter.horizontalFit = fitMode;
			return fitter;
		}

		public static ContentSizeFitter SetVerticalFit(this ContentSizeFitter fitter, FitMode fitMode)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			fitter.verticalFit = fitMode;
			return fitter;
		}
	}
	public static class GameObjectExtensions
	{
		public static GameObject SetName(this GameObject gameObject, string name)
		{
			((Object)gameObject).name = name;
			return gameObject;
		}

		public static T SetName<T>(this T component, string name) where T : Component
		{
			((Object)((Component)component).gameObject).name = name;
			return component;
		}

		public static GameObject SetParent(this GameObject gameObject, Transform transform, bool worldPositionStays = false)
		{
			gameObject.transform.SetParent(transform, worldPositionStays);
			return gameObject;
		}

		public static IEnumerable<GameObject> Children(this GameObject gameObject)
		{
			return Object.op_Implicit((Object)(object)gameObject) ? (from Transform t in (IEnumerable)gameObject.transform
				select ((Component)t).gameObject) : Enumerable.Empty<GameObject>();
		}

		public static Button Button(this GameObject gameObject)
		{
			return Object.op_Implicit((Object)(object)gameObject) ? gameObject.GetComponent<Button>() : null;
		}

		public static Image Image(this GameObject gameObject)
		{
			return Object.op_Implicit((Object)(object)gameObject) ? gameObject.GetComponent<Image>() : null;
		}

		public static LayoutElement LayoutElement(this GameObject gameObject)
		{
			return Object.op_Implicit((Object)(object)gameObject) ? gameObject.GetComponent<LayoutElement>() : null;
		}

		public static RectTransform RectTransform(this GameObject gameObject)
		{
			return Object.op_Implicit((Object)(object)gameObject) ? gameObject.GetComponent<RectTransform>() : null;
		}

		public static Text Text(this GameObject gameObject)
		{
			return Object.op_Implicit((Object)(object)gameObject) ? gameObject.GetComponent<Text>() : null;
		}
	}
	public static class GridLayoutGroupExtensions
	{
		public static GridLayoutGroup SetCellSize(this GridLayoutGroup layoutGroup, Vector2 cellSize)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			layoutGroup.cellSize = cellSize;
			return layoutGroup;
		}

		public static GridLayoutGroup SetConstraint(this GridLayoutGroup layoutGroup, Constraint constraint)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			layoutGroup.constraint = constraint;
			return layoutGroup;
		}

		public static GridLayoutGroup SetConstraintCount(this GridLayoutGroup layoutGroup, int constraintCount)
		{
			layoutGroup.constraintCount = constraintCount;
			return layoutGroup;
		}

		public static GridLayoutGroup SetStartAxis(this GridLayoutGroup layoutGroup, Axis startAxis)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			layoutGroup.startAxis = startAxis;
			return layoutGroup;
		}

		public static GridLayoutGroup SetStartCorner(this GridLayoutGroup layoutGroup, Corner startCorner)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			layoutGroup.startCorner = startCorner;
			return layoutGroup;
		}

		public static GridLayoutGroup SetPadding(this GridLayoutGroup layoutGroup, int? left = null, int? right = null, int? top = null, int? bottom = null)
		{
			if (!left.HasValue && !right.HasValue && !top.HasValue && !bottom.HasValue)
			{
				throw new ArgumentException("Value for left, right, top or bottom must be provided.");
			}
			if (left.HasValue)
			{
				((LayoutGroup)layoutGroup).padding.left = left.Value;
			}
			if (right.HasValue)
			{
				((LayoutGroup)layoutGroup).padding.right = right.Value;
			}
			if (top.HasValue)
			{
				((LayoutGroup)layoutGroup).padding.top = top.Value;
			}
			if (bottom.HasValue)
			{
				((LayoutGroup)layoutGroup).padding.bottom = bottom.Value;
			}
			return layoutGroup;
		}

		public static GridLayoutGroup SetSpacing(this GridLayoutGroup layoutGroup, Vector2 spacing)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			layoutGroup.spacing = spacing;
			return layoutGroup;
		}
	}
	public static class HorizontalLayoutGroupExtensions
	{
		public static HorizontalLayoutGroup SetChildControl(this HorizontalLayoutGroup layoutGroup, bool? width = null, bool? height = null)
		{
			if (!width.HasValue && !height.HasValue)
			{
				throw new ArgumentException("Value for width or height must be provided.");
			}
			if (width.HasValue)
			{
				((HorizontalOrVerticalLayoutGroup)layoutGroup).childControlWidth = width.Value;
			}
			if (height.HasValue)
			{
				((HorizontalOrVerticalLayoutGroup)layoutGroup).childControlHeight = height.Value;
			}
			return layoutGroup;
		}

		public static HorizontalLayoutGroup SetChildForceExpand(this HorizontalLayoutGroup layoutGroup, bool? width = null, bool? height = null)
		{
			if (!width.HasValue && !height.HasValue)
			{
				throw new ArgumentException("Value for width or height must be provided.");
			}
			if (width.HasValue)
			{
				((HorizontalOrVerticalLayoutGroup)layoutGroup).childForceExpandWidth = width.Value;
			}
			if (height.HasValue)
			{
				((HorizontalOrVerticalLayoutGroup)layoutGroup).childForceExpandHeight = height.Value;
			}
			return layoutGroup;
		}

		public static HorizontalLayoutGroup SetChildAlignment(this HorizontalLayoutGroup layoutGroup, TextAnchor alignment)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			((LayoutGroup)layoutGroup).childAlignment = alignment;
			return layoutGroup;
		}

		public static HorizontalLayoutGroup SetPadding(this HorizontalLayoutGroup layoutGroup, int? left = null, int? right = null, int? top = null, int? bottom = null)
		{
			if (!left.HasValue && !right.HasValue && !top.HasValue && !bottom.HasValue)
			{
				throw new ArgumentException("Value for left, right, top or bottom must be provided.");
			}
			if (left.HasValue)
			{
				((LayoutGroup)layoutGroup).padding.left = left.Value;
			}
			if (right.HasValue)
			{
				((LayoutGroup)layoutGroup).padding.right = right.Value;
			}
			if (top.HasValue)
			{
				((LayoutGroup)layoutGroup).padding.top = top.Value;
			}
			if (bottom.HasValue)
			{
				((LayoutGroup)layoutGroup).padding.bottom = bottom.Value;
			}
			return layoutGroup;
		}

		public static HorizontalLayoutGroup SetSpacing(this HorizontalLayoutGroup layoutGroup, float spacing)
		{
			((HorizontalOrVerticalLayoutGroup)layoutGroup).spacing = spacing;
			return layoutGroup;
		}
	}
	public static class ImageExtensions
	{
		public static Image SetColor(this Image image, Color color)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			((Graphic)image).color = color;
			return image;
		}

		public static Image SetFillAmount(this Image image, float amount)
		{
			image.fillAmount = amount;
			return image;
		}

		public static Image SetFillCenter(this Image image, bool fillCenter)
		{
			image.fillCenter = fillCenter;
			return image;
		}

		public static Image SetFillMethod(this Image image, FillMethod fillMethod)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			image.fillMethod = fillMethod;
			return image;
		}

		public static Image SetFillOrigin(this Image image, OriginHorizontal origin)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected I4, but got Unknown
			image.fillOrigin = (int)origin;
			return image;
		}

		public static Image SetFillOrigin(this Image image, OriginVertical origin)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected I4, but got Unknown
			image.fillOrigin = (int)origin;
			return image;
		}

		public static Image SetMaskable(this Image image, bool maskable)
		{
			((MaskableGraphic)image).maskable = maskable;
			return image;
		}

		public static Image SetPreserveAspect(this Image image, bool preserveAspect)
		{
			image.preserveAspect = preserveAspect;
			return image;
		}

		public static Image SetRaycastTarget(this Image image, bool raycastTarget)
		{
			((Graphic)image).raycastTarget = raycastTarget;
			return image;
		}

		public static Image SetSprite(this Image image, Sprite sprite)
		{
			image.sprite = sprite;
			return image;
		}

		public static Image SetType(this Image image, Type type)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			image.type = type;
			return image;
		}
	}
	public static class InputFieldExtensions
	{
		public static InputField SetTextComponent(this InputField inputField, Text textComponent)
		{
			inputField.textComponent = textComponent;
			return inputField;
		}
	}
	public static class LayoutElementExtensions
	{
		public static LayoutElement SetPreferred(this LayoutElement layoutElement, float? width = null, float? height = null)
		{
			if (!width.HasValue && !height.HasValue)
			{
				throw new ArgumentException("Value for width or height must be provided.");
			}
			if (width.HasValue)
			{
				layoutElement.preferredWidth = width.Value;
			}
			if (height.HasValue)
			{
				layoutElement.preferredHeight = height.Value;
			}
			return layoutElement;
		}

		public static LayoutElement SetPreferred(this LayoutElement layoutElement, Vector2 sizeDelta)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			layoutElement.preferredWidth = sizeDelta.x;
			layoutElement.preferredHeight = sizeDelta.y;
			return layoutElement;
		}

		public static LayoutElement SetFlexible(this LayoutElement layoutElement, float? width = null, float? height = null)
		{
			if (!width.HasValue && !height.HasValue)
			{
				throw new ArgumentException("Value for width or height must be provided.");
			}
			if (width.HasValue)
			{
				layoutElement.flexibleWidth = width.Value;
			}
			if (height.HasValue)
			{
				layoutElement.flexibleHeight = height.Value;
			}
			return layoutElement;
		}

		public static LayoutElement SetMinimum(this LayoutElement layoutElement, float? width = null, float? height = null)
		{
			if (!width.HasValue && !height.HasValue)
			{
				throw new ArgumentException("Value for width or height must be provided.");
			}
			if (width.HasValue)
			{
				layoutElement.minWidth = width.Value;
			}
			if (height.HasValue)
			{
				layoutElement.minHeight = height.Value;
			}
			return layoutElement;
		}

		public static LayoutElement SetIgnoreLayout(this LayoutElement layoutElement, bool ignoreLayout)
		{
			layoutElement.ignoreLayout = ignoreLayout;
			return layoutElement;
		}
	}
	public static class MaskExtensions
	{
		public static Mask SetShowMaskGraphic(this Mask mask, bool showMaskGraphic)
		{
			mask.showMaskGraphic = showMaskGraphic;
			return mask;
		}
	}
	public static class OutlineExtensions
	{
		public static Outline SetEffectColor(this Outline outline, Color effectColor)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			((Shadow)outline).effectColor = effectColor;
			return outline;
		}

		public static Outline SetEffectDistance(this Outline outline, Vector2 effectDistance)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			((Shadow)outline).effectDistance = effectDistance;
			return outline;
		}

		public static Outline SetUseGraphicAlpha(this Outline outline, bool useGraphicAlpha)
		{
			((Shadow)outline).useGraphicAlpha = useGraphicAlpha;
			return outline;
		}
	}
	public static class RectTransformExtensions
	{
		public static RectTransform SetAnchorMin(this RectTransform rectTransform, Vector2 anchorMin)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			rectTransform.anchorMin = anchorMin;
			return rectTransform;
		}

		public static RectTransform SetAnchorMax(this RectTransform rectTransform, Vector2 anchorMax)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			rectTransform.anchorMax = anchorMax;
			return rectTransform;
		}

		public static RectTransform SetPivot(this RectTransform rectTransform, Vector2 pivot)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			rectTransform.pivot = pivot;
			return rectTransform;
		}

		public static RectTransform SetPosition(this RectTransform rectTransform, Vector2 position)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			rectTransform.anchoredPosition = position;
			return rectTransform;
		}

		public static RectTransform SetSizeDelta(this RectTransform rectTransform, Vector2 sizeDelta)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			rectTransform.sizeDelta = sizeDelta;
			return rectTransform;
		}
	}
	public static class SelectableExtensions
	{
		public static Selectable SetColors(this Selectable selectable, ColorBlock colors)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			selectable.colors = colors;
			return selectable;
		}

		public static Selectable SetImage(this Selectable selectable, Image image)
		{
			selectable.image = image;
			return selectable;
		}

		public static Selectable SetInteractable(this Selectable selectable, bool interactable)
		{
			selectable.interactable = interactable;
			return selectable;
		}

		public static Selectable SetTargetGraphic(this Selectable selectable, Graphic graphic)
		{
			selectable.targetGraphic = graphic;
			return selectable;
		}

		public static Selectable SetTransition(this Selectable selectable, Transition transition)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			selectable.transition = transition;
			return selectable;
		}

		public static Selectable SetNavigationMode(this Selectable selectable, Mode mode)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			Navigation navigation = selectable.navigation;
			((Navigation)(ref navigation)).mode = mode;
			selectable.navigation = navigation;
			return selectable;
		}
	}
	public static class ShadowExtensions
	{
		public static Shadow SetEffectColor(this Shadow shadow, Color effectColor)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			shadow.effectColor = effectColor;
			return shadow;
		}

		public static Shadow SetEffectDistance(this Shadow shadow, Vector2 effectDistance)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			shadow.effectDistance = effectDistance;
			return shadow;
		}
	}
	public static class ScrollRectExtensions
	{
		public static ScrollRect SetScrollSensitivity(this ScrollRect scrollRect, float sensitivity)
		{
			scrollRect.scrollSensitivity = sensitivity;
			return scrollRect;
		}

		public static ScrollRect SetVerticalScrollPosition(this ScrollRect scrollRect, float position)
		{
			scrollRect.verticalNormalizedPosition = position;
			return scrollRect;
		}

		public static ScrollRect SetViewport(this ScrollRect scrollRect, RectTransform viewport)
		{
			scrollRect.viewport = viewport;
			return scrollRect;
		}

		public static ScrollRect SetContent(this ScrollRect scrollRect, RectTransform content)
		{
			scrollRect.content = content;
			return scrollRect;
		}

		public static ScrollRect SetHorizontal(this ScrollRect scrollRect, bool horizontal)
		{
			scrollRect.horizontal = horizontal;
			return scrollRect;
		}

		public static ScrollRect SetVertical(this ScrollRect scrollRect, bool vertical)
		{
			scrollRect.vertical = vertical;
			return scrollRect;
		}
	}
	public static class SpriteExtensions
	{
		public static Sprite SetName(this Sprite sprite, string name)
		{
			((Object)sprite).name = name;
			return sprite;
		}
	}
	public static class TextExtensions
	{
		public static Text SetAlignment(this Text text, TextAnchor alignment)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			text.alignment = alignment;
			return text;
		}

		public static Text SetColor(this Text text, Color color)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			((Graphic)text).color = color;
			return text;
		}

		public static Text SetFont(this Text text, Font font)
		{
			text.font = font;
			return text;
		}

		public static Text SetFontStyle(this Text text, FontStyle fontStyle)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			text.fontStyle = fontStyle;
			return text;
		}

		public static Text SetFontSize(this Text text, int fontSize)
		{
			text.fontSize = fontSize;
			return text;
		}

		public static Text SetResizeTextForBestFit(this Text text, bool resizeTextForBestFit)
		{
			text.resizeTextForBestFit = resizeTextForBestFit;
			return text;
		}

		public static Text SetSupportRichText(this Text text, bool supportRichText)
		{
			text.supportRichText = supportRichText;
			return text;
		}

		public static Text SetText(this Text text, string value)
		{
			text.text = value;
			return text;
		}
	}
	public static class TMPTextExtensions
	{
		public static TMP_Text SetText(this TMP_Text text, string value)
		{
			text.text = value;
			return text;
		}
	}
	public static class Texture2DExtensions
	{
		public static Texture2D SetName(this Texture2D texture, string name)
		{
			((Object)texture).name = name;
			return texture;
		}

		public static Texture2D SetWrapMode(this Texture2D texture, TextureWrapMode wrapMode)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			((Texture)texture).wrapMode = wrapMode;
			return texture;
		}

		public static Texture2D SetFilterMode(this Texture2D texture, FilterMode filterMode)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			((Texture)texture).filterMode = filterMode;
			return texture;
		}
	}
	public static class VerticalLayoutGroupExtensions
	{
		public static VerticalLayoutGroup SetChildControl(this VerticalLayoutGroup layoutGroup, bool? width = null, bool? height = null)
		{
			if (!width.HasValue && !height.HasValue)
			{
				throw new ArgumentException("Value for width or height must be provided.");
			}
			if (width.HasValue)
			{
				((HorizontalOrVerticalLayoutGroup)layoutGroup).childControlWidth = width.Value;
			}
			if (height.HasValue)
			{
				((HorizontalOrVerticalLayoutGroup)layoutGroup).childControlHeight = height.Value;
			}
			return layoutGroup;
		}

		public static VerticalLayoutGroup SetChildForceExpand(this VerticalLayoutGroup layoutGroup, bool? width = null, bool? height = null)
		{
			if (!width.HasValue && !height.HasValue)
			{
				throw new ArgumentException("Value for width or height must be provided.");
			}
			if (width.HasValue)
			{
				((HorizontalOrVerticalLayoutGroup)layoutGroup).childForceExpandWidth = width.Value;
			}
			if (height.HasValue)
			{
				((HorizontalOrVerticalLayoutGroup)layoutGroup).childForceExpandHeight = height.Value;
			}
			return layoutGroup;
		}

		public static VerticalLayoutGroup SetChildAlignment(this VerticalLayoutGroup layoutGroup, TextAnchor alignment)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			((LayoutGroup)layoutGroup).childAlignment = alignment;
			return layoutGroup;
		}

		public static VerticalLayoutGroup SetPadding(this VerticalLayoutGroup layoutGroup, int? left = null, int? right = null, int? top = null, int? bottom = null)
		{
			if (!left.HasValue && !right.HasValue && !top.HasValue && !bottom.HasValue)
			{
				throw new ArgumentException("Value for left, right, top or bottom must be provided.");
			}
			if (left.HasValue)
			{
				((LayoutGroup)layoutGroup).padding.left = left.Value;
			}
			if (right.HasValue)
			{
				((LayoutGroup)layoutGroup).padding.right = right.Value;
			}
			if (top.HasValue)
			{
				((LayoutGroup)layoutGroup).padding.top = top.Value;
			}
			if (bottom.HasValue)
			{
				((LayoutGroup)layoutGroup).padding.bottom = bottom.Value;
			}
			return layoutGroup;
		}

		public static VerticalLayoutGroup SetSpacing(this VerticalLayoutGroup layoutGroup, float spacing)
		{
			((HorizontalOrVerticalLayoutGroup)layoutGroup).spacing = spacing;
			return layoutGroup;
		}
	}
	public static class ButtonExtensions
	{
		public static Button SetOnClickListener(this Button button, UnityAction action)
		{
			((UnityEvent)button.onClick).AddListener(action);
			return button;
		}
	}
	public class UIResources
	{
		private static readonly Dictionary<string, Sprite> SpriteCache = new Dictionary<string, Sprite>();

		public static string ValheimNorseFont = "Valheim-Norse";

		public static string ValheimAveriaSansLibre = "Valheim-AveriaSansLibre";

		public static Dictionary<string, TMP_FontAsset> FontAssetCache { get; private set; } = new Dictionary<string, TMP_FontAsset>();


		public static TMP_FontAsset ValheimNorseFontAsset => ((TMP_Text)Minimap.m_instance.m_pinNamePrefab.GetComponentInChildren<TextMeshProUGUI>()).font;

		public static TMP_FontAsset ValheimAveriaSansLibreFontAsset => ((TMP_Text)UnifiedPopup.instance.bodyText).font;

		public static Sprite GetSprite(string spriteName)
		{
			if (!SpriteCache.TryGetValue(spriteName, out var value))
			{
				value = ((IEnumerable<Sprite>)Resources.FindObjectsOfTypeAll<Sprite>()).FirstOrDefault((Func<Sprite, bool>)((Sprite sprite) => ((Object)sprite).name == spriteName));
				SpriteCache[spriteName] = value;
			}
			return value;
		}

		public static TMP_FontAsset GetFontAssetByName(string fontAssetName)
		{
			if (FontAssetCache.TryGetValue(fontAssetName, out var value))
			{
				return value;
			}
			if (fontAssetName == ValheimNorseFont)
			{
				value = ValheimNorseFontAsset;
				FontAssetCache[fontAssetName] = value;
				return value;
			}
			if (fontAssetName == ValheimAveriaSansLibre)
			{
				value = ValheimAveriaSansLibreFontAsset;
				FontAssetCache[fontAssetName] = value;
				return value;
			}
			TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
			foreach (TMP_FontAsset val in array)
			{
				FontAssetCache[((Object)val).name] = val;
			}
			return FontAssetCache[fontAssetName];
		}
	}
	public class PlayerListRow
	{
		private long _pid;

		private static readonly Lazy<ColorBlock> ButtonColorBlock = new Lazy<ColorBlock>((Func<ColorBlock>)delegate
		{
			//IL_0002: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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)
			ColorBlock result = default(ColorBlock);
			((ColorBlock)(ref result)).normalColor = new Color(0f, 0f, 0f, 0.01f);
			((ColorBlock)(ref result)).highlightedColor = Color32.op_Implicit(new Color32((byte)50, (byte)161, (byte)217, (byte)128));
			((ColorBlock)(ref result)).disabledColor = new Color(0f, 0f, 0f, 0.1f);
			((ColorBlock)(ref result)).pressedColor = Color32.op_Implicit(new Color32((byte)50, (byte)161, (byte)217, (byte)192));
			((ColorBlock)(ref result)).selectedColor = Color32.op_Implicit(new Color32((byte)50, (byte)161, (byte)217, (byte)248));
			((ColorBlock)(ref result)).colorMultiplier = 1f;
			((ColorBlock)(ref result)).fadeDuration = 0f;
			return result;
		});

		public GameObject Row { get; private set; }

		public Image PinIcon { get; private set; }

		public TMP_Text PinName { get; private set; }

		public TMP_Text PinCount { get; private set; }

		public TMP_Text FilterStatus { get; private set; }

		public PlayerListRow(Transform parentTransform)
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			Row = CreateChildRow(parentTransform);
			PinIcon = CreateChildPinIcon(Row.transform).Image();
			PinName = CreateChildPinName(Row.transform);
			UIBuilder.CreateRowSpacer(Row.transform);
			PinCount = CreatePinCountValue(Row.transform);
			((Graphic)PinCount).color = new Color(0.565f, 0.792f, 0.976f);
			FilterStatus = CreatePinCountValue(Row.transform);
			FilterStatus.fontSize = 14f;
		}

		public PlayerListRow SetRowContent(long pid)
		{
			_pid = pid;
			PinIcon.SetSprite(Minimap.m_instance.GetSprite((PinType)10));
			UpdateName();
			UpdateCount();
			UpdateFilterStatus();
			return this;
		}

		public void UpdateName()
		{
			PinName.SetText(NameManager.GetPlayerNameById(_pid));
		}

		public void UpdateCount()
		{
			PinCount.SetText($"{PinOwnerManager.GetPinsByPid(_pid).Count}");
		}

		public void UpdateFilterStatus()
		{
			if (PinOwnerManager.IsFiltered(_pid))
			{
				FilterStatus.SetText("<color=red>X</color>");
			}
			else
			{
				FilterStatus.SetText("<color=green><b>✓</b></color>");
			}
		}

		private GameObject CreateChildRow(Transform parentTransform)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("PinList.Row", new Type[1] { typeof(RectTransform) });
			val.SetParent(parentTransform);
			val.AddComponent<HorizontalLayoutGroup>().SetChildControl(true, true).SetChildForceExpand(false, false)
				.SetChildAlignment((TextAnchor)4)
				.SetPadding(5, 10, 5, 5)
				.SetSpacing(5f);
			val.AddComponent<Image>().SetType((Type)1).SetSprite(UIBuilder.CreateRoundedCornerSprite(400, 400, 5, (FilterMode)1));
			((Selectable)(object)val.AddComponent<Button>().SetOnClickListener(new UnityAction(ToggleFilter))).SetNavigationMode((Mode)0).SetTargetGraphic((Graphic)(object)val.Image()).SetColors(ButtonColorBlock.Value);
			val.AddComponent<ContentSizeFitter>().SetHorizontalFit((FitMode)0).SetVerticalFit((FitMode)2);
			val.AddComponent<ParentSizeFitter>();
			return val;
		}

		public void ToggleFilter()
		{
			PinOwnerManager.ToggleFilter(_pid);
			UpdateFilterStatus();
		}

		private GameObject CreateChildPinIcon(Transform parentTransform)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			GameObject val = new GameObject("Pin.Icon", new Type[1] { typeof(RectTransform) });
			val.SetParent(parentTransform);
			val.AddComponent<LayoutElement>().SetPreferred(20f, 20f);
			val.AddComponent<Image>().SetType((Type)0);
			return val;
		}

		private TMP_Text CreateChildPinName(Transform parentTransform)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			TMP_Text val = (TMP_Text)(object)UIBuilder.CreateTMPLabel(parentTransform);
			val.SetName<TMP_Text>("Pin.Name");
			val.alignment = (TextAlignmentOptions)513;
			val.text = "Blankname1234567891011121314";
			((Component)val).gameObject.AddComponent<LayoutElement>().SetPreferred(val.GetPreferredValues().x, null);
			return val;
		}

		private TMP_Text CreatePinCountValue(Transform parentTransform)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			TMP_Text val = (TMP_Text)(object)UIBuilder.CreateTMPLabel(parentTransform);
			val.SetName<TMP_Text>("Pin.Count.Value");
			val.alignment = (TextAlignmentOptions)516;
			val.text = "-12X✓";
			((Component)val).gameObject.AddComponent<LayoutElement>().SetPreferred(val.GetPreferredValues().x, val.GetPreferredValues().y);
			return val;
		}
	}
	public class PlayerPinFilterPanel
	{
		private readonly PointerState _pointerState;

		private readonly List<PlayerListRow> _rowCache = new List<PlayerListRow>();

		private int _visibleRows = 0;

		private float _rowPreferredHeight = 0f;

		private LayoutElement _bufferBlock;

		private bool _isRefreshing = false;

		private int _previousRowIndex = -1;

		public GameObject Panel { get; private set; }

		public ValueCell PinNameFilter { get; private set; }

		public GameObject Viewport { get; private set; }

		public GameObject Content { get; private set; }

		public ScrollRect ScrollRect { get; private set; }

		public LabelCell PinStats { get; private set; }

		public PanelDragger PanelDragger { get; private set; }

		public PanelResizer PanelResizer { get; private set; }

		public PlayerPinFilterPanel(Transform parentTransform)
		{
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			Panel = CreateChildPanel(parentTransform);
			PanelDragger = CreateChildPanelDragger(Panel).AddComponent<PanelDragger>();
			PanelDragger.TargetRectTransform = Panel.RectTransform();
			PanelResizer = CreateChildPanelResizer(Panel).AddComponent<PanelResizer>();
			PanelResizer.TargetRectTransform = Panel.RectTransform();
			PinNameFilter = new ValueCell(Panel.transform);
			LayoutElement layoutElement = PinNameFilter.Cell.LayoutElement().SetFlexible(1f);
			float? height = 30f;
			layoutElement.SetPreferred(null, height);
			Viewport = CreateChildViewport(Panel.transform);
			Content = CreateChildContent(Viewport.transform);
			ScrollRect = CreateChildScrollRect(Panel, Viewport, Content);
			PinStats = new LabelCell(Panel.transform);
			PinStats.Cell.GetComponent<HorizontalLayoutGroup>().SetPadding(8, 8, 5, 5);
			PinStats.Cell.Image().SetColor(new Color(0.5f, 0.5f, 0.5f, 0.1f));
			PinStats.Cell.AddComponent<Outline>().SetEffectDistance(new Vector2(2f, -2f));
			_pointerState = Panel.AddComponent<PointerState>();
			UpdatePanel();
		}

		public bool HasFocus()
		{
			return Object.op_Implicit((Object)(object)Panel) && Panel.activeInHierarchy && _pointerState.IsPointerHovered;
		}

		public void UpdatePinCounts()
		{
			if ((Object)(object)Panel == (Object)null)
			{
				return;
			}
			foreach (PlayerListRow item in _rowCache)
			{
				item.UpdateCount();
			}
		}

		public void UpdatePanel()
		{
			RefreshPinListRows();
			PinStats.Label.SetText($"{PinOwnerManager.ForeignPinOwners.Count} players with pins.");
		}

		private void BuildPinListRows()
		{
		}

		private void RefreshPinListRows()
		{
			//IL_001d: 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
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			((UnityEventBase)ScrollRect.onValueChanged).RemoveAllListeners();
			Content.RectTransform().SetPosition(Vector2.zero);
			ScrollRect.SetVerticalScrollPosition(1f);
			_previousRowIndex = -1;
			_rowCache.Clear();
			foreach (GameObject item in Content.Children())
			{
				Object.Destroy((Object)(object)item);
			}
			GameObject val = new GameObject("ppl.Block", new Type[1] { typeof(RectTransform) });
			val.SetParent(Content.transform);
			_bufferBlock = val.AddComponent<LayoutElement>();
			LayoutElement bufferBlock = _bufferBlock;
			float? height = 0f;
			bufferBlock.SetPreferred(null, height);
			PlayerListRow playerListRow = new PlayerListRow(Content.transform);
			LayoutRebuilder.ForceRebuildLayoutImmediate(Panel.RectTransform());
			_rowPreferredHeight = LayoutUtility.GetPreferredHeight(playerListRow.Row.RectTransform());
			_visibleRows = Mathf.CeilToInt(Viewport.RectTransform().sizeDelta.y / _rowPreferredHeight);
			Object.Destroy((Object)(object)playerListRow.Row);
			Content.RectTransform().SetSizeDelta(new Vector2(Viewport.RectTransform().sizeDelta.x, _rowPreferredHeight * (float)PinOwnerManager.ForeignPinOwners.Count));
			PinOwnerManager.SortPinOwnersByName();
			for (int i = 0; i < PinOwnerManager.ForeignPinOwners.Count; i++)
			{
				playerListRow = new PlayerListRow(Content.transform);
				playerListRow.SetRowContent(PinOwnerManager.GetForeignPinOwnerAtIndex(i));
				_rowCache.Add(playerListRow);
			}
			_previousRowIndex = -1;
			ScrollRect.SetVerticalScrollPosition(1f);
		}

		private GameObject CreateChildPanel(Transform parentTransform)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("PlayerPinList.Panel", new Type[1] { typeof(RectTransform) });
			val.SetParent(parentTransform);
			val.AddComponent<VerticalLayoutGroup>().SetChildControl(true, true).SetChildForceExpand(false, false)
				.SetPadding(8, 8, 8, 8)
				.SetSpacing(8f);
			val.AddComponent<Image>().SetType((Type)1).SetSprite(UIBuilder.CreateSuperellipse(400, 400, 15f))
				.SetColor(new Color(0f, 0f, 0f, 0.9f));
			return val;
		}

		private GameObject CreateChildViewport(Transform parentTransform)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("PlayerPinList.Viewport", new Type[1] { typeof(RectTransform) });
			val.SetParent(parentTransform);
			val.AddComponent<RectMask2D>();
			val.AddComponent<LayoutElement>().SetFlexible(1f, 1f);
			val.AddComponent<Image>().SetType((Type)1).SetSprite(UIBuilder.CreateRoundedCornerSprite(128, 128, 8, (FilterMode)1))
				.SetColor(new Color(0.5f, 0.5f, 0.5f, 0.1f));
			val.AddComponent<Outline>().SetEffectDistance(new Vector2(2f, -2f));
			return val;
		}

		private GameObject CreateChildContent(Transform parentTransform)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_002e: 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_0042: 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)
			GameObject val = new GameObject("PlayerPinList.Content", new Type[1] { typeof(RectTransform) });
			val.SetParent(parentTransform);
			val.RectTransform().SetAnchorMin(Vector2.up).SetAnchorMax(Vector2.up)
				.SetPivot(Vector2.up);
			val.AddComponent<VerticalLayoutGroup>().SetChildControl(true, true).SetChildForceExpand(false, false)
				.SetSpacing(0f);
			val.AddComponent<Image>().SetColor(Color.clear).SetRaycastTarget(raycastTarget: true);
			return val;
		}

		private ScrollRect CreateChildScrollRect(GameObject panel, GameObject viewport, GameObject content)
		{
			return panel.AddComponent<ScrollRect>().SetViewport(viewport.RectTransform()).SetContent(content.RectTransform())
				.SetHorizontal(horizontal: false)
				.SetVertical(vertical: true)
				.SetScrollSensitivity(30f);
		}

		private GameObject CreateChildPanelDragger(GameObject panel)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("ppl.Dragger", new Type[1] { typeof(RectTransform) });
			val.SetParent(panel.transform);
			val.AddComponent<LayoutElement>().SetIgnoreLayout(ignoreLayout: true);
			val.RectTransform().SetAnchorMin(Vector2.zero).SetAnchorMax(Vector2.one)
				.SetPivot(new Vector2(0.5f, 0.5f))
				.SetSizeDelta(Vector2.zero);
			val.AddComponent<Image>().SetColor(Color.clear);
			return val;
		}

		private GameObject CreateChildPanelResizer(GameObject panel)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("ppl.Resizer", new Type[1] { typeof(RectTransform) });
			val.SetParent(panel.transform);
			val.AddComponent<LayoutElement>().SetIgnoreLayout(ignoreLayout: true);
			val.RectTransform().SetAnchorMin(Vector2.right).SetAnchorMax(Vector2.right)
				.SetPivot(Vector2.right)
				.SetSizeDelta(new Vector2(40f, 40f))
				.SetPosition(new Vector2(15f, -15f));
			val.AddComponent<Image>().SetType((Type)1).SetSprite(UIBuilder.CreateRoundedCornerSprite(128, 128, 12, (FilterMode)1))
				.SetColor(new Color(0.565f, 0.792f, 0.976f, 0.849f));
			val.AddComponent<Shadow>().SetEffectDistance(new Vector2(2f, -2f));
			val.AddComponent<CanvasGroup>().SetAlpha(0f);
			TMP_Text val2 = (TMP_Text)(object)UIBuilder.CreateTMPLabel(val.transform);
			val2.SetName<TMP_Text>("Resizer.Icon");
			((Component)val2).gameObject.AddComponent<LayoutElement>().SetIgnoreLayout(ignoreLayout: true);
			((Component)val2).gameObject.RectTransform().SetAnchorMin(Vector2.zero).SetAnchorMax(Vector2.one)
				.SetPivot(new Vector2(0.5f, 0.5f))
				.SetSizeDelta(Vector2.zero);
			val2.alignment = (TextAlignmentOptions)514;
			val2.fontSize = 24f;
			val2.text = "⇆⇅";
			return val;
		}
	}
}
namespace Pintervention.Patches
{
	[HarmonyPatch(typeof(MapTable))]
	internal static class MapTablePatch
	{
		private static readonly string _nameHashBase = "pintervention.pid_name";

		private static readonly char _seperator = '_';

		[HarmonyPrefix]
		[HarmonyPatch("OnRead", new Type[]
		{
			typeof(Switch),
			typeof(Humanoid),
			typeof(ItemData)
		})]
		private static bool OnReadPostfix(MapTable __instance, ItemData item, ref bool __result)
		{
			if (!PluginConfig.IsModEnabled.Value || !Object.op_Implicit((Object)(object)__instance) || !Object.op_Implicit((Object)(object)__instance.m_nview) || !__instance.m_nview.IsValid() || item != null)
			{
				return true;
			}
			LoadPlayerNames(__instance.m_nview.GetZDO());
			if (PluginConfig.ReadRevealedMapOnInteract.Value && PluginConfig.ReadPinsOnInteract.Value)
			{
				return true;
			}
			SharedMapDataManager.ReadMapData(__instance.m_nview.GetZDO());
			__result = false;
			return false;
		}

		[HarmonyPostfix]
		[HarmonyPatch("OnRead", new Type[]
		{
			typeof(Switch),
			typeof(Humanoid),
			typeof(ItemData)
		})]
		private static void OnReadPostfix(MapTable __instance, ItemData item)
		{
			if (PluginConfig.ReadPinsOnInteract.Value)
			{
				PinOwnerManager.FindPinOwners();
				NameManager.WriteNamesToFile();
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("OnWrite")]
		private static void OnWritePrefix(MapTable __instance)
		{
			if (PluginConfig.IsModEnabled.Value && Object.op_Implicit((Object)(object)__instance) && Object.op_Implicit((Object)(object)__instance.m_nview) && __instance.m_nview.IsValid() && Object.op_Implicit((Object)(object)Player.m_localPlayer) && ClaimOwnership(__instance) && __instance.m_nview.IsOwner())
			{
				AddNamesToTable(__instance);
				SendTableZdoUpdate(__instance);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("GetReadHoverText")]
		private static void GetReadHoverTextPostfix(MapTable __instance, ref string __result)
		{
			__result = Localization.instance.Localize(__instance.m_name + "\n[<color=yellow><b>$KEY_Use</b></color>]") + " Interact\n[" + GetBoolUnicodeCharacter(PluginConfig.ReadPinsOnInteract.Value) + "] Read pins\n[" + GetBoolUnicodeCharacter(PluginConfig.ReadRevealedMapOnInteract.Value) + "] Read revealed map";
		}

		private static string GetBoolUnicodeCharacter(bool enabled)
		{
			if (enabled)
			{
				return "<color=green><b>✓</b></color>";
			}
			return "<color=red><b>X</b></color>";
		}

		private static void SendTableZdoUpdate(MapTable __instance)
		{
			//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_0064: Unknown result type (might be due to invalid IL or missing references)
			ZDOID uid = __instance.m_nview.GetZDO().m_uid;
			List<ZNetPeer> list = ZNet.instance.m_peers.Where((ZNetPeer x) => Player.s_players.Select((Player x) => ((Character)x).m_nview.GetZDO().m_uid).Contains(x.m_characterID)).ToList();
			foreach (ZNetPeer item in list)
			{
				ZDOMan.instance.ForceSendZDO(item.m_uid, uid);
			}
		}

		private static bool ClaimOwnership(MapTable table)
		{
			if (!Object.op_Implicit((Object)(object)table) || !Object.op_Implicit((Object)(object)table.m_nview) || !table.m_nview.IsValid())
			{
				return false;
			}
			Pintervention.Log("Claimed table ownership to write name data.");
			table.m_nview.ClaimOwnership();
			return true;
		}

		private static void LoadPlayerNames(ZDO zdo)
		{
			string text = "not empty";
			int num = 0;
			while (text != string.Empty)
			{
				text = zdo.GetString(GetNumberedHashCode(num), string.Empty);
				if (!(text == string.Empty))
				{
					num++;
					KeyValuePair<long, string> keyValuePair = ParsePidNamePair(text);
					if (keyValuePair.Equals(default(KeyValuePair<long, string>)))
					{
						Pintervention.LogWarning($"Unable to parse name at index {num} with value {text}.");
					}
					else
					{
						NameManager.AddPlayerName(keyValuePair.Key, keyValuePair.Value);
					}
				}
			}
		}

		private static KeyValuePair<long, string> ParsePidNamePair(string storedValue)
		{
			string[] array = storedValue.Split(new char[1] { _seperator });
			if (array.Length != 2 || !long.TryParse(array[0], out var result))
			{
				return default(KeyValuePair<long, string>);
			}
			return new KeyValuePair<long, string>(result, array[1]);
		}

		private static bool IsNameOnTable(MapTable table, long pid, string name)
		{
			ZDO zDO = table.m_nview.GetZDO();
			string storedValue = GetStoredValue(pid, name);
			int num = 0;
			string text = "not empty";
			while (text != string.Empty)
			{
				text = zDO.GetString(GetNumberedHashCode(num), string.Empty);
				if (text == storedValue)
				{
					return true;
				}
				num++;
			}
			Pintervention.Log("Name " + Player.m_localPlayer.GetPlayerName() + " not found on map table.");
			return false;
		}

		private static void AddNamesToTable(MapTable table)
		{
			Dictionary<long, string> playerNamesById = NameManager.PlayerNamesById;
			if (!playerNamesById.ContainsKey(Player.m_localPlayer.GetPlayerID()))
			{
				playerNamesById.Add(Player.m_localPlayer.GetPlayerID(), Player.m_localPlayer.GetPlayerName());
			}
			foreach (KeyValuePair<long, string> item in NameManager.PlayerNamesById)
			{
				if (!IsNameOnTable(table, item.Key, item.Value) && !item.Value.StartsWith("Unknown"))
				{
					table.m_nview.GetZDO().Set(GetNextEmptyHashCode(table.m_nview.GetZDO()), GetStoredValue(item.Key, item.Value));
				}
			}
		}

		private static string GetStoredValue(long pid, string name)
		{
			return $"{pid}{_seperator}{name}";
		}

		private static int GetNextEmptyHashCode(ZDO zdo)
		{
			int num = 0;
			string text = "not empty";
			while (text != string.Empty)
			{
				text = zdo.GetString(GetNumberedHashCode(num), string.Empty);
				if (!(text == string.Empty))
				{
					num++;
				}
			}
			return GetNumberedHashCode(num);
		}

		private static int GetNumberedHashCode(int i)
		{
			return StringExtensionMethods.GetStableHashCode($"{_nameHashBase}{i}");
		}
	}
}
namespace Pintervention.Extensions
{
	public static class PinDataExtensions
	{
		public static PinData SetType(this PinData pin, PinType pinType)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			pin.m_type = pinType;
			return pin;
		}

		public static PinData SetName(this PinData pin, string name)
		{
			pin.m_name = name;
			return pin;
		}

		public static PinData SetPosition(this PinData pin, Vector3 position)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			pin.m_pos = position;
			return pin;
		}

		public static PinData SetSave(this PinData pin, bool save)
		{
			pin.m_save = save;
			return pin;
		}

		public static PinData SetChecked(this PinData pin, bool isChecked)
		{
			pin.m_checked = isChecked;
			return pin;
		}

		public static PinData SetOwnerID(this PinData pin, long ownerID)
		{
			pin.m_ownerID = ownerID;
			return pin;
		}

		public static PinData SetAuthor(this PinData pin, string author)
		{
			pin.m_author = author;
			return pin;
		}

		public static PinData SetIcon(this PinData pin, Sprite icon)
		{
			pin.m_icon = icon;
			return pin;
		}
	}
}
namespace Pintervention.Core
{
	public class SharedMapDataManager
	{
		public static void ReadMapData(ZDO zdo)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			byte[] byteArray = zdo.GetByteArray(ZDOVars.s_data, (byte[])null);
			if (byteArray == null)
			{
				Pintervention.LogWarning("No data found in zdo data field.");
				return;
			}
			if (!PluginConfig.ReadRevealedMapOnInteract.Value && !PluginConfig.ReadPinsOnInteract.Value)
			{
				Pintervention.MessageLocalPlayer("All cartography table data disabled on read.");
				return;
			}
			byte[] array = Utils.Decompress(byteArray);
			ZPackage val = new ZPackage(array);
			int version = val.ReadInt();
			if (PluginConfig.ReadPinsOnInteract.Value)
			{
				WritePinsToMap(val, version);
				Pintervention.MessageLocalPlayer("Added pins from cartography table to map.");
			}
			else if (PluginConfig.ReadRevealedMapOnInteract.Value)
			{
				WriteExploredAreaToMap(val, version);
				Pintervention.MessageLocalPlayer("Added revealed area from cartography table to map.");
			}
		}

		public static void WritePinsToMap(ZPackage zPackage, int version)
		{
			if (Minimap.instance.ReadExploredArray(zPackage, version) == null)
			{
				Pintervention.LogWarning("Failed to read explored map from ZPackage.");
				return;
			}
			List<PinData> list = ReadImportedPins(zPackage, version);
			if (!list.Any())
			{
				Pintervention.MessageLocalPlayer("No new pins found to copy to player map.");
			}
			else
			{
				Minimap.instance.m_pins.AddRange(list);
			}
		}

		public static List<PinData> ReadImportedPins(ZPackage zPackage, int version)
		{
			List<PinData> list = new List<PinData>();
			if (version < 2)
			{
				return list;
			}
			int num = zPackage.ReadInt();
			for (int i = 0; i < num; i++)
			{
				PinData val = ReadPin(zPackage, version);
				if (val != null)
				{
					list.Add(val);
				}
			}
			return list;
		}

		private static PinData ReadPin(ZPackage zPackage, int version)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_0065: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected O, but got Unknown
			long ownerID = zPackage.ReadLong();
			string name = zPackage.ReadString();
			Vector3 val = zPackage.ReadVector3();
			PinType val2 = (PinType)zPackage.ReadInt();
			bool isChecked = zPackage.ReadBool();
			string author = ((version >= 3) ? zPackage.ReadString() : "");
			if (Minimap.instance.HavePinInRange(val, 1f))
			{
				return null;
			}
			PinData val3 = PinDataExtensions.SetOwnerID(new PinData(), ownerID).SetName(name).SetPosition(val)
				.SetType(val2)
				.SetChecked(isChecked)
				.SetAuthor(author)
				.SetIcon(Minimap.instance.GetSprite(val2));
			if (!string.IsNullOrEmpty(val3.m_name))
			{
				val3.m_NamePinData = new PinNameData(val3);
			}
			return val3;
		}

		public static bool WriteExploredAreaToMap(ZPackage zPackage, int version)
		{
			List<bool> list = Minimap.instance.ReadExploredArray(zPackage, version);
			if (list == null)
			{
				return false;
			}
			bool flag = false;
			for (int i = 0; i < Minimap.instance.m_textureSize; i++)
			{
				for (int j = 0; j < Minimap.instance.m_textureSize; j++)
				{
					int num = i * Minimap.instance.m_textureSize + j;
					if (list[num] && (Minimap.instance.m_exploredOthers[num] || Minimap.instance.m_explored[num]) != list[num] && Minimap.instance.ExploreOthers(j, i))
					{
						flag = true;
					}
				}
			}
			if (!flag)
			{
				return false;
			}
			Minimap.instance.m_fogTexture.Apply();
			return true;
		}
	}
}