Decompiled source of FusionHealthBars v1.2.2

Mods/FusionHealthBars.dll

Decompiled 2 hours 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 BoneLib;
using BoneLib.BoneMenu;
using FusionHpDisplay;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Marrow;
using LabFusion.Entities;
using LabFusion.Network;
using LabFusion.Player;
using MelonLoader;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Main), "FusionHpDisplay", "1.2.0", "Moris", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: AssemblyTitle("FusionHealthBars")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FusionHealthBars")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("58607be7-5b2b-4a2d-aca0-8c74c5993bfc")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace FusionHpDisplay;

public enum HudPosition
{
	Left,
	Right
}
public class Main : MelonMod
{
	private const string MetadataHpKey = "FusionHpDisplay.HP";

	private bool _isEnabled = true;

	private bool _selfHudEnabled = true;

	private bool _unlimitedViewAngle = false;

	private HudPosition _hudPosition = HudPosition.Left;

	private readonly Dictionary<byte, PixelTextDisplay> _indicators = new Dictionary<byte, PixelTextDisplay>();

	private readonly HashSet<byte> _activePlayers = new HashSet<byte>();

	private readonly List<byte> _stalePlayers = new List<byte>();

	private PixelTextDisplay _selfHud;

	private PixelFontAtlas _fontAtlas;

	private MemberInfo _nameTagMember;

	private PropertyInfo _nameTagGoProp;

	private PropertyInfo _metadataProp;

	private MethodInfo _trySetMetadataMethod;

	private MethodInfo _tryGetMetadataMethod;

	private int _lastBroadcastPercent = -1;

	private float _lastBroadcastTime = 0f;

	public override void OnInitializeMelon()
	{
		CacheReflection();
		SetupBoneMenu();
		((MelonBase)this).LoggerInstance.Msg("FusionHpDisplay v1.2.0 initialized!");
	}

