Decompiled source of MiniStates v1.3.0

MiniStates.dll

Decompiled 4 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using Bounce.Unmanaged;
using HarmonyLib;
using LordAshes;
using Microsoft.CodeAnalysis;
using RadialUI;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("MiniStates")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MiniStates")]
[assembly: AssemblyTitle("MiniStates")]
[assembly: AssemblyVersion("1.0.0.0")]
[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;
		}
	}
}
namespace MiniStates
{
	[BepInPlugin("org.harudm.plugins.ministates", "MiniStates", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class MiniStatesPlugin : BaseUnityPlugin
	{
		private struct StateDef
		{
			public string Name;

			public Color Color;

			public StateDef(string name, Color color)
			{
				//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)
				Name = name;
				Color = color;
			}
		}

		private sealed class BillboardToCamera : MonoBehaviour
		{
			private void LateUpdate()
			{
				//IL_002f: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: 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)
				Camera val = Camera.main;
				if ((Object)(object)val == (Object)null && Camera.allCamerasCount > 0)
				{
					val = Camera.allCameras[0];
				}
				if (!((Object)(object)val == (Object)null))
				{
					Vector3 val2 = ((Component)this).transform.position - ((Component)val).transform.position;
					if (!(((Vector3)(ref val2)).sqrMagnitude < 0.0001f))
					{
						((Component)this).transform.rotation = Quaternion.LookRotation(((Vector3)(ref val2)).normalized, Vector3.up);
					}
				}
			}
		}

		public const string Guid = "org.harudm.plugins.ministates";

		public const string Name = "MiniStates";

		public const string Version = "1.1.0";

		private static ManualLogSource _log;

		private static Harmony _harmony;

		private static MiniStatesPlugin _instance;

		private const string StateKey = "MiniStates.State";

		private const string RadialMainGuid = "MiniStates.Radial.Estados";

		private const string StateClean = "Limpio";

		private static readonly Dictionary<string, SortedSet<string>> _statesCache = new Dictionary<string, SortedSet<string>>();

		private static readonly Dictionary<string, TextMeshPro> _worldLabelCache = new Dictionary<string, TextMeshPro>();

		private static bool _radialRegistered = false;

		private static FieldInfo _fiSubMenuEntries;

		private static FieldInfo _fiSubMenuChecker;

		private static readonly Dictionary<string, Color> StateColors = new Dictionary<string, Color>
		{
			["Envenenado"] = Color.green,
			["Maldito"] = new Color(0.7f, 0.15f, 0.8f, 1f),
			["Marcado"] = new Color(1f, 0.55f, 0f, 1f),
			["Aturdido"] = Color.yellow,
			["Petrificado"] = new Color(0.6f, 0.6f, 0.6f, 1f),
			["Derribado"] = new Color(0.75f, 0.45f, 0.2f, 1f),
			["Apresado"] = new Color(0.6f, 0.35f, 0.1f, 1f),
			["Dormido"] = new Color(0.55f, 0.35f, 0.8f, 1f),
			["Incapacitado"] = new Color(0.7f, 0.7f, 0.7f, 1f),
			["Asustado"] = new Color(1f, 0.6f, 0f, 1f),
			["Aterrado"] = new Color(1f, 0.2f, 0.2f, 1f),
			["Hechizado"] = new Color(1f, 0.35f, 0.75f, 1f),
			["Cegado"] = new Color(0.25f, 0.25f, 0.25f, 1f),
			["Ensordecido"] = new Color(0.45f, 0.45f, 0.45f, 1f),
			["Invisible"] = new Color(0.9f, 0.9f, 0.9f, 1f),
			["Bendito"] = new Color(0.25f, 0.85f, 1f, 1f),
			["Inspirado"] = new Color(0.35f, 1f, 0.6f, 1f),
			["Esquiva"] = new Color(0.4f, 0.7f, 1f, 1f),
			["Concentración"] = new Color(0.35f, 0.55f, 1f, 1f)
		};

		private static readonly StateDef[] Debuffs = new StateDef[3]
		{
			new StateDef("Envenenado", ColorOf("Envenenado")),
			new StateDef("Marcado", ColorOf("Marcado")),
			new StateDef("Maldito", ColorOf("Maldito"))
		};

		private static readonly StateDef[] Control = new StateDef[6]
		{
			new StateDef("Aturdido", ColorOf("Aturdido")),
			new StateDef("Petrificado", ColorOf("Petrificado")),
			new StateDef("Derribado", ColorOf("Derribado")),
			new StateDef("Apresado", ColorOf("Apresado")),
			new StateDef("Dormido", ColorOf("Dormido")),
			new StateDef("Incapacitado", ColorOf("Incapacitado"))
		};

		private static readonly StateDef[] Mente = new StateDef[3]
		{
			new StateDef("Asustado", ColorOf("Asustado")),
			new StateDef("Aterrado", ColorOf("Aterrado")),
			new StateDef("Hechizado", ColorOf("Hechizado"))
		};

		private static readonly StateDef[] Sentidos = new StateDef[3]
		{
			new StateDef("Cegado", ColorOf("Cegado")),
			new StateDef("Ensordecido", ColorOf("Ensordecido")),
			new StateDef("Invisible", ColorOf("Invisible"))
		};

		private static readonly StateDef[] Buffs = new StateDef[4]
		{
			new StateDef("Bendito", ColorOf("Bendito")),
			new StateDef("Inspirado", ColorOf("Inspirado")),
			new StateDef("Esquiva", ColorOf("Esquiva")),
			new StateDef("Concentración", ColorOf("Concentración"))
		};

		private static Color ColorOf(string stateName)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return GetStateColor(stateName);
		}

		private void Awake()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			_instance = this;
			_log = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("org.harudm.plugins.ministates");
			_harmony.PatchAll();
			CacheRadialSubmenuInternals();
			SetupAssetDataSubscription();
			((MonoBehaviour)this).StartCoroutine(RoleMenuGuardLoop());
			_log.LogInfo((object)"MiniStates by HaruDM loaded. v1.1.0");
		}

		private static void CacheRadialSubmenuInternals()
		{
			try
			{
				Type typeFromHandle = typeof(RadialSubmenu);
				_fiSubMenuEntries = typeFromHandle.GetField("subMenuEntries", BindingFlags.Static | BindingFlags.NonPublic);
				_fiSubMenuChecker = typeFromHandle.GetField("subMenuChecker", BindingFlags.Static | BindingFlags.NonPublic);
			}
			catch
			{
			}
		}

		private static bool CanEdit()
		{
			try
			{
				if (LocalClient.IsPartyGm)
				{
					return true;
				}
			}
			catch
			{
			}
			try
			{
				PropertyInfo property = typeof(LocalClient).GetProperty("IsGm", BindingFlags.Static | BindingFlags.Public);
				if (property != null && property.PropertyType == typeof(bool) && (bool)property.GetValue(null))
				{
					return true;
				}
			}
			catch
			{
			}
			return false;
		}

		private static bool IsInBoard()
		{
			try
			{
				Type type = AccessTools.TypeByName("BoardSessionManager");
				if (type == null)
				{
					return false;
				}
				PropertyInfo property = type.GetProperty("InBoard", BindingFlags.Static | BindingFlags.Public);
				if (property != null && property.PropertyType == typeof(bool))
				{
					return (bool)property.GetValue(null);
				}
				return false;
			}
			catch
			{
				return false;
			}
		}

		private IEnumerator RoleMenuGuardLoop()
		{
			while (!IsInBoard())
			{
				yield return null;
			}
			while (IsInBoard())
			{
				bool flag = CanEdit();
				if (flag && !_radialRegistered)
				{
					SetupRadialMenu();
					_radialRegistered = true;
					_log.LogInfo((object)"MiniStates: Estados menu registered (GM).");
				}
				else if (!flag && _radialRegistered)
				{
					UnregisterRadialMenu();
					_radialRegistered = false;
					_log.LogInfo((object)"MiniStates: Estados menu unregistered (non-GM).");
				}
				yield return (object)new WaitForSeconds(0.5f);
			}
			_radialRegistered = false;
		}

		private static void SetupRadialMenu()
		{
			RadialSubmenu.EnsureMainMenuItem("MiniStates.Radial.Estados", (MenuType)1, "Estados", (Sprite)null, (Func<NGuid, NGuid, bool>)null);
			RadialSubmenu.CreateSubMenuItem("MiniStates.Radial.Estados", "Limpio (Quitar todos)", (Sprite)null, (Action<CreatureGuid, string, MapMenuItem>)delegate(CreatureGuid creature, string _, MapMenuItem __)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				ClearAllStates(GetTargetCreature(creature));
			}, true, (Func<bool>)null);
			RadialSubmenu.CreateSubMenuItem("MiniStates.Radial.Estados", "Debuffs", (Sprite)null, (Action<CreatureGuid, string, MapMenuItem>)delegate(CreatureGuid creature, string _, MapMenuItem __)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				OpenCategoryMenuDelayed(GetTargetCreature(creature), "Debuffs", Debuffs);
			}, true, (Func<bool>)null);
			RadialSubmenu.CreateSubMenuItem("MiniStates.Radial.Estados", "Control", (Sprite)null, (Action<CreatureGuid, string, MapMenuItem>)delegate(CreatureGuid creature, string _, MapMenuItem __)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				OpenCategoryMenuDelayed(GetTargetCreature(creature), "Control", Control);
			}, true, (Func<bool>)null);
			RadialSubmenu.CreateSubMenuItem("MiniStates.Radial.Estados", "Mente", (Sprite)null, (Action<CreatureGuid, string, MapMenuItem>)delegate(CreatureGuid creature, string _, MapMenuItem __)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				OpenCategoryMenuDelayed(GetTargetCreature(creature), "Mente", Mente);
			}, true, (Func<bool>)null);
			RadialSubmenu.CreateSubMenuItem("MiniStates.Radial.Estados", "Sentidos", (Sprite)null, (Action<CreatureGuid, string, MapMenuItem>)delegate(CreatureGuid creature, string _, MapMenuItem __)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				OpenCategoryMenuDelayed(GetTargetCreature(creature), "Sentidos", Sentidos);
			}, true, (Func<bool>)null);
			RadialSubmenu.CreateSubMenuItem("MiniStates.Radial.Estados", "Buffs", (Sprite)null, (Action<CreatureGuid, string, MapMenuItem>)delegate(CreatureGuid creature, string _, MapMenuItem __)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				OpenCategoryMenuDelayed(GetTargetCreature(creature), "Buffs", Buffs);
			}, true, (Func<bool>)null);
		}

		private static void UnregisterRadialMenu()
		{
			try
			{
				RadialUIPlugin.RemoveCustomButtonOnCharacter("MiniStates.Radial.Estados");
			}
			catch
			{
			}
			try
			{
				if (_fiSubMenuEntries == null || !(_fiSubMenuEntries.GetValue(null) is Dictionary<string, List<ItemArgs>> dictionary))
				{
					return;
				}
				if (!dictionary.TryGetValue("MiniStates.Radial.Estados", out var value) || value == null)
				{
					dictionary.Remove("MiniStates.Radial.Estados");
					return;
				}
				if (_fiSubMenuChecker != null && _fiSubMenuChecker.GetValue(null) is Dictionary<ItemArgs, Func<bool>> dictionary2)
				{
					foreach (ItemArgs item in value)
					{
						dictionary2.Remove(item);
					}
				}
				dictionary.Remove("MiniStates.Radial.Estados");
			}
			catch
			{
			}
		}

		private static void OpenCategoryMenuDelayed(CreatureGuid creature, string title, StateDef[] states)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			if (CanEdit() && !((Object)(object)_instance == (Object)null))
			{
				((MonoBehaviour)_instance).StartCoroutine(OpenCategoryMenuCoroutine(creature, title, states));
			}
		}

		private static IEnumerator OpenCategoryMenuCoroutine(CreatureGuid creature, string title, StateDef[] states)
		{
			//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)
			yield return null;
			OpenCategoryMenu(creature, title, states);
		}

		private static void OpenCategoryMenu(CreatureGuid creature, string title, StateDef[] states)
		{
			//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_001d: 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_002d: 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_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_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_0087: 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_00b8: Expected O, but got Unknown
			//IL_00e1: 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)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Expected O, but got Unknown
			//IL_0127: 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_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Expected O, but got Unknown
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: 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_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Expected O, but got Unknown
			if (!CanEdit() || ((CreatureGuid)(ref creature)).Equals(default(CreatureGuid)) || !TryGetCreatureAsset(creature, out var asset) || (Object)(object)asset == (Object)null)
			{
				return;
			}
			MapMenu val = MapMenuManager.OpenMenu(((Component)asset).transform.position + Vector3.up * 1.2f, true);
			val.AddItem(new ItemArgs
			{
				Title = "[" + title + "] (toggle)",
				CloseMenuOnActivate = false,
				Action = delegate
				{
				}
			});
			for (int i = 0; i < states.Length; i++)
			{
				StateDef s = states[i];
				val.AddItem(new ItemArgs
				{
					Title = s.Name,
					CloseMenuOnActivate = false,
					Action = delegate
					{
						//IL_0006: Unknown result type (might be due to invalid IL or missing references)
						ToggleState(creature, s.Name);
					}
				});
			}
			val.AddItem(new ItemArgs
			{
				Title = "Limpio (Quitar todos)",
				CloseMenuOnActivate = false,
				Action = delegate
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					ClearAllStates(creature);
				}
			});
			val.AddItem(new ItemArgs
			{
				Title = "Listo (Cerrar)",
				CloseMenuOnActivate = true,
				Action = delegate
				{
				}
			});
		}

		private static CreatureGuid GetTargetCreature(CreatureGuid creatureFromCallback)
		{
			//IL_0004: 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_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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_002d: 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_0033: 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)
			if (!((CreatureGuid)(ref creatureFromCallback)).Equals(default(CreatureGuid)))
			{
				return creatureFromCallback;
			}
			try
			{
				NGuid lastRadialTargetCreature = RadialUIPlugin.GetLastRadialTargetCreature();
				if (!((NGuid)(ref lastRadialTargetCreature)).Equals(default(NGuid)))
				{
					return new CreatureGuid(lastRadialTargetCreature);
				}
			}
			catch
			{
			}
			return creatureFromCallback;
		}

		private static void SetupAssetDataSubscription()
		{
			try
			{
				AssetDataPlugin.Subscribe("MiniStates.State", (Action<DatumChange>)OnAssetDataChanged);
				_log.LogInfo((object)"MiniStates: AssetData subscription registered.");
			}
			catch (Exception ex)
			{
				_log.LogWarning((object)("MiniStates: AssetDataPlugin.Subscribe failed: " + ex.Message));
			}
		}

		private static void OnAssetDataChanged(DatumChange change)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Invalid comparison between Unknown and I4
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				string text = ((change != null) ? change.source : null);
				if (!string.IsNullOrWhiteSpace(text))
				{
					if ((int)change.action == 1)
					{
						_statesCache[text] = new SortedSet<string>(StringComparer.OrdinalIgnoreCase);
					}
					else
					{
						_statesCache[text] = ParseStateList(change.value?.ToString());
					}
					if (TryGetCreatureAsset(new CreatureGuid(text), out var asset))
					{
						ApplyWorldLabel(asset);
					}
				}
			}
			catch
			{
			}
		}

		private static SortedSet<string> GetStates(CreatureGuid creature)
		{
			string text = ((object)(CreatureGuid)(ref creature)).ToString();
			if (_statesCache.TryGetValue(text, out var value) && value != null)
			{
				return value;
			}
			try
			{
				value = ParseStateList(AssetDataPlugin.ReadInfo(text, "MiniStates.State"));
				_statesCache[text] = value;
				return value;
			}
			catch
			{
				value = new SortedSet<string>(StringComparer.OrdinalIgnoreCase);
				_statesCache[text] = value;
				return value;
			}
		}

		private static void SaveStates(CreatureGuid creature, SortedSet<string> states)
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			if (!CanEdit())
			{
				return;
			}
			string text = ((object)(CreatureGuid)(ref creature)).ToString();
			if (states.Contains("Limpio"))
			{
				states.Remove("Limpio");
			}
			if (states.Count == 0)
			{
				_statesCache[text] = new SortedSet<string>(StringComparer.OrdinalIgnoreCase);
				try
				{
					AssetDataPlugin.ClearInfo(text, "MiniStates.State", false);
				}
				catch
				{
				}
			}
			else
			{
				string text2 = SerializeStateList(states);
				_statesCache[text] = states;
				try
				{
					AssetDataPlugin.SetInfo(text, "MiniStates.State", text2, false);
				}
				catch
				{
				}
			}
			if (TryGetCreatureAsset(creature, out var asset))
			{
				ApplyWorldLabel(asset);
			}
		}

		private static void ToggleState(CreatureGuid creature, string state)
		{
			//IL_000c: 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_0031: 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)
			if (CanEdit() && !((CreatureGuid)(ref creature)).Equals(default(CreatureGuid)) && !string.IsNullOrWhiteSpace(state) && !(state == "Limpio"))
			{
				SortedSet<string> states = GetStates(creature);
				if (states.Contains(state))
				{
					states.Remove(state);
				}
				else
				{
					states.Add(state);
				}
				SaveStates(creature, states);
			}
		}

		private static void ClearAllStates(CreatureGuid creature)
		{
			//IL_000c: 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_001b: Unknown result type (might be due to invalid IL or missing references)
			if (CanEdit() && !((CreatureGuid)(ref creature)).Equals(default(CreatureGuid)))
			{
				SaveStates(creature, new SortedSet<string>(StringComparer.OrdinalIgnoreCase));
			}
		}

		private static SortedSet<string> ParseStateList(string raw)
		{
			SortedSet<string> sortedSet = new SortedSet<string>(StringComparer.OrdinalIgnoreCase);
			if (string.IsNullOrWhiteSpace(raw))
			{
				return sortedSet;
			}
			string[] array = raw.Split(new char[1] { '|' }, StringSplitOptions.RemoveEmptyEntries);
			for (int i = 0; i < array.Length; i++)
			{
				string text = (array[i] ?? "").Trim();
				if (text.Length != 0 && !(text == "Limpio"))
				{
					sortedSet.Add(text);
				}
			}
			return sortedSet;
		}

		private static string SerializeStateList(SortedSet<string> set)
		{
			if (set == null || set.Count == 0)
			{
				return "";
			}
			return string.Join("|", set);
		}

		private static Color GetStateColor(string state)
		{
			//IL_001c: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrWhiteSpace(state))
			{
				return new Color(0.85f, 0.85f, 0.85f, 1f);
			}
			if (StateColors.TryGetValue(state, out var value))
			{
				return value;
			}
			return new Color(0.85f, 0.85f, 0.85f, 1f);
		}

		private static bool ShouldShowStates(SortedSet<string> states)
		{
			if (states != null)
			{
				return states.Count > 0;
			}
			return false;
		}

		private static string BuildRichTextLabel(SortedSet<string> states)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			List<string> list = new List<string>(states.Count);
			foreach (string state in states)
			{
				string text = ColorUtility.ToHtmlStringRGB(GetStateColor(state));
				list.Add("<color=#" + text + ">" + state.ToUpperInvariant() + "</color>");
			}
			return string.Join("\n", list);
		}

		private static bool TryGetCreatureAsset(CreatureGuid id, out CreatureBoardAsset asset)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			asset = null;
			try
			{
				return CreaturePresenter.TryGetAsset(id, ref asset) && (Object)(object)asset != (Object)null;
			}
			catch
			{
				return false;
			}
		}

		private static void ApplyWorldLabel(CreatureBoardAsset asset)
		{
			//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_0032: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)asset == (Object)null))
			{
				CreatureGuid creatureId = asset.CreatureId;
				string key = ((object)(CreatureGuid)(ref creatureId)).ToString();
				if (!_statesCache.TryGetValue(key, out var value) || value == null)
				{
					value = GetStates(asset.CreatureId);
				}
				if (!_worldLabelCache.TryGetValue(key, out var value2) || (Object)(object)value2 == (Object)null)
				{
					value2 = CreateWorldLabel(asset);
					_worldLabelCache[key] = value2;
				}
				if (!ShouldShowStates(value))
				{
					((TMP_Text)value2).text = "";
					((Component)value2).gameObject.SetActive(false);
				}
				else
				{
					((Component)value2).gameObject.SetActive(true);
					((TMP_Text)value2).text = BuildRichTextLabel(value);
				}
			}
		}

		private static TextMeshPro CreateWorldLabel(CreatureBoardAsset asset)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_004c: 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_005c: 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_006c: 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_0080: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
			Transform val = null;
			try
			{
				val = asset.HookHead;
			}
			catch
			{
				val = null;
			}
			if ((Object)(object)val == (Object)null)
			{
				val = ((Component)asset).transform;
			}
			GameObject val2 = new GameObject("MiniStates_WorldState");
			val2.transform.SetParent(val, false);
			val2.transform.localPosition = new Vector3(0f, 0.6f, 0f);
			val2.transform.localRotation = Quaternion.identity;
			val2.transform.localScale = Vector3.one * 0.08f;
			TextMeshPro val3 = val2.AddComponent<TextMeshPro>();
			((TMP_Text)val3).text = "";
			((TMP_Text)val3).richText = true;
			((TMP_Text)val3).enableWordWrapping = false;
			((TMP_Text)val3).alignment = (TextAlignmentOptions)514;
			((TMP_Text)val3).fontSize = 8.5f;
			MeshRenderer component = val2.GetComponent<MeshRenderer>();
			if ((Object)(object)component != (Object)null)
			{
				((Renderer)component).sortingOrder = 5000;
			}
			val2.AddComponent<BillboardToCamera>();
			val2.SetActive(false);
			return val3;
		}
	}
}