Decompiled source of PeakCompass v1.0.0

PeakAuraCompass.dll

Decompiled 3 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
public class AuraController : MonoBehaviour
{
	private Light auraLight;

	private void Start()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0022: 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_0083: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("AuraLight");
		val.transform.SetParent(((Component)this).transform);
		val.transform.localPosition = Vector3.up * 1.8f;
		auraLight = val.AddComponent<Light>();
		auraLight.type = (LightType)2;
		auraLight.range = 6f;
		auraLight.intensity = 2f;
		auraLight.color = new Color(0.2f, 0.7f, 1f);
		auraLight.shadows = (LightShadows)0;
	}

	private void OnDestroy()
	{
		if ((Object)(object)auraLight != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)auraLight).gameObject);
		}
	}
}
public class CompassController : MonoBehaviour
{
	private RectTransform compassBar;

	private readonly Dictionary<Player, RectTransform> dotMap = new Dictionary<Player, RectTransform>();

	private readonly Dictionary<Player, TextMeshProUGUI> labelMap = new Dictionary<Player, TextMeshProUGUI>();

	private readonly Dictionary<Player, Image> dotImageMap = new Dictionary<Player, Image>();

	private Canvas hudCanvas;

	private readonly Dictionary<Player, float> playersNeedingPositionRetry = new Dictionary<Player, float>();

	private const float POSITION_RETRY_INTERVAL = 0.5f;

	private readonly HashSet<int> expectedActorNumbers = new HashSet<int>();

	private readonly Dictionary<int, Player> actorToPlayerCache = new Dictionary<int, Player>();

	private const int MAX_VIEW_IDS = 10000;

	private float debugLogTimer;

	private const float DEBUG_LOG_INTERVAL = 2f;

	private float reinitCheckTimer;

	private const float REINIT_CHECK_INTERVAL = 1f;

	public static CompassController Instance { get; private set; }

