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 XH DamageShow EnemyHealthBar v1.0.3
REPO MOD.dll
Decompiled 3 months agousing System; using System.Collections.Generic; using System.Diagnostics; 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 HarmonyLib; using TMPro; 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("REPO MOD")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("微软中国")] [assembly: AssemblyProduct("REPO MOD")] [assembly: AssemblyCopyright("Copyright © 微软中国 2025")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("48060547-bfdb-47cd-aac0-71116dcfa012")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] namespace REPO_MOD; [BepInPlugin("com.XhPlugin.Repo_Mod", "XH_REPO_DamageShow&EnemyHealthBar_Mod", "1.0.3")] public class Plugin : BaseUnityPlugin { public static ManualLogSource Logger; internal static bool VerboseLogging; internal static ConfigEntry<float> HealthBarExtraHeightOffset; private readonly Harmony _harmony = new Harmony("com.XhPlugin.Repo_Mod"); private void Awake() { Logger = ((BaseUnityPlugin)this).Logger; HealthBarExtraHeightOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Enemy Health Bar / 敌人血条", "ExtraHeightOffset / 增高偏移", 0.55f, "血条额外增高偏移:在自动高度计算完成后始终追加(单位:米) / Extra height offset: always added after auto height calculation (unit: meters)"); _harmony.PatchAll(); Logger.LogInfo((object)"小海怪物血量MOD加载成功!Xiaohai DamageShow&EnemyHealthBar MOD loaded successfully ! v1.0.3"); } } public class WorldSpaceUIDamageText : WorldSpaceUIChild { private TextMeshProUGUI textComponent; private float timer = 1.5f; private Vector3 baseWorldPosition; private float floatHeight; public void Awake() { textComponent = ((Component)this).GetComponent<TextMeshProUGUI>(); if ((Object)(object)textComponent == (Object)null) { textComponent = ((Component)this).gameObject.AddComponent<TextMeshProUGUI>(); } } public override void Start() { //IL_001b: 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) ((WorldSpaceUIChild)this).Start(); ((TMP_Text)textComponent).alignment = (TextAlignmentOptions)514; baseWorldPosition = base.worldPosition; } public override void Update() { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0032: 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) //IL_003c: Unknown result type (might be due to invalid IL or missing references) ((WorldSpaceUIChild)this).Update(); floatHeight += Time.deltaTime * 0.8f; base.worldPosition = baseWorldPosition + Vector3.up * floatHeight; timer -= Time.deltaTime; ((TMP_Text)textComponent).alpha = Mathf.Clamp01(timer * 2f); if (timer <= 0f) { Object.Destroy((Object)(object)((Component)this).gameObject); } } public void Initialize(int damage, Color color, float fontSize, float time) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)textComponent == (Object)null) { textComponent = ((Component)this).GetComponent<TextMeshProUGUI>(); } ((TMP_Text)textComponent).text = $"-{damage}"; ((Graphic)textComponent).color = color; ((TMP_Text)textComponent).fontSize = fontSize; timer = time; } } public static class DamageTextManager { public static void CreateDamageText(Vector3 position, int damage) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown //IL_0065: 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_008c: 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) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("DamageText", new Type[3] { typeof(RectTransform), typeof(TextMeshProUGUI), typeof(WorldSpaceUIDamageText) }); val.transform.SetParent(((Component)WorldSpaceUIParent.instance).transform); WorldSpaceUIDamageText component = val.GetComponent<WorldSpaceUIDamageText>(); if (damage >= 50) { component.Initialize(damage, Color.red, 43f, 3f); } else if (damage >= 25) { component.Initialize(damage, Color.yellow, 35f, 2f); } else { component.Initialize(damage, new Color(1f, 23f / 85f, 0f), 25f, 1.5f); } ((WorldSpaceUIChild)component).worldPosition = position; } } public class EnemyHealthBar : MonoBehaviour { public class Billboard : MonoBehaviour { private Camera mainCamera; private void Start() { mainCamera = Camera.main; } private void LateUpdate() { //IL_0023: 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_0047: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)mainCamera != (Object)null) { ((Component)this).transform.rotation = Quaternion.Euler(((Component)mainCamera).transform.eulerAngles.x, ((Component)mainCamera).transform.eulerAngles.y, 0f); } } } private float _lastDamageTime; private bool _isActive = true; private bool _initialized; public Vector3 worldOffset = new Vector3(0f, 1.25f, 0f); public Vector2 size = new Vector2(20f, 2.5f); public Color backgroundColor = new Color(0.3f, 0.3f, 0.3f, 0.9f); public Color healthColor = Color.red; public Canvas canvas; private Image foreground; private Image background; private EnemyHealth enemyHealth; private TextMeshProUGUI healthText; private Enemy enemy; private Transform followTransform; private Camera mainCamera; private float targetFillAmount = 1f; private int lastHealthCurrent = int.MinValue; private int lastHealthMax = int.MinValue; private float nextVisibilityUpdateTime; private float nextFollowResolveTime; private float nextOffsetResolveTime; private static Sprite sharedWhiteSprite; public void EnsureInitialized() { if (!_initialized) { enemyHealth = ((Component)this).GetComponent<EnemyHealth>(); if (!((Object)(object)enemyHealth == (Object)null)) { enemy = enemyHealth.enemy; followTransform = ResolveFollowTransform(); mainCamera = Camera.main; InitializeCanvas(); UpdateWorldOffsetFromBounds(force: true); UpdateCanvasWorldPosition(); UpdateHealthDisplay(); ResetTimer(); _initialized = true; } } } private Transform ResolveFollowTransform() { if ((Object)(object)enemy != (Object)null) { if (enemy.HasRigidbody && (Object)(object)enemy.Rigidbody != (Object)null) { return ((Component)enemy.Rigidbody).transform; } if ((Object)(object)enemy.CenterTransform != (Object)null) { return enemy.CenterTransform; } } return ((Component)this).transform; } private static Sprite GetSharedWhiteSprite() { //IL_0038: 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) if ((Object)(object)sharedWhiteSprite != (Object)null) { return sharedWhiteSprite; } Texture2D whiteTexture = Texture2D.whiteTexture; sharedWhiteSprite = Sprite.Create(whiteTexture, new Rect(0f, 0f, (float)((Texture)whiteTexture).width, (float)((Texture)whiteTexture).height), new Vector2(0.5f, 0.5f)); return sharedWhiteSprite; } public void ResetTimer() { _lastDamageTime = Time.time; if (!_isActive && (Object)(object)canvas != (Object)null) { ReactivateHealthBar(); } } private void ReactivateHealthBar() { _isActive = true; if ((Object)(object)canvas != (Object)null) { ((Component)canvas).gameObject.SetActive(true); } UpdateHealthDisplay(); UpdateCanvasVisibility(); } private void DestroyHealthBar() { _isActive = false; if ((Object)(object)canvas != (Object)null) { ((Component)canvas).gameObject.SetActive(false); } } private void InitializeCanvas() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_005f: 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_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("HealthCanvas"); canvas = val.AddComponent<Canvas>(); canvas.renderMode = (RenderMode)2; ((Component)canvas).transform.SetParent(((Object)(object)followTransform != (Object)null) ? followTransform : ((Component)this).transform, false); ((Component)canvas).transform.localPosition = worldOffset; RectTransform component = ((Component)canvas).GetComponent<RectTransform>(); component.sizeDelta = size; ((Transform)component).localScale = new Vector3(0.03f, 0.03f, 0.03f); val.AddComponent<GraphicRaycaster>(); background = CreateBarElement(((Component)canvas).transform, backgroundColor, "Background"); foreground = CreateBarElement(((Component)canvas).transform, healthColor, "Foreground"); foreground.type = (Type)3; foreground.fillMethod = (FillMethod)0; foreground.fillOrigin = 0; val.AddComponent<Billboard>(); CreateHealthText(((Component)canvas).transform); } private void UpdateWorldOffsetFromBounds(bool force) { //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) if (!force && Time.time < nextOffsetResolveTime) { return; } nextOffsetResolveTime = Time.time + 1f; Transform val = ResolveBoundsRoot(); if (!((Object)(object)val == (Object)null) && !((Object)(object)followTransform == (Object)null) && TryGetWorldBounds(val, out var bounds)) { float y = followTransform.position.y; float num = 0.15f; float num2 = ((Bounds)(ref bounds)).max.y - y + num; num2 = Mathf.Clamp(num2, 0.35f, 12f); float num3 = ((Plugin.HealthBarExtraHeightOffset != null) ? Plugin.HealthBarExtraHeightOffset.Value : 1.25f); if (num3 < 0f) { num3 = 0f; } float num4 = Mathf.Clamp(num2 + num3, 0.35f, 20f); if (Mathf.Abs(worldOffset.y - num4) > 0.01f) { worldOffset = new Vector3(worldOffset.x, num4, worldOffset.z); UpdateCanvasWorldPosition(); } } } private Transform ResolveBoundsRoot() { if ((Object)(object)enemyHealth != (Object)null && (Object)(object)((Component)enemyHealth).transform != (Object)null && (Object)(object)((Component)enemyHealth).transform.parent != (Object)null) { return ((Component)enemyHealth).transform.parent; } if ((Object)(object)enemy != (Object)null && (Object)(object)enemy.EnemyParent != (Object)null) { return ((Component)enemy.EnemyParent).transform; } if ((Object)(object)enemyHealth != (Object)null) { return ((Component)enemyHealth).transform; } return null; } private void UpdateCanvasWorldPosition() { //IL_002b: 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_0055: 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_006f: 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)canvas == (Object)null) && !((Object)(object)followTransform == (Object)null)) { Vector3 position = followTransform.position + new Vector3(worldOffset.x, 0f, worldOffset.z) + Vector3.up * worldOffset.y; ((Component)canvas).transform.position = position; } } private static bool TryGetWorldBounds(Transform root, out Bounds bounds) { //IL_0002: 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_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: 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_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) bounds = default(Bounds); bool flag = false; Collider[] componentsInChildren = ((Component)root).GetComponentsInChildren<Collider>(true); foreach (Collider val in componentsInChildren) { if (!((Object)(object)val == (Object)null) && !val.isTrigger) { if (!flag) { bounds = val.bounds; flag = true; } else { ((Bounds)(ref bounds)).Encapsulate(val.bounds); } } } if (flag) { return true; } Renderer[] componentsInChildren2 = ((Component)root).GetComponentsInChildren<Renderer>(true); foreach (Renderer val2 in componentsInChildren2) { if (!((Object)(object)val2 == (Object)null)) { if (!flag) { bounds = val2.bounds; flag = true; } else { ((Bounds)(ref bounds)).Encapsulate(val2.bounds); } } } return flag; } private void CreateHealthText(Transform parent) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: 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_00d7: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("HealthText"); val.transform.SetParent(parent, false); healthText = val.AddComponent<TextMeshProUGUI>(); ((TMP_Text)healthText).alignment = (TextAlignmentOptions)514; ((TMP_Text)healthText).fontSize = 10f; ((Graphic)healthText).color = Color.white; ((TMP_Text)healthText).margin = new Vector4(0f, 0f, 0f, 10f); RectTransform component = ((Component)healthText).GetComponent<RectTransform>(); component.anchorMin = new Vector2(0.5f, 1f); component.anchorMax = new Vector2(0.5f, 1f); component.pivot = new Vector2(0.5f, 0.5f); component.anchoredPosition = new Vector2(0f, 5f); } private void UpdateHealthText() { //IL_009c: 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)healthText != (Object)null && (Object)(object)enemyHealth != (Object)null) { ((TMP_Text)healthText).text = $"{enemyHealth.healthCurrent}/{enemyHealth.health}"; if ((float)enemyHealth.healthCurrent / (float)enemyHealth.health < 0.3f) { ((Graphic)healthText).color = Color.yellow; } else { ((Graphic)healthText).color = Color.white; } } } private Image CreateBarElement(Transform parent, Color color, string name) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_002a: 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_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name); val.transform.SetParent(parent, false); Image val2 = val.AddComponent<Image>(); val2.sprite = GetSharedWhiteSprite(); ((Graphic)val2).color = color; RectTransform component = val.GetComponent<RectTransform>(); component.anchorMin = Vector2.zero; component.anchorMax = Vector2.one; component.offsetMin = Vector2.zero; component.offsetMax = Vector2.zero; return val2; } private void Update() { //IL_0264: Unknown result type (might be due to invalid IL or missing references) //IL_026e: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Unknown result type (might be due to invalid IL or missing references) //IL_0228: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) EnsureInitialized(); if (!_initialized || !_isActive) { return; } if (Time.time - _lastDamageTime > 10f) { DestroyHealthBar(); } else { if ((Object)(object)enemyHealth == (Object)null || (Object)(object)foreground == (Object)null || (Object)(object)background == (Object)null) { return; } if (Time.time >= nextFollowResolveTime) { Transform val = ResolveFollowTransform(); if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)followTransform) { followTransform = val; if ((Object)(object)canvas != (Object)null) { ((Component)canvas).transform.SetParent(followTransform, false); ((Component)canvas).transform.localPosition = worldOffset; } UpdateWorldOffsetFromBounds(force: true); } nextFollowResolveTime = Time.time + 0.5f; } UpdateWorldOffsetFromBounds(force: false); UpdateCanvasWorldPosition(); int healthCurrent = enemyHealth.healthCurrent; int health = enemyHealth.health; if (health > 0 && (healthCurrent != lastHealthCurrent || health != lastHealthMax)) { lastHealthCurrent = healthCurrent; lastHealthMax = health; targetFillAmount = Mathf.Clamp01((float)healthCurrent / (float)health); UpdateHealthText(); } foreground.fillAmount = Mathf.Lerp(foreground.fillAmount, targetFillAmount, Time.deltaTime * 10f); if (targetFillAmount < 0.3f) { float num = Mathf.PingPong(Time.time * 2f, 1f); ((Graphic)foreground).color = new Color(1f, num, num, ((Graphic)foreground).color.a); } else { ((Graphic)foreground).color = new Color(healthColor.r, healthColor.g, healthColor.b, ((Graphic)foreground).color.a); } if (Time.time >= nextVisibilityUpdateTime) { UpdateCanvasVisibility(); nextVisibilityUpdateTime = Time.time + 0.1f; } } } private void UpdateCanvasVisibility() { //IL_007b: 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_0080: Unknown result type (might be due to invalid IL or missing references) //IL_008c: 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_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)mainCamera == (Object)null) { mainCamera = Camera.main; } if (!((Object)(object)mainCamera == (Object)null) && !((Object)(object)foreground == (Object)null) && !((Object)(object)background == (Object)null)) { Vector3 val = (((Object)(object)canvas != (Object)null) ? ((Component)canvas).transform.position : ((Component)this).transform.position); float num = Vector3.Distance(((Component)mainCamera).transform.position, val); float num2 = Mathf.Clamp01(1f - num / 50f); ((Graphic)foreground).color = new Color(healthColor.r, healthColor.g, healthColor.b, num2); ((Graphic)background).color = new Color(backgroundColor.r, backgroundColor.g, backgroundColor.b, num2 * 0.8f); } } public void UpdateHealthDisplay() { if (!((Object)(object)enemyHealth == (Object)null)) { int health = enemyHealth.health; if (health > 0) { targetFillAmount = Mathf.Clamp01((float)enemyHealth.healthCurrent / (float)health); } UpdateHealthText(); } } private void OnDestroy() { if ((Object)(object)canvas != (Object)null) { Debug.Log((object)("销毁血条:" + ((Object)enemyHealth).name)); Object.Destroy((Object)(object)((Component)canvas).gameObject); } } } [HarmonyPatch] public static class Patch { [HarmonyPatch(typeof(HurtCollider), "EnemyHurt")] public static class HurtColliderPatch { [HarmonyPostfix] public static void EnemyHurtPatch(HurtCollider __instance, ref Enemy _enemy) { if (Plugin.VerboseLogging && Plugin.Logger != null && !((Object)(object)_enemy == (Object)null) && !((Object)(object)_enemy.EnemyParent == (Object)null)) { int num = ((!__instance.enemyKill) ? __instance.enemyDamage : (((Object)(object)_enemy.Health != (Object)null) ? _enemy.Health.healthCurrent : 0)); Plugin.Logger.LogInfo((object)$"敌人{_enemy.EnemyParent.enemyName}受伤,伤害{num}"); } } } [HarmonyPatch(typeof(BigMessageUI))] internal class BigMessageUIPatch { [HarmonyPatch("Update")] [HarmonyPrefix] private static bool UpdatePrefix(BigMessageUI __instance, ref float ___bigMessageTimer) { if (___bigMessageTimer > 0f) { ___bigMessageTimer -= Time.deltaTime * 0.5f; return false; } return true; } } private static readonly Dictionary<int, float> lastDamageTextTimeByEnemy = new Dictionary<int, float>(); [HarmonyPatch(typeof(EnemyHealth), "HurtRPC")] [HarmonyPostfix] private static void OnHurt(EnemyHealth __instance, int _damage, Vector3 _hurtDirection) { //IL_00a8: 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_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) if (_damage <= 0 || (Object)(object)__instance == (Object)null) { return; } try { EnemyHealthBar enemyHealthBar = ((Component)__instance).GetComponent<EnemyHealthBar>(); if ((Object)(object)enemyHealthBar == (Object)null) { enemyHealthBar = ((Component)__instance).gameObject.AddComponent<EnemyHealthBar>(); } enemyHealthBar.EnsureInitialized(); enemyHealthBar.ResetTimer(); enemyHealthBar.UpdateHealthDisplay(); int instanceID = ((Object)__instance).GetInstanceID(); float time = Time.time; if (lastDamageTextTimeByEnemy.TryGetValue(instanceID, out var value) && time - value < 0.05f) { return; } lastDamageTextTimeByEnemy[instanceID] = time; int damage = Mathf.Clamp(_damage, 1, 9999); Vector3 position = ((Component)__instance).transform.position; Enemy enemy = __instance.enemy; if ((Object)(object)enemy != (Object)null) { if (enemy.HasRigidbody && (Object)(object)enemy.Rigidbody != (Object)null) { position = ((Component)enemy.Rigidbody).transform.position; } else if ((Object)(object)enemy.CenterTransform != (Object)null) { position = enemy.CenterTransform.position; } } Vector3 position2 = position + Vector3.up * 1.5f + Random.insideUnitSphere * 0.3f; DamageTextManager.CreateDamageText(position2, damage); } catch (Exception arg) { Plugin.Logger.LogError((object)$"处理伤害时出错: {arg}"); } } [HarmonyPostfix] [HarmonyPatch(typeof(EnemyHealth), "Death")] private static void OnDeath(EnemyHealth __instance) { EnemyHealthBar component = ((Component)__instance).GetComponent<EnemyHealthBar>(); if ((Object)(object)component != (Object)null) { Object.Destroy((Object)(object)component); } } [HarmonyPostfix] [HarmonyPatch(typeof(EnemyHealth), "Awake")] private static void PostStart(EnemyHealth __instance) { //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) try { if ((Object)(object)((Component)__instance).GetComponent<EnemyHealthBar>() == (Object)null) { EnemyHealthBar enemyHealthBar = ((Component)__instance).gameObject.AddComponent<EnemyHealthBar>(); enemyHealthBar.worldOffset = new Vector3(0f, GetEnemyHeight(__instance), 0f); if (Plugin.VerboseLogging && Plugin.Logger != null && (Object)(object)__instance.enemy != (Object)null && (Object)(object)__instance.enemy.EnemyParent != (Object)null) { Plugin.Logger.LogInfo((object)("初始化血条:" + __instance.enemy.EnemyParent.enemyName)); } } } catch (Exception arg) { Debug.LogError((object)$"血条初始化失败:{arg}"); } } private static float GetEnemyHeight(EnemyHealth enemy) { //IL_0023: 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_002b: Unknown result type (might be due to invalid IL or missing references) Collider componentInChildren = ((Component)((Component)enemy).transform.parent).GetComponentInChildren<Collider>(); float result; if (!((Object)(object)componentInChildren != (Object)null)) { result = 2.5f; } else { Bounds bounds = componentInChildren.bounds; result = ((Bounds)(ref bounds)).size.y + 0.5f; } return result; } } [HarmonyPatch(typeof(ExtractionPoint))] public static class ExtractionPoint_Patches { private static bool once; [HarmonyPrefix] [HarmonyPatch("StateActive")] private static void Postfix_MissionText() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) if (!once) { once = true; SemiFunc.UIFocusText("欢迎使用由CO2赞助的怪物血量MOD by小海", Color.white, AssetManager.instance.colorYellow, 5f); } } }