Decompiled source of MapTeleport v0.6.0

MapTeleport.dll

Decompiled a year ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MapTeleport;

[BepInPlugin("aedenthorn.MapTeleport", "Map Teleport", "0.6.0")]
public class BepInExPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Minimap), "OnMapLeftClick")]
	private static class OnMapLeftClick_Patch
	{
		private static bool Prefix(Minimap __instance)
		{
			//IL_004c: 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_0071: 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_008d: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Expected O, but got Unknown
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			if (!modEnabled.Value || !CheckKeyHeld(modKey.Value) || !Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				return true;
			}
			Vector3 value = Traverse.Create((object)__instance).Method("ScreenToWorldPoint", new object[1] { Input.mousePosition }).GetValue<Vector3>();
			Dbgl($"trying to teleport from {((Component)Player.m_localPlayer).transform.position} to {value}");
			if (value != Vector3.zero && Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				__instance.SetMapMode((MapMode)1);
				Minimap.instance.m_smallRoot.SetActive(true);
				HMBuildData val = new HMBuildData(value, 1, 1f, false, WorldGenerator.instance);
				Traverse.Create((object)HeightmapBuilder.instance).Method("Build", new object[1] { val }).GetValue();
				value.y = val.m_baseHeights[0];
				Dbgl($"teleporting from {((Component)Player.m_localPlayer).transform.position} to {value}");
				((Character)Player.m_localPlayer).TeleportTo(value, ((Component)Player.m_localPlayer).transform.rotation, true);
			}
			return false;
		}
	}

	[HarmonyPatch(typeof(Terminal), "InputText")]
	private static class InputText_Patch
	{
		private static bool Prefix(Terminal __instance)
		{
			if (!modEnabled.Value)
			{
				return true;
			}
			string text = ((TMP_InputField)__instance.m_input).text;
			if (text.ToLower().Equals("mapteleport reset"))
			{
				((BaseUnityPlugin)context).Config.Reload();
				((BaseUnityPlugin)context).Config.Save();
				Traverse.Create((object)__instance).Method("AddString", new object[1] { text }).GetValue();
				Traverse.Create((object)__instance).Method("AddString", new object[1] { "Map Teleport config reloaded" }).GetValue();
				return false;
			}
			return true;
		}
	}

	private static readonly bool isDebug = true;

	private static BepInExPlugin context;

	public static ConfigEntry<bool> modEnabled;

	public static ConfigEntry<string> modKey;

	public static ConfigEntry<int> nexusID;

	public static void Dbgl(string str = "", bool pref = true)
	{
		if (isDebug)
		{
			Debug.Log((object)((pref ? (typeof(BepInExPlugin).Namespace + " ") : "") + str));
		}
	}

	private void Awake()
	{
		context = this;
		modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable this mod");
		modKey = ((BaseUnityPlugin)this).Config.Bind<string>("General", "ModKey", "left shift", "Modifier key. Use https://docs.unity3d.com/Manual/class-InputManager.html");
		nexusID = ((BaseUnityPlugin)this).Config.Bind<int>("General", "NexusID", 251, "Nexus mod ID for updates");
		if (modEnabled.Value)
		{
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
		}
	}

	private static bool CheckKeyHeld(string value)
	{
		try
		{
			return Input.GetKey(value.ToLower());
		}
		catch
		{
			return false;
		}
	}
}