diff --git a/EXILED/Exiled.Events/Patches/Events/Map/SpawningItem.cs b/EXILED/Exiled.Events/Patches/Events/Map/SpawningItem.cs index df768a3048..bac813d138 100644 --- a/EXILED/Exiled.Events/Patches/Events/Map/SpawningItem.cs +++ b/EXILED/Exiled.Events/Patches/Events/Map/SpawningItem.cs @@ -11,18 +11,22 @@ namespace Exiled.Events.Patches.Events.Map using System.Reflection.Emit; using API.Features.Doors; - using API.Features.Pickups; using API.Features.Pools; - using Exiled.Events.Attributes; - using Exiled.Events.EventArgs.Map; - using Handlers; + using Attributes; + + using EventArgs.Map; + using HarmonyLib; + using Interactables.Interobjects.DoorUtils; + using MapGeneration.Distributors; using static HarmonyLib.AccessTools; + using Map = Handlers.Map; + /// /// Patches . /// Adds the event. @@ -40,6 +44,9 @@ private static IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable i.opcode == OpCodes.Ldfld) + offset; + index = newInstructions.FindLastIndex(i => i.LoadsField(Field(typeof(DoorVariantExtension), nameof(DoorVariantExtension.TargetDoor)))) + offset; + + newInstructions[index].WithLabels(allowOriginalLogic); - newInstructions.RemoveRange(index, 2); + int temp_instr = newInstructions.FindLastIndex(i => i.Calls(PropertyGetter(typeof(UnityEngine.Component), nameof(UnityEngine.Component.gameObject)))) - 1; + newInstructions[temp_instr].WithLabels(loadGameObjectLocation); newInstructions.InsertRange(index, new[] { // ev.Door.Base - new CodeInstruction(OpCodes.Ldloc_S, ev.LocalIndex), + new CodeInstruction(OpCodes.Ldloc, ev.LocalIndex), + new(OpCodes.Brfalse, allowOriginalLogic), + new CodeInstruction(OpCodes.Ldloc, ev.LocalIndex), + new(OpCodes.Callvirt, PropertyGetter(typeof(SpawningItemEventArgs), nameof(SpawningItemEventArgs.TriggerDoor))), + new(OpCodes.Brfalse, allowOriginalLogic), + new CodeInstruction(OpCodes.Ldloc, ev.LocalIndex), new(OpCodes.Callvirt, PropertyGetter(typeof(SpawningItemEventArgs), nameof(SpawningItemEventArgs.TriggerDoor))), new(OpCodes.Callvirt, PropertyGetter(typeof(Door), nameof(Door.Base))), + new(OpCodes.Br, loadGameObjectLocation), }); - newInstructions[newInstructions.Count - 1].WithLabels(returnLabel); - for (int z = 0; z < newInstructions.Count; z++) yield return newInstructions[z];