using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("NicerTeleporters")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NicerTeleporters")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("70cb27b0-8de2-449b-9992-aadcd6903262")]
[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 NicerTeleporters
{
[BepInPlugin("MV.NicerTeleporters", "NicerTeleporters", "1.1.1")]
public class NicerTeleportersBase : BaseUnityPlugin
{
public const string modGUID = "MV.NicerTeleporters";
public const string modName = "NicerTeleporters";
public const string modVersion = "1.1.1";
private readonly Harmony harmony = new Harmony("MV.NicerTeleporters");
private static NicerTeleportersBase instance;
private ManualLogSource mls;
private void Awake()
{
if ((Object)(object)instance == (Object)null)
{
instance = this;
}
mls = Logger.CreateLogSource("MV.NicerTeleporters");
harmony.PatchAll();
mls.LogInfo((object)"Patched NicerTeleporters.");
}
}
internal class Utils
{
internal static void dropMostHeldItems(ref PlayerControllerB __instance, bool itemsFall = true, bool disconnecting = false)
{
MethodInfo method = typeof(PlayerControllerB).GetMethod("SetSpecialGrabAnimationBool", BindingFlags.Instance | BindingFlags.NonPublic);
float num = 1f;
for (int i = 0; i < __instance.ItemSlots.Length; i++)
{
GrabbableObject val = __instance.ItemSlots[i];
if ((Object)(object)val != (Object)null)
{
num += Mathf.Clamp(val.itemProperties.weight - 1f, 0f, 10f);
}
}
if (__instance.isHoldingObject)
{
__instance.isHoldingObject = false;
if ((Object)(object)__instance.currentlyHeldObjectServer != (Object)null)
{
method.Invoke(__instance, new object[2] { false, __instance.currentlyHeldObjectServer });
}
__instance.playerBodyAnimator.SetBool("cancelHolding", true);
__instance.playerBodyAnimator.SetTrigger("Throw");
}
__instance.activatingItem = false;
__instance.carryWeight = num;
__instance.twoHanded = false;
__instance.currentlyHeldObjectServer = null;
}
}
}
namespace NicerTeleporters.Patches
{
[HarmonyPatch]
internal class CommonPatch
{
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatch
{
private static FieldInfo cooldownProp = typeof(ShipTeleporter).GetField("cooldownTime", BindingFlags.Instance | BindingFlags.NonPublic);
[HarmonyPatch("StartGame")]
[HarmonyPostfix]
private static void StartGame()
{
ResetCooldown();
}
[HarmonyPatch("EndOfGame")]
[HarmonyPostfix]
private static void EndOfGame()
{
ResetCooldown();
}
[HarmonyPatch("EndOfGameClientRpc")]
[HarmonyPostfix]
private static void EndOfGameClientRpc()
{
ResetCooldown();
}
private static void ResetCooldown()
{
ShipTeleporter[] array = Object.FindObjectsOfType<ShipTeleporter>();
ShipTeleporter[] array2 = array;
foreach (ShipTeleporter obj in array2)
{
cooldownProp.SetValue(obj, 0f);
}
}
}
}
[HarmonyPatch]
internal class InverseTeleporterPatch
{
[HarmonyPrefix]
[HarmonyPatch(typeof(ShipTeleporter), "Awake")]
private static void Awake(ShipTeleporter __instance)
{
if (__instance.isInverseTeleporter)
{
__instance.cooldownAmount = 3f;
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(ShipTeleporter), "TeleportPlayerOutWithInverseTeleporter")]
private static bool inverseTeleport(int playerObj, ref Vector3 teleportPos, ShipTeleporter __instance)
{
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
MethodInfo method = typeof(ShipTeleporter).GetMethod("teleportBodyOut", BindingFlags.Instance | BindingFlags.NonPublic);
MethodInfo method2 = typeof(ShipTeleporter).GetMethod("SetPlayerTeleporterId", BindingFlags.Instance | BindingFlags.NonPublic);
if (StartOfRound.Instance.allPlayerScripts[playerObj].isPlayerDead)
{
((MonoBehaviour)__instance).StartCoroutine((IEnumerator)method.Invoke(__instance, new object[2] { playerObj, teleportPos }));
return false;
}
PlayerControllerB __instance2 = StartOfRound.Instance.allPlayerScripts[playerObj];
method2.Invoke(__instance, new object[2] { __instance2, -1 });
Utils.dropMostHeldItems(ref __instance2);
if (Object.op_Implicit((Object)(object)Object.FindObjectOfType<AudioReverbPresets>()))
{
Object.FindObjectOfType<AudioReverbPresets>().audioPresets[2].ChangeAudioReverbForPlayer(__instance2);
}
__instance2.isInElevator = false;
__instance2.isInHangarShipRoom = false;
__instance2.isInsideFactory = true;
__instance2.averageVelocity = 0f;
__instance2.velocityLastFrame = Vector3.zero;
StartOfRound.Instance.allPlayerScripts[playerObj].TeleportPlayer(teleportPos, false, 0f, false, true);
StartOfRound.Instance.allPlayerScripts[playerObj].beamOutParticle.Play();
__instance.shipTeleporterAudio.PlayOneShot(__instance.teleporterBeamUpSFX);
StartOfRound.Instance.allPlayerScripts[playerObj].movementAudio.PlayOneShot(__instance.teleporterBeamUpSFX);
if ((Object)(object)__instance2 == (Object)(object)GameNetworkManager.Instance.localPlayerController)
{
Debug.Log((object)"Teleporter shaking camera");
HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
}
return false;
}
}
[HarmonyPatch]
internal class TeleporterPatch
{
[HarmonyTranspiler]
[HarmonyPatch(typeof(ShipTeleporter), "PressTeleportButtonClientRpc")]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
{
new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(ShipTeleporter), "beamUpPlayer", (Type[])null, (Type[])null), (string)null)
}).ThrowIfInvalid("Method not found.").SetOperandAndAdvance((object)AccessTools.Method(typeof(TeleporterPatch), "betterBeamUpPlayer", (Type[])null, (Type[])null))
.InstructionEnumeration();
}
private static IEnumerator betterBeamUpPlayer(ShipTeleporter __instance)
{
MethodInfo SetPlayerTeleporterId = typeof(ShipTeleporter).GetMethod("SetPlayerTeleporterId", BindingFlags.Instance | BindingFlags.NonPublic);
__instance.shipTeleporterAudio.PlayOneShot(__instance.teleporterSpinSFX);
PlayerControllerB playerToBeamUp = StartOfRound.Instance.mapScreen.targetedPlayer;
if ((Object)(object)playerToBeamUp == (Object)null)
{
Debug.Log((object)"Targeted player is null");
yield break;
}
if ((Object)(object)playerToBeamUp.redirectToEnemy != (Object)null)
{
Debug.Log((object)$"Attemping to teleport enemy '{((Object)((Component)playerToBeamUp.redirectToEnemy).gameObject).name}' (tied to player #{playerToBeamUp.playerClientId}) to ship.");
if (StartOfRound.Instance.shipIsLeaving)
{
Debug.Log((object)$"Ship could not teleport enemy '{((Object)((Component)playerToBeamUp.redirectToEnemy).gameObject).name}' (tied to player #{playerToBeamUp.playerClientId}) because the ship is leaving the nav mesh.");
}
playerToBeamUp.redirectToEnemy.ShipTeleportEnemy();
yield return (object)new WaitForSeconds(3f);
__instance.shipTeleporterAudio.PlayOneShot(__instance.teleporterBeamUpSFX);
if (GameNetworkManager.Instance.localPlayerController.isInHangarShipRoom)
{
HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
}
}
SetPlayerTeleporterId.Invoke(__instance, new object[2] { playerToBeamUp, -1 });
if ((Object)(object)playerToBeamUp.deadBody != (Object)null)
{
if ((Object)(object)playerToBeamUp.deadBody.beamUpParticle == (Object)null)
{
yield break;
}
playerToBeamUp.deadBody.beamUpParticle.Play();
playerToBeamUp.deadBody.bodyAudio.PlayOneShot(__instance.beamUpPlayerBodySFX);
}
else
{
playerToBeamUp.beamUpParticle.Play();
playerToBeamUp.movementAudio.PlayOneShot(__instance.beamUpPlayerBodySFX);
}
Debug.Log((object)"Teleport A");
yield return (object)new WaitForSeconds(3f);
bool flag = false;
if ((Object)(object)playerToBeamUp.deadBody != (Object)null)
{
if ((Object)(object)playerToBeamUp.deadBody.grabBodyObject == (Object)null || !playerToBeamUp.deadBody.grabBodyObject.isHeldByEnemy)
{
flag = true;
playerToBeamUp.deadBody.attachedTo = null;
playerToBeamUp.deadBody.attachedLimb = null;
playerToBeamUp.deadBody.secondaryAttachedLimb = null;
playerToBeamUp.deadBody.secondaryAttachedTo = null;
playerToBeamUp.deadBody.SetRagdollPositionSafely(__instance.teleporterPosition.position, true);
((Component)playerToBeamUp.deadBody).transform.SetParent(StartOfRound.Instance.elevatorTransform, true);
if ((Object)(object)playerToBeamUp.deadBody.grabBodyObject != (Object)null && playerToBeamUp.deadBody.grabBodyObject.isHeld && (Object)(object)playerToBeamUp.deadBody.grabBodyObject.playerHeldBy != (Object)null)
{
playerToBeamUp.deadBody.grabBodyObject.playerHeldBy.DropAllHeldItems(true, false);
}
}
}
else
{
flag = true;
Utils.dropMostHeldItems(ref playerToBeamUp);
if (Object.op_Implicit((Object)(object)Object.FindObjectOfType<AudioReverbPresets>()))
{
Object.FindObjectOfType<AudioReverbPresets>().audioPresets[3].ChangeAudioReverbForPlayer(playerToBeamUp);
}
playerToBeamUp.isInElevator = true;
playerToBeamUp.isInHangarShipRoom = true;
playerToBeamUp.isInsideFactory = false;
playerToBeamUp.averageVelocity = 0f;
playerToBeamUp.velocityLastFrame = Vector3.zero;
playerToBeamUp.TeleportPlayer(__instance.teleporterPosition.position, true, 160f, false, true);
}
Debug.Log((object)"Teleport B");
SetPlayerTeleporterId.Invoke(__instance, new object[2] { playerToBeamUp, -1 });
if (flag)
{
__instance.shipTeleporterAudio.PlayOneShot(__instance.teleporterBeamUpSFX);
if (GameNetworkManager.Instance.localPlayerController.isInHangarShipRoom)
{
HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
}
}
Debug.Log((object)"Teleport C");
}
}
}