Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of TeleporterFix v1.0.0
BepInEx/plugins/TeleporterFix/TeleporterFix.dll
Decompiled 5 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("TeleporterFix")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("TeleporterFix")] [assembly: AssemblyTitle("TeleporterFix")] [assembly: AssemblyVersion("1.0.0.0")] [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 TeleporterFix { internal static class MyPluginInfo { public const string PLUGIN_GUID = "ivanmods.TeleporterFix"; public const string PLUGIN_NAME = "TeleporterFix"; public const string PLUGIN_VERSION = "1.0.0"; } [BepInPlugin("ivanmods.TeleporterFix", "TeleporterFix", "1.0.0")] public class Plugin : BaseUnityPlugin { internal static ManualLogSource Log = null; private static readonly Harmony Harmony = new Harmony("ivanmods.TeleporterFix"); private void Awake() { Log = ((BaseUnityPlugin)this).Logger; Harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"TeleporterFix v1.0.0 loaded!"); } } internal static class TeleportContext { internal static readonly HashSet<ulong> RegularTeleporting = new HashSet<ulong>(); internal static readonly HashSet<ulong> InverseTeleporting = new HashSet<ulong>(); internal static readonly Dictionary<ulong, GrabbableObject?[]> SavedSlots = new Dictionary<ulong, GrabbableObject[]>(); internal static bool IsRegularTeleporting(PlayerControllerB player) { return RegularTeleporting.Contains(player.playerClientId); } internal static bool IsInverseTeleporting(PlayerControllerB player) { return InverseTeleporting.Contains(player.playerClientId); } internal static void Clear(PlayerControllerB player) { ulong playerClientId = player.playerClientId; RegularTeleporting.Remove(playerClientId); InverseTeleporting.Remove(playerClientId); SavedSlots.Remove(playerClientId); } } } namespace TeleporterFix.Patches { [HarmonyPatch(typeof(ShipTeleporter), "PressTeleportButtonOnLocalClient")] internal static class CooldownPatch { private static void Postfix(ShipTeleporter __instance, ref float ___cooldownTime, ref float ___cooldownAmount) { ___cooldownTime = 5f; ___cooldownAmount = 5f; } } [HarmonyPatch(typeof(ShipTeleporter), "SetPlayerTeleporterId")] internal static class TrackTeleportPatch { private static void Prefix(ShipTeleporter __instance, PlayerControllerB playerScript, int teleporterId) { if ((Object)(object)playerScript == (Object)null) { return; } switch (teleporterId) { case 1: if (__instance.isInverseTeleporter) { TeleportContext.InverseTeleporting.Add(playerScript.playerClientId); } else { TeleportContext.RegularTeleporting.Add(playerScript.playerClientId); } break; case -1: TeleportContext.Clear(playerScript); break; } } } [HarmonyPatch(typeof(PlayerControllerB), "DropAllHeldItems")] internal static class DropAllHeldItemsPatch { private static void Prefix(PlayerControllerB __instance) { ItemSaver.Save(__instance); } private static void Postfix(PlayerControllerB __instance) { ItemSaver.Restore(__instance); } } [HarmonyPatch(typeof(PlayerControllerB), "DropAllHeldItemsAndSync")] internal static class DropAllHeldItemsAndSyncPatch { private static void Prefix(PlayerControllerB __instance) { ItemSaver.Save(__instance); } private static void Postfix(PlayerControllerB __instance) { ItemSaver.Restore(__instance); } } internal static class ItemSaver { private static readonly HashSet<string> EquipmentNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Shovel", "Stop sign", "Yield sign", "Weed killer", "Walkie-talkie", "Flashlight", "Pro-flashlight" }; private static bool IsEquipment(GrabbableObject item) { if ((Object)(object)item.itemProperties != (Object)null) { return EquipmentNames.Contains(item.itemProperties.itemName); } return false; } internal static void Save(PlayerControllerB player) { bool flag = TeleportContext.IsRegularTeleporting(player); bool flag2 = TeleportContext.IsInverseTeleporting(player); if (!flag && !flag2) { return; } GrabbableObject[] itemSlots = player.ItemSlots; GrabbableObject[] array = (GrabbableObject[])(object)new GrabbableObject[itemSlots.Length]; bool flag3 = false; for (int i = 0; i < itemSlots.Length; i++) { GrabbableObject val = itemSlots[i]; if (!((Object)(object)val == (Object)null) && (flag2 || (flag && IsEquipment(val)))) { array[i] = val; itemSlots[i] = null; flag3 = true; } } if (flag3) { TeleportContext.SavedSlots[player.playerClientId] = array; Plugin.Log.LogInfo((object)$"[TeleporterFix] Saved items for player {player.playerClientId} (inverse={flag2})"); } } internal static void Restore(PlayerControllerB player) { if (!TeleportContext.SavedSlots.TryGetValue(player.playerClientId, out GrabbableObject[] value)) { return; } GrabbableObject[] itemSlots = player.ItemSlots; for (int i = 0; i < value.Length && i < itemSlots.Length; i++) { GrabbableObject val = value[i]; if (!((Object)(object)val == (Object)null)) { itemSlots[i] = val; val.isHeld = true; val.playerHeldBy = player; val.hasHitGround = false; val.EnablePhysics(false); if ((Object)(object)val.parentObject != (Object)null) { ((Component)val).transform.SetParent(val.parentObject, false); } } } TeleportContext.SavedSlots.Remove(player.playerClientId); Plugin.Log.LogInfo((object)$"[TeleporterFix] Restored items for player {player.playerClientId}"); } } }