Decompiled source of Simple Compass v1.0.1

BepInEx/plugins/SimpleCompass.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("SimpleCompass")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+d540f715d81476ae587631540cea377a0235dcd2")]
[assembly: AssemblyProduct("SimpleCompass")]
[assembly: AssemblyTitle("SimpleCompass")]
[assembly: AssemblyVersion("1.0.1.0")]
namespace SimpleCompass;

public sealed class CompassLineGraphic : MaskableGraphic
{
	private const int LineSegments = 24;

	public float heading;

	public float fov = 160f;

	public bool intercardinalTicks = true;

	public float gapCenter;

	public float gapHalfWidth;

	protected override void OnPopulateMesh(VertexHelper vh)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//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_0034: 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_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: 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_01b2: 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_01cc: 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_01e2: 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_01e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: 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_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: 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_0164: 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_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		vh.Clear();
		Rect rect = ((Graphic)this).rectTransform.rect;
		float num = ((Rect)(ref rect)).width * 0.5f;
		if (num <= 0f)
		{
			return;
		}
		Color32 val = Color32.op_Implicit(((Graphic)this).color);
		for (int i = 0; i < 24; i++)
		{
			float num2 = Mathf.Lerp(0f - num, num, (float)i / 24f);
			float num3 = Mathf.Lerp(0f - num, num, (float)(i + 1) / 24f);
			LinePiece(vh, num2, Mathf.Min(num3, gapCenter - gapHalfWidth), num, val);
			LinePiece(vh, Mathf.Max(num2, gapCenter + gapHalfWidth), num3, num, val);
		}
		for (int j = 0; j < 360; j += 45)
		{
			bool flag = j % 90 == 0;
			if (!flag && !intercardinalTicks)
			{
				continue;
			}
			float num4 = CompassMath.BarPosition(heading, j, fov);
			if (!(Mathf.Abs(num4) > 1f))
			{
				float num5 = num4 * num;
				if (!(Mathf.Abs(num5 - gapCenter) < gapHalfWidth))
				{
					float num6 = (flag ? 7f : 4f);
					Color32 val2 = Alpha(val, CompassMath.EdgeFade(num4));
					Quad(vh, new Vector2(num5 - 1f, -1f - num6), new Vector2(num5 - 1f, -1f), new Vector2(num5 + 1f, -1f), new Vector2(num5 + 1f, -1f - num6), val2, val2);
				}
			}
		}
		int currentVertCount = vh.currentVertCount;
		vh.AddVert(new Vector3(0f, -2f), val, Vector4.zero);
		vh.AddVert(new Vector3(5f, -9f), val, Vector4.zero);
		vh.AddVert(new Vector3(-5f, -9f), val, Vector4.zero);
		vh.AddTriangle(currentVertCount, currentVertCount + 1, currentVertCount + 2);
	}

	private static void LinePiece(VertexHelper vh, float x0, float x1, float half, Color32 c)
	{
		//IL_000c: 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_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: 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_004b: Unknown result type (might be due to invalid IL or missing references)
		if (!(x1 <= x0))
		{
			Quad(vh, new Vector2(x0, -1f), new Vector2(x0, 1f), new Vector2(x1, 1f), new Vector2(x1, -1f), Alpha(c, CompassMath.EdgeFade(x0 / half)), Alpha(c, CompassMath.EdgeFade(x1 / half)));
		}
	}

	private static Color32 Alpha(Color32 c, float a)
	{
		//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_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		return new Color32(c.r, c.g, c.b, (byte)((float)(int)c.a * a));
	}

	private static void Quad(VertexHelper vh, Vector2 a, Vector2 b, Vector2 c, Vector2 d, Color32 left, Color32 right)
	{
		//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_000e: 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_001b: 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_0021: 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_002e: 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_0034: 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_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: 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_004a: Unknown result type (might be due to invalid IL or missing references)
		int currentVertCount = vh.currentVertCount;
		vh.AddVert(Vector2.op_Implicit(a), left, Vector4.zero);
		vh.AddVert(Vector2.op_Implicit(b), left, Vector4.zero);
		vh.AddVert(Vector2.op_Implicit(c), right, Vector4.zero);
		vh.AddVert(Vector2.op_Implicit(d), right, Vector4.zero);
		vh.AddTriangle(currentVertCount, currentVertCount + 1, currentVertCount + 2);
		vh.AddTriangle(currentVertCount, currentVertCount + 2, currentVertCount + 3);
	}
}
internal static class CompassMath
{
	public static float Bearing(float dx, float dz)
	{
		return Mathf.Repeat(Mathf.Atan2(dx, dz) * 57.29578f, 360f);
	}

