forked from SubnauticaNitrox/Nitrox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added precursor teleporer sync (SubnauticaNitrox#1105)
* Added precursor teleporer sync * Made changes as suggested
- Loading branch information
1 parent
c8635f9
commit 5ffc5d0
Showing
7 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
NitroxClient/GameLogic/Spawning/Metadata/PrecursorTeleporterMetadataProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
NitroxModel/DataStructures/GameLogic/Entities/Metadata/PrecursorTeleporterMetadata.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + "]"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
NitroxPatcher/Patches/Dynamic/PrecursorTeleporter_OnActivateTeleporter_Patch.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |