Decompiled source of BigTeleport v1.0.2

BepInEx/plugins/BigTeleport.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Microsoft.CodeAnalysis;
using Mirror;
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(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("BigTeleport")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Teleport")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("BigTeleport")]
[assembly: AssemblyTitle("BigTeleport")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BigWalkHelloWorld
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "BigTeleport";

		public const string PLUGIN_NAME = "BigTeleport";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}
namespace BigTeleport
{
	[BepInPlugin("markviews.bigTeleport", "Big Teleport", "1.0.2")]
	public class Plugin : BasePlugin
	{
		public static ConfigEntry<float> MinTeleportDistance;

		public static readonly Dictionary<string, string> NameOverrides = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
		{
			{ "HighButton", "TallButtonChallenge" },
			{ "CannonBall", "CannonBallCarry" },
			{ "Basketball", "BasketballChallenge" },
			{ "Coordinates", "CoordinatesSimPress" },
			{ "MediumSimPress", "MediumSimPressChallenge" },
			{ "EasySimPress", "SmallSimPressChallenge" },
			{ "Concert", "ConductorConcert" },
			{ "CenturonSong", "CenturionSong" },
			{ "TelescopeToBox", "FixedTelescopeToGourd" },
			{ "WindowLabyrinth", "Labyrinth" },
			{ "IndoorSemaphore", "SemaphoreRooms" },
			{ "InvisibleInk", "InvisibleInkChallenge" },
			{ "RingRoom", "RingRoomChallenge" },
			{ "TileSoup", "SilentGauntlet 4Player" },
			{ "Maypole", "BlackTower" }
		};

		public static readonly Dictionary<string, Vector3> locations = new Dictionary<string, Vector3>();

		internal static ManualLogSource Log;

		public override void Load()
		{
			//IL_0011: 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)
			//IL_002d: Expected O, but got Unknown
			Log = ((BasePlugin)this).Log;
			new Harmony("markviews.bigTeleport").PatchAll();
			ClassInjector.RegisterTypeInIl2Cpp<ButtonScanner>();
			GameObject val = new GameObject("BigWalkHelloWorld_ButtonScanner");
			Object.DontDestroyOnLoad((Object)(object)val);
			val.AddComponent<ButtonScanner>();
			MinTeleportDistance = ((BasePlugin)this).Config.Bind<float>("General", "Min Distance From Puzzle To Teleport To Map Room", 20f, "How far you have to be from any puzzle to use 'map' teleport command");
		}
	}
	public class ButtonScanner : MonoBehaviour
	{
		private static GameObject prefab;

		private static TextMeshProUGUI chatBox;

		private static TextMeshProUGUI chatOutput;

		private TextMeshProUGUI myOutput;

		private Vector3 mapPosition;

		private PlayerCharacter localPlayer;

		private static readonly string[] SearchRoots = new string[4] { "LandmarksPlayerCount2/Contents", "LandmarksPlayerCount3/Contents", "LandmarksPlayerCount4/Contents", "LandmarksPlayerCountAny" };

		private Coroutine delayCoroutine;

		public ButtonScanner(IntPtr ptr)
			: base(ptr)
		{
		}

		private void Start()
		{
			WorldManager.OnWorldManagerStart += Action.op_Implicit((Action)delegate
			{
				((MonoBehaviour)this).InvokeRepeating("ScanForButton", 0f, 1f);
			});
		}

		private void Update()
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetMouseButtonDown(0))
			{
				if ((Object)(object)localPlayer == (Object)null)
				{
					return;
				}
				PlayerCaster caster = localPlayer.caster;
				if (caster == null)
				{
					return;
				}
				CastableTarget castableTarget = caster.castableTarget;
				if ((Object)(object)castableTarget == (Object)null)
				{
					return;
				}
				if (Plugin.locations.TryGetValue(((Object)((Component)castableTarget).gameObject).name, out var value))
				{
					((MonoBehaviour)this).StartCoroutine(CollectionExtensions.WrapToIl2Cpp(Teleport(localPlayer, value)));
				}
			}
			if ((!Input.GetKeyDown((KeyCode)13) && !Input.GetKeyDown((KeyCode)271)) || (Object)(object)chatBox == (Object)null || (Object)(object)localPlayer == (Object)null || (Object)(object)myOutput == (Object)null)
			{
				return;
			}
			string text = ((TMP_Text)chatBox).text.Replace("\u200b", "").Trim().ToLower();
			if (text.Equals("map") || text.Equals("/map"))
			{
				((MonoBehaviour)this).StartCoroutine(CollectionExtensions.WrapToIl2Cpp(ClearChatbox()));
				float nearestPuzzle = GetNearestPuzzle();
				if (nearestPuzzle < Plugin.MinTeleportDistance.Value)
				{
					float value2 = Mathf.Max(Plugin.MinTeleportDistance.Value - nearestPuzzle, 0.01f);
					ShowMessage($"<color=red>Move {value2:F1}m away from puzzle</color>");
				}
				else
				{
					((MonoBehaviour)this).StartCoroutine(CollectionExtensions.WrapToIl2Cpp(Teleport(localPlayer, mapPosition)));
				}
			}
		}

		private float GetNearestPuzzle()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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)
			string text = null;
			float num = float.MaxValue;
			Vector3 position = ((Component)localPlayer).transform.position;
			foreach (KeyValuePair<string, Vector3> location in Plugin.locations)
			{
				float num2 = Vector3.Distance(position, location.Value);
				if (num2 < num)
				{
					num = num2;
					text = location.Key;
				}
			}
			if (text == null)
			{
				Plugin.Log.LogWarning((object)"GetNearestPuzzle: locations dictionary is empty.");
				return -1f;
			}
			return num;
		}

		private IEnumerator ClearChatbox()
		{
			yield return (object)new WaitForSeconds(0.5f);
			((TMP_Text)chatBox).text = "";
		}

		private void ShowMessage(string message)
		{
			((TMP_Text)myOutput).text = message;
			if (delayCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(delayCoroutine);
			}
			delayCoroutine = ((MonoBehaviour)this).StartCoroutine(CollectionExtensions.WrapToIl2Cpp(DelayClearMessage()));
		}

		private IEnumerator DelayClearMessage()
		{
			yield return (object)new WaitForSeconds(3f);
			((TMP_Text)myOutput).text = "";
			delayCoroutine = null;
		}

		private void CreateMyOutput()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(((Component)chatOutput).gameObject, ((TMP_Text)chatOutput).transform.parent.parent.parent);
			((Object)val).name = "MyModOutput";
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchoredPosition = new Vector2(0f, -80f);
			val.SetActive(true);
			myOutput = val.GetComponent<TextMeshProUGUI>();
			((TMP_Text)myOutput).richText = true;
		}

		private IEnumerator Teleport(PlayerCharacter player, Vector3 pos)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			int attempt = 0;
			bool flag = default(bool);
			while (true)
			{
				attempt++;
				if (attempt >= 10)
				{
					ManualLogSource log = Plugin.Log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(24, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Teleport attempt ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Vector3>(pos);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" FAILED");
					}
					log.LogInfo(val);
					ShowMessage("<color=red>Teleport Failed after 10 attempts</color>");
					break;
				}
				float dist = Vector3.Distance(((Component)player).transform.position, pos);
				if (dist <= 1f)
				{
					break;
				}
				player.grease.Teleport(pos, Quaternion.identity, true);
				yield return null;
			}
			ShowMessage("Teleport Successful");
		}

		private void ScanForButton()
		{
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: 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 ((Object)(object)NetworkClient.localPlayer == (Object)null)
			{
				return;
			}
			GameObject val = GameObject.Find("LandmarksNonChallenge/SpawnCourtyardandHubPlatform/Positioner/TeachingArea/Positioner/ObjectsTeaching/Switch/PushButton/BasicPushButton/PeckSwitchTrigger");
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			GameObject val2 = GameObject.Find("WorldUI/WorldUICanvas/GameOverlay/TextChatInput/LocalInput/Text Area/Text");
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			GameObject val3 = GameObject.Find("WorldUI/WorldUICanvas/GameOverlay/TextChatInput/LocalOutput");
			if ((Object)(object)val3 == (Object)null)
			{
				return;
			}
			GameObject val4 = GameObject.Find("LandmarksNonChallenge/MapRoom/Positioner/TeleportPointMapRoom");
			if ((Object)(object)val4 == (Object)null)
			{
				return;
			}
			GameObject val5 = GameObject.Find("LandmarksNonChallenge/MapRoom/Positioner/MapRoom/RoofParent");
			if (!((Object)(object)val5 == (Object)null))
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val6 = new BepInExInfoLogInterpolatedStringHandler(21, 0, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val6).AppendLiteral("ScanForButton SUCCESS");
				}
				log.LogInfo(val6);
				val5.SetActive(false);
				mapPosition = val4.transform.position;
				chatBox = val2.GetComponent<TextMeshProUGUI>();
				chatOutput = ((Component)val2.transform).GetComponent<TextMeshProUGUI>();
				localPlayer = ((Component)NetworkClient.localPlayer).gameObject.GetComponent<PlayerCharacter>();
				CreateMyOutput();
				val.SetActive(false);
				prefab = Object.Instantiate<GameObject>(val);
				((Component)prefab.transform.Find("CrosshairPosition")).transform.localPosition = Vector3.zero;
				Object.Destroy((Object)(object)((Component)prefab.transform.Find("UpSwitch")).gameObject);
				PeckSwitch component = prefab.GetComponent<PeckSwitch>();
				if ((Object)(object)component != (Object)null)
				{
					Object.Destroy((Object)(object)component);
				}
				PeckEffectMaterialProperty component2 = prefab.GetComponent<PeckEffectMaterialProperty>();
				if ((Object)(object)component2 != (Object)null)
				{
					Object.Destroy((Object)(object)component2);
				}
				PeckEffectAudio component3 = prefab.GetComponent<PeckEffectAudio>();
				if ((Object)(object)component3 != (Object)null)
				{
					Object.Destroy((Object)(object)component3);
				}
				component3 = prefab.GetComponent<PeckEffectAudio>();
				if ((Object)(object)component3 != (Object)null)
				{
					Object.Destroy((Object)(object)component3);
				}
				PeckEffectToggle component4 = prefab.GetComponent<PeckEffectToggle>();
				if ((Object)(object)component4 != (Object)null)
				{
					Object.Destroy((Object)(object)component4);
				}
				val.SetActive(true);
				((MonoBehaviour)this).CancelInvoke("ScanForButton");
				SpawnButtonsOnChildren();
			}
		}

		private void SpawnButtonsOnChildren()
		{
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Expected O, but got Unknown
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Expected O, but got Unknown
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: 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)
			GameObject val = GameObject.Find("LandmarksNonChallenge/MapRoom/Positioner/Map-Relief/GourdMap");
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"GourdMap not found — check the path or make sure it's active in the hierarchy.");
				return;
			}
			Transform[] array = (Transform[])(object)new Transform[SearchRoots.Length];
			bool flag = default(bool);
			for (int i = 0; i < SearchRoots.Length; i++)
			{
				GameObject val2 = GameObject.Find(SearchRoots[i]);
				array[i] = (((Object)(object)val2 != (Object)null) ? val2.transform : null);
				if ((Object)(object)val2 == (Object)null)
				{
					ManualLogSource log = Plugin.Log;
					BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(23, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Search root not found: ");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(SearchRoots[i]);
					}
					log.LogWarning(val3);
				}
			}
			Transform transform = val.transform;
			int childCount = transform.childCount;
			for (int j = 0; j < childCount; j++)
			{
				Transform child = transform.GetChild(j);
				string name = ((Object)child).name;
				Vector3 position = child.position;
				string text = (name.StartsWith("gourd", StringComparison.OrdinalIgnoreCase) ? name.Substring(5) : name);
				if (Plugin.NameOverrides.TryGetValue(text, out var value))
				{
					text = value;
				}
				Transform val4 = null;
				string text2 = null;
				for (int k = 0; k < array.Length; k++)
				{
					if (!((Object)(object)array[k] == (Object)null))
					{
						val4 = FindDescendant(array[k], text);
						if ((Object)(object)val4 != (Object)null)
						{
							text2 = SearchRoots[k];
							break;
						}
					}
				}
				Transform val5 = null;
				if ((Object)(object)val4 != (Object)null)
				{
					val5 = FindTeleportPoint(val4);
					if (!((Object)(object)val5 != (Object)null))
					{
						ManualLogSource log2 = Plugin.Log;
						BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(64, 2, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("[");
							((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(name);
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("] -> matched '");
							((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(text);
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("' but no teleport point found among its children.");
						}
						log2.LogWarning(val3);
					}
				}
				else
				{
					ManualLogSource log3 = Plugin.Log;
					BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(47, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("[");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(name);
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("] -> no match found for '");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(text);
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("' in any search root.");
					}
					log3.LogWarning(val3);
				}
				Transform val6 = val5;
				if ((Object)(object)val6 != (Object)null)
				{
					Plugin.locations[text] = val6.position;
				}
				GameObject val7 = Object.Instantiate<GameObject>(prefab, position, Quaternion.identity);
				((Object)val7).name = text;
				val7.transform.SetParent(child);
				val7.transform.localPosition = Vector3.zero;
				val7.SetActive(true);
			}
		}

		private static Transform FindDescendant(Transform root, string name)
		{
			if ((Object)(object)root == (Object)null)
			{
				return null;
			}
			Il2CppArrayBase<Transform> componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true);
			foreach (Transform item in componentsInChildren)
			{
				if ((Object)(object)item != (Object)(object)root && string.Equals(((Object)item).name, name, StringComparison.OrdinalIgnoreCase))
				{
					return item;
				}
			}
			return null;
		}

		private static Transform FindTeleportPoint(Transform root)
		{
			if ((Object)(object)root == (Object)null)
			{
				return null;
			}
			Il2CppArrayBase<Transform> componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true);
			foreach (Transform item in componentsInChildren)
			{
				if ((Object)(object)item != (Object)(object)root && ((Object)item).name.IndexOf("teleport", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return item;
				}
			}
			return null;
		}
	}
}