Skip to content

Commit

Permalink
Sync FleeOnDamage
Browse files Browse the repository at this point in the history
  • Loading branch information
dartasen committed Jan 12, 2025
1 parent 8c5c008 commit 19d2afe
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions Nitrox.Test/Patcher/Patches/PatchesTranspilerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class PatchesTranspilerTest
[typeof(FireExtinguisherHolder_TakeTankAsync_Patch), 2],
[typeof(FireExtinguisherHolder_TryStoreTank_Patch), 3],
[typeof(Flare_Update_Patch), 0],
[typeof(FleeOnDamage_StopPerform_Patch), 2],
[typeof(FootstepSounds_OnStep_Patch), 6],
[typeof(GameInput_Initialize_Patch), 5],
[typeof(Player_TriggerInfectionRevealAsync_Patch), 1],
Expand Down
1 change: 0 additions & 1 deletion NitroxClient/GameLogic/Entities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public class Entities
private bool spawningEntities;

private readonly HashSet<NitroxId> deletedEntitiesIds = new();
private readonly List<SimulatedEntity> pendingSimulatedEntities = new();

public Entities(IPacketSender packetSender, ThrottledPacketSender throttledPacketSender, EntityMetadataManager entityMetadataManager, PlayerManager playerManager, ILocalNitroxPlayer localPlayer, LiveMixinManager liveMixinManager, TimeManager timeManager, SimulationOwnership simulationOwnership)
{
Expand Down
43 changes: 43 additions & 0 deletions NitroxPatcher/Patches/Dynamic/FleeOnDamage_StopPerform_Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using HarmonyLib;
using NitroxClient.GameLogic.Spawning.Metadata.Extractor;
using NitroxClient.GameLogic;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using NitroxModel.Helper;
using NitroxModel.DataStructures;

namespace NitroxPatcher.Patches.Dynamic;

public sealed partial class FleeOnDamage_StopPerform_Patch : NitroxPatch, IDynamicPatch
{
internal static readonly MethodInfo TARGET_METHOD = Reflect.Method((FleeOnDamage t) => t.StopPerform(default, default));

/**
* this.accumulatedDamage = 0f;
* if (this.breakLeash)
* {
* creature.leashPosition = base.transform.position;
* FleeOnDamage_StopPerform_Patch.BroadcastChange(creature); <======= [INSERTED LINE]
* }
**/
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
return new CodeMatcher(instructions).MatchEndForward(new CodeMatch(OpCodes.Stfld, Reflect.Field((Creature t) => t.leashPosition)))
.Advance(1)
.InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_1))
.Insert(new CodeInstruction(OpCodes.Call, Reflect.Method(() => BroadcastChange(default))))
.InstructionEnumeration();
}

public static void BroadcastChange(Creature creature)
{
if (creature.TryGetNitroxId(out NitroxId creatureId))
{
StayAtLeashPositionMetadata metadata = Resolve<StayAtLeastPositionMetadataExtractor>().Extract(creature);
Resolve<Entities>().BroadcastMetadataUpdate(creatureId, metadata);
}
}
}

0 comments on commit 19d2afe

Please sign in to comment.