Skip to content

Commit 299308a

Browse files
committed
Add sync for AvoidEscapePod
1 parent d02bd8d commit 299308a

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

Nitrox.Test/Patcher/Patches/PatchesTranspilerTest.cs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class PatchesTranspilerTest
1717
[typeof(AggressiveWhenSeeTarget_ScanForAggressionTarget_Patch), 3],
1818
[typeof(AttackCyclops_OnCollisionEnter_Patch), -17],
1919
[typeof(AttackCyclops_UpdateAggression_Patch), -23],
20+
[typeof(AvoidEscapePod_StopPerform_Patch), 2],
2021
[typeof(Bullet_Update_Patch), 3],
2122
[typeof(BaseDeconstructable_Deconstruct_Patch), BaseDeconstructable_Deconstruct_Patch.InstructionsToAdd(true).Count() * 2],
2223
[typeof(BaseHullStrength_CrushDamageUpdate_Patch), 3],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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

Comments
 (0)