	public static void Create()
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		if (!((Object)(object)Instance != (Object)null))
		{
			GameObject val = new GameObject("CompassController");
			Object.DontDestroyOnLoad((Object)val);
			Instance = val.AddComponent<CompassController>();
		}
	}

	private void Start()
	{
		TryInitialize();
	}

	private bool TryInitialize()
	{
		if ((Object)(object)GUIManager.instance == (Object)null)
		{
			return false;
		}
		hudCanvas = GUIManager.instance.hudCanvas;
		if ((Object)(object)hudCanvas == (Object)null)
		{
			return false;
		}
		dotMap.Clear();
		labelMap.Clear();
		CreateCompassBar();
		return true;
	}

	private void CreateCompassBar()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("CompassBar");
		val.transform.SetParent(((Component)hudCanvas).transform, false);
		val.layer = ((Component)hudCanvas).gameObject.layer;
		compassBar = val.AddComponent<RectTransform>();
		compassBar.anchorMin = new Vector2(0.5f, 1f);
		compassBar.anchorMax = new Vector2(0.5f, 1f);
		compassBar.pivot = new Vector2(0.5f, 1f);
		compassBar.anchoredPosition = new Vector2(0f, -60f);
		compassBar.sizeDelta = new Vector2(500f, 40f);
		((Transform)compassBar).localScale = Vector3.one;
		((Graphic)val.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0.3f);
	}

	public void RegisterPlayer(Player player)
	{
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Expected O, but got Unknown
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: 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_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: 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)
		if ((Object)(object)player == (Object)null || ((Object)(object)compassBar == (Object)null && !TryInitialize()))
		{
			return;
		}
		PhotonView component = ((Component)player).GetComponent<PhotonView>();
		if ((!((Object)(object)component != (Object)null) || !component.IsMine) && !dotMap.ContainsKey(player))
		{
			GameObject val = new GameObject($"CompassDot_{((Object)player).GetInstanceID()}");
			val.transform.SetParent((Transform)(object)compassBar, false);
			val.layer = ((Component)compassBar).gameObject.layer;
			RectTransform val2 = val.AddComponent<RectTransform>();
			val2.anchorMin = new Vector2(0.5f, 0.5f);
			val2.anchorMax = new Vector2(0.5f, 0.5f);
			val2.pivot = new Vector2(0.5f, 0.5f);
			val2.sizeDelta = new Vector2(8f, 8f);
			val2.anchoredPosition = Vector2.zero;
			((Transform)val2).localScale = Vector3.one;
			Image val3 = val.AddComponent<Image>();
			Color playerColor = GetPlayerColor(player);
			((Graphic)val3).color = playerColor;
			dotMap[player] = val2;
			dotImageMap[player] = val3;
			GameObject val4 = new GameObject("DistanceLabel");
			val4.transform.SetParent(val.transform, false);
			val4.layer = val.layer;
			RectTransform obj = val4.AddComponent<RectTransform>();
			obj.anchorMin = new Vector2(0.5f, 0f);
			obj.anchorMax = new Vector2(0.5f, 0f);
			obj.pivot = new Vector2(0.5f, 1f);
			obj.anchoredPosition = new Vector2(0f, -10f);
			((Transform)obj).localScale = Vector3.one;
			TextMeshProUGUI val5 = val4.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val5).fontSize = 10f;
			((TMP_Text)val5).alignment = (TextAlignmentOptions)514;
			((Graphic)val5).color = Color.white;
			((TMP_Text)val5).text = string.Empty;
			labelMap[player] = val5;
			if ((Object)(object)component != (Object)null && component.Owner != null)
			{
				actorToPlayerCache[component.Owner.ActorNumber] = player;
				expectedActorNumbers.Remove(component.Owner.ActorNumber);
			}
		}
	}

	public void OnNetworkPlayerEntered(int actorNumber)
	{
		expectedActorNumbers.Add(actorNumber);
	}

	public void OnNetworkPlayerLeft(int actorNumber)
	{
		expectedActorNumbers.Remove(actorNumber);
		if (actorToPlayerCache.TryGetValue(actorNumber, out var value))
		{
			RemovePlayer(value);
			actorToPlayerCache.Remove(actorNumber);
			return;
		}
		foreach (KeyValuePair<Player, RectTransform> item in dotMap.ToList())
		{
			Player key = item.Key;
			if (!((Object)(object)key == (Object)null))
			{
				PhotonView component = ((Component)key).GetComponent<PhotonView>();
				if ((Object)(object)component != (Object)null && component.Owner != null && component.Owner.ActorNumber == actorNumber)
				{
					RemovePlayer(key);
					break;
				}
			}
		}
	}

	public void RemovePlayer(Player player)
	{
		if ((Object)(object)player == (Object)null)
		{
			return;
		}
		if (dotMap.TryGetValue(player, out var value))
		{
			if ((Object)(object)value != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)value).gameObject);
			}
			dotMap.Remove(player);
		}
		labelMap.Remove(player);
		dotImageMap.Remove(player);
		playersNeedingPositionRetry.Remove(player);
	}

	private void Update()
	{
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d3: 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_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: 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_01fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_0258: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: 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_02e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f4: 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)
		Camera main = Camera.main;
		if ((Object)(object)main == (Object)null)
		{
			return;
		}
		if ((Object)(object)compassBar == (Object)null || (Object)(object)hudCanvas == (Object)null)
		{
			reinitCheckTimer += Time.deltaTime;
			if (reinitCheckTimer >= 1f)
			{
				reinitCheckTimer = 0f;
				TryInitialize();
			}
			return;
		}
		Vector3 position = ((Component)main).transform.position;
		debugLogTimer += Time.deltaTime;
		bool flag = debugLogTimer >= 2f;
		if (flag)
		{
			debugLogTimer = 0f;
		}
		Vector3 val2 = default(Vector3);
		Vector3 val3 = default(Vector3);
		foreach (KeyValuePair<Player, RectTransform> item in dotMap.ToList())
		{
			Player key = item.Key;
			RectTransform value = item.Value;
			if ((Object)(object)key == (Object)null)
			{
				if ((Object)(object)value != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)value).gameObject);
				}
				dotMap.Remove(key);
				labelMap.Remove(key);
				dotImageMap.Remove(key);
				playersNeedingPositionRetry.Remove(key);
				continue;
			}
			Vector3 playerPosition = GetPlayerPosition(key, flag);
			if (!(((Vector3)(ref playerPosition)).sqrMagnitude > 1f))
			{
				if (!playersNeedingPositionRetry.ContainsKey(key))
				{
					playersNeedingPositionRetry[key] = Time.time;
				}
				((Component)value).gameObject.SetActive(false);
				if (labelMap.TryGetValue(key, out var value2))
				{
					((TMP_Text)value2).text = string.Empty;
				}
				continue;
			}
			if (playersNeedingPositionRetry.ContainsKey(key))
			{
				playersNeedingPositionRetry.Remove(key);
			}
			((Component)value).gameObject.SetActive(true);
			float num = Vector3.Distance(position, playerPosition);
			Vector3 val = playerPosition - position;
			((Vector3)(ref val2))..ctor(val.x, 0f, val.z);
			Vector3 forward = ((Component)main).transform.forward;
			((Vector3)(ref val3))..ctor(forward.x, 0f, forward.z);
			if (((Vector3)(ref val2)).sqrMagnitude < 0.0001f || ((Vector3)(ref val3)).sqrMagnitude < 0.0001f)
			{
				value.anchoredPosition = new Vector2(0f, 0f);
			}
			else
			{
				float num2 = Vector3.SignedAngle(((Vector3)(ref val3)).normalized, ((Vector3)(ref val2)).normalized, Vector3.up);
				float num3 = compassBar.sizeDelta.x * 0.5f;
				float num4 = Mathf.Clamp(num2 / 180f * num3, 0f - num3, num3);
				value.anchoredPosition = new Vector2(num4, 0f);
			}
			if (labelMap.TryGetValue(key, out var value3))
			{
				((TMP_Text)value3).text = $"{num:F0}m";
			}
			if (dotImageMap.TryGetValue(key, out var value4) && (Object)(object)value4 != (Object)null)
			{
				Color playerColor = GetPlayerColor(key);
				if (playerColor != ((Graphic)value4).color)
				{
					((Graphic)value4).color = playerColor;
				}
			}
		}
		foreach (Player item2 in new List<Player>(playersNeedingPositionRetry.Keys))
		{
			if ((Object)(object)item2 == (Object)null || !dotMap.ContainsKey(item2))
			{
				playersNeedingPositionRetry.Remove(item2);
			}
		}
	}

	private Vector3 GetPlayerPosition(Player player, bool shouldLog = false)
	{
		//IL_0009: 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)
		//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b2: 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_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0386: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0592: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d0: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_058c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0283: Unknown result type (might be due to invalid IL or missing references)
		//IL_0288: Unknown result type (might be due to invalid IL or missing references)
		//IL_0347: 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_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0565: Unknown result type (might be due to invalid IL or missing references)
		//IL_056a: Unknown result type (might be due to invalid IL or missing references)
		//IL_056e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0573: 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_029a: Unknown result type (might be due to invalid IL or missing references)
		//IL_035c: Unknown result type (might be due to invalid IL or missing references)
		//IL_035e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0474: Unknown result type (might be due to invalid IL or missing references)
		//IL_0479: Unknown result type (might be due to invalid IL or missing references)
		//IL_051a: Unknown result type (might be due to invalid IL or missing references)
		//IL_051f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0523: Unknown result type (might be due to invalid IL or missing references)
		//IL_0528: Unknown result type (might be due to invalid IL or missing references)
		//IL_0583: Unknown result type (might be due to invalid IL or missing references)
		//IL_0489: Unknown result type (might be due to invalid IL or missing references)
		//IL_0538: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)player == (Object)null)
		{
			return Vector3.zero;
		}
		PhotonView component = ((Component)player).GetComponent<PhotonView>();
		int num = -1;
		if ((Object)(object)component != (Object)null && component.Owner != null)
		{
			num = component.Owner.ActorNumber;
		}
		else if ((Object)(object)component != (Object)null && component.ViewID > 0)
		{
			num = component.ViewID / 10000;
		}
		try
		{
			PropertyInfo property = ((object)player).GetType().GetProperty("character");
			if (property != null)
			{
				object? value = property.GetValue(player);
				Component val = (Component)((value is Component) ? value : null);
				if ((Object)(object)val != (Object)null)
				{
					PropertyInfo property2 = ((object)val).GetType().GetProperty("Center");
					if (property2 != null)
					{
						try
						{
							object value2 = property2.GetValue(val);
							if (value2 is Vector3)
							{
								Vector3 result = (Vector3)value2;
								if (((Vector3)(ref result)).sqrMagnitude > 1f)
								{
									return result;
								}
							}
						}
						catch
						{
						}
					}
					MethodInfo method = ((object)val).GetType().GetMethod("GetBodypart");
					if (method != null)
					{
						try
						{
							object obj2 = method.Invoke(val, new object[1] { 2 });
							if (obj2 != null)
							{
								Component val2 = (Component)((obj2 is Component) ? obj2 : null);
								if ((Object)(object)val2 != (Object)null)
								{
									Vector3 position = val2.transform.position;
									if (((Vector3)(ref position)).sqrMagnitude > 1f)
									{
										return position;
									}
								}
							}
						}
						catch
						{
						}
					}
					Vector3 bestWorldPos = WorldPosUtil.GetBestWorldPos(val);
					if (((Vector3)(ref bestWorldPos)).sqrMagnitude > 1f)
					{
						return bestWorldPos;
					}
					Vector3 position2 = val.transform.position;
					if (((Vector3)(ref position2)).sqrMagnitude > 1f)
					{
						return position2;
					}
				}
			}
		}
		catch (Exception)
		{
		}
		if (num >= 0)
		{
			PhotonView[] array = Object.FindObjectsByType<PhotonView>((FindObjectsSortMode)0);
			foreach (PhotonView val3 in array)
			{
				if ((Object)(object)val3 == (Object)null)
				{
					continue;
				}
				int num2 = -1;
				if (val3.Owner != null)
				{
					num2 = val3.Owner.ActorNumber;
				}
				else if (val3.ViewID > 0)
				{
					num2 = val3.ViewID / 10000;
				}
				if (num2 != num)
				{
					continue;
				}
				Component[] componentsInParent = ((Component)val3).GetComponentsInParent<Component>(true);
				foreach (Component val4 in componentsInParent)
				{
					if ((Object)(object)val4 == (Object)null || !(((object)val4).GetType().Name == "Character"))
					{
						continue;
					}
					PropertyInfo property3 = ((object)val4).GetType().GetProperty("Center");
					if (property3 != null)
					{
						try
						{
							object value3 = property3.GetValue(val4);
							if (value3 is Vector3)
							{
								Vector3 result2 = (Vector3)value3;
								if (((Vector3)(ref result2)).sqrMagnitude > 1f)
								{
									return result2;
								}
							}
						}
						catch
						{
						}
					}
					Vector3 position3 = val4.transform.position;
					if (((Vector3)(ref position3)).sqrMagnitude > 1f)
					{
						return position3;
					}
				}
				componentsInParent = ((Component)val3).GetComponentsInChildren<Component>(true);
				foreach (Component val5 in componentsInParent)
				{
					if ((Object)(object)val5 == (Object)null || !(((object)val5).GetType().Name == "Character"))
					{
						continue;
					}
					PropertyInfo property4 = ((object)val5).GetType().GetProperty("Center");
					if (property4 != null)
					{
						try
						{
							object value4 = property4.GetValue(val5);
							if (value4 is Vector3)
							{
								Vector3 result3 = (Vector3)value4;
								if (((Vector3)(ref result3)).sqrMagnitude > 1f)
								{
									return result3;
								}
							}
						}
						catch
						{
						}
					}
					Vector3 position4 = val5.transform.position;
					if (((Vector3)(ref position4)).sqrMagnitude > 1f)
					{
						return position4;
					}
				}
				Vector3 position5 = ((Component)val3).transform.position;
				if (((Vector3)(ref position5)).sqrMagnitude > 1f)
				{
					return position5;
				}
				Vector3 bestWorldPos2 = WorldPosUtil.GetBestWorldPos((Component)(object)val3);
				if (((Vector3)(ref bestWorldPos2)).sqrMagnitude > 1f)
				{
					return bestWorldPos2;
				}
			}
		}
		Vector3 bestWorldPos3 = WorldPosUtil.GetBestWorldPos((Component)(object)player);
		if (((Vector3)(ref bestWorldPos3)).sqrMagnitude > 1f)
		{
			return bestWorldPos3;
		}
		PhotonTransformView[] array2 = Object.FindObjectsByType<PhotonTransformView>((FindObjectsSortMode)0);
		foreach (PhotonTransformView val6 in array2)
		{
			if ((Object)(object)val6 == (Object)null)
			{
				continue;
			}
			PhotonView component2 = ((Component)val6).GetComponent<PhotonView>();
			if ((Object)(object)component2 == (Object)null)
			{
				continue;
			}
			int num3 = -1;
			if (component2.Owner != null)
			{
				num3 = component2.Owner.ActorNumber;
			}
			else if (component2.ViewID > 0)
			{
				num3 = component2.ViewID / 10000;
			}
			if (num < 0 || num3 == num)
			{
				Vector3 position6 = ((Component)val6).transform.position;
				if (((Vector3)(ref position6)).sqrMagnitude > 1f)
				{
					return position6;
				}
			}
		}
		SkinnedMeshRenderer[] array3 = Object.FindObjectsByType<SkinnedMeshRenderer>((FindObjectsSortMode)0);
		Bounds bounds;
		foreach (SkinnedMeshRenderer val7 in array3)
		{
			if ((Object)(object)val7 == (Object)null || !((Renderer)val7).enabled)
			{
				continue;
			}
			PhotonView componentInParent = ((Component)val7).GetComponentInParent<PhotonView>();
			if ((Object)(object)componentInParent != (Object)null && num >= 0)
			{
				int num4 = -1;
				if (componentInParent.Owner != null)
				{
					num4 = componentInParent.Owner.ActorNumber;
				}
				else if (componentInParent.ViewID > 0)
				{
					num4 = componentInParent.ViewID / 10000;
				}
				if (num4 != num)
				{
					continue;
				}
			}
			bounds = ((Renderer)val7).bounds;
			Vector3 center = ((Bounds)(ref bounds)).center;
			if (((Vector3)(ref center)).sqrMagnitude > 1f)
			{
				return center;
			}
		}
		Renderer componentInChildren = ((Component)player).GetComponentInChildren<Renderer>();
		if ((Object)(object)componentInChildren != (Object)null && componentInChildren.enabled)
		{
			bounds = componentInChildren.bounds;
			Vector3 center2 = ((Bounds)(ref bounds)).center;
			if (((Vector3)(ref center2)).sqrMagnitude > 1f)
			{
				return center2;
			}
		}
		return ((Component)player).transform.position;
	}

	private Color GetPlayerColor(Player player)
	{
		//IL_0009: 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_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: 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_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: 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_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)player == (Object)null)
		{
			return Color.red;
		}
		try
		{
			PropertyInfo property = ((object)player).GetType().GetProperty("character");
			if (property == null)
			{
				return Color.red;
			}
			object? value = property.GetValue(player);
			Component val = (Component)((value is Component) ? value : null);
			if ((Object)(object)val == (Object)null)
			{
				return Color.red;
			}
			FieldInfo field = ((object)val).GetType().GetField("refs");
			if (field == null)
			{
				return Color.red;
			}
			object value2 = field.GetValue(val);
			if (value2 == null)
			{
				return Color.red;
			}
			FieldInfo field2 = value2.GetType().GetField("customization");
			if (field2 == null)
			{
				return Color.red;
			}
			object value3 = field2.GetValue(value2);
			if (value3 == null)
			{
				return Color.red;
			}
			PropertyInfo property2 = value3.GetType().GetProperty("PlayerColor");
			if (property2 == null)
			{
				return Color.red;
			}
			object value4 = property2.GetValue(value3);
			if (value4 is Color)
			{
				return (Color)value4;
			}
		}
		catch (Exception)
		{
		}
		return Color.red;
	}
}
internal static class LocalPlayerCache
{
	private static Player cached;

