Decompiled source of WarpToInitialPosition v1.0.0

WarpToInitialPosition.dll

Decompiled a day ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("WarpToInitialPosition")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WarpToInitialPosition")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("188200a7-dd9a-4202-95a9-61868746f6cc")]
[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 WarpToInitialPosition;

public class PluginConfig
{
	public static PluginConfig Instance;

	public ConfigEntry<Key> WarpKey;

	public PluginConfig(ConfigFile config)
	{
		Instance = this;
		WarpKey = config.Bind<Key>("General", "WarpKey", (Key)23, "Key used to warp to initial ship position");
	}
}
[BepInPlugin("azumi.WarpToInitialPosition", "WarpToInitialPosition", "1.0.0")]
public class WarpToInitialPositionPlugin : BaseUnityPlugin
{
	public const string ModGUID = "azumi.WarpToInitialPosition";

	public const string ModName = "WarpToInitialPosition";

	public const string ModVersion = "1.0.0";

	internal static WarpToInitialPositionPlugin Instance;

	internal static ManualLogSource Log;

	private Harmony harmony;

	private static bool hasTeleportedAfterSpawn;

	private InputAction warpAction;

	public static PluginConfig ModConfig { get; private set; }

	private void CreateInputAction()
	{
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Expected O, but got Unknown
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		if (warpAction != null)
		{
			warpAction.performed -= OnWarpPerformed;
			warpAction.Disable();
			warpAction.Dispose();
		}
		string text = $"<Keyboard>/{ModConfig.WarpKey.Value}";
		Log.LogInfo((object)("Creating binding: " + text));
		warpAction = new InputAction("Warp", (InputActionType)1, text, (string)null, (string)null, (string)null);
		warpAction.performed += OnWarpPerformed;
		warpAction.Enable();
		Log.LogInfo((object)$"Warp key bound to: {ModConfig.WarpKey.Value}");
	}

	private void OnWarpPerformed(CallbackContext ctx)
	{
		Log.LogInfo((object)"Warp key pressed");
		TryWarpLocalPlayer();
	}

	private void Awake()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		harmony = new Harmony("azumi.WarpToInitialPosition");
		harmony.PatchAll();
		ModConfig = new PluginConfig(((BaseUnityPlugin)this).Config);
		CreateInputAction();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"WarpToInitialPosition loaded");
	}

	public static void TryWarpLocalPlayer()
	{
		//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_008d: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)StartOfRound.Instance == (Object)null || !StartOfRound.Instance.inShipPhase)
		{
			return;
		}
		PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
		if (!((Object)(object)val == (Object)null) && !val.isPlayerDead)
		{
			Transform shipSpawnPoint = GetShipSpawnPoint();
			if ((Object)(object)shipSpawnPoint == (Object)null)
			{
				Log.LogWarning((object)"Failed to find ship spawn point.");
				return;
			}
			Vector3 position = shipSpawnPoint.position;
			val.TeleportPlayer(position, false, 0f, false, true);
			val.isInElevator = true;
			val.isInHangarShipRoom = true;
			val.isInsideFactory = false;
			val.ResetPlayerBloodObjects(true);
			Log.LogInfo((object)$"Warped player {val.playerClientId} to ship.");
		}
	}

	private static Transform GetShipSpawnPoint()
	{
		if ((Object)(object)StartOfRound.Instance == (Object)null)
		{
			return null;
		}
		if (StartOfRound.Instance.playerSpawnPositions == null)
		{
			return null;
		}
		if (StartOfRound.Instance.playerSpawnPositions.Length == 0)
		{
			return null;
		}
		return StartOfRound.Instance.playerSpawnPositions[0];
	}

	public static void ResetSpawnTeleport()
	{
		hasTeleportedAfterSpawn = false;
	}

	public static void TryInitialSpawnTeleport(PlayerControllerB player)
	{
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		if (!hasTeleportedAfterSpawn && !((Object)(object)player == (Object)null) && ((NetworkBehaviour)player).IsOwner && !((Object)(object)StartOfRound.Instance == (Object)null) && StartOfRound.Instance.inShipPhase)
		{
			Transform shipSpawnPoint = GetShipSpawnPoint();
			if (!((Object)(object)shipSpawnPoint == (Object)null))
			{
				hasTeleportedAfterSpawn = true;
				player.TeleportPlayer(shipSpawnPoint.position, false, 0f, false, true);
				player.isInElevator = true;
				player.isInHangarShipRoom = true;
				player.isInsideFactory = false;
				player.ResetPlayerBloodObjects(true);
				Log.LogInfo((object)$"Initial orbit warp applied to player {player.playerClientId}");
			}
		}
	}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatch
{
	[HarmonyPatch("Awake")]
	[HarmonyPostfix]
	private static void ResetTeleportFlag()
	{
		WarpToInitialPositionPlugin.ResetSpawnTeleport();
	}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch
{
	[HarmonyPatch("ConnectClientToPlayerObject")]
	[HarmonyPostfix]
	private static void OnConnectClient(PlayerControllerB __instance)
	{
		WarpToInitialPositionPlugin.TryInitialSpawnTeleport(__instance);
	}

	[HarmonyPatch("SpawnPlayerAnimation")]
	[HarmonyPostfix]
	private static void OnSpawnPlayer(PlayerControllerB __instance)
	{
		WarpToInitialPositionPlugin.TryInitialSpawnTeleport(__instance);
	}
}