Decompiled source of PlayerColorCompassAndQuickPinTweaks v1.4.2

PlayerColorCompassAndQuickPinTweaks.dll

Decompiled 44 minutes ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Splatform;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace PlayerColorCompassAndQuickPinTweaks
{
	internal class AdminColors
	{
		private class Row
		{
			public string Id;

			public ConfigEntry<Color> Entry;

			public bool Pending;

			public float SendAt;
		}

		private const string Section = "Admin - Player colors";

		private readonly ConfigFile _config;

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

		private bool _suppress;

		private float _nextRefresh;

		public AdminColors(ConfigFile config)
		{
			_config = config;
		}

		public unsafe void Tick()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			foreach (Row value2 in _rows.Values)
			{
				if (value2.Pending && Time.unscaledTime >= value2.SendAt)
				{
					value2.Pending = false;
					ColorSync.AdminSetColor(value2.Id, value2.Entry.Value);
				}
			}
			if (Time.unscaledTime < _nextRefresh)
			{
				return;
			}
			_nextRefresh = Time.unscaledTime + 2f;
			if (!((Object)(object)ZNet.instance != (Object)null) || !ColorSync.ServerHasMod || !ColorSync.LocalLooksLikeAdmin())
			{
				RemoveAll();
				return;
			}
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			string text = ColorSync.LocalId();
			foreach (PlayerInfo player in ZNet.instance.GetPlayerList())
			{
				PlatformUserID id = player.m_userInfo.m_id;
				string text2 = ((object)(*(PlatformUserID*)(&id))/*cast due to .constrained prefix*/).ToString();
				if (!string.IsNullOrEmpty(text2) && text2 != text)
				{
					dictionary[text2] = player.m_name;
				}
			}
			List<string> list = new List<string>();
			foreach (KeyValuePair<string, Row> row in _rows)
			{
				if (!dictionary.ContainsKey(row.Key))
				{
					list.Add(row.Key);
				}
			}
			foreach (string item in list)
			{
				RemoveRow(item);
			}
			foreach (KeyValuePair<string, string> item2 in dictionary)
			{
				ColorSync.TryGetColor(item2.Key, out var color);
				Color32 color2;
				Color val = (ColorSync.TryGetColor(item2.Key, out color2) ? Color32.op_Implicit(color) : ColorSync.GetColor(item2.Key));
				if (!_rows.TryGetValue(item2.Key, out var value))
				{
					value = CreateRow(item2.Key, item2.Value, val);
					_rows[item2.Key] = value;
				}
				else if (!value.Pending && !SameColor(value.Entry.Value, val))
				{
					SetSilently(value.Entry, val);
				}
			}
		}

		private Row CreateRow(string id, string name, Color current)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			string text = ((id.Length > 4) ? id.Substring(id.Length - 4) : id);
			string text2 = Sanitize(name) + " (" + text + ")";
			ConfigEntry<Color> val = _config.Bind<Color>("Admin - Player colors", text2, current, "Admin only: this player's marker color. Changing it changes it for everybody. Players keep the color you give them next time they join.");
			SetSilently(val, current);
			Row row = new Row
			{
				Id = id,
				Entry = val
			};
			val.SettingChanged += delegate
			{
				if (!_suppress)
				{
					row.Pending = true;
					row.SendAt = Time.unscaledTime + 0.5f;
				}
			};
			return row;
		}

		private void SetSilently(ConfigEntry<Color> entry, Color value)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			_suppress = true;
			try
			{
				entry.Value = value;
			}
			finally
			{
				_suppress = false;
			}
		}

		private void RemoveRow(string id)
		{
			if (_rows.TryGetValue(id, out var value))
			{
				_config.Remove(((ConfigEntryBase)value.Entry).Definition);
				_rows.Remove(id);
			}
		}

		private void RemoveAll()
		{
			if (_rows.Count == 0)
			{
				return;
			}
			foreach (Row value in _rows.Values)
			{
				_config.Remove(((ConfigEntryBase)value.Entry).Definition);
			}
			_rows.Clear();
		}

		private static bool SameColor(Color a, Color b)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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)
			Color32 val = ColorSync.ToColor32(a);
			Color32 val2 = ColorSync.ToColor32(b);
			if (val.r == val2.r && val.g == val2.g)
			{
				return val.b == val2.b;
			}
			return false;
		}

		private static string Sanitize(string name)
		{
			if (string.IsNullOrWhiteSpace(name))
			{
				return "Player";
			}
			string text = "=\n\t\\\"'[]";
			for (int i = 0; i < text.Length; i++)
			{
				name = name.Replace(text[i].ToString(), "");
			}
			name = name.Trim();
			if (name.Length != 0)
			{
				return name;
			}
			return "Player";
		}
	}
	internal static class Boats
	{
		private sealed class Boat
		{
			public string Id;

			public long Key;

			public string Name;

			public Vector3 Pos;

			public Ship Ship;

			public PinData Pin;
		}

		[HarmonyPatch(typeof(Ship), "Awake")]
		private static class Ship_Awake_Patch
		{
			private static void Postfix(Ship __instance)
			{
				Loaded.Add(__instance);
			}
		}

		[HarmonyPatch(typeof(ZNetScene), "Destroy")]
		private static class ZNetScene_Destroy_Patch
		{
			private static void Prefix(GameObject go)
			{
				if (Object.op_Implicit((Object)(object)go) && Known.Count != 0)
				{
					ZNetView val = (Object.op_Implicit((Object)(object)go.GetComponent<Ship>()) ? go.GetComponent<ZNetView>() : null);
					ZDO val2 = (Object.op_Implicit((Object)(object)val) ? val.GetZDO() : null);
					if (val2 != null)
					{
						Forget(((object)Unsafe.As<ZDOID, ZDOID>(ref val2.m_uid)/*cast due to .constrained prefix*/).ToString());
					}
				}
			}
		}

		private static readonly List<Ship> Loaded = new List<Ship>();

		private static readonly Dictionary<string, Boat> Known = new Dictionary<string, Boat>();

		private static readonly HashSet<string> OtherWorldLines = new HashSet<string>();

		private static readonly Dictionary<PinData, long> KeyOfPin = new Dictionary<PinData, long>();

		private static Minimap _map;

		private static string _world;

		private static float _loadedAt;

		private static float _nextCheck;

		private static bool _dirty;

		private static float _nextSave;

		private static Sprite _icon;

		private static readonly FieldRef<Minimap, List<PinData>> PinsRef = AccessTools.FieldRefAccess<Minimap, List<PinData>>("m_pins");

		private static string Path_ => Path.Combine(Paths.ConfigPath, "PlayerColorCompass.boats.txt");

		internal static bool TryGetKey(PinData pin, out long key)
		{
			key = 0L;
			if (pin != null && KeyOfPin.Count > 0)
			{
				return KeyOfPin.TryGetValue(pin, out key);
			}
			return false;
		}

		private static long MakeKey(ZDOID id)
		{
			return long.MinValue | ((((ZDOID)(ref id)).UserID & 0x3FFFFFFF) << 32) | ((ZDOID)(ref id)).ID;
		}

		private static Sprite Icon()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: 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_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_icon != (Object)null)
			{
				return _icon;
			}
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)1
			};
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.78f, 0.55f, 0.28f, 1f);
			Color val3 = default(Color);
			((Color)(ref val3))..ctor(0.95f, 0.93f, 0.85f, 1f);
			Color val4 = default(Color);
			((Color)(ref val4))..ctor(0.12f, 0.08f, 0.04f, 1f);
			Color[] array = (Color[])(object)new Color[4096];
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					Color val5 = Color.clear;
					float num = (float)j - 31.5f;
					bool flag = i >= 12 && i <= 30 && Mathf.Abs(num) <= 8f + (float)(i - 12) * 1.05f;
					bool flag2 = i >= 33 && i <= 58 && num >= 1.5f && num <= 4f + (float)(58 - i) * 0.85f && num <= 22f - (float)(i - 33) * 0.62f + 2f;
					bool num2 = Mathf.Abs(num) <= 1.5f && i >= 30 && i <= 60;
					if (flag)
					{
						val5 = val2;
					}
					if (flag2)
					{
						val5 = val3;
					}
					if (num2)
					{
						val5 = val4;
					}
					array[i * 64 + j] = val5;
				}
			}
			Color[] array2 = (Color[])array.Clone();
			for (int k = 1; k < 63; k++)
			{
				for (int l = 1; l < 63; l++)
				{
					if (array[k * 64 + l].a < 0.5f && (array[k * 64 + l - 1].a > 0.5f || array[k * 64 + l + 1].a > 0.5f || array[(k - 1) * 64 + l].a > 0.5f || array[(k + 1) * 64 + l].a > 0.5f))
					{
						array2[k * 64 + l] = val4;
					}
				}
			}
			val.SetPixels(array2);
			val.Apply();
			_icon = Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f));
			return _icon;
		}

		private static void Forget(string id)
		{
			if (Known.TryGetValue(id, out var value))
			{
				RemovePin(value);
				Known.Remove(id);
				_dirty = true;
			}
		}

		private static void RemovePin(Boat boat)
		{
			if (boat.Pin != null)
			{
				KeyOfPin.Remove(boat.Pin);
				if ((Object)(object)_map != (Object)null && PinsRef.Invoke(_map).Contains(boat.Pin))
				{
					_map.RemovePin(boat.Pin);
				}
				boat.Pin = null;
			}
		}

		private static void ClearPins()
		{
			foreach (Boat value in Known.Values)
			{
				RemovePin(value);
			}
			KeyOfPin.Clear();
		}

		internal static void Tick()
		{
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: 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_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			Minimap instance = Minimap.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)ZNet.instance == (Object)null || !Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				return;
			}
			if (!Plugin.ShowBoats.Value)
			{
				if (Known.Count > 0 && (Object)(object)_map != (Object)null)
				{
					ClearPins();
				}
				return;
			}
			if ((Object)(object)instance != (Object)(object)_map || _world != ZNet.instance.GetWorldName())
			{
				Load(instance);
			}
			for (int num = Loaded.Count - 1; num >= 0; num--)
			{
				Ship val = Loaded[num];
				if ((Object)(object)val == (Object)null)
				{
					Loaded.RemoveAt(num);
				}
				else
				{
					ZNetView component = ((Component)val).GetComponent<ZNetView>();
					ZDO val2 = (Object.op_Implicit((Object)(object)component) ? component.GetZDO() : null);
					if (val2 != null)
					{
						string text = ((object)Unsafe.As<ZDOID, ZDOID>(ref val2.m_uid)/*cast due to .constrained prefix*/).ToString();
						if (!Known.TryGetValue(text, out var value))
						{
							Piece component2 = ((Component)val).GetComponent<Piece>();
							string name = ((Object.op_Implicit((Object)(object)component2) && !string.IsNullOrEmpty(component2.m_name)) ? Localization.instance.Localize(component2.m_name) : ((Object)val).name.Replace("(Clone)", ""));
							value = new Boat
							{
								Id = text,
								Key = MakeKey(val2.m_uid),
								Name = name
							};
							Known[text] = value;
							_dirty = true;
						}
						value.Ship = val;
						Vector3 val3 = value.Pos - ((Component)val).transform.position;
						if (((Vector3)(ref val3)).sqrMagnitude > 1f)
						{
							_dirty = true;
						}
						value.Pos = ((Component)val).transform.position;
					}
				}
			}
			foreach (Boat value2 in Known.Values)
			{
				if ((Object)(object)value2.Ship == (Object)null && value2.Pin != null && value2.Pin.m_pos != value2.Pos)
				{
					value2.Pin.m_pos = value2.Pos;
				}
				if ((Object)(object)value2.Ship != (Object)null && value2.Pin != null)
				{
					value2.Pin.m_pos = value2.Pos;
				}
			}
			if (Time.time >= _nextCheck)
			{
				_nextCheck = Time.time + 1f;
				Housekeeping(instance);
			}
			if (_dirty && Time.time >= _nextSave)
			{
				_nextSave = Time.time + 10f;
				Save();
			}
		}

		private static void Housekeeping(Minimap map)
		{
			//IL_000a: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)Player.m_localPlayer).transform.position;
			List<string> list = null;
			List<PinData> list2 = PinsRef.Invoke(map);
			foreach (Boat value in Known.Values)
			{
				if ((Object)(object)value.Ship == (Object)null)
				{
					float num = position.x - value.Pos.x;
					float num2 = position.z - value.Pos.z;
					if (Time.time - _loadedAt > 20f && num * num + num2 * num2 < 1600f)
					{
						(list ?? (list = new List<string>())).Add(value.Id);
					}
				}
				if (value.Pin == null || !list2.Contains(value.Pin))
				{
					if (value.Pin != null)
					{
						KeyOfPin.Remove(value.Pin);
					}
					value.Pin = map.AddPin(value.Pos, (PinType)8, value.Name, false, false, 0L, default(PlatformUserID));
					value.Pin.m_icon = Icon();
					KeyOfPin[value.Pin] = value.Key;
				}
			}
			if (list == null)
			{
				return;
			}
			foreach (string item in list)
			{
				Forget(item);
			}
		}

		private static void Load(Minimap map)
		{
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_map != (Object)null)
			{
				ClearPins();
			}
			Known.Clear();
			OtherWorldLines.Clear();
			KeyOfPin.Clear();
			Loaded.RemoveAll((Ship s) => (Object)(object)s == (Object)null);
			_map = map;
			_world = ZNet.instance.GetWorldName();
			_loadedAt = Time.time;
			_dirty = false;
			try
			{
				if (!File.Exists(Path_))
				{
					return;
				}
				string[] array = File.ReadAllLines(Path_);
				foreach (string text in array)
				{
					string[] array2 = text.Split(new char[1] { '|' });
					if (array2.Length >= 6)
					{
						float result;
						float result2;
						float result3;
						ZDOID id;
						if (array2[0] != _world)
						{
							OtherWorldLines.Add(text);
						}
						else if (float.TryParse(array2[2], NumberStyles.Float, CultureInfo.InvariantCulture, out result) && float.TryParse(array2[3], NumberStyles.Float, CultureInfo.InvariantCulture, out result2) && float.TryParse(array2[4], NumberStyles.Float, CultureInfo.InvariantCulture, out result3) && TryParseId(array2[1], out id))
						{
							Known[array2[1]] = new Boat
							{
								Id = array2[1],
								Key = MakeKey(id),
								Name = array2[5],
								Pos = new Vector3(result, result2, result3)
							};
						}
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not read the remembered boats: " + ex.Message));
			}
		}

		private static bool TryParseId(string text, out ZDOID id)
		{
			//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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			id = ZDOID.None;
			string[] array = text.Split(new char[1] { ':' });
			if (array.Length != 2 || !long.TryParse(array[0], out var result) || !uint.TryParse(array[1], out var result2))
			{
				return false;
			}
			id = new ZDOID(result, result2);
			return true;
		}

		private static void Save()
		{
			_dirty = false;
			try
			{
				List<string> list = new List<string>(OtherWorldLines);
				foreach (Boat value in Known.Values)
				{
					list.Add(string.Join("|", _world, value.Id, value.Pos.x.ToString("R", CultureInfo.InvariantCulture), value.Pos.y.ToString("R", CultureInfo.InvariantCulture), value.Pos.z.ToString("R", CultureInfo.InvariantCulture), value.Name.Replace('|', '_')));
				}
				File.WriteAllLines(Path_, list.ToArray());
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not save the remembered boats: " + ex.Message));
			}
		}
	}
	internal static class ColorSync
	{
		[HarmonyPatch(typeof(ZNet), "OnNewConnection")]
		private static class ZNet_OnNewConnection_Patch
		{
			[CompilerGenerated]
			private static class <>O
			{
				public static Method <0>__RPC_Hello;

				public static Action<ZRpc, string> <1>__RPC_SetColor;

				public static Action<ZRpc, string, string> <2>__RPC_AdminSetColor;

				public static Action<ZRpc, bool> <3>__RPC_AdminSetShare;

				public static Action<ZRpc, ZPackage> <4>__RPC_Colors;

				public static Action<ZRpc, bool> <5>__RPC_Settings;
			}

			private static void Postfix(ZNet __instance, ZNetPeer peer)
			{
				//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)
				//IL_0031: Expected O, but got Unknown
				if (__instance.IsServer())
				{
					ZRpc rpc = peer.m_rpc;
					object obj = <>O.<0>__RPC_Hello;
					if (obj == null)
					{
						Method val = RPC_Hello;
						<>O.<0>__RPC_Hello = val;
						obj = (object)val;
					}
					rpc.Register("PCC_Hello", (Method)obj);
					peer.m_rpc.Register<string>("PCC_SetColor", (Action<ZRpc, string>)RPC_SetColor);
					peer.m_rpc.Register<string, string>("PCC_AdminSetColor", (Action<ZRpc, string, string>)RPC_AdminSetColor);
					peer.m_rpc.Register<bool>("PCC_AdminSetShare", (Action<ZRpc, bool>)RPC_AdminSetShare);
				}
				else
				{
					peer.m_rpc.Register<ZPackage>("PCC_Colors", (Action<ZRpc, ZPackage>)RPC_Colors);
					peer.m_rpc.Register<bool>("PCC_Settings", (Action<ZRpc, bool>)RPC_Settings);
				}
			}
		}

		[HarmonyPatch(typeof(ZNet), "Awake")]
		private static class ZNet_Awake_Patch
		{
			private static void Postfix(ZNet __instance)
			{
				ResetState();
				if (__instance.IsServer())
				{
					Load();
				}
				else
				{
					Colors.Clear();
				}
			}
		}

		private const string HelloRpc = "PCC_Hello";

		private const string SetColorRpc = "PCC_SetColor";

		private const string AdminSetColorRpc = "PCC_AdminSetColor";

		private const string ColorsRpc = "PCC_Colors";

		private const string SettingsRpc = "PCC_Settings";

		private const string AdminSetShareRpc = "PCC_AdminSetShare";

		private static readonly Dictionary<string, Color32> Colors = new Dictionary<string, Color32>();

		private static bool _reconciled;

		private static bool _pendingSend;

		private static bool _suppress;

		private static float _nextHello;

		private static int _helloAttempts;

		private static bool? _serverShare;

		private static bool _shareOriginalKnown;

		private static bool _shareOriginal;

		private static bool _shareSuppress;

		private static float _nextShareRefresh;

		private static string StorePath => Path.Combine(Paths.ConfigPath, "PlayerColorCompass.colors.txt");

		internal static bool ServerHasMod { get; private set; }

		internal static bool SharePinsEffective
		{
			get
			{
				if (!_serverShare.HasValue || !((Object)(object)ZNet.instance != (Object)null) || ZNet.instance.IsServer())
				{
					return Plugin.SharePins.Value;
				}
				return _serverShare.Value;
			}
		}

		internal static void MarkDirty()
		{
			if (!_suppress)
			{
				_pendingSend = true;
			}
		}

		private static void SetShareSilently(bool value)
		{
			if (Plugin.SharePins.Value == value)
			{
				return;
			}
			_shareSuppress = true;
			try
			{
				Plugin.SharePins.Value = value;
			}
			finally
			{
				_shareSuppress = false;
			}
		}

		internal static void OnShareSettingChanged()
		{
			if (_shareSuppress || (Object)(object)ZNet.instance == (Object)null)
			{
				return;
			}
			if (ZNet.instance.IsServer())
			{
				foreach (ZNetPeer peer in ZNet.instance.GetPeers())
				{
					ZRpc rpc = peer.m_rpc;
					if (rpc != null)
					{
						rpc.Invoke("PCC_Settings", new object[1] { Plugin.SharePins.Value });
					}
				}
				return;
			}
			if (!_serverShare.HasValue)
			{
				return;
			}
			if (LocalLooksLikeAdmin())
			{
				ZRpc serverRPC = ZNet.instance.GetServerRPC();
				if (serverRPC != null)
				{
					serverRPC.Invoke("PCC_AdminSetShare", new object[1] { Plugin.SharePins.Value });
				}
			}
			else
			{
				SetShareSilently(_serverShare.Value);
			}
		}

		private static void RefreshShareSetting()
		{
			if (!(Time.unscaledTime < _nextShareRefresh))
			{
				_nextShareRefresh = Time.unscaledTime + 1f;
				bool flag = _serverShare.HasValue && (Object)(object)ZNet.instance != (Object)null && !ZNet.instance.IsServer() && !LocalLooksLikeAdmin();
				Plugin.SharePinsTags.Browsable = !flag;
			}
		}

		private static void ResetState()
		{
			if (_serverShare.HasValue && _shareOriginalKnown)
			{
				SetShareSilently(_shareOriginal);
			}
			_serverShare = null;
			_shareOriginalKnown = false;
			ServerHasMod = false;
			_reconciled = false;
			_pendingSend = false;
			_nextHello = 0f;
			_helloAttempts = 0;
		}

		internal static void Tick()
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			RefreshShareSetting();
			ZNet instance = ZNet.instance;
			if ((Object)(object)instance == (Object)null)
			{
				ResetState();
			}
			else
			{
				if ((Object)(object)Player.m_localPlayer == (Object)null)
				{
					return;
				}
				if (instance.IsServer())
				{
					ServerHasMod = true;
					if (!_reconciled)
					{
						_reconciled = true;
						ReconcileWith(Colors.TryGetValue(LocalId(), out var value) ? new Color32?(value) : ((Color32?)null));
					}
					else if (_pendingSend)
					{
						_pendingSend = false;
						SetColor(LocalId(), ToColor32(Plugin.PlayerColor.Value), broadcast: true);
					}
				}
				else if (!ServerHasMod)
				{
					if (_helloAttempts < 4 && Time.unscaledTime >= _nextHello)
					{
						_helloAttempts++;
						_nextHello = Time.unscaledTime + 10f;
						ZRpc serverRPC = instance.GetServerRPC();
						if (serverRPC != null)
						{
							serverRPC.Invoke("PCC_Hello", Array.Empty<object>());
						}
						if (_helloAttempts == 4)
						{
							Plugin.Log.LogInfo((object)"The server did not answer: it does not have PlayerColorCompassAndQuickPinTweaks. Player markers and the admin color list stay hidden until the server has the mod.");
						}
					}
				}
				else if (_pendingSend)
				{
					_pendingSend = false;
					ZRpc serverRPC2 = instance.GetServerRPC();
					if (serverRPC2 != null)
					{
						serverRPC2.Invoke("PCC_SetColor", new object[1] { ToHex(ToColor32(Plugin.PlayerColor.Value)) });
					}
				}
			}
		}

		internal static string LocalId()
		{
			return ((object)Unsafe.As<PlatformUserID, PlatformUserID>(ref UserInfo.GetLocalUser().UserId)/*cast due to .constrained prefix*/).ToString();
		}

		private static void ReconcileWith(Color32? serverColor)
		{
			//IL_0012: 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)
			if (serverColor.HasValue && !_pendingSend)
			{
				AdoptColor(serverColor.Value);
				return;
			}
			_pendingSend = false;
			if ((Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer())
			{
				SetColor(LocalId(), ToColor32(Plugin.PlayerColor.Value), broadcast: true);
			}
			else
			{
				_pendingSend = true;
			}
		}

		private static void AdoptColor(Color32 color)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_002c: 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)
			Color32 val = ToColor32(Plugin.PlayerColor.Value);
			if (val.r == color.r && val.g == color.g && val.b == color.b)
			{
				return;
			}
			_suppress = true;
			try
			{
				Plugin.PlayerColor.Value = Color32.op_Implicit(color);
			}
			finally
			{
				_suppress = false;
			}
		}

		internal static bool TryGetColor(string platformId, out Color32 color)
		{
			return Colors.TryGetValue(platformId, out color);
		}

		internal static Color GetColor(string platformId)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if (!string.IsNullOrEmpty(platformId) && Colors.TryGetValue(platformId, out var value))
			{
				return Color32.op_Implicit(value);
			}
			return DefaultColorFor(platformId ?? "");
		}

		internal static Color DefaultColorFor(string text)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			int num = 17;
			foreach (char c in text)
			{
				num = num * 31 + c;
			}
			return Color.HSVToRGB((float)(num & 0xFFFF) / 65535f, 0.7f, 1f);
		}

		internal static bool LocalLooksLikeAdmin()
		{
			if ((Object)(object)ZNet.instance != (Object)null)
			{
				if (!ZNet.instance.LocalPlayerIsAdminOrHost())
				{
					return Terminal.m_cheat;
				}
				return true;
			}
			return false;
		}

		internal static void AdminSetColor(string targetId, Color color)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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 ((Object)(object)ZNet.instance == (Object)null || string.IsNullOrEmpty(targetId))
			{
				return;
			}
			Color32 val = ToColor32(color);
			if (ZNet.instance.IsServer())
			{
				SetColor(targetId, val, broadcast: true);
				if (targetId == LocalId())
				{
					AdoptColor(val);
				}
				return;
			}
			ZRpc serverRPC = ZNet.instance.GetServerRPC();
			if (serverRPC != null)
			{
				serverRPC.Invoke("PCC_AdminSetColor", new object[2]
				{
					targetId,
					ToHex(val)
				});
			}
		}

		private static void SetColor(string id, Color32 color, bool broadcast)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			if (!string.IsNullOrEmpty(id))
			{
				Colors[id] = color;
				Save();
				if (broadcast)
				{
					Broadcast();
				}
			}
		}

		private static ZPackage BuildTable()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			ZPackage val = new ZPackage();
			val.Write(Colors.Count);
			foreach (KeyValuePair<string, Color32> color in Colors)
			{
				val.Write(color.Key);
				val.Write(color.Value.r | (color.Value.g << 8) | (color.Value.b << 16));
			}
			return val;
		}

		private static void Broadcast()
		{
			if ((Object)(object)ZNet.instance == (Object)null)
			{
				return;
			}
			foreach (ZNetPeer peer in ZNet.instance.GetPeers())
			{
				ZRpc rpc = peer.m_rpc;
				if (rpc != null)
				{
					rpc.Invoke("PCC_Colors", new object[1] { BuildTable() });
				}
			}
		}

		private static void Load()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			Colors.Clear();
			try
			{
				if (!File.Exists(StorePath))
				{
					return;
				}
				string[] array = File.ReadAllLines(StorePath);
				foreach (string text in array)
				{
					int num = text.LastIndexOf('=');
					if (num > 0 && TryParseHex(text.Substring(num + 1), out var color))
					{
						Colors[text.Substring(0, num)] = color;
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not read the saved player colors: " + ex.Message));
			}
		}

		private static void Save()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				List<string> list = new List<string>();
				foreach (KeyValuePair<string, Color32> color in Colors)
				{
					list.Add(color.Key + "=" + ToHex(color.Value));
				}
				File.WriteAllLines(StorePath, list.ToArray());
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not save the player colors: " + ex.Message));
			}
		}

		private static void RPC_Hello(ZRpc rpc)
		{
			if (rpc != null)
			{
				rpc.Invoke("PCC_Colors", new object[1] { BuildTable() });
			}
			if (rpc != null)
			{
				rpc.Invoke("PCC_Settings", new object[1] { Plugin.SharePins.Value });
			}
		}

		private static void RPC_Settings(ZRpc rpc, bool share)
		{
			if (!_shareOriginalKnown)
			{
				_shareOriginal = Plugin.SharePins.Value;
				_shareOriginalKnown = true;
			}
			_serverShare = share;
			SetShareSilently(share);
		}

		private static void RPC_AdminSetShare(ZRpc rpc, bool share)
		{
			object obj;
			if (rpc == null)
			{
				obj = null;
			}
			else
			{
				ISocket socket = rpc.GetSocket();
				obj = ((socket != null) ? socket.GetHostName() : null);
			}
			string text = (string)obj;
			if (!string.IsNullOrEmpty(text))
			{
				ZNet instance = ZNet.instance;
				if (IsOnAdminList((instance != null) ? instance.GetAdminList() : null, text))
				{
					Plugin.Log.LogInfo((object)$"Admin {text} set SharePins = {share}");
					Plugin.SharePins.Value = share;
					return;
				}
			}
			Plugin.Log.LogWarning((object)("Ignored a SharePins change from non-admin " + text));
		}

		private static void RPC_SetColor(ZRpc rpc, string hex)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			object obj;
			if (rpc == null)
			{
				obj = null;
			}
			else
			{
				ISocket socket = rpc.GetSocket();
				obj = ((socket != null) ? socket.GetHostName() : null);
			}
			string text = (string)obj;
			if (!string.IsNullOrEmpty(text) && TryParseHex(hex, out var color))
			{
				SetColor(text, color, broadcast: true);
			}
		}

		private static void RPC_AdminSetColor(ZRpc rpc, string targetId, string hex)
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			object obj;
			if (rpc == null)
			{
				obj = null;
			}
			else
			{
				ISocket socket = rpc.GetSocket();
				obj = ((socket != null) ? socket.GetHostName() : null);
			}
			string text = (string)obj;
			ZNet instance = ZNet.instance;
			List<string> admins = ((instance != null) ? instance.GetAdminList() : null);
			Color32 color;
			if (string.IsNullOrEmpty(text) || !IsOnAdminList(admins, text))
			{
				Plugin.Log.LogWarning((object)("Ignored a color change for " + targetId + " from non-admin " + text));
			}
			else if (!string.IsNullOrEmpty(targetId) && targetId.Length <= 100 && TryParseHex(hex, out color))
			{
				SetColor(targetId, color, broadcast: true);
			}
		}

		internal static bool IsOnAdminList(List<string> admins, string connectionName)
		{
			if (admins == null)
			{
				return false;
			}
			int num = connectionName.IndexOf('_');
			string text = ((num >= 0) ? connectionName.Substring(num + 1) : connectionName);
			foreach (string admin in admins)
			{
				string text2 = admin?.Trim();
				if (!string.IsNullOrEmpty(text2) && (text2 == connectionName || text2 == text))
				{
					return true;
				}
			}
			return false;
		}

		private static void RPC_Colors(ZRpc rpc, ZPackage pkg)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			int num = pkg.ReadInt();
			Colors.Clear();
			for (int i = 0; i < num; i++)
			{
				string key = pkg.ReadString();
				int num2 = pkg.ReadInt();
				Colors[key] = new Color32((byte)(num2 & 0xFF), (byte)((num2 >> 8) & 0xFF), (byte)((num2 >> 16) & 0xFF), byte.MaxValue);
			}
			ServerHasMod = true;
			string text = LocalId();
			Color32 value;
			bool flag = Colors.TryGetValue(text, out value);
			if (!_reconciled)
			{
				_reconciled = true;
				Plugin.Log.LogInfo((object)("Joined a server with PlayerColorCompassAndQuickPinTweaks as " + text + "; the server " + (flag ? "knows" : "does not know") + " this player's color"));
				ReconcileWith(flag ? new Color32?(value) : ((Color32?)null));
			}
			else if (flag && !_pendingSend)
			{
				AdoptColor(value);
			}
		}

		internal static Color32 ToColor32(Color color)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			return new Color32((byte)Mathf.RoundToInt(Mathf.Clamp01(color.r) * 255f), (byte)Mathf.RoundToInt(Mathf.Clamp01(color.g) * 255f), (byte)Mathf.RoundToInt(Mathf.Clamp01(color.b) * 255f), byte.MaxValue);
		}

		private static string ToHex(Color32 c)
		{
			return c.r.ToString("X2") + c.g.ToString("X2") + c.b.ToString("X2");
		}

		private static bool TryParseHex(string hex, out Color32 color)
		{
			//IL_0001: 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)
			color = default(Color32);
			hex = hex?.Trim();
			if (hex == null || hex.Length != 6 || !int.TryParse(hex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var result))
			{
				return false;
			}
			color = new Color32((byte)((result >> 16) & 0xFF), (byte)((result >> 8) & 0xFF), (byte)(result & 0xFF), byte.MaxValue);
			return true;
		}
	}
	internal static class CompassHud
	{
		private class Marker
		{
			public RectTransform Rect;

			public Image Image;

			public TMP_Text Text;

			public RectTransform Glass;
		}

		private struct Entry
		{
			public Vector3 Position;

			public Sprite Sprite;

			public Color Color;

			public string Name;

			public bool IsPlayer;

			public bool Tracked;

			public float Distance;
		}

		[HarmonyPatch(typeof(Hud), "Awake")]
		private static class Hud_Awake_Patch
		{
			private static void Postfix()
			{
				Build();
			}
		}

		[HarmonyPatch(typeof(Hud), "Update")]
		private static class Hud_Update_Patch
		{
			private static void Postfix()
			{
				Update();
			}
		}

		[HarmonyPatch(typeof(Hud), "OnDestroy")]
		private static class Hud_OnDestroy_Patch
		{
			private static void Postfix()
			{
				Teardown();
			}
		}

		private static readonly int LayerUI = LayerMask.NameToLayer("UI");

		private static GameObject _parent;

		private static RectTransform _compassRect;

		private static RectTransform _pinsRoot;

		private static RectTransform _pinTemplate;

		private static Mask _mask;

		private static Image _maskImage;

		private static Sprite _markerSprite;

		private static float _compassWidth;

		private static float _height;

		private static readonly FieldRef<Minimap, GameObject> PinNamePrefabRef = AccessTools.FieldRefAccess<Minimap, GameObject>("m_pinNamePrefab");

		private static readonly FieldRef<Minimap, List<PinData>> PinsRef = AccessTools.FieldRefAccess<Minimap, List<PinData>>("m_pins");

		private static readonly List<Marker> Markers = new List<Marker>();

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

		internal static Sprite MarkerSprite
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)_markerSprite))
				{
					return _markerSprite = BuildMarkerSprite(50);
				}
				return _markerSprite;
			}
		}

		private static GameObject PinNamePrefab(Minimap minimap)
		{
			if (!Object.op_Implicit((Object)(object)minimap))
			{
				return null;
			}
			return PinNamePrefabRef.Invoke(minimap);
		}

		private static List<PinData> MapPins(Minimap minimap)
		{
			return PinsRef.Invoke(minimap);
		}

		private static Texture2D LoadEmbedded(string name)
		{
			//IL_0074: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name);
			if (stream == null)
			{
				return null;
			}
			byte[] array = new byte[stream.Length];
			int num;
			for (int i = 0; i < array.Length; i += num)
			{
				num = stream.Read(array, i, array.Length - i);
				if (num <= 0)
				{
					break;
				}
			}
			int num2 = BitConverter.ToInt32(array, 0);
			int num3 = BitConverter.ToInt32(array, 4);
			byte[] array2 = new byte[num2 * num3 * 4];
			Buffer.BlockCopy(array, 8, array2, 0, array2.Length);
			Texture2D val = new Texture2D(num2, num3, (TextureFormat)4, false, true);
			val.LoadRawTextureData(array2);
			val.Apply();
			((Texture)val).wrapMode = (TextureWrapMode)1;
			return val;
		}

		private static Sprite MakeSprite(Texture2D texture, int width)
		{
			//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)
			return Sprite.Create(texture, new Rect(0f, 0f, (float)width, (float)((Texture)texture).height), Vector2.zero);
		}

		private static GameObject NewObject(string name, Transform parent)
		{
			//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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) })
			{
				layer = LayerUI
			};
			val.transform.SetParent(parent, false);
			return val;
		}

		private static Image AddImage(GameObject go, Sprite sprite, int width, int height)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			go.GetComponent<RectTransform>().sizeDelta = new Vector2((float)width, (float)height);
			Image obj = go.AddComponent<Image>();
			obj.sprite = sprite;
			obj.preserveAspect = true;
			return obj;
		}

		private static Sprite BuildMarkerSprite(int size)
		{
			//IL_0004: 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_0011: Expected O, but got Unknown
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(size, size, (TextureFormat)4, false)
			{
				wrapMode = (TextureWrapMode)1
			};
			float num = (float)(size - 1) / 2f;
			float num2 = (float)size * 0.3f;
			float num3 = num2 - 2.5f;
			for (int i = 0; i < size; i++)
			{
				for (int j = 0; j < size; j++)
				{
					float num4 = Vector2.Distance(new Vector2((float)j, (float)i), new Vector2(num, num));
					Color val2 = Color.clear;
					if (num4 <= num3)
					{
						val2 = Color.white;
					}
					else if (num4 <= num2)
					{
						((Color)(ref val2))..ctor(0f, 0f, 0f, 0.85f);
					}
					val.SetPixel(j, i, val2);
				}
			}
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, (float)size, (float)size), new Vector2(0.5f, 0.5f));
		}

		private static void Build()
		{
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			string text = (Plugin.DetailedMode.Value ? "_detailed" : "");
			Texture2D val = LoadEmbedded("compass" + text + ".rgba");
			Texture2D val2 = LoadEmbedded("mask" + text + ".rgba");
			Texture2D val3 = LoadEmbedded("center" + text + ".rgba");
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null)
			{
				Plugin.Log.LogWarning((object)"Compass images could not be loaded");
				return;
			}
			_height = ((Texture)val).height;
			_compassWidth = ((Texture)val).width;
			_parent = NewObject("PlayerColorCompass", Hud.instance.m_rootObject.transform);
			_parent.layer = LayerUI;
			GameObject val4 = NewObject("Clip", _parent.transform);
			val4.AddComponent<RectMask2D>();
			val4.GetComponent<RectTransform>().sizeDelta = new Vector2(1600f, 400f);
			int num = ((Texture)val).width / 2;
			GameObject val5 = NewObject("Mask", val4.transform);
			_maskImage = AddImage(val5, MakeSprite(val2, num), num, ((Texture)val2).height);
			_mask = val5.AddComponent<Mask>();
			_mask.showMaskGraphic = false;
			GameObject obj = NewObject("Compass", val5.transform);
			AddImage(obj, MakeSprite(val, ((Texture)val).width), ((Texture)val).width, ((Texture)val).height);
			_compassRect = obj.GetComponent<RectTransform>();
			AddImage(NewObject("Center", val4.transform), MakeSprite(val3, ((Texture)val3).width), ((Texture)val3).width, ((Texture)val3).height);
			_pinsRoot = NewObject("Markers", val5.transform).GetComponent<RectTransform>();
			_pinsRoot.sizeDelta = new Vector2((float)num, (float)((Texture)val).height);
			_pinTemplate = NewObject("MarkerTemplate", _parent.transform).GetComponent<RectTransform>();
			((Component)_pinTemplate).gameObject.AddComponent<Image>();
			_pinTemplate.sizeDelta = new Vector2(_height, _height);
			GameObject obj2 = PinNamePrefab(Minimap.instance);
			Transform val6 = ((obj2 != null) ? obj2.transform.Find("Name") : null);
			if ((Object)(object)val6 != (Object)null)
			{
				GameObject obj3 = Object.Instantiate<GameObject>(((Component)val6).gameObject, (Transform)(object)_pinTemplate);
				((Object)obj3).name = "Name";
				obj3.SetActive(false);
			}
			((Component)_pinTemplate).gameObject.SetActive(false);
			ApplyLayout();
		}

		private static void ApplyLayout()
		{
			//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)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)_parent))
			{
				_parent.SetActive(Plugin.Enabled.Value);
				RectTransform component = _parent.GetComponent<RectTransform>();
				((Transform)component).localScale = Vector3.one * Plugin.HudScale.Value;
				component.anchorMin = new Vector2(0.5f, 1f);
				component.anchorMax = new Vector2(0.5f, 1f);
				component.anchoredPosition = new Vector2(0f, (0f - _height) / 2f) + new Vector2(Plugin.HudOffset.Value.x, 0f - Plugin.HudOffset.Value.y);
			}
		}

		internal static void Rebuild()
		{
			if (Object.op_Implicit((Object)(object)_parent))
			{
				Object.Destroy((Object)(object)_parent);
			}
			Teardown();
			if ((Object)(object)Hud.instance != (Object)null && (Object)(object)Hud.instance.m_rootObject != (Object)null)
			{
				Build();
			}
		}

		private static void Teardown()
		{
			_parent = null;
			_compassRect = null;
			_pinsRoot = null;
			_pinTemplate = null;
			_mask = null;
			_maskImage = null;
			Markers.Clear();
		}

		private static void Update()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)_parent) || !Object.op_Implicit((Object)(object)Player.m_localPlayer) || !Object.op_Implicit((Object)(object)GameCamera.instance))
			{
				return;
			}
			ApplyLayout();
			if (Plugin.Enabled.Value)
			{
				Transform transform = ((Component)GameCamera.instance).transform;
				float num = transform.eulerAngles.y;
				if (num > 180f)
				{
					num -= 360f;
				}
				num *= -(float)Math.PI / 180f;
				Vector3 val = Vector3.right * (_compassWidth / 2f) * num / ((float)Math.PI * 2f) - new Vector3(_compassWidth * 0.125f, 0f, 0f);
				if (((Transform)_compassRect).localPosition != val)
				{
					((Transform)_compassRect).localPosition = val;
				}
				CollectEntries(((Component)Player.m_localPlayer).transform.position);
				DrawMarkers(transform);
			}
		}

		private unsafe static void CollectEntries(Vector3 from)
		{
			//IL_0037: 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_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: 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_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Invalid comparison between Unknown and I4
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			Entries.Clear();
			if ((Object)(object)Minimap.instance != (Object)null)
			{
				Vector3 val = (Plugin.OnlyLastDeath.Value ? Game.instance.GetPlayerProfile().GetDeathPoint() : Vector3.zero);
				foreach (PinData item in MapPins(Minimap.instance))
				{
					if (item == null || !Object.op_Implicit((Object)(object)item.m_icon))
					{
						continue;
					}
					bool flag = Pins.IsTracked(item);
					if ((flag || IsWantedPinType(item.m_type)) && (flag || Plugin.ShowMapPins.Value) && (flag || (int)item.m_type != 4 || !Plugin.OnlyLastDeath.Value || !(item.m_pos != val)))
					{
						float num = Distance2D(from, item.m_pos);
						if (flag || !(num > Plugin.MaxPinDistance.Value))
						{
							Entries.Add(new Entry
							{
								Position = item.m_pos,
								Sprite = item.m_icon,
								Color = Pins.TintOf(item),
								Name = ((Plugin.ShowPinNames.Value && !string.IsNullOrWhiteSpace(item.m_name)) ? Localization.instance.Localize(item.m_name) : null),
								IsPlayer = false,
								Tracked = flag,
								Distance = num
							});
						}
					}
				}
			}
			if (Plugin.ShowPlayers.Value && ColorSync.ServerHasMod && (Object)(object)ZNet.instance != (Object)null)
			{
				ZDOID zDOID = ((Character)Player.m_localPlayer).GetZDOID();
				foreach (PlayerInfo player in ZNet.instance.GetPlayerList())
				{
					if (player.m_publicPosition && !(player.m_characterID == zDOID))
					{
						PlatformUserID id = player.m_userInfo.m_id;
						string platformId = ((object)(*(PlatformUserID*)(&id))/*cast due to .constrained prefix*/).ToString();
						Entries.Add(new Entry
						{
							Position = player.m_position,
							Sprite = MarkerSprite,
							Color = ColorSync.GetColor(platformId),
							Name = (Plugin.ShowPlayerNames.Value ? player.m_name : null),
							IsPlayer = true,
							Distance = Distance2D(from, player.m_position)
						});
					}
				}
			}
			if (Plugin.TestMarkers.Value)
			{
				string[] array = new string[3] { "Test North", "Test East", "Test South-West" };
				Vector3[] array2 = (Vector3[])(object)new Vector3[3]
				{
					new Vector3(0f, 0f, 120f),
					new Vector3(200f, 0f, 0f),
					new Vector3(-90f, 0f, -90f)
				};
				for (int i = 0; i < array.Length; i++)
				{
					Entries.Add(new Entry
					{
						Position = from + array2[i],
						Sprite = MarkerSprite,
						Color = ColorSync.DefaultColorFor(array[i]),
						Name = (Plugin.ShowPlayerNames.Value ? array[i] : null),
						IsPlayer = true,
						Distance = ((Vector3)(ref array2[i])).magnitude
					});
				}
			}
			Entries.Sort((Entry a, Entry b) => (a.Tracked == b.Tracked) ? b.Distance.CompareTo(a.Distance) : a.Tracked.CompareTo(b.Tracked));
		}

		private static float Distance2D(Vector3 a, Vector3 b)
		{
			//IL_0000: 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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			float num = a.x - b.x;
			float num2 = a.z - b.z;
			return Mathf.Sqrt(num * num + num2 * num2);
		}

		private static bool IsWantedPinType(PinType type)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected I4, but got Unknown
			switch ((int)type)
			{
			case 0:
			case 1:
			case 2:
			case 3:
			case 4:
			case 5:
			case 6:
			case 9:
			case 14:
			case 15:
			case 16:
				return true;
			default:
				return false;
			}
		}

		private static string BuildLabel(Entry entry)
		{
			bool flag = !string.IsNullOrEmpty(entry.Name);
			string text = null;
			if (entry.IsPlayer ? Plugin.ShowPlayerDistance.Value : Plugin.ShowPinDistance.Value)
			{
				text = ((entry.Distance >= 1000f) ? $"{entry.Distance / 1000f:0.0} km" : $"{Mathf.RoundToInt(entry.Distance)} m");
			}
			if (flag && text != null)
			{
				return entry.Name + "\n<size=75%>" + text + "</size>";
			}
			if (flag)
			{
				return entry.Name;
			}
			return text;
		}

		private static void DrawMarkers(Transform anchor)
		{
			//IL_0045: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: Unknown result type (might be due to invalid IL or missing references)
			//IL_033c: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_050c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0513: Unknown result type (might be due to invalid IL or missing references)
			//IL_0525: Unknown result type (might be due to invalid IL or missing references)
			//IL_054a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0551: Unknown result type (might be due to invalid IL or missing references)
			//IL_056c: Unknown result type (might be due to invalid IL or missing references)
			while (Markers.Count < Entries.Count)
			{
				RectTransform val = Object.Instantiate<RectTransform>(_pinTemplate, (Transform)(object)_pinsRoot);
				((Component)val).gameObject.SetActive(true);
				GameObject val2 = NewObject("Glass", (Transform)(object)_pinsRoot);
				Image obj = val2.AddComponent<Image>();
				obj.sprite = Pins.StarSprite;
				((Graphic)obj).color = Pins.StarColor;
				((Graphic)obj).raycastTarget = false;
				val2.SetActive(false);
				List<Marker> markers = Markers;
				Marker obj2 = new Marker
				{
					Rect = val,
					Image = ((Component)val).GetComponent<Image>()
				};
				Transform obj3 = ((Transform)val).Find("Name");
				obj2.Text = ((obj3 != null) ? ((Component)obj3).GetComponent<TMP_Text>() : null);
				obj2.Glass = val2.GetComponent<RectTransform>();
				markers.Add(obj2);
			}
			Vector3 position = anchor.position;
			Matrix4x4 worldToLocalMatrix = anchor.worldToLocalMatrix;
			bool flag = false;
			Vector2 val4 = default(Vector2);
			for (int i = 0; i < Markers.Count; i++)
			{
				Marker marker = Markers[i];
				if (i >= Entries.Count)
				{
					if (((Component)marker.Rect).gameObject.activeSelf)
					{
						((Component)marker.Rect).gameObject.SetActive(false);
					}
					if ((Object)(object)marker.Glass != (Object)null && ((Component)marker.Glass).gameObject.activeSelf)
					{
						((Component)marker.Glass).gameObject.SetActive(false);
					}
					continue;
				}
				Entry entry = Entries[i];
				if (!((Component)marker.Rect).gameObject.activeSelf)
				{
					((Component)marker.Rect).gameObject.SetActive(true);
				}
				float num = (entry.IsPlayer ? Plugin.PlayerMarkerScale.Value : 1f);
				float num2 = 1f;
				if (!entry.Tracked && Plugin.DistanceScaling.Value && (!entry.IsPlayer || Plugin.ShrinkDistantPlayers.Value))
				{
					float value = Plugin.NearDistance.Value;
					float num3 = Mathf.Max(Plugin.FarDistance.Value, value + 1f);
					num *= Mathf.Lerp(1f, Plugin.FarScale.Value, Mathf.InverseLerp(value, num3, entry.Distance));
					num2 = Mathf.Lerp(1f, Plugin.FarAlpha.Value, Mathf.InverseLerp(num3, Mathf.Max(Plugin.MaxPinDistance.Value, num3 + 1f), entry.Distance));
				}
				marker.Image.sprite = entry.Sprite;
				Color color = entry.Color;
				color.a = num2;
				((Graphic)marker.Image).color = color;
				marker.Rect.sizeDelta = new Vector2(_height, _height);
				((Transform)marker.Rect).localScale = Vector3.one * num;
				((Transform)marker.Glass).SetSiblingIndex(2 * i);
				((Transform)marker.Rect).SetSiblingIndex(2 * i + 1);
				Vector3 val3 = ((Matrix4x4)(ref worldToLocalMatrix)).MultiplyPoint3x4(new Vector3(entry.Position.x, position.y, entry.Position.z));
				float num4 = Mathf.Atan2(val3.x, val3.z);
				((Transform)marker.Rect).localPosition = Vector3.right * (_compassWidth / 2f) * num4 / ((float)Math.PI * 2f);
				if (((Component)marker.Glass).gameObject.activeSelf != entry.Tracked)
				{
					((Component)marker.Glass).gameObject.SetActive(entry.Tracked);
				}
				if (entry.Tracked)
				{
					marker.Glass.sizeDelta = new Vector2(_height, _height) * 1.5f;
					((Transform)marker.Glass).localScale = Vector3.one * num;
					((Transform)marker.Glass).localPosition = ((Transform)marker.Rect).localPosition;
				}
				string text = BuildLabel(entry);
				bool flag2 = (Object)(object)marker.Text != (Object)null && text != null;
				if ((Object)(object)marker.Text != (Object)null && ((Component)marker.Text).gameObject.activeSelf != flag2)
				{
					((Component)marker.Text).gameObject.SetActive(flag2);
				}
				if (flag2)
				{
					flag = true;
					marker.Text.enableAutoSizing = false;
					marker.Text.fontSize = (entry.IsPlayer ? Plugin.PlayerNameFontSize.Value : Plugin.PinNameFontSize.Value);
					((Graphic)marker.Text).color = (Color)(entry.IsPlayer ? color : new Color(1f, 1f, 1f, num2));
					marker.Text.richText = true;
					marker.Text.SetText(text);
					marker.Text.verticalAlignment = (VerticalAlignmentOptions)256;
					RectTransform rectTransform = marker.Text.rectTransform;
					((Vector2)(ref val4))..ctor(0.5f, 0.5f);
					rectTransform.anchorMax = val4;
					rectTransform.anchorMin = val4;
					rectTransform.pivot = new Vector2(0.5f, 1f);
					float num5 = ((num > 0.0001f) ? (1f / num) : 0f);
					((Transform)rectTransform).localScale = Vector3.one * num5;
					rectTransform.anchoredPosition = new Vector2(0f, (0f - _height) / 2f);
				}
			}
			if (((Behaviour)_mask).enabled == flag)
			{
				((Behaviour)_mask).enabled = !flag;
				((Behaviour)_maskImage).enabled = !flag;
			}
		}
	}
	internal static class MinimapColors
	{
		[HarmonyPatch(typeof(Minimap), "UpdatePins")]
		private static class Minimap_UpdatePins_Patch
		{
			private unsafe static void Postfix(Minimap __instance)
			{
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_0077: Unknown result type (might be due to invalid IL or missing references)
				//IL_0090: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00df: Unknown result type (might be due to invalid IL or missing references)
				//IL_0107: Unknown result type (might be due to invalid IL or missing references)
				if (!Plugin.ColorMapIcons.Value || !ColorSync.ServerHasMod)
				{
					return;
				}
				List<PinData> list = PlayerPinsRef.Invoke(__instance);
				List<PlayerInfo> list2 = PlayerInfoRef.Invoke(__instance);
				if (list == null || list2 == null)
				{
					return;
				}
				int num = Mathf.Min(list.Count, list2.Count);
				for (int i = 0; i < num; i++)
				{
					PinData val = list[i];
					if (!((Object)(object)val?.m_iconElement == (Object)null))
					{
						PlayerInfo val2 = list2[i];
						Color color = ColorSync.GetColor(((object)(*(PlatformUserID*)(&val2.m_userInfo.m_id))/*cast due to .constrained prefix*/).ToString());
						color.a = ((Graphic)val.m_iconElement).color.a;
						if ((Object)(object)val.m_iconElement.sprite != (Object)(object)CompassHud.MarkerSprite)
						{
							val.m_iconElement.sprite = CompassHud.MarkerSprite;
						}
						((Graphic)val.m_iconElement).color = color;
						PinNameData namePinData = val.m_NamePinData;
						TMP_Text val3 = ((namePinData != null) ? namePinData.PinNameText : null);
						if ((Object)(object)val3 != (Object)null)
						{
							((Graphic)val3).color = color;
						}
					}
				}
			}
		}

		private static readonly FieldRef<Minimap, List<PinData>> PlayerPinsRef = AccessTools.FieldRefAccess<Minimap, List<PinData>>("m_playerPins");

		private static readonly FieldRef<Minimap, List<PlayerInfo>> PlayerInfoRef = AccessTools.FieldRefAccess<Minimap, List<PlayerInfo>>("m_tempPlayerInfo");
	}
	internal static class Pins
	{
		private sealed class StoredPin
		{
			public int Type;

			public Vector3 Pos;

			public string Name = "";

			public bool Checked;

			public string Hex = "";
		}

		[HarmonyPatch(typeof(ZNet), "OnNewConnection")]
		private static class ZNet_OnNewConnection_Patch
		{
			[CompilerGenerated]
			private static class <>O
			{
				public static Action<ZRpc, int, Vector3, string> <0>__RPC_Add;

				public static Action<ZRpc, int, Vector3> <1>__RPC_Remove;

				public static Action<ZRpc, int, Vector3, string> <2>__RPC_Rename;

				public static Action<ZRpc, int, Vector3, bool> <3>__RPC_Check;

				public static Action<ZRpc, int, Vector3, string> <4>__RPC_Tint;

				public static Method <5>__RPC_ForceSync;

				public static Method <6>__RPC_SendPins;

				public static Action<ZRpc, bool> <7>__RPC_AdminSetReplace;

				public static Action<ZRpc, ZPackage> <8>__HandleHello;

				public static Action<ZRpc, ZPackage> <9>__ApplySnapshot;
			}

			private static void Postfix(ZNetPeer peer)
			{
				//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fd: Expected O, but got Unknown
				//IL_011d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0122: Unknown result type (might be due to invalid IL or missing references)
				//IL_0128: Expected O, but got Unknown
				peer.m_rpc.Register<int, Vector3, string>("PCC_PinAdd", (Action<ZRpc, int, Vector3, string>)RPC_Add);
				peer.m_rpc.Register<int, Vector3>("PCC_PinRemove", (Action<ZRpc, int, Vector3>)RPC_Remove);
				peer.m_rpc.Register<int, Vector3, string>("PCC_PinRename", (Action<ZRpc, int, Vector3, string>)RPC_Rename);
				peer.m_rpc.Register<int, Vector3, bool>("PCC_PinCheck", (Action<ZRpc, int, Vector3, bool>)RPC_Check);
				peer.m_rpc.Register<int, Vector3, string>("PCC_PinTint", (Action<ZRpc, int, Vector3, string>)RPC_Tint);
				ZRpc rpc = peer.m_rpc;
				object obj = <>O.<5>__RPC_ForceSync;
				if (obj == null)
				{
					Method val = RPC_ForceSync;
					<>O.<5>__RPC_ForceSync = val;
					obj = (object)val;
				}
				rpc.Register("PCC_PinForceSync", (Method)obj);
				ZRpc rpc2 = peer.m_rpc;
				object obj2 = <>O.<6>__RPC_SendPins;
				if (obj2 == null)
				{
					Method val2 = RPC_SendPins;
					<>O.<6>__RPC_SendPins = val2;
					obj2 = (object)val2;
				}
				rpc2.Register("PCC_PinSendAll", (Method)obj2);
				peer.m_rpc.Register<bool>("PCC_AdminSetReplace", (Action<ZRpc, bool>)RPC_AdminSetReplace);
				QuickPin.RegisterRpcs(peer.m_rpc);
				peer.m_rpc.Register<ZPackage>("PCC_PinHello", (Action<ZRpc, ZPackage>)HandleHello);
				peer.m_rpc.Register<ZPackage>("PCC_PinSnapshot", (Action<ZRpc, ZPackage>)ApplySnapshot);
			}
		}

		[HarmonyPatch(typeof(Minimap), "ShowPinNameInput")]
		private static class Minimap_ShowPinNameInput_Patch
		{
			private static void Postfix(Minimap __instance)
			{
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Expected I4, but got Unknown
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				PinData val = NamePinRef.Invoke(__instance);
				if (ColorSync.SharePinsEffective && IsShared(val))
				{
					Send("PCC_PinAdd", (int)val.m_type, val.m_pos, "");
				}
			}
		}

		[HarmonyPatch(typeof(Minimap), "OnPinTextEntered")]
		private static class Minimap_OnPinTextEntered_Patch
		{
			private static PinData _pin;

			private static string _before;

			private static void Prefix(Minimap __instance)
			{
				_pin = NamePinRef.Invoke(__instance);
				_before = _pin?.m_name;
			}

			private static void Postfix()
			{
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: Expected I4, but got Unknown
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				PinData pin = _pin;
				_pin = null;
				if (pin != null && ColorSync.SharePinsEffective && IsShared(pin) && pin.m_name != _before)
				{
					Send("PCC_PinRename", (int)pin.m_type, pin.m_pos, pin.m_name);
				}
			}
		}

		[HarmonyPatch(typeof(Minimap), "RemovePin", new Type[] { typeof(PinData) })]
		private static class Minimap_RemovePin_Patch
		{
			private static void Prefix(PinData pin)
			{
				//IL_0028: 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: Expected I4, but got Unknown
				//IL_005b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0065: Expected I4, but got Unknown
				//IL_0069: Unknown result type (might be due to invalid IL or missing references)
				if (pin != null && !_remote)
				{
					if (pin.m_save)
					{
						SetTracked(pin, on: false);
					}
					if (IsShared(pin))
					{
						SharedTints.Remove(PinKey((int)pin.m_type, pin.m_pos));
					}
					if (ColorSync.SharePinsEffective && IsShared(pin))
					{
						Send("PCC_PinRemove", (int)pin.m_type, pin.m_pos);
					}
				}
			}
		}

		[HarmonyPatch(typeof(Minimap), "OnMapLeftClick")]
		private static class Minimap_OnMapLeftClick_Patch
		{
			private static readonly Dictionary<PinData, bool> Before = new Dictionary<PinData, bool>();

			private static void Prefix(Minimap __instance)
			{
				Before.Clear();
				foreach (PinData item in PinsRef.Invoke(__instance))
				{
					if (item != null)
					{
						Before[item] = item.m_checked;
					}
				}
			}

			private static void Postfix(Minimap __instance)
			{
				//IL_0089: Unknown result type (might be due to invalid IL or missing references)
				//IL_0093: Expected I4, but got Unknown
				//IL_0097: Unknown result type (might be due to invalid IL or missing references)
				bool flag = false;
				foreach (PinData item in PinsRef.Invoke(__instance))
				{
					if (item != null && Before.TryGetValue(item, out var value) && item.m_checked != value)
					{
						flag = true;
						if (value)
						{
							SetTracked(item, on: true);
						}
						else if (IsTracked(item))
						{
							item.m_checked = false;
							SetTracked(item, on: false);
						}
						if (item.m_checked != value && ColorSync.SharePinsEffective && IsShared(item))
						{
							Send("PCC_PinCheck", (int)item.m_type, item.m_pos, item.m_checked);
						}
					}
				}
				Before.Clear();
				if (!flag)
				{
					ClickWorldPin(__instance);
				}
			}

			private static void ClickWorldPin(Minimap map)
			{
				//IL_0028: 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_003d: 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_0095: Invalid comparison between Unknown and I4
				//IL_00b9: 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)
				Traverse val = Traverse.Create((object)map);
				Vector3 value = val.Method("ScreenToWorldPoint", new Type[1] { typeof(Vector3) }, new object[1] { ZInput.pointerPosition }).GetValue<Vector3>();
				float value2 = val.Property("PinInteractRadius", (object[])null).GetValue<float>();
				PinData val2 = null;
				float num = float.MaxValue;
				foreach (PinData item in PinsRef.Invoke(map))
				{
					if (item != null && !item.m_save && item.m_ownerID == 0L && (int)item.m_type == 8 && !((Object)(object)item.m_iconElement == (Object)null) && ((Component)item.m_iconElement).gameObject.activeInHierarchy)
					{
						float num2 = Utils.DistanceXZ(value, item.m_pos);
						if (num2 < value2 && num2 < num)
						{
							val2 = item;
							num = num2;
						}
					}
				}
				if (val2 != null)
				{
					if (IsTracked(val2))
					{
						SetTracked(val2, on: false);
					}
					else if (val2.m_checked)
					{
						val2.m_checked = false;
						SetTracked(val2, on: true);
					}
					else
					{
						val2.m_checked = true;
					}
				}
			}
		}

		[HarmonyPatch(typeof(Minimap), "UpdatePins")]
		private static class Minimap_UpdatePins_Patch
		{
			private static readonly Dictionary<PinData, RectTransform> Glasses = new Dictionary<PinData, RectTransform>();

			private static void Postfix(Minimap __instance)
			{
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
				//IL_0100: Unknown result type (might be due to invalid IL or missing references)
				//IL_010d: Unknown result type (might be due to invalid IL or missing references)
				//IL_011a: Unknown result type (might be due to invalid IL or missing references)
				//IL_011f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0123: Unknown result type (might be due to invalid IL or missing references)
				//IL_012d: Unknown result type (might be due to invalid IL or missing references)
				foreach (PinData item in PinsRef.Invoke(__instance))
				{
					if ((Object)(object)item?.m_iconElement == (Object)null)
					{
						continue;
					}
					if (IsShared(item))
					{
						Color val = TintOf(item);
						if (((Graphic)item.m_iconElement).color != val)
						{
							((Graphic)item.m_iconElement).color = val;
						}
					}
					RectTransform uiElement = item.m_uiElement;
					RectTransform value2;
					if (IsTracked(item) && (Object)(object)uiElement != (Object)null && ((Component)uiElement).gameObject.activeInHierarchy)
					{
						if (!Glasses.TryGetValue(item, out var value) || (Object)(object)value == (Object)null)
						{
							value = (Glasses[item] = CreateGlass(((Transform)uiElement).parent));
						}
						if ((Object)(object)((Transform)value).parent != (Object)(object)((Transform)uiElement).parent)
						{
							((Transform)value).SetParent(((Transform)uiElement).parent, false);
						}
						value.anchorMin = uiElement.anchorMin;
						value.anchorMax = uiElement.anchorMax;
						value.pivot = uiElement.pivot;
						value.anchoredPosition = uiElement.anchoredPosition;
						RectTransform obj = value;
						Rect rect = uiElement.rect;
						obj.sizeDelta = ((Rect)(ref rect)).size * 1.5f;
						if (!((Component)value).gameObject.activeSelf)
						{
							((Component)value).gameObject.SetActive(true);
						}
						if (((Transform)value).GetSiblingIndex() > ((Transform)uiElement).GetSiblingIndex())
						{
							((Transform)value).SetSiblingIndex(((Transform)uiElement).GetSiblingIndex());
						}
					}
					else if (Glasses.TryGetValue(item, out value2) && (Object)(object)value2 != (Object)null && ((Component)value2).gameObject.activeSelf)
					{
						((Component)value2).gameObject.SetActive(false);
					}
				}
				if (Glasses.Count <= 0)
				{
					return;
				}
				List<PinData> list = null;
				foreach (KeyValuePair<PinData, RectTransform> glass in Glasses)
				{
					PinData key = glass.Key;
					if ((Object)(object)glass.Value == (Object)null || key == null || (Object)(object)key.m_uiElement == (Object)null || !PinsRef.Invoke(__instance).Contains(key))
					{
						(list ?? (list = new List<PinData>())).Add(key);
					}
				}
				if (list == null)
				{
					return;
				}
				foreach (PinData item2 in list)
				{
					if (item2 != null && Glasses.TryGetValue(item2, out var value3) && (Object)(object)value3 != (Object)null)
					{
						Object.Destroy((Object)(object)((Component)value3).gameObject);
					}
					Glasses.Remove(item2);
				}
			}

			private static RectTransform CreateGlass(Transform parent)
			{
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: 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)
				GameObject val = new GameObject("PCC_Star", new Type[2]
				{
					typeof(RectTransform),
					typeof(Image)
				})
				{
					layer = ((Component)parent).gameObject.layer
				};
				val.transform.SetParent(parent, false);
				Image component = val.GetComponent<Image>();
				component.sprite = StarSprite;
				((Graphic)component).color = StarColor;
				((Graphic)component).raycastTarget = false;
				return val.GetComponent<RectTransform>();
			}
		}

		private const string AddRpc = "PCC_PinAdd";

		private const string RemoveRpc = "PCC_PinRemove";

		private const string RenameRpc = "PCC_PinRename";

		private const string CheckRpc = "PCC_PinCheck";

		private const string ForceSyncRpc = "PCC_PinForceSync";

		private const string SendPinsRpc = "PCC_PinSendAll";

		private const string StarName = "PCC_Star";

		private static readonly FieldRef<Minimap, PinData> NamePinRef = AccessTools.FieldRefAccess<Minimap, PinData>("m_namePin");

		private static readonly FieldRef<Minimap, List<PinData>> PinsRef = AccessTools.FieldRefAccess<Minimap, List<PinData>>("m_pins");

		private static bool _remote;

		private const string TintRpc = "PCC_PinTint";

		private static readonly Dictionary<string, Color> SharedTints = new Dictionary<string, Color>();

		private static int _tintSeen = -1;

		private static float _tintAt;

		private static bool _tintPending;

		private static readonly HashSet<long> Tracked = new HashSet<long>();

		private static readonly HashSet<string> OtherWorlds = new HashSet<string>();

		private static string _world;

		private static Sprite _star;

		internal static readonly Color StarColor = Color.white;

		private const string HelloRpc = "PCC_PinHello";

		private const string SnapshotRpc = "PCC_PinSnapshot";

		private static readonly Dictionary<string, StoredPin> Store = new Dictionary<string, StoredPin>();

		private static readonly Dictionary<string, int[]> Tombs = new Dictionary<string, int[]>();

		private static readonly List<string> StoreOtherWorlds = new List<string>();

		private static string _storeWorld;

		private static bool _storeDirty;

		private static float _storeSaveAt;

		private static ZNet _helloFor;

		private const string AdminSetReplaceRpc = "PCC_AdminSetReplace";

		private static bool _adoptingReplace;

		private static readonly Queue<Action> Outbox = new Queue<Action>();

		private static float _nextAdminCheck;

		private static string TrackedPath => Path.Combine(Paths.ConfigPath, "PlayerColorCompass.tracked.txt");

		internal static Sprite StarSprite
		{
			get
			{
				//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)
				//IL_0034: Expected O, but got Unknown
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0054: Unknown result type (might be due to invalid IL or missing references)
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Unknown result type (might be due to invalid IL or missing references)
				//IL_0067: Unknown result type (might be due to invalid IL or missing references)
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0071: 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)
				//IL_007b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0080: Unknown result type (might be due to invalid IL or missing references)
				//IL_0085: Unknown result type (might be due to invalid IL or missing references)
				//IL_019a: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
				//IL_009d: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a2: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e7: 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_0113: Unknown result type (might be due to invalid IL or missing references)
				//IL_011c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0125: Unknown result type (might be due to invalid IL or missing references)
				//IL_0154: Unknown result type (might be due to invalid IL or missing references)
				//IL_014c: Unknown result type (might be due to invalid IL or missing references)
				//IL_014d: Unknown result type (might be due to invalid IL or missing references)
				if (Object.op_Implicit((Object)(object)_star))
				{
					return _star;
				}
				SamplePinColors(out var fill, out var edge);
				Texture2D val = new Texture2D(128, 128, (TextureFormat)4, false)
				{
					wrapMode = (TextureWrapMode)1
				};
				Vector2 val2 = default(Vector2);
				((Vector2)(ref val2))..ctor(63.5f, 63.5f);
				Vector2 val3 = new Vector2(1f, -1f);
				Vector2 normalized = ((Vector2)(ref val3)).normalized;
				Vector2 a = val2 + normalized * 42f;
				Vector2 b = val2 + normalized * 70f;
				for (int i = 0; i < 128; i++)
				{
					for (int j = 0; j < 128; j++)
					{
						Vector2 val4 = new Vector2((float)j, (float)i);
						float num = Mathf.Abs(Vector2.Distance(val4, val2) - 41f);
						float num2 = DistanceToSegment(val4, a, b);
						Color val5 = Color.clear;
						if (num <= 2.5f || num2 <= 3.5f)
						{
							float num3 = Mathf.Lerp(1f, 0.82f, Mathf.Clamp01(((float)j - val2.x - ((float)i - val2.y)) / 142f + 0.5f));
							((Color)(ref val5))..ctor(fill.r * num3, fill.g * num3, fill.b * num3, 1f);
						}
						else if (num <= 4f || num2 <= 5f)
						{
							val5 = edge;
						}
						val.SetPixel(j, i, val5);
					}
				}
				val.Apply();
				_star = Sprite.Create(val, new Rect(0f, 0f, 128f, 128f), new Vector2(0.5f, 0.5f));
				return _star;
			}
		}

		private static string StorePath => Path.Combine(Paths.ConfigPath, "PlayerColorCompass.serverpins.txt");

		internal static List<PinData> SharedPins()
		{
			List<PinData> list = new List<PinData>();
			Minimap instance = Minimap.instance;
			if ((Object)(object)instance != (Object)null)
			{
				foreach (PinData item in PinsRef.Invoke(instance))
				{
					if (IsShared(item))
					{
						list.Add(item);
					}
				}
			}
			return list;
		}

		internal static Color TintOf(PinData pin)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected I4, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected I4, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			if (pin == null || !IsShared(pin))
			{
				return Color.white;
			}
			if (SharedTints.TryGetValue(PinKey((int)pin.m_type, pin.m_pos), out var value))
			{
				return value;
			}
			if (!QuickPin.TryGetTint(pin.m_name, (int)pin.m_type, out var color))
			{
				return Color.white;
			}
			return color;
		}

		private static string HexOf(Color c)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return ColorUtility.ToHtmlStringRGB(c);
		}

		private static bool TryHex(string hex, out Color c)
		{
			//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)
			c = Color.white;
			if (!string.IsNullOrEmpty(hex) && hex.Length <= 8)
			{
				return ColorUtility.TryParseHtmlString("#" + hex, ref c);
			}
			return false;
		}

		internal static void ShareTint(int type, Vector3 pos, string name)
		{
			//IL_000d: 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_0023: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			if (!QuickPin.TryGetTint(name, type, out var color))
			{
				return;
			}
			string key = PinKey(type, pos);
			if (!SharedTints.TryGetValue(key, out var value) || !(value == color))
			{
				SharedTints[key] = color;
				if (ColorSync.SharePinsEffective)
				{
					Send("PCC_PinTint", type, pos, HexOf(color));
				}
			}
		}

		private static void RPC_Tint(ZRpc rpc, int type, Vector3 pos, string hex)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			if (IsPlacedType((PinType)type) && TryHex(hex, out var c))
			{
				hex = HexOf(c);
				if ((Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer())
				{
					StoreUpdate("PCC_PinTint", new object[3] { type, pos, hex });
					Relay(rpc, "PCC_PinTint", new object[3] { type, pos, hex });
				}
				if (ColorSync.SharePinsEffective)
				{
					SharedTints[PinKey(type, pos)] = c;
				}
			}
		}

		private static void PublishTints()
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Expected I4, but got Unknown
			if (QuickPin.TintVersion != _tintSeen)
			{
				_tintSeen = QuickPin.TintVersion;
				_tintAt = Time.unscaledTime + 1f;
				_tintPending = true;
			}
			if (!_tintPending || Time.unscaledTime < _tintAt || (Object)(object)Minimap.instance == (Object)null || (Object)(object)ZNet.instance == (Object)null || (Object)(object)Player.m_localPlayer == (Object)null)
			{
				return;
			}
			_tintPending = false;
			foreach (PinData item in SharedPins())
			{
				ShareTint((int)item.m_type, item.m_pos, item.m_name);
			}
		}

		internal static void Retarget(PinData pin, int newType, string newName)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected I4, but got Unknown
			//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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			Minimap instance = Minimap.instance;
			if ((Object)(object)instance == (Object)null || pin == null || !IsPlacedType((PinType)newType))
			{
				return;
			}
			newName = CleanName(newName);
			int num = (int)pin.m_type;
			Vector3 pos = pin.m_pos;
			bool flag = pin.m_checked;
			_remote = true;
			try
			{
				instance.RemovePin(pin);
			}
			finally
			{
				_remote = false;
			}
			instance.AddPin(pos, (PinType)newType, newName, true, flag, 0L, default(PlatformUserID));
			if (newType != num)
			{
				SharedTints.Remove(PinKey(num, pos));
			}
			if (!ColorSync.SharePinsEffective)
			{
				return;
			}
			if (newType == num)
			{
				Send("PCC_PinRename", num, pos, newName);
			}
			else
			{
				Send("PCC_PinRemove", num, pos);
				Send("PCC_PinAdd", newType, pos, newName);
				if (flag)
				{
					Send("PCC_PinCheck", newType, pos, true);
				}
			}
			ShareTint(newType, pos, newName);
		}

		internal static bool CreatePlaced(Vector3 pos, int type, string name)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Invalid comparison between Unknown and I4
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: 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)
			Minimap instance = Minimap.instance;
			if ((Object)(object)instance == (Object)null || !IsPlacedType((PinType)type))
			{
				return false;
			}
			name = CleanName(name);
			foreach (PinData item in PinsRef.Invoke(instance))
			{
				if (IsShared(item) && (int)item.m_type == type && Utils.DistanceXZ(item.m_pos, pos) < 3f)
				{
					return false;
				}
			}
			instance.AddPin(pos, (PinType)type, name, true, false, 0L, default(PlatformUserID));
			if (ColorSync.SharePinsEffective)
			{
				Send("PCC_PinAdd", type, pos, name);
			}
			ShareTint(type, pos, name);
			return true;
		}

		private static bool IsShared(PinData pin)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if (pin != null && pin.m_save && pin.m_ownerID == 0L)
			{
				return IsPlacedType(pin.m_type);
			}
			return false;
		}

		private static bool IsPlacedType(PinType type)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Invalid comparison between Unknown and I4
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Invalid comparison between Unknown and I4
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Invalid comparison between Unknown and I4
			if ((int)type != 0 && (int)type != 1 && (int)type != 2 && (int)type != 3)
			{
				return (int)type == 6;
			}
			return true;
		}

		private static PinData Find(Minimap map, int type, Vector3 pos)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			//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)
			foreach (PinData item in PinsRef.Invoke(map))
			{
				if (IsShared(item) && (int)item.m_type == type && Utils.DistanceXZ(item.m_pos, pos) < 1f)
				{
					return item;
				}
			}
			return null;
		}

		private static string CleanName(string name)
		{
			if (string.IsNullOrEmpty(name))
			{
				return "";
			}
			name = name.Replace('$', ' ').Replace('<', ' ').Replace('>', ' ')
				.Replace('|', ' ')
				.Replace('\n', ' ')
				.Replace('\r', ' ');
			if (name.Length <= 60)
			{
				return name;
			}
			return name.Substring(0, 60);
		}

		private static void Send(string rpc, params object[] args)
		{
			ZNet instance = ZNet.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			if (instance.IsServer())
			{
				StoreUpdate(rpc, args);
				Relay(null, rpc, args);
				return;
			}
			ZRpc serverRPC = instance.GetServerRPC();
			if (serverRPC != null)
			{
				serverRPC.Invoke(rpc, args);
			}
		}

		private static void Relay(ZRpc except, string rpc, object[] args)
		{
			foreach (ZNetPeer peer in ZNet.instance.GetPeers())
			{
				if (peer.m_rpc != null && peer.m_rpc != except)
				{
					peer.m_rpc.Invoke(rpc, args);
				}
			}
		}

		private static void RPC_Add(ZRpc rpc, int type, Vector3 pos, string name)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			if (IsPlacedType((PinType)type))
			{
				name = CleanName(name);
				if ((Obj