Decompiled source of TeleportYourself v0.0.9

teleport.dll

Decompiled 7 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using GameNetcodeStuff;
using HarmonyLib;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("teleport")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("teleport")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("6903eff3-7839-4ca9-862c-ea0a372128e6")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace TeleportYourself;

[BepInPlugin("nexor.TeleportYourself", "TeleportYourself", "0.0.9")]
public class TeleportYourself : BaseUnityPlugin
{
	private const string modGUID = "nexor.TeleportYourself";

	private const string modName = "TeleportYourself";

	private const string modVersion = "0.0.9";

	private readonly Harmony harmony = new Harmony("nexor.TeleportYourself");

	public ConfigEntry<string> teleportKey;

	public static TeleportYourself Instance;

	public float teleportCooldown = 240f;

	public float lastTeleportTime;

	private void Awake()
	{
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
		}
		teleportKey = ((BaseUnityPlugin)this).Config.Bind<string>("Teleport Yourself Config", "Teleport Key(传送键)", "V", "Which key to press to trigger teleportation, supports letter keys and F1,F2... If the value is invalid then the default V will be used.(摁哪个键触发传送,支持字母键和F1,F2...如果是无效值则会使用默认V)");
		harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)("TeleportYourself " + "0.0.9 loaded."));
	}
}
[HarmonyPatch(typeof(HUDManager), "Update")]
internal class HUDPatch
{
	private static Key teleportKey;

	static HUDPatch()
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		TeleportYourself.Instance.lastTeleportTime = 0f - TeleportYourself.Instance.teleportCooldown;
		if (!Enum.TryParse<Key>(TeleportYourself.Instance.teleportKey.Value, ignoreCase: true, out teleportKey))
		{
			teleportKey = (Key)36;
		}
	}

	[HarmonyPostfix]
	public static void UpdatePatch()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		if (!((ButtonControl)Keyboard.current[teleportKey]).wasPressedThisFrame)
		{
			return;
		}
		PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
		if (!localPlayerController.isTypingChat && !localPlayerController.inTerminalMenu)
		{
			if (Time.time - TeleportYourself.Instance.lastTeleportTime >= TeleportYourself.Instance.teleportCooldown)
			{
				((MonoBehaviour)localPlayerController).StartCoroutine(DelayedTeleport());
			}
			else
			{
				HUDManager.Instance.DisplayTip("Warning!", "Teleport is on " + (int)(TeleportYourself.Instance.teleportCooldown - Time.time + TeleportYourself.Instance.lastTeleportTime) + " seconds's cooldown. Please wait.", false, false, "LC_Tip1");
			}
		}
	}

	private static IEnumerator DelayedTeleport()
	{
		List<ShipTeleporter> teleporters = Object.FindObjectsOfType<ShipTeleporter>().ToList();
		teleporters.RemoveAll((ShipTeleporter t) => t.isInverseTeleporter);
		if (teleporters.Count == 0)
		{
			HUDManager.Instance.DisplayTip("Warning!", "No Teleporter!", false, false, "LC_Tip1");
			yield break;
		}
		if (!teleporters[0].buttonTrigger.interactable)
		{
			HUDManager.Instance.DisplayTip("Warning!", "Teleport Button cant be used right now.", false, false, "LC_Tip1");
			yield break;
		}
		TeleportYourself.Instance.lastTeleportTime = Time.time;
		PlayerControllerB old = StartOfRound.Instance.mapScreen.targetedPlayer;
		int old_id = 0;
		int my_id = 0;
		for (int i = 0; i < StartOfRound.Instance.mapScreen.radarTargets.Count; i++)
		{
			PlayerControllerB now = ((Component)StartOfRound.Instance.mapScreen.radarTargets[i].transform).gameObject.GetComponent<PlayerControllerB>();
			if ((Object)(object)now == (Object)(object)StartOfRound.Instance.localPlayerController)
			{
				my_id = i;
			}
			if ((Object)(object)now == (Object)(object)old)
			{
				old_id = i;
			}
		}
		StartOfRound.Instance.mapScreen.SwitchRadarTargetServerRpc(my_id);
		yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)StartOfRound.Instance.mapScreen.targetedPlayer == (Object)(object)StartOfRound.Instance.localPlayerController));
		teleporters[0].PressTeleportButtonOnLocalClient();
		StartOfRound.Instance.mapScreen.SwitchRadarTargetServerRpc(old_id);
	}
}
[HarmonyPatch(typeof(StartOfRound), "Awake")]
internal class StartOfRound_Awake_Patch
{
	[HarmonyPostfix]
	public static void Postfix()
	{
		TeleportYourself.Instance.lastTeleportTime = 0f - TeleportYourself.Instance.teleportCooldown;
	}
}