Decompiled source of RcHud Lite v1.2.4

plugins/RcHud-lite.dll

Decompiled 2 weeks ago
using System;
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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RcHud-lite")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Stripped-down version of RcHud")]
[assembly: AssemblyFileVersion("1.2.3.0")]
[assembly: AssemblyInformationalVersion("1.2.3")]
[assembly: AssemblyProduct("RcHud-lite")]
[assembly: AssemblyTitle("RcHud-lite")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.3.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 RcHud
{
	public enum StaminaColorMode
	{
		Vanilla,
		Static,
		AllRed,
		AllDark,
		RedDark
	}
	public static class Config
	{
		private static ConfigEntry<bool> hiVisOverheal;

		private static ConfigEntry<bool> persistentHp;

		private static ConfigEntry<StaminaColorMode> staminaColorMode;

		private static ConfigEntry<float> wheelFade;

		public static bool HiVisOverheal => hiVisOverheal.Value;

		public static bool PersistentHp => persistentHp.Value;

		public static StaminaColorMode StaminaColorMode => staminaColorMode.Value;

		public static float WheelFadeTime => wheelFade.Value;

		public static void Init(ConfigFile cfg)
		{
			string[] value = new string[6] { "Vanilla: vanilla behavior (first segment red while charging)", "Static: all segments blue, all the time", "AllRed: all segments red while charging", "AllDark: all segments dark blue while charging", "RedDark: first segment red while charging, other segments dark blue", "(the actual colors reflect game color settings)" };
			staminaColorMode = cfg.Bind<StaminaColorMode>("Tweaks", "StaminaColorMode", StaminaColorMode.AllRed, string.Join("\n", value));
			hiVisOverheal = cfg.Bind<bool>("Tweaks", "HiVisOverheal", true, "Display overheal as a dark green ring with a different thickness");
			persistentHp = cfg.Bind<bool>("Tweaks", "PersistentHp", true, "Prevent HP wheel from fading if damaged or overhealed");
			wheelFade = cfg.Bind<float>("FadeTime", "RailcannonMeter", 5f, AcceptableRange(0f, 30f));
		}

		private static ConfigDescription AcceptableRange<T>(T min, T max) where T : IComparable
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			return new ConfigDescription("", (AcceptableValueBase)(object)new AcceptableValueRange<T>(min, max), Array.Empty<object>());
		}
	}
	[BepInPlugin("RcHud-lite", "RcHud-lite", "1.2.3")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public void Awake()
		{
			Config.Init(((BaseUnityPlugin)this).Config);
			Harmony.CreateAndPatchAll(((object)this).GetType(), (string)null);
		}

		public void Start()
		{
			RacecarHud.SetLogger(((BaseUnityPlugin)this).Logger);
		}

		public void Update()
		{
			_ = MonoSingleton<RacecarHud>.Instance;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Crosshair), "CheckCrossHair")]
		private static void UpdateCrosshairSettings()
		{
			MonoSingleton<RacecarHud>.Instance.ApplyHiVisOverhealSettings();
		}
	}
	public sealed class RacecarHud : MonoSingleton<RacecarHud>
	{
		private static ManualLogSource log = new ManualLogSource("");

		private bool initialized = false;

		private GameObject wheel = new GameObject();

		private Crosshair crosshairReference = new Crosshair();

		internal static void SetLogger(ManualLogSource logger)
		{
			log = logger;
		}

		public void Update()
		{
			//IL_001c: 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_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			if (TryInit())
			{
				GunControl instance = MonoSingleton<GunControl>.Instance;
				Scene activeScene = SceneManager.GetActiveScene();
				bool flag;
				switch (((Scene)(ref activeScene)).name)
				{
				case "Level 0-S":
				case "Level 1-S":
				case "Level 4-S":
					flag = true;
					break;
				default:
					flag = false;
					break;
				}
				bool flag2 = flag;
				bool flag3 = true;
				flag3 &= instance.slot4.Count > 0;
				flag3 = flag3 && !flag2;
				wheel.SetActive(flag3);
				WeaponCharges instance2 = MonoSingleton<WeaponCharges>.Instance;
				ColorBlindSettings instance3 = MonoSingleton<ColorBlindSettings>.Instance;
				Slider component = wheel.GetComponent<Slider>();
				component.value = instance2.raicharge;
				Image component2 = wheel.GetComponent<Image>();
				((Graphic)component2).color = ((component.normalizedValue < 1f) ? instance3.railcannonChargingColor : instance3.railcannonFullColor);
				UpdateStaminaColors();
				UpdatePersistentHp();
			}
		}

		private void UpdateStaminaColors()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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_00a3: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			ColorBlindSettings instance = MonoSingleton<ColorBlindSettings>.Instance;
			Color staminaColor = instance.staminaColor;
			Color val = instance.staminaChargingColor * 0.6f;
			Color staminaEmptyColor = instance.staminaEmptyColor;
			for (int i = 2; i < 5; i++)
			{
				Image val2 = crosshairReference.chuds[i];
				SliderToFillAmount component = ((Component)val2).GetComponent<SliderToFillAmount>();
				component.copyColor = false;
				bool flag = val2.fillAmount == component.maxFill;
				bool flag2 = i == 2;
				Image val3 = val2;
				StaminaColorMode staminaColorMode = Config.StaminaColorMode;
				if (1 == 0)
				{
				}
				Color color = (Color)(staminaColorMode switch
				{
					StaminaColorMode.Vanilla => flag ? staminaColor : (flag2 ? staminaEmptyColor : staminaColor), 
					StaminaColorMode.Static => staminaColor, 
					StaminaColorMode.AllRed => flag ? staminaColor : staminaEmptyColor, 
					StaminaColorMode.AllDark => flag ? staminaColor : val, 
					StaminaColorMode.RedDark => flag ? staminaColor : (flag2 ? staminaEmptyColor : val), 
					_ => Color.magenta, 
				});
				if (1 == 0)
				{
				}
				((Graphic)val3).color = color;
			}
		}

		private void UpdatePersistentHp()
		{
			if (Config.PersistentHp)
			{
				Image[] chuds = crosshairReference.chuds;
				Image val = chuds[1];
				Image val2 = chuds[7];
				SliderToFillAmount component = ((Component)val).GetComponent<SliderToFillAmount>();
				if (val.fillAmount < component.maxFill || val2.fillAmount > 0f)
				{
					component.mama.fadeOutTime = 2f;
				}
			}
		}

		public void ApplyHiVisOverhealSettings()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			TryInit();
			Image[] chuds = crosshairReference.chuds;
			Sprite[] circles = crosshairReference.circles;
			Image val = chuds[7];
			Image val2 = chuds[6];
			if (!Config.HiVisOverheal)
			{
				((Graphic)val).color = new Color(0.703f, 1f, 0.704f);
				return;
			}
			Sprite val3;
			switch (MonoSingleton<PrefsManager>.Instance.GetInt("crossHairHud", 0))
			{
			default:
				return;
			case 1:
				val3 = circles[2];
				break;
			case 2:
				val3 = circles[3];
				break;
			case 3:
				val3 = circles[0];
				break;
			case 4:
				val3 = circles[1];
				break;
			}
			Sprite sprite = (val.sprite = val3);
			val2.sprite = sprite;
			((Graphic)val).color = Color.green * 0.65f;
		}

		private bool TryInit()
		{
			if (initialized)
			{
				return true;
			}
			PowerUpMeter instance = MonoSingleton<PowerUpMeter>.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			crosshairReference = MonoSingleton<CanvasController>.Instance.crosshair;
			InitWheel(instance);
			log.LogInfo((object)"hud initialized");
			initialized = true;
			return true;
		}

		private void InitWheel(PowerUpMeter powerUpMeter)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Wheel");
			Image val2 = val.AddComponent<Image>();
			val2.type = (Type)3;
			val2.fillMethod = (FillMethod)4;
			val2.fillAmount = 0.5f;
			val2.sprite = ((Component)powerUpMeter).GetComponentInChildren<Image>().sprite;
			RectTransform val3 = InitTransform(val);
			val3.sizeDelta = new Vector2(64f, 64f);
			val3.anchoredPosition = new Vector2(0f, 0f);
			((Transform)val3).Rotate(0f, 0f, 180f);
			((Component)powerUpMeter).GetComponent<RectTransform>().sizeDelta = new Vector2(69f, 69f);
			Slider val4 = val.AddComponent<Slider>();
			val4.minValue = 0f;
			val4.maxValue = 4f;
			SliderToFillAmount val5 = val.AddComponent<SliderToFillAmount>();
			val5.targetSlider = val4;
			val5.maxFill = 1f;
			FadeOutBars val6 = val.AddComponent<FadeOutBars>();
			val6.fadeOutTime = Config.WheelFadeTime;
			wheel = val;
		}

		private RectTransform InitTransform(GameObject obj)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = obj.GetComponent<RectTransform>();
			((Transform)component).parent = ((Component)crosshairReference).transform;
			((Transform)component).localScale = Vector3.one * 2f / 3f;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0.5f, 0.5f);
			component.anchorMax = val;
			component.anchorMin = val;
			return component;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "RcHud-lite";

		public const string PLUGIN_NAME = "RcHud-lite";

		public const string PLUGIN_VERSION = "1.2.3";
	}
}