	private void CacheReflection()
	{
		BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
		PropertyInfo[] properties = typeof(NetworkPlayer).GetProperties(bindingAttr);
		for (int i = 0; i < properties.Length; i++)
		{
			if (properties[i].Name.IndexOf("nametag", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				_nameTagMember = properties[i];
				_nameTagGoProp = properties[i].PropertyType.GetProperty("GameObject", bindingAttr) ?? properties[i].PropertyType.GetProperty("gameObject", bindingAttr);
				break;
			}
		}
		if (_nameTagMember == null)
		{
			FieldInfo[] fields = typeof(NetworkPlayer).GetFields(bindingAttr);
			for (int j = 0; j < fields.Length; j++)
			{
				if (fields[j].Name.IndexOf("nametag", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					_nameTagMember = fields[j];
					_nameTagGoProp = fields[j].FieldType.GetProperty("GameObject", bindingAttr) ?? fields[j].FieldType.GetProperty("gameObject", bindingAttr);
					break;
				}
			}
		}
		_metadataProp = typeof(PlayerID).GetProperty("Metadata", bindingAttr);
		if (_metadataProp != null)
		{
			Type propertyType = _metadataProp.PropertyType;
			_trySetMetadataMethod = propertyType.GetMethod("TrySetMetadata", bindingAttr, null, new Type[2]
			{
				typeof(string),
				typeof(string)
			}, null) ?? propertyType.GetMethod("SetMetadata", bindingAttr, null, new Type[2]
			{
				typeof(string),
				typeof(string)
			}, null);
			_tryGetMetadataMethod = propertyType.GetMethod("TryGetMetadata", bindingAttr, null, new Type[2]
			{
				typeof(string),
				typeof(string).MakeByRefType()
			}, null);
		}
	}

	private void SetupBoneMenu()
	{
		//IL_000b: 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_003c: 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_0078: Unknown result type (might be due to invalid IL or missing references)
		Page val = Page.Root.CreatePage("Fusion HP", Color.cyan, 0, true);
		val.CreateBool("Enabled", Color.white, true, (Action<bool>)delegate(bool isEnabled)
		{
			_isEnabled = isEnabled;
			if (!_isEnabled)
			{
				HideAllIndicators();
				SetSelfHudVisible(visible: false);
			}
		});
		val.CreateBool("Unlimited View Angle", Color.white, false, (Action<bool>)delegate(bool unlimitedViewAngle)
		{
			_unlimitedViewAngle = unlimitedViewAngle;
		});
		val.CreateBool("Self VR HUD", Color.white, true, (Action<bool>)delegate(bool selfHudEnabled)
		{
			_selfHudEnabled = selfHudEnabled;
			if (!_selfHudEnabled)
			{
				SetSelfHudVisible(visible: false);
			}
		});
		val.CreateEnum("Self HP position", Color.white, (Enum)_hudPosition, (Action<Enum>)delegate(Enum obj)
		{
			_hudPosition = (HudPosition)(object)obj;
		});
	}

	public override void OnSceneWasUnloaded(int buildIndex, string sceneName)
	{
		ClearAllIndicators();
		DestroySelfHud();
		_lastBroadcastPercent = -1;
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		ClearAllIndicators();
		DestroySelfHud();
		_lastBroadcastPercent = -1;
	}

	public override void OnUpdate()
	{
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: 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_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_023f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0201: Unknown result type (might be due to invalid IL or missing references)
		//IL_0251: Unknown result type (might be due to invalid IL or missing references)
		//IL_0256: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0301: Unknown result type (might be due to invalid IL or missing references)
		//IL_0306: Unknown result type (might be due to invalid IL or missing references)
		//IL_030b: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (!_isEnabled || (Object)(object)Player.Head == (Object)null || PlayerIDManager.PlayerIDs == null)
			{
				HideAllIndicators();
				return;
			}
			if (LobbyInfoManager.LobbyInfo != null && !LobbyInfoManager.LobbyInfo.NameTags)
			{
				HideAllIndicators();
				return;
			}
			_activePlayers.Clear();
			Transform head = Player.Head;
			NetworkPlayer val = default(NetworkPlayer);
			foreach (PlayerID playerID in PlayerIDManager.PlayerIDs)
			{
				if (playerID == null || playerID.IsMe || !NetworkPlayerManager.TryGetPlayer(PlayerID.op_Implicit(playerID), ref val) || val == null)
				{
					continue;
				}
				byte smallID = playerID.SmallID;
				_activePlayers.Add(smallID);
				if (!val.HasRig || val.RigRefs == null || (Object)(object)val.RigRefs.RigManager == (Object)null || (Object)(object)val.RigRefs.Head == (Object)null)
				{
					SetIndicatorVisible(smallID, visible: false);
					continue;
				}
				if (!IsPlayerNameTagVisible(val))
				{
					SetIndicatorVisible(smallID, visible: false);
					continue;
				}
				Transform head2 = val.RigRefs.Head;
				Vector3 position = head2.position;
				Vector3 val2 = position - Vector3.up * 0.45f;
				Vector3 p = position - Vector3.up * 0.85f;
				Vector3 p2 = position - Vector3.up * 1.25f;
				float num = Vector3.Distance(head.position, val2);
				if (num > 35f || num < 0.2f)
				{
					SetIndicatorVisible(smallID, visible: false);
					continue;
				}
				if (!_unlimitedViewAngle)
				{
					float minBodyAngle = GetMinBodyAngle(head, position, val2, p, p2);
					if (minBodyAngle > 28f)
					{
						SetIndicatorVisible(smallID, visible: false);
						continue;
					}
				}
				Transform transform = ((Component)val.RigRefs.RigManager).transform;
				if (IsObstructed(head.position, position, transform) && IsObstructed(head.position, val2, transform))
				{
					SetIndicatorVisible(smallID, visible: false);
					continue;
				}
				int remotePlayerHealthPercent = GetRemotePlayerHealthPercent(playerID, val);
				if (remotePlayerHealthPercent < 0)
				{
					SetIndicatorVisible(smallID, visible: false);
					continue;
				}
				PixelTextDisplay orCreateIndicator = GetOrCreateIndicator(smallID);
				orCreateIndicator.SetText($"{remotePlayerHealthPercent}%", GetHealthColor(remotePlayerHealthPercent), (TextAlignment)1);
				Transform transform2 = orCreateIndicator.Transform;
				transform2.position = head2.position + Vector3.up * 0.52f;
				transform2.rotation = Quaternion.LookRotation(transform2.position - head.position);
				orCreateIndicator.SetVisible(visible: true);
			}
			CleanupDisconnectedPlayers();
		}
		catch (Exception)
		{
		}
	}

	private float GetMinBodyAngle(Transform localHead, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3)
	{
		//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_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_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: 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_0028: 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_002e: 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_003d: 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_0040: 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)
		//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)
		//IL_0057: 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_005a: 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_0063: Unknown result type (might be due to invalid IL or missing references)
		Vector3 position = localHead.position;
		Vector3 forward = localHead.forward;
		Vector3 val = p0 - position;
		float num = Vector3.Angle(forward, ((Vector3)(ref val)).normalized);
		val = p1 - position;
		float num2 = Vector3.Angle(forward, ((Vector3)(ref val)).normalized);
		val = p2 - position;
		float num3 = Vector3.Angle(forward, ((Vector3)(ref val)).normalized);
		val = p3 - position;
		float num4 = Vector3.Angle(forward, ((Vector3)(ref val)).normalized);
		float num5 = ((num < num2) ? num : num2);
		if (num3 < num5)
		{
			num5 = num3;
		}
		if (num4 < num5)
		{
			num5 = num4;
		}
		return num5;
	}

	private int GetRemotePlayerHealthPercent(PlayerID playerId, NetworkPlayer netPlayer)
	{
		if (_metadataProp != null && _tryGetMetadataMethod != null)
		{
			try
			{
				object value = _metadataProp.GetValue(playerId);
				if (value != null)
				{
					object[] array = new object[2] { "FusionHpDisplay.HP", null };
					if ((bool)_tryGetMetadataMethod.Invoke(value, array) && array[1] is string s && int.TryParse(s, out var result))
					{
						return Mathf.Clamp(result, 0, 999);
					}
				}
			}
			catch (Exception)
			{
			}
		}
		Health health = netPlayer.RigRefs.RigManager.health;
		if ((Object)(object)health == (Object)null)
		{
			return -1;
		}
		float num = ((health.max_Health > 0f) ? health.max_Health : 100f);
		return Mathf.Clamp(Mathf.CeilToInt(health.curr_Health / num * 100f), 0, 999);
	}

	private PlayerID GetLocalPlayerID()
	{
		if (PlayerIDManager.PlayerIDs == null)
		{
			return null;
		}
		foreach (PlayerID playerID in PlayerIDManager.PlayerIDs)
		{
			if (playerID != null && playerID.IsMe)
			{
				return playerID;
			}
		}
		return null;
	}

	private void BroadcastLocalHealth(int percent)
	{
		if (_metadataProp == null || _trySetMetadataMethod == null)
		{
			return;
		}
		float unscaledTime = Time.unscaledTime;
		if ((percent == _lastBroadcastPercent && unscaledTime - _lastBroadcastTime < 2f) || unscaledTime - _lastBroadcastTime < 0.15f)
		{
			return;
		}
		try
		{
			PlayerID localPlayerID = GetLocalPlayerID();
			if (localPlayerID != null)
			{
				object value = _metadataProp.GetValue(localPlayerID);
				if (value != null)
				{
					_trySetMetadataMethod.Invoke(value, new object[2]
					{
						"FusionHpDisplay.HP",
						percent.ToString()
					});
					_lastBroadcastPercent = percent;
					_lastBroadcastTime = unscaledTime;
				}
			}
		}
		catch (Exception)
		{
		}
	}

	private bool IsPlayerNameTagVisible(NetworkPlayer netPlayer)
	{
		if (_nameTagMember == null)
		{
			return true;
		}
		object obj = ((_nameTagMember is PropertyInfo propertyInfo) ? propertyInfo.GetValue(netPlayer) : ((FieldInfo)_nameTagMember).GetValue(netPlayer));
		if (obj == null)
		{
			return true;
		}
		GameObject val = (GameObject)((obj is GameObject) ? obj : null);
		if (val != null)
		{
			return (Object)(object)val != (Object)null && val.activeInHierarchy;
		}
		Component val2 = (Component)((obj is Component) ? obj : null);
		if (val2 != null)
		{
			return (Object)(object)val2 != (Object)null && (Object)(object)val2.gameObject != (Object)null && val2.gameObject.activeInHierarchy;
		}
		if (_nameTagGoProp != null)
		{
			object? value = _nameTagGoProp.GetValue(obj);
			GameObject val3 = (GameObject)((value is GameObject) ? value : null);
			if ((Object)(object)val3 != (Object)null)
			{
				return val3.activeInHierarchy;
			}
		}
		return true;
	}

	public override void OnLateUpdate()
	{
		//IL_00de: 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_0127: 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)
		try
		{
			if ((Object)(object)Player.RigManager == (Object)null)
			{
				SetSelfHudVisible(visible: false);
				return;
			}
			Health health = Player.RigManager.health;
			if ((Object)(object)health == (Object)null)
			{
				SetSelfHudVisible(visible: false);
				return;
			}
			float num = ((health.max_Health > 0f) ? health.max_Health : 100f);
			int num2 = Mathf.Clamp(Mathf.CeilToInt(health.curr_Health / num * 100f), 0, 999);
			BroadcastLocalHealth(num2);
			if (!_isEnabled || !_selfHudEnabled || (Object)(object)Player.Head == (Object)null)
			{
				SetSelfHudVisible(visible: false);
				return;
			}
			PixelTextDisplay orCreateSelfHud = GetOrCreateSelfHud();
			bool flag = _hudPosition == HudPosition.Right;
			orCreateSelfHud.SetText($"HP {num2}%", Color.white, (TextAlignment)(flag ? 2 : 0));
			Transform head = Player.Head;
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(flag ? 0.165f : (-0.165f), -0.115f, 0.45f);
			Transform transform = orCreateSelfHud.Transform;
			transform.position = head.TransformPoint(val);
			transform.rotation = head.rotation;
			orCreateSelfHud.SetVisible(visible: true);
		}
		catch (Exception)
		{
		}
	}

	private PixelFontAtlas GetFontAtlas()
	{
		if (_fontAtlas == null || !_fontAtlas.IsValid)
		{
			_fontAtlas = new PixelFontAtlas();
		}
		return _fontAtlas;
	}

	private PixelTextDisplay GetOrCreateSelfHud()
	{
		if (_selfHud == null || _selfHud.IsDestroyed)
		{
			_selfHud = new PixelTextDisplay("FusionSelfHpHud", GetFontAtlas(), 0.0014f);
		}
		return _selfHud;
	}

	private void SetSelfHudVisible(bool visible)
	{
		if (_selfHud != null && !_selfHud.IsDestroyed)
		{
			_selfHud.SetVisible(visible);
		}
	}

	private void DestroySelfHud()
	{
		if (_selfHud != null)
		{
			_selfHud.Destroy();
			_selfHud = null;
		}
	}

	private bool IsObstructed(Vector3 origin, Vector3 target, Transform targetRoot)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//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_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = target - origin;
		float magnitude = ((Vector3)(ref val)).magnitude;
		RaycastHit val2 = default(RaycastHit);
		if (Physics.Raycast(origin, ((Vector3)(ref val)).normalized, ref val2, magnitude, -1, (QueryTriggerInteraction)1))
		{
			if ((Object)(object)((RaycastHit)(ref val2)).transform == (Object)null)
			{
				return false;
			}
			if (((RaycastHit)(ref val2)).transform.IsChildOf(targetRoot))
			{
				return false;
			}
			if ((Object)(object)Player.RigManager != (Object)null && ((RaycastHit)(ref val2)).transform.IsChildOf(((Component)Player.RigManager).transform))
			{
				return false;
			}
			return true;
		}
		return false;
	}

