From 6a9c9b6ab96db59cb144355b24be4af14d65393f Mon Sep 17 00:00:00 2001 From: Banalny-Banan Date: Thu, 28 Nov 2024 14:57:12 +0200 Subject: [PATCH 1/8] New Shooting patch (not tested) --- .../EventArgs/Player/ShootingEventArgs.cs | 89 +++++-------------- .../Patches/Events/Player/Shooting.cs | 89 +++++++++---------- 2 files changed, 67 insertions(+), 111 deletions(-) diff --git a/EXILED/Exiled.Events/EventArgs/Player/ShootingEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/ShootingEventArgs.cs index c348e649b..e58f0b9d9 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/ShootingEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/ShootingEventArgs.cs @@ -5,20 +5,16 @@ // // ----------------------------------------------------------------------- +using InventorySystem.Items.Firearms.Modules.Misc; + namespace Exiled.Events.EventArgs.Player { using API.Features; - + using Exiled.API.Features.Items; - + using Interfaces; - - using InventorySystem.Items.Firearms.BasicMessages; - - using RelativePositioning; - - using UnityEngine; - + using BaseFirearm = InventorySystem.Items.Firearms.Firearm; /// @@ -29,85 +25,46 @@ public class ShootingEventArgs : IPlayerEvent, IDeniableEvent, IFirearmEvent /// /// Initializes a new instance of the class. /// - /// - /// - /// /// - /// + /// The that is being fired. + /// + /// + /// sent by the client. /// - public ShootingEventArgs(Player shooter, BaseFirearm firearm) + public ShootingEventArgs(BaseFirearm firearm, ShotBacktrackData shotBacktrackData) { - Player = shooter; - Firearm = Item.Get(firearm).As(); - + Firearm = (Firearm)Item.Get(firearm); + Player = Firearm.Owner; + ShotBacktrackData = shotBacktrackData; // ShotMessage = msg; } /// - /// 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. This value is controlled by the client and should not be trusted. Can be null. /// - public Firearm Firearm { get; } + public Player ClaimedTarget => ShotBacktrackData.HasPrimaryTarget ? Player.Get(ShotBacktrackData.PrimaryTargetHub) : null; - /// - public Item Item => Firearm; - - /* /// - /// Gets or sets the for the event. + /// Gets the . This object contains the data sent by the client to the server. Values should not be trusted. /// - public ShotMessage ShotMessage { get; set; } + public ShotBacktrackData ShotBacktrackData { get; } /// - /// Gets or sets the position of the shot. + /// Gets the target . /// - public Vector3 ShotPosition - { - 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, - }; - } - } + public Firearm Firearm { get; } - /// - /// Gets or sets the netId of the target of the shot. - /// - 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 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 3c779e704..bbc60faea 100644 --- a/EXILED/Exiled.Events/Patches/Events/Player/Shooting.cs +++ b/EXILED/Exiled.Events/Patches/Events/Player/Shooting.cs @@ -18,8 +18,7 @@ namespace Exiled.Events.Patches.Events.Player using HarmonyLib; - using InventorySystem.Items.Firearms.BasicMessages; - using InventorySystem.Items.Firearms.Modules; + using InventorySystem.Items.Firearms.Modules.Misc; using static HarmonyLib.AccessTools; @@ -28,58 +27,59 @@ namespace Exiled.Events.Patches.Events.Player /// Adds the events. /// [EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.Shooting))] - - // [HarmonyPatch(typeof(FirearmBasicMessagesHandler), nameof(FirearmBasicMessagesHandler.ServerShotReceived))] + + [HarmonyPatch(typeof(ShotBacktrackData), nameof(ShotBacktrackData.ProcessShot))] internal static class Shooting { - /* private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) { List newInstructions = ListPool.Pool.Get(instructions); - Label isAllowedLabel = generator.DefineLabel(); Label returnLabel = generator.DefineLabel(); - LocalBuilder ev = generator.DeclareLocal(typeof(ShootingEventArgs)); - - int offset = -2; - int index = newInstructions.FindIndex(instruction => instruction.Calls(Method(typeof(IActionModule), nameof(IActionModule.ServerAuthorizeShot)))) + offset; + /* + [] <= Here + IL_0078: ldarg.2 // processingMethod (FindIndex here) + 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)) - 1; + List