	public static float BarPosition(float heading, float bearing, float fov)
	{
		return Mathf.DeltaAngle(heading, bearing) / (fov * 0.5f);
	}

	public static float EdgeFade(float barPos)
	{
		return 1f - Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.7f, 1f, Mathf.Abs(barPos)));
	}

	public static string FormatDistance(float meters)
	{
		if (!(meters < 1000f))
		{
			return (meters / 1000f).ToString("0.0", CultureInfo.InvariantCulture) + " km";
		}
		return $"{Mathf.RoundToInt(meters)} m";
	}
}
[BepInPlugin("com.mous.simplecompass", "Simple Compass", "1.0.1")]
public class SimpleCompassPlugin : BaseUnityPlugin
{
	public const string PluginGuid = "com.mous.simplecompass";

	public const string PluginName = "Simple Compass";

	public const string PluginVersion = "1.0.1";

	private const float PinDeadZone = 5f;

	private const float FocusDegrees = 10f;

	private static readonly string[] Letters = new string[4] { "N", "E", "S", "W" };

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

	private ConfigEntry<bool> _enabled;

	private ConfigEntry<Vector2> _position;

	private ConfigEntry<float> _width;

	private ConfigEntry<float> _fov;

	private ConfigEntry<float> _opacity;

	private ConfigEntry<bool> _intercardinalTicks;

	private ConfigEntry<float> _fontSize;

	private ConfigEntry<float> _pinRange;

	private ConfigEntry<float> _iconSize;

	private ConfigEntry<bool> _hideCheckedPins;

	private ConfigEntry<bool> _showPinNames;

	private RectTransform _root;

	private CompassLineGraphic _line;

	private readonly TextMeshProUGUI[] _letters = (TextMeshProUGUI[])(object)new TextMeshProUGUI[4];

	private readonly List<Image> _icons = new List<Image>();

	private TextMeshProUGUI _focusLabel;

	private TMP_Text _vanillaText;

	private bool _dragging;

	private Vector2 _dragOffset;

