Skip to content

Commit cfe27a8

Browse files
committed
Review changes
1 parent 1001e6e commit cfe27a8

11 files changed

Lines changed: 41 additions & 53 deletions

File tree

Nitrox.Test/Patcher/Patches/PatchesTranspilerTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ public class PatchesTranspilerTest
9090
[typeof(uSkyManager_SetVaryingMaterialProperties_Patch), 0],
9191
[typeof(Welder_Weld_Patch), 1],
9292
[typeof(Poop_Perform_Patch), 1],
93-
[typeof(PrisonPredatorSwimToPlayer_Evaluate_Patch), -52, true],
94-
[typeof(PrisonPredatorSwimToPlayer_Perform_Patch), -26, true],
93+
[typeof(PrisonPredatorSwimToPlayer_Evaluate_Patch), -52],
94+
[typeof(PrisonPredatorSwimToPlayer_Perform_Patch), -26],
9595
[typeof(SeaDragonMeleeAttack_OnTouchFront_Patch), 9],
9696
[typeof(SeaDragonMeleeAttack_SwatAttack_Patch), 4],
9797
[typeof(SeaTreaderSounds_SpawnChunks_Patch), 3],

NitroxClient/Communication/Packets/Processors/PlayerStatsProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public Task Process(ClientProcessorContext context, PlayerStats playerStats)
1313
{
1414
if (playerManager.TryFind(playerStats.SessionId, out RemotePlayer remotePlayer))
1515
{
16-
RemotePlayerVitals vitals = remotePlayer.vitals;
16+
RemotePlayerVitals vitals = remotePlayer.Vitals;
1717
if (vitals)
1818
{
1919
vitals.SetOxygen(playerStats.Oxygen, playerStats.MaxOxygen);

NitroxClient/GameLogic/AI.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public sealed class AI
2828
typeof(Poop),
2929
typeof(RangedAttackLastTarget),
3030
typeof(SwimToHeroPeeper),
31+
typeof(SwimToEnzymes),
3132
typeof(SwimToMeat)
3233
];
3334

NitroxClient/GameLogic/RemotePlayer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void InitializeGameObject(GameObject playerBody)
109109
PlayerAnimation animation = PlayerContext.Animation;
110110
UpdateAnimationAndCollider((AnimChangeType)animation.Type, (AnimChangeState)animation.State);
111111

112-
vitals = playerVitalsManager.CreateOrFindForPlayer(this);
112+
Vitals = playerVitalsManager.CreateOrFindForPlayer(this);
113113
RefreshVitalsVisibility();
114114

115115
PlayerDisconnectEvent.AddHandler(Body, _ =>

NitroxClient/GameLogic/Spawning/Metadata/Extractor/StayAtLeashPositionMetadataExtractor.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
using Nitrox.Model.Subnautica.DataStructures.GameLogic.Entities.Metadata;
12
using NitroxClient.GameLogic.Spawning.Metadata.Extractor.Abstract;
2-
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
3-
using NitroxModel_Subnautica.DataStructures;
43

54
namespace NitroxClient.GameLogic.Spawning.Metadata.Extractor;
65

7-
public sealed class StayAtLeastPositionMetadataExtractor : EntityMetadataExtractor<Creature, StayAtLeashPositionMetadata>
6+
public sealed class StayAtLeashPositionMetadataExtractor : EntityMetadataExtractor<Creature, StayAtLeashPositionMetadata>
87
{
98
public override StayAtLeashPositionMetadata Extract(Creature entity)
109
{

NitroxPatcher/Patches/Dynamic/AvoidEscapePod_StopPerform_Patch.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
using HarmonyLib;
55
using NitroxClient.GameLogic.Spawning.Metadata.Extractor;
66
using NitroxClient.GameLogic;
7-
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
8-
using NitroxModel.DataStructures;
9-
using NitroxModel.Helper;
7+
using Nitrox.Model.DataStructures;
8+
using Nitrox.Model.Subnautica.DataStructures.GameLogic.Entities.Metadata;
109

1110
namespace NitroxPatcher.Patches.Dynamic;
1211

1312
public sealed partial class AvoidEscapePod_StopPerform_Patch : NitroxPatch, IDynamicPatch
1413
{
1514
internal static readonly MethodInfo TARGET_METHOD = Reflect.Method((AvoidEscapePod t) => t.StopPerform(default(Creature), default(float)));
1615

16+
// TODO: Rework this patch once we have many escape pods
1717
/**
1818
* if (EscapePod.main != null)
1919
* {
@@ -37,7 +37,7 @@ public static void BroadcastChange(Creature creature)
3737
{
3838
if (creature.TryGetNitroxId(out NitroxId creatureId))
3939
{
40-
StayAtLeashPositionMetadata metadata = Resolve<StayAtLeastPositionMetadataExtractor>().Extract(creature);
40+
StayAtLeashPositionMetadata metadata = Resolve<StayAtLeashPositionMetadataExtractor>().Extract(creature);
4141
Resolve<Entities>().BroadcastMetadataUpdate(creatureId, metadata);
4242
}
4343
}

NitroxPatcher/Patches/Dynamic/FleeOnDamage_StopPerform_Patch.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
using HarmonyLib;
55
using NitroxClient.GameLogic.Spawning.Metadata.Extractor;
66
using NitroxClient.GameLogic;
7-
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
8-
using NitroxModel.Helper;
9-
using NitroxModel.DataStructures;
7+
using Nitrox.Model.DataStructures;
8+
using Nitrox.Model.Subnautica.DataStructures.GameLogic.Entities.Metadata;
109

1110
namespace NitroxPatcher.Patches.Dynamic;
1211

@@ -36,7 +35,7 @@ public static void BroadcastChange(Creature creature)
3635
{
3736
if (creature.TryGetNitroxId(out NitroxId creatureId))
3837
{
39-
StayAtLeashPositionMetadata metadata = Resolve<StayAtLeastPositionMetadataExtractor>().Extract(creature);
38+
StayAtLeashPositionMetadata metadata = Resolve<StayAtLeashPositionMetadataExtractor>().Extract(creature);
4039
Resolve<Entities>().BroadcastMetadataUpdate(creatureId, metadata);
4140
}
4241
}

NitroxPatcher/Patches/Dynamic/MeleeAttack_OnTouch_Patch.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
using System.Collections.Generic;
21
using System.Reflection;
3-
using System.Reflection.Emit;
4-
using HarmonyLib;
2+
using Nitrox.Model.DataStructures;
53
using NitroxClient.GameLogic;
6-
using NitroxClient.MonoBehaviours.Cyclops;
7-
using NitroxModel.DataStructures;
8-
using NitroxModel.Helper;
94
using UnityEngine;
105

116
namespace NitroxPatcher.Patches.Dynamic;
127

138

149
/// <summary>
1510
/// Prevents non simulating players from running locally <see cref="MeleeAttack.OnTouch(Collider)"/>.
16-
///
17-
/// Adds RemotePlayer support for the simulating player
1811
/// </summary>
1912
public sealed partial class MeleeAttack_OnTouch_Patch : NitroxPatch, IDynamicPatch
2013
{
@@ -32,5 +25,5 @@ public static bool Prefix(MeleeAttack __instance)
3225
}
3326

3427
// TODO: Add transpiler to add support for held item eat from remote players, we might need to add an equivalent of Inventory.GetHeldItem()
35-
// For the MeleeAttack part , it'll natively work since RemotePlayer should have a LiveMixin
28+
// For the MeleeAttack part, it'll natively work since RemotePlayer should have a LiveMixin
3629
}

NitroxPatcher/Patches/Dynamic/PrisonPredatorSwimToPlayer_Evaluate_Patch.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
using HarmonyLib;
55
using NitroxClient.GameLogic;
66
using NitroxClient.GameLogic.PlayerLogic;
7-
using NitroxModel.DataStructures;
8-
using NitroxModel.Helper;
97
using UnityEngine;
108

119
namespace NitroxPatcher.Patches.Dynamic;
@@ -16,10 +14,14 @@ public sealed partial class PrisonPredatorSwimToPlayer_Evaluate_Patch : NitroxPa
1614

1715
internal static readonly EcoRegion.TargetFilter isTargetValidFilter = new(IsTargetValid);
1816

17+
/// <summary>
18+
/// Replace all the method with our custom <see cref="EvaluatePriority(PrisonPredatorSwimToPlayer, Creature, float)" />
19+
///
20+
/// Original method does hardcode Player.main usage and doesn't use any "GameObject" or Target abstraction as in other <see cref="CreatureAction"/>
21+
/// So we need to rewrite <see cref="PrisonPredatorSwimToPlayer.Evaluate(Creature, float)"/> to use the same logic as <see cref="PrisonPredatorSwimToPlayer.Perform(Creature, float, float)"/>"/>
22+
/// </summary>
1923
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
2024
{
21-
// Replace everything with
22-
// return EvaluatePriority(__instance, creature, time);
2325
yield return new CodeInstruction(OpCodes.Ldarg_0);
2426
yield return new CodeInstruction(OpCodes.Ldarg_1);
2527
yield return new CodeInstruction(OpCodes.Ldarg_2);
@@ -65,19 +67,17 @@ public static float EvaluatePriority(PrisonPredatorSwimToPlayer instance, Creatu
6567
LastTarget lastTarget = creature.GetComponent<LastTarget>();
6668
if (!lastTarget)
6769
{
68-
Log.Error($"Creature {creature} does not have a LastTarget component.");
70+
Log.Error($"[{nameof(PrisonPredatorSwimToPlayer_Evaluate_Patch)}] Creature {creature} does not have a LastTarget component.");
71+
6972
return 0f;
7073
}
7174

72-
creature.TryGetNitroxId(out NitroxId nitroxId);
73-
74-
Log.InGame($"[PrisonPredatorSwimTo Eval] {creature.name} {nitroxId?.ToString()} {gameobject.name}");
75-
lastTarget.SetTarget(gameobject);
75+
lastTarget.SetLockedTarget(gameobject);
7676

7777
return instance.GetEvaluatePriority();
7878
}
7979

80-
public static bool IsTargetValid(IEcoTarget ecoTarget)
80+
private static bool IsTargetValid(IEcoTarget ecoTarget)
8181
{
8282
GameObject target = ecoTarget.GetGameObject();
8383
if (!target)
@@ -98,7 +98,7 @@ public static bool IsTargetValid(IEcoTarget ecoTarget)
9898
return true;
9999
}
100100

101-
public static IEcoTarget GetNearestTarget(PrisonPredatorSwimToPlayer creatureAction)
101+
private static IEcoTarget GetNearestTarget(PrisonPredatorSwimToPlayer creatureAction)
102102
{
103103
IEcoTarget ecoTarget = EcoRegionManager.main.FindNearestTarget(
104104
RemotePlayer.PLAYER_ECO_TARGET_TYPE,

NitroxPatcher/Patches/Dynamic/PrisonPredatorSwimToPlayer_Perform_Patch.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
using System.Reflection;
33
using System.Reflection.Emit;
44
using HarmonyLib;
5-
using NitroxModel.DataStructures;
6-
using NitroxModel.Helper;
75
using UnityEngine;
86

97
namespace NitroxPatcher.Patches.Dynamic;
@@ -12,10 +10,14 @@ public sealed partial class PrisonPredatorSwimToPlayer_Perform_Patch : NitroxPat
1210
{
1311
internal static readonly MethodInfo TARGET_METHOD = Reflect.Method((PrisonPredatorSwimToPlayer t) => t.Perform(default, default, default));
1412

13+
/// <summary>
14+
/// Replace all the method with our custom <see cref="Perform(PrisonPredatorSwimToPlayer, Creature, float)"/>
15+
///
16+
/// Original method does hardcode Player.main usage and doesn't use any "GameObject" or Target abstraction as in other <see cref="CreatureAction"/>
17+
/// So we need to rewrite <see cref="PrisonPredatorSwimToPlayer.Evaluate(Creature, float)"/> to use the same logic as <see cref="PrisonPredatorSwimToPlayer.Perform(Creature, float)"/>"/>
18+
/// </summary>
1519
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
1620
{
17-
// Replace everything with
18-
// return EvaluatePriority(__instance, creature, time);
1921
yield return new CodeInstruction(OpCodes.Ldarg_0);
2022
yield return new CodeInstruction(OpCodes.Ldarg_1);
2123
yield return new CodeInstruction(OpCodes.Ldarg_2);
@@ -28,22 +30,17 @@ public static void Perform(PrisonPredatorSwimToPlayer instance, Creature creatur
2830
LastTarget lastTarget = creature.GetComponent<LastTarget>();
2931
if (!lastTarget)
3032
{
31-
Log.Error($"Creature {creature} does not have a LastTarget component.");
33+
Log.Error($"[{nameof(PrisonPredatorSwimToPlayer_Perform_Patch)}]: Creature {creature} does not have a LastTarget component.");
3234
return;
3335
}
3436

3537
Transform targetTransform = lastTarget.target ? lastTarget.target.transform : null;
36-
if (!targetTransform)
37-
{
38-
return;
39-
}
40-
41-
if (time > instance.timeNextSwim)
38+
if (targetTransform && time > instance.timeNextSwim)
4239
{
40+
instance.timeNextSwim = time + instance.swimInterval;
4341
instance.swimBehaviour.SwimTo(targetTransform.position, instance.swimVelocity);
44-
creature.TryGetNitroxId(out NitroxId nitroxId);
45-
46-
Log.InGame($"[PrisonPredatorSwimTo Swim] {creature.name} {nitroxId?.ToString()} {lastTarget.target.name}");
4742
}
43+
44+
lastTarget.UnlockTarget();
4845
}
4946
}

0 commit comments

Comments
 (0)