Decompiled source of BetterHudLite v0.3.0

plugins/BetterHudLite.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using EntityStates.Seeker;
using On.EntityStates.Seeker;
using On.RoR2.UI;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.UI;
using UnityEngine;
using UnityEngine.AddressableAssets;
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: AssemblyCompany("BetterHudLite")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+9d55d99a5adf679d7486465bdc64cc38d2f368f8")]
[assembly: AssemblyProduct("BetterHudLite")]
[assembly: AssemblyTitle("BetterHudLite")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace BetterHudLite;

public abstract class BaseHudHandler : MonoBehaviour
{
	protected HUD _hud;

	public void Init(HUD hud)
	{
		_hud = hud;
		((MonoBehaviour)this).StartCoroutine(hackyDelayedMoveHud());
	}

	private IEnumerator hackyDelayedMoveHud()
	{
		yield return null;
		MoveHud();
	}

	protected abstract void MoveHud();
}
[BepInPlugin("com.TheTimeSweeper.BetterHudLite", "BetterHudLite", "0.3.0")]
public class BetterHudLitePlugin : BaseUnityPlugin
{
	public static BetterHudLitePlugin instance;

	private void Awake()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Expected O, but got Unknown
		instance = this;
		Confug.doConfig();
		HUD.Awake += new hook_Awake(HUD_Awake);
		MeditationUI.SetupInputUIIcons += new hook_SetupInputUIIcons(MeditationUI_SetupInputUIIcons);
	}

	private void HUD_Awake(orig_Awake orig, HUD self)
	{
		//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)
		orig.Invoke(self);
		if (Confug.doBar)
		{
			((Component)self).gameObject.AddComponent<HealthHudHandler>().Init(self);
		}
		if (Confug.doSkills)
		{
			((Component)self).gameObject.AddComponent<SkillsHudHandler>().Init(self);
		}
		if (Confug.doNuke)
		{
			BoxNukerHudHandler.frame = Addressables.LoadAssetAsync<Sprite>((object)"RoR2/Base/UI/texUIHighlightHeader.png").WaitForCompletion();
			((Component)self).gameObject.AddComponent<BoxNukerHudHandler>().Init(self);
		}
	}

	private void MeditationUI_SetupInputUIIcons(orig_SetupInputUIIcons orig, MeditationUI self)
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		orig.Invoke(self);
		if (Confug.doSkills)
		{
			((Component)self.overlayInstanceChildLocator).transform.localPosition = new Vector3(0f, 120f, 0f);
		}
	}

	private void ShowBoxesGodDang(HUD hud)
	{
		Sprite sprite = ((Component)hud.mainUIPanel.transform.Find("SpringCanvas/BottomRightCluster/Scaler/Outline")).GetComponent<Image>().sprite;
		RectTransform[] componentsInChildren = hud.mainUIPanel.GetComponentsInChildren<RectTransform>();
		foreach (RectTransform val in componentsInChildren)
		{
			if ((Object)(object)((Component)val).GetComponent<Graphic>() == (Object)null)
			{
				Image val2 = ((Component)val).gameObject.AddComponent<Image>();
				val2.sprite = sprite;
				val2.type = (Type)1;
			}
		}
	}
}
public class BoxNukerHudHandler : BaseHudHandler
{
	public static Sprite frame;

	protected override void MoveHud()
	{
		Image[] componentsInChildren = _hud.mainUIPanel.GetComponentsInChildren<Image>();
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			if ((Object)(object)componentsInChildren[i].sprite == (Object)(object)frame)
			{
				((Behaviour)componentsInChildren[i]).enabled = false;
			}
		}
	}
}
public class Confug
{
	private static bool loadedIcon;

	private static ConfigEntry<bool> _doBar;

	private static ConfigEntry<bool> _doSkills;

	private static ConfigEntry<bool> _hideSkillKeys;

	private static ConfigEntry<bool> _doNuke;

	public static float healthBarWidth = 1f;

	public static float healthBarHeight = 1f;

	public static bool doBar
	{
		get
		{
			reloadConfig();
			return _doBar.Value;
		}
	}

	public static bool doSkills
	{
		get
		{
			reloadConfig();
			return _doSkills.Value;
		}
	}

	public static bool HideSkillKeys
	{
		get
		{
			reloadConfig();
			return _hideSkillKeys.Value;
		}
	}

	public static bool doNuke
	{
		get
		{
			reloadConfig();
			return _doNuke.Value;
		}
	}

	private static BetterHudLitePlugin plugin => BetterHudLitePlugin.instance;

	private static void reloadConfig()
	{
		((BaseUnityPlugin)plugin).Config.Reload();
	}

