diff --git a/EXILED/Exiled.Events/EventArgs/Player/ShootingEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/ShootingEventArgs.cs index c348e649b1..3c2f9d12b6 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/ShootingEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/ShootingEventArgs.cs @@ -8,106 +8,72 @@ namespace Exiled.Events.EventArgs.Player { using API.Features; - using Exiled.API.Features.Items; - using Interfaces; - - using InventorySystem.Items.Firearms.BasicMessages; - - using RelativePositioning; - + using InventorySystem.Items.Firearms.Modules.Misc; using UnityEngine; using BaseFirearm = InventorySystem.Items.Firearms.Firearm; /// /// Contains all information before a player fires a weapon. + /// ClaimedTarget and Player transform values are modified by according to sent by the Player and do not match the actual values. /// public class ShootingEventArgs : IPlayerEvent, IDeniableEvent, IFirearmEvent { /// /// Initializes a new instance of the class. /// - /// - /// - /// /// - /// + /// The that is being fired. /// - public ShootingEventArgs(Player shooter, BaseFirearm firearm) + /// + /// sent by the client. + /// + public ShootingEventArgs(BaseFirearm firearm, ref ShotBacktrackData shotBacktrackData) { - Player = shooter; - Firearm = Item.Get(firearm).As(); - - // ShotMessage = msg; + Firearm = (Firearm)Item.Get(firearm); + Player = Firearm.Owner; + ShotBacktrackData = shotBacktrackData; } /// - /// Gets the player who's shooting. + /// Gets the player who is shooting. /// public Player Player { get; } /// - /// Gets the target . + /// Gets the target that client claims it hit. /// - public Firearm Firearm { get; } - - /// - public Item Item => Firearm; + /// This value is controlled by the shooting player and should not be trusted. Can be null. + public Player ClaimedTarget => ShotBacktrackData.HasPrimaryTarget ? Player.Get(ShotBacktrackData.PrimaryTargetHub) : null; - /* /// - /// Gets or sets the for the event. + /// Gets the . This object contains the data sent by the client to the server. /// - public ShotMessage ShotMessage { get; set; } + /// Values are controlled by the shooting player and should not be trusted. + public ShotBacktrackData ShotBacktrackData { get; } /// - /// Gets or sets the position of the shot. + /// Gets or sets the exact direction of the shot before the bullet spread is applied. /// - public Vector3 ShotPosition + public Vector3 Direction { - get => ShotMessage.TargetPosition.Position; - set - { - ShotMessage msg = ShotMessage; - ShotMessage = new ShotMessage - { - ShooterPosition = msg.ShooterPosition, - ShooterCameraRotation = msg.ShooterCameraRotation, - ShooterWeaponSerial = msg.ShooterWeaponSerial, - TargetPosition = new RelativePosition(value), - TargetRotation = msg.TargetRotation, - TargetNetId = msg.TargetNetId, - }; - } + get => Player.CameraTransform.forward; + set => Player.CameraTransform.forward = value; // It is going to be reset by FpcBacktracker the same frame, so why we can set it freely. } /// - /// Gets or sets the netId of the target of the shot. + /// Gets the firearm that is being fired. /// - public uint TargetNetId - { - get => ShotMessage.TargetNetId; - set - { - ShotMessage msg = ShotMessage; - ShotMessage = new ShotMessage - { - ShooterPosition = msg.ShooterPosition, - ShooterCameraRotation = msg.ShooterCameraRotation, - ShooterWeaponSerial = msg.ShooterWeaponSerial, - TargetPosition = msg.TargetPosition, - TargetRotation = msg.TargetRotation, - TargetNetId = value, - }; - } - } - */ + public Firearm Firearm { get; } + + /// + public Item Item => Firearm; /// /// Gets or sets a value indicating whether the shot can be fired. /// public bool IsAllowed { get; set; } = true; } -} +} \ No newline at end of file diff --git a/EXILED/Exiled.Events/Patches/Events/Player/Shooting.cs b/EXILED/Exiled.Events/Patches/Events/Player/Shooting.cs index fc1265b8e1..501c1f812b 100644 --- a/EXILED/Exiled.Events/Patches/Events/Player/Shooting.cs +++ b/EXILED/Exiled.Events/Patches/Events/Player/Shooting.cs @@ -8,19 +8,14 @@ namespace Exiled.Events.Patches.Events.Player { using System.Collections.Generic; + using System.Reflection; using System.Reflection.Emit; using API.Features; using API.Features.Pools; - using Exiled.Events.Attributes; using Exiled.Events.EventArgs.Player; - using HarmonyLib; - - using InventorySystem.Items.Firearms; - using InventorySystem.Items.Firearms.BasicMessages; - using InventorySystem.Items.Firearms.Modules; using InventorySystem.Items.Firearms.Modules.Misc; using static HarmonyLib.AccessTools; @@ -39,34 +34,62 @@ private static IEnumerable Transpiler(IEnumerable newInstructions = ListPool.Pool.Get(instructions); Label returnLabel = generator.DefineLabel(); - - int offset = 1; - int index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Stloc_2) + offset; - - newInstructions.InsertRange( - index, + Label continueLabel1 = generator.DefineLabel(); + Label continueLabel2 = generator.DefineLabel(); + + /* + [] <= Here + IL_0078: ldarg.2 // processingMethod + IL_0079: ldarg.0 // this + IL_007a: ldfld class ReferenceHub InventorySystem.Items.Firearms.Modules.Misc.ShotBacktrackData::PrimaryTargetHub + IL_007f: callvirt instance void class [mscorlib]System.Action`1::Invoke(!0/*class ReferenceHub* /) + */ + int hasTargetIndex = newInstructions.FindIndex(instruction => instruction.IsLdarg(2)); + + /* + [] <= Here + IL_0092: ldarg.2 // processingMethod + IL_0093: ldnull // null + IL_0094: callvirt instance void class [mscorlib]System.Action`1::Invoke(!0/*class ReferenceHub* /) + */ + int noTargetIndex = newInstructions.FindIndex(hasTargetIndex + 1, instruction => instruction.IsLdarg(2)); + List