Decompiled source of ChatTooltips v1.0.0

ChatTooltips.dll

Decompiled 3 hours ago
using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using ChatTooltips.Properties;
using HarmonyLib;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.UI;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ChatTooltips")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ChatTooltips")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d6a316ac-523f-4709-9664-2a3e0468b33f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ChatTooltips
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("bulletbot.chattooltips", "ChatTooltips", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private static class RiskOfOptions
		{
			[Serializable]
			[CompilerGenerated]
			private sealed class <>c
			{
				public static readonly <>c <>9 = new <>c();

				public static IsDisabledDelegate <>9__1_0;

				internal bool <OnAwake>b__1_0()
				{
					return !instance.isLookingGlassModLoaded();
				}
			}

			public static bool IsLoaded()
			{
				return Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions");
			}

			[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
			public static void OnAwake()
			{
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				//IL_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0095: Unknown result type (might be due to invalid IL or missing references)
				//IL_009f: Expected O, but got Unknown
				//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b4: Expected O, but got Unknown
				//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c9: Expected O, but got Unknown
				//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0103: Expected O, but got Unknown
				//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
				//IL_0108: Expected O, but got Unknown
				//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f9: Expected O, but got Unknown
				Bitmap icon = Resources.icon;
				using (MemoryStream memoryStream = new MemoryStream())
				{
					((Image)icon).Save((Stream)memoryStream, ImageFormat.Png);
					Texture2D val = new Texture2D(((Image)icon).Width, ((Image)icon).Height, (TextureFormat)5, false, false);
					ImageConversion.LoadImage(val, memoryStream.ToArray());
					((Texture)val).filterMode = (FilterMode)0;
					ModSettingsManager.SetModIcon(Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f)));
				}
				ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(instance.itemTooltip));
				ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(instance.achievementTooltip));
				ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(instance.equipmentFullDescription));
				ConfigEntry<bool> lookingGlassDescription = instance.lookingGlassDescription;
				CheckBoxConfig val2 = new CheckBoxConfig();
				object obj = <>c.<>9__1_0;
				if (obj == null)
				{
					IsDisabledDelegate val3 = () => !instance.isLookingGlassModLoaded();
					<>c.<>9__1_0 = val3;
					obj = (object)val3;
				}
				((BaseOptionConfig)val2).checkIfDisabled = (IsDisabledDelegate)obj;
				ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(lookingGlassDescription, val2));
			}
		}

		public enum MessageType
		{
			Pickup,
			Achievement
		}

		private const string modGUID = "bulletbot.chattooltips";

		private const string modName = "ChatTooltips";

		private const string modVer = "1.0.0";

		private const string riskOfOptionsModGUID = "com.rune580.riskofoptions";

		private const string lookingGlassModGUID = "droppod.lookingglass";

		public static Plugin instance;

		public ManualLogSource logger;

		private readonly Harmony harmony = new Harmony("bulletbot.chattooltips");

		private ConfigEntry<bool> itemTooltip;

		private ConfigEntry<bool> achievementTooltip;

		private ConfigEntry<bool> equipmentFullDescription;

		private ConfigEntry<bool> lookingGlassDescription;

		public TMP_InputField messagesText;

		private int currentQuantity;

		private TooltipProvider tooltipProvider;

		private MethodInfo lookingGlassMethod;

		private const string dataSeperator = "|";

		private bool isLookingGlassModLoaded()
		{
			return Chainloader.PluginInfos.ContainsKey("droppod.lookingglass");
		}

		private void Awake()
		{
			instance = this;
			logger = Logger.CreateLogSource("ChatTooltips");
			currentQuantity = -1;
			string text = "General";
			itemTooltip = ((BaseUnityPlugin)this).Config.Bind<bool>(text, "Item Tooltip", true, "Determines whether to be able to display the item tooltip.");
			achievementTooltip = ((BaseUnityPlugin)this).Config.Bind<bool>(text, "Achievement Tooltip", true, "Determines whether to be able to display the description tooltip.");
			equipmentFullDescription = ((BaseUnityPlugin)this).Config.Bind<bool>(text, "Equipment Full Description", false, "Determines whether to display the full description of the equipment.");
			lookingGlassDescription = ((BaseUnityPlugin)this).Config.Bind<bool>(text, "Looking Glass Description", true, "Determines whether to display the custom description from the \"LookingGlass\" mod.");
			if (isLookingGlassModLoaded())
			{
				Type type = AccessTools.TypeByName("LookingGlass.ItemStatsNameSpace.ItemStats");
				if (type != null)
				{
					lookingGlassMethod = AccessTools.Method(type, "GetDescription", (Type[])null, (Type[])null);
				}
			}
			if (RiskOfOptions.IsLoaded())
			{
				RiskOfOptions.OnAwake();
			}
			RoR2Application.onUpdate += delegate
			{
				//IL_0091: Unknown result type (might be due to invalid IL or missing references)
				//IL_0096: Unknown result type (might be due to invalid IL or missing references)
				//IL_0099: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
				//IL_011e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0123: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b6: 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_01bf: Unknown result type (might be due to invalid IL or missing references)
				//IL_03c5: Unknown result type (might be due to invalid IL or missing references)
				//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
				//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
				//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
				//IL_0494: Unknown result type (might be due to invalid IL or missing references)
				//IL_0496: Unknown result type (might be due to invalid IL or missing references)
				//IL_0451: Unknown result type (might be due to invalid IL or missing references)
				//IL_0453: Unknown result type (might be due to invalid IL or missing references)
				//IL_046b: Unknown result type (might be due to invalid IL or missing references)
				//IL_046d: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
				//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
				//IL_0405: Unknown result type (might be due to invalid IL or missing references)
				//IL_040a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0200: Unknown result type (might be due to invalid IL or missing references)
				//IL_0220: Unknown result type (might be due to invalid IL or missing references)
				//IL_0225: Unknown result type (might be due to invalid IL or missing references)
				//IL_022a: Unknown result type (might be due to invalid IL or missing references)
				//IL_022f: Unknown result type (might be due to invalid IL or missing references)
				//IL_02db: Unknown result type (might be due to invalid IL or missing references)
				//IL_02e0: 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_0270: Unknown result type (might be due to invalid IL or missing references)
				//IL_0310: Unknown result type (might be due to invalid IL or missing references)
				//IL_0315: Unknown result type (might be due to invalid IL or missing references)
				//IL_031a: Unknown result type (might be due to invalid IL or missing references)
				//IL_031f: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)messagesText != (Object)null)
				{
					EventSystem current = EventSystem.current;
					MPEventSystem val = (MPEventSystem)(object)((current is MPEventSystem) ? current : null);
					if (!((Object)(object)val == (Object)null))
					{
						TMP_Text componentInChildren = (TMP_Text)(object)((Component)messagesText).GetComponentInChildren<HGTextMeshProUGUI>();
						if ((Object)(object)tooltipProvider == (Object)null)
						{
							tooltipProvider = ((Component)componentInChildren).gameObject.AddComponent<TooltipProvider>();
						}
						CanvasRenderer component = ((Component)componentInChildren).GetComponent<CanvasRenderer>();
						if (component.GetInheritedAlpha() <= 0.1f || PauseManager.PauseScreenIsOpen())
						{
							RemoveTooltip(val);
						}
						else
						{
							Vector3 mousePosition = Input.mousePosition;
							int num = TMP_TextUtilities.FindIntersectingLink(componentInChildren, mousePosition, Object.FindObjectOfType<Camera>());
							if (num != -1)
							{
								TMP_LinkInfo linkInfo = componentInChildren.textInfo.linkInfo[num];
								if (IsLinkVisible(linkInfo, componentInChildren, ((Component)((Component)messagesText).transform.parent).GetComponent<RectTransform>()))
								{
									string[] array = ((TMP_LinkInfo)(ref linkInfo)).GetLinkID().Split("|".ToCharArray());
									MessageType messageType = (MessageType)int.Parse(array[0]);
									bool flag = false;
									bool flag2 = false;
									Color titleColor = Color.white;
									string text2 = null;
									Color bodyColor = default(Color);
									((Color)(ref bodyColor))..ctor(0.6f, 0.6f, 0.6f, 1f);
									string bodyToken = null;
									string overrideBodyText = null;
									if (messageType == MessageType.Pickup && itemTooltip.Value)
									{
										text2 = array[1];
										int num2 = int.Parse(array[2]);
										flag = tooltipProvider.titleToken == text2 && currentQuantity == num2;
										if (!flag)
										{
											RemoveTooltip(val);
											GenericStaticEnumerable<ItemIndex, AllItemsEnumerator> allItems = ItemCatalog.allItems;
											AllItemsEnumerator enumerator = allItems.GetEnumerator();
											try
											{
												while (((AllItemsEnumerator)(ref enumerator)).MoveNext())
												{
													ItemIndex current2 = ((AllItemsEnumerator)(ref enumerator)).Current;
													ItemDef itemDef = ItemCatalog.GetItemDef(current2);
													if ((Object)(object)itemDef != (Object)null && itemDef.nameToken == text2)
													{
														ItemTierDef itemTierDef = ItemTierCatalog.GetItemTierDef(itemDef.tier);
														if ((Object)(object)itemTierDef != (Object)null)
														{
															titleColor = Color32.op_Implicit(ColorCatalog.GetColor(itemTierDef.darkColorIndex));
															bodyToken = itemDef.pickupToken;
															if (lookingGlassDescription.Value && lookingGlassMethod != null)
															{
																overrideBodyText = (string)lookingGlassMethod.Invoke(null, new object[6] { itemDef, current2, num2, null, false, false });
															}
															flag = true;
															flag2 = true;
														}
													}
												}
											}
											finally
											{
												((IDisposable)(AllItemsEnumerator)(ref enumerator)).Dispose();
											}
											GenericStaticEnumerable<EquipmentIndex, AllEquipmentEnumerator> allEquipment = EquipmentCatalog.allEquipment;
											AllEquipmentEnumerator enumerator2 = allEquipment.GetEnumerator();
											try
											{
												while (((AllEquipmentEnumerator)(ref enumerator2)).MoveNext())
												{
													EquipmentIndex current3 = ((AllEquipmentEnumerator)(ref enumerator2)).Current;
													EquipmentDef equipmentDef = EquipmentCatalog.GetEquipmentDef(current3);
													if ((Object)(object)equipmentDef != (Object)null && equipmentDef.nameToken == text2)
													{
														titleColor = Color32.op_Implicit(ColorCatalog.GetColor(equipmentDef.colorIndex));
														bodyToken = (equipmentFullDescription.Value ? equipmentDef.descriptionToken : equipmentDef.pickupToken);
														flag = true;
														flag2 = true;
													}
												}
											}
											finally
											{
												((IDisposable)(AllEquipmentEnumerator)(ref enumerator2)).Dispose();
											}
											if (flag)
											{
												currentQuantity = num2;
											}
										}
									}
									else if (messageType == MessageType.Achievement && achievementTooltip.Value)
									{
										text2 = array[1];
										flag = tooltipProvider.titleToken == text2;
										if (!flag)
										{
											RemoveTooltip(val);
											GenericStaticEnumerable<AchievementDef, Enumerator> allAchievementDefs = AchievementManager.allAchievementDefs;
											Enumerator enumerator3 = allAchievementDefs.GetEnumerator();
											try
											{
												while (((Enumerator)(ref enumerator3)).MoveNext())
												{
													AchievementDef current4 = ((Enumerator)(ref enumerator3)).Current;
													if (current4.nameToken == text2)
													{
														titleColor = new Color(0.741f, 0.882f, 0.318f);
														bodyToken = current4.descriptionToken;
														flag = true;
														flag2 = true;
													}
												}
											}
											finally
											{
												((IDisposable)(Enumerator)(ref enumerator3)).Dispose();
											}
										}
									}
									if (flag)
									{
										if (flag2)
										{
											tooltipProvider.titleColor = titleColor;
											tooltipProvider.titleToken = text2;
											tooltipProvider.bodyColor = bodyColor;
											tooltipProvider.bodyToken = bodyToken;
											tooltipProvider.overrideBodyText = overrideBodyText;
										}
										TooltipController.SetTooltip(val, tooltipProvider, Vector2.op_Implicit(mousePosition), (RectTransform)null);
										return;
									}
								}
							}
							RemoveTooltip(val);
						}
					}
				}
			};
			harmony.PatchAll();
		}

		private bool IsLinkVisible(TMP_LinkInfo linkInfo, TMP_Text textMesh, RectTransform maskRect)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_001c: 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_0024: 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_0035: 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_003b: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			for (int i = linkInfo.linkTextfirstCharacterIndex; i < linkInfo.linkTextfirstCharacterIndex + linkInfo.linkTextLength; i++)
			{
				TMP_CharacterInfo val = textMesh.textInfo.characterInfo[i];
				Vector3 val2 = textMesh.transform.TransformPoint(val.bottomLeft);
				Vector3 val3 = textMesh.transform.TransformPoint(val.topRight);
				if (!RectTransformUtility.RectangleContainsScreenPoint(maskRect, Vector2.op_Implicit(val2), (Camera)null) || !RectTransformUtility.RectangleContainsScreenPoint(maskRect, Vector2.op_Implicit(val3), (Camera)null))
				{
					return false;
				}
			}
			return true;
		}

		private void RemoveTooltip(MPEventSystem eventSystem)
		{
			tooltipProvider.titleToken = null;
			currentQuantity = -1;
			TooltipController.RemoveTooltip(eventSystem, tooltipProvider);
		}

		public void LinkMessage(ref string result, MessageType messageType, string target, string[] data)
		{
			int num = result.IndexOf(target);
			if (num == -1)
			{
				return;
			}
			string text = "";
			for (int i = 0; i < data.Length; i++)
			{
				if (string.IsNullOrEmpty(text))
				{
					text = "|";
				}
				text = text + data[i] + ((i != data.Length - 1) ? "|" : "");
			}
			string[] obj = new string[8]
			{
				result.Substring(0, num),
				"<link=\"",
				null,
				null,
				null,
				null,
				null,
				null
			};
			int num2 = (int)messageType;
			obj[2] = num2.ToString();
			obj[3] = text;
			obj[4] = "\">";
			obj[5] = target;
			obj[6] = "</link>";
			obj[7] = result.Substring(num + target.Length);
			result = string.Concat(obj);
		}
	}
}
namespace ChatTooltips.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					ResourceManager resourceManager = new ResourceManager("ChatTooltips.Properties.Resources", typeof(Resources).Assembly);
					resourceMan = resourceManager;
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal static Bitmap icon
		{
			get
			{
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Expected O, but got Unknown
				object @object = ResourceManager.GetObject("icon", resourceCulture);
				return (Bitmap)@object;
			}
		}

		internal Resources()
		{
		}
	}
}
namespace ChatTooltips.Patches
{
	[HarmonyPatch(typeof(ChatBox))]
	internal class ChatBoxPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void Start(ChatBox __instance)
		{
			if (!((Object)(object)Run.instance == (Object)null))
			{
				Plugin.instance.messagesText = __instance.messagesText;
			}
		}
	}
	[HarmonyPatch(typeof(SubjectFormatChatMessage))]
	internal class SubjectFormatChatMessage
	{
		[HarmonyPatch("ConstructChatString")]
		[HarmonyPostfix]
		private static void ConstructChatString(SubjectFormatChatMessage __instance, ref string __result)
		{
			if (((SubjectChatMessage)__instance).baseToken.StartsWith("ACHIEVEMENT_UNLOCKED_MESSAGE"))
			{
				Plugin.instance.LinkMessage(ref __result, Plugin.MessageType.Achievement, Language.GetString(__instance.paramTokens[0]), new string[1] { __instance.paramTokens[0] });
			}
		}
	}
	[HarmonyPatch(typeof(PlayerPickupChatMessage))]
	internal class PlayerPickupChatMessagePatch
	{
		[HarmonyPatch("ConstructChatString")]
		[HarmonyPostfix]
		private static void ConstructChatString(PlayerPickupChatMessage __instance, ref string __result)
		{
			Plugin.instance.LinkMessage(ref __result, Plugin.MessageType.Pickup, Language.GetString(__instance.pickupToken), new string[2]
			{
				__instance.pickupToken,
				__instance.pickupQuantity.ToString()
			});
		}
	}
}