	public static void doConfig()
	{
		string section = "Health UI";
		_doBar = BindAndOptions(section, "Do the health bar", defaultValue: true, "Brings the health and level bar to the center");
		healthBarWidth = BindAndOptions(section, "Health Bar Width Factor", 1f, "size of health bar, range 0 to 4.5, 0 making it nonexistent, 4.5 making it cover the screen\nless than 0 just shifts it to the right, higher than 4.5 goes off screen obviously").Value;
		healthBarHeight = BindAndOptions(section, "Health Bar Height Multiplier", 1f, "multiply health bar height by this value\nexpands both up and down. attempts to move skills with it").Value;
		string section2 = "Skills UI";
		_doSkills = BindAndOptions(section2, "Do the skills", defaultValue: true, "Brings the skills to the center above where the health bar is (if that's also enabled)");
		_hideSkillKeys = BindAndOptions(section2, "Hide Skill Keys", defaultValue: false, "Hide the M1, M2, etc under your skills. Woops oversight requires Do The Skills enabled, don't have time to fix sorry");
		string section3 = "Other";
		_doNuke = BindAndOptions(section3, "Nuke all transparent boxes", defaultValue: false, "Finds all transparent boxes on the hud (like the one around inventory and currencies) and hides them.");
	}

	public static ConfigEntry<T> BindAndOptions<T>(string section, string name, T defaultValue, string description = "", bool restartRequired = false)
	{
		return BindAndOptions(section, name, defaultValue, 0f, 20f, description, restartRequired);
	}

