Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify teleport to move vehicle #2111

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using NitroxClient.Communication.Packets.Processors.Abstract;
using NitroxClient.MonoBehaviours;
using NitroxModel.Packets;
using NitroxModel_Subnautica.DataStructures;
using NitroxModel.Packets;
using UnityEngine;
using UWE;
using Terrain = NitroxClient.GameLogic.Terrain;
Expand All @@ -21,7 +21,7 @@ public override void Process(PlayerTeleported packet)
if (subRoot.isCyclops)
{
// Reversing calculations from PlayerMovementBroadcaster.Update()
Vector3 position = (subRoot.transform.rotation * packet.DestinationTo.ToUnity()) + subRoot.transform.position;
Vector3 position = subRoot.transform.rotation * packet.DestinationTo.ToUnity() + subRoot.transform.position;
Jannify marked this conversation as resolved.
Show resolved Hide resolved

Player.main.SetPosition(position);
Player.main.SetCurrentSub(subRoot);
Expand All @@ -30,14 +30,21 @@ public override void Process(PlayerTeleported packet)

Player.main.SetCurrentSub(subRoot);
}


Vehicle currentVehicle = Player.main.currentMountedVehicle;
if (currentVehicle)
{
currentVehicle.TeleportVehicle(packet.DestinationTo.ToUnity(), currentVehicle.transform.rotation);
Jannify marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Player.main.SetPosition(packet.DestinationTo.ToUnity());
// Freeze the player while he's loading its new position
Player.main.cinematicModeActive = true;
try
{
CoroutineHost.StartCoroutine(Terrain.WaitForWorldLoad());
} catch (Exception e)
}
catch (Exception e)
{
Player.main.cinematicModeActive = false;
Log.Warn($"Something wrong happened while waiting for the terrain to load.\n{e}");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Reflection;
using NitroxModel.Helper;
using UnityEngine;

namespace NitroxPatcher.Patches.Dynamic;

public sealed partial class GotoConsoleCommand_GotoPosition_Patch : NitroxPatch, IDynamicPatch
{
public static readonly MethodInfo TARGET_METHOD = Reflect.Method((GotoConsoleCommand t) => t.GotoPosition(default, default));

public static bool Prefix(Vector3 position)
{
Vehicle currentMountedVehicle = Player.main.currentMountedVehicle;
if (!currentMountedVehicle)
{
return true; // Normal GoTo behaviour if not in vehicle
}
currentMountedVehicle.TeleportVehicle(position, currentMountedVehicle.transform.rotation); // handle GoTo with a vehicle teleport, which takes player too
Jannify marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
}
26 changes: 26 additions & 0 deletions NitroxPatcher/Patches/Dynamic/Player_WarpForward_Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Reflection;
using NitroxModel.Helper;
using UnityEngine;

namespace NitroxPatcher.Patches.Dynamic;

public sealed partial class Player_WarpForward_Patch : NitroxPatch, IDynamicPatch
{
public static readonly MethodInfo TARGET_METHOD = Reflect.Method((Player t) => t.OnConsoleCommand_warpforward(default));

public static bool Prefix(Player __instance, NotificationCenter.Notification n)
{
float num;
DevConsole.ParseFloat(n, 0, out num, 3f);
Vector3 newPosition = __instance.transform.position + __instance.camRoot.GetAimingTransform().forward * num;
Jannify marked this conversation as resolved.
Show resolved Hide resolved

if (__instance.currentMountedVehicle == null)
Jannify marked this conversation as resolved.
Show resolved Hide resolved
{
return true;
}
__instance.currentMountedVehicle.TeleportVehicle(newPosition, __instance.currentMountedVehicle.transform.rotation);
__instance.OnPlayerPositionCheat();
return false;
}

}