Decompiled source of Better Weapon HUDs v1.3.0

BetterWeaponHUDs.dll

Decompiled a month ago
using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BetterWeaponHUDs.Properties;
using HarmonyLib;
using JadeLib;
using JadeLib.PluginConfigurator;
using Microsoft.CodeAnalysis;
using PluginConfig.API;
using PluginConfig.API.Decorators;
using PluginConfig.API.Fields;
using TMPro;
using ULTRAKILL.Cheats;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("BetterWeaponHUDs")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.0+53803f1bbb32d284dc23ece5bba25e41657bb549")]
[assembly: AssemblyProduct("BetterWeaponHUDs")]
[assembly: AssemblyTitle("BetterWeaponHUDs")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BetterWeaponHUDs
{
	[HarmonyPatch]
	internal static class Patches
	{
		private static readonly Vector2 speedometerPos = new Vector2(-79f, 590f);

		private static readonly Vector2 altSpeedometerPos = new Vector2(-79f, 190f);

		[HarmonyPatch(typeof(HudController), "Awake")]
		[HarmonyPostfix]
		private static void HudController_Awake(HudController __instance)
		{
			Object.Instantiate<GameObject>(Plugin.Assets.LoadAsset<GameObject>("Gun Canvas"), ((Component)__instance).transform, false);
			__instance.textElements = CollectionExtensions.AddToArray<TMP_Text>(__instance.textElements, Object.Instantiate<GameObject>(Plugin.Assets.LoadAsset<GameObject>("Hard Damage"), ((Component)__instance).transform.Find("GunCanvas/StatsPanel/Filler/Panel (2)/Filler"), false).GetComponent<TMP_Text>());
		}

		[HarmonyPatch(typeof(HudController), "CheckSituation")]
		[HarmonyPostfix]
		private static void HudController_CheckSituation(HudController __instance)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			if (!__instance.altHud)
			{
				RectTransform rect = __instance.speedometer.rect;
				if (rect != null && MonoSingleton<PrefsManager>.Instance.GetBool("weaponIcons", false))
				{
					rect.anchoredPosition = (Settings.AltIndicatorPosition ? altSpeedometerPos : speedometerPos);
				}
				Transform val = ((Component)__instance).transform.Find("Gun Canvas(Clone)");
				((Component)val).gameObject.SetActive(!HideUI.Active && MonoSingleton<PrefsManager>.Instance.GetInt("hudType", 0) == 1);
				Transform obj = ((Component)__instance).transform.Find("GunCanvas/StatsPanel/Filler/Panel (2)/Filler/Hard Damage(Clone)");
				if (obj != null)
				{
					((Component)obj).gameObject.SetActive(Settings.ShowHardDamageNumber);
				}
				__instance.weaponIcon.transform.SetParent(Settings.AltIndicatorPosition ? val : ((Component)__instance).transform.Find("GunCanvas"), false);
			}
		}

		[HarmonyPatch(typeof(RailcannonMeter), "CheckStatus")]
		[HarmonyPostfix]
		private static void RailcannonMeter_CheckStatus(RailcannonMeter __instance)
		{
			if (MonoSingleton<PrefsManager>.Instance.GetBool("weaponIcons", false) && (Settings.AltIndicatorPosition || Settings.ForceAltRailcannonCharge))
			{
				((Behaviour)__instance.self).enabled = false;
				__instance.miniVersion.SetActive(__instance.RailcannonStatus());
			}
		}

		[HarmonyPatch(typeof(Crosshair), "Start")]
		[HarmonyPrefix]
		private static void Crosshair_Start(Crosshair __instance)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			Object.Instantiate<GameObject>(Plugin.Assets.LoadAsset<GameObject>("Railcannon Slider"), ((Component)__instance).transform.Find("PowerUpBar"), false);
			Transform obj = ((Component)__instance).transform.Find("PowerUpBar/HealthSliderAfterImage (2)");
			Transform obj2 = ((obj is RectTransform) ? obj : null);
			((RectTransform)obj2).sizeDelta = new Vector2(50f, 50f);
			((Component)obj2).GetComponent<Image>().fillClockwise = true;
			((Component)obj2).GetComponent<Image>().fillOrigin = 4;
		}

		[HarmonyPatch(typeof(Crosshair), "CheckCrossHair")]
		[HarmonyPostfix]
		private static void Crosshair_CheckCrossHair(Crosshair __instance)
		{
			if (Settings.UseAlternateCrosshair)
			{
				((Behaviour)__instance.mainch).enabled = false;
				Image[] altchs = __instance.altchs;
				for (int i = 0; i < altchs.Length; i++)
				{
					((Behaviour)altchs[i]).enabled = true;
				}
			}
		}

		[HarmonyPatch(typeof(StatsManager), "Update")]
		[HarmonyPostfix]
		private static void StatsManager_Update(StatsManager __instance)
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			GameObject crosshair = __instance.crosshair;
			object obj;
			if (crosshair == null)
			{
				obj = null;
			}
			else
			{
				Transform obj2 = crosshair.transform.Find("PowerUpBar/Railcannon Slider(Clone)");
				obj = ((obj2 != null) ? ((Component)obj2).GetComponent<Image>() : null);
			}
			Image val = (Image)obj;
			if (val != null && (((Behaviour)val).enabled = Settings.ShowRailcannonCharge))
			{
				val.fillAmount = Mathf.Lerp(0f, 0.5f, MonoSingleton<WeaponCharges>.Instance.raicharge / 4f);
				((Graphic)val).color = ((MonoSingleton<WeaponCharges>.Instance.raicharge >= 5f) ? MonoSingleton<ColorBlindSettings>.Instance.railcannonFullColor : MonoSingleton<ColorBlindSettings>.Instance.railcannonChargingColor);
			}
		}

		[HarmonyPatch(typeof(PowerUpMeter), "UpdateMeter")]
		[HarmonyPostfix]
		private static void PowerUpMeter_UpdateMeter(PowerUpMeter __instance)
		{
			if (Settings.ShowRailcannonCharge)
			{
				Image meter = __instance.meter;
				meter.fillAmount /= 2f;
			}
		}

		[HarmonyPatch(typeof(HUDOptions), "WeaponIcon")]
		[HarmonyPostfix]
		private static void HUDOptions_WeaponIcon(bool stuff)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = HudController.Instance?.speedometer.rect;
			if (val != null && stuff)
			{
				val.anchoredPosition = (Settings.AltIndicatorPosition ? altSpeedometerPos : speedometerPos);
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPostfix]
		private static void StyleHUD_set_rankIndex(StyleHUD __instance)
		{
			SetRankImage(__instance);
		}

		[HarmonyPatch(typeof(StyleHUD), "DescendRank")]
		[HarmonyPostfix]
		private static void StyleHUD_DescendRank(StyleHUD __instance)
		{
			SetRankImage(__instance);
		}

		private static void SetRankImage(StyleHUD __instance)
		{
			if (Settings.CustomStyleImages.Length > __instance.rankIndex)
			{
				Sprite val = Settings.CustomStyleImages[__instance.rankIndex];
				if (val != null)
				{
					__instance.rankImage.sprite = val;
				}
			}
		}
	}
	[BepInPlugin("BetterWeaponHUDs", "BetterWeaponHUDs", "1.3.0")]
	internal class Plugin : BaseUnityPlugin
	{
		public static readonly AssetBundle Assets = AssetBundle.LoadFromMemory(Resources.Assets);

		private GameObject FUPIndicator;

		private void Awake()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			Settings.Initialize();
			SceneManager.sceneLoaded += OnSceneLoaded;
			new Harmony("BetterWeaponHUDs").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin BetterWeaponHUDs is loaded!");
		}

		private void Update()
		{
			GameObject fUPIndicator = FUPIndicator;
			if (fUPIndicator != null)
			{
				int active;
				if (Settings.FUPAlert)
				{
					HookArm instance = MonoSingleton<HookArm>.Instance;
					active = ((instance != null && instance.caughtGrenade != null && instance.returning) ? 1 : 0);
				}
				else
				{
					active = 0;
				}
				fUPIndicator.SetActive((byte)active != 0);
			}
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			if (!Object.op_Implicit((Object)(object)FUPIndicator))
			{
				GameObject obj = GameObject.Find("/Canvas");
				Transform val = ((obj != null) ? obj.transform : null);
				if (val != null)
				{
					FUPIndicator = Object.Instantiate<GameObject>(Assets.LoadAsset<GameObject>("FUP Indicator"), val, false);
				}
			}
		}
	}
	public static class Settings
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static PostBoolValueChangeEvent <>9__19_0;

			public static PostBoolValueChangeEvent <>9__19_1;

			public static PostBoolValueChangeEvent <>9__19_2;

			public static PostBoolValueChangeEvent <>9__19_3;

			internal void <Initialize>b__19_0(bool _)
			{
				HUDOptions instance = MonoSingleton<HUDOptions>.Instance;
				if (instance != null)
				{
					instance.crosshair.CheckCrossHair();
				}
			}

			internal void <Initialize>b__19_1(bool _)
			{
				HudController instance = HudController.Instance;
				if (instance != null)
				{
					instance.CheckSituation();
				}
			}

			internal void <Initialize>b__19_2(bool value)
			{
				((ConfigField)forceAltRailcannonCharge).interactable = !value;
				RailcannonMeter instance = MonoSingleton<RailcannonMeter>.Instance;
				if (instance != null)
				{
					instance.CheckStatus();
				}
				HudController instance2 = HudController.Instance;
				if (instance2 != null)
				{
					instance2.CheckSituation();
				}
			}

			internal void <Initialize>b__19_3(bool _)
			{
				RailcannonMeter instance = MonoSingleton<RailcannonMeter>.Instance;
				if (instance != null)
				{
					instance.CheckStatus();
				}
			}
		}

		private static BoolField useAlternateCrosshair;

		private static BoolField showRailcannonCharge;

		private static BoolField showHardDamageNumber;

		private static BoolField altIndicatorPosition;

		private static BoolField forceAltRailcannonCharge;

		private static BoolField fupAlert;

		public static readonly Sprite[] CustomStyleImages = (Sprite[])(object)new Sprite[8];

		public static bool UseAlternateCrosshair => useAlternateCrosshair.value;

		public static bool ShowRailcannonCharge
		{
			get
			{
				if (showRailcannonCharge.value)
				{
					return MonoSingleton<RailcannonMeter>.Instance.RailcannonStatus();
				}
				return false;
			}
		}

		public static bool ShowHardDamageNumber => showHardDamageNumber.value;

		public static bool AltIndicatorPosition => altIndicatorPosition.value;

		public static bool ForceAltRailcannonCharge => forceAltRailcannonCharge.value;

		public static bool FUPAlert => fupAlert.value;

		internal static void Initialize()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Expected O, but got Unknown
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Expected O, but got Unknown
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Expected O, but got Unknown
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Expected O, but got Unknown
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Expected O, but got Unknown
			//IL_0196: 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_01bc: 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_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Expected O, but got Unknown
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Expected O, but got Unknown
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Expected O, but got Unknown
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Expected O, but got Unknown
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Expected O, but got Unknown
			PluginConfigurator val = PluginConfigurator.Create("BetterWeaponHUDs", "BetterWeaponHUDs");
			val.icon = Plugin.Assets.LoadAsset<Sprite>("Icon");
			new ConfigHeader(val.rootPanel, "CROSSHAIR HUD", 24);
			useAlternateCrosshair = new BoolField(val.rootPanel, "ALTERNATE CROSSHAIR", "use_alt_crosshair", false);
			BoolField obj = useAlternateCrosshair;
			object obj2 = <>c.<>9__19_0;
			if (obj2 == null)
			{
				PostBoolValueChangeEvent val2 = delegate
				{
					HUDOptions instance6 = MonoSingleton<HUDOptions>.Instance;
					if (instance6 != null)
					{
						instance6.crosshair.CheckCrossHair();
					}
				};
				<>c.<>9__19_0 = val2;
				obj2 = (object)val2;
			}
			obj.postValueChangeEvent += (PostBoolValueChangeEvent)obj2;
			showRailcannonCharge = new BoolField(val.rootPanel, "RAILCANNON CHARGE", "crosshair_rc_charge", false);
			new ConfigHeader(val.rootPanel, "STATUS HUD", 24);
			showHardDamageNumber = new BoolField(val.rootPanel, "HARD DAMAGE INDICATOR", "show_hard_damage", false);
			BoolField obj3 = showHardDamageNumber;
			object obj4 = <>c.<>9__19_1;
			if (obj4 == null)
			{
				PostBoolValueChangeEvent val3 = delegate
				{
					HudController instance5 = HudController.Instance;
					if (instance5 != null)
					{
						instance5.CheckSituation();
					}
				};
				<>c.<>9__19_1 = val3;
				obj4 = (object)val3;
			}
			obj3.postValueChangeEvent += (PostBoolValueChangeEvent)obj4;
			altIndicatorPosition = new BoolField(val.rootPanel, "ALTERNATE WEAPON ICON POSITION", "alt_equipped_indicator_pos", false);
			BoolField obj5 = altIndicatorPosition;
			object obj6 = <>c.<>9__19_2;
			if (obj6 == null)
			{
				PostBoolValueChangeEvent val4 = delegate(bool value)
				{
					((ConfigField)forceAltRailcannonCharge).interactable = !value;
					RailcannonMeter instance3 = MonoSingleton<RailcannonMeter>.Instance;
					if (instance3 != null)
					{
						instance3.CheckStatus();
					}
					HudController instance4 = HudController.Instance;
					if (instance4 != null)
					{
						instance4.CheckSituation();
					}
				};
				<>c.<>9__19_2 = val4;
				obj6 = (object)val4;
			}
			obj5.postValueChangeEvent += (PostBoolValueChangeEvent)obj6;
			forceAltRailcannonCharge = new BoolField(val.rootPanel, "FORCE ALTERNATE RAILCANNON DISPLAY", "force_alt_railcannon_charge", false)
			{
				interactable = !altIndicatorPosition.value
			};
			BoolField obj7 = forceAltRailcannonCharge;
			object obj8 = <>c.<>9__19_3;
			if (obj8 == null)
			{
				PostBoolValueChangeEvent val5 = delegate
				{
					RailcannonMeter instance2 = MonoSingleton<RailcannonMeter>.Instance;
					if (instance2 != null)
					{
						instance2.CheckStatus();
					}
				};
				<>c.<>9__19_3 = val5;
				obj8 = (object)val5;
			}
			obj7.postValueChangeEvent += (PostBoolValueChangeEvent)obj8;
			new ConfigHeader(val.rootPanel, "STYLE HUD", 24);
			new ConfigHeader(val.rootPanel, "CUSTOM STYLE RANK IMAGES", 16);
			new ConfigHeader(val.rootPanel, "MUST BE THE FULL PATH TO A .PNG .JPG OR .EXF FILE\nLEAVE BLANK TO USE DEFAULT IMAGE", 12);
			for (int i = 0; i < 8; i++)
			{
				string prevValue = "";
				int index = i;
				StringField stringField = new StringField(val.rootPanel, GenericExtensions.GetRankText(i, true), "customrankimages_" + i, "", true);
				SpriteField spriteField = new SpriteField(val.rootPanel, (Sprite)null);
				stringField.postValueChangeEvent += new PostStringValueChangeEvent(SetSpriteFromPath);
				SetSpriteFromPath(stringField.value);
				void SetSpriteFromPath(string path)
				{
					//IL_0026: Unknown result type (might be due to invalid IL or missing references)
					//IL_002c: Expected O, but got Unknown
					//IL_008f: 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)
					if (Utility.IsNullOrWhiteSpace(path))
					{
						prevValue = "";
						spriteField.Sprite = null;
					}
					else
					{
						Texture2D val6 = new Texture2D(0, 0);
						if ((path.EndsWith(".png") || path.EndsWith(".jpg") || path.EndsWith(".exf")) && File.Exists(path) && ImageConversion.LoadImage(val6, File.ReadAllBytes(path)))
						{
							prevValue = path;
							spriteField.Sprite = Sprite.Create(val6, new Rect(0f, 0f, (float)((Texture)val6).width, (float)((Texture)val6).height), new Vector2(0.5f, 0.5f));
						}
						else
						{
							stringField.value = prevValue;
						}
					}
					CustomStyleImages[index] = spriteField.Sprite;
					StyleHUD instance = MonoSingleton<StyleHUD>.Instance;
					if (instance != null && index != instance.rankIndex)
					{
						instance.rankImage.sprite = spriteField.Sprite ?? instance.ranks[index].sprite;
					}
				}
			}
			new ConfigHeader(val.rootPanel, "OTHER", 24);
			fupAlert = new BoolField(val.rootPanel, "ROCKET WHIPLASH ALERT", "fup_alert", false);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "BetterWeaponHUDs";

		public const string PLUGIN_NAME = "BetterWeaponHUDs";

		public const string PLUGIN_VERSION = "1.3.0";
	}
}
namespace BetterWeaponHUDs.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					resourceMan = new ResourceManager("BetterWeaponHUDs.Properties.Resources", typeof(Resources).Assembly);
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal static byte[] Assets => (byte[])ResourceManager.GetObject("Assets", resourceCulture);

		internal Resources()
		{
		}
	}
}