|
| 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.DataStructures; |
| 9 | +using NitroxModel.Helper; |
| 10 | + |
| 11 | +namespace NitroxPatcher.Patches.Dynamic; |
| 12 | + |
| 13 | +public sealed partial class AvoidEscapePod_StopPerform_Patch : NitroxPatch, IDynamicPatch |
| 14 | +{ |
| 15 | + internal static readonly MethodInfo TARGET_METHOD = Reflect.Method((AvoidEscapePod t) => t.StopPerform(default(Creature), default(float))); |
| 16 | + |
| 17 | + /** |
| 18 | + * if (EscapePod.main != null) |
| 19 | + * { |
| 20 | + * Vector3 position = EscapePod.main.transform.position; |
| 21 | + * if (Vector3.Distance(position, base.transform.position) > Vector3.Distance(position, creature.leashPosition)) |
| 22 | + * { |
| 23 | + * creature.leashPosition = base.transform.position; |
| 24 | + * AvoidEscapePod_StopPerform_Patch.BroadcastChange(creature); <======= [INSERTED LINE] |
| 25 | + * } |
| 26 | + **/ |
| 27 | + public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) |
| 28 | + { |
| 29 | + return new CodeMatcher(instructions).MatchEndForward(new CodeMatch(OpCodes.Stfld, Reflect.Field((Creature t) => t.leashPosition))) |
| 30 | + .Advance(1) |
| 31 | + .InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_1)) |
| 32 | + .Insert(new CodeInstruction(OpCodes.Call, Reflect.Method(() => BroadcastChange(default)))) |
| 33 | + .InstructionEnumeration(); |
| 34 | + } |
| 35 | + |
| 36 | + public static void BroadcastChange(Creature creature) |
| 37 | + { |
| 38 | + if (creature.TryGetNitroxId(out NitroxId creatureId)) |
| 39 | + { |
| 40 | + StayAtLeashPositionMetadata metadata = Resolve<StayAtLeastPositionMetadataExtractor>().Extract(creature); |
| 41 | + Resolve<Entities>().BroadcastMetadataUpdate(creatureId, metadata); |
| 42 | + } |
| 43 | + } |
| 44 | +} |
0 commit comments