diff --git a/Exiled.Events/EventArgs/Map/ExplodingGrenadeEventArgs.cs b/Exiled.Events/EventArgs/Map/ExplodingGrenadeEventArgs.cs
index b8e1fec768..28b7b30f0d 100644
--- a/Exiled.Events/EventArgs/Map/ExplodingGrenadeEventArgs.cs
+++ b/Exiled.Events/EventArgs/Map/ExplodingGrenadeEventArgs.cs
@@ -88,15 +88,18 @@ public ExplodingGrenadeEventArgs(Footprint thrower, Vector3 position, ExplosionG
///
///
///
+ ///
+ ///
+ ///
///
///
///
- public ExplodingGrenadeEventArgs(Player thrower, EffectGrenade grenade, bool isAllowed = true)
+ public ExplodingGrenadeEventArgs(Player thrower, EffectGrenade grenade, List targetsToAffect, bool isAllowed = true)
{
Player = thrower ?? Server.Host;
Projectile = (EffectGrenadeProjectile)Pickup.Get(grenade);
Position = Projectile.Position;
- TargetsToAffect = ListPool.Pool.Get(Player.List);
+ TargetsToAffect = ListPool.Pool.Get(targetsToAffect ?? new());
IsAllowed = isAllowed;
}
diff --git a/Exiled.Events/Patches/Events/Map/BreakingScp2176.cs b/Exiled.Events/Patches/Events/Map/BreakingScp2176.cs
index 9b0c2cb5c5..53f8f97e43 100644
--- a/Exiled.Events/Patches/Events/Map/BreakingScp2176.cs
+++ b/Exiled.Events/Patches/Events/Map/BreakingScp2176.cs
@@ -50,11 +50,14 @@ private static IEnumerable Transpiler(IEnumerable, bool)
+ new(OpCodes.Newobj, DeclaredConstructor(typeof(ExplodingGrenadeEventArgs), new[] { typeof(Player), typeof(EffectGrenade), typeof(List), typeof(bool) })),
new(OpCodes.Dup),
// Handlers.Map.OnExplodingGrenade(ev);
diff --git a/Exiled.Events/Patches/Events/Map/ExplodingFlashGrenade.cs b/Exiled.Events/Patches/Events/Map/ExplodingFlashGrenade.cs
index 7320ef208b..236939b22a 100644
--- a/Exiled.Events/Patches/Events/Map/ExplodingFlashGrenade.cs
+++ b/Exiled.Events/Patches/Events/Map/ExplodingFlashGrenade.cs
@@ -7,6 +7,7 @@
namespace Exiled.Events.Patches.Events.Map
{
+ using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
@@ -35,27 +36,25 @@ private static IEnumerable Transpiler(IEnumerable newInstructions = ListPool.Pool.Get(instructions);
- // Immediately return
- Label returnLabel = generator.DefineLabel();
+ Label ignoreLabel = generator.DefineLabel();
- int offset = 4;
- int index = newInstructions.FindLastIndex(instruction => instruction.Calls(PropertyGetter(typeof(Keyframe), nameof(Keyframe.time)))) + offset;
+ int offset = 1;
+ int index = newInstructions.FindLastIndex(instruction => instruction.StoresField(Field(typeof(FlashbangGrenade), nameof(FlashbangGrenade._hitPlayerCount)))) + offset;
newInstructions.InsertRange(
index,
new[]
{
- // FlashbangGrenade
+ // ExplodingFlashGrenade.ProcessEvent(this, num)
new CodeInstruction(OpCodes.Ldarg_0),
- new CodeInstruction(OpCodes.Ldarg_0),
-
- // Processes ExplodingGrenadeEventArgs and stores flashed players count
+ new CodeInstruction(OpCodes.Ldloc_0),
new(OpCodes.Call, Method(typeof(ExplodingFlashGrenade), nameof(ProcessEvent))),
- new(OpCodes.Stfld, Field(typeof(FlashbangGrenade), nameof(FlashbangGrenade._hitPlayerCount))),
- new(OpCodes.Br_S, returnLabel),
+
+ // ignore the foreach since exiled overwrite it
+ new(OpCodes.Br_S, ignoreLabel),
});
- newInstructions[newInstructions.FindLastIndex(i => i.opcode == OpCodes.Ble_S) - 3].WithLabels(returnLabel);
+ newInstructions[newInstructions.FindLastIndex(i => i.opcode == OpCodes.Ble_S) - 3].WithLabels(ignoreLabel);
for (int z = 0; z < newInstructions.Count; z++)
yield return newInstructions[z];
@@ -63,31 +62,37 @@ private static IEnumerable Transpiler(IEnumerable.Pool.Return(newInstructions);
}
- private static int ProcessEvent(FlashbangGrenade instance)
+ private static void ProcessEvent(FlashbangGrenade instance, float distance)
{
- ExplodingGrenadeEventArgs explodingGrenadeEvent = new ExplodingGrenadeEventArgs(Player.Get(instance.PreviousOwner.Hub), instance);
+ List targetToAffect = ListPool.Pool.Get();
+ foreach (ReferenceHub referenceHub in ReferenceHub.AllHubs)
+ {
+ Player player = Player.Get(referenceHub);
+ if ((instance.transform.position - referenceHub.transform.position).sqrMagnitude <= distance)
+ continue;
+ if (!ExiledEvents.Instance.Config.CanFlashbangsAffectThrower && instance.PreviousOwner.SameLife(new(referenceHub)))
+ continue;
+ if (!IndividualFriendlyFire.CheckFriendlyFirePlayer(instance.PreviousOwner, player.ReferenceHub))
+ continue;
+ if (!Physics.Linecast(instance.transform.position, player.Position, instance._blindingMask))
+ continue;
+
+ targetToAffect.Add(Player.Get(referenceHub));
+ }
+
+ ExplodingGrenadeEventArgs explodingGrenadeEvent = new(Player.Get(instance.PreviousOwner.Hub), instance, targetToAffect);
+
+ ListPool.Pool.Return(targetToAffect);
Handlers.Map.OnExplodingGrenade(explodingGrenadeEvent);
if (!explodingGrenadeEvent.IsAllowed)
- return 0;
+ return;
- int size = 0;
foreach (Player player in explodingGrenadeEvent.TargetsToAffect)
{
- if (!ExiledEvents.Instance.Config.CanFlashbangsAffectThrower && explodingGrenadeEvent.Player == player)
- continue;
-
- if (IndividualFriendlyFire.CheckFriendlyFirePlayer(instance.PreviousOwner, player.ReferenceHub))
- {
- instance.ProcessPlayer(player.ReferenceHub);
- size++;
- }
+ instance.ProcessPlayer(player.ReferenceHub);
}
-
- return size;
}
-
- private static List ConvertHubs(List hubs) => hubs.Select(Player.Get).ToList();
}
}
\ No newline at end of file