-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pings for all players in the small cyclops sonar HUD
- Loading branch information
1 parent
990dd36
commit c57adb1
Showing
5 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
Nitrox.Test/Patcher/Patches/Dynamic/CyclopsSonarDisplay_NewEntityOnSonar_PatchTest.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,18 @@ | ||
using HarmonyLib; | ||
using NitroxPatcher.PatternMatching; | ||
using NitroxTest.Patcher; | ||
|
||
namespace NitroxPatcher.Patches.Dynamic; | ||
|
||
[TestClass] | ||
public class CyclopsSonarDisplay_NewEntityOnSonar_PatchTest | ||
{ | ||
[TestMethod] | ||
public void Sanity() | ||
{ | ||
IEnumerable<CodeInstruction> originalIl = PatchTestHelper.GetInstructionsFromMethod(CyclopsSonarDisplay_NewEntityOnSonar_Patch.TARGET_METHOD); | ||
IEnumerable<CodeInstruction> transformedIl = CyclopsSonarDisplay_NewEntityOnSonar_Patch.Transpiler(originalIl); | ||
transformedIl.Count().Should().Be(originalIl.Count() + 3); | ||
Console.WriteLine(transformedIl.ToPrettyString()); | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
NitroxPatcher/Patches/Dynamic/CyclopsSonarCreatureDetector_CheckForCreaturesInRange_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,17 @@ | ||
using System.Reflection; | ||
using NitroxClient.GameLogic; | ||
using NitroxModel.Helper; | ||
|
||
namespace NitroxPatcher.Patches.Persistent; | ||
|
||
public sealed partial class CyclopsSonarCreatureDetector_CheckForCreaturesInRange_Patch : NitroxPatch, IPersistentPatch | ||
{ | ||
public static readonly MethodInfo TARGET_METHOD = Reflect.Method((CyclopsSonarCreatureDetector t) => t.CheckForCreaturesInRange()); | ||
|
||
public const CyclopsSonarDisplay.EntityType PLAYER_TYPE = (CyclopsSonarDisplay.EntityType)2; | ||
|
||
public static void Postfix(CyclopsSonarCreatureDetector __instance) | ||
{ | ||
__instance.ChekItemsOnHashSet(Resolve<PlayerManager>().GetAllPlayerObjects(), PLAYER_TYPE); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
NitroxPatcher/Patches/Dynamic/CyclopsSonarDisplay_NewEntityOnSonar_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,63 @@ | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Reflection.Emit; | ||
using HarmonyLib; | ||
using NitroxClient.GameLogic; | ||
using NitroxClient.GameLogic.PlayerLogic; | ||
using NitroxModel.Helper; | ||
using NitroxModel_Subnautica.DataStructures; | ||
using NitroxPatcher.Patches.Persistent; | ||
using UnityEngine; | ||
|
||
namespace NitroxPatcher.Patches.Dynamic; | ||
|
||
public sealed partial class CyclopsSonarDisplay_NewEntityOnSonar_Patch : NitroxPatch, IPersistentPatch | ||
{ | ||
public static readonly MethodInfo TARGET_METHOD = Reflect.Method((CyclopsSonarDisplay t) => t.NewEntityOnSonar(default)); | ||
|
||
/* | ||
* } | ||
* this.entitysOnSonar.Add(entityPing2); | ||
* SetupPing(component, entityData); <----- INSERTED LINE | ||
*/ | ||
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) | ||
{ | ||
return new CodeMatcher(instructions).End() | ||
.InsertAndAdvance(TARGET_METHOD.Ldloc<CyclopsHUDSonarPing>()) | ||
.InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_1)) | ||
.InsertAndAdvance(new CodeInstruction(OpCodes.Call, Reflect.Method(() => SetupPing(default, default)))) | ||
.InstructionEnumeration(); | ||
} | ||
|
||
public static void SetupPing(CyclopsHUDSonarPing ping, CyclopsSonarCreatureDetector.EntityData entityData) | ||
{ | ||
if (entityData.entityType != CyclopsSonarCreatureDetector_CheckForCreaturesInRange_Patch.PLAYER_TYPE) | ||
{ | ||
return; | ||
} | ||
|
||
Color color; | ||
if (entityData.gameObject == Player.mainObject) | ||
{ | ||
color = Resolve<LocalPlayer>().PlayerSettings.PlayerColor.ToUnity(); | ||
} | ||
else if (entityData.gameObject.TryGetComponent(out RemotePlayerIdentifier remotePlayerIdentifier)) | ||
{ | ||
color = remotePlayerIdentifier.RemotePlayer.PlayerSettings.PlayerColor.ToUnity(); | ||
} | ||
else | ||
{ | ||
return; | ||
} | ||
|
||
CyclopsHUDSonarPing sonarPing = ping.GetComponent<CyclopsHUDSonarPing>(); | ||
// Set isCreaturePing to true so that CyclopsHUDSonarPing.Start runs the SetColor code | ||
sonarPing.isCreaturePing = true; | ||
sonarPing.passiveColor = color; | ||
sonarPing.Start(); | ||
sonarPing.isCreaturePing = false; | ||
|
||
// We remove the pulse to be able to differentiate those signals from the creatures and decoy ones | ||
GameObject.Destroy(sonarPing.transform.Find("Ping/PingPulse").gameObject); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
NitroxPatcher/Patches/Persistent/Application_targetFrameRate_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,16 @@ | ||
using System.Reflection; | ||
using NitroxClient.MonoBehaviours; | ||
using NitroxModel.Helper; | ||
using UnityEngine; | ||
|
||
namespace NitroxPatcher.Patches.Persistent; | ||
|
||
public sealed partial class Application_targetFrameRate_Patch : NitroxPatch, IPersistentPatch | ||
{ | ||
public static readonly MethodInfo TARGET_METHOD = Reflect.Property(() => Application.targetFrameRate).GetSetMethod(); | ||
|
||
public static void Postfix() | ||
{ | ||
MovementReplicator.UpdateInterpolationTime(); | ||
} | ||
} |