Decompiled source of ExtractionCompass v0.2.0

ExtractionCompass.dll

Decompiled 8 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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("ExtractionCompass")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ExtractionCompass")]
[assembly: AssemblyTitle("ExtractionCompass")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ExtractionCompass
{
	[BepInPlugin("lch.extractioncompass", "ExtractionCompass", "0.1.1")]
	public class CompassPlugin : BaseUnityPlugin
	{
		public const string GUID = "lch.extractioncompass";

		public const string MODNAME = "ExtractionCompass";

		public const string VERSION = "0.1.1";

		private GUIStyle _style;

		private ExtractionPoint[] _cache = (ExtractionPoint[])(object)new ExtractionPoint[0];

		private float _refreshTimer;

		private string _label = "";

		private static readonly FieldInfo _fState = typeof(ExtractionPoint).GetField("currentState", BindingFlags.Instance | BindingFlags.NonPublic);

		private void Awake()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			GUIStyle val = new GUIStyle
			{
				fontSize = 16
			};
			val.normal.textColor = Color.cyan;
			val.alignment = (TextAnchor)4;
			val.fontStyle = (FontStyle)1;
			_style = val;
		}

		private void Update()
		{
			//IL_0101: 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_010c: 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_013b: 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_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: 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_00b5: 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)
			_refreshTimer -= Time.deltaTime;
			if (_refreshTimer <= 0f)
			{
				_refreshTimer = 1f;
				_cache = Object.FindObjectsOfType<ExtractionPoint>();
			}
			Camera main = Camera.main;
			if ((Object)(object)main == (Object)null || (Object)(object)PlayerController.instance == (Object)null)
			{
				_label = "";
				return;
			}
			Transform transform = ((Component)PlayerController.instance).transform;
			ExtractionPoint val = null;
			float num = float.MaxValue;
			ExtractionPoint[] cache = _cache;
			foreach (ExtractionPoint val2 in cache)
			{
				if (!((Object)(object)val2 == (Object)null) && Object.op_Implicit((Object)(object)((Component)val2).gameObject) && ((Component)val2).gameObject.activeInHierarchy && !IsCompleted(val2))
				{
					float num2 = Vector3.Distance(transform.position, ((Component)val2).transform.position);
					if (num2 < num)
					{
						num = num2;
						val = val2;
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				_label = "";
				return;
			}
			Vector3 val3 = ((Component)val).transform.position - transform.position;
			val3.y = 0f;
			if (!(((Vector3)(ref val3)).sqrMagnitude < 0.01f))
			{
				((Vector3)(ref val3)).Normalize();
				Vector3 forward = ((Component)main).transform.forward;
				forward.y = 0f;
				if (!(((Vector3)(ref forward)).sqrMagnitude < 0.01f))
				{
					((Vector3)(ref forward)).Normalize();
					float num3 = Vector3.SignedAngle(forward, val3, Vector3.up);
					string arg = ((num3 > 20f && num3 <= 70f) ? "↗" : ((num3 > 70f && num3 <= 110f) ? "→" : ((num3 > 110f && num3 <= 160f) ? "↘" : ((num3 >= -20f && num3 <= 20f) ? "↑" : ((num3 < -20f && num3 >= -70f) ? "↖" : ((!(num3 < -70f) || !(num3 >= -110f)) ? "↙" : "←"))))));
					_label = (val.isLocked ? $"EXTRACT? {arg} {num:0}m" : $"EXTRACT {arg} {num:0}m");
				}
			}
		}

		private void OnGUI()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_004f: 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_0076: 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_0094: 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)
			if (!string.IsNullOrEmpty(_label))
			{
				Vector2 val = _style.CalcSize(new GUIContent(_label));
				GUI.Box(new Rect((float)Screen.width / 2f - val.x / 2f, 8f, val.x + 16f, val.y + 10f), "");
				GUI.Label(new Rect((float)Screen.width / 2f - val.x / 2f, 12f, val.x + 16f, val.y + 10f), _label, _style);
			}
		}

		private bool IsCompleted(ExtractionPoint p)
		{
			try
			{
				string text = _fState.GetValue(p)?.ToString();
				return text == "Complete" || text == "TaxReturn";
			}
			catch
			{
				return false;
			}
		}
	}
}