Decompiled source of Robins Dynamic Compass v0.1.0

RobinsDynamicCompass.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
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.Logging;
using HarmonyLib;
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: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("ThatRobin3001")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RobinsDynamicCompass")]
[assembly: AssemblyTitle("RobinsDynamicCompass")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 InfiniteCompass : MonoBehaviour
{
	private struct CompassMarker
	{
		public Transform transform;

		public TMP_Text text;

		public float worldAngle;
	}

	[Header("Settings")]
	public float maxVisibleAngle = 60f;

	public float scrollSmoothness = 5f;

	public float markerSpacing = 80f;

	private TMP_FontAsset fontAsset;

	private List<CompassMarker> markers = new List<CompassMarker>();

	private float currentAngle;

	private float targetAngle;

	private void Update()
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)PlayerAvatar.instance != (Object)null && (Object)(object)PlayerAvatar.instance.localCameraTransform != (Object)null)
		{
			targetAngle = PlayerAvatar.instance.localCameraTransform.eulerAngles.y;
			currentAngle = Mathf.LerpAngle(currentAngle, targetAngle, scrollSmoothness * Time.deltaTime);
			UpdateMarkerPositions();
		}
		else
		{
			Debug.LogWarning((object)"PlayerAvatar instance or localCameraTransform not found!");
		}
	}

	public void CreateCompassMarkers(TMP_FontAsset fontAsset)
	{
		this.fontAsset = fontAsset;
		CreateMarker("N", 0f);
		CreateMarker("E", 90f);
		CreateMarker("S", 180f);
		CreateMarker("W", 270f);
		CreateMarker("NE", 45f);
		CreateMarker("SE", 135f);
		CreateMarker("SW", 225f);
		CreateMarker("NW", 315f);
		for (int i = 0; i < 360; i += 15)
		{
			if (i % 45 != 0)
			{
				CreateMarker("-", i);
			}
		}
	}

	private void CreateMarker(string label, float angle)
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Expected O, but got Unknown
		//IL_0071: 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_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject($"CompassMarker_{label}_{angle}", new Type[3]
		{
			typeof(RectTransform),
			typeof(CanvasRenderer),
			typeof(TextMeshProUGUI)
		});
		val.transform.SetParent(((Component)this).transform);
		val.layer = ((Component)this).gameObject.layer;
		RectTransform component = val.GetComponent<RectTransform>();
		((Transform)component).localScale = Vector3.one;
		((Transform)component).localRotation = Quaternion.identity;
		component.anchorMin = new Vector2(0.5f, 0.5f);
		component.anchorMax = new Vector2(0.5f, 0.5f);
		component.pivot = new Vector2(0.5f, 0.5f);
		component.sizeDelta = new Vector2(50f, 50f);
		((Transform)component).localPosition = Vector3.zero;
		TMP_Text component2 = val.GetComponent<TMP_Text>();
		component2.text = label;
		component2.font = fontAsset;
		component2.fontSize = 36f;
		((Graphic)component2).color = Color.white;
		component2.alignment = (TextAlignmentOptions)514;
		component2.verticalAlignment = (VerticalAlignmentOptions)512;
		component2.enableWordWrapping = true;
		component2.overflowMode = (TextOverflowModes)0;
		((Graphic)component2).raycastTarget = false;
		CompassMarker compassMarker = default(CompassMarker);
		compassMarker.transform = val.transform;
		compassMarker.text = val.GetComponentInChildren<TMP_Text>();
		compassMarker.worldAngle = angle;
		CompassMarker item = compassMarker;
		item.text.text = label;
		markers.Add(item);
	}

	private void UpdateMarkerPositions()
	{
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: 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)
		foreach (CompassMarker marker in markers)
		{
			float num = Mathf.DeltaAngle(currentAngle, marker.worldAngle);
			if (Mathf.Abs(num) < maxVisibleAngle)
			{
				float num2 = num / maxVisibleAngle;
				Rect rect = ((Component)this).GetComponent<RectTransform>().rect;
				float num3 = num2 * (((Rect)(ref rect)).width / 2f);
				marker.transform.localPosition = new Vector3(num3, 0f, 0f);
				float num4 = 1f - Mathf.Abs(num) / maxVisibleAngle;
				marker.transform.localScale = Vector3.one * (0.7f + 0.3f * num4);
				((Component)marker.transform).gameObject.SetActive(true);
			}
			else
			{
				((Component)marker.transform).gameObject.SetActive(false);
			}
		}
	}
}
namespace RobinsDynamicCompass
{
	[HarmonyPatch(typeof(EnergyUI))]
	public class EnergyUIPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void Start_Postfix(EnergyUI __instance)
		{
			InfiniteCompassHelper.CreateUI(((Component)__instance).gameObject);
		}
	}
	public class InfiniteCompassHelper : MonoBehaviour
	{
		public static void CreateUI(GameObject energy)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_005a: 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_0072: 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_009e: 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_00ca: 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)
			GameObject val = new GameObject("Compass", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(energy.transform.parent);
			val.layer = energy.layer;
			RectTransform component = val.GetComponent<RectTransform>();
			((Transform)component).localPosition = new Vector3(0f, 160f, 0f);
			((Transform)component).localScale = Vector3.one;
			((Transform)component).localRotation = Quaternion.identity;
			component.anchorMin = new Vector2(0.5f, 1f);
			component.anchorMax = new Vector2(0.5f, 1f);
			component.anchoredPosition = new Vector2(0f, -25f);
			component.pivot = new Vector2(0.5f, 1f);
			component.sizeDelta = new Vector2(250f, 50f);
			EnergyUI component2 = energy.GetComponent<EnergyUI>();
			TMP_FontAsset font = ((TMP_Text)component2.textEnergyMax).font;
			InfiniteCompass infiniteCompass = val.AddComponent<InfiniteCompass>();
			infiniteCompass.CreateCompassMarkers(font);
		}
	}
	[BepInPlugin("ThatRobin3001.RobinsDynamicCompass", "RobinsDynamicCompass", "0.1.0")]
	public class RobinsDynamicCompass : BaseUnityPlugin
	{
		internal static RobinsDynamicCompass Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		internal void Patch()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll(typeof(EnergyUIPatch));
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void Update()
		{
		}
	}
}