diff --git a/EXILED/Exiled.Events/Patches/Events/Player/Shooting.cs b/EXILED/Exiled.Events/Patches/Events/Player/Shooting.cs index 501c1f812b..7fe54c41a3 100644 --- a/EXILED/Exiled.Events/Patches/Events/Player/Shooting.cs +++ b/EXILED/Exiled.Events/Patches/Events/Player/Shooting.cs @@ -7,6 +7,7 @@ namespace Exiled.Events.Patches.Events.Player { + using System; using System.Collections.Generic; using System.Reflection; using System.Reflection.Emit; @@ -34,8 +35,6 @@ private static IEnumerable Transpiler(IEnumerable newInstructions = ListPool.Pool.Get(instructions); Label returnLabel = generator.DefineLabel(); - Label continueLabel1 = generator.DefineLabel(); - Label continueLabel2 = generator.DefineLabel(); /* [] <= Here @@ -59,37 +58,60 @@ private static IEnumerable Transpiler(IEnumerable - new[] - { - // ShootingEventArgs ev = new(firearm, this) - new(OpCodes.Ldarg_1), - new(OpCodes.Ldarg_0), - new(OpCodes.Newobj, constructorInfo), + // Handlers.Player.OnShooting(ev) + new(OpCodes.Dup), // Dup to keep ev on the stack + new(OpCodes.Call, Method(typeof(Handlers.Player), nameof(Handlers.Player.OnShooting))), - // Handlers.Player.OnShooting(ev) - new(OpCodes.Dup), // Dup to keep ev on the stack - new(OpCodes.Call, Method(typeof(Handlers.Player), nameof(Handlers.Player.OnShooting))), + // if (!ev.IsAllowed) return + new(OpCodes.Callvirt, PropertyGetter(typeof(ShootingEventArgs), nameof(ShootingEventArgs.IsAllowed))), + new(OpCodes.Brtrue_S, continueLabel2), - // if (!ev.IsAllowed) return - new(OpCodes.Callvirt, PropertyGetter(typeof(ShootingEventArgs), nameof(ShootingEventArgs.IsAllowed))), - new(OpCodes.Brtrue_S, continueLabel), - new(OpCodes.Leave_S, returnLabel), + // Dispose target FpcBacktracker + new(OpCodes.Ldloc_S, 5), + new(OpCodes.Callvirt, Method(typeof(IDisposable), nameof(IDisposable.Dispose))), - new CodeInstruction(OpCodes.Nop).WithLabels(continueLabel), - }; + new(OpCodes.Leave_S, returnLabel), + new CodeInstruction(OpCodes.Nop).WithLabels(continueLabel2), + }; newInstructions.InsertRange( // noTargetIndex goes first because it's higher then hasTargetIndex so it won't mess it up noTargetIndex, - patchInstructions1); + noTargetInstructions); newInstructions[noTargetIndex].WithLabels(noTargetLabels); newInstructions.InsertRange( hasTargetIndex, - patchInstructions2); + hasTargetInstructions); newInstructions[newInstructions.Count - 1].WithLabels(returnLabel);