Decompiled source of BattleImprovements v1.0.2

plugins/battle_improve/BattleImprove.dll

Decompiled 21 hours ago
using 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.Versioning;
using System.Security;
using System.Security.Permissions;
using BattleImprove.Components;
using BattleImprove.Patcher.BattleFeedback;
using BattleImprove.Patcher.QOL;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PerfectRandom.Sulfur.Core;
using PerfectRandom.Sulfur.Core.DevTools;
using PerfectRandom.Sulfur.Core.Input;
using PerfectRandom.Sulfur.Core.Items;
using PerfectRandom.Sulfur.Core.Stats;
using PerfectRandom.Sulfur.Core.Units;
using PerfectRandom.Sulfur.Core.Weapons;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BattleImprove")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Battle Improvements")]
[assembly: AssemblyTitle("BattleImprove")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
public class DamageInfo : MonoBehaviour
{
	public TMP_Text tmpTotalDamage;

	public GameObject damageSourcePrefab;

	private int currentDamage;

	private GameObject damageParent;

	private GameObject firstMessage;

	private GameObject messageContainer;

	private float timer;

	private int totalDamage;

	private void Start()
	{
		damageParent = ((Component)((Component)this).gameObject.transform.Find("Total")).gameObject;
		damageParent.SetActive(false);
		totalDamage = 0;
		currentDamage = 0;
		timer = 10f;
		messageContainer = ((Component)((Component)this).gameObject.transform.Find("Detail")).gameObject;
	}

	private void Update()
	{
		UpdateDamage();
		timer += Time.deltaTime;
		if (timer > 5f)
		{
			damageParent.SetActive(false);
			timer = 0f;
			totalDamage = 0;
			currentDamage = 0;
		}
	}

	public void ShowDamageInfo(string type, int damage)
	{
		AddTotalDamage(damage);
		AddDamageSource(type, damage);
	}

	private void AddTotalDamage(int damage)
	{
		damageParent.SetActive(true);
		totalDamage += damage;
	}

	private void AddDamageSource(string type, int damage)
	{
		if ((Object)(object)firstMessage != (Object)null && (Object)(object)messageContainer != (Object)null)
		{
			DamageSource[] componentsInChildren = messageContainer.GetComponentsInChildren<DamageSource>();
			DamageSource[] array = componentsInChildren;
			foreach (DamageSource damageSource in array)
			{
				if (damageSource.damageType == type)
				{
					damageSource.damage += damage;
					damageSource.Reset();
					return;
				}
			}
		}
		firstMessage = Object.Instantiate<GameObject>(damageSourcePrefab, messageContainer.transform);
		firstMessage.transform.SetAsFirstSibling();
		firstMessage.GetComponent<DamageSource>().InitMessage(type, damage);
	}

	private void UpdateDamage()
	{
		if (currentDamage < totalDamage)
		{
			timer = 0f;
			int num = Mathf.Max(1, (totalDamage - currentDamage) / 10);
			currentDamage += num;
			tmpTotalDamage.text = currentDamage.ToString();
		}
	}
}
public class DamageSource : MonoBehaviour
{
	public string damageType;

	public int damage;

	public TMP_Text message;

	private float timer;

	public void Reset()
	{
		timer = 0f;
		message.text = damageType + " " + damage;
	}

	private void Start()
	{
		timer = 0f;
		message = ((Component)this).GetComponent<TMP_Text>();
	}

	private void Update()
	{
		timer += Time.deltaTime;
		if (timer > 5f)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
	}

	public void InitMessage(string type, int damage)
	{
		damageType = type;
		this.damage = damage;
		message.text = damageType + " " + damage;
		Reset();
	}
}
public class HitSoundEffect : MonoBehaviour
{
	public AudioClip[] hitClose;

	public AudioClip[] hitFar;

	public AudioClip[] hitCrit;

	public void PlayHitSound(Vector3 position, bool isCrit, bool isFar = false)
	{
		//IL_001b: 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_0043: Unknown result type (might be due to invalid IL or missing references)
		if (isCrit)
		{
			AudioSource.PlayClipAtPoint(hitCrit[Random.Range(0, hitCrit.Length)], position, 1f);
		}
		else if (isFar)
		{
			AudioSource.PlayClipAtPoint(hitFar[Random.Range(0, hitFar.Length)], position, 1f);
		}
		else
		{
			AudioSource.PlayClipAtPoint(hitClose[Random.Range(0, hitClose.Length)], position, 1f);
		}
	}
}
public class KillMessage : MonoBehaviour
{
	private struct KillMessageStruct
	{
		public string EnemyName;

		public string WeaponName;

		public string Exp;
	}

	public TMP_Text tmpEnemyName;

	public TMP_Text tmpWeaponName;

	public TMP_Text tmpExp;

	public AudioClip killSound;

	public AudioClip headShotKillSound;

	public AudioSource audioSource;

	public Animator killMessageAnim;

	private readonly Queue<KillMessageStruct> messageQueue = new Queue<KillMessageStruct>();

	private bool isShowing;

	private void Start()
	{
		isShowing = false;
	}

	private void Update()
	{
		if (messageQueue.Count != 0 && !isShowing)
		{
			ShowKIllMessage();
		}
	}

	public void AddKillMessage(string enemyName, string weaponName, string exp)
	{
		messageQueue.Enqueue(new KillMessageStruct
		{
			EnemyName = enemyName,
			WeaponName = weaponName,
			Exp = exp
		});
	}

	private void ShowKIllMessage()
	{
		KillMessageStruct killMessageStruct = messageQueue.Dequeue();
		tmpEnemyName.text = killMessageStruct.EnemyName;
		tmpWeaponName.text = killMessageStruct.WeaponName;
		tmpExp.text = killMessageStruct.Exp;
		((MonoBehaviour)this).StartCoroutine(Showing());
	}

	private IEnumerator Showing()
	{
		isShowing = true;
		killMessageAnim.SetTrigger("Pop");
		yield return (object)new WaitForEndOfFrame();
		Transform transform = ((Component)this).transform;
		LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)(object)((transform is RectTransform) ? transform : null));
		yield return (object)((messageQueue.Count > 1) ? new WaitForSeconds(0.8f) : new WaitForSeconds(1.5f));
		killMessageAnim.SetTrigger("Fade");
		yield return (object)new WaitForSeconds(0.3f);
		isShowing = false;
	}

	public void OnEnemyKill(bool isHeadShot)
	{
		audioSource.PlayOneShot(isHeadShot ? headShotKillSound : killSound, 0.5f);
	}
}
public class xCrossHair : MonoBehaviour
{
	public Animator crossHairAnim;

