-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
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
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
43 changes: 43 additions & 0 deletions
43
NitroxPatcher/Patches/Dynamic/FleeOnDamage_StopPerform_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,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); | ||
} | ||
} | ||
} |