	private void Awake()
	{
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Expected O, but got Unknown
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Expected O, but got Unknown
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Expected O, but got Unknown
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Expected O, but got Unknown
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: Expected O, but got Unknown
		//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Expected O, but got Unknown
		_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "Enabled", true, "Show the compass.");
		_fov = ((BaseUnityPlugin)this).Config.Bind<float>("1 - General", "FieldOfView", 160f, new ConfigDescription("Degrees of heading visible across the bar.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(60f, 360f), Array.Empty<object>()));
		_intercardinalTicks = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "IntercardinalTicks", true, "Small ticks at NE/SE/SW/NW.");
		_position = ((BaseUnityPlugin)this).Config.Bind<Vector2>("2 - Layout", "Position", new Vector2(0.5f, 0.955f), "Bar centre on screen (0..1, x from left, y from bottom). Or open the inventory and drag the compass.");
		_width = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Layout", "Width", 640f, new ConfigDescription("Bar width in HUD units.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(200f, 1600f), Array.Empty<object>()));
		_opacity = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Layout", "Opacity", 0.9f, new ConfigDescription("Overall opacity.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.2f, 1f), Array.Empty<object>()));
		_fontSize = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Layout", "FontSize", 18f, new ConfigDescription("Size of the direction letters and pin label.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 36f), Array.Empty<object>()));
		_pinRange = ((BaseUnityPlugin)this).Config.Bind<float>("3 - Pins", "Range", 300f, new ConfigDescription("Map pins further than this (metres) are not shown. 0 = no pins.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 5000f), Array.Empty<object>()));
		_iconSize = ((BaseUnityPlugin)this).Config.Bind<float>("3 - Pins", "IconSize", 22f, new ConfigDescription("Icon size of a nearby pin; far pins shrink to half.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(8f, 64f), Array.Empty<object>()));
		_hideCheckedPins = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Pins", "HideCheckedPins", true, "Skip pins you crossed out on the map.");
		_showPinNames = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Pins", "ShowPinNames", true, "Show the name next to the distance of the pin closest to the centre.");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Simple Compass 1.0.1 loaded");
	}

	private void Update()
	{
		//IL_00aa: 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_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)Hud.instance == (Object)null || (Object)(object)localPlayer == (Object)null || (Object)(object)GameCamera.instance == (Object)null || ((Object)(object)_root == (Object)null && !TryCreate()))
		{
			return;
		}
		bool flag = _enabled.Value && !Minimap.IsOpen();
		if (((Component)_root).gameObject.activeSelf != flag)
		{
			((Component)_root).gameObject.SetActive(flag);
		}
		if (!flag)
		{
			return;
		}
		float value = _fov.Value;
		float num = _width.Value * 0.5f;
		float y = ((Component)GameCamera.instance).transform.eulerAngles.y;
		_root.sizeDelta = new Vector2(_width.Value, 40f);
		((Component)_root).GetComponent<CanvasGroup>().alpha = _opacity.Value;
		for (int i = 0; i < 4; i++)
		{
			float num2 = CompassMath.BarPosition(y, (float)i * 90f, value);
			TextMeshProUGUI val = _letters[i];
			((Behaviour)val).enabled = Mathf.Abs(num2) <= 1f;
			if (((Behaviour)val).enabled)
			{
				((TMP_Text)val).fontSize = _fontSize.Value;
				((TMP_Text)val).alpha = CompassMath.EdgeFade(num2);
				((TMP_Text)val).rectTransform.anchoredPosition = new Vector2(num2 * num, -11f);
			}
		}
		float gapCenter;
		float num3 = UpdatePins(((Component)localPlayer).transform.position, y, value, num, out gapCenter);
		if (_line.heading != y || _line.fov != value || _line.intercardinalTicks != _intercardinalTicks.Value || _line.gapCenter != gapCenter || _line.gapHalfWidth != num3)
		{
			_line.heading = y;
			_line.fov = value;
			_line.intercardinalTicks = _intercardinalTicks.Value;
			_line.gapCenter = gapCenter;
			_line.gapHalfWidth = num3;
			((Graphic)_line).SetVerticesDirty();
		}
		Drag(InventoryGui.IsVisible());
	}

	private float UpdatePins(Vector3 from, float heading, float fov, float half, out float gapCenter)
	{
		//IL_0269: Unknown result type (might be due to invalid IL or missing references)
		//IL_026e: Unknown result type (might be due to invalid IL or missing references)
		//IL_026f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0274: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Invalid comparison between Unknown and I4
		//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ab: 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_02b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: 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_00c0: 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_0311: Unknown result type (might be due to invalid IL or missing references)
		//IL_032f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0355: 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_00ed: 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_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: 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_01ca: Unknown result type (might be due to invalid IL or missing references)
		gapCenter = 0f;
		int num = 0;
		PinData val = null;
		Image val2 = null;
		float num2 = 10f;
		float value = _pinRange.Value;
		List<PinData> list = ((value > 0f && (Object)(object)Minimap.instance != (Object)null) ? Pins.Invoke(Minimap.instance) : null);
		Vector2 val4;
		if (list != null)
		{
			foreach (PinData item in list)
			{
				if ((Object)(object)item.m_icon == (Object)null || (int)item.m_type == 13 || (item.m_checked && _hideCheckedPins.Value))
				{
					continue;
				}
				Vector3 val3 = item.m_pos - from;
				val4 = new Vector2(val3.x, val3.z);
				float magnitude = ((Vector2)(ref val4)).magnitude;
				if (magnitude < 5f || magnitude > value)
				{
					continue;
				}
				float num3 = CompassMath.BarPosition(heading, CompassMath.Bearing(val3.x, val3.z), fov);
				if (!(Mathf.Abs(num3) > 1f))
				{
					float num4 = magnitude / value;
					Image val5 = Icon(num++);
					val5.sprite = item.m_icon;
					((Graphic)val5).color = new Color(1f, 1f, 1f, CompassMath.EdgeFade(num3) * (1f - Mathf.InverseLerp(0.8f, 1f, num4)));
					((Graphic)val5).rectTransform.sizeDelta = Vector2.one * (_iconSize.Value * Mathf.Lerp(1f, 0.5f, num4));
					((Graphic)val5).rectTransform.anchoredPosition = new Vector2(num3 * half, ((Graphic)val5).rectTransform.sizeDelta.y * 0.5f + 3f);
					float num5 = Mathf.Abs(num3) * fov * 0.5f;
					if (num5 < num2)
					{
						num2 = num5;
						val = item;
						val2 = val5;
					}
				}
			}
		}
		for (int i = num; i < _icons.Count; i++)
		{
			if (((Behaviour)_icons[i]).enabled)
			{
				((Behaviour)_icons[i]).enabled = false;
			}
		}
		((Behaviour)_focusLabel).enabled = val != null;
		if (val == null)
		{
			return 0f;
		}
		Vector3 val6 = val.m_pos - from;
		string text = ((!_showPinNames.Value) ? null : Localization.instance.Localize(val.m_name)?.Trim());
		val4 = new Vector2(val6.x, val6.z);
		string text2 = CompassMath.FormatDistance(((Vector2)(ref val4)).magnitude);
		((TMP_Text)_focusLabel).text = (string.IsNullOrEmpty(text) ? text2 : (text + "  " + text2));
		((TMP_Text)_focusLabel).fontSize = _fontSize.Value * 0.85f;
		gapCenter = ((Graphic)val2).rectTransform.anchoredPosition.x;
		((TMP_Text)_focusLabel).rectTransform.anchoredPosition = new Vector2(gapCenter, 0f);
		((Component)val2).transform.SetAsLastSibling();
		return ((TMP_Text)_focusLabel).GetPreferredValues(((TMP_Text)_focusLabel).text).x * 0.5f + 5f;
	}

	private Image Icon(int index)
	{
		//IL_0033: 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)
		if (index == _icons.Count)
		{
			GameObject val = new GameObject("Pin", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val.transform.SetParent((Transform)(object)_root, false);
			Image component = val.GetComponent<Image>();
			((Graphic)component).raycastTarget = false;
			component.preserveAspect = true;
			_icons.Add(component);
		}
		Image obj = _icons[index];
		((Behaviour)obj).enabled = true;
		return obj;
	}

	private void Drag(bool editing)
	{
		//IL_0002: 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)
		//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_010a: 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_010c: 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_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: 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_0050: 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_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_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		Vector2 val = default(Vector2);
		((Vector2)(ref val))..ctor(Input.mousePosition.x / (float)Screen.width, Input.mousePosition.y / (float)Screen.height);
		if (!_dragging && editing && Input.GetMouseButtonDown(0))
		{
			Canvas rootCanvas = ((Component)_root).GetComponentInParent<Canvas>().rootCanvas;
			Camera val2 = (((int)rootCanvas.renderMode == 0) ? null : rootCanvas.worldCamera);
			if (RectTransformUtility.RectangleContainsScreenPoint(_root, Vector2.op_Implicit(Input.mousePosition), val2))
			{
				_dragging = true;
				_dragOffset = _position.Value - val;
			}
		}
		Vector2 value = _position.Value;
		if (_dragging)
		{
			((Vector2)(ref value))..ctor(Mathf.Clamp01(val.x + _dragOffset.x), Mathf.Clamp01(val.y + _dragOffset.y));
			if (!editing || !Input.GetMouseButton(0))
			{
				_dragging = false;
				_position.Value = value;
			}
		}
		RectTransform root = _root;
		Vector2 anchorMin = (_root.anchorMax = value);
		root.anchorMin = anchorMin;
		_root.anchoredPosition = Vector2.zero;
	}

	private bool TryCreate()
	{
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Expected O, but got Unknown
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Expected O, but got Unknown
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Expected O, but got Unknown
		//IL_00d5: 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_00e7: 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_00fc: 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_011b: 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_017e: 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_01c6: Unknown result type (might be due to invalid IL or missing references)
		_vanillaText = (Object.op_Implicit((Object)(object)Hud.instance.m_statusEffectTemplate) ? ((Component)Hud.instance.m_statusEffectTemplate).GetComponentInChildren<TMP_Text>(true) : null);
		if ((Object)(object)_vanillaText == (Object)null)
		{
			return false;
		}
		GameObject val = new GameObject("SimpleCompass", new Type[2]
		{
			typeof(RectTransform),
			typeof(CanvasGroup)
		});
		_root = (RectTransform)val.transform;
		((Transform)_root).SetParent(Hud.instance.m_rootObject.transform, false);
		CanvasGroup component = val.GetComponent<CanvasGroup>();
		component.blocksRaycasts = false;
		component.interactable = false;
		GameObject val2 = new GameObject("Line", new Type[2]
		{
			typeof(RectTransform),
			typeof(CompassLineGraphic)
		});
		RectTransform val3 = (RectTransform)val2.transform;
		((Transform)val3).SetParent((Transform)(object)_root, false);
		val3.anchorMin = new Vector2(0f, 0.5f);
		val3.anchorMax = new Vector2(1f, 0.5f);
		val3.sizeDelta = new Vector2(0f, 20f);
		_line = val2.GetComponent<CompassLineGraphic>();
		((Graphic)_line).raycastTarget = false;
		((Graphic)_line).color = new Color(0.95f, 0.93f, 0.88f, 0.9f);
		for (int i = 0; i < 4; i++)
		{
			_letters[i] = Text(Letters[i], new Vector2(0.5f, 1f));
		}
		_focusLabel = Text("", new Vector2(0.5f, 0.5f));
		((Graphic)_focusLabel).color = new Color(1f, 0.8f, 0.4f);
		return true;
	}

	private TextMeshProUGUI Text(string text, Vector2 pivot)
	{
		//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_0030: 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_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: 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_009a: 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)
		GameObject val = new GameObject("Text", new Type[2]
		{
			typeof(RectTransform),
			typeof(TextMeshProUGUI)
		});
		RectTransform val2 = (RectTransform)val.transform;
		((Transform)val2).SetParent((Transform)(object)_root, false);
		val2.pivot = pivot;
		val2.sizeDelta = new Vector2(300f, 30f);
		TextMeshProUGUI component = val.GetComponent<TextMeshProUGUI>();
		((TMP_Text)component).font = _vanillaText.font;
		((TMP_Text)component).fontSharedMaterial = _vanillaText.fontSharedMaterial;
		((TMP_Text)component).text = text;
		((Graphic)component).raycastTarget = false;
		((TMP_Text)component).richText = true;
		((TMP_Text)component).alignment = (TextAlignmentOptions)((pivot.y > 0.5f) ? 258 : 4098);
		((TMP_Text)component).textWrappingMode = (TextWrappingModes)0;
		((Graphic)component).color = new Color(0.95f, 0.93f, 0.88f);
		return component;
	}

	private void OnDestroy()
	{
		if ((Object)(object)_root != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)_root).gameObject);
		}
	}
}