Decompiled source of CompassUI v2.0.1

CompassUI.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CompassUI")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Compass UI Mod for Peak")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyInformationalVersion("2.0.0")]
[assembly: AssemblyProduct("CompassUI")]
[assembly: AssemblyTitle("CompassUI")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.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;
		}
	}
}
namespace CompassUI
{
	[BepInPlugin("com.compass.plugin", "Compass UI", "2.0.0")]
	public class CompassUIPlugin : BaseUnityPlugin
	{
		public static ManualLogSource Log;

		public static CompassUIPlugin Instance;

		public static ConfigEntry<bool> showPlayersOnCompass;

		public static ConfigEntry<bool> alwaysShowSuitcases;

		public static ConfigEntry<float> suitcaseDistance;

		public static ConfigEntry<KeyCode> suitcasePingKeybind;

		private bool compassCreated = false;

		private float nextAttemptTime = 0f;

		private void Awake()
		{
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"=== Compass UI Plugin Starting ===");
			showPlayersOnCompass = ((BaseUnityPlugin)this).Config.Bind<bool>("Compass", "showPlayersOnCompass", true, "Whether to show player dots on the compass UI");
			alwaysShowSuitcases = ((BaseUnityPlugin)this).Config.Bind<bool>("Compass", "alwaysShowSuitcases", false, "Whether to show suitcases all the time or not (otherwise will require ping)");
			suitcaseDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Compass", "pingDistance", 100f, "What distance will suitcases show up on the compass");
			suitcasePingKeybind = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Compass", "suitcasePingKeybind", (KeyCode)282, "What button does the suitcase ping");
			Log.LogInfo((object)"Compass UI Plugin loaded!");
		}

		private void Update()
		{
			if (!compassCreated && Time.time > nextAttemptTime)
			{
				nextAttemptTime = Time.time + 2f;
				if ((Object)(object)Camera.main != (Object)null)
				{
					Log.LogInfo((object)"Camera found, attempting to create compass...");
					TryCreateCompass();
				}
			}
		}

