Decompiled source of Numerical HUD v1.0.0

Numerical_HUD.dll

Decompiled 4 days 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(".NETFramework,Version=v4.6.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("Numerical_HUD")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+a12467cb2e4a17aba0f75fa1dc3c212304224c31")]
[assembly: AssemblyProduct("Numerical_HUD")]
[assembly: AssemblyTitle("Numerical_HUD")]
[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;
		}
	}
}
namespace Numerical_HUD
{
	[BepInPlugin("Numerical_HUD", "Numerical_HUD", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static Character? localChar;

		internal static GUIManager? manager;

		internal static UITextObject? staminatext;

		internal static UITextObject? extraStam;

		internal static List<UITextObject> afflictions = new List<UITextObject>();

		internal static List<UITextObject> textToCleanup = new List<UITextObject>();

		private static ManualLogSource log = null;

		internal static ManualLogSource Log
		{
			get
			{
				return log;
			}
			private set
			{
				log = value;
			}
		}

		private void OnDestroy()
		{
			textToCleanup.ForEach((Action<UITextObject>)Object.Destroy);
		}

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"Plugin Numerical_HUD is loaded!");
		}

		private void FixedUpdate()
		{
			if ((Object)(object)localChar == (Object)null)
			{
				localChar = Character.localCharacter;
			}
			if ((Object)(object)manager == (Object)null)
			{
				GUIManager instance = GUIManager.instance;
				if ((Object)(object)instance != (Object)null)
				{
					Log.LogInfo((object)"Manager isn't null attempting binding");
					manager = instance;
				}
			}
			if ((Object)(object)localChar != (Object)null && (Object)(object)manager != (Object)null && (Object)(object)staminatext == (Object)null)
			{
				AttachText(manager, localChar);
			}
		}

		private void AttachText(GUIManager manager, Character localChar)
		{
			TMP_FontAsset font = ((TMP_Text)manager.interactPromptText).font;
			((Component)manager.hudCanvas).gameObject.SetActive(false);
			CreateStaminaBarText(font, manager, localChar);
			CreateExtraStaminaBarText(font, manager, localChar);
			CreateAfflictionBarText(font, manager, localChar);
			CreateAltitudeText(font, manager, localChar);
			((Component)manager.hudCanvas).gameObject.SetActive(true);
		}

		private void CreateStaminaBarText(TMP_FontAsset font, GUIManager manager, Character localChar)
		{
			Character localChar2 = localChar;
			staminatext = ((Component)manager.hudCanvas).gameObject.AddComponent<UITextObject>();
			staminatext.Logger = Log;
			staminatext.FontObject = font;
			staminatext.Parent = ((Component)manager.bar.staminaBar).gameObject;
			staminatext.TextName = "Stamina_Bar";
			staminatext.UpdateFunc = () => Math.Round(localChar2.data.currentStamina * 100f, 0, MidpointRounding.ToEven).ToString();
			CollectionExtensions.AddItem<UITextObject>((IEnumerable<UITextObject>)textToCleanup, staminatext);
		}

		private void CreateExtraStaminaBarText(TMP_FontAsset font, GUIManager manager, Character localChar)
		{
			Character localChar2 = localChar;
			extraStam = ((Component)manager.hudCanvas).gameObject.AddComponent<UITextObject>();
			extraStam.Logger = Log;
			extraStam.FontObject = font;
			extraStam.Parent = ((Component)manager.bar.extraBarStamina).gameObject;
			extraStam.TextName = "Extra_Stamina_Bar";
			extraStam.UpdateFunc = () => Math.Round(localChar2.data.extraStamina * 100f, 0, MidpointRounding.ToEven).ToString();
			CollectionExtensions.AddItem<UITextObject>((IEnumerable<UITextObject>)textToCleanup, extraStam);
		}

