diff --git a/EXILED/Exiled.Events/Patches/Fixes/FixScp1507DestroyingDoor.cs b/EXILED/Exiled.Events/Patches/Fixes/FixScp1507DestroyingDoor.cs new file mode 100644 index 000000000..c40037f4b --- /dev/null +++ b/EXILED/Exiled.Events/Patches/Fixes/FixScp1507DestroyingDoor.cs @@ -0,0 +1,52 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.Patches.Fixes +{ + using System.Collections.Generic; + using System.Reflection.Emit; + + using API.Features.Pools; + using Footprinting; + using HarmonyLib; + using Interactables.Interobjects.DoorUtils; + using PlayerRoles.PlayableScps.Scp1507; + + using static HarmonyLib.AccessTools; + + /// + /// Patches delegate. + /// Fix than NW don't set the footprint argument . + /// + [HarmonyPatch(typeof(Scp1507AttackAbility), nameof(Scp1507AttackAbility.TryAttackDoor))] + internal class FixScp1507DestroyingDoor + { + private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) + { + List newInstructions = ListPool.Pool.Get(instructions); + + int offset = -1; + int index = newInstructions.FindLastIndex(instruction => instruction.opcode == OpCodes.Initobj) + offset; + + newInstructions.RemoveRange(index, 3); + + newInstructions.InsertRange( + index, + new CodeInstruction[] + { + new(OpCodes.Ldarg_0), + new(OpCodes.Callvirt, PropertyGetter(typeof(Scp1507AttackAbility), nameof(Scp1507AttackAbility.Owner))), + new(OpCodes.Newobj, GetDeclaredConstructors(typeof(Footprint))[0]), + }); + + for (int z = 0; z < newInstructions.Count; z++) + yield return newInstructions[z]; + + ListPool.Pool.Return(newInstructions); + } + } +}