Decompiled source of EnemySpeechBubbles v1.0.0

EnemySpeechBubbles.dll

Decompiled 8 hours ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using On.RoR2;
using RoR2;
using RoR2.UI;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("EnemySpeechBubbles")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EnemySpeechBubbles")]
[assembly: AssemblyTitle("EnemySpeechBubbles")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 ExamplePlugin
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("Yogarpg.EnemySpeechBubbles", "EnemySpeechBubbles", "1.0.0")]
	public class ExamplePlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "Yogarpg.EnemySpeechBubbles";

		public const string PluginAuthor = "Yogarpg";

		public const string PluginName = "EnemySpeechBubbles";

		public const string PluginVersion = "1.0.0";

		private static ChatMessageBase _lastProcessedMessage;

		private static float _lastProcessedTime;

		private static Vector3 _lastKnownBossHeadPosition = Vector3.zero;

		private static string _lastKnownBossName = "";

		public void Awake()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[EnemySpeechBubbles] Inicializando plugin de Balões de Fala para Inimigos...");
			Chat.AddMessage_ChatMessageBase += new hook_AddMessage_ChatMessageBase(Chat_AddMessage_ChatMessageBase);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[EnemySpeechBubbles] Hook registrado: On.RoR2.Chat.AddMessage_ChatMessageBase");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[EnemySpeechBubbles] Mod carregado com sucesso!");
		}

		private void Update()
		{
			TrackBossPosition();
		}

		private void TrackBossPosition()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Invalid comparison between Unknown and I4
			//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)
			foreach (CharacterBody readOnlyInstances in CharacterBody.readOnlyInstancesList)
			{
				if (Object.op_Implicit((Object)(object)readOnlyInstances) && readOnlyInstances.isBoss && (!Object.op_Implicit((Object)(object)readOnlyInstances.teamComponent) || (int)readOnlyInstances.teamComponent.teamIndex != 1) && Object.op_Implicit((Object)(object)readOnlyInstances.healthComponent) && readOnlyInstances.healthComponent.alive)
				{
					_lastKnownBossHeadPosition = SpeechBubbleController.GetHeadWorldPositionFor(readOnlyInstances);
					_lastKnownBossName = readOnlyInstances.GetDisplayName();
					break;
				}
			}
		}

		private void Chat_AddMessage_ChatMessageBase(orig_AddMessage_ChatMessageBase orig, ChatMessageBase message)
		{
			orig.Invoke(message);
			try
			{
				ProcessMessageSafe(message);
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)string.Format("[{0}] Erro ao processar mensagem de chat: {1}", "EnemySpeechBubbles", arg));
			}
		}

		private void ProcessMessageSafe(ChatMessageBase message)
		{
			if (message != null && (_lastProcessedMessage != message || !(Time.time - _lastProcessedTime < 0.25f)))
			{
				_lastProcessedMessage = message;
				_lastProcessedTime = Time.time;
				HandleChatMessage(message);
			}
		}

		private void HandleChatMessage(ChatMessageBase message)
		{
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Invalid comparison between Unknown and I4
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Invalid comparison between Unknown and I4
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Invalid comparison between Unknown and I4
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			if (message == null || message is PlayerPickupChatMessage || message is PlayerDeathChatMessage || message is UserChatMessage)
			{
				return;
			}
			CharacterBody val = null;
			string text = "";
			string inferredName = "";
			bool flag = false;
			NpcChatMessage val2 = (NpcChatMessage)(object)((message is NpcChatMessage) ? message : null);
			if (val2 != null)
			{
				flag = true;
				if (Object.op_Implicit((Object)(object)val2.sender))
				{
					val = val2.sender.GetComponent<CharacterBody>();
					if (!Object.op_Implicit((Object)(object)val))
					{
						CharacterMaster component = val2.sender.GetComponent<CharacterMaster>();
						if (Object.op_Implicit((Object)(object)component))
						{
							val = component.GetBody();
						}
					}
				}
				if (!string.IsNullOrEmpty(val2.baseToken))
				{
					text = Language.GetString(val2.baseToken);
				}
				if (string.IsNullOrEmpty(text) || text == val2.baseToken)
				{
					text = ((ChatMessageBase)val2).ConstructChatString();
				}
				if (!Object.op_Implicit((Object)(object)val))
				{
					val = FindBossByTokenOrScene(val2.formatStringToken, val2.baseToken, out inferredName);
				}
			}
			else
			{
				BodyChatMessage val3 = (BodyChatMessage)(object)((message is BodyChatMessage) ? message : null);
				if (val3 != null)
				{
					if (Object.op_Implicit((Object)(object)val3.bodyObject))
					{
						val = val3.bodyObject.GetComponent<CharacterBody>();
					}
					if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.teamComponent) && (int)val.teamComponent.teamIndex != 1)
					{
						flag = true;
						if (!string.IsNullOrEmpty(val3.token))
						{
							text = Language.GetString(val3.token);
						}
						if (string.IsNullOrEmpty(text))
						{
							text = ((ChatMessageBase)val3).ConstructChatString();
						}
					}
				}
				else
				{
					SubjectFormatChatMessage val4 = (SubjectFormatChatMessage)(object)((message is SubjectFormatChatMessage) ? message : null);
					if (val4 != null)
					{
						val = ((SubjectChatMessage)val4).subjectAsCharacterBody;
						if (SpeechBubbleLogic.IsExcludedToken(((SubjectChatMessage)val4).baseToken))
						{
							return;
						}
						if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.teamComponent) && (int)val.teamComponent.teamIndex != 1)
						{
							flag = true;
							if (!string.IsNullOrEmpty(((SubjectChatMessage)val4).baseToken))
							{
								text = Language.GetString(((SubjectChatMessage)val4).baseToken);
							}
							if (string.IsNullOrEmpty(text))
							{
								text = ((ChatMessageBase)val4).ConstructChatString();
							}
						}
					}
				}
			}
			if (!flag || string.IsNullOrWhiteSpace(text) || (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.teamComponent) && (int)val.teamComponent.teamIndex == 1))
			{
				return;
			}
			if (Object.op_Implicit((Object)(object)val) && string.IsNullOrEmpty(inferredName))
			{
				inferredName = val.GetDisplayName();
			}
			if (string.IsNullOrEmpty(inferredName))
			{
				inferredName = _lastKnownBossName;
			}
			if (string.IsNullOrEmpty(inferredName))
			{
				string text2 = Regex.Replace(message.ConstructChatString(), "<.*?>", string.Empty);
				int num = text2.IndexOf(':');
				if (num > 0)
				{
					inferredName = text2.Substring(0, num).Trim();
				}
			}
			if (string.IsNullOrEmpty(inferredName))
			{
				inferredName = "Chefe";
			}
			text = SpeechBubbleLogic.CleanDialogueText(text);
			float num2 = SpeechBubbleLogic.CalculateDisplayDuration(text.Length);
			Vector3 zero = Vector3.zero;
			if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)((Component)val).gameObject))
			{
				zero = (_lastKnownBossHeadPosition = SpeechBubbleController.GetHeadWorldPositionFor(val));
			}
			else if (_lastKnownBossHeadPosition != Vector3.zero)
			{
				zero = _lastKnownBossHeadPosition;
			}
			else
			{
				Camera camera = SpeechBubbleController.GetCamera();
				zero = (Object.op_Implicit((Object)(object)camera) ? (((Component)camera).transform.position + ((Component)camera).transform.forward * 8f + Vector3.up * 1f) : Vector3.zero);
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("[{0}] Fala de '{1}': \"{2}\" | Exibindo balão 3D na posição {3} por {4:F1}s.", "EnemySpeechBubbles", inferredName, text, zero, num2));
			SpawnSpeechBubble(val, zero, inferredName, text, num2);
		}

		private CharacterBody FindBossByTokenOrScene(string formatToken, string baseToken, out string inferredName)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Invalid comparison between Unknown and I4
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Invalid comparison between Unknown and I4
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Invalid comparison between Unknown and I4
			inferredName = "";
			string text = (formatToken + " " + baseToken).ToUpperInvariant();
			foreach (CharacterBody readOnlyInstances in CharacterBody.readOnlyInstancesList)
			{
				if (Object.op_Implicit((Object)(object)readOnlyInstances) && Object.op_Implicit((Object)(object)readOnlyInstances.healthComponent) && readOnlyInstances.healthComponent.alive && (!Object.op_Implicit((Object)(object)readOnlyInstances.teamComponent) || (int)readOnlyInstances.teamComponent.teamIndex != 1) && IsMatchingBoss(readOnlyInstances, text))
				{
					inferredName = readOnlyInstances.GetDisplayName();
					return readOnlyInstances;
				}
			}
			foreach (CharacterBody readOnlyInstances2 in CharacterBody.readOnlyInstancesList)
			{
				if (Object.op_Implicit((Object)(object)readOnlyInstances2) && (!Object.op_Implicit((Object)(object)readOnlyInstances2.teamComponent) || (int)readOnlyInstances2.teamComponent.teamIndex != 1) && IsMatchingBoss(readOnlyInstances2, text))
				{
					inferredName = readOnlyInstances2.GetDisplayName();
					return readOnlyInstances2;
				}
			}
			if (text.Contains("BROTHER") || text.Contains("MITHRIX"))
			{
				inferredName = "Mithrix";
				return null;
			}
			if (text.Contains("FALSE_SON") || text.Contains("FALSESON") || text.Contains("FILHO"))
			{
				inferredName = "Falso Filho";
				return null;
			}
			if (text.Contains("PROVIDENCE") || text.Contains("ECHO"))
			{
				inferredName = "Eco de Providência";
				return null;
			}
			if (text.Contains("VOID"))
			{
				inferredName = "Devorador do Vazio";
				return null;
			}
			if (text.Contains("SOLUS") || text.Contains("ALLOY") || text.Contains("COLLECTIVE") || text.Contains("HEART"))
			{
				inferredName = "Coração Solus";
				return null;
			}
			if (text.Contains("NKUHANA") || text.Contains("HALLOWED") || text.Contains("BASILICA") || text.Contains("LYNX"))
			{
				inferredName = "N'kuhana";
				return null;
			}
			foreach (CharacterBody readOnlyInstances3 in CharacterBody.readOnlyInstancesList)
			{
				if (Object.op_Implicit((Object)(object)readOnlyInstances3) && readOnlyInstances3.isBoss && Object.op_Implicit((Object)(object)readOnlyInstances3.teamComponent) && (int)readOnlyInstances3.teamComponent.teamIndex != 1)
				{
					inferredName = readOnlyInstances3.GetDisplayName();
					return readOnlyInstances3;
				}
			}
			return null;
		}

		private static bool IsMatchingBoss(CharacterBody body, string tokenCombo)
		{
			string text = ((Object)body).name ?? "";
			string text2 = body.baseNameToken ?? "";
			if ((tokenCombo.Contains("BROTHER") || tokenCombo.Contains("MITHRIX")) && (text.IndexOf("Brother", StringComparison.OrdinalIgnoreCase) >= 0 || text2.IndexOf("BROTHER", StringComparison.OrdinalIgnoreCase) >= 0))
			{
				return true;
			}
			if ((tokenCombo.Contains("FALSE_SON") || tokenCombo.Contains("FALSESON") || tokenCombo.Contains("FILHO")) && (text.IndexOf("FalseSon", StringComparison.OrdinalIgnoreCase) >= 0 || text2.IndexOf("FALSE_SON", StringComparison.OrdinalIgnoreCase) >= 0))
			{
				return true;
			}
			if ((tokenCombo.Contains("PROVIDENCE") || tokenCombo.Contains("ECHO")) && (text.IndexOf("Providence", StringComparison.OrdinalIgnoreCase) >= 0 || text2.IndexOf("PROVIDENCE", StringComparison.OrdinalIgnoreCase) >= 0))
			{
				return true;
			}
			if (tokenCombo.Contains("VOID") && body.isBoss && text.IndexOf("VoidRaid", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
			if ((tokenCombo.Contains("SOLUS") || tokenCombo.Contains("ALLOY") || tokenCombo.Contains("COLLECTIVE") || tokenCombo.Contains("HEART")) && (text.IndexOf("Solus", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("Alloy", StringComparison.OrdinalIgnoreCase) >= 0 || text2.IndexOf("SOLUS", StringComparison.OrdinalIgnoreCase) >= 0))
			{
				return true;
			}
			if ((tokenCombo.Contains("NKUHANA") || tokenCombo.Contains("HALLOWED") || tokenCombo.Contains("BASILICA") || tokenCombo.Contains("LYNX")) && (text.IndexOf("Nkuhana", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("Basilica", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("Lynx", StringComparison.OrdinalIgnoreCase) >= 0 || text2.IndexOf("NKUHANA", StringComparison.OrdinalIgnoreCase) >= 0))
			{
				return true;
			}
			return false;
		}

		private void SpawnSpeechBubble(CharacterBody body, Vector3 worldPosition, string speakerName, string quoteText, float duration)
		{
			//IL_006f: 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)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			SpeechBubbleController[] array = Object.FindObjectsOfType<SpeechBubbleController>();
			foreach (SpeechBubbleController speechBubbleController in array)
			{
				if (Object.op_Implicit((Object)(object)speechBubbleController) && (((Object)(object)body != (Object)null && (Object)(object)speechBubbleController.TargetBody == (Object)(object)body) || Vector3.Distance(((Component)speechBubbleController).transform.position, worldPosition) < 3.5f))
				{
					speechBubbleController.UpdateText(speakerName, quoteText, duration);
					return;
				}
			}
			new GameObject("EnemySpeechBubble_" + (speakerName ?? "Boss")).AddComponent<SpeechBubbleController>().Init(body, worldPosition, speakerName, quoteText, duration);
		}
	}
	public class SpeechBubbleController : MonoBehaviour
	{
		private Canvas canvas;

		private CanvasGroup canvasGroup;

		private HGTextMeshProUGUI textComponent;

		private LayoutElement layoutElement;

		private float expireTime;

		private float maxDuration;

		private float fadeDuration = 0.4f;

		private Vector3 _anchorPosition;

		private static TMP_FontAsset _cachedFont;

		public CharacterBody TargetBody { get; private set; }

		public static TMP_FontAsset GetGameFont()
		{
			if (Object.op_Implicit((Object)(object)_cachedFont))
			{
				return _cachedFont;
			}
			HGTextMeshProUGUI[] array = Object.FindObjectsOfType<HGTextMeshProUGUI>();
			foreach (HGTextMeshProUGUI val in array)
			{
				if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)((TMP_Text)val).font))
				{
					_cachedFont = ((TMP_Text)val).font;
					return _cachedFont;
				}
			}
			if (Object.op_Implicit((Object)(object)TMP_Settings.defaultFontAsset))
			{
				_cachedFont = TMP_Settings.defaultFontAsset;
				return _cachedFont;
			}
			return null;
		}

		public static Camera GetCamera()
		{
			if (CameraRigController.readOnlyInstancesList.Count > 0 && Object.op_Implicit((Object)(object)CameraRigController.readOnlyInstancesList[0]) && Object.op_Implicit((Object)(object)CameraRigController.readOnlyInstancesList[0].sceneCam))
			{
				return CameraRigController.readOnlyInstancesList[0].sceneCam;
			}
			return Camera.main;
		}

		public static Vector3 GetHeadWorldPositionFor(CharacterBody body)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: 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_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: 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)
			//IL_0120: 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_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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)
			if (!Object.op_Implicit((Object)(object)body))
			{
				return Vector3.zero;
			}
			float num = Mathf.Max(body.radius, 1f);
			float num2 = float.MinValue;
			bool flag = false;
			if (Object.op_Implicit((Object)(object)body.hurtBoxGroup) && body.hurtBoxGroup.hurtBoxes != null)
			{
				HurtBox[] hurtBoxes = body.hurtBoxGroup.hurtBoxes;
				foreach (HurtBox val in hurtBoxes)
				{
					if (!Object.op_Implicit((Object)(object)val))
					{
						continue;
					}
					Collider component = ((Component)val).GetComponent<Collider>();
					if (Object.op_Implicit((Object)(object)component))
					{
						Bounds bounds = component.bounds;
						float y = ((Bounds)(ref bounds)).max.y;
						if (y > num2)
						{
							num2 = y;
							flag = true;
						}
					}
				}
			}
			Vector3 val2 = ((!Object.op_Implicit((Object)(object)body.mainHurtBox)) ? body.corePosition : ((Component)body.mainHurtBox).transform.position);
			if (flag && num2 > val2.y)
			{
				float num3 = SpeechBubbleLogic.CalculateAboveHealthBarClearance(num);
				return new Vector3(val2.x, num2 + num3, val2.z);
			}
			float num4 = Mathf.Clamp(num * 1.8f + 2.6f, 4.2f, 7.5f);
			return val2 + Vector3.up * num4;
		}

		public void Init(CharacterBody body, Vector3 worldPosition, string speakerName, string quoteText, float duration)
		{
			//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_002b: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: 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_0106: Expected O, but got Unknown
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: 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_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Expected O, but got Unknown
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Expected O, but got Unknown
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			TargetBody = body;
			_anchorPosition = worldPosition;
			maxDuration = duration;
			expireTime = Time.time + duration;
			((Component)this).transform.position = _anchorPosition;
			((Component)this).transform.localScale = Vector3.one * 0.016f;
			((Component)this).gameObject.layer = 0;
			canvas = ((Component)this).gameObject.AddComponent<Canvas>();
			canvas.renderMode = (RenderMode)2;
			canvas.worldCamera = GetCamera();
			canvas.sortingOrder = 10000;
			canvasGroup = ((Component)this).gameObject.AddComponent<CanvasGroup>();
			canvasGroup.alpha = 1f;
			RectTransform component = ((Component)this).GetComponent<RectTransform>();
			component.sizeDelta = new Vector2(360f, 120f);
			component.pivot = new Vector2(0.5f, 0f);
			GameObject val = new GameObject("BubbleBackground", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(((Component)this).transform, false);
			val.layer = 0;
			RectTransform component2 = val.GetComponent<RectTransform>();
			component2.anchorMin = new Vector2(0.5f, 0f);
			component2.anchorMax = new Vector2(0.5f, 0f);
			component2.pivot = new Vector2(0.5f, 0f);
			component2.anchoredPosition = Vector2.zero;
			((Graphic)val.AddComponent<Image>()).color = new Color(0.04f, 0.05f, 0.08f, 0.92f);
			Outline obj = val.AddComponent<Outline>();
			((Shadow)obj).effectColor = new Color(0.35f, 0.75f, 1f, 0.9f);
			((Shadow)obj).effectDistance = new Vector2(1.5f, -1.5f);
			VerticalLayoutGroup obj2 = val.AddComponent<VerticalLayoutGroup>();
			((LayoutGroup)obj2).padding = new RectOffset(14, 14, 8, 8);
			((LayoutGroup)obj2).childAlignment = (TextAnchor)4;
			((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = false;
			ContentSizeFitter obj3 = val.AddComponent<ContentSizeFitter>();
			obj3.horizontalFit = (FitMode)2;
			obj3.verticalFit = (FitMode)2;
			GameObject val2 = new GameObject("SpeechText", new Type[1] { typeof(RectTransform) });
			val2.transform.SetParent(val.transform, false);
			val2.layer = 0;
			textComponent = val2.AddComponent<HGTextMeshProUGUI>();
			TMP_FontAsset gameFont = GetGameFont();
			if (Object.op_Implicit((Object)(object)gameFont))
			{
				((TMP_Text)textComponent).font = gameFont;
				((TMP_Text)textComponent).fontSharedMaterial = ((TMP_Asset)gameFont).material;
			}
			((TMP_Text)textComponent).alignment = (TextAlignmentOptions)514;
			((TMP_Text)textComponent).enableWordWrapping = true;
			((TMP_Text)textComponent).fontSize = 24f;
			((Graphic)textComponent).color = Color.white;
			layoutElement = val2.AddComponent<LayoutElement>();
			SetContent(speakerName, quoteText);
			if (Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)((Component)body).gameObject))
			{
				Util.PlaySound("Play_UI_chat", ((Component)body).gameObject);
			}
			else
			{
				Util.PlaySound("Play_UI_chat", Object.op_Implicit((Object)(object)RoR2Application.instance) ? ((Component)RoR2Application.instance).gameObject : null);
			}
		}

		public void UpdateText(string speakerName, string quoteText, float duration)
		{
			maxDuration = duration;
			expireTime = Time.time + duration;
			SetContent(speakerName, quoteText);
			if (Object.op_Implicit((Object)(object)canvasGroup))
			{
				canvasGroup.alpha = 1f;
			}
		}

		private void SetContent(string speakerName, string quoteText)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: 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)
			if (!((Object)(object)textComponent == (Object)null))
			{
				string text = (string.IsNullOrEmpty(speakerName) ? "" : ("<size=75%><color=#8FE3FF><b>" + speakerName + "</b></color></size>\n"));
				((TMP_Text)textComponent).text = text + "<b>\"" + quoteText + "\"</b>";
				if ((Object)(object)layoutElement != (Object)null)
				{
					Vector2 preferredValues = ((TMP_Text)textComponent).GetPreferredValues(((TMP_Text)textComponent).text, 340f, 1000f);
					layoutElement.preferredWidth = SpeechBubbleLogic.CalculateSnugWidth(preferredValues.x);
				}
			}
		}

		private void LateUpdate()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: 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)
			//IL_0056: 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_0077: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			Camera camera = GetCamera();
			if (Object.op_Implicit((Object)(object)camera))
			{
				((Component)this).transform.rotation = ((Component)camera).transform.rotation;
				if (Object.op_Implicit((Object)(object)canvas) && (Object)(object)canvas.worldCamera != (Object)(object)camera)
				{
					canvas.worldCamera = camera;
				}
				float num = SpeechBubbleLogic.CalculateAdaptiveScale(Vector3.Distance(((Component)camera).transform.position, ((Component)this).transform.position));
				((Component)this).transform.localScale = Vector3.one * num;
			}
			if (Object.op_Implicit((Object)(object)TargetBody) && Object.op_Implicit((Object)(object)((Component)TargetBody).gameObject) && Object.op_Implicit((Object)(object)TargetBody.healthComponent) && TargetBody.healthComponent.alive)
			{
				_anchorPosition = GetHeadWorldPositionFor(TargetBody);
			}
			Vector3 anchorPosition = _anchorPosition;
			anchorPosition.y += Mathf.Sin(Time.time * 2.5f) * 0.06f;
			((Component)this).transform.position = anchorPosition;
			float num2 = expireTime - Time.time;
			if (num2 <= 0f)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
			else if (num2 < fadeDuration)
			{
				canvasGroup.alpha = Mathf.Clamp01(num2 / fadeDuration);
			}
			else
			{
				canvasGroup.alpha = 1f;
			}
		}
	}
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		private static string Format(object data, string file, int line)
		{
			string fileName = Path.GetFileName(file);
			return $"[{fileName}:{line}] {data}";
		}

		internal static void Debug(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogDebug((object)Format(data, file, line));
		}

		internal static void Error(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogError((object)Format(data, file, line));
		}

		internal static void Fatal(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogFatal((object)Format(data, file, line));
		}

		internal static void Info(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogInfo((object)Format(data, file, line));
		}

		internal static void Message(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogMessage((object)Format(data, file, line));
		}

		internal static void Warning(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogWarning((object)Format(data, file, line));
		}
	}
	public static class SpeechBubbleLogic
	{
		public const float MinDisplayDuration = 5f;

		public const float MaxDisplayDuration = 9f;

		public const float DurationBase = 4.5f;

		public const float DurationPerChar = 0.08f;

		public const float MinScale = 0.015f;

		public const float MaxScale = 0.03f;

		public const float BaseScaleOffset = 0.012f;

		public const float ScalePerMeter = 0.0004f;

		public const float MinSnugWidth = 120f;

		public const float MaxSnugWidth = 340f;

		public const float SnugWidthPadding = 6f;

		public const float MinHealthBarClearance = 2f;

		public const float MaxHealthBarClearance = 4f;

		public static float CalculateDisplayDuration(int characterCount)
		{
			if (characterCount <= 0)
			{
				return 5f;
			}
			return Math.Clamp(4.5f + (float)characterCount * 0.08f, 5f, 9f);
		}

		public static float CalculateAdaptiveScale(float distance)
		{
			if (distance < 0f)
			{
				distance = 0f;
			}
			return Math.Clamp(0.012f + distance * 0.0004f, 0.015f, 0.03f);
		}

		public static float CalculateSnugWidth(float textPreferredWidth)
		{
			if (textPreferredWidth < 0f)
			{
				return 120f;
			}
			return Math.Clamp(textPreferredWidth + 6f, 120f, 340f);
		}

		public static float CalculateAboveHealthBarClearance(float radius)
		{
			if (radius < 0f)
			{
				radius = 1f;
			}
			return Math.Clamp(radius * 0.4f + 1.8f, 2f, 4f);
		}

		public static string CleanDialogueText(string rawText)
		{
			if (string.IsNullOrWhiteSpace(rawText))
			{
				return string.Empty;
			}
			string text = rawText.Trim();
			int num = text.IndexOf(": ", StringComparison.Ordinal);
			if (num >= 0 && num < text.Length - 2)
			{
				text = text.Substring(num + 2);
			}
			return text.Trim('"', ' ', '\t', '\r', '\n');
		}

		public static bool IsExcludedToken(string token)
		{
			if (string.IsNullOrEmpty(token))
			{
				return false;
			}
			string text = token.ToUpperInvariant();
			if (!text.Contains("PICKUP") && !text.Contains("ITEM") && !text.Contains("EQUIPMENT") && !text.Contains("SHRINE") && !text.Contains("DEATH") && !text.Contains("SUICIDE"))
			{
				return text.Contains("PING");
			}
			return true;
		}
	}
}