		private void CreateAfflictionBarText(TMP_FontAsset font, GUIManager manager, Character localChar)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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)
			Character localChar2 = localChar;
			BarAffliction[] array = manager.bar.afflictions;
			foreach (BarAffliction val in array)
			{
				STATUSTYPE afflictionType = val.afflictionType;
				UITextObject uITextObject = ((Component)manager.hudCanvas).gameObject.AddComponent<UITextObject>();
				uITextObject.Logger = Log;
				uITextObject.FontObject = font;
				uITextObject.Parent = ((Component)val).gameObject;
				uITextObject.TextName = $"{val.afflictionType}_Bar";
				uITextObject.UpdateFunc = () => Math.Round(localChar2.refs.afflictions.GetCurrentStatus(afflictionType) * 100f, 0, MidpointRounding.ToEven).ToString();
				CollectionExtensions.AddItem<UITextObject>((IEnumerable<UITextObject>)afflictions, uITextObject);
				CollectionExtensions.AddItem<UITextObject>((IEnumerable<UITextObject>)textToCleanup, uITextObject);
			}
		}

		private void CreateAltitudeText(TMP_FontAsset font, GUIManager manager, Character localChar)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			Character localChar2 = localChar;
			UITextObject uITextObject = ((Component)manager.hudCanvas).gameObject.AddComponent<UITextObject>();
			uITextObject.Logger = Log;
			uITextObject.FontObject = font;
			uITextObject.Parent = ((Component)manager.bar.maxStaminaBar).gameObject;
			uITextObject.AdditionalTranslation = new Vector2(0f, 75f);
			uITextObject.TextName = "Altitude_Text";
			uITextObject.UpdateFunc = () => $"Altitude: {Math.Floor(localChar2.refs.stats.heightInUnits)} ({Math.Floor(localChar2.refs.stats.heightInMeters)}M)";
			CollectionExtensions.AddItem<UITextObject>((IEnumerable<UITextObject>)textToCleanup, uITextObject);
		}
	}
	public class UITextObject : MonoBehaviour
	{
		private readonly GameObject textGameObject = new GameObject();

		private TextMeshProUGUI? textObject;

		private RectTransform? textTransform;

		public GameObject? Parent { get; set; }

		public Func<string>? UpdateFunc { get; set; }

		public TMP_FontAsset? FontObject { get; set; }

		public ManualLogSource? Logger { get; set; }

		public string TextName { get; set; } = "Default";


		public Vector2 AdditionalTranslation { get; set; } = Vector2.zero;


		private void Start()
		{
			//IL_003a: 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_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)
			//IL_0166: 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_0183: Unknown result type (might be due to invalid IL or missing references)
			textObject = textGameObject.AddComponent<TextMeshProUGUI>();
			((TMP_Text)textObject).text = "Init";
			((TMP_Text)textObject).fontSize = 50f;
			((Graphic)textObject).color = Color.white;
			((TMP_Text)textObject).fontStyle = (FontStyles)0;
			((TMP_Text)textObject).outlineColor = Color32.op_Implicit(new Color(50f, 50f, 50f));
			((TMP_Text)textObject).outlineWidth = 25f;
			((TMP_Text)textObject).font = FontObject;
			((TMP_Text)textObject).fontSizeMin = 50f;
			((TMP_Text)textObject).fontSizeMax = 50f;
			((TMP_Text)textObject).horizontalAlignment = (HorizontalAlignmentOptions)2;
			((TMP_Text)textObject).verticalAlignment = (VerticalAlignmentOptions)8192;
			((TMP_Text)textObject).textWrappingMode = (TextWrappingModes)0;
			GameObject val = Parent ?? ((Component)this).gameObject;
			textGameObject.transform.SetParent(val.transform);
			textTransform = textGameObject.GetComponent<RectTransform>();
			textTransform.offsetMax = new Vector2(1f, 1f);
			textTransform.offsetMin = new Vector2(0f, 0f);
			textTransform.sizeDelta = new Vector2(400f, 50f);
			((Transform)textTransform).Translate(AdditionalTranslation.x, AdditionalTranslation.y, 0f);
			ManualLogSource? logger = Logger;
			if (logger != null)
			{
				logger.LogInfo((object)("UITextObject(" + TextName + ") started"));
			}
		}

		private void OnDestroy()
		{
			Object.Destroy((Object)(object)textGameObject);
			Object.Destroy((Object)(object)textObject);
			Object.Destroy((Object)(object)textTransform);
			ManualLogSource? logger = Logger;
			if (logger != null)
			{
				logger.LogInfo((object)("UITextObject(" + TextName + ") Destroyed"));
			}
		}

		private void Update()
		{
			if (Object.op_Implicit((Object)(object)textObject) && UpdateFunc != null)
			{
				((TMP_Text)textObject).text = UpdateFunc();
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Numerical_HUD";

		public const string PLUGIN_NAME = "Numerical_HUD";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}