Decompiled source of HealthBar v1.0.1

Yap_HealthBar.dll

Decompiled 4 days ago
using 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;
using YAPYAP;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Yap_HealthBar")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("SOSRY7C6PMFEVJP")]
[assembly: AssemblyProduct("Yap_HealthBar")]
[assembly: AssemblyCopyright("Copyright © SOSRY7C6PMFEVJP 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a68c9f38-c2a9-4751-bf01-26b7553b3db0")]
[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 Yap_HealthBar;

[BepInPlugin("com.xiaohai.yap_healthbar", "Yap Health Bar", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
	public static ManualLogSource Logger;

	internal static ConfigEntry<float> HealthBarExtraHeightOffset;

	private readonly Harmony _harmony = new Harmony("com.xiaohai.yap_healthbar");

	private void Awake()
	{
		Logger = ((BaseUnityPlugin)this).Logger;
		HealthBarExtraHeightOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Enemy Health Bar / 敌人血条", "ExtraHeightOffset / 增高偏移", 0.45f, "血条额外增高偏移:在自动高度计算完成后始终追加(单位:米)");
		_harmony.PatchAll();
		Logger.LogInfo((object)"Yap Health Bar MOD loaded successfully!");
	}
}
public class DamageText3D : MonoBehaviour
{
	private TextMeshPro textComponent;

	private float timer = 1.5f;

	private Vector3 baseWorldPosition;

	private float floatHeight;

	private void Awake()
	{
		textComponent = ((Component)this).GetComponent<TextMeshPro>();
	}

	private void Start()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: 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)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		baseWorldPosition = ((Component)this).transform.position;
		if ((Object)(object)Camera.main != (Object)null)
		{
			((Component)this).transform.rotation = Quaternion.LookRotation(((Component)this).transform.position - ((Component)Camera.main).transform.position);
		}
	}

	private void Update()
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: 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_0074: Unknown result type (might be due to invalid IL or missing references)
		floatHeight += Time.deltaTime * 0.8f;
		((Component)this).transform.position = baseWorldPosition + Vector3.up * floatHeight;
		if ((Object)(object)Camera.main != (Object)null)
		{
			((Component)this).transform.rotation = Quaternion.LookRotation(((Component)this).transform.position - ((Component)Camera.main).transform.position);
		}
		timer -= Time.deltaTime;
		if ((Object)(object)textComponent != (Object)null)
		{
			((TMP_Text)textComponent).alpha = Mathf.Clamp01(timer * 2f);
		}
		if (timer <= 0f)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
	}

	public void Setup(float time)
	{
		timer = time;
	}
}
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 TextMeshProUGUI healthText;

	private NpcHurtbox npcHurtbox;

	private NpcBehaviour npcBehaviour;

	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)
		{
			npcHurtbox = ((Component)this).GetComponent<NpcHurtbox>();
			if (!((Object)(object)npcHurtbox == (Object)null))
			{
				npcBehaviour = ((Component)this).GetComponent<NpcBehaviour>();
				followTransform = ResolveFollowTransform();
				mainCamera = Camera.main;
				InitializeCanvas();
				UpdateWorldOffsetFromBounds(force: true);
				UpdateCanvasWorldPosition();
				UpdateHealthDisplay();
				ResetTimer();
				_initialized = true;
			}
		}
	}

	private Transform ResolveFollowTransform()
	{
		if ((Object)(object)npcBehaviour != (Object)null)
		{
			if ((Object)(object)npcBehaviour.Rigidbody != (Object)null)
			{
				return ((Component)npcBehaviour.Rigidbody).transform;
			}
			if ((Object)(object)npcBehaviour.CameraTargetTransform != (Object)null)
			{
				return npcBehaviour.CameraTargetTransform;
			}
		}
		return ((Component)this).transform;
	}

	private static Sprite GetSharedWhiteSprite()
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: 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_00ac: 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("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);
		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_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: 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 : 0.55f);
			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)npcBehaviour != (Object)null)
		{
			return ((Component)npcBehaviour).transform;
		}
		return ((Component)this).transform;
	}

	private void UpdateCanvasWorldPosition()
	{
		//IL_002a: 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)
		//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_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_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: 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_005d: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: 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);
		Collider[] array = componentsInChildren;
		foreach (Collider val in array)
		{
			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);
		Renderer[] array2 = componentsInChildren2;
		foreach (Renderer val2 in array2)
		{
			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)
		//IL_00ed: 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);
		component.sizeDelta = new Vector2(100f, 20f);
	}

	private void UpdateHealthText()
	{
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)healthText != (Object)null && (Object)(object)npcHurtbox != (Object)null)
		{
			((TMP_Text)healthText).text = $"{npcHurtbox.Health}/{npcHurtbox.MaxHealth}";
			if ((float)npcHurtbox.Health / (float)npcHurtbox.MaxHealth < 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_024e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0258: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Unknown result type (might be due to invalid IL or missing references)
		//IL_0212: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: 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)npcHurtbox == (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 health = npcHurtbox.Health;
			int maxHealth = npcHurtbox.MaxHealth;
			if (maxHealth > 0 && (health != lastHealthCurrent || maxHealth != lastHealthMax))
			{
				lastHealthCurrent = health;
				lastHealthMax = maxHealth;
				targetFillAmount = Mathf.Clamp01((float)health / (float)maxHealth);
				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_0078: 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_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: 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);
			if ((Object)(object)healthText != (Object)null)
			{
				((TMP_Text)healthText).alpha = num2;
			}
		}
	}

	private void OnDestroy()
	{
		if ((Object)(object)canvas != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)canvas).gameObject);
		}
		canvas = null;
	}

	public void UpdateHealthDisplay()
	{
		if (!((Object)(object)npcHurtbox == (Object)null))
		{
			int maxHealth = npcHurtbox.MaxHealth;
			if (maxHealth > 0)
			{
				targetFillAmount = Mathf.Clamp01((float)npcHurtbox.Health / (float)maxHealth);
			}
			UpdateHealthText();
		}
	}
}
[HarmonyPatch]
public static class Patch
{
	private static readonly Dictionary<int, float> lastDamageTextTimeByEnemy = new Dictionary<int, float>();

