-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix precursor proximity triggers not reacting to remote players #2649
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
Open
misterbubb
wants to merge
6
commits into
SubnauticaNitrox:master
Choose a base branch
from
misterbubb:fix/ion-cube-pedestal-remote-player-2643
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cac7672
Fix precursor pedestals not reacting to remote players (#2643)
misterbubb 70a69bb
Add PrecursorDisableGunTerminalArea patches for remote player support
misterbubb fe83e27
Fix remote player collider missing height property
misterbubb 64296a5
Disable SphereCollider on remote player ping signal
misterbubb e732979
Refactor player detection into shared helper method
misterbubb 7c6289c
Remove accidentally committed development config
misterbubb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
55 changes: 55 additions & 0 deletions
55
NitroxPatcher/Patches/Dynamic/PrecursorActivatedPillar_OnTriggerEnter_Patch.cs
This file contains hidden or 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,55 @@ | ||
| using System.Reflection; | ||
| using NitroxClient.GameLogic.PlayerLogic; | ||
| using UnityEngine; | ||
|
|
||
| namespace NitroxPatcher.Patches.Dynamic; | ||
|
|
||
| /// <summary> | ||
| /// Makes ion cube pedestals (the ones with ion cubes on top that rise up) react to remote players. | ||
| /// </summary> | ||
| public sealed partial class PrecursorActivatedPillar_OnTriggerEnter_Patch : NitroxPatch, IDynamicPatch | ||
| { | ||
| private static readonly MethodInfo TARGET_METHOD = Reflect.Method((PrecursorActivatedPillar t) => t.OnTriggerEnter(default)); | ||
|
|
||
| public static bool Prefix(PrecursorActivatedPillar __instance, Collider col, bool ___active, ref bool ___extended, ref bool ___isFullyExtended, FMODAsset ___openSound, FMOD_CustomLoopingEmitter ___openedLoopingSound) | ||
| { | ||
| if (!___active) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| GameObject entityRoot = UWE.Utils.GetEntityRoot(col.gameObject); | ||
| if (!entityRoot) | ||
| { | ||
| entityRoot = col.gameObject; | ||
| } | ||
|
|
||
| bool isLocalPlayer = entityRoot.GetComponentInChildren<Player>() != null; | ||
| bool isRemotePlayer = entityRoot.GetComponentInChildren<RemotePlayerIdentifier>() != null; | ||
|
|
||
| if (!isLocalPlayer && !isRemotePlayer) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| // Track player count for proper exit handling | ||
| PrecursorActivatedPillar_OnTriggerExit_Patch.IncrementPlayerCount(__instance); | ||
|
|
||
| // Only play sounds and animate if not already extended | ||
| if (!___extended) | ||
| { | ||
| if (___openSound) | ||
| { | ||
| Utils.PlayFMODAsset(___openSound, __instance.transform, 20f); | ||
| } | ||
| if (___openedLoopingSound) | ||
| { | ||
| ___openedLoopingSound.Play(); | ||
| } | ||
| ___extended = true; | ||
| ___isFullyExtended = false; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } |
70 changes: 70 additions & 0 deletions
70
NitroxPatcher/Patches/Dynamic/PrecursorActivatedPillar_OnTriggerExit_Patch.cs
This file contains hidden or 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,70 @@ | ||
| using System.Collections.Generic; | ||
| using System.Reflection; | ||
| using FMOD.Studio; | ||
| using NitroxClient.GameLogic.PlayerLogic; | ||
| using UnityEngine; | ||
|
|
||
| namespace NitroxPatcher.Patches.Dynamic; | ||
|
|
||
| /// <summary> | ||
| /// Prevents ion cube pedestals from retracting when a player leaves if other players are still nearby. | ||
| /// </summary> | ||
| public sealed partial class PrecursorActivatedPillar_OnTriggerExit_Patch : NitroxPatch, IDynamicPatch | ||
| { | ||
| private static readonly MethodInfo TARGET_METHOD = Reflect.Method((PrecursorActivatedPillar t) => t.OnTriggerExit(default)); | ||
|
|
||
| /// <summary> | ||
| /// Tracks the number of players currently in each pillar's trigger zone. | ||
| /// </summary> | ||
| private static readonly Dictionary<int, int> playerCountByPillar = []; | ||
|
|
||
| public static void IncrementPlayerCount(PrecursorActivatedPillar pillar) | ||
| { | ||
| int id = pillar.GetInstanceID(); | ||
| playerCountByPillar.TryGetValue(id, out int count); | ||
| playerCountByPillar[id] = count + 1; | ||
| } | ||
|
|
||
| public static bool Prefix(PrecursorActivatedPillar __instance, Collider col, ref bool ___extended, ref bool ___isFullyExtended, FMODAsset ___closeSound, FMOD_CustomLoopingEmitter ___openedLoopingSound) | ||
| { | ||
| GameObject entityRoot = UWE.Utils.GetEntityRoot(col.gameObject); | ||
| if (!entityRoot) | ||
| { | ||
| entityRoot = col.gameObject; | ||
| } | ||
|
|
||
| bool isLocalPlayer = entityRoot.GetComponentInChildren<Player>() != null; | ||
| bool isRemotePlayer = entityRoot.GetComponentInChildren<RemotePlayerIdentifier>() != null; | ||
|
|
||
| if (!isLocalPlayer && !isRemotePlayer) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| // Decrement player count (only if we have a count for this pillar) | ||
| int id = __instance.GetInstanceID(); | ||
| int newCount = 0; | ||
| if (playerCountByPillar.TryGetValue(id, out int count) && count > 0) | ||
| { | ||
| newCount = count - 1; | ||
| playerCountByPillar[id] = newCount; | ||
| } | ||
|
|
||
| // Only retract if no players remain | ||
| if (newCount <= 0) | ||
| { | ||
| if (___closeSound) | ||
| { | ||
| Utils.PlayFMODAsset(___closeSound, __instance.transform, 20f); | ||
| } | ||
| if (___openedLoopingSound) | ||
| { | ||
| ___openedLoopingSound.Stop(STOP_MODE.ALLOWFADEOUT); | ||
| } | ||
| ___extended = false; | ||
| ___isFullyExtended = true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
NitroxPatcher/Patches/Dynamic/PrecursorDisableGunTerminalArea_OnTriggerEnter_Patch.cs
This file contains hidden or 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,32 @@ | ||
| using System.Reflection; | ||
| using NitroxClient.GameLogic.PlayerLogic; | ||
| using UnityEngine; | ||
|
|
||
| namespace NitroxPatcher.Patches.Dynamic; | ||
|
|
||
| /// <summary> | ||
| /// Makes the gun disable terminal open when remote players approach. | ||
| /// </summary> | ||
| public sealed partial class PrecursorDisableGunTerminalArea_OnTriggerEnter_Patch : NitroxPatch, IDynamicPatch | ||
| { | ||
| private static readonly MethodInfo TARGET_METHOD = Reflect.Method((PrecursorDisableGunTerminalArea t) => t.OnTriggerEnter(default)); | ||
|
|
||
| public static bool Prefix(PrecursorDisableGunTerminalArea __instance, Collider other) | ||
| { | ||
| if (!PrecursorDisableGunTerminalArea_OnTriggerExit_Patch.IsPlayerCollider(other, out GameObject entityRoot)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| // Track player count for proper exit handling | ||
| PrecursorDisableGunTerminalArea_OnTriggerExit_Patch.IncrementPlayerCount(__instance); | ||
|
|
||
| // Only open if this is the first player entering | ||
| if (PrecursorDisableGunTerminalArea_OnTriggerExit_Patch.GetPlayerCount(__instance) == 1) | ||
| { | ||
| __instance.terminal.OnTerminalAreaEnter(); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } |
78 changes: 78 additions & 0 deletions
78
NitroxPatcher/Patches/Dynamic/PrecursorDisableGunTerminalArea_OnTriggerExit_Patch.cs
This file contains hidden or 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,78 @@ | ||
| using System.Collections.Generic; | ||
| using System.Reflection; | ||
| using NitroxClient.GameLogic.PlayerLogic; | ||
| using UnityEngine; | ||
|
|
||
| namespace NitroxPatcher.Patches.Dynamic; | ||
|
|
||
| /// <summary> | ||
| /// Prevents the gun disable terminal from closing when a player leaves if other players are still nearby. | ||
| /// </summary> | ||
| public sealed partial class PrecursorDisableGunTerminalArea_OnTriggerExit_Patch : NitroxPatch, IDynamicPatch | ||
| { | ||
| private static readonly MethodInfo TARGET_METHOD = Reflect.Method((PrecursorDisableGunTerminalArea t) => t.OnTriggerExit(default)); | ||
|
|
||
| /// <summary> | ||
| /// Tracks the number of players currently in each trigger zone. | ||
| /// </summary> | ||
| private static readonly Dictionary<int, int> playerCountByTrigger = []; | ||
|
|
||
| /// <summary> | ||
| /// Checks if the collider belongs to a player (local or remote) and returns the entity root. | ||
| /// </summary> | ||
| /// <param name="other">The collider to check</param> | ||
| /// <param name="entityRoot">The entity root GameObject if it's a player, null otherwise</param> | ||
| /// <returns>True if the collider belongs to a player, false otherwise</returns> | ||
| public static bool IsPlayerCollider(Collider other, out GameObject entityRoot) | ||
| { | ||
| entityRoot = UWE.Utils.GetEntityRoot(other.gameObject); | ||
| if (entityRoot == null) | ||
| { | ||
| entityRoot = other.gameObject; | ||
| } | ||
|
|
||
| bool isLocalPlayer = entityRoot.GetComponent<Player>() != null; | ||
| bool isRemotePlayer = entityRoot.GetComponent<RemotePlayerIdentifier>() != null; | ||
|
|
||
| return isLocalPlayer || isRemotePlayer; | ||
| } | ||
|
|
||
| public static void IncrementPlayerCount(PrecursorDisableGunTerminalArea trigger) | ||
| { | ||
| int id = trigger.GetInstanceID(); | ||
| playerCountByTrigger.TryGetValue(id, out int count); | ||
| playerCountByTrigger[id] = count + 1; | ||
| } | ||
|
|
||
| public static int GetPlayerCount(PrecursorDisableGunTerminalArea trigger) | ||
| { | ||
| int id = trigger.GetInstanceID(); | ||
| playerCountByTrigger.TryGetValue(id, out int count); | ||
| return count; | ||
| } | ||
|
|
||
| public static bool Prefix(PrecursorDisableGunTerminalArea __instance, Collider other) | ||
| { | ||
| if (!IsPlayerCollider(other, out GameObject entityRoot)) | ||
| { | ||
| return false; | ||
| } | ||
|
misterbubb marked this conversation as resolved.
|
||
|
|
||
| // Decrement player count (only if we have a count for this trigger) | ||
| int id = __instance.GetInstanceID(); | ||
| int newCount = 0; | ||
| if (playerCountByTrigger.TryGetValue(id, out int count) && count > 0) | ||
| { | ||
| newCount = count - 1; | ||
| playerCountByTrigger[id] = newCount; | ||
| } | ||
|
|
||
| // Only close if no players remain | ||
| if (newCount <= 0) | ||
| { | ||
| __instance.terminal.OnTerminalAreaExit(); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
35 changes: 35 additions & 0 deletions
35
NitroxPatcher/Patches/Dynamic/PrecursorKeyTerminalTrigger_OnTriggerEnter_Patch.cs
This file contains hidden or 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,35 @@ | ||
| using System.Reflection; | ||
| using NitroxClient.GameLogic.PlayerLogic; | ||
| using UnityEngine; | ||
|
|
||
| namespace NitroxPatcher.Patches.Dynamic; | ||
|
|
||
| /// <summary> | ||
| /// Makes precursor key terminal pedestals (tablet pedestals) react to remote players. | ||
| /// </summary> | ||
| public sealed partial class PrecursorKeyTerminalTrigger_OnTriggerEnter_Patch : NitroxPatch, IDynamicPatch | ||
| { | ||
| private static readonly MethodInfo TARGET_METHOD = Reflect.Method((PrecursorKeyTerminalTrigger t) => t.OnTriggerEnter(default)); | ||
|
|
||
| public static bool Prefix(PrecursorKeyTerminalTrigger __instance, Collider col) | ||
| { | ||
| bool isLocalPlayer = col.gameObject.Equals(Player.main.gameObject); | ||
| bool isRemotePlayer = col.GetComponentInParent<RemotePlayerIdentifier>() != null; | ||
|
|
||
| if (!isLocalPlayer && !isRemotePlayer) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| // Track player count for proper exit handling | ||
| PrecursorKeyTerminalTrigger_OnTriggerExit_Patch.IncrementPlayerCount(__instance); | ||
|
|
||
| // Only send OpenDeck if this is the first player entering | ||
| if (PrecursorKeyTerminalTrigger_OnTriggerExit_Patch.GetPlayerCount(__instance) == 1) | ||
| { | ||
| __instance.SendMessageUpwards("OpenDeck"); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } |
61 changes: 61 additions & 0 deletions
61
NitroxPatcher/Patches/Dynamic/PrecursorKeyTerminalTrigger_OnTriggerExit_Patch.cs
This file contains hidden or 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,61 @@ | ||
| using System.Collections.Generic; | ||
| using System.Reflection; | ||
| using NitroxClient.GameLogic.PlayerLogic; | ||
| using UnityEngine; | ||
|
|
||
| namespace NitroxPatcher.Patches.Dynamic; | ||
|
|
||
| /// <summary> | ||
| /// Prevents precursor key terminal pedestals from closing when a player leaves if other players are still nearby. | ||
| /// </summary> | ||
| public sealed partial class PrecursorKeyTerminalTrigger_OnTriggerExit_Patch : NitroxPatch, IDynamicPatch | ||
| { | ||
| private static readonly MethodInfo TARGET_METHOD = Reflect.Method((PrecursorKeyTerminalTrigger t) => t.OnTriggerExit(default)); | ||
|
|
||
| /// <summary> | ||
| /// Tracks the number of players currently in each trigger zone. | ||
| /// </summary> | ||
| private static readonly Dictionary<int, int> playerCountByTrigger = []; | ||
|
|
||
| public static void IncrementPlayerCount(PrecursorKeyTerminalTrigger trigger) | ||
| { | ||
| int id = trigger.GetInstanceID(); | ||
| playerCountByTrigger.TryGetValue(id, out int count); | ||
| playerCountByTrigger[id] = count + 1; | ||
| } | ||
|
|
||
| public static int GetPlayerCount(PrecursorKeyTerminalTrigger trigger) | ||
| { | ||
| int id = trigger.GetInstanceID(); | ||
| playerCountByTrigger.TryGetValue(id, out int count); | ||
| return count; | ||
| } | ||
|
|
||
| public static bool Prefix(PrecursorKeyTerminalTrigger __instance, Collider col) | ||
| { | ||
| bool isLocalPlayer = col.gameObject.Equals(Player.main.gameObject); | ||
| bool isRemotePlayer = col.GetComponentInParent<RemotePlayerIdentifier>() != null; | ||
|
|
||
| if (!isLocalPlayer && !isRemotePlayer) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| // Decrement player count (only if we have a count for this trigger) | ||
| int id = __instance.GetInstanceID(); | ||
| int newCount = 0; | ||
| if (playerCountByTrigger.TryGetValue(id, out int count) && count > 0) | ||
| { | ||
| newCount = count - 1; | ||
| playerCountByTrigger[id] = newCount; | ||
| } | ||
|
|
||
| // Only close if no players remain | ||
| if (newCount <= 0) | ||
| { | ||
| __instance.SendMessageUpwards("CloseDeck"); | ||
|
misterbubb marked this conversation as resolved.
|
||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.