Skip to content

Commit 19d2afe

Browse files
committed
Sync FleeOnDamage
1 parent 8c5c008 commit 19d2afe

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

Nitrox.Test/Patcher/Patches/PatchesTranspilerTest.cs

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class PatchesTranspilerTest
4747
[typeof(FireExtinguisherHolder_TakeTankAsync_Patch), 2],
4848
[typeof(FireExtinguisherHolder_TryStoreTank_Patch), 3],
4949
[typeof(Flare_Update_Patch), 0],
50+
[typeof(FleeOnDamage_StopPerform_Patch), 2],
5051
[typeof(FootstepSounds_OnStep_Patch), 6],
5152
[typeof(GameInput_Initialize_Patch), 5],
5253
[typeof(Player_TriggerInfectionRevealAsync_Patch), 1],

NitroxClient/GameLogic/Entities.cs

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public class Entities
4040
private bool spawningEntities;
4141

4242
private readonly HashSet<NitroxId> deletedEntitiesIds = new();
43-
private readonly List<SimulatedEntity> pendingSimulatedEntities = new();
4443

4544
public Entities(IPacketSender packetSender, ThrottledPacketSender throttledPacketSender, EntityMetadataManager entityMetadataManager, PlayerManager playerManager, ILocalNitroxPlayer localPlayer, LiveMixinManager liveMixinManager, TimeManager timeManager, SimulationOwnership simulationOwnership)
4645
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System.Collections.Generic;
2+
using System.Reflection;
3+
using System.Reflection.Emit;
4+
using HarmonyLib;
5+
using NitroxClient.GameLogic.Spawning.Metadata.Extractor;
6+
using NitroxClient.GameLogic;
7+
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
8+
using NitroxModel.Helper;
9+
using NitroxModel.DataStructures;
10+
11+
namespace NitroxPatcher.Patches.Dynamic;
12+
13+
public sealed partial class FleeOnDamage_StopPerform_Patch : NitroxPatch, IDynamicPatch
14+
{
15+
internal static readonly MethodInfo TARGET_METHOD = Reflect.Method((FleeOnDamage t) => t.StopPerform(default, default));
16+
17+
/**
18+
* this.accumulatedDamage = 0f;
19+
* if (this.breakLeash)
20+
* {
21+
* creature.leashPosition = base.transform.position;
22+
* FleeOnDamage_StopPerform_Patch.BroadcastChange(creature); <======= [INSERTED LINE]
23+
* }
24+
25+
**/
26+
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
27+
{
28+
return new CodeMatcher(instructions).MatchEndForward(new CodeMatch(OpCodes.Stfld, Reflect.Field((Creature t) => t.leashPosition)))
29+
.Advance(1)
30+
.InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_1))
31+
.Insert(new CodeInstruction(OpCodes.Call, Reflect.Method(() => BroadcastChange(default))))
32+
.InstructionEnumeration();
33+
}
34+
35+
public static void BroadcastChange(Creature creature)
36+
{
37+
if (creature.TryGetNitroxId(out NitroxId creatureId))
38+
{
39+
StayAtLeashPositionMetadata metadata = Resolve<StayAtLeastPositionMetadataExtractor>().Extract(creature);
40+
Resolve<Entities>().BroadcastMetadataUpdate(creatureId, metadata);
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)