Decompiled source of TidyPins v0.1.2

TidyPins.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace TidyPins;

[BepInPlugin("com.burks.tidypins", "Tidy Pins", "0.1.2")]
public class TidyPinsPlugin : BaseUnityPlugin
{
	public const string GUID = "com.burks.tidypins";

	public const string NAME = "Tidy Pins";

	public const string VERSION = "0.1.2";

	public static ManualLogSource Log;

	public static ConfigEntry<bool> HoverNames;

	public static ConfigEntry<bool> HideMinimapNames;

	public static ConfigEntry<bool> KeepPlayerNames;

	public static ConfigEntry<float> HoverRadius;

	public static ConfigEntry<float> IconScale;

	public static ConfigEntry<float> MinimapIconScale;

	public static ConfigEntry<float> HoverGrow;

	public static ConfigEntry<float> CheckedAlpha;

	public static ConfigEntry<float> NameScale;

	public static ConfigEntry<KeyCode> ShowAllKey;

	private bool _on;

	private void Awake()
	{
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Invalid comparison between Unknown and I4
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		HoverNames = ((BaseUnityPlugin)this).Config.Bind<bool>("Names", "OnlyOnHover", true, "On the big map, a pin's name only shows while the mouse is over it.");
		HoverRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Names", "HoverRadius", 22f, "How close the mouse must be to a pin, in pixels (at 1080p).");
		ShowAllKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Names", "ShowAllKey", (KeyCode)308, "Hold this on the big map to show every name at once.");
		HideMinimapNames = ((BaseUnityPlugin)this).Config.Bind<bool>("Names", "HideOnMinimap", true, "Never show pin names on the small corner map.");
		KeepPlayerNames = ((BaseUnityPlugin)this).Config.Bind<bool>("Names", "AlwaysShowPlayerNames", true, "Other players' names, pings and shouts stay visible.");
		NameScale = ((BaseUnityPlugin)this).Config.Bind<float>("Names", "NameScale", 1f, "Size of the name text (1 = game default).");
		IconScale = ((BaseUnityPlugin)this).Config.Bind<float>("Icons", "BigMapIconScale", 0.8f, "Size of pin icons on the big map (1 = game default).");
		MinimapIconScale = ((BaseUnityPlugin)this).Config.Bind<float>("Icons", "MinimapIconScale", 0.8f, "Size of pin icons on the corner map.");
		HoverGrow = ((BaseUnityPlugin)this).Config.Bind<float>("Icons", "HoverGrow", 1.35f, "The pin under the mouse grows by this factor.");
		CheckedAlpha = ((BaseUnityPlugin)this).Config.Bind<float>("Icons", "CrossedOutOpacity", 0.45f, "Crossed-out pins are faded to this opacity (1 = not faded).");
		if ((int)SystemInfo.graphicsDeviceType != 4)
		{
			new Harmony("com.burks.tidypins").PatchAll(Assembly.GetExecutingAssembly());
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Tidy Pins 0.1.2 loaded.");
			_on = true;
		}
	}

	private void LateUpdate()
	{
		if (_on && (Object)(object)Minimap.instance != (Object)null && (Object)(object)Player.m_localPlayer != (Object)null)
		{
			PinsPatch.Apply(Minimap.instance);
		}
	}
}
[HarmonyPatch(typeof(Minimap), "UpdatePins")]
public static class PinsPatch
{
	private static readonly FieldRef<Minimap, List<PinData>> Pins = AccessTools.FieldRefAccess<Minimap, List<PinData>>("m_pins");

	private static bool _warned;