	private static float lastRefresh;

	public static Player Get(float refreshInterval = 1f)
	{
		if ((Object)(object)cached != (Object)null && Time.time - lastRefresh < refreshInterval)
		{
			return cached;
		}
		lastRefresh = Time.time;
		Player[] array = Object.FindObjectsByType<Player>((FindObjectsSortMode)0);
		foreach (Player val in array)
		{
			if (!((Object)(object)val == (Object)null))
			{
				PhotonView val2 = null;
				try
				{
					val2 = ((MonoBehaviourPun)val).photonView;
				}
				catch
				{
				}
				if ((Object)(object)val2 != (Object)null && val2.IsMine)
				{
					cached = val;
					return cached;
				}
			}
		}
		cached = null;
		return null;
	}
}
public class NameTagController : MonoBehaviour
{
	private Player player;

	private RectTransform rect;

	private TextMeshProUGUI label;

	private Canvas hudCanvas;

	private string cachedName;

	private void Start()
	{
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Expected O, but got Unknown
		//IL_00ae: 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_0104: Unknown result type (might be due to invalid IL or missing references)
		player = ((Component)this).GetComponent<Player>();
		if ((Object)(object)player == (Object)null)
		{
			Object.Destroy((Object)(object)this);
			return;
		}
		hudCanvas = GUIManager.instance.hudCanvas;
		if ((Object)(object)hudCanvas == (Object)null)
		{
			Object.Destroy((Object)(object)this);
			return;
		}
		GameObject val = new GameObject($"NameTag_{((Object)player).GetInstanceID()}");
		val.transform.SetParent(((Component)hudCanvas).transform);
		val.layer = ((Component)hudCanvas).gameObject.layer;
		rect = val.AddComponent<RectTransform>();
		rect.sizeDelta = new Vector2(160f, 20f);
		rect.pivot = new Vector2(0.5f, 0f);
		label = val.AddComponent<TextMeshProUGUI>();
		((TMP_Text)label).fontSize = 14f;
		((TMP_Text)label).alignment = (TextAlignmentOptions)514;
		((Graphic)label).color = Color.white;
		cachedName = ResolvePlayerName();
		((TMP_Text)label).text = cachedName;
	}