	private Color GetHealthColor(int percent)
	{
		//IL_000a: 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_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_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)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		if (percent > 60)
		{
			return Color.green;
		}
		if (percent > 25)
		{
			return Color.yellow;
		}
		return Color.red;
	}

	private PixelTextDisplay GetOrCreateIndicator(byte playerId)
	{
		if (_indicators.TryGetValue(playerId, out var value) && value != null && !value.IsDestroyed)
		{
			return value;
		}
		PixelTextDisplay pixelTextDisplay = new PixelTextDisplay($"FusionHpIndicator_{playerId}", GetFontAtlas(), 0.017f);
		_indicators[playerId] = pixelTextDisplay;
		return pixelTextDisplay;
	}

	private void SetIndicatorVisible(byte playerId, bool visible)
	{
		if (_indicators.TryGetValue(playerId, out var value) && value != null && !value.IsDestroyed)
		{
			value.SetVisible(visible);
		}
	}

	private void HideAllIndicators()
	{
		foreach (KeyValuePair<byte, PixelTextDisplay> indicator in _indicators)
		{
			if (indicator.Value != null && !indicator.Value.IsDestroyed)
			{
				indicator.Value.SetVisible(visible: false);
			}
		}
	}

	private void CleanupDisconnectedPlayers()
	{
		_stalePlayers.Clear();
		foreach (KeyValuePair<byte, PixelTextDisplay> indicator in _indicators)
		{
			if (!_activePlayers.Contains(indicator.Key))
			{
				if (indicator.Value != null)
				{
					indicator.Value.Destroy();
				}
				_stalePlayers.Add(indicator.Key);
			}
		}
		for (int i = 0; i < _stalePlayers.Count; i++)
		{
			_indicators.Remove(_stalePlayers[i]);
		}
	}

