Decompiled source of EasyPins v1.0.0

EasyPins.dll

Decompiled 3 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Splatform;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("EasyPins")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EasyPins")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2332a7f1-2480-46d8-910b-d751d24a0730")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace RCGaming;

[BepInPlugin("RCGaming.EasyPins", "EasyPins", "1.0.0")]
public class EasyPins : BaseUnityPlugin
{
	public const string PluginGUID = "RCGaming.EasyPins";

	public const string PluginName = "EasyPins";

	public const string PluginVersion = "1.0.0";

	public static ConfigEntry<KeyCode> configMapKey;

	private static ConfigEntry<bool> modEnabled;

	public static string originalHoverText = "";

	private GameObject lastHoverObject;

	private void Awake()
	{
		configMapKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Hotkeys", "HotKey", (KeyCode)289, "Key to press to map the hovered pickable");
		modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ModEnabled", true, "Enable or disable the mod.");
		if (modEnabled.Value)
		{
			Harmony.CreateAndPatchAll(typeof(EasyPins).Assembly, "RCGaming.EasyPins");
		}
	}

	private void Update()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		if (!modEnabled.Value)
		{
			return;
		}
		if (ZInput.GetKeyDown(configMapKey.Value, true))
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			GameObject hoverObject = ((Humanoid)localPlayer).GetHoverObject();
			if ((Object)(object)hoverObject == (Object)null)
			{
				return;
			}
			Pickable componentInParent = hoverObject.GetComponentInParent<Pickable>();
			if ((Object)(object)componentInParent == (Object)null)
			{
				return;
			}
			AddPickableToMap(componentInParent, originalHoverText);
		}
		Player localPlayer2 = Player.m_localPlayer;
		if ((Object)(object)localPlayer2 == (Object)null)
		{
			return;
		}
		GameObject hoverObject2 = ((Humanoid)localPlayer2).GetHoverObject();
		if ((Object)(object)hoverObject2 == (Object)null)
		{
			lastHoverObject = null;
			return;
		}
		Pickable componentInParent2 = hoverObject2.GetComponentInParent<Pickable>();
		if (!((Object)(object)componentInParent2 == (Object)null) && (Object)(object)hoverObject2 != (Object)(object)lastHoverObject)
		{
			originalHoverText = GetOriginalHoverText(componentInParent2);
			lastHoverObject = hoverObject2;
		}
	}

	private bool pinExistsAtPosition(Vector3 position, float maxDistance = 1f)
	{
		//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)
		foreach (PinData minimapPin in getMinimapPins())
		{
			if (Vector3.Distance(minimapPin.m_pos, position) < maxDistance)
			{
				return true;
			}
		}
		return false;
	}

	private List<PinData> getMinimapPins()
	{
		FieldInfo field = typeof(Minimap).GetField("m_pins", BindingFlags.Instance | BindingFlags.NonPublic);
		if (field != null)
		{
			return (List<PinData>)field.GetValue(Minimap.instance);
		}
		return new List<PinData>();
	}

	private string GetOriginalHoverText(Pickable pickable)
	{
		string hoverText = pickable.GetHoverText();
		if (!string.IsNullOrEmpty(hoverText))
		{
			string[] array = hoverText.Split(new char[1] { '\n' });
			if (array.Length > 1)
			{
				return array[0];
			}
		}
		return "Resource";
	}

	private void AddPickableToMap(Pickable pickable, string pinName)
	{
		//IL_001f: 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_0026: 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_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		Minimap instance = Minimap.instance;
		if ((Object)(object)instance == (Object)null || (Object)(object)pickable == (Object)null)
		{
			return;
		}
		Vector3 position = ((Component)pickable).transform.position;
		if (pinExistsAtPosition(position))
		{
			Player localPlayer = Player.m_localPlayer;
			if (localPlayer != null)
			{
				((Character)localPlayer).Message((MessageType)1, "A pin already exists here!", 0, (Sprite)null);
			}
			return;
		}
		instance.AddPin(position, (PinType)3, pinName, true, false, 0L, default(PlatformUserID));
		Player localPlayer2 = Player.m_localPlayer;
		if (localPlayer2 != null)
		{
			((Character)localPlayer2).Message((MessageType)1, "Pin `" + pinName + "` added!", 0, (Sprite)null);
		}
	}
}
[HarmonyPatch(typeof(Pickable), "GetHoverText")]
public static class PickableGetHoverTextPatch
{
	public static void Postfix(Pickable __instance, ref string __result)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		__result += $"\n[<color=yellow>{EasyPins.configMapKey.Value}</color>] Map";
	}
}