	private string ResolvePlayerName()
	{
		string result = ((Object)((Component)this).gameObject).name;
		try
		{
			PhotonView component = ((Component)this).GetComponent<PhotonView>();
			if ((Object)(object)component != (Object)null && component.Owner != null && !string.IsNullOrEmpty(component.Owner.NickName))
			{
				result = component.Owner.NickName;
			}
		}
		catch
		{
		}
		return result;
	}

	private void Update()
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: 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_0053: 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_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: 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)
		if ((Object)(object)hudCanvas == (Object)null || (Object)(object)Camera.main == (Object)null)
		{
			return;
		}
		Vector3 val = ((Component)this).transform.position + Vector3.up * 2.2f;
		Vector3 val2 = Camera.main.WorldToScreenPoint(val);
		Vector2 anchoredPosition = default(Vector2);
		if (RectTransformUtility.ScreenPointToLocalPointInRectangle(((Component)hudCanvas).GetComponent<RectTransform>(), Vector2.op_Implicit(val2), Camera.main, ref anchoredPosition))
		{
			rect.anchoredPosition = anchoredPosition;
		}
		if (val2.z <= 0f)
		{
			((Behaviour)label).enabled = false;
			return;
		}
		((Behaviour)label).enabled = true;
		Player val3 = LocalPlayerCache.Get();
		if ((Object)(object)val3 != (Object)null && (Object)(object)val3 != (Object)(object)player)
		{
			float num = Vector3.Distance(WorldPosUtil.GetBestWorldPos((Component)(object)player), WorldPosUtil.GetBestWorldPos((Component)(object)val3));
			((TMP_Text)label).text = $"{cachedName} ({num:F0}m)";
		}
		else
		{
			((TMP_Text)label).text = cachedName;
		}
	}

	private void OnDestroy()
	{
		if ((Object)(object)rect != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)rect).gameObject);
		}
	}
}
internal static class WorldPosUtil
{
	private static bool typesResolved;

