Decompiled source of ZenMap v0.4.4

plugins\ZenMap.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using JetBrains.Annotations;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using Splatform;
using UnityEngine;
using UnityEngine.UI;
using Zen.Config;
using Zen.Lib;
using Zen.Logging;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ZenMap")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ZenMap")]
[assembly: AssemblyCopyright("Copyright \ufffd  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ZenMap
{
	public static class MapPinItem
	{
		public const string PrefabName = "ZenMapPin";

		private const string DisplayName = "Map Pin";

		private const string Description = "Attach to a sign to create a pin on your map.";

		internal static Action AddCraftingItem()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			Log.Info((object)"Add crafting item: ZenMapPin", (ushort)0);
			ItemConfig val = new ItemConfig();
			val.Name = "Map Pin";
			val.Description = "Attach to a sign to create a pin on your map.";
			val.CraftingStation = Configs.MapPinCraftingStation.Value;
			val.MinStationLevel = Configs.MapPinCraftingStationLevel.Value;
			val.Requirements = Configs.MapPinItemResources.Value.ToRequirementConfigs(':');
			val.Icons = (Sprite[])(object)new Sprite[1] { GUIManager.Instance.GetSprite("mapicon_ping") };
			val.Amount = 1;
			val.Weight = 0.1f;
			val.StackSize = Configs.MapPinStackSize.Value;
			CustomItem mapPinItem = new CustomItem("ZenMapPin", "Wisp", val);
			SharedData shared = mapPinItem.ItemDrop.m_itemData.m_shared;
			shared.m_value = 0;
			shared.m_itemType = (ItemType)16;
			ItemManager.Instance.AddItem(mapPinItem);
			return ConfigSync;
			void ConfigSync()
			{
				Recipe recipe = mapPinItem.Recipe.Recipe;
				recipe.m_craftingStation = PrefabManagerExt.GetCraftingStation(PrefabManager.Instance, Configs.MapPinCraftingStation.Value);
				recipe.m_minStationLevel = Configs.MapPinCraftingStationLevel.Value;
				recipe.m_resources = Configs.MapPinItemResources.Value.ToRequirements(':');
				recipe.m_item.m_itemData.m_shared.m_maxStackSize = Configs.MapPinStackSize.Value;
			}
		}

		internal static bool HaveInInventory()
		{
			if (Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				return ((Humanoid)Player.m_localPlayer).GetInventory().ContainsItemByName("Map Pin");
			}
			return false;
		}
	}
	[HarmonyPatch]
	public static class DeathPin
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(Minimap), "AddPin")]
		private static void Minimap_AddPin(PinType type, string name, ref bool __runOriginal)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			if ((int)type == 4 && name.StartsWith("$hud_mapday"))
			{
				__runOriginal = false;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Minimap), "LoadMapData")]
		private static void Minimap_LoadMapData(Minimap __instance)
		{
			RemoveAllDeathPins(__instance);
		}

		private static void RemoveAllDeathPins(Minimap map)
		{
			PinData[] array = map.m_pins.Where((PinData pin) => (int)pin.m_type == 4).ToArray();
			foreach (PinData item in array)
			{
				map.m_pins.Remove(item);
			}
		}
	}
	internal static class MapFogCache
	{
		private static Texture2D? _fogCopy;

		private static readonly Color32[] AllFog;

		static MapFogCache()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			int textureSize = Minimap.instance.m_textureSize;
			AllFog = (Color32[])(object)new Color32[textureSize * textureSize];
			for (int i = 0; i < AllFog.Length; i++)
			{
				AllFog[i] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
			}
		}

		public static void Reset()
		{
			Minimap instance = Minimap.instance;
			instance.m_fogTexture.SetPixels32(AllFog);
			instance.m_fogTexture.Apply();
		}

		public static void Save()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)_fogCopy))
			{
				Texture2D fogTexture = Minimap.instance.m_fogTexture;
				_fogCopy = new Texture2D(((Texture)fogTexture).width, ((Texture)fogTexture).height, fogTexture.format, ((Texture)fogTexture).mipmapCount, false, true);
				Graphics.CopyTexture((Texture)(object)fogTexture, (Texture)(object)_fogCopy);
			}
		}

		public static void Restore()
		{
			if (Object.op_Implicit((Object)(object)_fogCopy))
			{
				Graphics.CopyTexture((Texture)(object)_fogCopy, (Texture)(object)Minimap.instance.m_fogTexture);
				_fogCopy = null;
			}
		}
	}
	internal static class MapPinType
	{
		private const int ReservedTypes = 32;

		private const int CustomRangeStart = 256;

		internal const int CustomRangeEnd = 288;

		public const PinType Raft = 256;

		public const PinType Karve = 257;

		public const PinType VikingShip = 258;

		public const PinType VikingShipAshlands = 259;

		public const PinType Cart = 260;

		public const PinType Catapult = 261;

		public const PinType BatteringRam = 262;

		public const PinType Cave = 263;

		public const PinType None = 8;

		public const PinType Campfire = 0;

		public const PinType House = 1;

		public const PinType Hammer = 2;

		public const PinType Dot = 3;

		public const PinType Portal = 6;
	}
	[HarmonyPatch]
	public static class MapPinIcon
	{
		private static readonly Dictionary<string, PinType> NamedPinTypes;

		private static readonly Dictionary<PinType, string> PinTypeToResource;

		private static readonly Dictionary<string, Sprite> SpriteCache;

		static MapPinIcon()
		{
			NamedPinTypes = new Dictionary<string, PinType>
			{
				["Raft"] = (PinType)256,
				["Karve"] = (PinType)257,
				["VikingShip"] = (PinType)258,
				["VikingShip_Ashlands"] = (PinType)259,
				["Cart"] = (PinType)260,
				["Catapult"] = (PinType)261,
				["BatteringRam"] = (PinType)262,
				["Player_tombstone"] = (PinType)4,
				["bonfire"] = (PinType)0,
				["piece_cartographytable"] = (PinType)1,
				["portal_wood"] = (PinType)6,
				["portal_stone"] = (PinType)6
			};
			PinTypeToResource = new Dictionary<PinType, string>
			{
				[(PinType)256] = "5_raft.png",
				[(PinType)257] = "4_karve.png",
				[(PinType)258] = "3_longboat.png",
				[(PinType)259] = "2_drakkar.png",
				[(PinType)260] = "35_cart.png",
				[(PinType)261] = "35_cart.png",
				[(PinType)262] = "35_cart.png",
				[(PinType)263] = "44_cave.png"
			};
			SpriteCache = new Dictionary<string, Sprite>();
			SpriteCache.Clear();
			foreach (string item in PinTypeToResource.Values.Distinct())
			{
				SpriteCache.Add(item, LoadSprite(item));
			}
		}

		private static Sprite LoadSprite(string name)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			if (name.StartsWith("#"))
			{
				PinType val = (PinType)int.Parse(name.Substring(1));
				return Minimap.instance.GetSprite(val);
			}
			if (name.StartsWith("$"))
			{
				string text = name.Substring(1);
				GameObject prefab = ZNetScene.instance.GetPrefab(text);
				if (Object.op_Implicit((Object)(object)prefab))
				{
					return prefab.GetComponent<Piece>().m_icon;
				}
				prefab = ObjectDB.instance.GetItemPrefab(text);
				if (Object.op_Implicit((Object)(object)prefab))
				{
					return ItemDataExt.GetIcon(prefab.GetComponent<ItemDrop>());
				}
				throw new NullReferenceException("Prefab not found: " + name);
			}
			return AssetIO.LoadSprite("MapPins." + name, (Assembly)null);
		}

		private static PinType GetPinType(string name)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			if (!NamedPinTypes.TryGetValue(name, out var value))
			{
				return (PinType)3;
			}
			return value;
		}

		internal static PinType GetPinType(this ZDO zdo)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return GetPinType(ZdoExt.GetPrefabName(zdo));
		}

		private static Sprite? GetCustomIcon(PinType pinType)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			if (!PinTypeToResource.TryGetValue(pinType, out string value))
			{
				return null;
			}
			return SpriteCache[value];
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Minimap), "GetSprite")]
		private static void Minimap_GetSprite(PinType type, ref Sprite? __result, ref bool __runOriginal)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			Sprite customIcon = GetCustomIcon(type);
			if (Object.op_Implicit((Object)(object)customIcon))
			{
				__result = customIcon;
				__runOriginal = false;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Minimap), "Start")]
		private static void Minimap_Start(Minimap __instance)
		{
			Minimap.instance.m_visibleIconTypes = Enumerable.Repeat(element: true, 288).ToArray();
		}
	}
	[HarmonyPatch]
	public static class MapTrack
	{
		[HarmonyPatch(typeof(ZDOMan), "RPC_ZDOData")]
		private static class ZDOMan_RPC_ZDOData
		{
			private static bool _isFromRPC;

			[UsedImplicitly]
			private static void Prefix()
			{
				_isFromRPC = true;
			}

			[UsedImplicitly]
			private static void Postfix()
			{
				_isFromRPC = false;
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(ZDO), "Deserialize")]
			private static void ZDO_Deserialize(ZDO __instance)
			{
				if (_isFromRPC)
				{
					IndexAndPin(__instance);
				}
				else
				{
					Log.Info((object)"ZDO.Deserialize called outside of RPC_ZDOData", (ushort)0);
				}
			}
		}

		private static readonly HashSet<int> AutopinPrefabs = new string[10] { "Raft", "Karve", "VikingShip", "VikingShip_Ashlands", "Cart", "Catapult", "BatteringRam", "Player_tombstone", "piece_cartographytable", "bonfire" }.Select((string name) => StringExtensionMethods.GetStableHashCode(name)).ToHashSet();

		private const string GuidPrefix = "GUID|";

		private static readonly int ZDOVarGUID = StringExtensionMethods.GetStableHashCode("GUID|");

		private static readonly Dictionary<Guid, ZDOID> GuidIndexZDOID = new Dictionary<Guid, ZDOID>();

		private static readonly Dictionary<Guid, PinData> GuidIndexPin = new Dictionary<Guid, PinData>();

		private static readonly Dictionary<PinData, Guid> PinToGuidCache = new Dictionary<PinData, Guid>();

		private static bool _isIndexReady;

		private const string DataDelimiter = "\0#";

		private static readonly int DataSize;

		internal static void Init()
		{
			_isIndexReady = false;
			Log.Info((object)"Waiting before rebuilding index...", (ushort)0);
			Timing.Delay(3f, (Action)delegate
			{
				RebuildIndex();
				SetupAutopins();
				_isIndexReady = true;
			});
		}

		internal static void Shutdown()
		{
			_isIndexReady = false;
		}

		private static void SetupAutopins()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			Log.Debug((object)"Refreshing Autopins", (ushort)0);
			ZDOID[] array = GuidIndexZDOID.Values.ToArray();
			foreach (ZDOID val in array)
			{
				ZDO zDO = ZDOMan.instance.GetZDO(val);
				if (zDO == null)
				{
					Log.Warning((object)$"ZDO is null for ZDOID: {val} - skipping.", (ushort)0);
				}
				else
				{
					AutopinIfReq(zDO);
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Minimap), "UpdateDynamicPins")]
		private static void Minimap_UpdateDynamicPins(float dt)
		{
			if (_isIndexReady)
			{
				UpdatePins(dt);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Minimap), "AddPin")]
		private static void Minimap_AddPin(PinData? __result)
		{
			if (__result != null)
			{
				UpdateIndex(__result);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Minimap), "RemovePin", new Type[] { typeof(PinData) })]
		private static void Minimap_RemovePin(PinData? pin)
		{
			if (pin != null)
			{
				GuidIndexPin.Remove(pin.GetGuid());
				PinToGuidCache.Remove(pin);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(ZDOMan), "CreateSyncList")]
		private static void ZDOMan_CreateSyncList(ZDOMan __instance)
		{
			if (ZNet.instance.IsServer())
			{
				CollectionExtensions.Do<ZDOID>((IEnumerable<ZDOID>)GuidIndexZDOID.Values, (Action<ZDOID>)__instance.ForceSendZDO);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(ZDOMan), "HandleDestroyedZDO")]
		private static void ZDOMan_HandleDestroyedZDO(ZDOID uid)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			if (Game.instance.IsShuttingDown())
			{
				return;
			}
			Guid guid = ZDOMan.instance.GetZDO(uid).GetGuid();
			if (guid != Guid.Empty)
			{
				Log.Info((object)$"Remove Guid: {guid} for ZDOID: {uid}", (ushort)0);
				GuidIndexZDOID.Remove(guid);
			}
			if (Object.op_Implicit((Object)(object)Minimap.instance))
			{
				PinData val = FindPin(guid);
				if (val != null)
				{
					RemovePin(val);
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ZDOMan), "FilterZDO")]
		private static void ZDOMan_FilterZDO(ZDO? zdo)
		{
			if (zdo != null)
			{
				UpdateIndex(zdo);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ZDOMan), "GetZDO")]
		private static void ZDOMan_GetZDO(ZDO? __result)
		{
			if (__result != null)
			{
				UpdateIndex(__result);
			}
		}

		private static void IndexAndPin(ZDO zdo)
		{
			UpdateIndex(zdo);
			AutopinIfReq(zdo);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ZNetView), "Awake")]
		private static void ZNetView_Awake(ZNetView __instance)
		{
			if (__instance.IsValid())
			{
				AutopinIfReq(__instance.GetZDO());
			}
		}

		private static bool IsAutopinPrefab(ZDO zdo)
		{
			return AutopinPrefabs.Contains(zdo.GetPrefab());
		}

		private static void AutopinIfReq(ZDO zdo)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if (IsAutopinPrefab(zdo) && zdo.FindPin() == null)
			{
				Log.Info((object)$"Adding autopin for ZDO: {ZdoExt.GetPrefabName(zdo)} {zdo.m_uid}", (ushort)0);
				AddPin(zdo, save: false, (PinType)8);
			}
		}

		private static void RebuildIndex()
		{
			Log.Info((object)"Rebuilding Guid to ZDO index", (ushort)0);
			GuidIndexZDOID.Clear();
			foreach (ZDO value in ZDOMan.instance.m_objectsByID.Values)
			{
				UpdateIndex(value);
				if (ZNet.instance.IsServer() && IsAutopinPrefab(value))
				{
					TrackZDO(value);
				}
			}
			Log.Info((object)"Rebuilding Guid to PinData index", (ushort)0);
			GuidIndexPin.Clear();
			PinToGuidCache.Clear();
			foreach (PinData pin in Minimap.instance.m_pins)
			{
				UpdateIndex(pin);
			}
		}

		private static Guid UpdateIndex(PinData pin)
		{
			Guid guid = pin.GetGuid();
			if (guid != Guid.Empty)
			{
				GuidIndexPin[guid] = pin;
			}
			return guid;
		}

		private static Guid UpdateIndex(ZDO zdo)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			Guid guid = zdo.GetGuid();
			if (guid != Guid.Empty)
			{
				GuidIndexZDOID[guid] = zdo.m_uid;
			}
			return guid;
		}

		private static ZDOID LookupZDOID(Guid guid)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			if (guid == Guid.Empty)
			{
				return ZDOID.None;
			}
			if (!GuidIndexZDOID.TryGetValue(guid, out var value))
			{
				return ZDOID.None;
			}
			return value;
		}

		private static Guid GetGuid(this ZDO? zdo)
		{
			byte[] array = ((zdo != null) ? zdo.GetByteArray(ZDOVarGUID, (byte[])null) : null);
			if (array == null || array.Length != 16)
			{
				return Guid.Empty;
			}
			return new Guid(array);
		}

		private static string CreateTrackingLabel(string label, Guid guid)
		{
			if (label.Contains("\0#"))
			{
				throw new ArgumentException("label already contains guid, double guid encoding is not safe");
			}
			return label + "\0#" + guid.ToString("N");
		}

		private static Guid GetGuid(this PinData pin)
		{
			if (PinToGuidCache.TryGetValue(pin, out var value))
			{
				return value;
			}
			if (Utility.IsNullOrWhiteSpace(pin.m_name) || pin.m_name.Length < DataSize + "\0#".Length)
			{
				return Guid.Empty;
			}
			int num = pin.m_name.IndexOf("\0#"[0]);
			if (num < 0 || num >= pin.m_name.Length - 1 || pin.m_name[num + 1] != "\0#"[1])
			{
				return Guid.Empty;
			}
			value = Guid.ParseExact(pin.m_name.Substring(num + "\0#".Length, DataSize), "N");
			Log.Info((object)$"Caching Pin: {value}", (ushort)0);
			PinToGuidCache.Add(pin, value);
			return value;
		}

		private static string GetLabel(this PinData pin)
		{
			int num = pin.m_name.IndexOf("\0#"[0]);
			if (num >= 0)
			{
				return pin.m_name.Substring(0, num + 1);
			}
			return pin.m_name;
		}

		internal static PinData? FindPin(this ZDO zdo)
		{
			return FindPin(zdo.GetGuid());
		}

		private static PinData? FindPin(Guid guid)
		{
			if (!GuidIndexPin.TryGetValue(guid, out PinData value))
			{
				return null;
			}
			return value;
		}

		internal static void RemovePin(PinData pin)
		{
			//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)
			Log.Info((object)$"Remove: {pin.m_name} {MathExt.XZY(pin.m_pos)}", (ushort)0);
			Minimap.instance.RemovePin(pin);
		}

		private static Guid TrackZDO(ZDO zdo)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			Guid guid = zdo.GetGuid();
			if (guid != Guid.Empty)
			{
				return guid;
			}
			ZNetView val = ZNetScene.instance.FindInstance(zdo);
			if (Object.op_Implicit((Object)(object)val))
			{
				val.ClaimOwnership();
			}
			guid = Guid.NewGuid();
			Log.Info((object)$"Create new Guid: {guid} for zdo {zdo.m_uid}", (ushort)0);
			zdo.Set(ZDOVarGUID, guid.ToByteArray());
			UpdateIndex(zdo);
			return guid;
		}

		private static bool TryGetZDO(this PinData pin, out ZDO zdo)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			ZDOID val = LookupZDOID(pin.GetGuid());
			zdo = ZDOMan.instance.GetZDO(val);
			return zdo != null;
		}

		private static bool IsSharedPin(PinData pin)
		{
			if (pin.m_ownerID != Player.m_localPlayer.GetPlayerID())
			{
				return pin.m_ownerID != 0;
			}
			return false;
		}

		private static void UpdatePins(float dt)
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Invalid comparison between Unknown and I4
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Invalid comparison between Unknown and I4
			if (Game.instance.IsShuttingDown())
			{
				return;
			}
			List<PinData> pins = Minimap.instance.m_pins;
			Ship val = (Configs.HideActiveShipPin.Value ? Player.m_localPlayer.GetControlledShip() : null);
			for (int num = pins.Count - 1; num >= 0; num--)
			{
				PinData val2 = pins[num];
				ZDO zdo;
				if (IsSharedPin(val2))
				{
					Log.Info((object)"Shared pin found, ignoring", (ushort)0);
				}
				else if (!val2.TryGetZDO(out zdo))
				{
					if (val2.GetGuid() != Guid.Empty)
					{
						RemovePin(val2);
					}
				}
				else
				{
					Vector3 position = zdo.GetPosition();
					val2.m_pos = Vector3.MoveTowards(val2.m_pos, position, 200f * dt);
					if (!MathExt.Approximately(val2.m_pos, position))
					{
						Minimap.instance.m_pinUpdateRequired = true;
					}
					MapMode mode = Minimap.instance.m_mode;
					if ((int)mode > 1)
					{
						if ((int)mode != 2)
						{
							throw new ArgumentOutOfRangeException();
						}
						val2.SetLabel(zdo.GetLabel());
					}
					else if (Configs.HideActiveShipPin.Value && Object.op_Implicit((Object)(object)val2.m_uiElement))
					{
						((Component)val2.m_uiElement).gameObject.SetActive((Object.op_Implicit((Object)(object)val) ? val.m_nview.GetZDO() : null) != zdo);
					}
				}
			}
		}

		internal static void AddPin(ZDO zdo, bool save, PinType type = 8)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Invalid comparison between Unknown and I4
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			if (zdo == null)
			{
				throw new NullReferenceException("ZDO can not be null");
			}
			PinData val = zdo.FindPin();
			if (val != null)
			{
				Log.Debug((object)$"Pin already exists: {val.GetGuid()} {val.m_name} {val.m_pos}", (ushort)0);
				return;
			}
			string label = zdo.GetLabel();
			Vector3 position = zdo.GetPosition();
			Guid guid = TrackZDO(zdo);
			string text = CreateTrackingLabel(label, guid);
			Log.Info((object)("Tracking Label: " + text), (ushort)0);
			if ((int)type == 8)
			{
				type = zdo.GetPinType();
			}
			Minimap.instance.AddPin(position, type, text, save, false, 0L, default(PlatformUserID));
			Log.Info((object)$"Add: {guid} {ZdoExt.GetPrefabName(zdo)} ({MathExt.XZY(position)}) ", (ushort)0);
		}

		private static void SetLabel(this PinData pin, string label)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			if (!Utility.IsNullOrWhiteSpace(label))
			{
				pin.m_name = CreateTrackingLabel(label, pin.GetGuid());
				if (pin.m_NamePinData == null)
				{
					pin.m_NamePinData = new PinNameData(pin);
				}
				if (Object.op_Implicit((Object)(object)pin.m_NamePinData.PinNameText))
				{
					pin.m_NamePinData.PinNameText.text = pin.GetLabel();
				}
			}
		}

		private static string GetLabel(this ZDO zdo)
		{
			GameObject prefab = ZNetScene.instance.GetPrefab(zdo.GetPrefab());
			Sign val = default(Sign);
			string text = default(string);
			if (prefab.TryGetComponent<Sign>(ref val) && zdo.GetString(ZDOVars.s_text, ref text))
			{
				if (!(text != val.m_defaultText))
				{
					return string.Empty;
				}
				return text;
			}
			TombStone val2 = default(TombStone);
			if (prefab.TryGetComponent<TombStone>(ref val2))
			{
				return zdo.GetString(ZDOVars.s_ownerName, "");
			}
			string text2 = string.Empty;
			Piece val3 = default(Piece);
			Hoverable val4 = default(Hoverable);
			if (prefab.TryGetComponent<Piece>(ref val3))
			{
				text2 = val3.m_name;
			}
			else if (prefab.TryGetComponent<Hoverable>(ref val4))
			{
				text2 = val4.GetHoverName();
			}
			return Localization.instance.Localize(text2);
		}

		static MapTrack()
		{
			Guid empty = Guid.Empty;
			DataSize = empty.ToString("N").Length;
		}
	}
	[BepInPlugin("ZenDragon.ZenMap", "ZenMap", "0.4.4")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	internal class Plugin : ZenMod<Plugin>
	{
		public const string PluginName = "ZenMap";

		public const string PluginVersion = "0.4.4";

		public const string PluginGUID = "ZenDragon.ZenMap";

		protected override void Setup()
		{
			((ZenMod)this).RunOnServer = true;
			((ZenMod)this).RegisterCraftingItems += MapPinItem.AddCraftingItem;
		}

		protected override void TitleScene(bool isFirstBoot)
		{
		}

		protected override void WorldStart()
		{
			Configs.SetNoMap();
			MapTrack.Init();
			((MonoBehaviour)this).InvokeRepeating("CheckNoMapMode", 1f, 1f);
		}

		protected override void Shutdown()
		{
			MapTrack.Shutdown();
		}

		private void CheckNoMapMode()
		{
			if (Configs.MapEnabledInGodMode.Value && Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				Game.m_noMap = ZoneSystem.instance.GetGlobalKey("nomap");
				if (((Character)Player.m_localPlayer).InGodMode())
				{
					Game.m_noMap = false;
				}
			}
		}
	}
	[HarmonyPatch]
	public static class Configs
	{
		public static readonly ConfigEntry<bool> MapEnabledInGodMode;

		public static readonly ConfigEntry<int> MapTableDaysUntilFull;

		public static readonly ConfigEntry<float> MapTableFullRadius;

		public static readonly ConfigEntry<KeyCode> MapTableAdminAccelerateAgeKey;

		public static readonly ConfigEntry<bool> HideActiveShipPin;

		public static readonly ConfigEntry<bool> AlwaysShowPlayers;

		public static readonly ConfigEntry<bool> HidePlayerArrow;

		public static readonly ConfigEntry<bool> AutosetNoMap;

		public static readonly ConfigEntry<bool> HideMapPingInWorld;

		public static readonly ConfigEntry<string> MapPinCraftingStation;

		public static readonly ConfigEntry<int> MapPinCraftingStationLevel;

		public static readonly ConfigEntry<StringList> MapPinItemResources;

		public static readonly ConfigEntry<int> MapPinStackSize;

		public static readonly ConfigEntry<bool> MapPinRefund;

		public static readonly ConfigEntry<bool> DebugSantizeZDOs;

		static Configs()
		{
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Expected O, but got Unknown
			//IL_018f: Expected O, but got Unknown
			AutosetNoMap = Config.Define<bool>(true, "General", "Autoset World Modifier NoMap", true, "Automatically set the world modifier nomap on startup.");
			HidePlayerArrow = Config.Define<bool>(true, "General", "Hide Player Arrow Icon", true, "Hide the player's arrow icon when looking at the map table.\nThey should use the landscape and compass insted to get their bearings.");
			AlwaysShowPlayers = Config.Define<bool>(true, "General", "Show All Players Unless PVP", true, "Always show players on the map unless PVP is enabled.");
			MapEnabledInGodMode = Config.Define<bool>(true, "General", "Map Enabled In God Mode", true, "Map key always enabled for admin when they are in God mode");
			MapTableDaysUntilFull = Config.Define<int>(true, "General", "Days Until Full Map", 5, "How long must pass for a map table to be fully explored. (game days)");
			MapTableFullRadius = Config.Define<float>(true, "General", "Map Table Fully Explored Radius", 2110f, "How large of an area does the fully explored map reveal");
			MapTableAdminAccelerateAgeKey = Config.Define<KeyCode>(true, "General", "Admin Accelerate Age Key", (KeyCode)304, "Key that admin can hold while interacting with the table to accelerate its age. (God mode must be active)");
			HideActiveShipPin = Config.Define<bool>(true, "General", "Hide Active Ship Pin", true, "Hide the pin of the currently active ship that the player is controlling.");
			HideMapPingInWorld = Config.Define<bool>(true, "General", "Map Ping - Hide In World", true, "When true the map ping can only be seen on the map table, not in the game world as floating text, not on the compass either.\r\nYou can still see each other's pings when both viewing the map table.  Even if you are at different tables.  \r\nThis prevents guiding players via ping spam. You have to talk to each other and plan ahead instead.");
			MapPinCraftingStation = Config.Define<string>(true, "Crafting", "Map Pin Crafting Station", CraftingStations.None, CraftingStations.GetAcceptableValueList(), "Crafting station for the map pin item.");
			MapPinCraftingStationLevel = Config.Define<int>(true, "Crafting", "Map Pin Crafting Station Level", 1, Config.AcceptRange<int>(1, 5), "Minimum level required for the crafting station to craft map pins");
			MapPinStackSize = Config.Define<int>(true, "Crafting", "Map Pin Stack Size", 100, Config.AcceptRange<int>(1, 100), "Max stack size. How many pins can be stored in a single inventory slot.");
			StringList val = new StringList(Array.Empty<IEnumerable<string>>());
			((List<string>)val).Add("BronzeNails:1");
			MapPinItemResources = Config.Define<StringList>(true, "Crafting", "Map Pin Resources", val, "Resource requirements for crafting a Map Pin.\r\nBronze nails is the default because it gives a perioid of early game progression without pins\r\nfor added challenge and reward.");
			MapPinRefund = Config.Define<bool>(true, "Crafting", "Map Pin Refund", true, "Refund the map pin when manually removing it from a sign?");
		}

		internal static void SetNoMap()
		{
			if (ZNet.instance.IsServer() && AutosetNoMap.Value)
			{
				ZoneSystem.instance.SetGlobalKey((GlobalKeys)25);
				Log.Message((object)"World modifier enabled: NoMap", (ushort)0);
			}
		}
	}
	[HarmonyPatch]
	public static class Map
	{
		private class MapLocation
		{
			public readonly Vector3 Position;

			public readonly float Range;

			public readonly float Percent;

			public int DaysLeft => Configs.MapTableDaysUntilFull.Value - Mathf.FloorToInt((float)Configs.MapTableDaysUntilFull.Value * Percent);

			public MapLocation(Vector3 pos, float range)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				Position = pos;
				Range = range;
				Percent = Mathf.Clamp(range / Configs.MapTableFullRadius.Value, 0f, 1f);
				base..ctor();
			}

			public MapLocation(MapTable mapTable)
				: this(((Component)mapTable).transform.position, mapTable.ExploredRadius())
			{
			}//IL_0007: Unknown result type (might be due to invalid IL or missing references)

		}

		private const float MaxMapTableZoom = 0.075f;

		private const float MinMapTableZoom = 0.015f;

		private static MapLocation? _mapLocation;

		private static bool IsUsingMapObject => _mapLocation != null;

		private static float TimeElapsedSeconds(this MapTable table)
		{
			if (!table.m_nview.IsValid())
			{
				Log.Warning((object)"MapTable ZNetView invalid", (ushort)0);
				return 0f;
			}
			return ZdoExt.GetAgeSeconds(table.m_nview.GetZDO());
		}

		private static float ExploredRadius(this MapTable table)
		{
			float num = Mathf.Clamp(table.TimeElapsedSeconds() / (float)EnvMan.instance.m_dayLengthSec / (float)Configs.MapTableDaysUntilFull.Value, 0.05f, 1f);
			return Configs.MapTableFullRadius.Value * num;
		}

		private static void AccelerateAge(this MapTable table, float seconds)
		{
			ZNetView nview = table.m_nview;
			if (!nview.IsOwner())
			{
				nview.ClaimOwnership();
			}
			ZdoExt.AccelerateAge(nview.GetZDO(), seconds);
		}

		private static void ApplyWriteFX(this MapTable table)
		{
			//IL_000e: 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)
			Transform transform = ((Component)table).transform;
			table.m_writeEffects.Create(transform.position, transform.rotation, (Transform)null, 1f, -1);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(ZNet), "SendServerSyncPlayerData")]
		private static void ZNet_SendServerSyncPlayerData(ZNet __instance)
		{
			if (Object.op_Implicit((Object)(object)Player.m_localPlayer) && Configs.AlwaysShowPlayers.Value)
			{
				__instance.m_publicReferencePosition = !((Character)Player.m_localPlayer).IsPVPEnabled();
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Minimap), "UpdateMap")]
		private static void Minimap_UpdateMap(ref bool __runOriginal, float dt)
		{
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			if (IsUsingMapObject)
			{
				__runOriginal = false;
				Minimap instance = Minimap.instance;
				float num = ZInput.GetMouseScrollWheel() * instance.m_largeZoom * 0.03f;
				if (ZInput.GetButton("JoyLTrigger"))
				{
					num -= instance.m_largeZoom * dt * 2f;
				}
				if (ZInput.GetButton("JoyRTrigger"))
				{
					num += instance.m_largeZoom * dt * 2f;
				}
				instance.m_largeZoom = Mathf.Clamp(instance.m_largeZoom - num, 0.015f, 0.075f);
				((Component)instance.m_gamepadCrosshair).gameObject.SetActive(false);
				instance.m_hints[0].SetActive(false);
				instance.UpdatePlayerMarker(Player.m_localPlayer, Quaternion.identity);
				instance.CenterMap(((Component)Player.m_localPlayer).transform.position);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlayerController), "TakeInput")]
		private static void BlockMovementIfMapOpen(ref bool __runOriginal, ref bool __result)
		{
			if (Minimap.IsOpen())
			{
				__result = false;
				__runOriginal = false;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Minimap), "OnMapDblClick")]
		private static void Minimap_OnMapDblClick(ref bool __runOriginal)
		{
			if (IsUsingMapObject)
			{
				__runOriginal = false;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Minimap), "OnMapRightClick")]
		private static void Minimap_OnMapRightClick(ref bool __runOriginal)
		{
			__runOriginal = ZInput.GetKey((KeyCode)306, true);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Minimap), "IsPointVisible")]
		private static void Minimap_IsPointVisible(ref bool __result, Vector3 p)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			if ((int)Minimap.instance.m_mode == 2 && _mapLocation != null)
			{
				float range = _mapLocation.Range;
				if (Vector3.Distance(_mapLocation.Position, p) > range)
				{
					__result = false;
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Minimap), "SetMapMode")]
		private static void Minimap_SetMapMode(Minimap __instance, MapMode mode)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			if ((int)mode != 2)
			{
				MapFogCache.Restore();
				_mapLocation = null;
				return;
			}
			Transform transform = __instance.m_largeRoot.transform;
			((Component)transform.Find("IconPanel")).gameObject.SetActive(!IsUsingMapObject);
			((Component)transform.Find("IconPanel2")).gameObject.SetActive(!IsUsingMapObject);
			((Component)transform.Find("KeyHints")).gameObject.SetActive(!IsUsingMapObject);
			((Component)transform.Find("SharedPanel")).gameObject.SetActive(!IsUsingMapObject);
			((Component)transform.Find("PublicPanel")).gameObject.SetActive(!IsUsingMapObject);
			((Component)__instance.m_pinNameRootLarge).gameObject.SetActive(!IsUsingMapObject);
			((Component)((Component)__instance.m_publicPosition).transform.parent).gameObject.SetActive(!Configs.AlwaysShowPlayers.Value);
			((Behaviour)((Component)__instance.m_largeMarker).GetComponent<Image>()).enabled = !Configs.HidePlayerArrow.Value || !IsUsingMapObject;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Minimap), "IsExplored")]
		public static void Minimap_IsExplored(Vector3 worldPos, ref bool __result)
		{
			//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)
			if (_mapLocation != null && VectorExtensions.DistanceTo(_mapLocation.Position, worldPos) > _mapLocation.Range)
			{
				__result = false;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(MapTable), "Start")]
		private static void MapTable_Start(MapTable __instance)
		{
			if (__instance.m_nview.IsOwner())
			{
				ZdoExt.InitEpoch(__instance.m_nview.GetZDO());
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(MapTable), "GetReadHoverText")]
		public static void MapTable_GetReadHoverText(MapTable __instance, ref string __result, ref bool __runOriginal)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			__result = __instance.m_name + "\n" + UI.PromptInteract + " $piece_readmap";
			MapLocation mapLocation = new MapLocation(__instance);
			string arg = ((mapLocation.DaysLeft == 1) ? "" : "s");
			if (mapLocation.DaysLeft > 0)
			{
				__result += $"\n<color={UIColor.MinorInfo}>Charting area: {mapLocation.DaysLeft} day{arg}</color>";
			}
			__result = StringExt.Localize(__result);
			__runOriginal = false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(MapTable), "GetWriteHoverText")]
		public static void MapTable_GetWriteHoverText(MapTable __instance, ref string __result, ref bool __runOriginal)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.m_nview.GetZDO() != null && PrivateArea.CheckAccess(((Component)__instance).transform.position, 0f, false, false))
			{
				__runOriginal = false;
				__result = "";
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(MapTable), "OnRead", new Type[]
		{
			typeof(Switch),
			typeof(Humanoid),
			typeof(ItemData)
		})]
		private static void MapTable_OnRead(MapTable __instance, ref bool __runOriginal, ItemData? item)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			Log.Debug((object)"Read the MapTable", (ushort)0);
			__runOriginal = false;
			if (item != null)
			{
				return;
			}
			if (((Character)Player.m_localPlayer).InGodMode() && ZInput.GetKey(Configs.MapTableAdminAccelerateAgeKey.Value, true))
			{
				__instance.AccelerateAge(EnvMan.instance.m_dayLengthSec);
				__instance.ApplyWriteFX();
				((Character)Player.m_localPlayer).Message((MessageType)2, "Map table aged 1 day", 0, (Sprite)null);
				return;
			}
			_mapLocation = new MapLocation(__instance);
			MapFogCache.Save();
			MapFogCache.Reset();
			Minimap instance = Minimap.instance;
			float range = _mapLocation.Range;
			if (range > 0f)
			{
				instance.Explore(((Component)__instance).transform.position, range);
			}
			bool noMap = Game.m_noMap;
			Game.m_noMap = false;
			instance.m_largeZoom = Mathf.Max(0.015f, 0.075f * (_mapLocation.Percent + 0.2f));
			instance.SetMapMode((MapMode)2);
			Game.m_noMap = noMap;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(MapTable), "OnWrite")]
		private static bool MapTable_Write(MapTable __instance, ref bool __runOriginal, ItemData? item)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			Log.Debug((object)"Write the MapTable", (ushort)0);
			__runOriginal = false;
			if (item != null)
			{
				return false;
			}
			if (!PrivateArea.CheckAccess(((Component)__instance).transform.position, 0f, true, false))
			{
				Log.Debug((object)"MapTable warded, abort.", (ushort)0);
				return false;
			}
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Minimap), "Explore", new Type[]
		{
			typeof(int),
			typeof(int)
		})]
		private static void ExploreFog(ref bool __runOriginal, ref bool __result, int x, int y)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			if (IsUsingMapObject)
			{
				Minimap instance = Minimap.instance;
				Color pixel = instance.m_fogTexture.GetPixel(x, y);
				pixel.r = 0f;
				Color val = pixel;
				instance.m_fogTexture.SetPixel(x, y, val);
				__runOriginal = false;
				__result = true;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Chat), "AddInworldText")]
		private static void AddInWorldText(Type type, Vector3 position, ref bool __runOriginal)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			if ((int)Minimap.instance.m_mode != 2 && (int)type == 3)
			{
				__runOriginal = !Configs.HideMapPingInWorld.Value;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Chat), "UpdateWorldTextField")]
		private static void UpdateWorldTextField(WorldTextInstance wt)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if ((int)wt.m_type == 3 && Configs.HideMapPingInWorld.Value)
			{
				((Component)wt.m_textMeshField).gameObject.SetActive(false);
			}
		}
	}
	[HarmonyPatch]
	public static class PinToSign
	{
		private static void AddPin(this Sign sign, PinType pinType)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			MapTrack.AddPin(sign.m_nview.GetZDO(), save: true, pinType);
			((Character)Player.m_localPlayer).Message((MessageType)2, "$msg_pin_added", 0, (Sprite)null);
		}

		private static bool HasPin(this Sign sign)
		{
			return sign.m_nview.GetZDO().FindPin() != null;
		}

		private static void RemovePin(this Sign sign)
		{
			PinData val = sign.m_nview.GetZDO().FindPin();
			if (val == null)
			{
				Log.Error((object)"Attempting to remove pin from sign that does not have a pin", (ushort)0);
				return;
			}
			MapTrack.RemovePin(val);
			((Character)Player.m_localPlayer).Message((MessageType)2, "$msg_removed", 0, (Sprite)null);
		}

		private static bool RefundPin(this Sign sign)
		{
			ItemData itemData = ObjectDB.instance.GetItemPrefab("ZenMapPin").GetComponent<ItemDrop>().m_itemData;
			Player localPlayer = Player.m_localPlayer;
			if (((Humanoid)localPlayer).GetInventory().CanAddItem(itemData, 1))
			{
				sign.RemovePin();
				((Humanoid)localPlayer).GetInventory().AddItem(itemData.m_dropPrefab, 1);
				((Character)localPlayer).Message((MessageType)1, "$piece_tombstone_recovered", 1, itemData.GetIcon());
				return true;
			}
			((Character)localPlayer).Message((MessageType)2, "$msg_noroom", 0, (Sprite)null);
			return false;
		}

		private static string GetPromptUseMapPin(Sign sign)
		{
			string name = ItemDataExt.GetName(ObjectDB.instance.GetItemPrefab("ZenMapPin").GetComponent<ItemDrop>());
			if (!((Humanoid)Player.m_localPlayer).GetInventory().ContainsItemByName(name))
			{
				return string.Empty;
			}
			string text = ((sign.m_nview.GetZDO().FindPin() == null) ? "$hud_addpin" : "$hud_removepin");
			return StringExt.Localize(UI.PromptUseItem + " " + text);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Sign), "GetHoverText")]
		private static void Sign_GetHoverText(Sign __instance, ref string __result)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if (!__result.Contains(StringExt.Localize(UI.PromptUseItem)))
			{
				__result = __result + "\n" + GetPromptUseMapPin(__instance);
			}
			if (__instance.HasPin())
			{
				PinType val = (PinType)12;
				HudExt.UpdateHoverIcons(Hud.instance, (Sprite[])(object)new Sprite[1] { Minimap.instance.GetSprite(val) });
				string text = StringExt.Localize("$piece_sign");
				string replacement = text + " «";
				__result = Regex.Replace(__result, "^" + text, replacement, RegexOptions.Multiline);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Sign), "UseItem")]
		private static void Sign_UseItem(Sign __instance, ItemData item, ref bool __result, ref bool __runOriginal)
		{
			string prefabName = ItemDataExt.GetPrefabName(item);
			bool flag = prefabName == "Hammer";
			if ((!(prefabName != "ZenMapPin") || flag) && (!flag || __instance.HasPin()))
			{
				__runOriginal = false;
				__result = true;
				Player localPlayer = Player.m_localPlayer;
				Inventory inventory = ((Humanoid)localPlayer).GetInventory();
				if (((Character)localPlayer).InInterior())
				{
					((Character)localPlayer).Message((MessageType)2, "Can not apply pin in dungeon.", 0, (Sprite)null);
					__result = false;
				}
				else if (!__instance.HasPin())
				{
					inventory.RemoveOneItem(item);
					__instance.AddPin((PinType)3);
				}
				else if (Configs.MapPinRefund.Value)
				{
					__instance.RefundPin();
				}
				else
				{
					__instance.RemovePin();
				}
			}
		}
	}
}