Decompiled source of DudeWheresMyPortal v0.2.1

plugins/DWMP.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
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("DWMP")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DWMP")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ee0ccb4c-4389-47c4-967d-f37b5dbe65b1")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace DWMP;

[BepInPlugin("com.oathorse.DWMP", "Dude, Where's My Portal", "0.2.1")]
public class DWMP : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Player), "PlacePiece", new Type[]
	{
		typeof(Piece),
		typeof(Vector3),
		typeof(Quaternion),
		typeof(bool),
		typeof(bool)
	})]
	public static class Player_PlacePiece_Patch
	{
		public static void Postfix(Player __instance, Piece piece, Vector3 pos, Quaternion rot, bool doAttack)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			if (Enabled.Value && (Object)(object)piece != (Object)null && (((Object)piece).name == "portal_wood" || ((Object)piece).name == "portal_stone"))
			{
				AddPortalPin(pos);
			}
		}
	}

	[HarmonyPatch(typeof(Piece), "DropResources")]
	public static class Piece_DropResources_Patch
	{
		public static void Postfix(Piece __instance)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			if (Enabled.Value)
			{
				Vector3 position = ((Component)__instance).transform.position;
				if ((Object)(object)((Component)__instance).GetComponent<TeleportWorld>() != (Object)null)
				{
					RemovePortalPin(position);
				}
			}
		}
	}

	[HarmonyPatch(typeof(TeleportWorld), "SetText")]
	public static class TeleportWorld_SetText_Patch
	{
		public static void Postfix(TeleportWorld __instance, string text)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance != (Object)null && Enabled.Value)
			{
				RenamePortalPin(((Component)__instance).transform.position, text);
			}
		}
	}

	[HarmonyPatch(typeof(TeleportWorld), "Teleport")]
	public static class TeleportWorld_Teleport_Patch
	{
		public static void Postfix(TeleportWorld __instance, Player player, ZNetView ___m_nview)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance == (Object)null) && Enabled.Value && CreatePinOnTeleport.Value)
			{
				RenamePortalPin(((Component)__instance).transform.position, __instance.GetText());
				ZDO zDO = ZDOMan.instance.GetZDO(___m_nview.GetZDO().GetConnectionZDOID((ConnectionType)1));
				if (zDO != null)
				{
					string text = zDO.GetString(ZDOVars.s_tag, "");
					RenamePortalPin(zDO.GetPosition(), text);
				}
			}
		}
	}

	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static ConsoleEventFailable <>9__8_0;

		internal object <AddConsoleCommands>b__8_0(ConsoleEventArgs args)
		{
			if (!Object.op_Implicit((Object)(object)Game.instance))
			{
				return true;
			}
			CreatePinOnTeleport.Value = !CreatePinOnTeleport.Value;
			if (Object.op_Implicit((Object)(object)Chat.instance))
			{
				if (CreatePinOnTeleport.Value)
				{
					((Terminal)Chat.instance).AddString("CreatePinOnTeleport ENABLED!");
				}
				else
				{
					((Terminal)Chat.instance).AddString("CreatePinOnTeleport DISABLED!");
				}
			}
			return true;
		}
	}

	public const string PluginGUID = "com.oathorse.DWMP";

	public const string PluginName = "Dude, Where's My Portal";

	public const string PluginVersion = "0.2.1";

	private readonly Harmony harmony = new Harmony("com.oathorse.DWMP");

	private List<PinData> __m_pins = new List<PinData>();

	public static ConfigEntry<bool> Enabled;

	public static ConfigEntry<bool> CreatePinOnTeleport;

	public void Awake()
	{
		Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable the mod, adding/updating pins for placed, removed or renamed portals");
		CreatePinOnTeleport = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Create Pin On Teleport", false, "Also add/update a portal pin to the minimap for each portal you pass through");
		harmony.PatchAll();
		AddConsoleCommands();
	}

	public static void AddConsoleCommands()
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: 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_0029: Expected O, but got Unknown
		object obj = <>c.<>9__8_0;
		if (obj == null)
		{
			ConsoleEventFailable val = delegate
			{
				if (!Object.op_Implicit((Object)(object)Game.instance))
				{
					return true;
				}
				CreatePinOnTeleport.Value = !CreatePinOnTeleport.Value;
				if (Object.op_Implicit((Object)(object)Chat.instance))
				{
					if (CreatePinOnTeleport.Value)
					{
						((Terminal)Chat.instance).AddString("CreatePinOnTeleport ENABLED!");
					}
					else
					{
						((Terminal)Chat.instance).AddString("CreatePinOnTeleport DISABLED!");
					}
				}
				return true;
			};
			<>c.<>9__8_0 = val;
			obj = (object)val;
		}
		new ConsoleCommand("createpinonteleport", "Add a portal pin to the minimap for each portal you pass through", (ConsoleEventFailable)obj, false, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
	}

	private static void AddPortalPin(Vector3 pos, string text = "")
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		Minimap.instance.AddPin(pos, (PinType)6, text, true, false, 0L, default(PlatformUserID));
	}

	private static void RemovePortalPin(Vector3 pos)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		PinData closestPin = Minimap.instance.GetClosestPin(pos, 0.1f, false);
		if (closestPin != null)
		{
			Minimap.instance.RemovePin(closestPin);
		}
	}

	private static void RenamePortalPin(Vector3 pos, string text)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		RemovePortalPin(pos);
		AddPortalPin(pos, text);
	}
}