Decompiled source of EdgeMapMarker v1.0.0

plugins/EdgeMapMarker.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace EdgeMapMarker
{
	[HarmonyPatch(typeof(Minimap), "Update")]
	internal static class EdgeMarker
	{
		private class MarkerView
		{
			public RectTransform Icon;

			public Image IconImage;

			public RectTransform Arrow;

			public Image ArrowImage;

			public TMP_Text Label;
		}

		private const float ArrowInset = 8f;

		private const float IconInset = 32f;

		private const float LabelInset = 60f;

		private const float ArrowSize = 14f;

		private const float LabelFontSize = 14f;

		private static RectTransform _root;

		private static Sprite _arrowSprite;

		private static readonly List<MarkerView> Views = new List<MarkerView>();

		private static readonly List<PinTracker.Target> Targets = new List<PinTracker.Target>();

		private static void Postfix(Minimap __instance)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (int)__instance.m_mode != 1)
			{
				SetActive((Component)(object)_root, active: false);
				return;
			}
			EnsureRoot(__instance);
			SetActive((Component)(object)_root, active: true);
			PinTracker.GetTargets(__instance, Targets);
			RawImage mapImageSmall = __instance.m_mapImageSmall;
			Rect rect = ((Graphic)mapImageSmall).rectTransform.rect;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(((Rect)(ref rect)).width / 2f, ((Rect)(ref rect)).height / 2f);
			float value = Plugin.MarkerScale.Value;
			Vector3 localScale = default(Vector3);
			((Vector3)(ref localScale))..ctor(value, value, 1f);
			int num = 0;
			float num2 = default(float);
			float num3 = default(float);
			foreach (PinTracker.Target target in Targets)
			{
				if ((target.Views & MarkerViews.Minimap) == 0)
				{
					continue;
				}
				__instance.WorldToMapPoint(target.Position, ref num2, ref num3);
				Vector2 val2 = __instance.MapPointToLocalGuiPos(num2, num3, mapImageSmall.uvRect, rect) - val;
				if (!(Mathf.Abs(val2.x) <= val.x) || !(Mathf.Abs(val2.y) <= val.y))
				{
					if (num == Views.Count)
					{
						Views.Add(CreateView(__instance));
					}
					MarkerView markerView = Views[num++];
					SetActive((Component)(object)markerView.Icon, Plugin.ShowIcon.Value);
					if ((Object)(object)markerView.IconImage.sprite != (Object)(object)target.Icon)
					{
						markerView.IconImage.sprite = target.Icon;
					}
					((Transform)markerView.Icon).localScale = localScale;
					markerView.Icon.anchoredPosition = val + ClampToEdge(val2, val, 32f * value);
					bool num4 = target.PlayerName != null;
					Color color = ((num4 && Plugin.ColorPlayers.Value) ? PlayerTracker.ColorFor(target.PlayerName) : Color.white);
					SetActive((Component)(object)markerView.Arrow, Plugin.ShowArrow.Value);
					((Graphic)markerView.ArrowImage).color = color;
					((Transform)markerView.Arrow).localScale = localScale;
					markerView.Arrow.anchoredPosition = val + ClampToEdge(val2, val, 8f * value);
					((Transform)markerView.Arrow).localRotation = Quaternion.Euler(0f, 0f, Mathf.Atan2(val2.y, val2.x) * 57.29578f - 90f);
					bool flag = num4 && Plugin.ShowPlayerNames.Value;
					bool flag2 = flag || Plugin.ShowDistance.Value;
					SetActive((Component)(object)markerView.Label.rectTransform, flag2);
					((Transform)markerView.Label.rectTransform).localScale = localScale;
					markerView.Label.rectTransform.anchoredPosition = val + ClampToEdge(val2, val, 60f * value);
					if (flag2)
					{
						string text = (Plugin.ShowDistance.Value ? FormatDistance(Utils.DistanceXZ(((Component)localPlayer).transform.position, target.Position)) : "");
						markerView.Label.text = (flag ? (target.PlayerName + " " + text).TrimEnd() : text);
						((Graphic)markerView.Label).color = color;
					}
				}
			}
			for (int i = num; i < Views.Count; i++)
			{
				SetActive((Component)(object)Views[i].Icon, active: false);
				SetActive((Component)(object)Views[i].Arrow, active: false);
				SetActive((Component)(object)Views[i].Label.rectTransform, active: false);
			}
		}

		private static Vector2 ClampToEdge(Vector2 offset, Vector2 halfSize, float inset)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			float num = halfSize.x - inset;
			float num2 = halfSize.y - inset;
			float num3 = Mathf.Min((offset.x != 0f) ? (num / Mathf.Abs(offset.x)) : float.MaxValue, (offset.y != 0f) ? (num2 / Mathf.Abs(offset.y)) : float.MaxValue);
			return offset * num3;
		}

		internal static string FormatDistance(float meters)
		{
			if (!(meters < 1000f))
			{
				return $"{meters / 1000f:0.0} km";
			}
			return $"{meters:0} m";
		}

		private static void EnsureRoot(Minimap minimap)
		{
			//IL_0030: 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_0044: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_root != (Object)null))
			{
				Views.Clear();
				_root = (RectTransform)new GameObject("EdgeMapMarker", new Type[1] { typeof(RectTransform) }).transform;
				((Transform)_root).SetParent((Transform)(object)minimap.m_pinRootSmall, false);
				_root.anchorMin = Vector2.zero;
				_root.anchorMax = Vector2.one;
				_root.offsetMin = Vector2.zero;
				_root.offsetMax = Vector2.zero;
			}
		}

		private static MarkerView CreateView(Minimap minimap)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Expected O, but got Unknown
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			MarkerView markerView = new MarkerView();
			RectTransform anchorsFrom = (RectTransform)minimap.m_pinPrefab.transform;
			GameObject val = Object.Instantiate<GameObject>(minimap.m_pinPrefab, (Transform)(object)_root);
			((Object)val).name = "Icon";
			markerView.Icon = (RectTransform)val.transform;
			markerView.Icon.SetSizeWithCurrentAnchors((Axis)0, minimap.m_pinSizeSmall);
			markerView.Icon.SetSizeWithCurrentAnchors((Axis)1, minimap.m_pinSizeSmall);
			Transform obj = val.transform.Find("Checked");
			if (obj != null)
			{
				((Component)obj).gameObject.SetActive(false);
			}
			markerView.IconImage = val.GetComponent<Image>();
			((Graphic)markerView.IconImage).raycastTarget = false;
			if ((Object)(object)_arrowSprite == (Object)null)
			{
				_arrowSprite = CreateArrowSprite();
			}
			GameObject val2 = NewChild("Arrow", _root, anchorsFrom);
			Image val3 = val2.AddComponent<Image>();
			val3.sprite = _arrowSprite;
			((Graphic)val3).raycastTarget = false;
			markerView.ArrowImage = val3;
			markerView.Arrow = (RectTransform)val2.transform;
			markerView.Arrow.sizeDelta = new Vector2(14f, 14f);
			GameObject val4 = NewChild("Distance", _root, anchorsFrom);
			markerView.Label = (TMP_Text)(object)val4.AddComponent<TextMeshProUGUI>();
			markerView.Label.font = minimap.m_biomeNameSmall.font;
			markerView.Label.fontSharedMaterial = minimap.m_biomeNameSmall.fontSharedMaterial;
			markerView.Label.fontSize = 14f;
			markerView.Label.alignment = (TextAlignmentOptions)514;
			markerView.Label.textWrappingMode = (TextWrappingModes)0;
			((Graphic)markerView.Label).raycastTarget = false;
			markerView.Label.rectTransform.sizeDelta = new Vector2(160f, 20f);
			return markerView;
		}

		private static GameObject NewChild(string name, RectTransform parent, RectTransform anchorsFrom)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent((Transform)(object)parent, false);
			val2.anchorMin = anchorsFrom.anchorMin;
			val2.anchorMax = anchorsFrom.anchorMax;
			val2.pivot = new Vector2(0.5f, 0.5f);
			return val;
		}

		private static Sprite CreateArrowSprite()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(32, 32, (TextureFormat)4, false);
			((Texture)val).wrapMode = (TextureWrapMode)1;
			Color32 val2 = default(Color32);
			((Color32)(ref val2))..ctor(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)0);
			for (int i = 0; i < 32; i++)
			{
				float num = (float)(31 - i) / 2f;
				for (int j = 0; j < 32; j++)
				{
					float num2 = Mathf.Abs((float)j + 0.5f - 16f);
					float num3 = Mathf.Clamp01(num - num2 + 0.5f);
					val.SetPixel(j, i, (Color)((num3 > 0f) ? new Color(1f, 1f, 1f, num3) : Color32.op_Implicit(val2)));
				}
			}
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, 32f, 32f), new Vector2(0.5f, 0.5f));
		}

		private static void SetActive(Component component, bool active)
		{
			if ((Object)(object)component != (Object)null && component.gameObject.activeSelf != active)
			{
				component.gameObject.SetActive(active);
			}
		}
	}
	[HarmonyPatch(typeof(GameCamera), "LateUpdate")]
	internal static class HudMarkers
	{
		private class View
		{
			public GameObject Root;

			public RectTransform Rect;

			public TMP_Text Text;

			public Image Icon;
		}

		private const float IconSize = 26f;

		private const float HeightAboveGround = 2f;

		private static readonly List<View> Views = new List<View>();

		private static readonly List<PinTracker.Target> Targets = new List<PinTracker.Target>();

		private static Chat _owner;

		private static void Postfix()
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Invalid comparison between Unknown and I4
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			Minimap instance = Minimap.instance;
			Chat instance2 = Chat.instance;
			Camera mainCamera = Utils.GetMainCamera();
			if ((Object)(object)_owner != (Object)(object)instance2)
			{
				Views.Clear();
				_owner = instance2;
			}
			int num = 0;
			if (Plugin.ShowHudMarkers.Value && (Object)(object)localPlayer != (Object)null && (Object)(object)instance != (Object)null && (Object)(object)instance2 != (Object)null && (Object)(object)mainCamera != (Object)null && (int)instance.m_mode != 2 && !Hud.IsUserHidden())
			{
				PinTracker.GetTargets(instance, Targets);
				foreach (PinTracker.Target target in Targets)
				{
					if ((target.Views & MarkerViews.Hud) == 0)
					{
						continue;
					}
					float num2 = Utils.DistanceXZ(((Component)localPlayer).transform.position, target.Position);
					if (!(num2 < Plugin.HudHideWithin.Value))
					{
						if (num == Views.Count)
						{
							Views.Add(CreateView(instance2));
						}
						View view = Views[num++];
						if (!view.Root.activeSelf)
						{
							view.Root.SetActive(true);
						}
						string text = EdgeMarker.FormatDistance(num2);
						view.Text.text = (string.IsNullOrEmpty(target.Label) ? text : (target.Label + " (" + text + ")"));
						((Graphic)view.Text).color = ((target.PlayerName != null && Plugin.ColorPlayers.Value) ? PlayerTracker.ColorFor(target.PlayerName) : Color.white);
						bool flag = Plugin.HudShowIcon.Value && (Object)(object)target.Icon != (Object)null;
						if (((Component)view.Icon).gameObject.activeSelf != flag)
						{
							((Component)view.Icon).gameObject.SetActive(flag);
						}
						if ((Object)(object)view.Icon.sprite != (Object)(object)target.Icon)
						{
							view.Icon.sprite = target.Icon;
						}
						Vector3 val = ToScreen(mainCamera, WorldPoint(target));
						val = instance2.ClampToScreenEdge(val, view.Rect, true);
						val.z = Mathf.Min(val.z, 100f);
						view.Root.transform.position = val;
					}
				}
			}
			for (int i = num; i < Views.Count; i++)
			{
				if ((Object)(object)Views[i].Root != (Object)null && Views[i].Root.activeSelf)
				{
					Views[i].Root.SetActive(false);
				}
			}
		}

		private static Vector3 WorldPoint(PinTracker.Target target)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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)
			Vector3 position = target.Position;
			if (target.PlayerName == null && Mathf.Approximately(position.y, 0f))
			{
				float num = default(float);
				position.y = (ZoneSystem.instance.GetGroundHeight(position, ref num) ? num : Mathf.Max(WorldGenerator.instance.GetHeight(position.x, position.z), ZoneSystem.instance.m_waterLevel));
			}
			position.y += 2f;
			return position;
		}

		private static Vector3 ToScreen(Camera camera, Vector3 world)
		{
			//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)
			//IL_0007: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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_00a2: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Utils.WorldToScreenPointScaled(camera, world);
			if (val.x < 0f || val.x > (float)Screen.width || val.y < 0f || val.y > (float)Screen.height || val.z < 0f)
			{
				Vector3 val2 = world - ((Component)camera).transform.position;
				bool flag = Vector3.Dot(((Component)camera).transform.right, val2) < 0f;
				Vector3 val3 = val2;
				val3.y = 0f;
				Vector3 val4 = ((Component)camera).transform.forward;
				val4.y = 0f;
				val4 = ((Vector3)(ref val4)).normalized * ((Vector3)(ref val3)).magnitude;
				val = Utils.WorldToScreenPointScaled(camera, ((Component)camera).transform.position + val4 + Vector3.up * val2.y);
				val.x = (flag ? 0f : ((float)Screen.width));
			}
			return val;
		}

		private static View CreateView(Chat chat)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(chat.m_worldTextBase, ((Component)chat).transform);
			((Object)val).name = "EdgeMapMarkerHud";
			val.SetActive(true);
			View view = new View
			{
				Root = val,
				Rect = (RectTransform)val.transform,
				Text = ((Component)val.transform.Find("Text")).GetComponent<TMP_Text>()
			};
			GameObject val2 = new GameObject("Icon", new Type[1] { typeof(RectTransform) });
			RectTransform val3 = (RectTransform)val2.transform;
			((Transform)val3).SetParent(val.transform, false);
			val3.anchorMin = new Vector2(0.5f, 1f);
			val3.anchorMax = new Vector2(0.5f, 1f);
			val3.pivot = new Vector2(0.5f, 0f);
			val3.sizeDelta = new Vector2(26f, 26f);
			val3.anchoredPosition = new Vector2(0f, 2f);
			view.Icon = val2.AddComponent<Image>();
			view.Icon.preserveAspect = true;
			((Graphic)view.Icon).raycastTarget = false;
			return view;
		}
	}
	[Flags]
	public enum MarkerViews
	{
		None = 0,
		Minimap = 1,
		Hud = 2,
		Both = 3
	}
	internal static class MarkerViewsExtensions
	{
		public static MarkerViews Next(this MarkerViews views)
		{
			return views switch
			{
				MarkerViews.Both => MarkerViews.Minimap, 
				MarkerViews.Minimap => MarkerViews.Hud, 
				_ => MarkerViews.Both, 
			};
		}

		public static string Describe(this MarkerViews views)
		{
			return views switch
			{
				MarkerViews.Minimap => "minimap only", 
				MarkerViews.Hud => "HUD only", 
				_ => "minimap + HUD", 
			};
		}

		public static MarkerViews Parse(string value)
		{
			if (!int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result) || result < 1 || result > 3)
			{
				return MarkerViews.Both;
			}
			return (MarkerViews)result;
		}
	}
	internal static class PinTracker
	{
		public struct Target
		{
			public Vector3 Position;

			public Sprite Icon;

			public MarkerViews Views;

			public string Label;

			public string PlayerName;
		}

		private class Entry
		{
			public PinType Type;

			public Vector3 Position;

			public MarkerViews Views = MarkerViews.Both;

			public PinData Pin;

			public float RemovedAt = -1f;
		}

		private enum ClickKind
		{
			Nothing,
			Pin,
			Player,
			Home
		}

		[HarmonyPatch(typeof(Minimap), "OnMapLeftClick")]
		private static class TrackClickPatch
		{
			private static bool Prefix(Minimap __instance)
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				if (!ZInput.GetKey(Plugin.TrackKey.Value, true))
				{
					return true;
				}
				ToggleTracked(__instance);
				__instance.m_pinUpdateRequired = true;
				return false;
			}
		}

		[HarmonyPatch(typeof(Minimap), "RemovePinUnderPointer")]
		private static class CycleClickPatch
		{
			private static bool Prefix(Minimap __instance)
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				if (!ZInput.GetKey(Plugin.TrackKey.Value, true))
				{
					return true;
				}
				CycleViews(__instance);
				__instance.m_pinUpdateRequired = true;
				return false;
			}
		}

		[HarmonyPatch(typeof(Minimap), "RemovePin", new Type[] { typeof(PinData) })]
		private static class RemovePinPatch
		{
			private static void Postfix(PinData pin, bool __runOriginal)
			{
				//IL_0027: 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)
				if (pin == null || !__runOriginal)
				{
					return;
				}
				foreach (Entry entry in Entries)
				{
					if (entry.Pin == pin)
					{
						entry.Position = pin.m_pos;
						entry.Pin = null;
						entry.RemovedAt = (_userRemoving ? Time.time : (-1f));
					}
				}
			}
		}

		[HarmonyPatch(typeof(Minimap), "RemovePin", new Type[]
		{
			typeof(Vector3),
			typeof(float)
		})]
		private static class UserRemovePinPatch
		{
			private static void Prefix()
			{
				_userRemoving = true;
			}

			private static void Finalizer()
			{
				_userRemoving = false;
			}
		}

		private const string SaveKeyPrefix = "EdgeMapMarker.Tracked.";

		private const string HomeKeyPrefix = "EdgeMapMarker.HomeViews.";

		private const string LegacyHomeKeyPrefix = "EdgeMapMarker.Home.";

		private const float RemovalGraceSeconds = 2f;

		private static bool _userRemoving;

		private static readonly List<Entry> Entries = new List<Entry>();

		private static Minimap _loadedFor;

		private static string SaveKey => "EdgeMapMarker.Tracked." + ZNet.instance.GetWorldUID();

		private static string HomeKey => "EdgeMapMarker.HomeViews." + ZNet.instance.GetWorldUID();

		private static string LegacyHomeKey => "EdgeMapMarker.Home." + ZNet.instance.GetWorldUID();

		public static void GetTargets(Minimap minimap, List<Target> targets)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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)
			targets.Clear();
			Refresh(minimap);
			MarkerViews homeViews = GetHomeViews();
			if (homeViews != MarkerViews.None)
			{
				targets.Add(new Target
				{
					Position = GetHomePosition(),
					Icon = minimap.GetSprite((PinType)5),
					Views = homeViews,
					Label = "Home"
				});
			}
			foreach (Entry entry in Entries)
			{
				if (entry.Pin != null)
				{
					targets.Add(new Target
					{
						Position = entry.Pin.m_pos,
						Icon = entry.Pin.m_icon,
						Views = entry.Views,
						Label = Localization.instance.Localize(entry.Pin.m_name)
					});
				}
			}
			PlayerTracker.AddTargets(minimap, targets);
		}

		public static void GetTrackedPins(Minimap minimap, List<PinData> pins)
		{
			pins.Clear();
			Refresh(minimap);
			if (GetHomeViews() != MarkerViews.None && minimap.m_spawnPointPin != null)
			{
				pins.Add(minimap.m_spawnPointPin);
			}
			foreach (Entry entry in Entries)
			{
				if (entry.Pin != null)
				{
					pins.Add(entry.Pin);
				}
			}
			PlayerTracker.AddTrackedPins(minimap, pins);
		}

		private static Vector3 GetHomePosition()
		{
			//IL_001b: 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)
			PlayerProfile playerProfile = Game.instance.GetPlayerProfile();
			if (!playerProfile.HaveCustomSpawnPoint())
			{
				return playerProfile.GetHomePoint();
			}
			return playerProfile.GetCustomSpawnPoint();
		}

		private static MarkerViews GetHomeViews()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer != (Object)null)
			{
				if (localPlayer.m_customData.TryGetValue(HomeKey, out var value))
				{
					if (!(value == "0"))
					{
						return MarkerViewsExtensions.Parse(value);
					}
					return MarkerViews.None;
				}
				if (localPlayer.m_customData.TryGetValue(LegacyHomeKey, out var value2))
				{
					if (!(value2 == "1"))
					{
						return MarkerViews.None;
					}
					return MarkerViews.Both;
				}
			}
			if (!Plugin.TrackHomeByDefault.Value)
			{
				return MarkerViews.None;
			}
			return MarkerViews.Both;
		}

		private static void SetHomeViews(MarkerViews views)
		{
			Player localPlayer = Player.m_localPlayer;
			Dictionary<string, string> customData = localPlayer.m_customData;
			string homeKey = HomeKey;
			int num = (int)views;
			customData[homeKey] = num.ToString(CultureInfo.InvariantCulture);
			localPlayer.m_customData.Remove(LegacyHomeKey);
		}

		private static void Refresh(Minimap minimap)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_loadedFor != (Object)(object)minimap && (Object)(object)Player.m_localPlayer != (Object)null)
			{
				Load();
				_loadedFor = minimap;
			}
			bool flag = false;
			for (int num = Entries.Count - 1; num >= 0; num--)
			{
				Entry entry = Entries[num];
				if (entry.Pin == null)
				{
					entry.Pin = FindPin(minimap, entry.Type, entry.Position);
					if (entry.Pin != null)
					{
						entry.RemovedAt = -1f;
					}
					else if (entry.RemovedAt >= 0f && Time.time - entry.RemovedAt > 2f)
					{
						Entries.RemoveAt(num);
						flag = true;
						ShowMessage("Stopped tracking: pin removed", minimap.GetSprite(entry.Type));
					}
				}
			}
			if (flag)
			{
				Save();
			}
		}

		private static PinData FindPin(Minimap minimap, PinType type, Vector3 pos)
		{
			//IL_0017: 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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			foreach (PinData pin in minimap.m_pins)
			{
				if (pin.m_type == type && Utils.DistanceXZ(pin.m_pos, pos) < 1f)
				{
					return pin;
				}
			}
			return null;
		}

		private static string PinLabel(PinData pin)
		{
			string text = Localization.instance.Localize(pin.m_name);
			if (!string.IsNullOrEmpty(text))
			{
				return text;
			}
			return "pin";
		}

		internal static void ShowMessage(string text, Sprite icon)
		{
			Player localPlayer = Player.m_localPlayer;
			if (localPlayer != null)
			{
				((Character)localPlayer).Message((MessageType)1, text, 0, icon, false);
			}
		}

		private static void Save()
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Expected I4, but got Unknown
			//IL_009c: 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)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			if (Entries.Count == 0)
			{
				localPlayer.m_customData.Remove(SaveKey);
				return;
			}
			StringBuilder stringBuilder = new StringBuilder();
			foreach (Entry entry in Entries)
			{
				Vector3 val = ((entry.Pin != null) ? entry.Pin.m_pos : entry.Position);
				if (stringBuilder.Length > 0)
				{
					stringBuilder.Append(';');
				}
				stringBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}|{1}|{2}|{3}", (int)entry.Type, val.x, val.z, (int)entry.Views);
			}
			localPlayer.m_customData[SaveKey] = stringBuilder.ToString();
		}

		private static void Load()
		{
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			Entries.Clear();
			if (!Player.m_localPlayer.m_customData.TryGetValue(SaveKey, out var value))
			{
				return;
			}
			string[] array = value.Split(';');
			for (int i = 0; i < array.Length; i++)
			{
				string[] array2 = array[i].Split('|');
				if ((array2.Length == 3 || array2.Length == 4) && int.TryParse(array2[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result) && float.TryParse(array2[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) && float.TryParse(array2[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var result3))
				{
					Entries.Add(new Entry
					{
						Type = (PinType)result,
						Position = new Vector3(result2, 0f, result3),
						Views = ((array2.Length == 4) ? MarkerViewsExtensions.Parse(array2[3]) : MarkerViews.Both)
					});
				}
			}
		}

		private static ClickKind FindClickTarget(Minimap minimap, out PinData pin, out string playerName)
		{
			//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_0015: 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)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			float pinInteractRadius = minimap.PinInteractRadius;
			Vector3 val = minimap.ScreenToWorldPoint(ZInput.pointerPosition);
			pin = minimap.GetClosestPin(val, pinInteractRadius, true);
			float num = ((pin != null) ? Utils.DistanceXZ(val, pin.m_pos) : float.MaxValue);
			float num2 = Utils.DistanceXZ(val, GetHomePosition());
			if (num2 >= pinInteractRadius)
			{
				num2 = float.MaxValue;
			}
			if (!PlayerTracker.TryFindClosest(val, pinInteractRadius, out playerName, out var distance))
			{
				distance = float.MaxValue;
			}
			if (distance < num && distance < num2)
			{
				return ClickKind.Player;
			}
			if (num2 < num)
			{
				return ClickKind.Home;
			}
			if (pin == null)
			{
				return ClickKind.Nothing;
			}
			return ClickKind.Pin;
		}

		private static void ToggleTracked(Minimap minimap)
		{
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			Refresh(minimap);
			PinData pin;
			string playerName;
			switch (FindClickTarget(minimap, out pin, out playerName))
			{
			case ClickKind.Player:
				PlayerTracker.Toggle(minimap, playerName);
				break;
			case ClickKind.Home:
			{
				bool num = GetHomeViews() == MarkerViews.None;
				SetHomeViews(num ? MarkerViews.Both : MarkerViews.None);
				ShowMessage(num ? ("Tracking: Home (" + MarkerViews.Both.Describe() + ")") : "Stopped tracking: Home", minimap.GetSprite((PinType)5));
				break;
			}
			case ClickKind.Pin:
			{
				Entry entry = Entries.Find((Entry e) => e.Pin == pin);
				if (entry != null)
				{
					Entries.Remove(entry);
					ShowMessage("Stopped tracking: " + PinLabel(pin), pin.m_icon);
				}
				else
				{
					Entries.Add(new Entry
					{
						Type = pin.m_type,
						Position = pin.m_pos,
						Pin = pin
					});
					ShowMessage("Tracking: " + PinLabel(pin) + " (" + MarkerViews.Both.Describe() + ")", pin.m_icon);
				}
				Save();
				break;
			}
			}
		}

		private static void CycleViews(Minimap minimap)
		{
			Refresh(minimap);
			PinData pin;
			string playerName;
			switch (FindClickTarget(minimap, out pin, out playerName))
			{
			case ClickKind.Player:
				PlayerTracker.CycleViews(minimap, playerName);
				break;
			case ClickKind.Home:
			{
				MarkerViews homeViews = GetHomeViews();
				if (homeViews != MarkerViews.None)
				{
					homeViews = homeViews.Next();
					SetHomeViews(homeViews);
					ShowMessage("Home: " + homeViews.Describe(), minimap.GetSprite((PinType)5));
				}
				break;
			}
			case ClickKind.Pin:
			{
				Entry entry = Entries.Find((Entry e) => e.Pin == pin);
				if (entry != null)
				{
					entry.Views = entry.Views.Next();
					ShowMessage(PinLabel(pin) + ": " + entry.Views.Describe(), pin.m_icon);
					Save();
				}
				break;
			}
			}
		}
	}
	internal static class PlayerTracker
	{
		private const string SaveKeyPrefix = "EdgeMapMarker.Players.";

		private static readonly Color[] Palette = (Color[])(object)new Color[10]
		{
			new Color(1f, 0.38f, 0.38f),
			new Color(0.38f, 0.7f, 1f),
			new Color(0.45f, 0.9f, 0.4f),
			new Color(1f, 0.85f, 0.3f),
			new Color(0.8f, 0.5f, 1f),
			new Color(0.3f, 0.92f, 0.88f),
			new Color(1f, 0.6f, 0.2f),
			new Color(1f, 0.55f, 0.82f),
			new Color(0.75f, 0.95f, 0.3f),
			new Color(0.62f, 0.62f, 1f)
		};

		private static readonly Dictionary<string, MarkerViews> Names = new Dictionary<string, MarkerViews>();

		private static readonly List<PlayerInfo> Players = new List<PlayerInfo>();

		private static Minimap _loadedFor;

		private static string SaveKey => "EdgeMapMarker.Players." + ZNet.instance.GetWorldUID();

		public static void AddTargets(Minimap minimap, List<PinTracker.Target> targets)
		{
			//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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			if (!Refresh(minimap))
			{
				return;
			}
			Sprite sprite = minimap.GetSprite((PinType)10);
			foreach (PlayerInfo player in Players)
			{
				if (Names.TryGetValue(player.m_name, out var value))
				{
					targets.Add(new PinTracker.Target
					{
						Position = player.m_position,
						Icon = sprite,
						Views = value,
						Label = player.m_name,
						PlayerName = player.m_name
					});
				}
			}
		}

		public static void AddTrackedPins(Minimap minimap, List<PinData> pins)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if (!Refresh(minimap))
			{
				return;
			}
			int num = Mathf.Min(Players.Count, minimap.m_playerPins.Count);
			for (int i = 0; i < num; i++)
			{
				if (Names.ContainsKey(Players[i].m_name))
				{
					pins.Add(minimap.m_playerPins[i]);
				}
			}
		}

		public static bool TryFindClosest(Vector3 pos, float radius, out string name, out float distance)
		{
			//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)
			//IL_0034: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			name = null;
			distance = radius;
			Players.Clear();
			ZNet.instance.GetOtherPublicPlayers(Players);
			foreach (PlayerInfo player in Players)
			{
				float num = Utils.DistanceXZ(pos, player.m_position);
				if (num < distance)
				{
					name = player.m_name;
					distance = num;
				}
			}
			return name != null;
		}

		public static void Toggle(Minimap minimap, string name)
		{
			Refresh(minimap);
			Sprite sprite = minimap.GetSprite((PinType)10);
			if (Names.Remove(name))
			{
				PinTracker.ShowMessage("Stopped tracking: " + name, sprite);
			}
			else
			{
				Names[name] = MarkerViews.Both;
				PinTracker.ShowMessage("Tracking: " + name + " (" + MarkerViews.Both.Describe() + ")", sprite);
			}
			Save();
		}

		public static void CycleViews(Minimap minimap, string name)
		{
			Refresh(minimap);
			if (Names.TryGetValue(name, out var value))
			{
				value = value.Next();
				Names[name] = value;
				PinTracker.ShowMessage(name + ": " + value.Describe(), minimap.GetSprite((PinType)10));
				Save();
			}
		}

		public static Color ColorFor(string name)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			uint num = 2166136261u;
			string text = name.ToLowerInvariant();
			foreach (char c in text)
			{
				num = (num ^ c) * 16777619;
			}
			return Palette[num % (uint)Palette.Length];
		}

		private static bool Refresh(Minimap minimap)
		{
			if ((Object)(object)_loadedFor != (Object)(object)minimap && (Object)(object)Player.m_localPlayer != (Object)null)
			{
				Load();
				_loadedFor = minimap;
			}
			if (Names.Count == 0)
			{
				return false;
			}
			Players.Clear();
			ZNet.instance.GetOtherPublicPlayers(Players);
			return true;
		}

		private static void Save()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			if (Names.Count == 0)
			{
				localPlayer.m_customData.Remove(SaveKey);
				return;
			}
			StringBuilder stringBuilder = new StringBuilder();
			foreach (KeyValuePair<string, MarkerViews> name in Names)
			{
				if (stringBuilder.Length > 0)
				{
					stringBuilder.Append('\n');
				}
				stringBuilder.Append(name.Key).Append('\t').Append((int)name.Value);
			}
			localPlayer.m_customData[SaveKey] = stringBuilder.ToString();
		}

		private static void Load()
		{
			Names.Clear();
			if (!Player.m_localPlayer.m_customData.TryGetValue(SaveKey, out var value))
			{
				return;
			}
			string[] array = value.Split('\n');
			for (int i = 0; i < array.Length; i++)
			{
				string[] array2 = array[i].Split('\t');
				if (array2[0].Length > 0)
				{
					Names[array2[0]] = ((array2.Length > 1) ? MarkerViewsExtensions.Parse(array2[1]) : MarkerViews.Both);
				}
			}
		}
	}
	[BepInPlugin("rdcampbell555.EdgeMapMarker", "Edge Map Marker", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "rdcampbell555.EdgeMapMarker";

		public const string PluginName = "Edge Map Marker";

		public const string PluginVersion = "1.0.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> ShowIcon;

		internal static ConfigEntry<bool> ShowArrow;

		internal static ConfigEntry<bool> ShowDistance;

		internal static ConfigEntry<float> MarkerScale;

		internal static ConfigEntry<KeyCode> TrackKey;

		internal static ConfigEntry<bool> TrackHomeByDefault;

		internal static ConfigEntry<bool> ShowHudMarkers;

		internal static ConfigEntry<bool> HudShowIcon;

		internal static ConfigEntry<float> HudHideWithin;

		internal static ConfigEntry<KeyboardShortcut> ToggleHudMarkersKey;

		internal static ConfigEntry<KeyboardShortcut> ToggleHudIconsKey;

		internal static ConfigEntry<bool> ShowPlayerNames;

		internal static ConfigEntry<bool> ColorPlayers;

		internal static ConfigEntry<bool> HighlightTracked;

		internal static ConfigEntry<HighlightStyle> HighlightStyleSetting;

		internal static ConfigEntry<Color> HighlightColor;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Expected O, but got Unknown
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			ShowIcon = ((BaseUnityPlugin)this).Config.Bind<bool>("Edge marker", "Show icon", true, "Show the target's pin icon on the minimap edge.");
			ShowArrow = ((BaseUnityPlugin)this).Config.Bind<bool>("Edge marker", "Show arrow", true, "Show an arrow pointing toward the target.");
			ShowDistance = ((BaseUnityPlugin)this).Config.Bind<bool>("Edge marker", "Show distance", true, "Show the distance to the target.");
			MarkerScale = ((BaseUnityPlugin)this).Config.Bind<float>("Edge marker", "Marker size", 0.7f, new ConfigDescription("Size of the icon, arrow and distance text, relative to the game's own pins.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.3f, 1.5f), Array.Empty<object>()));
			TrackKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Tracking", "Track key", (KeyCode)308, "On the large map, hold this and left-click a pin, player or your spawn point to track it (or stop). Hold it and right-click a tracked one to cycle where it shows: minimap + HUD, minimap only, HUD only.");
			TrackHomeByDefault = ((BaseUnityPlugin)this).Config.Bind<bool>("Tracking", "Track home by default", true, "Track your bed (or the world spawn if you have no bed) in worlds where you haven't toggled it. Track-key + click near your spawn point on the large map to toggle it per world.");
			ShowHudMarkers = ((BaseUnityPlugin)this).Config.Bind<bool>("HUD", "Show HUD markers", true, "Show a ping-style label on screen at each tracked target, with its name and distance.");
			HudShowIcon = ((BaseUnityPlugin)this).Config.Bind<bool>("HUD", "Show icon", true, "Show the target's map icon above its HUD label.");
			HudHideWithin = ((BaseUnityPlugin)this).Config.Bind<float>("HUD", "Hide within (m)", 20f, new ConfigDescription("Hide a target's HUD marker when you're closer than this.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 200f), Array.Empty<object>()));
			ToggleHudMarkersKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("HUD", "Toggle HUD markers key", new KeyboardShortcut((KeyCode)104, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }), "Press to show or hide all HUD markers (flips 'Show HUD markers').");
			ToggleHudIconsKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("HUD", "Toggle HUD icons key", new KeyboardShortcut((KeyCode)105, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }), "Press to show or hide the icons above HUD markers (flips 'Show icon').");
			ShowPlayerNames = ((BaseUnityPlugin)this).Config.Bind<bool>("Players", "Show player names", true, "Show a tracked player's name next to the distance on their edge marker.");
			ColorPlayers = ((BaseUnityPlugin)this).Config.Bind<bool>("Players", "Color players", true, "Give each tracked player's arrow and name a colour picked from their character name, so everyone with the mod sees the same player in the same colour.");
			HighlightTracked = ((BaseUnityPlugin)this).Config.Bind<bool>("Tracking", "Highlight tracked pins", true, "Mark tracked pins on the large map and the minimap.");
			HighlightStyleSetting = ((BaseUnityPlugin)this).Config.Bind<HighlightStyle>("Tracking", "Highlight style", HighlightStyle.Badge, "Badge: a small dot in the pin's top-right corner. Ring: a ring around the pin.");
			HighlightColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Tracking", "Tracked highlight color", new Color(0.3f, 0.95f, 0.4f, 1f), "Color of the tracked-pin highlight. Lower the alpha to make it fainter.");
			_harmony = Harmony.CreateAndPatchAll(typeof(Plugin).Assembly, "rdcampbell555.EdgeMapMarker");
			Log.LogInfo((object)"Edge Map Marker 1.0.0 loaded");
		}

		private void Update()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)Player.m_localPlayer == (Object)null) && !IsTyping())
			{
				if (IsPressed(ToggleHudMarkersKey.Value))
				{
					ShowHudMarkers.Value = !ShowHudMarkers.Value;
					((Character)Player.m_localPlayer).Message((MessageType)1, "HUD markers: " + (ShowHudMarkers.Value ? "on" : "off"), 0, (Sprite)null, false);
				}
				if (IsPressed(ToggleHudIconsKey.Value))
				{
					HudShowIcon.Value = !HudShowIcon.Value;
					((Character)Player.m_localPlayer).Message((MessageType)1, "HUD icons: " + (HudShowIcon.Value ? "on" : "off"), 0, (Sprite)null, false);
				}
			}
		}

		private static bool IsTyping()
		{
			if ((!((Object)(object)Chat.instance != (Object)null) || !Chat.instance.HasFocus()) && !Console.IsVisible() && !TextInput.IsVisible())
			{
				return Minimap.InTextInput();
			}
			return true;
		}

		private static bool IsPressed(KeyboardShortcut shortcut)
		{
			//IL_0002: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			if ((int)((KeyboardShortcut)(ref shortcut)).MainKey == 0 || !ZInput.GetKeyDown(((KeyboardShortcut)(ref shortcut)).MainKey, false))
			{
				return false;
			}
			foreach (KeyCode modifier in ((KeyboardShortcut)(ref shortcut)).Modifiers)
			{
				if (!ZInput.GetKey(modifier, false))
				{
					return false;
				}
			}
			return true;
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	public enum HighlightStyle
	{
		Badge,
		Ring
	}
	[HarmonyPatch(typeof(Minimap), "Update")]
	internal static class TrackedPinHighlight
	{
		private class Highlight
		{
			public Image Image;

			public HighlightStyle Style;
		}

		private static readonly Vector2 BadgeMin = new Vector2(0.71f, 0.71f);

		private static readonly Vector2 BadgeMax = new Vector2(1.03f, 1.03f);

		private static readonly Vector2 RingMin = new Vector2(-0.12f, -0.12f);

		private static readonly Vector2 RingMax = new Vector2(1.12f, 1.12f);

		private static readonly Dictionary<PinData, Highlight> Highlights = new Dictionary<PinData, Highlight>();

		private static readonly List<PinData> Tracked = new List<PinData>();

		private static readonly List<PinData> Stale = new List<PinData>();

		private static Minimap _owner;

		private static Sprite _badgeSprite;

		private static Sprite _ringSprite;

		private static void Postfix(Minimap __instance)
		{
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				return;
			}
			if ((Object)(object)_owner != (Object)(object)__instance)
			{
				Highlights.Clear();
				_owner = __instance;
			}
			if (Plugin.HighlightTracked.Value)
			{
				PinTracker.GetTrackedPins(__instance, Tracked);
			}
			else
			{
				Tracked.Clear();
			}
			HighlightStyle value = Plugin.HighlightStyleSetting.Value;
			Stale.Clear();
			foreach (KeyValuePair<PinData, Highlight> highlight in Highlights)
			{
				Image image = highlight.Value.Image;
				if ((Object)(object)image == (Object)null || (Object)(object)((Component)image).transform.parent != (Object)(object)highlight.Key.m_uiElement || highlight.Value.Style != value || !Tracked.Contains(highlight.Key))
				{
					Stale.Add(highlight.Key);
				}
			}
			foreach (PinData item in Stale)
			{
				if ((Object)(object)Highlights[item].Image != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)Highlights[item].Image).gameObject);
				}
				Highlights.Remove(item);
			}
			Color value2 = Plugin.HighlightColor.Value;
			foreach (PinData item2 in Tracked)
			{
				if (!((Object)(object)item2.m_uiElement == (Object)null))
				{
					if (!Highlights.TryGetValue(item2, out var value3))
					{
						value3 = new Highlight
						{
							Image = Create(item2.m_uiElement, value),
							Style = value
						};
						Highlights[item2] = value3;
					}
					((Graphic)value3.Image).color = PinColor(item2, value2);
				}
			}
		}

		private static Color PinColor(PinData pin, Color highlight)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			//IL_0023: 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)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			if ((int)pin.m_type != 10 || !Plugin.ColorPlayers.Value || string.IsNullOrEmpty(pin.m_name))
			{
				return highlight;
			}
			Color result = PlayerTracker.ColorFor(pin.m_name);
			result.a = highlight.a;
			return result;
		}

		private static Image Create(RectTransform pinElement, HighlightStyle style)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("EdgeMapMarkerHighlight", new Type[1] { typeof(RectTransform) });
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent((Transform)(object)pinElement, false);
			val2.anchorMin = ((style == HighlightStyle.Badge) ? BadgeMin : RingMin);
			val2.anchorMax = ((style == HighlightStyle.Badge) ? BadgeMax : RingMax);
			val2.offsetMin = Vector2.zero;
			val2.offsetMax = Vector2.zero;
			Image obj = val.AddComponent<Image>();
			obj.sprite = ((style == HighlightStyle.Badge) ? GetBadgeSprite() : GetRingSprite());
			((Graphic)obj).raycastTarget = false;
			return obj;
		}

		private static Sprite GetBadgeSprite()
		{
			if ((Object)(object)_badgeSprite == (Object)null)
			{
				_badgeSprite = CreateCircleSprite(32, 15.5f, 11.5f, filled: true);
			}
			return _badgeSprite;
		}

		private static Sprite GetRingSprite()
		{
			if ((Object)(object)_ringSprite == (Object)null)
			{
				_ringSprite = CreateCircleSprite(64, 31f, 28.5f, filled: false);
			}
			return _ringSprite;
		}

		private static Sprite CreateCircleSprite(int size, float outer, float inner, bool filled)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(size, size, (TextureFormat)4, false);
			((Texture)val).wrapMode = (TextureWrapMode)1;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor((float)size / 2f, (float)size / 2f);
			for (int i = 0; i < size; i++)
			{
				for (int j = 0; j < size; j++)
				{
					float num = Vector2.Distance(new Vector2((float)j + 0.5f, (float)i + 0.5f), val2);
					float num2 = Mathf.Clamp01(outer - num + 0.5f);
					float num3 = Mathf.Clamp01(inner - num + 0.5f);
					Color val3 = (filled ? new Color(num3, num3, num3, num2) : new Color(1f, 1f, 1f, Mathf.Min(num2, 1f - num3)));
					val.SetPixel(j, i, val3);
				}
			}
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, (float)size, (float)size), new Vector2(0.5f, 0.5f));
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}