	private void ClearAllIndicators()
	{
		foreach (KeyValuePair<byte, PixelTextDisplay> indicator in _indicators)
		{
			if (indicator.Value != null)
			{
				indicator.Value.Destroy();
			}
		}
		_indicators.Clear();
	}
}
internal class PixelFontAtlas
{
	public readonly Texture2D Texture;

	public readonly Material Material;

	public readonly Dictionary<char, Rect> Uvs = new Dictionary<char, Rect>();

	public const int GlyphWidth = 5;

	public const int GlyphHeight = 7;

	public bool IsValid => (Object)(object)Material != (Object)null && (Object)(object)Texture != (Object)null && (Object)(object)Material.mainTexture != (Object)null;

	public PixelFontAtlas()
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Expected O, but got Unknown
		//IL_0088: 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_0596: Unknown result type (might be due to invalid IL or missing references)
		//IL_05fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0608: Expected O, but got Unknown
		//IL_0620: Unknown result type (might be due to invalid IL or missing references)
		//IL_052b: Unknown result type (might be due to invalid IL or missing references)
		//IL_052d: Unknown result type (might be due to invalid IL or missing references)
		int num = 128;
		int num2 = 32;
		Texture = new Texture2D(num, num2, (TextureFormat)4, false);
		((Texture)Texture).filterMode = (FilterMode)0;
		((Texture)Texture).wrapMode = (TextureWrapMode)1;
		((Object)Texture).hideFlags = (HideFlags)32;
		Object.DontDestroyOnLoad((Object)(object)Texture);
		Color32[] array = (Color32[])(object)new Color32[num * num2];
		Color32 val = default(Color32);
		((Color32)(ref val))..ctor(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)0);
		for (int i = 0; i < array.Length; i++)
		{
			array[i] = val;
		}
		Texture.SetPixels32(Il2CppStructArray<Color32>.op_Implicit(array));
		Dictionary<char, string[]> dictionary = new Dictionary<char, string[]>
		{
			{
				'0',
				new string[7] { "01110", "10001", "10011", "10101", "11001", "10001", "01110" }
			},
			{
				'1',
				new string[7] { "00100", "01100", "00100", "00100", "00100", "00100", "01110" }
			},
			{
				'2',
				new string[7] { "01110", "10001", "00001", "00110", "01000", "10000", "11111" }
			},
			{
				'3',
				new string[7] { "11110", "00001", "00001", "01110", "00001", "00001", "11110" }
			},
			{
				'4',
				new string[7] { "00010", "00110", "01010", "10010", "11111", "00010", "00010" }
			},
			{
				'5',
				new string[7] { "11111", "10000", "11110", "00001", "00001", "10001", "01110" }
			},
			{
				'6',
				new string[7] { "01110", "10000", "11110", "10001", "10001", "10001", "01110" }
			},
			{
				'7',
				new string[7] { "11111", "00001", "00010", "00100", "01000", "01000", "01000" }
			},
			{
				'8',
				new string[7] { "01110", "10001", "10001", "01110", "10001", "10001", "01110" }
			},
			{
				'9',
				new string[7] { "01110", "10001", "10001", "01111", "00001", "00010", "01100" }
			},
			{
				'H',
				new string[7] { "10001", "10001", "10001", "11111", "10001", "10001", "10001" }
			},
			{
				'P',
				new string[7] { "11110", "10001", "10001", "11110", "10000", "10000", "10000" }
			},
			{
				'%',
				new string[7] { "11001", "11010", "00010", "00100", "01000", "01011", "10011" }
			},
			{
				' ',
				new string[7] { "00000", "00000", "00000", "00000", "00000", "00000", "00000" }
			}
		};
		Color32 val2 = default(Color32);
		((Color32)(ref val2))..ctor(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
		int num3 = 2;
		int num4 = 4;
		foreach (KeyValuePair<char, string[]> item in dictionary)
		{
			string[] value = item.Value;
			for (int j = 0; j < 7; j++)
			{
				string text = value[j];
				for (int k = 0; k < 5; k++)
				{
					if (text[k] == '1')
					{
						Texture.SetPixel(num3 + k, num4 + (6 - j), Color32.op_Implicit(val2));
					}
				}
			}
			float num5 = (float)num3 / (float)num;
			float num6 = (float)num4 / (float)num2;
			float num7 = 5f / (float)num;
			float num8 = 7f / (float)num2;
			Uvs[item.Key] = new Rect(num5, num6, num7, num8);
			num3 += 7;
		}
		Texture.Apply(false, false);
		Shader val3 = Shader.Find("GUI/Text Shader") ?? Shader.Find("Sprites/Default") ?? Shader.Find("Unlit/Transparent");
		Material = new Material(val3);
		Material.mainTexture = (Texture)(object)Texture;
		Material.color = Color.white;
		((Object)Material).hideFlags = (HideFlags)32;
		Object.DontDestroyOnLoad((Object)(object)Material);
	}
}
internal class PixelTextDisplay
{
	private readonly GameObject _gameObject;

