Skip to content

Commit 5ffc5d0

Browse files
authored
Added precursor teleporer sync (SubnauticaNitrox#1105)
* Added precursor teleporer sync * Made changes as suggested
1 parent c8635f9 commit 5ffc5d0

File tree

7 files changed

+84
-2
lines changed

7 files changed

+84
-2
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
2+
using NitroxModel.Logger;
3+
using UnityEngine;
4+
5+
namespace NitroxClient.GameLogic.Spawning.Metadata
6+
{
7+
public class PrecursorTeleporterMetadataProcessor : GenericEntityMetadataProcessor<PrecursorTeleporterMetadata>
8+
{
9+
public override void ProcessMetadata(GameObject gameObject, PrecursorTeleporterMetadata metadata)
10+
{
11+
Log.Debug($"Received precursor teleporter metadata change for {gameObject.name} with data of {metadata}");
12+
13+
PrecursorTeleporter precursorTeleporter = gameObject.GetComponent<PrecursorTeleporter>();
14+
if (precursorTeleporter)
15+
{
16+
precursorTeleporter.isOpen = metadata.IsOpen;
17+
18+
precursorTeleporter.ToggleDoor(metadata.IsOpen);
19+
}
20+
}
21+
}
22+
}

NitroxClient/NitroxClient.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
<Compile Include="GameLogic\Spawning\EntitySpawnerResolver.cs" />
6868
<Compile Include="GameLogic\Spawning\ExistingGameObjectSpawner.cs" />
6969
<Compile Include="GameLogic\Spawning\Metadata\PrecursorDoorwayMetadataProcessor.cs" />
70+
<Compile Include="GameLogic\Spawning\Metadata\PrecursorTeleporterMetadataProcessor.cs" />
7071
<Compile Include="GameLogic\Spawning\Metadata\SealedDoorMetadataProcessor.cs" />
7172
<Compile Include="GameLogic\Spawning\Metadata\KeypadMetadataProcessor.cs" />
7273
<Compile Include="GameLogic\Spawning\Metadata\EntityMetadataProcessor.cs" />

NitroxModel/DataStructures/GameLogic/Entities/Metadata/EntityMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata
55
{
66
[Serializable]
7-
[ProtoContract, ProtoInclude(50, typeof(KeypadMetadata)), ProtoInclude(60, typeof(SealedDoorMetadata)), ProtoInclude(70, typeof(PrecursorDoorwayMetadata))]
7+
[ProtoContract, ProtoInclude(50, typeof(KeypadMetadata)), ProtoInclude(60, typeof(SealedDoorMetadata)), ProtoInclude(70, typeof(PrecursorDoorwayMetadata)), ProtoInclude(80, typeof(PrecursorTeleporterMetadata))]
88
public abstract class EntityMetadata
99
{
1010
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using ProtoBufNet;
3+
4+
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata
5+
{
6+
[Serializable]
7+
[ProtoContract]
8+
public class PrecursorTeleporterMetadata : EntityMetadata
9+
{
10+
[ProtoMember(1)]
11+
public bool IsOpen { get; }
12+
13+
public PrecursorTeleporterMetadata()
14+
{
15+
// Constructor for serialization
16+
}
17+
18+
public PrecursorTeleporterMetadata(bool isOpen)
19+
{
20+
IsOpen = isOpen;
21+
}
22+
23+
public override string ToString()
24+
{
25+
return "[PrecursorTeleporterMetadata isOpen: " + IsOpen + "]";
26+
}
27+
}
28+
}

NitroxModel/NitroxModel.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
<Compile Include="Core\NitroxEnvironment.cs" />
5555
<Compile Include="Core\NitroxServiceLocator.cs" />
5656
<Compile Include="DataStructures\GameLogic\Entities\Metadata\PrecursorDoorwayMetadata.cs" />
57+
<Compile Include="DataStructures\GameLogic\Entities\Metadata\PrecursorTeleporterMetadata.cs" />
5758
<Compile Include="DataStructures\GameLogic\Entities\Metadata\SealedDoorMetadata.cs" />
5859
<Compile Include="DataStructures\GameLogic\Entities\Metadata\KeypadMetadata.cs" />
5960
<Compile Include="DataStructures\GameLogic\Entities\Metadata\EntityMetadata.cs" />

NitroxPatcher/NitroxPatcher.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
</ItemGroup>
5050
<ItemGroup>
5151
<Compile Include="Main.cs" />
52+
<Compile Include="Patches\Dynamic\PrecursorTeleporter_OnActivateTeleporter_Patch.cs" />
5253
<Compile Include="Patches\Persistent\SentrySdk_Start_Patch.cs" />
5354
<Compile Include="Modules\NitroxPatchesModule.cs" />
5455
<Compile Include="Patches\Dynamic\KeypadDoorConsole_AcceptNumberField_Patch.cs" />
@@ -214,4 +215,4 @@
214215
<Target Name="AfterBuild">
215216
</Target>
216217
-->
217-
</Project>
218+
</Project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Reflection;
2+
using Harmony;
3+
using NitroxClient.GameLogic;
4+
using NitroxClient.MonoBehaviours;
5+
using NitroxModel.Core;
6+
using NitroxModel.DataStructures;
7+
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
8+
9+
namespace NitroxPatcher.Patches.Dynamic
10+
{
11+
class PrecursorTeleporter_OnActivateTeleporter_Patch : NitroxPatch, IDynamicPatch
12+
{
13+
public static readonly MethodInfo TARGET_METHOD = typeof(PrecursorTeleporter).GetMethod("OnActivateTeleporter", BindingFlags.NonPublic | BindingFlags.Instance);
14+
15+
public static void Postfix(PrecursorTeleporter __instance)
16+
{
17+
NitroxId id = NitroxEntity.GetId(__instance.gameObject);
18+
PrecursorTeleporterMetadata precursorTeleporterMetadata = new PrecursorTeleporterMetadata(__instance.isOpen);
19+
20+
Entities entities = NitroxServiceLocator.LocateService<Entities>();
21+
entities.BroadcastMetadataUpdate(id, precursorTeleporterMetadata);
22+
}
23+
24+
public override void Patch(HarmonyInstance harmony)
25+
{
26+
PatchPostfix(harmony, TARGET_METHOD);
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)