Decompiled source of ANYWHERE v1.0.5

RandomTeleport.dll

Decompiled 10 hours ago
using System;
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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("radsi")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("testing")]
[assembly: AssemblyTitle("testing")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 testing
{
	[BepInPlugin("radsi.randomteleport", "RandomTeleport", "1.0")]
	public class RandomTeleport : BaseUnityPlugin
	{
		internal static RandomTeleport Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		private void Awake()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID).PatchAll();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} loaded!");
		}
	}
	public class ANYWHERE : MonoBehaviour
	{
		private ItemToggle? itemToggle;

		private ItemBattery? itemBattery;

		private PhysGrabObject? physGrabObject;

		public PhotonView photonView;

		private List<Vector3> possiblePoints;

		private FieldInfo playerToggleField;

		private void Start()
		{
			itemToggle = ((Component)this).GetComponent<ItemToggle>();
			itemBattery = ((Component)this).GetComponent<ItemBattery>();
			physGrabObject = ((Component)this).GetComponent<PhysGrabObject>();
			photonView = ((Component)this).GetComponent<PhotonView>();
		}

		private void Update()
		{
			if (itemToggle.toggleState && !(itemBattery.batteryLife <= 0f))
			{
				itemToggle.toggleState = false;
				itemBattery.Drain(500f);
				if (possiblePoints == null)
				{
					BuildPossiblePointsCache();
				}
				if (playerToggleField == null)
				{
					playerToggleField = typeof(ItemToggle).GetField("playerTogglePhotonID", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				}
				int num = (int)playerToggleField.GetValue(itemToggle);
				if (GameManager.Multiplayer())
				{
					photonView.RPC("RequestTeleportRPC", (RpcTarget)2, new object[1] { num });
				}
				else
				{
					TeleportPlayerLocal(num);
				}
			}
		}

		private void BuildPossiblePointsCache()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			possiblePoints = new List<Vector3>();
			ExtractionPoint[] array = Object.FindObjectsOfType<ExtractionPoint>();
			DirtFinderMapFloor[] array2 = Object.FindObjectsOfType<DirtFinderMapFloor>();
			DirtFinderMapFloor[] array3 = array2;
			foreach (DirtFinderMapFloor val in array3)
			{
				Vector3 position = ((Component)val).transform.position;
				if (Vector3.Distance(Vector3.zero, position) <= 40f)
				{
					continue;
				}
				bool flag = true;
				ExtractionPoint[] array4 = array;
				foreach (ExtractionPoint val2 in array4)
				{
					if (Vector3.Distance(((Component)val2).transform.position, position) <= 10f)
					{
						flag = false;
						break;
					}
				}
				if (flag)
				{
					possiblePoints.Add(position);
				}
			}
		}

		private Vector3 GetRandomMapPos()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = possiblePoints[Random.Range(0, possiblePoints.Count)];
			NavMeshHit val2 = default(NavMeshHit);
			return NavMesh.SamplePosition(val, ref val2, 999f, -1) ? ((NavMeshHit)(ref val2)).position : Vector3.zero;
		}

		[PunRPC]
		private void RequestTeleportRPC(int photonId, PhotonMessageInfo info)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if (PhotonNetwork.IsMasterClient)
			{
				Vector3 randomMapPos = GetRandomMapPos();
				photonView.RPC("ExecuteTeleportRPC", (RpcTarget)0, new object[2] { photonId, randomMapPos });
			}
		}

		[PunRPC]
		private void ExecuteTeleportRPC(int photonId, Vector3 targetPos)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			PlayerAvatar val = SemiFunc.PlayerAvatarGetFromPhotonID(photonId);
			val.Spawn(targetPos, Quaternion.identity);
			if (val.photonView.IsMine)
			{
				((Component)PlayerController.instance).GetComponent<Rigidbody>().MovePosition(targetPos);
			}
			if ((Object)(object)physGrabObject != (Object)null)
			{
				physGrabObject.Teleport(targetPos, ((Component)this).transform.rotation);
			}
		}

		private void TeleportPlayerLocal(int photonId)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			Vector3 randomMapPos = GetRandomMapPos();
			PlayerAvatar.instance.Spawn(randomMapPos, Quaternion.identity);
			((Component)PlayerController.instance).GetComponent<Rigidbody>().MovePosition(randomMapPos);
			if ((Object)(object)physGrabObject != (Object)null)
			{
				physGrabObject.Teleport(randomMapPos, ((Component)this).transform.rotation);
			}
		}
	}
	internal class RandomTeleportPatches
	{
		[HarmonyPatch(typeof(ItemToggle))]
		private static class ItemTogglePatch
		{
			[HarmonyPostfix]
			[HarmonyPatch("Start")]
			private static void StartPostfix(ItemToggle __instance)
			{
				if (((Object)__instance).name.Contains("A.N.Y.W.H.E.R.E"))
				{
					((Component)__instance).gameObject.AddComponent<ANYWHERE>();
				}
			}
		}
	}
}