Skip to content

Commit

Permalink
Added precursor teleporer sync (SubnauticaNitrox#1105)
Browse files Browse the repository at this point in the history
* Added precursor teleporer sync

* Made changes as suggested
  • Loading branch information
Coding-Hen authored May 28, 2020
1 parent c8635f9 commit 5ffc5d0
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using NitroxModel.Logger;
using UnityEngine;

namespace NitroxClient.GameLogic.Spawning.Metadata
{
public class PrecursorTeleporterMetadataProcessor : GenericEntityMetadataProcessor<PrecursorTeleporterMetadata>
{
public override void ProcessMetadata(GameObject gameObject, PrecursorTeleporterMetadata metadata)
{
Log.Debug($"Received precursor teleporter metadata change for {gameObject.name} with data of {metadata}");

PrecursorTeleporter precursorTeleporter = gameObject.GetComponent<PrecursorTeleporter>();
if (precursorTeleporter)
{
precursorTeleporter.isOpen = metadata.IsOpen;

precursorTeleporter.ToggleDoor(metadata.IsOpen);
}
}
}
}
1 change: 1 addition & 0 deletions NitroxClient/NitroxClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<Compile Include="GameLogic\Spawning\EntitySpawnerResolver.cs" />
<Compile Include="GameLogic\Spawning\ExistingGameObjectSpawner.cs" />
<Compile Include="GameLogic\Spawning\Metadata\PrecursorDoorwayMetadataProcessor.cs" />
<Compile Include="GameLogic\Spawning\Metadata\PrecursorTeleporterMetadataProcessor.cs" />
<Compile Include="GameLogic\Spawning\Metadata\SealedDoorMetadataProcessor.cs" />
<Compile Include="GameLogic\Spawning\Metadata\KeypadMetadataProcessor.cs" />
<Compile Include="GameLogic\Spawning\Metadata\EntityMetadataProcessor.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata
{
[Serializable]
[ProtoContract, ProtoInclude(50, typeof(KeypadMetadata)), ProtoInclude(60, typeof(SealedDoorMetadata)), ProtoInclude(70, typeof(PrecursorDoorwayMetadata))]
[ProtoContract, ProtoInclude(50, typeof(KeypadMetadata)), ProtoInclude(60, typeof(SealedDoorMetadata)), ProtoInclude(70, typeof(PrecursorDoorwayMetadata)), ProtoInclude(80, typeof(PrecursorTeleporterMetadata))]
public abstract class EntityMetadata
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using ProtoBufNet;

namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata
{
[Serializable]
[ProtoContract]
public class PrecursorTeleporterMetadata : EntityMetadata
{
[ProtoMember(1)]
public bool IsOpen { get; }

public PrecursorTeleporterMetadata()
{
// Constructor for serialization
}

public PrecursorTeleporterMetadata(bool isOpen)
{
IsOpen = isOpen;
}

public override string ToString()
{
return "[PrecursorTeleporterMetadata isOpen: " + IsOpen + "]";
}
}
}
1 change: 1 addition & 0 deletions NitroxModel/NitroxModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<Compile Include="Core\NitroxEnvironment.cs" />
<Compile Include="Core\NitroxServiceLocator.cs" />
<Compile Include="DataStructures\GameLogic\Entities\Metadata\PrecursorDoorwayMetadata.cs" />
<Compile Include="DataStructures\GameLogic\Entities\Metadata\PrecursorTeleporterMetadata.cs" />
<Compile Include="DataStructures\GameLogic\Entities\Metadata\SealedDoorMetadata.cs" />
<Compile Include="DataStructures\GameLogic\Entities\Metadata\KeypadMetadata.cs" />
<Compile Include="DataStructures\GameLogic\Entities\Metadata\EntityMetadata.cs" />
Expand Down
3 changes: 2 additions & 1 deletion NitroxPatcher/NitroxPatcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="Patches\Dynamic\PrecursorTeleporter_OnActivateTeleporter_Patch.cs" />
<Compile Include="Patches\Persistent\SentrySdk_Start_Patch.cs" />
<Compile Include="Modules\NitroxPatchesModule.cs" />
<Compile Include="Patches\Dynamic\KeypadDoorConsole_AcceptNumberField_Patch.cs" />
Expand Down Expand Up @@ -214,4 +215,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Reflection;
using Harmony;
using NitroxClient.GameLogic;
using NitroxClient.MonoBehaviours;
using NitroxModel.Core;
using NitroxModel.DataStructures;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;

namespace NitroxPatcher.Patches.Dynamic
{
class PrecursorTeleporter_OnActivateTeleporter_Patch : NitroxPatch, IDynamicPatch
{
public static readonly MethodInfo TARGET_METHOD = typeof(PrecursorTeleporter).GetMethod("OnActivateTeleporter", BindingFlags.NonPublic | BindingFlags.Instance);

public static void Postfix(PrecursorTeleporter __instance)
{
NitroxId id = NitroxEntity.GetId(__instance.gameObject);
PrecursorTeleporterMetadata precursorTeleporterMetadata = new PrecursorTeleporterMetadata(__instance.isOpen);

Entities entities = NitroxServiceLocator.LocateService<Entities>();
entities.BroadcastMetadataUpdate(id, precursorTeleporterMetadata);
}

public override void Patch(HarmonyInstance harmony)
{
PatchPostfix(harmony, TARGET_METHOD);
}
}
}

0 comments on commit 5ffc5d0

Please sign in to comment.