Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of BestHealthBar v1.0.0
Best_HpBar.dll
Decompiled 9 months agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using GlobalEnums; using HarmonyLib; using HealthbarPlugin; using Silk_HpBar_PRO; using TMProOld; using TeamCherry.Localization; using UnityEngine; 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: AssemblyTitle("Silk_HpBarPro")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Silk_HpBarPro")] [assembly: AssemblyCopyright("Copyright © 2025")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("5cb25a01-44e8-4dec-8f48-00508341c886")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] namespace HealthbarPlugin { public class DamageTextManager : MonoBehaviour { [CompilerGenerated] private sealed class <AnimateDamageText>d__10 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public GameObject damageTextCanvas; public Text damageText; public DamageTextManager <>4__this; private Vector3 <startPosition>5__1; private Vector3 <endPosition>5__2; private Color <startColor>5__3; private float <duration>5__4; private float <elapsedTime>5__5; private float <t>5__6; private Color <currentColor>5__7; private float <fadeT>5__8; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <AnimateDamageText>d__10(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_004f: 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) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0065: 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_00d2: 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_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) switch (<>1__state) { default: return false; case 0: <>1__state = -1; <startPosition>5__1 = damageTextCanvas.transform.position; <endPosition>5__2 = <startPosition>5__1 + new Vector3(0f, 0.3f, 0f); <startColor>5__3 = ((Graphic)damageText).color; <duration>5__4 = Plugin.DamageTextDuration.Value; <elapsedTime>5__5 = 0f; break; case 1: <>1__state = -1; break; } if (<elapsedTime>5__5 < <duration>5__4) { if ((Object)(object)damageTextCanvas == (Object)null || (Object)(object)damageText == (Object)null) { return false; } <t>5__6 = <elapsedTime>5__5 / <duration>5__4; damageTextCanvas.transform.position = Vector3.Lerp(<startPosition>5__1, <endPosition>5__2, <t>5__6); <currentColor>5__7 = <startColor>5__3; if (<t>5__6 > 0.66f) { <fadeT>5__8 = (<t>5__6 - 0.66f) / 0.34f; <currentColor>5__7.a = Mathf.Lerp(1f, 0f, <fadeT>5__8); } else { <currentColor>5__7.a = 1f; } ((Graphic)damageText).color = <currentColor>5__7; <elapsedTime>5__5 += Time.deltaTime; <>2__current = null; <>1__state = 1; return true; } if ((Object)(object)damageTextCanvas != (Object)null) { <>4__this.activeDamageTexts.Remove(damageTextCanvas); Object.Destroy((Object)(object)damageTextCanvas); } return false; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } [CompilerGenerated] private sealed class <CleanupDamageTexts>d__11 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public DamageTextManager <>4__this; private int <i>5__1; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <CleanupDamageTexts>d__11(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; break; case 1: <>1__state = -1; <i>5__1 = <>4__this.activeDamageTexts.Count - 1; while (<i>5__1 >= 0) { if ((Object)(object)<>4__this.activeDamageTexts[<i>5__1] == (Object)null) { <>4__this.activeDamageTexts.RemoveAt(<i>5__1); } <i>5__1--; } break; } <>2__current = (object)new WaitForSeconds(Plugin.DamageTextDuration.Value + 2f); <>1__state = 1; return true; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } private static DamageTextManager _instance; private List<GameObject> activeDamageTexts = new List<GameObject>(); private Font damageFont; public static DamageTextManager Instance { get { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown if ((Object)(object)_instance == (Object)null) { GameObject val = new GameObject("DamageTextManager"); _instance = val.AddComponent<DamageTextManager>(); Object.DontDestroyOnLoad((Object)(object)val); } return _instance; } } public static Font SharedFont => Instance.damageFont; private void Awake() { if ((Object)(object)_instance == (Object)null) { _instance = this; Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject); LoadDamageFont(); ((MonoBehaviour)this).StartCoroutine(CleanupDamageTexts()); } else if ((Object)(object)_instance != (Object)(object)this) { Object.Destroy((Object)(object)((Component)this).gameObject); } } private void LoadDamageFont() { try { Font[] source = Resources.FindObjectsOfTypeAll<Font>(); damageFont = ((IEnumerable<Font>)source).FirstOrDefault((Func<Font, bool>)((Font f) => ((Object)f).name.Contains("TrajanPro-Regular"))); if ((Object)(object)damageFont == (Object)null) { damageFont = Resources.GetBuiltinResource<Font>("Arial.ttf"); } if ((Object)(object)damageFont == (Object)null) { Plugin.Log.LogWarning((object)"[DamageTextManager] 未找到合适的字体,将使用默认字体"); } } catch (Exception ex) { Plugin.Log.LogError((object)("[DamageTextManager] 加载字体时出错: " + ex.Message)); } } public void ShowDamageText(Vector2 worldPosition, float damage) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0052: 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_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Expected O, but got Unknown //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_01fc: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_022c: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) try { GameObject val = new GameObject("DamageTextCanvas"); Canvas val2 = val.AddComponent<Canvas>(); val2.renderMode = (RenderMode)2; val2.sortingOrder = 1000; float num = Random.Range(-0.5f, 0.5f); float num2 = Random.Range(1f, 2f); Vector3 position = default(Vector3); ((Vector3)(ref position))..ctor(worldPosition.x + num, worldPosition.y + num2, 0f); val.transform.position = position; RectTransform component = val.GetComponent<RectTransform>(); float num3 = Mathf.Max(200, Plugin.DamageTextFontSize.Value * 4); float num4 = Mathf.Max(50f, (float)Plugin.DamageTextFontSize.Value * 1.5f); component.sizeDelta = new Vector2(num3, num4); GameObject val3 = new GameObject("DamageText"); val3.transform.SetParent(val.transform); Text val4 = val3.AddComponent<Text>(); if (Plugin.DamageTextUseSign.Value) { val4.text = ((damage > 0f) ? $"- {damage}" : $"+ {Mathf.Abs(damage)}"); } else { val4.text = damage.ToString(); } val4.fontSize = Plugin.DamageTextFontSize.Value; val4.alignment = (TextAnchor)4; if (damage > 0f) { Color color = default(Color); if (ColorUtility.TryParseHtmlString(Plugin.DamageTextColor.Value, ref color)) { ((Graphic)val4).color = color; } else { ((Graphic)val4).color = Color.red; } } else { ((Graphic)val4).color = Color.green; } if ((Object)(object)damageFont != (Object)null) { val4.font = damageFont; } RectTransform component2 = val3.GetComponent<RectTransform>(); component2.anchorMin = Vector2.zero; component2.anchorMax = Vector2.one; component2.offsetMin = Vector2.zero; component2.offsetMax = Vector2.zero; activeDamageTexts.Add(val.gameObject); val.transform.localScale = Vector3.one * 0.01f; ((MonoBehaviour)this).StartCoroutine(AnimateDamageText(val.gameObject, val4)); } catch (Exception ex) { Plugin.Log.LogError((object)("[DamageTextManager] 显示伤害文本时出错: " + ex.Message)); } } [IteratorStateMachine(typeof(<AnimateDamageText>d__10))] private IEnumerator AnimateDamageText(GameObject damageTextCanvas, Text damageText) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <AnimateDamageText>d__10(0) { <>4__this = this, damageTextCanvas = damageTextCanvas, damageText = damageText }; } [IteratorStateMachine(typeof(<CleanupDamageTexts>d__11))] private IEnumerator CleanupDamageTexts() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <CleanupDamageTexts>d__11(0) { <>4__this = this }; } public void ClearAllDamageTexts() { try { foreach (GameObject activeDamageText in activeDamageTexts) { if ((Object)(object)activeDamageText != (Object)null) { Object.Destroy((Object)(object)activeDamageText); } } activeDamageTexts.Clear(); } catch (Exception ex) { Plugin.Log.LogError((object)("DamageTextManager: 清理伤害文本时发生错误: " + ex.Message)); } } private void OnDestroy() { foreach (GameObject activeDamageText in activeDamageTexts) { if ((Object)(object)activeDamageText != (Object)null) { Object.Destroy((Object)(object)activeDamageText); } } activeDamageTexts.Clear(); } } } namespace Silk_HpBar_PRO { public class BossHealthBarManager : MonoBehaviour { private static BossHealthBarManager _instance; private List<BossHealthBar> activeBossHealthBars = new List<BossHealthBar>(); private float HEALTH_BAR_SPACING = 50f; private int MAX_HEALTH_BARS = 2; private float SCREEN_TOP_THRESHOLD = 0.6f; public static BossHealthBarManager Instance { get { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown if ((Object)(object)_instance == (Object)null) { GameObject val = new GameObject("BossHealthBarManager"); _instance = val.AddComponent<BossHealthBarManager>(); Object.DontDestroyOnLoad((Object)(object)val); } return _instance; } } private void Awake() { if ((Object)(object)_instance == (Object)null) { _instance = this; Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject); } else if ((Object)(object)_instance != (Object)(object)this) { Object.Destroy((Object)(object)((Component)this).gameObject); } } public bool RegisterHealthBar(BossHealthBar healthBar) { if (activeBossHealthBars.Count >= MAX_HEALTH_BARS) { return false; } activeBossHealthBars.Add(healthBar); ArrangeHealthBars(); return true; } public void UnregisterHealthBar(BossHealthBar healthBar) { if (activeBossHealthBars.Remove(healthBar)) { ArrangeHealthBars(); } } public void ArrangeHealthBars() { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: 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_0138: Unknown result type (might be due to invalid IL or missing references) if (activeBossHealthBars.Count == 0) { return; } BossHealthBar bossHealthBar = activeBossHealthBars[0]; if (activeBossHealthBars.Count == 1) { bossHealthBar.RefreshLayout(); } RectTransform healthBarTransform = bossHealthBar.GetHealthBarTransform(); if ((Object)(object)healthBarTransform == (Object)null) { return; } Vector2 anchoredPosition = healthBarTransform.anchoredPosition; float y = healthBarTransform.sizeDelta.y; bool flag = IsInUpperScreen(healthBarTransform); for (int i = 0; i < activeBossHealthBars.Count; i++) { BossHealthBar bossHealthBar2 = activeBossHealthBars[i]; RectTransform healthBarTransform2 = bossHealthBar2.GetHealthBarTransform(); if ((Object)(object)healthBarTransform2 == (Object)null) { continue; } Vector2 anchoredPosition2 = anchoredPosition; if (i == 0) { if (!flag && activeBossHealthBars.Count > 1) { anchoredPosition2.y += y + HEALTH_BAR_SPACING; } } else { if (flag) { anchoredPosition2.y -= (float)i * (y + HEALTH_BAR_SPACING); } else { anchoredPosition2.y += (float)i * (y + HEALTH_BAR_SPACING); } bossHealthBar2.SetBossName(isHide: true); } healthBarTransform2.anchoredPosition = anchoredPosition2; } } private bool IsInUpperScreen(RectTransform healthBarRect) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0066: 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) if ((Object)(object)healthBarRect == (Object)null) { return false; } Canvas componentInParent = ((Component)healthBarRect).GetComponentInParent<Canvas>(); if ((Object)(object)componentInParent == (Object)null) { return false; } RectTransform component = ((Component)componentInParent).GetComponent<RectTransform>(); if ((Object)(object)component == (Object)null) { return false; } Vector2 val = default(Vector2); RectTransformUtility.ScreenPointToLocalPointInRectangle(component, RectTransformUtility.WorldToScreenPoint(componentInParent.worldCamera, ((Transform)healthBarRect).position), componentInParent.worldCamera, ref val); float y = component.sizeDelta.y; float num = (val.y + y * 0.5f) / y; return num > SCREEN_TOP_THRESHOLD; } public int GetActiveHealthBarCount() { return activeBossHealthBars.Count; } public void ClearAllHealthBars() { activeBossHealthBars.Clear(); } } [BepInPlugin("com.xiaohai.HealthBarPro", "HealthBarPro", "1.0.1")] public class Plugin : BaseUnityPlugin { public const string PLUGIN_GUID = "com.xiaohai.HealthBarPro"; public const string PLUGIN_NAME = "HealthBarPro"; public const string PLUGIN_VERSION = "1.0.1"; public static Harmony harmony; public static ManualLogSource Log; public static ConfigEntry<int> BossHealthThreshold; public static ConfigEntry<float> BossPositionX; public static ConfigEntry<float> BossPositionY; public static ConfigEntry<float> BossScale; public static ConfigEntry<float> BossWidthOffset; public static ConfigEntry<float> BossHeightOffset; public static ConfigEntry<string> PreTitle; public static ConfigEntry<string> PostTitle; public static ConfigEntry<float> BossExpandDuration; public static ConfigEntry<float> NormalPositionX; public static ConfigEntry<float> NormalPositionY; public static ConfigEntry<float> NormalScale; public static ConfigEntry<float> NormalWidthOffset; public static ConfigEntry<float> NormalHeightOffset; public static ConfigEntry<float> NormalHideDelay; public static ConfigEntry<float> DamageTextDuration; public static ConfigEntry<int> DamageTextFontSize; public static ConfigEntry<string> DamageTextColor; public static ConfigEntry<bool> DamageTextUseSign; public static AssetBundle healthBarAssetBundle; public static GameObject bossHealthBarPrefab; public static GameObject healthBarPrefab; private void Awake() { //IL_02ba: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; BossHealthThreshold = ((BaseUnityPlugin)this).Config.Bind<int>("Boss识别设置", "血量阈值", 119, "Boss血量判定阈值,血量大于此值的敌人将被识别为Boss并使用Boss血条 / Boss health threshold, enemies with health above this value will be recognized as Boss and use Boss health bar"); BossPositionX = ((BaseUnityPlugin)this).Config.Bind<float>("BOSS血条调整/BossHpBar", "X轴位置偏移", 0f, "BOSS血条X轴位置偏移量 / Boss health bar X-axis position offset"); BossPositionY = ((BaseUnityPlugin)this).Config.Bind<float>("BOSS血条调整/BossHpBar", "Y轴位置偏移", 0f, "BOSS血条Y轴位置偏移量 / Boss health bar Y-axis position offset"); BossScale = ((BaseUnityPlugin)this).Config.Bind<float>("BOSS血条调整/BossHpBar", "缩放倍数", 1f, "BOSS血条缩放倍数 / Boss health bar scale multiplier"); BossWidthOffset = ((BaseUnityPlugin)this).Config.Bind<float>("BOSS血条调整/BossHpBar", "宽度偏移", 0f, "BOSS血条宽度偏移量 / Boss health bar width offset"); BossHeightOffset = ((BaseUnityPlugin)this).Config.Bind<float>("BOSS血条调整/BossHpBar", "高度偏移", 0f, "BOSS血条高度偏移量 / Boss health bar height offset"); PreTitle = ((BaseUnityPlugin)this).Config.Bind<string>("BOSS血条调整/BossHpBar", "标题前缀", "盘踞于", "BOSS血条标题前缀 / Boss health bar title prefix"); PostTitle = ((BaseUnityPlugin)this).Config.Bind<string>("BOSS血条调整/BossHpBar", "标题后缀", "的", "BOSS血条标题后缀 / Boss health bar title suffix"); BossExpandDuration = ((BaseUnityPlugin)this).Config.Bind<float>("BOSS血条调整/BossHpBar", "A展开动画时长", 1f, "BOSS血条从左到右展开的动画时长(秒) / Boss health bar expand animation duration (seconds)"); NormalPositionX = ((BaseUnityPlugin)this).Config.Bind<float>("普通血条调整/NormalHpBar", "X轴位置偏移", 0f, "普通血条X轴位置偏移量 / Normal health bar X-axis position offset"); NormalPositionY = ((BaseUnityPlugin)this).Config.Bind<float>("普通血条调整/NormalHpBar", "Y轴位置偏移", 0f, "普通血条Y轴位置偏移量 / Normal health bar Y-axis position offset"); NormalScale = ((BaseUnityPlugin)this).Config.Bind<float>("普通血条调整/NormalHpBar", "缩放倍数", 1f, "普通血条缩放倍数 / Normal health bar scale multiplier"); NormalWidthOffset = ((BaseUnityPlugin)this).Config.Bind<float>("普通血条调整/NormalHpBar", "宽度偏移", 0f, "普通血条宽度偏移量 / Normal health bar width offset"); NormalHeightOffset = ((BaseUnityPlugin)this).Config.Bind<float>("普通血条调整/NormalHpBar", "高度偏移", 0f, "普通血条高度偏移量 / Normal health bar height offset"); NormalHideDelay = ((BaseUnityPlugin)this).Config.Bind<float>("普通血条调整/NormalHpBar", "A隐藏延迟", 3f, "普通血条在受到伤害后持续显示的时间(秒) / Normal health bar display duration after taking damage (seconds)"); DamageTextDuration = ((BaseUnityPlugin)this).Config.Bind<float>("A伤害文本/DamageText", "Duration", 2f, "伤害文本显示持续时间(秒) / Damage text display duration (seconds)"); DamageTextFontSize = ((BaseUnityPlugin)this).Config.Bind<int>("A伤害文本/DamageText", "FontSize", 55, "伤害文本字体大小 / Damage text font size"); DamageTextColor = ((BaseUnityPlugin)this).Config.Bind<string>("A伤害文本/DamageText", "DamageColor", "#0e0404ff", "伤害文本颜色(十六进制格式,如#FF0000为红色)颜色十六进制代码转换:http://pauli.cn/tool/color.htm / Damage text color (hex format, e.g. #FF0000 for red)"); DamageTextUseSign = ((BaseUnityPlugin)this).Config.Bind<bool>("A伤害文本/DamageText", "UseSign", true, "伤害文本是否显示符号?(Plus:+, Minus:-) / Whether to show signs in damage text (Plus:+, Minus:-)"); LoadAssetBundle(); new Harmony("com.xiaohai.HealthBarPro").PatchAll(); TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>(); TMP_FontAsset[] array2 = array; foreach (TMP_FontAsset val in array2) { Log.LogInfo((object)("字体找到: " + ((Object)val).name)); } } private void LoadAssetBundle() { string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string text = Path.Combine(directoryName, "healthbar_pro"); if (!File.Exists(text)) { Log.LogError((object)"healthbar_pro 为空"); return; } healthBarAssetBundle = AssetBundle.LoadFromFile(text); if ((Object)(object)healthBarAssetBundle == (Object)null) { Log.LogError((object)"healthBarAssetBundle 为空"); return; } bossHealthBarPrefab = healthBarAssetBundle.LoadAsset<GameObject>("BossHealthBar.prefab"); if ((Object)(object)bossHealthBarPrefab == (Object)null) { bossHealthBarPrefab = healthBarAssetBundle.LoadAsset<GameObject>("BossHealthBar_1.prefab"); if ((Object)(object)bossHealthBarPrefab == (Object)null) { Log.LogError((object)"BossHealthBar和BossHealthBar_1都为空"); return; } } healthBarPrefab = healthBarAssetBundle.LoadAsset<GameObject>("HealthBar.prefab"); if ((Object)(object)healthBarPrefab == (Object)null) { Log.LogError((object)"HealthBar 为空"); } } private void Update() { if (Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305)) { BossHealthBar[] array = Object.FindObjectsByType<BossHealthBar>((FindObjectsSortMode)0); bool flag = false; BossHealthBar[] array2 = array; foreach (BossHealthBar bossHealthBar in array2) { if (bossHealthBar.IsExpanding()) { flag = true; break; } } if (flag) { return; } bool flag2 = false; if (Input.GetKey((KeyCode)273)) { ConfigEntry<float> bossPositionY = BossPositionY; bossPositionY.Value += 0.1f; flag2 = true; } if (Input.GetKey((KeyCode)274)) { ConfigEntry<float> bossPositionY2 = BossPositionY; bossPositionY2.Value -= 0.1f; flag2 = true; } if (Input.GetKey((KeyCode)276)) { ConfigEntry<float> bossPositionX = BossPositionX; bossPositionX.Value -= 0.1f; flag2 = true; } if (Input.GetKey((KeyCode)275)) { ConfigEntry<float> bossPositionX2 = BossPositionX; bossPositionX2.Value += 0.1f; flag2 = true; } if (Input.GetKey((KeyCode)270)) { ConfigEntry<float> bossScale = BossScale; bossScale.Value += 0.01f; flag2 = true; } if (Input.GetKey((KeyCode)269)) { ConfigEntry<float> bossScale2 = BossScale; bossScale2.Value -= 0.01f; flag2 = true; } if (Input.GetKey((KeyCode)43) || Input.GetKey((KeyCode)61)) { ConfigEntry<float> bossWidthOffset = BossWidthOffset; bossWidthOffset.Value += 0.1f; flag2 = true; } if (Input.GetKey((KeyCode)45)) { ConfigEntry<float> bossWidthOffset2 = BossWidthOffset; bossWidthOffset2.Value -= 0.1f; flag2 = true; } if (Input.GetKey((KeyCode)91)) { ConfigEntry<float> bossHeightOffset = BossHeightOffset; bossHeightOffset.Value += 0.1f; flag2 = true; } if (Input.GetKey((KeyCode)93)) { ConfigEntry<float> bossHeightOffset2 = BossHeightOffset; bossHeightOffset2.Value -= 0.1f; flag2 = true; } if (Input.GetKeyDown((KeyCode)261)) { BossPositionX.Value = 0f; BossPositionY.Value = 0f; BossScale.Value = 1f; BossWidthOffset.Value = 0f; BossHeightOffset.Value = 0f; flag2 = true; Log.LogInfo((object)"BOSS血条参数已重置"); } if (Input.GetKeyDown((KeyCode)262)) { NormalPositionX.Value = 0f; NormalPositionY.Value = 0f; NormalScale.Value = 1f; NormalWidthOffset.Value = 0f; NormalHeightOffset.Value = 0f; flag2 = true; Log.LogInfo((object)"普通血条参数已重置"); } if (flag2) { RefreshAllBossHealthBars(); } } if (Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307)) { bool flag3 = false; if (Input.GetKey((KeyCode)273)) { ConfigEntry<float> normalPositionY = NormalPositionY; normalPositionY.Value += 0.1f; flag3 = true; } if (Input.GetKey((KeyCode)274)) { ConfigEntry<float> normalPositionY2 = NormalPositionY; normalPositionY2.Value -= 0.1f; flag3 = true; } if (Input.GetKey((KeyCode)276)) { ConfigEntry<float> normalPositionX = NormalPositionX; normalPositionX.Value -= 0.1f; flag3 = true; } if (Input.GetKey((KeyCode)275)) { ConfigEntry<float> normalPositionX2 = NormalPositionX; normalPositionX2.Value += 0.1f; flag3 = true; } if (Input.GetKey((KeyCode)270)) { ConfigEntry<float> normalScale = NormalScale; normalScale.Value += 0.01f; flag3 = true; } if (Input.GetKey((KeyCode)269)) { ConfigEntry<float> normalScale2 = NormalScale; normalScale2.Value -= 0.01f; flag3 = true; } if (Input.GetKey((KeyCode)43) || Input.GetKey((KeyCode)61)) { ConfigEntry<float> normalWidthOffset = NormalWidthOffset; normalWidthOffset.Value += 0.1f; flag3 = true; } if (Input.GetKey((KeyCode)45)) { ConfigEntry<float> normalWidthOffset2 = NormalWidthOffset; normalWidthOffset2.Value -= 0.1f; flag3 = true; } if (Input.GetKey((KeyCode)91)) { ConfigEntry<float> normalHeightOffset = NormalHeightOffset; normalHeightOffset.Value += 0.1f; flag3 = true; } if (Input.GetKey((KeyCode)93)) { ConfigEntry<float> normalHeightOffset2 = NormalHeightOffset; normalHeightOffset2.Value -= 0.1f; flag3 = true; } if (flag3) { RefreshAllNormalHealthBars(); } } } private void RefreshAllBossHealthBars() { BossHealthBar[] array = Object.FindObjectsByType<BossHealthBar>((FindObjectsSortMode)0); BossHealthBar[] array2 = array; foreach (BossHealthBar bossHealthBar in array2) { bossHealthBar.RefreshLayout(); } } private void RefreshAllNormalHealthBars() { HealthBar[] array = Object.FindObjectsByType<HealthBar>((FindObjectsSortMode)0); HealthBar[] array2 = array; foreach (HealthBar healthBar in array2) { healthBar.RefreshLayout(); } } private void OnDestroy() { if ((Object)(object)healthBarAssetBundle != (Object)null) { healthBarAssetBundle.Unload(true); healthBarAssetBundle = null; } } } [HarmonyPatch] public class Patch { [HarmonyPatch(typeof(HealthManager), "Awake")] [HarmonyPostfix] public static void HealthManagerPatch(HealthManager __instance) { if (__instance.initHp >= 5) { HealthBarData healthBarData = ((Component)__instance).gameObject.AddComponent<HealthBarData>(); if (__instance.initHp > Plugin.BossHealthThreshold.Value) { ((Component)__instance).gameObject.AddComponent<BossHealthBar>(); healthBarData.barType = HealthBarData.BarType.Boss; } else { ((Component)__instance).gameObject.AddComponent<HealthBar>(); healthBarData.barType = HealthBarData.BarType.Normal; } } } [HarmonyPatch(typeof(HealthManager), "TakeDamage")] [HarmonyPrefix] public static void TakeDamagePrefix(HealthManager __instance) { HealthBarData component = ((Component)__instance).GetComponent<HealthBarData>(); if (!((Object)(object)component == (Object)null)) { component.lastHp = __instance.hp; } } [HarmonyPatch(typeof(HealthManager), "TakeDamage")] [HarmonyPostfix] public static void TakeDamagePatch(HealthManager __instance) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) HealthBarData component = ((Component)__instance).GetComponent<HealthBarData>(); if ((Object)(object)component == (Object)null) { return; } float num = component.lastHp - (float)__instance.hp; if (num != 0f) { DamageTextManager.Instance.ShowDamageText(Vector2.op_Implicit(((Component)__instance).transform.position), num); } if (component.barType == HealthBarData.BarType.Boss) { BossHealthBar bossHealthBar = ((Component)__instance).GetComponent<BossHealthBar>(); if ((Object)(object)bossHealthBar == (Object)null) { bossHealthBar = ((Component)__instance).gameObject.AddComponent<BossHealthBar>(); } bossHealthBar.OnTakeDamage(); } else { HealthBar healthBar = ((Component)__instance).GetComponent<HealthBar>(); if ((Object)(object)healthBar == (Object)null) { healthBar = ((Component)__instance).gameObject.AddComponent<HealthBar>(); } healthBar.OnTakeDamage(); } } } public class HealthBarData : MonoBehaviour { public enum BarType { Normal, Boss } public float lastHp; public BarType barType = BarType.Normal; } public class HealthBar : MonoBehaviour { private HealthManager healthManager; private float lastHealth; private float maxHealth; public float detectionDistance = 15f; private Transform playerTransform; private Collider2D colliders2D; private GameObject healthBarUI; private static Canvas sharedCanvas; private Image bgImage; private Image fillImage; public static float baseScale = 1f; private float lastDamageTime; private bool isDamageVisible = false; private bool isUICreated = false; private void Awake() { if (((Component)this).GetComponents<HealthBar>().Length > 1) { Object.Destroy((Object)(object)this); return; } healthManager = ((Component)this).GetComponent<HealthManager>(); maxHealth = healthManager.initHp; lastHealth = healthManager.hp; playerTransform = Object.FindFirstObjectByType<HeroController>().transform; colliders2D = ((Component)this).GetComponent<Collider2D>(); lastDamageTime = Time.time; } private void Update() { if (!((Object)(object)healthManager == (Object)null)) { CheckVisibilityConditions(); if ((Object)(object)healthBarUI == (Object)null && !isUICreated) { CreateHealthBarUI(); } float num = healthManager.hp; UpdateMaxHealth(); if (num != lastHealth) { lastHealth = num; UpdateHealthBar(); } if ((Object)(object)healthBarUI != (Object)null) { UpdateHealthBarPosition(); } } } private void UpdateHealthBarPosition() { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0087: 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_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0141: 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) if ((Object)(object)healthBarUI == (Object)null || (Object)(object)sharedCanvas == (Object)null) { return; } Vector3 headOffset = GetHeadOffset(); Vector3 val = ((Component)this).transform.position + headOffset; Camera val2 = GameCameras.instance?.mainCamera; if ((Object)(object)val2 != (Object)null) { Vector3 val3 = val2.WorldToScreenPoint(val); if (val3.z < 0f || val3.x < 0f || val3.x > (float)Screen.width || val3.y < 0f || val3.y > (float)Screen.height) { if (healthBarUI.activeSelf) { healthBarUI.SetActive(false); } return; } RectTransform component = healthBarUI.GetComponent<RectTransform>(); RectTransform component2 = ((Component)sharedCanvas).GetComponent<RectTransform>(); Vector2 val4 = default(Vector2); if (RectTransformUtility.ScreenPointToLocalPointInRectangle(component2, Vector2.op_Implicit(val3), (Camera)null, ref val4)) { val4.x += Plugin.NormalPositionX.Value; val4.y += Plugin.NormalPositionY.Value; ((Transform)component).localPosition = Vector2.op_Implicit(val4); } } if (!healthBarUI.activeSelf && isDamageVisible) { healthBarUI.SetActive(true); } } private void CreateHealthBarUI() { //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Expected O, but got Unknown if ((Object)(object)healthBarUI != (Object)null) { return; } healthBarUI = Object.Instantiate<GameObject>(Plugin.healthBarPrefab); Canvas component = healthBarUI.GetComponent<Canvas>(); if ((Object)(object)component != (Object)null) { CanvasScaler component2 = healthBarUI.GetComponent<CanvasScaler>(); if ((Object)(object)component2 != (Object)null) { Object.DestroyImmediate((Object)(object)component2); } GraphicRaycaster component3 = healthBarUI.GetComponent<GraphicRaycaster>(); if ((Object)(object)component3 != (Object)null) { Object.DestroyImmediate((Object)(object)component3); } Object.DestroyImmediate((Object)(object)component); } if ((Object)(object)sharedCanvas == (Object)null) { GameObject val = new GameObject("SharedHealthBarCanvas"); sharedCanvas = val.AddComponent<Canvas>(); sharedCanvas.renderMode = (RenderMode)0; sharedCanvas.sortingOrder = 100; val.AddComponent<CanvasScaler>(); val.AddComponent<GraphicRaycaster>(); } healthBarUI.transform.SetParent(((Component)sharedCanvas).transform, false); Transform val2 = healthBarUI.transform.Find("BG"); bgImage = ((Component)val2).GetComponent<Image>(); fillImage = ((Component)val2.Find("Fill")).GetComponent<Image>(); fillImage.type = (Type)3; fillImage.fillMethod = (FillMethod)0; SetupUILayout(); UpdateHealthBar(); ShowHealthBar(); isUICreated = true; } private Vector3 GetHeadOffset() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) return new Vector3(0f, 1f, 0f); } private void ShowHealthBar() { if ((Object)(object)healthBarUI != (Object)null) { healthBarUI.SetActive(true); } } private void HideHealthBar() { if ((Object)(object)healthBarUI != (Object)null) { healthBarUI.SetActive(false); } } private void SetupUILayout() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)bgImage != (Object)null) { RectTransform rectTransform = ((Graphic)bgImage).rectTransform; ((Transform)rectTransform).localScale = Vector3.one * baseScale * Plugin.NormalScale.Value; rectTransform.sizeDelta = new Vector2(320f + Plugin.NormalWidthOffset.Value, 32f + Plugin.NormalHeightOffset.Value); ((Graphic)fillImage).rectTransform.sizeDelta = rectTransform.sizeDelta; } } public void RefreshLayout() { SetupUILayout(); } private void UpdateMaxHealth() { if (!((Object)(object)healthManager == (Object)null)) { float num = healthManager.hp; if (num > maxHealth && num <= 3000f) { maxHealth = num; } } } private void UpdateHealthBar() { if (!((Object)(object)fillImage == (Object)null) && !((Object)(object)healthManager == (Object)null)) { float fillAmount = (float)healthManager.hp / maxHealth; fillImage.fillAmount = fillAmount; } } private void CheckVisibilityConditions() { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)healthBarUI == (Object)null || (Object)(object)playerTransform == (Object)null) { return; } bool flag = true; float num = Vector3.Distance(((Component)this).transform.position, playerTransform.position); if (num > detectionDistance) { flag = false; } if (!((Component)this).gameObject.activeInHierarchy) { flag = false; } if (!Object.op_Implicit((Object)(object)colliders2D) || !((Behaviour)colliders2D).enabled) { flag = false; } if (isDamageVisible && Time.time - lastDamageTime > Plugin.NormalHideDelay.Value) { isDamageVisible = false; } if (!isDamageVisible) { flag = false; } if (healthBarUI.activeSelf != flag) { if (flag) { ShowHealthBar(); } else { HideHealthBar(); } } } public void OnTakeDamage() { lastDamageTime = Time.time; isDamageVisible = true; if ((Object)(object)healthBarUI != (Object)null) { ShowHealthBar(); } } private void OnDestroy() { if ((Object)(object)healthBarUI != (Object)null) { Object.Destroy((Object)(object)healthBarUI); healthBarUI = null; } isUICreated = false; } } public class BossHealthBar : MonoBehaviour { [CompilerGenerated] private sealed class <ExpandHealthBarAnimation>d__23 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public BossHealthBar <>4__this; private float <originalBgAlpha>5__1; private float <originalFillAmount>5__2; private RectTransform <fillRect>5__3; private RectTransform <rightTransform>5__4; private Vector2 <originalRightPosition>5__5; private Color <bgColor>5__6; private float <elapsedTime>5__7; private float <duration>5__8; private float <fillWidth>5__9; private float <progress>5__10; private float <easedProgress>5__11; private float <fillWidth>5__12; private float <currentRightX>5__13; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <ExpandHealthBarAnimation>d__23(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <fillRect>5__3 = null; <rightTransform>5__4 = null; <>1__state = -2; } private bool MoveNext() { //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_02eb: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_027c: Unknown result type (might be due to invalid IL or missing references) //IL_0310: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) switch (<>1__state) { default: return false; case 0: { <>1__state = -1; if ((Object)(object)<>4__this.bgImage == (Object)null || (Object)(object)<>4__this.fillImage == (Object)null) { return false; } <>4__this.isExpanding = true; <originalBgAlpha>5__1 = ((Graphic)<>4__this.bgImage).color.a; <originalFillAmount>5__2 = <>4__this.fillImage.fillAmount; <fillRect>5__3 = ((Graphic)<>4__this.fillImage).rectTransform; Transform obj = ((Transform)<fillRect>5__3).Find("Right"); <rightTransform>5__4 = ((obj != null) ? ((Component)obj).GetComponent<RectTransform>() : null); <originalRightPosition>5__5 = Vector2.zero; if ((Object)(object)<rightTransform>5__4 != (Object)null) { <originalRightPosition>5__5 = <rightTransform>5__4.anchoredPosition; } <bgColor>5__6 = ((Graphic)<>4__this.bgImage).color; <bgColor>5__6.a = 0f; ((Graphic)<>4__this.bgImage).color = <bgColor>5__6; <>4__this.fillImage.fillAmount = 0f; if ((Object)(object)<rightTransform>5__4 != (Object)null) { <fillWidth>5__9 = <fillRect>5__3.sizeDelta.x; <rightTransform>5__4.anchoredPosition = new Vector2((0f - <fillWidth>5__9) / 2f + 65f, <originalRightPosition>5__5.y); } <elapsedTime>5__7 = 0f; <duration>5__8 = Plugin.BossExpandDuration.Value; break; } case 1: <>1__state = -1; break; } if (<elapsedTime>5__7 < <duration>5__8) { <elapsedTime>5__7 += Time.deltaTime; <progress>5__10 = <elapsedTime>5__7 / <duration>5__8; <easedProgress>5__11 = Mathf.SmoothStep(0f, 1f, <progress>5__10); <>4__this.fillImage.fillAmount = <easedProgress>5__11; if ((Object)(object)<rightTransform>5__4 != (Object)null) { <fillWidth>5__12 = <fillRect>5__3.sizeDelta.x; <currentRightX>5__13 = (0f - <fillWidth>5__12) / 2f + 65f + <fillWidth>5__12 * <easedProgress>5__11; <rightTransform>5__4.anchoredPosition = new Vector2(<currentRightX>5__13, <originalRightPosition>5__5.y); } <>2__current = null; <>1__state = 1; return true; } <>4__this.fillImage.fillAmount = <originalFillAmount>5__2; <bgColor>5__6.a = <originalBgAlpha>5__1; ((Graphic)<>4__this.bgImage).color = <bgColor>5__6; if ((Object)(object)<rightTransform>5__4 != (Object)null) { <rightTransform>5__4.anchoredPosition = <originalRightPosition>5__5; } <>4__this.isExpanding = false; <>4__this.hasExpanded = true; return false; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } private HealthManager healthManager; private float lastHealth; private float maxHealth; public float detectionDistance = 50f; private Transform playerTransform; private GameObject healthBarUI; private Canvas canvas; private Image bgImage; private Image fillImage; private Text bossNameText; private Image leftImage; private Image rightImage; public static float baseScale = 0.5f; private float fixedDistance = 150f; private bool isExpanding = false; private bool hasExpanded = false; private Vector2 originalSize; private PlayMakerFSM fsm; public bool IsExpanding() { return isExpanding; } private void Awake() { if (((Component)this).GetComponents<BossHealthBar>().Length > 1) { Object.Destroy((Object)(object)this); return; } HealthBar component = ((Component)this).GetComponent<HealthBar>(); if ((Object)(object)component != (Object)null) { Object.Destroy((Object)(object)component); } healthManager = ((Component)this).GetComponent<HealthManager>(); if (((Object)((Component)this).gameObject).name == "Silk Boss" && healthManager.hp >= 1000) { maxHealth = 100f; lastHealth = 100f; } else { maxHealth = healthManager.hp; lastHealth = healthManager.hp; } Plugin.Log.LogInfo((object)("Boss对象名:" + ((Object)((Component)this).gameObject).name)); playerTransform = Object.FindFirstObjectByType<HeroController>().transform; fsm = ((Component)this).gameObject.GetComponent<PlayMakerFSM>(); } private void Update() { if ((Object)(object)healthManager == (Object)null) { return; } int activeHealthBarCount = BossHealthBarManager.Instance.GetActiveHealthBarCount(); if (activeHealthBarCount < 2) { SetBossName(isHide: false); } float num = healthManager.hp; UpdateMaxHealth(); if (num != lastHealth) { lastHealth = num; if ((Object)(object)healthBarUI == (Object)null) { CreateHealthBarUI(); } UpdateHealthBar(); ShowHealthBar(); } CheckVisibilityConditions(); } private void CreateHealthBarUI() { //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: 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_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)healthBarUI != (Object)null) && BossHealthBarManager.Instance.RegisterHealthBar(this)) { healthBarUI = Object.Instantiate<GameObject>(Plugin.bossHealthBarPrefab); canvas = healthBarUI.GetComponent<Canvas>(); canvas.renderMode = (RenderMode)0; canvas.sortingOrder = 100; CanvasScaler component = healthBarUI.GetComponent<CanvasScaler>(); if ((Object)(object)component != (Object)null) { Object.DestroyImmediate((Object)(object)component); } Transform val = healthBarUI.transform.Find("BG"); bgImage = ((Component)val).GetComponent<Image>(); ((Graphic)bgImage).color = new Color(((Graphic)bgImage).color.r, ((Graphic)bgImage).color.g, ((Graphic)bgImage).color.b, 0.25f); fillImage = ((Component)val.Find("Fill")).GetComponent<Image>(); fillImage.type = (Type)3; fillImage.fillMethod = (FillMethod)0; bossNameText = ((Component)val.Find("BossName")).GetComponent<Text>(); leftImage = ((Component)val.Find("BossName").Find("Left")).GetComponent<Image>(); rightImage = ((Component)val.Find("BossName").Find("Right")).GetComponent<Image>(); SetupUILayout(); if ((Object)(object)bgImage != (Object)null) { originalSize = ((Graphic)bgImage).rectTransform.sizeDelta; } bossNameText.text = GetBossName(); bossNameText.fontSize = 65; UpdateNameLayout(); UpdateBossTitle(); BossHealthBarManager.Instance.ArrangeHealthBars(); HideHealthBar(); int num = BossHealthBarManager.Instance.GetActiveHealthBarCount() - 1; if (num > 0) { SetBossName(isHide: true); } } } private void ShowHealthBar() { if ((Object)(object)healthBarUI != (Object)null) { healthBarUI.SetActive(true); if (!hasExpanded && !isExpanding) { ((MonoBehaviour)this).StartCoroutine(ExpandHealthBarAnimation()); } } } [IteratorStateMachine(typeof(<ExpandHealthBarAnimation>d__23))] private IEnumerator ExpandHealthBarAnimation() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <ExpandHealthBarAnimation>d__23(0) { <>4__this = this }; } private void HideHealthBar() { if ((Object)(object)healthBarUI != (Object)null) { healthBarUI.SetActive(false); } } private void SetupUILayout() { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0091: 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) //IL_00aa: 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_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)bgImage != (Object)null) { RectTransform rectTransform = ((Graphic)bgImage).rectTransform; rectTransform.anchorMin = new Vector2(0.5f, 0f); rectTransform.anchorMax = new Vector2(0.5f, 0f); rectTransform.pivot = new Vector2(0.5f, 0f); rectTransform.anchoredPosition = new Vector2(Plugin.BossPositionX.Value, (float)Screen.height * 0.82f + Plugin.BossPositionY.Value); ((Transform)rectTransform).localScale = Vector3.one * baseScale * Plugin.BossScale.Value; rectTransform.sizeDelta = new Vector2(1572f, 35f) + new Vector2(Plugin.BossWidthOffset.Value, Plugin.BossHeightOffset.Value); RectTransform component = ((Component)((Transform)rectTransform).Find("Fill")).GetComponent<RectTransform>(); component.sizeDelta = rectTransform.sizeDelta; Transform obj = ((Transform)component).Find("Right"); RectTransform val = ((obj != null) ? ((Component)obj).GetComponent<RectTransform>() : null); Transform obj2 = ((Transform)component).Find("Left"); RectTransform val2 = ((obj2 != null) ? ((Component)obj2).GetComponent<RectTransform>() : null); if ((Object)(object)val2 != (Object)null && (Object)(object)val != (Object)null) { float x = component.sizeDelta.x; float num = 65f; float num2 = x / 2f; val2.anchoredPosition = new Vector2(0f - num2 - num, val2.anchoredPosition.y); val.anchoredPosition = new Vector2(num2 + num, val.anchoredPosition.y); } } } public void RefreshLayout() { SetupUILayout(); } private void UpdateNameLayout() { //IL_00ae: 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_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0075: 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_0087: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)bossNameText == (Object)null) && !((Object)(object)leftImage == (Object)null) && !((Object)(object)rightImage == (Object)null)) { Vector2 val2 = default(Vector2); try { TextGenerator val = new TextGenerator(); TextGenerationSettings generationSettings = bossNameText.GetGenerationSettings(Vector2.zero); float preferredWidth = val.GetPreferredWidth(bossNameText.text, generationSettings); float preferredHeight = val.GetPreferredHeight(bossNameText.text, generationSettings); val2 = new Vector2(preferredWidth, preferredHeight); } catch (Exception) { ((Vector2)(ref val2))..ctor(200f, 30f); } RectTransform rectTransform = ((Graphic)bossNameText).rectTransform; rectTransform.sizeDelta = new Vector2(val2.x, rectTransform.sizeDelta.y); RectTransform rectTransform2 = ((Graphic)leftImage).rectTransform; RectTransform rectTransform3 = ((Graphic)rightImage).rectTransform; float x = val2.x; float num = x * 0.5f; rectTransform2.anchoredPosition = new Vector2(0f - num - fixedDistance, 0f); rectTransform3.anchoredPosition = new Vector2(num + fixedDistance, 0f); } } private void UpdateHealthBar() { if (!((Object)(object)fillImage == (Object)null) && !((Object)(object)healthManager == (Object)null)) { float fillAmount = (float)healthManager.hp / maxHealth; fillImage.fillAmount = fillAmount; } } private void UpdateMaxHealth() { if (!((Object)(object)healthManager == (Object)null)) { float num = healthManager.hp; if (num > maxHealth && num <= 3000f) { maxHealth = num; } } } private void CheckVisibilityConditions() { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)healthBarUI == (Object)null || (Object)(object)playerTransform == (Object)null) { return; } bool flag = true; float num = Vector3.Distance(((Component)this).transform.position, playerTransform.position); if (num > detectionDistance) { flag = false; } if (healthBarUI.activeSelf != flag) { if (flag) { ShowHealthBar(); } else { HideHealthBar(); } } } public void OnTakeDamage() { if ((Object)(object)healthBarUI != (Object)null) { ShowHealthBar(); } } private MapZone GetCurrentMapZone() { //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) try { GameManager instance = GameManager.instance; if ((Object)(object)instance != (Object)null) { GameMap gameMap = instance.gameMap; if ((Object)(object)gameMap != (Object)null) { return gameMap.GetCurrentMapZone(); } } } catch (Exception ex) { Plugin.Log.LogError((object)("获取当前MapZone失败: " + ex.Message)); } return (MapZone)0; } private string GetLocalizedAreaName(MapZone mapZone) { try { string text = ((object)(MapZone)(ref mapZone)).ToString(); if (!string.IsNullOrEmpty(text)) { return Language.Get(text, "Map Zones"); } } catch (Exception ex) { Plugin.Log.LogError((object)("获取区域本地化名称失败: " + ex.Message)); } return ((object)(MapZone)(ref mapZone)).ToString(); } private void UpdateBossTitle() { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0008: 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) try { MapZone currentMapZone = GetCurrentMapZone(); string localizedAreaName = GetLocalizedAreaName(currentMapZone); if (!((Object)(object)healthBarUI != (Object)null)) { return; } Transform val = healthBarUI.transform.Find("BG"); if ((Object)(object)val != (Object)null) { Transform val2 = val.Find("BossName/Title"); if ((Object)(object)val2 != (Object)null) { Text component = ((Component)val2).GetComponent<Text>(); if ((Object)(object)component != (Object)null) { component.text = Plugin.PreTitle.Value + localizedAreaName + Plugin.PostTitle.Value; component.fontSize += 10; Plugin.Log.LogInfo((object)$"BOSS标题已更新: {component.text}, 字体大小: {component.fontSize}"); } else { Plugin.Log.LogWarning((object)"未找到Title对象的Text组件"); } } else { Plugin.Log.LogWarning((object)"未找到BG对象下的Title对象"); } } else { Plugin.Log.LogWarning((object)"未找到healthBarUI下的BG对象"); } } catch (Exception ex) { Plugin.Log.LogError((object)("更新BOSS标题失败: " + ex.Message)); } } private string GetBossName() { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_01f1: Unknown result type (might be due to invalid IL or missing references) //IL_02f8: Unknown result type (might be due to invalid IL or missing references) //IL_031d: Unknown result type (might be due to invalid IL or missing references) //IL_0336: Unknown result type (might be due to invalid IL or missing references) string name = ((Object)((Component)healthManager).gameObject).name; try { EnemyDeathEffects component = ((Component)healthManager).gameObject.GetComponent<EnemyDeathEffects>(); if ((Object)(object)component != (Object)null && (Object)(object)component.journalRecord != (Object)null) { LocalisedString displayName = component.journalRecord.displayName; if (!string.IsNullOrEmpty(LocalisedString.op_Implicit(displayName))) { return LocalisedString.op_Implicit(displayName); } } List<EnemyJournalRecord> allEnemies = EnemyJournalManager.GetAllEnemies(); string name2 = ((Object)((Component)healthManager).gameObject).name; string[] array = name2.Split(new char[5] { ' ', '(', ')', '_', '-' }, StringSplitOptions.RemoveEmptyEntries); foreach (EnemyJournalRecord item in allEnemies) { if ((Object)(object)item == (Object)null || string.IsNullOrEmpty(((Object)item).name)) { continue; } string[] array2 = ((Object)item).name.Split(new char[5] { ' ', '(', ')', '_', '-' }, StringSplitOptions.RemoveEmptyEntries); int num = 0; string[] array3 = array; foreach (string text in array3) { if (string.IsNullOrEmpty(text) || text.Length < 2) { continue; } string[] array4 = array2; foreach (string text2 in array4) { if (!string.IsNullOrEmpty(text2) && text2.Length >= 2 && string.Equals(text, text2, StringComparison.OrdinalIgnoreCase)) { num++; break; } } } if (num < 2 || string.IsNullOrEmpty(LocalisedString.op_Implicit(item.displayName))) { continue; } Plugin.Log.LogInfo((object)$"通过EnemyJournalManager匹配到Boss名称: {item.displayName} (匹配单词数: {num})"); return LocalisedString.op_Implicit(item.displayName); } foreach (EnemyJournalRecord item2 in allEnemies) { if ((Object)(object)item2 == (Object)null || string.IsNullOrEmpty(((Object)item2).name)) { continue; } string[] array5 = ((Object)item2).name.Split(new char[5] { ' ', '(', ')', '_', '-' }, StringSplitOptions.RemoveEmptyEntries); string[] array6 = array; foreach (string text3 in array6) { if (string.IsNullOrEmpty(text3) || text3.Length < 3) { continue; } string[] array7 = array5; foreach (string text4 in array7) { if (!string.IsNullOrEmpty(text4) && text4.Length >= 3 && string.Equals(text3, text4, StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(LocalisedString.op_Implicit(item2.displayName))) { Plugin.Log.LogInfo((object)$"通过EnemyJournalManager单词匹配到Boss名称: {item2.displayName} (匹配单词: {text3})"); return LocalisedString.op_Implicit(item2.displayName); } } } } name = CleanGameObjectName(((Object)((Component)healthManager).gameObject).name); } catch (Exception ex) { Plugin.Log.LogWarning((object)("获取Boss名称时发生异常: " + ex.Message)); name = CleanGameObjectName(((Object)((Component)healthManager).gameObject).name); } return name; } private string CleanGameObjectName(string originalName) { if (string.IsNullOrEmpty(originalName)) { return "未知Boss"; } int num = originalName.IndexOf('('); if (num >= 0) { originalName = originalName.Substring(0, num).Trim(); } string[] array = new string[4] { " Clone", "(Clone)", " Instance", "(Instance)" }; string[] array2 = array; foreach (string text in array2) { if (originalName.EndsWith(text)) { originalName = originalName.Substring(0, originalName.Length - text.Length).Trim(); } } return string.IsNullOrEmpty(originalName) ? "未知Boss" : originalName; } public RectTransform GetHealthBarTransform() { if ((Object)(object)healthBarUI != (Object)null && (Object)(object)bgImage != (Object)null) { return ((Graphic)bgImage).rectTransform; } return null; } public void SetBossName(bool isHide) { if ((Object)(object)bossNameText != (Object)null) { RectTransform rectTransform = ((Graphic)bossNameText).rectTransform; ((Component)rectTransform).gameObject.SetActive(!isHide); } } private void OnDestroy() { if ((Object)(object)BossHealthBarManager.Instance != (Object)null) { BossHealthBarManager.Instance.UnregisterHealthBar(this); } if ((Object)(object)healthBarUI != (Object)null) { Object.Destroy((Object)(object)healthBarUI); } } } }