Decompiled source of simple health indicator v1.0.0

health_indicator.dll

Decompiled 2 days ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ClassLibrary1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ClassLibrary1")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("adae4720-c7c6-4fb5-92cb-019b6182cba6")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("healthmod", "Health Display Mod", "1.0.0")]
public class HealthModPlugin : BaseUnityPlugin
{
	private ManualLogSource Logger;

	public static ConfigEntry<float> PanelScale;

	public static ConfigEntry<float> PanelX;

	public static ConfigEntry<float> PanelY;

	public static ConfigEntry<float> HealthMultiplier;

	private void Awake()
	{
		Logger = ((BaseUnityPlugin)this).Logger;
		PanelScale = ((BaseUnityPlugin)this).Config.Bind<float>("HUD", "PanelScale", 1f, "Hud scaling (panel scaling) ");
		PanelX = ((BaseUnityPlugin)this).Config.Bind<float>("HUD", "PanelX", 0.012f, "pos horizontal");
		PanelY = ((BaseUnityPlugin)this).Config.Bind<float>("HUD", "PanelY", 0.02f, "pos vertical");
		HealthMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("HUD", "HealthMultiplier", 20f, "HP Display Multiplier");
		Logger.LogInfo((object)"HealthMod: Awake called!");
		SceneManager.sceneLoaded += OnSceneLoaded;
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)GameObject.Find("HealthModGUI") != (Object)null))
		{
			GameObject val = new GameObject("HealthModGUI");
			SceneManager.MoveGameObjectToScene(val, scene);
			HealthModGUI healthModGUI = val.AddComponent<HealthModGUI>();
			healthModGUI.logger = Logger;
		}
	}
}
public class HealthModGUI : MonoBehaviour
{
	public ManualLogSource logger;

	private Texture2D _black;

	private Texture2D _barBg;

	private Texture2D _barFill;

	private void Awake()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: 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)
		_black = MakeTexture(new Color(0f, 0f, 0f, 0.75f));
		_barBg = MakeTexture(new Color(0.15f, 0.15f, 0.15f, 0.9f));
		_barFill = MakeTexture(Color.white);
	}

	private Texture2D MakeTexture(Color color)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Expected O, but got Unknown
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(1, 1);
		val.SetPixel(0, 0, color);
		val.Apply();
		return val;
	}

	private void OnGUI()
	{
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Expected O, but got Unknown
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Expected O, but got Unknown
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_024a: Unknown result type (might be due to invalid IL or missing references)
		//IL_025e: Unknown result type (might be due to invalid IL or missing references)
		//IL_026b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0270: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0232: Unknown result type (might be due to invalid IL or missing references)
		//IL_0237: Unknown result type (might be due to invalid IL or missing references)
		//IL_027a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
		ENT_Player player = ENT_Player.GetPlayer();
		if (!((Object)(object)player == (Object)null))
		{
			float value = HealthModPlugin.PanelScale.Value;
			float value2 = HealthModPlugin.HealthMultiplier.Value;
			float num = ((GameEntity)player).health * value2;
			float num2 = ((GameEntity)player).maxHealth * value2;
			float num3 = Mathf.Clamp01(((GameEntity)player).health / ((GameEntity)player).maxHealth);
			float num4 = Screen.width;
			float num5 = Screen.height;
			float num6 = num4 * 0.2f * value;
			float num7 = num5 * 0.075f * value;
			float num8 = num4 * HealthModPlugin.PanelX.Value;
			float num9 = num5 - num7 - num5 * HealthModPlugin.PanelY.Value;
			float num10 = num6 * 0.023f;
			float num11 = num7 * 0.26f;
			float num12 = num9 + num10 + num7 * 0.37f;
			float num13 = num6 - num10 * 2f;
			int fontSize = Mathf.RoundToInt(num5 * 0.019f * value);
			GUI.DrawTexture(new Rect(num8, num9, num6, num7), (Texture)(object)_black);
			GUIStyle val = new GUIStyle();
			val.fontSize = fontSize;
			val.fontStyle = (FontStyle)1;
			val.normal.textColor = new Color(0.85f, 0.85f, 0.85f);
			GUI.Label(new Rect(num8 + num10, num9 + num10, num6 * 0.4f, num7 * 0.4f), "HEALTH", val);
			GUIStyle val2 = new GUIStyle();
			val2.fontSize = fontSize;
			val2.fontStyle = (FontStyle)1;
			val2.alignment = (TextAnchor)2;
			val2.normal.textColor = Color.white;
			GUI.Label(new Rect(num8 + num10, num9 + num10, num13, num7 * 0.4f), $"{num:F0} / {num2:F0}", val2);
			GUI.DrawTexture(new Rect(num8 + num10, num12, num13, num11), (Texture)(object)_barBg);
			Color val3 = ((!(num3 > 0.5f)) ? Color.Lerp(new Color(0.9f, 0.1f, 0.1f), new Color(1f, 0.8f, 0f), num3 * 2f) : Color.Lerp(new Color(1f, 0.8f, 0f), new Color(0.2f, 0.9f, 0.2f), (num3 - 0.5f) * 2f));
			_barFill.SetPixel(0, 0, val3);
			_barFill.Apply();
			if (num3 > 0f)
			{
				GUI.DrawTexture(new Rect(num8 + num10, num12, num13 * num3, num11), (Texture)(object)_barFill);
			}
		}
	}
}