Decompiled source of Where Am I v1.1.0

ForceTeleport.dll

Decompiled 3 months ago
using System;
using System.Collections;
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 ForceTeleportMod.patches;
using ForceTeleportMod.patches.networking;
using GameNetcodeStuff;
using HarmonyLib;
using LethalNetworkAPI;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
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("ForceTeleport")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Force Teleport")]
[assembly: AssemblyTitle("ForceTeleport")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ForceTeleportMod
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("Zmodding-ForceTeleportMod", "ForceTeleportMod", "1.0.0")]
	public class Main : BaseUnityPlugin
	{
		private static Main instance;

		private const string GUID = "Zmodding-ForceTeleportMod";

		private const string NAME = "ForceTeleportMod";

		private const string VERSION = "1.0.0";

		internal static ManualLogSource cout;

		private readonly Harmony harmony = new Harmony("Zmodding-ForceTeleportMod");

		private void Awake()
		{
			cout = ((BaseUnityPlugin)this).Logger;
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			NetManager.Init();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Zmodding-ForceTeleportMod is loaded!");
			harmony.PatchAll(typeof(Main));
			harmony.PatchAll(typeof(ForceTeleportPatch));
			harmony.PatchAll(typeof(ForceTeleport));
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ForceTeleport";

		public const string PLUGIN_NAME = "Force Teleport";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace ForceTeleportMod.patches
{
	[HarmonyPatch(typeof(RoundManager))]
	internal class ForceTeleport : MonoBehaviour
	{
		private static readonly ManualLogSource cout = Main.cout;

		private static PlayerControllerB selectedPlayer;

		private static Random shipTeleporterSeed;

		private static Vector3 teleportPosition;

		public void TeleportPlayer()
		{
			cout.LogDebug((object)"begining teleport player sequence");
			SetRandomTeleportPosition();
			SetTeleportConditions();
			((MonoBehaviour)this).StartCoroutine(Teleport());
			cout.LogDebug((object)"ending teleport player sequence");
			cout.LogInfo((object)"wait, where am i?");
		}

		private IEnumerator Teleport()
		{
			Random rand = new Random();
			yield return (object)new WaitForSeconds((float)(int)(3.0 + 6.0 * rand.NextDouble()));
			cout.LogDebug((object)"teleporting all players now");
			selectedPlayer.TeleportPlayer(teleportPosition, false, 0f, false, true);
			selectedPlayer.beamOutParticle.Play();
			Debug.Log((object)"Teleporter shaking camera");
			HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
		}

		private void SetTeleportConditions(bool isInElevator = false, bool isInHangarShipRoom = false, bool isInsideFactory = true, float averageVelocity = 0f)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			cout.LogDebug((object)"setting teleport conditions");
			selectedPlayer.isInElevator = isInElevator;
			selectedPlayer.isInHangarShipRoom = isInHangarShipRoom;
			selectedPlayer.isInsideFactory = isInsideFactory;
			selectedPlayer.averageVelocity = averageVelocity;
			selectedPlayer.velocityLastFrame = Vector3.zero;
		}

		private void SetRandomTeleportPosition()
		{
			//IL_003f: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			cout.LogDebug((object)"setting random teleport position");
			SetRandomSeed();
			teleportPosition = RoundManager.Instance.insideAINodes[shipTeleporterSeed.Next(0, RoundManager.Instance.insideAINodes.Length)].transform.position;
			Debug.DrawRay(teleportPosition, Vector3.up * 1f, Color.red);
			teleportPosition = RoundManager.Instance.GetRandomNavMeshPositionInBoxPredictable(teleportPosition, 10f, default(NavMeshHit), shipTeleporterSeed, -1);
			Debug.DrawRay(teleportPosition + Vector3.right * 0.01f, Vector3.up * 3f, Color.green);
		}

		public void SetSelectedPlayer(ulong clientId)
		{
			cout.LogDebug((object)"setting selected player for teleportation");
			selectedPlayer = LethalNetworkExtensions.GetPlayerController(clientId);
		}

		private void SetRandomSeed()
		{
			cout.LogDebug((object)"setting random seed");
			shipTeleporterSeed = new Random(StartOfRound.Instance.randomMapSeed + 17 + (int)GameNetworkManager.Instance.localPlayerController.playerClientId);
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal class ForceTeleportPatch
	{
		[HarmonyPatch("Update")]
		[HarmonyILManipulator]
		private static void PatchUpdate(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			val.GotoNext(new Func<Instruction, bool>[5]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 1),
				(Instruction x) => ILPatternMatchingExt.MatchStfld<RoundManager>(x, "begunSpawningEnemies"),
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchCall<RoundManager>(x, "BeginEnemySpawning")
			});
			val.Emit(OpCodes.Ldarg_0);
			val.EmitDelegate<Action<RoundManager>>((Action<RoundManager>)delegate
			{
				Main.cout.LogDebug((object)"teleporting now...");
				NetManager.lethalEvent.InvokeClients();
				Main.cout.LogDebug((object)"successful teleport");
			});
		}
	}
}
namespace ForceTeleportMod.patches.networking
{
	internal static class NetManager
	{
		private static readonly ManualLogSource cout = Main.cout;

		[PublicNetworkVariable]
		public static LNetworkEvent lethalEvent = new LNetworkEvent("FTEevent", (Action<ulong>)null, (Action)null, (Action<ulong>)null);

		public static ForceTeleport ForceTeleport;

		public static void Init()
		{
			cout.LogInfo((object)"initializing NetManager");
			lethalEvent.OnClientReceived += TeleportEvent;
			cout.LogInfo((object)"NetManager initialized!");
		}

		private static void TeleportEvent()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			cout.LogDebug((object)"TeleportEvent begining...");
			ulong actualClientId = GameNetworkManager.Instance.localPlayerController.actualClientId;
			GameObject val = new GameObject();
			ForceTeleport = val.AddComponent<ForceTeleport>();
			ForceTeleport.SetSelectedPlayer(actualClientId);
			ForceTeleport.TeleportPlayer();
			cout.LogDebug((object)"TeleportEvent ended");
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}