using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("HowToFish.BossHpText")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+596085f7d256c0a323c69a08f032aece310fb3b7")]
[assembly: AssemblyProduct("Boss HP Text")]
[assembly: AssemblyTitle("HowToFish.BossHpText")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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 HowToFish.BossHpText
{
[HarmonyPatch(typeof(BossUI))]
internal static class BossHpLabel
{
private const string LabelName = "BossHpTextLabel";
private static readonly FieldRef<BossUI, Image> BossHealthRef = AccessTools.FieldRefAccess<BossUI, Image>("_bossHealth");
private static readonly FieldRef<BossUI, TextMeshProUGUI> BossNameRef = AccessTools.FieldRefAccess<BossUI, TextMeshProUGUI>("_bossNameText");
private static TextMeshProUGUI _label;
private static int _lastCur = int.MinValue;
private static int _lastMax = int.MinValue;
[HarmonyPatch("UpdateBossHp")]
[HarmonyPostfix]
private static void ShowHpNumbers(BossUI __instance, int curHp)
{
try
{
if (!Plugin.Enabled.Value)
{
if ((Object)(object)_label != (Object)null)
{
((Component)_label).gameObject.SetActive(false);
}
}
else if (!((Object)(object)_label == (Object)null) || TryCreateLabel(__instance))
{
if (!((Component)_label).gameObject.activeSelf)
{
((Component)_label).gameObject.SetActive(true);
}
int bossMaxHp = BossManager.BossMaxHp;
if (curHp != _lastCur || bossMaxHp != _lastMax)
{
_lastCur = curHp;
_lastMax = bossMaxHp;
((TMP_Text)_label).text = SafeFormat(curHp, bossMaxHp);
}
}
}
catch (Exception ex)
{
Plugin.Log.LogError((object)("Failed to update the boss HP label: " + ex));
}
}
private static bool TryCreateLabel(BossUI bossUi)
{
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: 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_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Unknown result type (might be due to invalid IL or missing references)
Image val = BossHealthRef.Invoke(bossUi);
TextMeshProUGUI val2 = BossNameRef.Invoke(bossUi);
if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
{
Plugin.Log.LogWarning((object)"Boss bar or boss name label not found; skipping this boss.");
return false;
}
GameObject val3 = new GameObject("BossHpTextLabel", new Type[1] { typeof(RectTransform) });
val3.transform.SetParent((Transform)(object)((Graphic)val).rectTransform, false);
RectTransform val4 = (RectTransform)val3.transform;
val4.anchorMin = Vector2.zero;
val4.anchorMax = Vector2.one;
val4.offsetMin = Vector2.zero;
val4.offsetMax = Vector2.zero;
((Transform)val4).localScale = Vector3.one;
((Transform)val4).localRotation = Quaternion.identity;
_label = val3.AddComponent<TextMeshProUGUI>();
((TMP_Text)_label).font = ((TMP_Text)val2).font;
((TMP_Text)_label).fontSize = ((Plugin.FontSize.Value > 0f) ? Plugin.FontSize.Value : ((TMP_Text)val2).fontSize);
((TMP_Text)_label).alignment = (TextAlignmentOptions)514;
((TMP_Text)_label).overflowMode = (TextOverflowModes)0;
((Graphic)_label).color = ParseColor(Plugin.TextColor.Value, Color.white);
((Graphic)_label).raycastTarget = false;
ApplyOutline(_label);
val3.transform.SetAsLastSibling();
_lastCur = int.MinValue;
_lastMax = int.MinValue;
Plugin.Log.LogInfo((object)("Boss HP label attached to " + ((Object)val).name + "."));
return true;
}
private static void ApplyOutline(TextMeshProUGUI label)
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
float num = Mathf.Clamp01(Plugin.OutlineWidth.Value);
if (!(num <= 0f))
{
Material fontMaterial = ((TMP_Text)label).fontMaterial;
if (!((Object)(object)fontMaterial == (Object)null))
{
fontMaterial.EnableKeyword(ShaderUtilities.Keyword_Outline);
((TMP_Text)label).outlineColor = Color32.op_Implicit(ParseColor(Plugin.OutlineColor.Value, Color.black));
((TMP_Text)label).outlineWidth = num;
}
}
}
private static string SafeFormat(int cur, int max)
{
try
{
return string.Format(Plugin.Format.Value, cur, max);
}
catch (FormatException)
{
return cur + "/" + max;
}
}
private static Color ParseColor(string hex, Color fallback)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
Color result = default(Color);
if (!ColorUtility.TryParseHtmlString(hex, ref result))
{
return fallback;
}
return result;
}
}
[BepInPlugin("alexandre.howtofish.bosshptext", "Boss HP Text", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public const string Guid = "alexandre.howtofish.bosshptext";
internal static ManualLogSource Log;
internal static ConfigEntry<bool> Enabled;
internal static ConfigEntry<string> Format;
internal static ConfigEntry<float> FontSize;
internal static ConfigEntry<string> TextColor;
internal static ConfigEntry<float> OutlineWidth;
internal static ConfigEntry<string> OutlineColor;
private void Awake()
{
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Show the boss's current and maximum HP as text inside the boss health bar.");
Format = ((BaseUnityPlugin)this).Config.Bind<string>("Display", "Format", "{0}/{1}", "How the numbers are written. {0} is current HP, {1} is maximum HP.");
FontSize = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "FontSize", 0f, "Font size in points. 0 copies the size of the boss name label above the bar.");
TextColor = ((BaseUnityPlugin)this).Config.Bind<string>("Display", "TextColor", "#FFFFFF", "Colour of the numbers, as a hex code.");
OutlineWidth = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "OutlineWidth", 0.2f, "Outline thickness, 0 to 1. The bar changes colour between bosses and mini-bosses, so some outline keeps the numbers readable on both. 0 disables it.");
OutlineColor = ((BaseUnityPlugin)this).Config.Bind<string>("Display", "OutlineColor", "#000000", "Colour of the outline, as a hex code.");
new Harmony("alexandre.howtofish.bosshptext").PatchAll();
Log.LogInfo((object)"Boss HP Text loaded.");
}
}
}