	public void StartTrigger(string type)
	{
		if (!(type == "Hit"))
		{
			if (type == "Kill")
			{
				KillTrigger();
			}
		}
		else
		{
			HitTrigger();
		}
	}

	private void HitTrigger()
	{
		crossHairAnim.SetTrigger("Hit");
	}

	private void KillTrigger()
	{
		crossHairAnim.SetTrigger("Kill");
	}
}
namespace BattleImprove
{
	public class Config
	{
		internal static ConfigEntry<bool> EnableHealthBar;

		internal static ConfigEntry<bool> EnableExpShare;

		internal static ConfigEntry<bool> EnableSoundFeedback;

		internal static ConfigEntry<bool> EnableDeadUnitCollision;

		internal static ConfigEntry<bool> EnableXCrossHair;

		internal static ConfigEntry<bool> EnableDamageMessage;

		internal static ConfigEntry<float> Proportion;

		public static void InitConifg(ConfigFile cfg)
		{
			ToggleConfigInit(cfg);
			ExpShareConfigInit(cfg);
		}

		private static void ToggleConfigInit(ConfigFile cfg)
		{
			EnableExpShare = cfg.Bind<bool>("Toggle/开关", "EnableExpShare", true, "Enable experience share/是否开启经验共享");
			EnableHealthBar = cfg.Bind<bool>("Toggle/开关", "EnableHealthBar", true, "Enable health bar/是否开启血条");
			EnableXCrossHair = cfg.Bind<bool>("Toggle/开关", "EnableHitFeedback", true, "Enable xCrossHair feedback/是否开启击中准心反馈");
			EnableSoundFeedback = cfg.Bind<bool>("Toggle/开关", "EnableSoundFeedback", true, "Enable hit sound feedback on enemies/是否开启敌人受击声音反馈");
			EnableDamageMessage = cfg.Bind<bool>("Toggle/开关", "EnableDamageMessage", true, "Enable damage and kill message/是否开启伤害与击杀信息");
			EnableDeadUnitCollision = cfg.Bind<bool>("Toggle/开关", "EnableDeadUnitCollision", true, "Enable bullet will bounce on deadbody/是否开启子弹会在尸体上反弹");
		}