	private static bool Special(PinData p)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Invalid comparison between Unknown and I4
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Invalid comparison between Unknown and I4
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Invalid comparison between Unknown and I4
		if ((int)p.m_type != 10 && (int)p.m_type != 12)
		{
			return (int)p.m_type == 7;
		}
		return true;
	}

	[HarmonyPostfix]
	public static void Postfix(Minimap __instance)
	{
		Apply(__instance);
	}

	public static void Apply(Minimap __instance)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Invalid comparison between Unknown and I4
		//IL_004d: 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)
		//IL_0057: 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_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: 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_010e: 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_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: 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_027a: Unknown result type (might be due to invalid IL or missing references)
		//IL_029a: Unknown result type (might be due to invalid IL or missing references)
		//IL_039d: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			List<PinData> list = Pins.Invoke(__instance);
			if (list == null)
			{
				return;
			}
			bool flag = (int)__instance.m_mode == 2;
			float num = Mathf.Max(0.5f, (float)Screen.height / 1080f);
			float num2 = Mathf.Max(4f, TidyPinsPlugin.HoverRadius.Value) * num;
			Vector2 val = Vector2.op_Implicit(Input.mousePosition);
			bool flag2 = flag && (int)TidyPinsPlugin.ShowAllKey.Value != 0 && Input.GetKey(TidyPinsPlugin.ShowAllKey.Value);
			PinData val2 = null;
			if (flag)
			{
				Camera val3 = null;
				Canvas val4 = (((Object)(object)__instance.m_pinRootLarge != (Object)null) ? ((Component)__instance.m_pinRootLarge).GetComponentInParent<Canvas>() : null);
				if ((Object)(object)val4 != (Object)null && (int)val4.renderMode != 0)
				{
					val3 = val4.worldCamera;
				}
				float num3 = num2 * num2;
				foreach (PinData item in list)
				{
					if (item != null && !((Object)(object)item.m_uiElement == (Object)null) && ((Component)item.m_uiElement).gameObject.activeInHierarchy)
					{
						Vector2 val5 = RectTransformUtility.WorldToScreenPoint(val3, ((Transform)item.m_uiElement).position) - val;
						float sqrMagnitude = ((Vector2)(ref val5)).sqrMagnitude;
						if (sqrMagnitude < num3)
						{
							num3 = sqrMagnitude;
							val2 = item;
						}
					}
				}
			}
			float num4 = Mathf.Clamp(flag ? TidyPinsPlugin.IconScale.Value : TidyPinsPlugin.MinimapIconScale.Value, 0.3f, 3f);
			float num5 = Mathf.Clamp(TidyPinsPlugin.HoverGrow.Value, 1f, 3f);
			float num6 = Mathf.Clamp01(TidyPinsPlugin.CheckedAlpha.Value);
			float num7 = Mathf.Clamp(TidyPinsPlugin.NameScale.Value, 0.4f, 3f);
			Vector3 val6 = default(Vector3);
			Vector3 val9 = default(Vector3);
			foreach (PinData item2 in list)
			{
				if (item2 == null || (Object)(object)item2.m_uiElement == (Object)null)
				{
					continue;
				}
				bool flag3 = Special(item2);
				if (!flag3)
				{
					float num8 = num4 * ((item2 == val2) ? num5 : 1f);
					((Vector3)(ref val6))..ctor(num8, num8, 1f);
					if (((Transform)item2.m_uiElement).localScale != val6)
					{
						((Transform)item2.m_uiElement).localScale = val6;
					}
					if ((Object)(object)item2.m_iconElement != (Object)null)
					{
						Color color = ((Graphic)item2.m_iconElement).color;
						float num9 = ((item2.m_checked && item2 != val2) ? num6 : 1f);
						if (!Mathf.Approximately(color.a, num9))
						{
							color.a = num9;
							((Graphic)item2.m_iconElement).color = color;
						}
					}
				}
				if (item2 == val2)
				{
					((Transform)item2.m_uiElement).SetAsLastSibling();
				}
				PinNameData namePinData = item2.m_NamePinData;
				GameObject val7 = ((namePinData != null) ? namePinData.PinNameGameObject : null);
				if ((Object)(object)val7 == (Object)null)
				{
					continue;
				}
				bool flag4 = (flag3 && TidyPinsPlugin.KeepPlayerNames.Value) || ((!flag) ? (!TidyPinsPlugin.HideMinimapNames.Value) : (!TidyPinsPlugin.HoverNames.Value || flag2 || item2 == val2));
				if (!val7.activeSelf)
				{
					val7.SetActive(true);
				}
				CanvasGroup val8 = val7.GetComponent<CanvasGroup>();
				if ((Object)(object)val8 == (Object)null)
				{
					val8 = val7.AddComponent<CanvasGroup>();
					val8.interactable = false;
					val8.blocksRaycasts = false;
				}
				float num10 = (flag4 ? 1f : 0f);
				if (val8.alpha != num10)
				{
					val8.alpha = num10;
				}
				if (flag4)
				{
					((Vector3)(ref val9))..ctor(num7, num7, 1f);
					if (val7.transform.localScale != val9)
					{
						val7.transform.localScale = val9;
					}
					if (item2 == val2)
					{
						val7.transform.SetAsLastSibling();
					}
				}
			}
		}
		catch (Exception ex)
		{
			if (!_warned)
			{
				_warned = true;
				TidyPinsPlugin.Log.LogWarning((object)("Pin tidy-up failed: " + ex));
			}
		}
	}
}