	private readonly Mesh _mesh;

	private readonly PixelFontAtlas _atlas;

	private readonly float _pixelSize;

	private string _lastText = string.Empty;

	private Color _lastColor = Color.clear;

	private TextAlignment _lastAlignment = (TextAlignment)(-1);

	public Transform Transform => _gameObject.transform;

	public bool IsDestroyed => (Object)(object)_gameObject == (Object)null;

	public PixelTextDisplay(string name, PixelFontAtlas atlas, float pixelSize)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: 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_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Expected O, but got Unknown
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Expected O, but got Unknown
		_atlas = atlas;
		_pixelSize = pixelSize;
		_gameObject = new GameObject(name);
		Object.DontDestroyOnLoad((Object)(object)_gameObject);
		MeshFilter val = _gameObject.AddComponent<MeshFilter>();
		MeshRenderer val2 = _gameObject.AddComponent<MeshRenderer>();
		((Renderer)val2).sharedMaterial = _atlas.Material;
		_mesh = new Mesh();
		((Object)_mesh).hideFlags = (HideFlags)32;
		Object.DontDestroyOnLoad((Object)(object)_mesh);
		val.sharedMesh = _mesh;
	}

	public void SetVisible(bool visible)
	{
		if ((Object)(object)_gameObject != (Object)null && _gameObject.activeSelf != visible)
		{
			_gameObject.SetActive(visible);
		}
	}

	public void SetText(string text, Color color, TextAlignment alignment)
	{
		//IL_0026: 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_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: 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_005a: 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_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Invalid comparison between Unknown and I4
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Invalid comparison between Unknown and I4
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: 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)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: 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_01ea: 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_0208: Unknown result type (might be due to invalid IL or missing references)
		//IL_020d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0226: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_025e: Unknown result type (might be due to invalid IL or missing references)
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_026a: Unknown result type (might be due to invalid IL or missing references)
		//IL_026b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0276: Unknown result type (might be due to invalid IL or missing references)
		//IL_0277: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_gameObject == (Object)null || (text == _lastText && color == _lastColor && alignment == _lastAlignment))
		{
			return;
		}
		_lastText = text;
		_lastColor = color;
		_lastAlignment = alignment;
		int length = text.Length;
		if (length == 0)
		{
			_mesh.Clear();
			return;
		}
		float num = 6f * _pixelSize;
		float num2 = 5f * _pixelSize;
		float num3 = 7f * _pixelSize;
		float num4 = (float)length * num - _pixelSize;
		float num5 = 0f;
		if ((int)alignment == 1)
		{
			num5 = (0f - num4) * 0.5f;
		}
		else if ((int)alignment == 2)
		{
			num5 = 0f - num4;
		}
		Vector3[] array = (Vector3[])(object)new Vector3[length * 4];
		Vector2[] array2 = (Vector2[])(object)new Vector2[length * 4];
		Color[] array3 = (Color[])(object)new Color[length * 4];
		int[] array4 = new int[length * 6];
		for (int i = 0; i < length; i++)
		{
			char key = text[i];
			if (!_atlas.Uvs.TryGetValue(key, out var value))
			{
				value = _atlas.Uvs[' '];
			}
			float num6 = num5 + (float)i * num;
			float num7 = num6 + num2;
			float num8 = 0f;
			float num9 = num3;
			int num10 = i * 4;
			array[num10] = new Vector3(num6, num8, 0f);
			array[num10 + 1] = new Vector3(num6, num9, 0f);
			array[num10 + 2] = new Vector3(num7, num9, 0f);
			array[num10 + 3] = new Vector3(num7, num8, 0f);
			array2[num10] = new Vector2(((Rect)(ref value)).xMin, ((Rect)(ref value)).yMin);
			array2[num10 + 1] = new Vector2(((Rect)(ref value)).xMin, ((Rect)(ref value)).yMax);
			array2[num10 + 2] = new Vector2(((Rect)(ref value)).xMax, ((Rect)(ref value)).yMax);
			array2[num10 + 3] = new Vector2(((Rect)(ref value)).xMax, ((Rect)(ref value)).yMin);
			array3[num10] = color;
			array3[num10 + 1] = color;
			array3[num10 + 2] = color;
			array3[num10 + 3] = color;
			int num11 = i * 6;
			array4[num11] = num10;
			array4[num11 + 1] = num10 + 1;
			array4[num11 + 2] = num10 + 2;
			array4[num11 + 3] = num10;
			array4[num11 + 4] = num10 + 2;
			array4[num11 + 5] = num10 + 3;
		}
		_mesh.Clear();
		_mesh.vertices = Il2CppStructArray<Vector3>.op_Implicit(array);
		_mesh.uv = Il2CppStructArray<Vector2>.op_Implicit(array2);
		_mesh.colors = Il2CppStructArray<Color>.op_Implicit(array3);
		_mesh.triangles = Il2CppStructArray<int>.op_Implicit(array4);
		_mesh.RecalculateBounds();
	}

	public void Destroy()
	{
		if ((Object)(object)_mesh != (Object)null)
		{
			Object.Destroy((Object)(object)_mesh);
		}
		if ((Object)(object)_gameObject != (Object)null)
		{
			Object.Destroy((Object)(object)_gameObject);
		}
	}
}