		private static void ExpShareConfigInit(ConfigFile cfg)
		{
			Proportion = cfg.Bind<float>("ExpShare/经验共享", "Proportion", 0.5f, "The proportion of experience shared to second weapon/共享给第二把武器的经验比例");
		}
	}
	[BepInPlugin("BattleImprove", "Battle Improvements", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public class StaticInstance
		{
			internal static GameObject PluginInstance;

			internal static Npc[] Enemies;

			internal static List<Unit> KilledEnemies;

			internal static HitSoundEffect HitSoundClips;

			internal static xCrossHair CrossHair;

			internal static KillMessage KillMessage;

			internal static DamageInfo DamageInfo;

			[HarmonyPostfix]
			[HarmonyPriority(800)]
			[HarmonyPatch(typeof(GameManager), "Start")]
			private static void AddBattleImprove()
			{
				PluginInstance = Object.Instantiate<GameObject>(AssetBundle.LoadAsset<GameObject>("BattleImprove"));
				HitSoundClips = PluginInstance.GetComponentInChildren<HitSoundEffect>();
				CrossHair = PluginInstance.GetComponentInChildren<xCrossHair>();
				KillMessage = PluginInstance.GetComponentInChildren<KillMessage>();
				DamageInfo = PluginInstance.GetComponentInChildren<DamageInfo>();
			}

			[HarmonyPrefix]
			[HarmonyPriority(800)]
			[HarmonyPatch(typeof(InputReader), "LoadingContinue")]
			private static void AddFrame()
			{
				Enemies = StaticInstance<UnitManager>.Instance.GetAllEnemies();
				KilledEnemies = new List<Unit>();
			}
		}

		internal static ManualLogSource Logger;

		internal static AssetBundle AssetBundle;

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin BattleImprove is loading!");
			Config.InitConifg(((BaseUnityPlugin)this).Config);
			Patching();
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			AssetBundle = AssetBundle.LoadFromFile(Path.Combine(directoryName, "battle_improve"));
			if ((Object)(object)AssetBundle == (Object)null)
			{
				Logger.LogError((object)"Failed to load custom assets.");
			}
			else
			{
				Logger.LogInfo((object)"Plugin BattleImprove is loaded!");
			}
		}

		private void Patching()
		{
			Harmony.CreateAndPatchAll(typeof(StaticInstance), (string)null);
			if (Config.EnableExpShare.Value)
			{
				Harmony.CreateAndPatchAll(typeof(ExpSharePatch), (string)null);
			}
			if (Config.EnableHealthBar.Value)
			{
				Harmony.CreateAndPatchAll(typeof(HealthBarPatch), (string)null);
			}
			if (Config.EnableSoundFeedback.Value)
			{
				Harmony.CreateAndPatchAll(typeof(SoundPatch), (string)null);
			}
			if (Config.EnableDeadUnitCollision.Value)
			{
				Harmony.CreateAndPatchAll(typeof(DeadUnitCollisionPatch), (string)null);
			}
			Harmony.CreateAndPatchAll(typeof(AttackFeedbackPatch), (string)null);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "BattleImprove";

		public const string PLUGIN_NAME = "Battle Improvements";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace BattleImprove.Patcher.QOL
{
	[HarmonyPatch]
	public class DeadUnitCollisionPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(Projectile), "ReportBounceOnHitbox")]
		private static bool CheckPass(Projectile __instance, Hitbox hitbox)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			return (int)hitbox.GetOwner().UnitState == 2;
		}
	}
	public class ExpSharePatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(Npc), "GiveExperience")]
		private static void GiveExperiencePrePatch(Npc __instance)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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)
			Weapon lastUsedWeapon = StaticInstance<GameManager>.Instance.GetPlayerUnit().lastUsedWeapon;
			InventorySlot key = (InventorySlot)(((int)((Holdable)lastUsedWeapon).inventorySlot == 4) ? 5 : 4);
			Dictionary<InventorySlot, InventoryItem> equippedHoldables = ((Component)StaticInstance<GameManager>.Instance.GetPlayerUnit()).GetComponent<EquipmentManager>().EquippedHoldables;
			float num = ((Unit)__instance).ExperienceOnKill;
			float value = Config.Proportion.Value;
			if (equippedHoldables.ContainsKey(key))
			{
				equippedHoldables[key].AddExperience(num * value);
			}
		}
	}
	[HarmonyPatch]
	public class HealthBarPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(UnitDebugFrame), "Update")]
		private static bool UpdateHPBar(UnitDebugFrame __instance)
		{
			if (StaticInstance<DevToolsManager>.Instance.shouldShow)
			{
				return true;
			}
			((Component)__instance).transform.LookAt(((Component)StaticInstance<GameManager>.Instance.currentCamera).transform);
			HealthBar component = ((Component)__instance.owner).GetComponent<HealthBar>();
			if (component.UpdateValue())
			{
				Traverse.Create((object)__instance).Method("UpdateValues", Array.Empty<object>()).GetValue();
			}
			if (__instance.owner.IsAlive)
			{
				return false;
			}
			((Behaviour)component).enabled = false;
			((Component)__instance).gameObject.SetActive(false);
			return false;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Npc), "Start")]
		private static void AddDebugFrame(Player __instance)
		{
			((Component)__instance).gameObject.AddComponent<HealthBar>();
		}
	}
}
namespace BattleImprove.Patcher.BattleFeedback
{
	[HarmonyPatch]
	public class AttackFeedbackPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(Hitbox), "TakeHit")]
		private static void AddDamageMessage(Hitbox __instance, out float __state)
		{
			__state = __instance.Owner.GetCurrentHealth();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Hitbox), "TakeHit")]
		private static void AttackFeedback(Hitbox __instance, DamageType damageType, IDamager source, Vector3 collisionPoint, float __state)
		{
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: 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)
			if (!source.SourceUnit.isPlayer || __instance.Owner is Breakable || __instance.Owner.isPlayer || PlayHitAnimation(__instance.Owner) || !Config.EnableDamageMessage.Value)
			{
				return;
			}
			float num = __state - __instance.Owner.GetCurrentHealth();
			if (num > 0f)
			{
				string text = "";
				if (source.SourceWeapon.IsMelee)
				{
					text += ((ItemDefinition)source.SourceWeapon.weaponDefinition).displayName;
				}
				else
				{
					string[] obj = new string[6]
					{
						text,
						damageType.shortLabel,
						" ",
						source.SourceProjectile.CurrentCaliber.label,
						" ",
						null
					};
					ProjectileTypes projectileType = source.SourceProjectile.projectileType;
					obj[5] = ((object)(ProjectileTypes)(ref projectileType)).ToString();
					text = string.Concat(obj);
				}
				Plugin.StaticInstance.DamageInfo.ShowDamageInfo(text, Convert.ToInt32(num));
			}
			if (!IsDead(__instance.Owner))
			{
				PlayKillAudio(__instance, source.SourceWeapon, collisionPoint);
				ShowKillMessage(__instance.Owner, source.SourceWeapon);
			}
		}

		private static bool PlayHitAnimation(Unit unit)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: 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)
			//IL_000c: Invalid comparison between Unknown and I4
			UnitState unitState = unit.UnitState;
			bool flag = unitState - 1 <= 1;
			bool flag2 = flag;
			bool value = Config.EnableXCrossHair.Value;
			if (value && flag2)
			{
				Plugin.StaticInstance.CrossHair.StartTrigger("Hit");
			}
			return flag2;
		}

		private static void PlayKillAudio(Hitbox hitbox, Weapon weapon, Vector3 collisionPoint)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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)
			//IL_0022: Invalid comparison between Unknown and I4
			float num = Vector3.Distance(StaticInstance<GameManager>.Instance.GetPlayerUnit().EyesPosition, collisionPoint);
			HoldableWeightClass holdableWeightClass = ((Holdable)weapon).holdableWeightClass;
			bool flag = holdableWeightClass - 3 <= 1;
			bool flag2 = flag;
			if (num > 20f && flag2)
			{
				Plugin.StaticInstance.KillMessage.OnEnemyKill(hitbox.bodyPart.label == "Head");
			}
			else
			{
				Plugin.StaticInstance.KillMessage.OnEnemyKill(isHeadShot: false);
			}
		}

		private static void ShowKillMessage(Unit enemy, Weapon weapon)
		{
			string sourceName = enemy.SourceName;
			string displayName = ((ItemDefinition)weapon.weaponDefinition).displayName;
			string exp = Convert.ToString(enemy.ExperienceOnKill);
			Plugin.StaticInstance.KillMessage.AddKillMessage(sourceName, displayName, exp);
		}

		private static bool IsDead(Unit unit)
		{
			if (Plugin.StaticInstance.KilledEnemies.Contains(unit))
			{
				return true;
			}
			Plugin.StaticInstance.KilledEnemies.Add(unit);
			if (Config.EnableXCrossHair.Value)
			{
				Plugin.StaticInstance.CrossHair.StartTrigger("Kill");
			}
			return false;
		}
	}
	[HarmonyPatch]
	public class SoundPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(Hitbox), "TakeHit")]
		private static void PlayHitSound(Hitbox __instance, DamageType damageType, IDamager source, Vector3 collisionPoint)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Invalid comparison between Unknown and I4
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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_0088: Invalid comparison between Unknown and I4
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.Owner is Breakable || __instance.Owner.isPlayer)
			{
				return;
			}
			Npc component = ((Component)__instance.GetOwner()).gameObject.GetComponent<Npc>();
			if ((int)((Unit)component).UnitState == 0 || !Plugin.StaticInstance.Enemies.Contains(component))
			{
				return;
			}
			float num = Vector3.Distance(StaticInstance<GameManager>.Instance.GetPlayerUnit().EyesPosition, ((Component)component).transform.position);
			if ((int)damageType.id == 1 || __instance.bodyPart.label == "Head")
			{
				Plugin.StaticInstance.HitSoundClips.PlayHitSound(collisionPoint, isCrit: true);
				return;
			}
			GameObject player = StaticInstance<GameManager>.Instance.GetPlayer();
			Vector3 val = Vector3.Normalize(collisionPoint - player.transform.position);
			val = player.transform.position + val * 3f;
			if (num < 20f)
			{
				Plugin.StaticInstance.HitSoundClips.PlayHitSound(val, isCrit: false);
			}
			else
			{
				Plugin.StaticInstance.HitSoundClips.PlayHitSound(val, isCrit: false, isFar: true);
			}
		}
	}
}
namespace BattleImprove.Components
{
	public class HealthBar : MonoBehaviour
	{
		private Camera camera;

