Skip to content

Commit 73d7640

Browse files
authored
Fix vehicles not charging with multiple players connected (SubnauticaNitrox#2505)
2 parents 162e573 + 4fca09b commit 73d7640

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Reflection;
2+
using NitroxClient.GameLogic;
3+
using NitroxModel.DataStructures;
4+
5+
namespace NitroxPatcher.Patches.Dynamic;
6+
7+
/// <summary>
8+
/// Ensures vehicle charging from modules only occurs on the simulating player.
9+
/// </summary>
10+
public sealed partial class Vehicle_AddEnergy_Patch : NitroxPatch, IDynamicPatch
11+
{
12+
private static readonly MethodInfo TARGET_METHOD = Reflect.Method((Vehicle t) => t.AddEnergy(default));
13+
14+
public static bool Prefix(Vehicle __instance)
15+
{
16+
return __instance.TryGetNitroxId(out NitroxId vehicleId) && Resolve<SimulationOwnership>().HasAnyLockType(vehicleId);
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Reflection;
2+
using NitroxClient.GameLogic;
3+
using NitroxModel.DataStructures;
4+
5+
namespace NitroxPatcher.Patches.Dynamic;
6+
7+
/// <summary>
8+
/// Ensures vehicle charging from moonpool only occurs on the simulating player.
9+
/// </summary>
10+
public sealed partial class Vehicle_UpdateEnergyRecharge_Patch : NitroxPatch, IDynamicPatch
11+
{
12+
private static readonly MethodInfo TARGET_METHOD = Reflect.Method((Vehicle t) => t.UpdateEnergyRecharge());
13+
14+
public static bool Prefix(Vehicle __instance)
15+
{
16+
return __instance.TryGetNitroxId(out NitroxId vehicleId) && Resolve<SimulationOwnership>().HasAnyLockType(vehicleId);
17+
}
18+
}

0 commit comments

Comments
 (0)