	private static Type rbType;

	private static Type colType;

	private static Type ccType;

	private static void EnsureTypes()
	{
		if (!typesResolved)
		{
			typesResolved = true;
			rbType = FindType("UnityEngine.Rigidbody");
			colType = FindType("UnityEngine.Collider");
			ccType = FindType("UnityEngine.CharacterController");
		}
	}

	private static Type FindType(string fullName)
	{
		try
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			for (int i = 0; i < assemblies.Length; i++)
			{
				Type type = assemblies[i].GetType(fullName, throwOnError: false);
				if (type != null)
				{
					return type;
				}
			}
		}
		catch
		{
		}
		return null;
	}

	public static Vector3 GetBestWorldPos(Component root)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: 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_01e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ef: Expected O, but got Unknown
		//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Unknown result type (might be due to invalid IL or missing references)
		//IL_020d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0237: Unknown result type (might be due to invalid IL or missing references)
		//IL_023d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: 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_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: 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)
		if ((Object)(object)root == (Object)null)
		{
			return Vector3.zero;
		}
		EnsureTypes();
		if (ccType != null)
		{
			Component componentInChildren = root.GetComponentInChildren(ccType);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				Vector3 position = componentInChildren.transform.position;
				if (((Vector3)(ref position)).sqrMagnitude > 0.0001f || IsValidNonZeroPosition(position, root))
				{
					return position;
				}
			}
		}
		Renderer componentInChildren2 = root.GetComponentInChildren<Renderer>();
		if ((Object)(object)componentInChildren2 != (Object)null && componentInChildren2.enabled)
		{
			Bounds bounds = componentInChildren2.bounds;
			Vector3 center = ((Bounds)(ref bounds)).center;
			if (((Vector3)(ref center)).sqrMagnitude > 0.0001f || IsValidNonZeroPosition(center, root))
			{
				return center;
			}
		}
		if (rbType != null)
		{
			Component componentInChildren3 = root.GetComponentInChildren(rbType);
			if ((Object)(object)componentInChildren3 != (Object)null)
			{
				PropertyInfo property = rbType.GetProperty("position");
				if (property != null)
				{
					try
					{
						object value = property.GetValue(componentInChildren3, null);
						if (value is Vector3)
						{
							Vector3 val = (Vector3)value;
							if (((Vector3)(ref val)).sqrMagnitude > 0.0001f || IsValidNonZeroPosition(val, root))
							{
								return val;
							}
						}
					}
					catch
					{
					}
				}
			}
		}
		if (colType != null)
		{
			Component componentInChildren4 = root.GetComponentInChildren(colType);
			if ((Object)(object)componentInChildren4 != (Object)null)
			{
				PropertyInfo property2 = colType.GetProperty("bounds");
				if (property2 != null)
				{
					try
					{
						object value2 = property2.GetValue(componentInChildren4, null);
						if (value2 != null)
						{
							PropertyInfo property3 = value2.GetType().GetProperty("center");
							if (property3 != null)
							{
								object value3 = property3.GetValue(value2, null);
								if (value3 is Vector3)
								{
									Vector3 val2 = (Vector3)value3;
									if (((Vector3)(ref val2)).sqrMagnitude > 0.0001f || IsValidNonZeroPosition(val2, root))
									{
										return val2;
									}
								}
							}
						}
					}
					catch
					{
					}
				}
			}
		}
		foreach (Transform item in root.transform)
		{
			Transform val3 = item;
			Vector3 position2 = val3.position;
			if (((Vector3)(ref position2)).sqrMagnitude > 0.0001f)
			{
				return val3.position;
			}
		}
		return root.transform.position;
	}

	private static bool IsValidNonZeroPosition(Vector3 pos, Component root)
	{
		//IL_0000: 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)
		return Vector3.Distance(pos, root.transform.position) < 10f;
	}
}
namespace PeakAuraCompass
{
	[BepInPlugin("com.modders.peakcompass", "Peak Compass", "1.0.0")]
	[BepInProcess("PEAK.exe")]
	public class Plugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <FindAndRegisterNetworkPlayer>d__14 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public Player photonPlayer;

