Decompiled source of AltitudeMeter v1.0.1

AltitudeMeter.dll

Decompiled 17 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
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(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("AltitudeMeter")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AltitudeMeter")]
[assembly: AssemblyTitle("AltitudeMeter")]
[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 AltitudeMeter
{
	public enum Preset
	{
		Default,
		AboveStamina
	}
	[BepInPlugin("lurien.peak.altitudemeter", "Altitude Meter", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private TextMeshProUGUI label;

		private RectTransform rectTransform;

		private Canvas canvas;

		private bool fontApplied;

		private int lastHeight = int.MinValue;

		private float nextSpectateCheckTime;

		private Character cachedSpectatedPlayer;

		private ConfigEntry<Preset> configPreset;

		private void Awake()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			configPreset = ((BaseUnityPlugin)this).Config.Bind<Preset>("Settings", "Preset", Preset.Default, "Choose the display preset for the altitude meter");
			((BaseUnityPlugin)this).Config.Save();
			SceneManager.sceneLoaded += delegate(Scene scene, LoadSceneMode mode)
			{
				if ((Object)(object)canvas != (Object)null)
				{
					((Behaviour)canvas).enabled = ((Scene)(ref scene)).name.StartsWith("Level_");
				}
			};
			GameObject val = new GameObject("AltitudeMeterCanvas");
			Object.DontDestroyOnLoad((Object)(object)val);
			canvas = val.AddComponent<Canvas>();
			canvas.renderMode = (RenderMode)0;
			canvas.sortingOrder = 999;
			val.AddComponent<CanvasScaler>();
			GameObject val2 = new GameObject("AltitudeText");
			val2.transform.SetParent(val.transform, false);
			label = val2.AddComponent<TextMeshProUGUI>();
			((Graphic)label).color = Color.white;
			rectTransform = ((TMP_Text)label).rectTransform;
			rectTransform.sizeDelta = new Vector2(400f, 70f);
			UpdatePreset();
			configPreset.SettingChanged += delegate
			{
				UpdatePreset();
			};
		}

		private void UpdatePreset()
		{
			//IL_0067: 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_009d: 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_00fa: 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)
			//IL_0130: 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)
			if (!((Object)(object)rectTransform == (Object)null) && !((Object)(object)label == (Object)null))
			{
				switch (configPreset.Value)
				{
				case Preset.Default:
					((TMP_Text)label).fontSize = 30f;
					rectTransform.anchorMin = new Vector2(0.5f, 1f);
					rectTransform.anchorMax = new Vector2(0.5f, 1f);
					rectTransform.pivot = new Vector2(0.5f, 1f);
					rectTransform.anchoredPosition = new Vector2(0f, -20f);
					((TMP_Text)label).alignment = (TextAlignmentOptions)258;
					break;
				case Preset.AboveStamina:
					((TMP_Text)label).fontSize = 28f;
					rectTransform.anchorMin = new Vector2(0f, 0f);
					rectTransform.anchorMax = new Vector2(0f, 0f);
					rectTransform.pivot = new Vector2(0f, 0f);
					rectTransform.anchoredPosition = new Vector2(35f, 160f);
					((TMP_Text)label).alignment = (TextAlignmentOptions)1025;
					break;
				}
			}
		}

		private void Update()
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: 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_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Character.localCharacter == (Object)null)
			{
				return;
			}
			if (!fontApplied)
			{
				TMP_FontAsset val = ((IEnumerable<TMP_FontAsset>)Resources.FindObjectsOfTypeAll<TMP_FontAsset>()).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => ((Object)f).name == "DarumaDropOne-Regular SDF"));
				if ((Object)(object)val != (Object)null)
				{
					((TMP_Text)label).font = val;
					fontApplied = true;
				}
			}
			Character localCharacter = Character.localCharacter;
			float num = localCharacter.Center.y * CharacterStats.unitsToMeters;
			int num2 = Mathf.RoundToInt(num);
			int num3 = num2;
			if (num2 >= 7000)
			{
				float time = Time.time;
				if (time >= nextSpectateCheckTime)
				{
					nextSpectateCheckTime = time + 0.2f;
					Camera main = Camera.main;
					if ((Object)(object)main != (Object)null)
					{
						Character[] array = Object.FindObjectsOfType<Character>();
						float num4 = float.MaxValue;
						Character val2 = null;
						Vector3 position = ((Component)main).transform.position;
						foreach (Character val3 in array)
						{
							if (!((Object)(object)val3 == (Object)(object)Character.localCharacter) && !((Object)(object)val3 == (Object)null))
							{
								float num6 = Vector3.Distance(((Component)val3).transform.position, position);
								if (num6 < num4)
								{
									num4 = num6;
									val2 = val3;
								}
							}
						}
						cachedSpectatedPlayer = val2;
					}
				}
				if ((Object)(object)cachedSpectatedPlayer != (Object)null)
				{
					localCharacter = cachedSpectatedPlayer;
					float num7 = localCharacter.Center.y * CharacterStats.unitsToMeters;
					num3 = Mathf.RoundToInt(num7);
				}
			}
			if (num3 != lastHeight)
			{
				lastHeight = num3;
				((TMP_Text)label).text = $"{num3} m";
			}
		}
	}
}