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 BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using TeleportWithYourItems.Patches;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("TeleportWithYourItems")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TeleportWithYourItems")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("6261767b-9394-4f76-bde6-a70753c54949")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace TeleportWithYourItems
{
internal static class ModInfo
{
internal const string modGUID = "PixelIndieDev_TeleportWithYourItems";
internal const string modName = "Teleport With Your Items";
internal const string modVersion = "1.0.0.0";
}
[BepInPlugin("PixelIndieDev_TeleportWithYourItems", "Teleport With Your Items", "1.0.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class TeleportPatchBase : BaseUnityPlugin
{
private readonly Harmony harmony = new Harmony("PixelIndieDev_TeleportWithYourItems");
public static TeleportPatchBase instance;
internal ConfigEntry<bool> ConfigEntry_CancelOnTeleport;
internal ConfigEntry<bool> ConfigEntry_CancelOnInverseTeleport;
internal static ManualLogSource logSource;
private void Awake()
{
//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_005a: Expected O, but got Unknown
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Expected O, but got Unknown
//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_0097: Expected O, but got Unknown
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Expected O, but got Unknown
if ((Object)(object)instance == (Object)null)
{
instance = this;
}
logSource = Logger.CreateLogSource("PixelIndieDev_TeleportWithYourItems");
ConfigEntry_CancelOnTeleport = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Keep items when being teleported back to the ship", true, "When enabled, the normal teleporter won't make you drop your items when being teleported back to the ship.");
LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(ConfigEntry_CancelOnTeleport, new BoolCheckBoxOptions
{
RequiresRestart = false
}));
ConfigEntry_CancelOnInverseTeleport = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Keep items when being teleported into the facility", true, "When enabled, the inverse teleporter won't make you drop your items when being teleported into the facility.");
LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(ConfigEntry_CancelOnInverseTeleport, new BoolCheckBoxOptions
{
RequiresRestart = false
}));
harmony.PatchAll(typeof(PlayerControllerBPatch));
harmony.PatchAll(typeof(TeleporterPatch));
harmony.PatchAll(typeof(NetworkPatch));
logSource.LogInfo((object)"Teleport With Your Items (version - 1.0.0.0): patches applied successfully");
}
}
internal static class TeleporterHelper
{
private static readonly Dictionary<ulong, bool> PlayersBeingTeleported = new Dictionary<ulong, bool>();
public static void RemovePlayerFromMap(ulong playerId)
{
PlayersBeingTeleported.Remove(playerId);
}
public static void AddPlayerToMap(ulong playerId, bool value)
{
if (PlayersBeingTeleported.ContainsKey(playerId))
{
PlayersBeingTeleported[playerId] = value;
}
else
{
PlayersBeingTeleported.Add(playerId, value);
}
}
public static bool IsPlayerInTeleporter(ulong playerId, out bool isInverseTeleporter)
{
return PlayersBeingTeleported.TryGetValue(playerId, out isInverseTeleporter);
}
}
}
namespace TeleportWithYourItems.Patches
{
[HarmonyPatch(typeof(NetworkManager))]
internal static class NetworkPatch
{
[HarmonyPostfix]
[HarmonyPatch("SetSingleton")]
private static void RegisterPrefab()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("PixelIndieDev_TeleportWithYourItems Prefab");
((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x3D);
Object.DontDestroyOnLoad((Object)(object)val);
NetworkObject obj = val.AddComponent<NetworkObject>();
typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(obj, GetHash("PixelIndieDev_TeleportWithYourItems"));
NetworkManager.Singleton.PrefabHandler.AddNetworkPrefab(val);
}
private static uint GetHash(string value)
{
return value?.Aggregate(17u, (uint current, char c) => (current * 31) ^ c) ?? 0;
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch
{
[HarmonyPatch("DropAllHeldItemsAndSync")]
[HarmonyPrefix]
[HarmonyPriority(0)]
private static bool SkipDropAllSync(PlayerControllerB __instance)
{
if ((Object)(object)__instance != (Object)null)
{
if (TeleporterHelper.IsPlayerInTeleporter(__instance.playerClientId, out var isInverseTeleporter))
{
TeleporterHelper.RemovePlayerFromMap(__instance.playerClientId);
if (!isInverseTeleporter && TeleportPatchBase.instance.ConfigEntry_CancelOnTeleport.Value)
{
return false;
}
}
else
{
TeleporterHelper.RemovePlayerFromMap(__instance.playerClientId);
}
}
return true;
}
[HarmonyPatch("DropAllHeldItems")]
[HarmonyPrefix]
[HarmonyPriority(0)]
private static bool SkipDropAll(PlayerControllerB __instance)
{
if ((Object)(object)__instance != (Object)null)
{
if (TeleporterHelper.IsPlayerInTeleporter(__instance.playerClientId, out var isInverseTeleporter))
{
TeleporterHelper.RemovePlayerFromMap(__instance.playerClientId);
if (isInverseTeleporter && TeleportPatchBase.instance.ConfigEntry_CancelOnInverseTeleport.Value)
{
return false;
}
}
else
{
TeleporterHelper.RemovePlayerFromMap(__instance.playerClientId);
}
}
return true;
}
}
[HarmonyPatch(typeof(ShipTeleporter))]
internal class TeleporterPatch
{
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
[HarmonyPrefix]
[HarmonyPriority(0)]
private static void BeamUpPrefix(ShipTeleporter __instance)
{
PlayerControllerB targetedPlayer = StartOfRound.Instance.mapScreen.targetedPlayer;
if ((Object)(object)targetedPlayer != (Object)null)
{
TeleporterHelper.AddPlayerToMap(targetedPlayer.playerClientId, value: false);
}
}
[HarmonyPatch("TeleportPlayerOutWithInverseTeleporter")]
[HarmonyPrefix]
[HarmonyPriority(0)]
private static void InversePrefix(int playerObj, Vector3 teleportPos)
{
PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[playerObj];
if ((Object)(object)val != (Object)null)
{
TeleporterHelper.AddPlayerToMap(val.playerClientId, value: true);
}
}
[HarmonyPatch("TeleportPlayerOutWithInverseTeleporter")]
[HarmonyPostfix]
[HarmonyPriority(0)]
private static void InversePostfix(int playerObj, Vector3 teleportPos)
{
PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[playerObj];
if ((Object)(object)val != (Object)null)
{
TeleporterHelper.RemovePlayerFromMap(val.playerClientId);
}
}
}
}