			public Plugin <>4__this;

			private float <startTime>5__2;

			private int <actorNumber>5__3;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <FindAndRegisterNetworkPlayer>d__14(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ad: Expected O, but got Unknown
				int num = <>1__state;
				Plugin plugin = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<startTime>5__2 = Time.time;
					<actorNumber>5__3 = photonPlayer.ActorNumber;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (Time.time - <startTime>5__2 < 5f)
				{
					Player[] array = Object.FindObjectsByType<Player>((FindObjectsSortMode)0);
					foreach (Player val in array)
					{
						if (!((Object)(object)val == (Object)null))
						{
							PhotonView component = ((Component)val).GetComponent<PhotonView>();
							if ((Object)(object)component != (Object)null && component.Owner != null && component.Owner.ActorNumber == <actorNumber>5__3)
							{
								plugin.TryRegisterPlayer(val);
								return false;
							}
						}
					}
					<>2__current = (object)new WaitForSeconds(0.5f);
					<>1__state = 1;
					return true;
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <InitialiseCoroutine>d__10 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public Plugin <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <InitialiseCoroutine>d__10(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Expected O, but got Unknown
				int num = <>1__state;
				Plugin plugin = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if ((Object)(object)GUIManager.instance == (Object)null)
				{
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				CompassController.Create();
				if ((Object)(object)plugin.photonHandler == (Object)null)
				{
					GameObject val = new GameObject("PhotonCallbackHandler");
					Object.DontDestroyOnLoad((Object)(object)val);
					plugin.photonHandler = val.AddComponent<PhotonCallbackHandler>();
					plugin.photonHandler.Initialize(plugin);
				}
				plugin.RegisterExistingPlayers();
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public const string ModGuid = "com.modders.peakcompass";

		public const string ModName = "Peak Compass";

		public const string ModVersion = "1.0.0";

		private Harmony harmony;

		private readonly HashSet<Player> registeredPlayers = new HashSet<Player>();

		private readonly Dictionary<Player, float> pendingPlayers = new Dictionary<Player, float>();

		private const float REGISTRATION_RETRY_DELAY = 0.5f;

		private const float MAX_REGISTRATION_WAIT = 5f;

		private PhotonCallbackHandler photonHandler;

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			harmony = new Harmony("com.modders.peakcompass");
			harmony.PatchAll();
			((MonoBehaviour)this).StartCoroutine(InitialiseCoroutine());
		}

		[IteratorStateMachine(typeof(<InitialiseCoroutine>d__10))]
		private IEnumerator InitialiseCoroutine()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <InitialiseCoroutine>d__10(0)
			{
				<>4__this = this
			};
		}

		private void RegisterExistingPlayers()
		{
			Player[] array = Object.FindObjectsByType<Player>((FindObjectsSortMode)0);
			foreach (Player player in array)
			{
				TryRegisterPlayer(player);
			}
		}

		public void OnNetworkPlayerEntered(Player photonPlayer)
		{
			CompassController.Instance?.OnNetworkPlayerEntered(photonPlayer.ActorNumber);
			((MonoBehaviour)this).StartCoroutine(FindAndRegisterNetworkPlayer(photonPlayer));
		}

		public void OnNetworkPlayerLeft(Player photonPlayer)
		{
			CompassController.Instance?.OnNetworkPlayerLeft(photonPlayer.ActorNumber);
		}

		[IteratorStateMachine(typeof(<FindAndRegisterNetworkPlayer>d__14))]
		private IEnumerator FindAndRegisterNetworkPlayer(Player photonPlayer)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <FindAndRegisterNetworkPlayer>d__14(0)
			{
				<>4__this = this,
				photonPlayer = photonPlayer
			};
		}

		private void TryRegisterPlayer(Player player)
		{
			if ((Object)(object)player == (Object)null || registeredPlayers.Contains(player))
			{
				return;
			}
			PhotonView component = ((Component)player).GetComponent<PhotonView>();
			if ((Object)(object)component == (Object)null || component.Owner == null)
			{
				if (!pendingPlayers.ContainsKey(player))
				{
					pendingPlayers[player] = Time.time;
				}
			}
			else
			{
				registeredPlayers.Add(player);
				pendingPlayers.Remove(player);
				CompassController.Instance?.RegisterPlayer(player);
			}
		}

		private void Update()
		{
			foreach (Player item in new List<Player>(pendingPlayers.Keys))
			{
				if ((Object)(object)item == (Object)null)
				{
					pendingPlayers.Remove(item);
				}
				else if (Time.time - pendingPlayers[item] > 5f)
				{
					pendingPlayers.Remove(item);
				}
				else
				{
					TryRegisterPlayer(item);
				}
			}
			Player[] array = Object.FindObjectsByType<Player>((FindObjectsSortMode)0);
			foreach (Player val in array)
			{
				if (!registeredPlayers.Contains(val) && !pendingPlayers.ContainsKey(val))
				{
					TryRegisterPlayer(val);
				}
			}
			registeredPlayers.RemoveWhere((Player p) => (Object)(object)p == (Object)null);
		}
	}
	public class PhotonCallbackHandler : MonoBehaviourPunCallbacks
	{
		[CompilerGenerated]
		private sealed class <DelayedPlayerScan>d__5 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <DelayedPlayerScan>d__5(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(1f);
					<>1__state = 1;
					return true;
				case 1:
				{
					<>1__state = -1;
					Player[] array = Object.FindObjectsByType<Player>((FindObjectsSortMode)0);
					foreach (Player val in array)
					{
						if (!((Object)(object)val == (Object)null))
						{
							PhotonView component = ((Component)val).GetComponent<PhotonView>();
							if ((Object)(object)component != (Object)null && !component.IsMine)
							{
								CompassController.Instance?.RegisterPlayer(val);
							}
						}
					}
					return false;
				}
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private Plugin plugin;

		public void Initialize(Plugin plugin)
		{
			this.plugin = plugin;
		}

		public override void OnPlayerEnteredRoom(Player newPlayer)
		{
			plugin?.OnNetworkPlayerEntered(newPlayer);
		}

		public override void OnPlayerLeftRoom(Player otherPlayer)
		{
			plugin?.OnNetworkPlayerLeft(otherPlayer);
		}

		public override void OnJoinedRoom()
		{
			((MonoBehaviour)this).StartCoroutine(DelayedPlayerScan());
		}

		[IteratorStateMachine(typeof(<DelayedPlayerScan>d__5))]
		private IEnumerator DelayedPlayerScan()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DelayedPlayerScan>d__5(0);
		}
	}
}