Decompiled source of EnemyBarOnScreen v1.0.2

EnemyBarOnScreen.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace EnemyBarOnScreen;

[BepInPlugin("EnemyBarOnScreen", "EnemyBarOnScreen", "1.0.2")]
public class Plugin : BaseUnityPlugin
{
	public const string Guid = "EnemyBarOnScreen";

	public const string ModName = "EnemyBarOnScreen";

	public const string Version = "1.0.2";

	internal static ConfigEntry<bool> Enabled;

	internal static ConfigEntry<float> TopMargin;

	private void Awake()
	{
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Expected O, but got Unknown
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Turns the mod on or off.");
		TopMargin = ((BaseUnityPlugin)this).Config.Bind<float>("General", "TopMarginPercent", 10f, new ConfigDescription("How far below the top edge of the screen the health bar stops, in percent of the screen height. Raise it if the bar's name text is cut off or overlaps your hotbar.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 50f), new object[0]));
		new Harmony("EnemyBarOnScreen").PatchAll(typeof(UpdateHudsPatch));
	}
}
[HarmonyPatch(typeof(EnemyHud), "UpdateHuds")]
internal static class UpdateHudsPatch
{
	private static readonly FieldInfo hudsField = AccessTools.Field(typeof(EnemyHud), "m_huds");

	private static readonly Type hudDataType = AccessTools.Inner(typeof(EnemyHud), "HudData");

	private static readonly FieldInfo characterField = AccessTools.Field(hudDataType, "m_character");

	private static readonly FieldInfo guiField = AccessTools.Field(hudDataType, "m_gui");

	private static void Postfix(EnemyHud __instance)
	{
		//IL_00b4: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
		if (!Plugin.Enabled.Value || !(hudsField.GetValue(__instance) is IDictionary dictionary))
		{
			return;
		}
		float num = (float)Screen.height * (1f - Plugin.TopMargin.Value / 100f);
		foreach (object value3 in dictionary.Values)
		{
			object? value = guiField.GetValue(value3);
			GameObject val = (GameObject)((value is GameObject) ? value : null);
			if ((Object)(object)val == (Object)null || !val.activeSelf)
			{
				continue;
			}
			object? value2 = characterField.GetValue(value3);
			Character val2 = (Character)((value2 is Character) ? value2 : null);
			if (!((Object)(object)val2 == (Object)null) && !val2.IsBoss() && !val2.IsPlayer())
			{
				Transform transform = val.transform;
				Vector3 position = transform.position;
				if (position.z > 0f && position.y > num)
				{
					position.y = num;
					transform.position = position;
				}
			}
		}
	}
}