		private bool isInitialized;

		private Npc npc;

		private float timer;

		private void Start()
		{
			npc = ((Component)this).gameObject.GetComponent<Npc>();
			if (((Unit)npc).IsProtectedNpc)
			{
				Object.Destroy((Object)(object)this);
				return;
			}
			isInitialized = false;
			((MonoBehaviour)this).StartCoroutine(Initialize());
		}

		private void Update()
		{
			//IL_0026: 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)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if (isInitialized && ((Unit)npc).IsAlive)
			{
				Vector3 eyesPosition = ((Unit)npc).EyesPosition;
				timer += Time.deltaTime;
				((Component)((Unit)npc).debugFrame).gameObject.SetActive(CheckVisible(eyesPosition));
			}
		}

		private IEnumerator Initialize()
		{
			yield return (object)new WaitForSeconds(3f);
			StaticInstance<DevToolsManager>.Instance.AddDebugFrameToUnit((Unit)(object)npc);
			camera = StaticInstance<GameManager>.Instance.currentCamera;
			isInitialized = true;
		}

		private bool CheckVisible(Vector3 position)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Vector3 val = camera.WorldToViewportPoint(position);
				int result;
				if (val.z > 0f)
				{
					float x = val.x;
					if (x > 0f && x < 1f)
					{
						float y = val.y;
						if (y > 0f && y < 1f)
						{
							result = ((Vector3.Distance(position, ((Component)camera).transform.position) < 15f) ? 1 : 0);
							goto IL_006a;
						}
					}
				}
				result = 0;
				goto IL_006a;
				IL_006a:
				return (byte)result != 0;
			}
			catch
			{
				Plugin.Logger.LogInfo((object)"Player camera lost, trying to find it again");
				camera = StaticInstance<GameManager>.Instance.currentCamera;
				StaticInstance<DevToolsManager>.Instance.AddDebugFrameToUnit((Unit)(object)npc);
			}
			return false;
		}

		public bool UpdateValue()
		{
			if (!(timer > 0.25f))
			{
				return false;
			}
			timer = 0f;
			return true;
		}
	}
}