		private void TryCreateCompass()
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Canvas[] array = Resources.FindObjectsOfTypeAll<Canvas>();
				Log.LogInfo((object)$"Found {array.Length} total canvases");
				Canvas val = null;
				Canvas[] array2 = array;
				foreach (Canvas val2 in array2)
				{
					if (((Component)val2).gameObject.activeInHierarchy)
					{
						Log.LogInfo((object)$"Found active canvas: {((Object)val2).name} (renderMode: {val2.renderMode})");
						val = val2;
						break;
					}
				}
				if ((Object)(object)val == (Object)null && array.Length != 0)
				{
					val = array[0];
					Log.LogInfo((object)("Using first canvas: " + ((Object)val).name));
				}
				if ((Object)(object)val == (Object)null)
				{
					Log.LogWarning((object)"No canvas found, will retry");
				}
				else
				{
					CreateCompassUI(((Component)val).transform);
				}
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Error in TryCreateCompass: {arg}");
			}
		}

		private void CreateCompassUI(Transform parent)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_005d: 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_0089: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Log.LogInfo((object)("=== Creating Compass UI on " + ((Object)parent).name + " ==="));
				GameObject val = new GameObject("CompassTapeUI");
				val.transform.SetParent(parent, false);
				Log.LogInfo((object)"Created GameObject");
				RectTransform val2 = val.AddComponent<RectTransform>();
				val2.anchorMin = new Vector2(0.3f, 1f);
				val2.anchorMax = new Vector2(0.7f, 1f);
				val2.pivot = new Vector2(0.5f, 1f);
				val2.anchoredPosition = new Vector2(0f, -75f);
				val2.sizeDelta = new Vector2(0f, 100f);
				Log.LogInfo((object)"RectTransform configured");
				CompassTapeUI compassTapeUI = val.AddComponent<CompassTapeUI>();
				Log.LogInfo((object)"CompassTapeUI component added");
				compassCreated = true;
				Log.LogInfo((object)"=== Compass UI created successfully! ===");
			}
			catch (Exception ex)
			{
				Log.LogError((object)$"Error creating compass: {ex}");
				Log.LogError((object)("Stack trace: " + ex.StackTrace));
			}
		}
	}
	public class CompassTapeUI : MonoBehaviour
	{
		private RectTransform rectTransform;

		private RectTransform lineTransform;

		private RawImage lineImage;

		private const int INCREMENT_COUNT = 24;

		private CompassMark[] marks = new CompassMark[24];

		private CompassMark[] playerBuffer = new CompassMark[20];

		private CompassMark[] suitcaseBuffer = new CompassMark[150];

		private float showSuitcasesUntilTime;

		private const float UP_DOWN_THRESHOLD = 7.5f;

		private void Start()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_00d7: 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_010d: Unknown result type (might be due to invalid IL or missing references)
			CompassUIPlugin.Log.LogInfo((object)"CompassTapeUI.Start() called");
			rectTransform = ((Component)this).GetComponent<RectTransform>();
			GameObject val = new GameObject("lineTransform");
			val.transform.SetParent((Transform)(object)rectTransform, false);
			lineTransform = val.AddComponent<RectTransform>();
			lineImage = val.AddComponent<RawImage>();
			((Graphic)lineImage).color = new Color(0.8f, 0.8f, 0.8f, 0.8f);
			lineImage.texture = (Texture)(object)GenerateHorizontalAlphaFadeTexture(2048, 10);
			lineTransform.anchorMin = new Vector2(0f, 0.5f);
			lineTransform.anchorMax = new Vector2(1f, 0.5f);
			lineTransform.pivot = new Vector2(0.5f, 0.5f);
			lineTransform.offsetMin = new Vector2(0f, -2f);
			lineTransform.offsetMax = new Vector2(0f, 2f);
			CompassUIPlugin.Log.LogInfo((object)"Creating compass marks...");
			for (int i = 0; i < marks.Length; i++)
			{
				marks[i] = SpawnCompassMark(i);
			}
			for (int j = 0; j < playerBuffer.Length; j++)
			{
				playerBuffer[j] = SpawnPlayerMarker(j);
			}
			for (int k = 0; k < suitcaseBuffer.Length; k++)
			{
				suitcaseBuffer[k] = SpawnSuitcaseMarker(k);
			}
			CompassUIPlugin.Log.LogInfo((object)"CompassTapeUI initialized successfully!");
		}

		private CompassMark SpawnCompassMark(int index)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			GameObject val = new GameObject($"Mark_{index}");
			val.transform.SetParent((Transform)(object)rectTransform, false);
			CompassMark compassMark = val.AddComponent<CompassMark>();
			float markDegrees = (float)index / 24f * 360f;
			compassMark.Init(markDegrees);
			return compassMark;
		}

		private CompassMark SpawnPlayerMarker(int index)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			GameObject val = new GameObject($"PlayerMarker_{index}");
			val.transform.SetParent((Transform)(object)rectTransform, false);
			CompassMark compassMark = val.AddComponent<CompassMark>();
			compassMark.Init(index, isForPlayer: true);
			return compassMark;
		}

		private CompassMark SpawnSuitcaseMarker(int index)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			GameObject val = new GameObject($"SuitcaseMarker_{index}");
			val.transform.SetParent((Transform)(object)rectTransform, false);
			CompassMark compassMark = val.AddComponent<CompassMark>();
			compassMark.Init(index, isForPlayer: false, isForSuitcase: true);
			return compassMark;
		}

		private void Update()
		{
			//IL_0006: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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_00c2: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: 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)
			if (Input.GetKeyDown(CompassUIPlugin.suitcasePingKeybind.Value))
			{
				showSuitcasesUntilTime = Time.time + 6f;
			}
			if (!((Object)(object)Camera.main == (Object)null))
			{
				Transform transform = ((Component)Camera.main).transform;
				Vector3 val = new Vector3(transform.forward.x, 0f, transform.forward.z);
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				Vector3 rightVector = Vector3.Cross(Vector3.up, normalized);
				Vector3 position = transform.position;
				for (int i = 0; i < marks.Length; i++)
				{
					UpdateMark(marks[i], normalized, rightVector);
				}
				for (int j = 0; j < playerBuffer.Length; j++)
				{
					UpdatePlayerMark(j, normalized, rightVector, position);
				}
				for (int k = 0; k < suitcaseBuffer.Length; k++)
				{
					UpdateSuitcaseMark(k, normalized, rightVector, position);
				}
			}
		}

		private void UpdateMark(CompassMark mark, Vector3 headingVector, Vector3 rightVector)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0096: 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)
			Vector3 precomputedDirectionVector = mark.precomputedDirectionVector;
			float num = Vector3.Dot(precomputedDirectionVector, headingVector);
			if (num < 0f)
			{
				mark.canvasGroup.alpha = 0f;
				return;
			}
			float num2 = Vector3.Dot(precomputedDirectionVector, rightVector);
			float num3 = Mathf.Acos(num) / MathF.PI * 2f;
			if (num2 < 0f)
			{
				num3 *= -1f;
			}
			Rect rect = rectTransform.rect;
			float num4 = ((Rect)(ref rect)).width * 0.5f;
			float num5 = num3 * num4;
			mark.rectTransform.anchoredPosition = new Vector2(num5, mark.rectTransform.anchoredPosition.y);
			float num6 = Mathf.InverseLerp(1f, 0.6f, Mathf.Abs(num3));
			mark.canvasGroup.alpha = Mathf.Clamp01(num6);
		}

		private void UpdatePlayerMark(int index, Vector3 headingVector, Vector3 rightVector, Vector3 cameraPosition)
		{
			//IL_00c6: 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_00cb: 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_00cd: 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_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: 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_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: 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_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: 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_0295: Unknown result type (might be due to invalid IL or missing references)
			CompassMark compassMark = playerBuffer[index];
			if (!CompassUIPlugin.showPlayersOnCompass.Value)
			{
				compassMark.canvasGroup.alpha = 0f;
				return;
			}
			if (Character.AllCharacters == null || index >= Character.AllCharacters.Count)
			{
				compassMark.canvasGroup.alpha = 0f;
				return;
			}
			Character val = Character.AllCharacters[index];
			if ((Object)(object)val == (Object)null || val.IsLocal)
			{
				compassMark.canvasGroup.alpha = 0f;
				return;
			}
			Vector3 val2 = (val.data.dead ? ((Component)val.Ghost).transform.position : val.Center);
			Vector3 val3 = val2 - cameraPosition;
			Vector3 val4 = new Vector3(val3.x, 0f, val3.z);
			Vector3 normalized = ((Vector3)(ref val4)).normalized;
			float num = Vector3.Dot(normalized, headingVector);
			if (num < 0f)
			{
				compassMark.canvasGroup.alpha = 0f;
				return;
			}
			float num2 = Vector3.Dot(normalized, rightVector);
			float num3 = Mathf.Acos(num) / MathF.PI * 2f;
			if (num2 < 0f)
			{
				num3 *= -1f;
			}
			Rect rect = rectTransform.rect;
			float num4 = ((Rect)(ref rect)).width * 0.5f;
			float num5 = num3 * num4;
			compassMark.rectTransform.anchoredPosition = new Vector2(num5, compassMark.rectTransform.anchoredPosition.y);
			float num6 = Mathf.InverseLerp(1f, 0.6f, Mathf.Abs(num3));
			compassMark.canvasGroup.alpha = Mathf.Clamp01(num6);
			float num7 = Vector3.Distance(val2, cameraPosition);
			((Graphic)compassMark.iconImage).color = val.refs.customization.PlayerColor;
			compassMark.tmpText.text = $"{num7:F0}m";
			float num8 = val2.y - cameraPosition.y;
			if (num8 >= 7.5f)
			{
				((Behaviour)compassMark.arrowImage).enabled = true;
				((Component)compassMark.arrowImage).transform.localEulerAngles = new Vector3(0f, 0f, 180f);
			}
			else if (num8 <= -7.5f)
			{
				((Behaviour)compassMark.arrowImage).enabled = true;
				((Component)compassMark.arrowImage).transform.localEulerAngles = Vector3.zero;
			}
			else
			{
				((Behaviour)compassMark.arrowImage).enabled = false;
			}
		}

		private void UpdateSuitcaseMark(int index, Vector3 headingVector, Vector3 rightVector, Vector3 cameraPosition)
		{
			//IL_00b3: 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_00b9: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: 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_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: 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_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: 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_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			CompassMark compassMark = suitcaseBuffer[index];
			if (Luggage.ALL_LUGGAGE == null || index >= Luggage.ALL_LUGGAGE.Count)
			{
				compassMark.canvasGroup.alpha = 0f;
				return;
			}
			Luggage val = Luggage.ALL_LUGGAGE[index];
			if ((Object)(object)val == (Object)null)
			{
				compassMark.canvasGroup.alpha = 0f;
				return;
			}
			if (!CompassUIPlugin.alwaysShowSuitcases.Value && Time.time >= showSuitcasesUntilTime)
			{
				compassMark.canvasGroup.alpha = 0f;
				return;
			}
			Vector3 position = ((Component)val).transform.position;
			if (position.y <= 0f)
			{
				compassMark.canvasGroup.alpha = 0f;
				return;
			}
			float num = Vector3.Distance(position, cameraPosition);
			if (num > CompassUIPlugin.suitcaseDistance.Value)
			{
				compassMark.canvasGroup.alpha = 0f;
				return;
			}
			Vector3 val2 = position - cameraPosition;
			Vector3 val3 = new Vector3(val2.x, 0f, val2.z);
			Vector3 normalized = ((Vector3)(ref val3)).normalized;
			float num2 = Vector3.Dot(normalized, headingVector);
			if (num2 < 0f)
			{
				compassMark.canvasGroup.alpha = 0f;
				return;
			}
			float num3 = Vector3.Dot(normalized, rightVector);
			float num4 = Mathf.Acos(num2) / MathF.PI * 2f;
			if (num3 < 0f)
			{
				num4 *= -1f;
			}
			Rect rect = rectTransform.rect;
			float num5 = ((Rect)(ref rect)).width * 0.5f;
			float num6 = num4 * num5;
			compassMark.rectTransform.anchoredPosition = new Vector2(num6, compassMark.rectTransform.anchoredPosition.y);
			float num7 = Mathf.Abs(num4);
			float num8 = Mathf.InverseLerp(1f, 0.6f, num7);
			float num9 = Mathf.Clamp01(num8);
			if (!CompassUIPlugin.alwaysShowSuitcases.Value)
			{
				float num10 = Mathf.InverseLerp(showSuitcasesUntilTime, showSuitcasesUntilTime - 0.5f, Time.time);
				num9 *= Mathf.Clamp01(num10);
			}
			compassMark.canvasGroup.alpha = num9;
			compassMark.tmpText.text = $"{num:F0}m";
			float num11 = position.y - cameraPosition.y;
			if (num11 >= 7.5f)
			{
				((Behaviour)compassMark.arrowImage).enabled = true;
				((Component)compassMark.arrowImage).transform.localEulerAngles = new Vector3(0f, 0f, 180f);
			}
			else if (num11 <= -7.5f)
			{
				((Behaviour)compassMark.arrowImage).enabled = true;
				((Component)compassMark.arrowImage).transform.localEulerAngles = Vector3.zero;
			}
			else
			{
				((Behaviour)compassMark.arrowImage).enabled = false;
			}
		}

		private Texture2D GenerateHorizontalAlphaFadeTexture(int width, int height)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//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)
			Texture2D val = new Texture2D(width, height, (TextureFormat)4, false);
			((Texture)val).filterMode = (FilterMode)1;
			float num = (float)width * 0.35f;
			float num2 = (float)width * 0.65f;
			for (int i = 0; i < height; i++)
			{
				for (int j = 0; j < width; j++)
				{
					byte b = ((!((float)j < num)) ? ((!((float)j > num2)) ? byte.MaxValue : ((byte)(Mathf.InverseLerp((float)width, num2, (float)j) * 255f))) : ((byte)(Mathf.InverseLerp(0f, num, (float)j) * 255f)));
					val.SetPixel(j, i, Color32.op_Implicit(new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, b)));
				}
			}
			val.Apply();
			return val;
		}
	}
	public class CompassMark : MonoBehaviour
	{
		public Vector3 precomputedDirectionVector;

		public CanvasGroup canvasGroup;

		public RectTransform rectTransform;

		public TMP_Text tmpText;

		public Image lineImage;

		public RawImage iconImage;

		public RawImage arrowImage;

		private static Texture2D cachedCircle;

		private static Texture2D cachedDiamond;

		private static Texture2D cachedTriangle;

		public void Init(float markDegrees, bool isForPlayer = false, bool isForSuitcase = false)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: 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_02a3: Expected O, but got Unknown
			//IL_02dd: 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_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Expected O, but got Unknown
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0427: Unknown result type (might be due to invalid IL or missing references)
			//IL_043e: Unknown result type (might be due to invalid IL or missing references)
			//IL_044e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0455: Expected O, but got Unknown
			//IL_04a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0501: Unknown result type (might be due to invalid IL or missing references)
			//IL_0518: 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_01b6: 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_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Expected O, but got Unknown
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			float num = markDegrees * (MathF.PI / 180f);
			Vector3 val = new Vector3(Mathf.Sin(num), 0f, Mathf.Cos(num));
			precomputedDirectionVector = ((Vector3)(ref val)).normalized;
			rectTransform = ((Component)this).gameObject.AddComponent<RectTransform>();
			canvasGroup = ((Component)this).gameObject.AddComponent<CanvasGroup>();
			if (!isForPlayer && !isForSuitcase)
			{
				GameObject val2 = new GameObject("Text");
				val2.transform.SetParent((Transform)(object)rectTransform, false);
				tmpText = (TMP_Text)(object)val2.AddComponent<TextMeshProUGUI>();
				tmpText.fontSize = ((markDegrees == 0f || markDegrees == 90f || markDegrees == 180f || markDegrees == 270f) ? 40f : 18f);
				((Graphic)tmpText).color = new Color(0.9f, 0.9f, 0.9f, 0.9f);
				tmpText.horizontalAlignment = (HorizontalAlignmentOptions)2;
				tmpText.verticalAlignment = (VerticalAlignmentOptions)512;
				if (markDegrees == 0f)
				{
					tmpText.text = "N";
				}
				else if (markDegrees == 90f)
				{
					tmpText.text = "E";
				}
				else if (markDegrees == 180f)
				{
					tmpText.text = "S";
				}
				else if (markDegrees == 270f)
				{
					tmpText.text = "W";
				}
				else
				{
					tmpText.text = markDegrees.ToString("F0");
				}
				RectTransform component = val2.GetComponent<RectTransform>();
				component.sizeDelta = new Vector2(60f, 50f);
				component.anchoredPosition = new Vector2(0f, 25f);
				rectTransform.sizeDelta = new Vector2(5f, 40f);
				GameObject val3 = new GameObject("Line");
				val3.transform.SetParent((Transform)(object)rectTransform, false);
				lineImage = val3.AddComponent<Image>();
				((Graphic)lineImage).color = new Color(0.9f, 0.9f, 0.9f, 0.8f);
				RectTransform component2 = val3.GetComponent<RectTransform>();
				component2.anchorMin = Vector2.zero;
				component2.anchorMax = Vector2.one;
				component2.sizeDelta = Vector2.zero;
				return;
			}
			rectTransform.sizeDelta = new Vector2(40f, 40f);
			GameObject val4 = new GameObject("Icon");
			val4.transform.SetParent((Transform)(object)rectTransform, false);
			iconImage = val4.AddComponent<RawImage>();
			RectTransform component3 = ((Component)iconImage).GetComponent<RectTransform>();
			component3.anchorMin = new Vector2(0.5f, 0.5f);
			component3.anchorMax = new Vector2(0.5f, 0.5f);
			component3.pivot = new Vector2(0.5f, 0.5f);
			component3.sizeDelta = new Vector2(30f, 30f);
			if (isForPlayer)
			{
				iconImage.texture = (Texture)(object)GetCircleTexture();
				((Graphic)iconImage).color = Color.red;
			}
			else
			{
				iconImage.texture = (Texture)(object)GetDiamondTexture();
				((Graphic)iconImage).color = new Color(0.7f, 0.5f, 0.3f, 1f);
			}
			GameObject val5 = new GameObject("Distance");
			val5.transform.SetParent((Transform)(object)rectTransform, false);
			tmpText = (TMP_Text)(object)val5.AddComponent<TextMeshProUGUI>();
			tmpText.fontSize = 18f;
			((Graphic)tmpText).color = Color.white;
			tmpText.horizontalAlignment = (HorizontalAlignmentOptions)2;
			tmpText.verticalAlignment = (VerticalAlignmentOptions)256;
			tmpText.text = "0m";
			RectTransform component4 = val5.GetComponent<RectTransform>();
			component4.sizeDelta = new Vector2(60f, 30f);
			component4.anchoredPosition = new Vector2(0f, -25f);
			GameObject val6 = new GameObject("Arrow");
			val6.transform.SetParent((Transform)(object)rectTransform, false);
			arrowImage = val6.AddComponent<RawImage>();
			arrowImage.texture = (Texture)(object)GetTriangleTexture();
			((Graphic)arrowImage).color = new Color(1f, 1f, 1f, 0.7f);
			((Behaviour)arrowImage).enabled = false;
			RectTransform component5 = ((Component)arrowImage).GetComponent<RectTransform>();
			component5.anchorMin = new Vector2(0.5f, 0.5f);
			component5.anchorMax = new Vector2(0.5f, 0.5f);
			component5.pivot = new Vector2(0.5f, 0.5f);
			component5.sizeDelta = new Vector2(15f, 15f);
		}

		private Texture2D GetCircleTexture()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)cachedCircle != (Object)null)
			{
				return cachedCircle;
			}
			int num = 64;
			cachedCircle = new Texture2D(num, num, (TextureFormat)4, false);
			int num2 = num / 2;
			float num3 = (float)num / 2f - 2f;
			for (int i = 0; i < num; i++)
			{
				for (int j = 0; j < num; j++)
				{
					float num4 = Vector2.Distance(new Vector2((float)j, (float)i), new Vector2((float)num2, (float)num2));
					if (num4 <= num3)
					{
						cachedCircle.SetPixel(j, i, Color.white);
					}
					else
					{
						cachedCircle.SetPixel(j, i, Color.clear);
					}
				}
			}
			cachedCircle.Apply();
			return cachedCircle;
		}

		private Texture2D GetDiamondTexture()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)cachedDiamond != (Object)null)
			{
				return cachedDiamond;
			}
			int num = 64;
			cachedDiamond = new Texture2D(num, num, (TextureFormat)4, false);
			int num2 = num / 2;
			for (int i = 0; i < num; i++)
			{
				for (int j = 0; j < num; j++)
				{
					int num3 = Mathf.Abs(j - num2) + Mathf.Abs(i - num2);
					if (num3 <= num2 - 2)
					{
						cachedDiamond.SetPixel(j, i, Color.white);
					}
					else
					{
						cachedDiamond.SetPixel(j, i, Color.clear);
					}
				}
			}
			cachedDiamond.Apply();
			return cachedDiamond;
		}

		private Texture2D GetTriangleTexture()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_008e: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)cachedTriangle != (Object)null)
			{
				return cachedTriangle;
			}
			int num = 32;
			cachedTriangle = new Texture2D(num, num, (TextureFormat)4, false);
			Vector2 v = default(Vector2);
			((Vector2)(ref v))..ctor((float)num / 2f, (float)num * 0.8f);
			Vector2 v2 = default(Vector2);
			((Vector2)(ref v2))..ctor((float)num * 0.2f, (float)num * 0.2f);
			Vector2 v3 = default(Vector2);
			((Vector2)(ref v3))..ctor((float)num * 0.8f, (float)num * 0.2f);
			Vector2 point = default(Vector2);
			for (int i = 0; i < num; i++)
			{
				for (int j = 0; j < num; j++)
				{
					((Vector2)(ref point))..ctor((float)j, (float)i);
					if (IsPointInTriangle(point, v, v2, v3))
					{
						cachedTriangle.SetPixel(j, i, Color.white);
					}
					else
					{
						cachedTriangle.SetPixel(j, i, Color.clear);
					}
				}
			}
			cachedTriangle.Apply();
			return cachedTriangle;
		}

		private bool IsPointInTriangle(Vector2 point, Vector2 v1, Vector2 v2, Vector2 v3)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_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)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			float num = Sign(point, v1, v2);
			float num2 = Sign(point, v2, v3);
			float num3 = Sign(point, v3, v1);
			bool flag = num < 0f || num2 < 0f || num3 < 0f;
			bool flag2 = num > 0f || num2 > 0f || num3 > 0f;
			return !(flag && flag2);
		}

		private float Sign(Vector2 p1, Vector2 p2, Vector2 p3)
		{
			//IL_0001: 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_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_0029: 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)
			return (p1.x - p3.x) * (p2.y - p3.y) - (p2.x - p3.x) * (p1.y - p3.y);
		}
	}
}