	[HarmonyPatch(typeof(NpcHurtbox), "RpcOnHit")]
	[HarmonyPostfix]
	private static void OnHit(NpcHurtbox __instance, int damage, Vector3 forceDir)
	{
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: 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)
		//IL_00a6: 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_00c9: 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)
		if ((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;
			int damage2 = Mathf.Clamp(damage, 1, 9999);
			Vector3 position = ((Component)__instance).transform.position;
			NpcBehaviour component = ((Component)__instance).GetComponent<NpcBehaviour>();
			if ((Object)(object)component != (Object)null)
			{
				if ((Object)(object)component.Rigidbody != (Object)null)
				{
					position = ((Component)component.Rigidbody).transform.position;
				}
				else if ((Object)(object)component.CameraTargetTransform != (Object)null)
				{
					position = component.CameraTargetTransform.position;
				}
			}
			position += new Vector3(Random.Range(-0.5f, 0.5f), Random.Range(1f, 1.5f), Random.Range(-0.5f, 0.5f));
			CreateDamageText(position, damage2);
		}
		catch (Exception arg)
		{
			Plugin.Logger.LogError((object)$"Error in OnHit Patch: {arg}");
		}
	}

	private static void CreateDamageText(Vector3 position, int damage)
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Expected O, but got Unknown
		//IL_006c: 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)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("DamageText", new Type[2]
		{
			typeof(TextMeshPro),
			typeof(DamageText3D)
		});
		TextMeshPro component = val.GetComponent<TextMeshPro>();
		DamageText3D component2 = val.GetComponent<DamageText3D>();
		((TMP_Text)component).alignment = (TextAlignmentOptions)514;
		((TMP_Text)component).text = $"-{damage}";
		Color color = default(Color);
		float fontSize;
		float time;
		if (damage >= 50)
		{
			color = Color.red;
			fontSize = 6f;
			time = 3f;
		}
		else if (damage >= 25)
		{
			color = Color.yellow;
			fontSize = 5f;
			time = 2f;
		}
		else
		{
			((Color)(ref color))..ctor(1f, 0.5f, 0f);
			fontSize = 4f;
			time = 1.5f;
		}
		((Graphic)component).color = color;
		((TMP_Text)component).fontSize = fontSize;
		val.transform.position = position;
		component2.Setup(time);
	}
}