	public static ConfigEntry<T> BindAndOptions<T>(string section, string name, T defaultValue, float min, float max, string description = "", bool restartRequired = false)
	{
		if (string.IsNullOrEmpty(description))
		{
			description = name;
		}
		description += $"\nDefault: {defaultValue}";
		if (restartRequired)
		{
			description += " (restart required)";
		}
		ConfigEntry<T> val = ((BaseUnityPlugin)BetterHudLitePlugin.instance).Config.Bind<T>(section, name, defaultValue, description);
		if (Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions"))
		{
			TryRegisterOption<T>(val, min, max, restartRequired);
		}
		return val;
	}

	public static ConfigEntry<float> BindAndOptionsSlider(string section, string name, float defaultValue, string description, float min = 0f, float max = 20f, bool restartRequired = false)
	{
		return BindAndOptions(section, name, defaultValue, min, max, description, restartRequired);
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	private static void TryRegisterOption<T>(ConfigEntry<T> entry, float min, float max, bool restartRequired)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: 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_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Expected O, but got Unknown
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Expected O, but got Unknown
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: 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_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Expected O, but got Unknown
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Expected O, but got Unknown
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Expected O, but got Unknown
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Expected O, but got Unknown
		if (entry is ConfigEntry<float>)
		{
			ModSettingsManager.AddOption((BaseOption)new SliderOption(entry as ConfigEntry<float>, new SliderConfig
			{
				min = min,
				max = max,
				formatString = "{0:0.00}",
				restartRequired = restartRequired
			}));
		}
		if (entry is ConfigEntry<int>)
		{
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(entry as ConfigEntry<int>, new IntSliderConfig
			{
				min = (int)min,
				max = (int)max,
				restartRequired = restartRequired
			}));
		}
		if (entry is ConfigEntry<bool>)
		{
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(entry as ConfigEntry<bool>, restartRequired));
		}
		if (entry is ConfigEntry<KeyboardShortcut>)
		{
			ModSettingsManager.AddOption((BaseOption)new KeyBindOption(entry as ConfigEntry<KeyboardShortcut>, restartRequired));
		}
		if (!loadedIcon)
		{
			loadedIcon = true;
			try
			{
				ModSettingsManager.SetModIcon(LoadSpriteFromModFolder("icon.png"));
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("error adding ROO mod icon\n" + ex));
			}
		}
	}

	internal static Sprite LoadSpriteFromModFolder(string fileName, bool pointFilter = false)
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_0097: 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)
		string path = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)BetterHudLitePlugin.instance).Info.Location), fileName);
		Texture2D val = new Texture2D(2, 2);
		byte[] array = File.ReadAllBytes(path);
		ImageConversion.LoadImage(val, array);
		((Texture)val).filterMode = (FilterMode)((!pointFilter) ? 1 : 0);
		val.Apply();
		if (pointFilter)
		{
			((Texture)val).filterMode = (FilterMode)0;
			val.Apply();
		}
		((Object)val).name = fileName;
		((Texture)val).filterMode = (FilterMode)0;
		val.Apply();
		Rect val2 = default(Rect);
		((Rect)(ref val2))..ctor(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height);
		Sprite val3 = Sprite.Create(val, val2, new Vector2(0.5f, 0.5f), 16f);
		((Object)val3).name = fileName;
		return val3;
	}
}
public class HealthHudHandler : BaseHudHandler
{
	protected override void MoveHud()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		//IL_005c: 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_007e: 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)
		RectTransform val = (RectTransform)_hud.mainUIPanel.transform.Find("SpringCanvas/BottomLeftCluster/BarRoots");
		Transform val2 = ((Transform)val).Find("LevelDisplayCluster/BuffDisplayRoot");
		val2.SetParent(((Transform)val).parent);
		((Transform)val).SetParent(_hud.mainUIPanel.transform.Find("SpringCanvas/BottomCenterCluster"));
		((Transform)val).rotation = Quaternion.identity;
		val.pivot = new Vector2(0.5f, 0.25f);
		val.anchoredPosition = Vector2.zero;
		val.sizeDelta = new Vector2(-432f + -432f * (0f - (Confug.healthBarWidth - 1f)), Confug.healthBarHeight * 72f);
	}
}
public class SkillsHudHandler : BaseHudHandler
{
	protected override void MoveHud()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Expected O, but got Unknown
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Expected O, but got Unknown
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Expected O, but got Unknown
		//IL_008a: 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)
		//IL_00b6: 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_00d3: Expected O, but got Unknown
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: 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_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: 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_01a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_027d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f0: Expected O, but got Unknown
		//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0313: Unknown result type (might be due to invalid IL or missing references)
		//IL_0329: Unknown result type (might be due to invalid IL or missing references)
		//IL_0330: Expected O, but got Unknown
		//IL_033c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Unknown result type (might be due to invalid IL or missing references)
		//IL_021c: Unknown result type (might be due to invalid IL or missing references)
		//IL_022f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Unknown result type (might be due to invalid IL or missing references)
		RectTransform val = (RectTransform)_hud.mainUIPanel.transform.Find("SpringCanvas/BottomRightCluster");
		RectTransform val2 = (RectTransform)_hud.mainUIPanel.transform.Find("SpringCanvas/BottomCenterCluster");
		RectTransform val3 = (RectTransform)_hud.mainUIPanel.transform.Find("SpringCanvas/BottomRightCluster/Scaler");
		RectTransform val4 = (RectTransform)((Transform)val3).Find("SprintCluster");
		((Transform)val4).SetParent(((Transform)val3).parent);
		val4.anchoredPosition = new Vector2(-100f, 0f);
		val4.anchorMin = new Vector2(1f, 0.5f);
		val4.anchorMax = new Vector2(1f, 0.5f);
		RectTransform val5 = (RectTransform)((Transform)val3).Find("InventoryCluster");
		((Transform)val5).SetParent(((Transform)val3).parent);
		val5.anchoredPosition = new Vector2(-146f, 0f);
		val5.anchorMin = new Vector2(1f, 0.5f);
		val5.anchorMax = new Vector2(1f, 0.5f);
		((Component)val3).transform.SetParent(_hud.mainUIPanel.transform.Find("SpringCanvas/BottomCenterCluster"));
		((Transform)val3).rotation = Quaternion.identity;
		val3.pivot = new Vector2(0.5f, 0f);
		val3.sizeDelta = new Vector2(-639f, -234f);
		float num = Confug.healthBarHeight - 1f;
		float num2 = 18f;
		val3.anchoredPosition = new Vector2(60f, 80f + num * num2);
		InputBindingDisplayController[] componentsInChildren = ((Component)val3).GetComponentsInChildren<InputBindingDisplayController>();
		foreach (InputBindingDisplayController val6 in componentsInChildren)
		{
			if (Confug.HideSkillKeys)
			{
				((Component)((Component)val6).transform.parent).gameObject.SetActive(false);
				continue;
			}
			Transform parent = ((Component)val6).transform.parent;
			Vector3 localPosition = parent.localPosition;
			localPosition.y += 9f;
			parent.localPosition = localPosition;
			Image component = ((Component)parent).GetComponent<Image>();
			Color color = ((Graphic)component).color;
			color.a = 0.76f;
			((Graphic)component).color = color;
		}
		((Component)((Transform)val3).Find("UtilityArea")).transform.localPosition = new Vector3(-363f, 0f, 0f);
		GraphicRaycaster component2 = ((Component)val).GetComponent<GraphicRaycaster>();
		GraphicRaycaster val7 = ((Component)val2).gameObject.AddComponent<GraphicRaycaster>();
		val7.blockingObjects = component2.blockingObjects;
		val7.ignoreReversedGraphics = component2.ignoreReversedGraphics;
		((MonoBehaviour)val7).useGUILayout = ((MonoBehaviour)component2).useGUILayout;
		RectTransform val8 = (RectTransform)_hud.mainUIPanel.transform.parent.Find("NotificationArea");
		val8.anchorMin = new Vector2(0.8f, 0.05f);
		val8.anchorMax = new Vector2(0.8f, 0.05f);
		RectTransform val9 = (RectTransform)((Transform)val2).Find("SpectatorLabel");
		val9.anchoredPosition = new Vector2(0f, 150f);
	}
}