From 3dbe83734af4afbc02ab0b7b41593f5fd73aa65e Mon Sep 17 00:00:00 2001 From: xNexusACS <83370388+xNexusACS@users.noreply.github.com> Date: Mon, 28 Oct 2024 21:29:59 +0100 Subject: [PATCH 1/5] Ban event improvements & Port TPS Fix to Dev --- .../EventArgs/Player/BannedEventArgs.cs | 5 +++ Exiled.Events/Patches/Events/Player/Banned.cs | 4 +- .../Patches/Fixes/VoiceChatTpsFix.cs | 41 +++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 Exiled.Events/Patches/Fixes/VoiceChatTpsFix.cs diff --git a/Exiled.Events/EventArgs/Player/BannedEventArgs.cs b/Exiled.Events/EventArgs/Player/BannedEventArgs.cs index 0d55acc865..458e118228 100644 --- a/Exiled.Events/EventArgs/Player/BannedEventArgs.cs +++ b/Exiled.Events/EventArgs/Player/BannedEventArgs.cs @@ -57,5 +57,10 @@ public BannedEventArgs(Player target, Player issuer, BanDetails details, BanHand /// Gets a value indicating whether the ban is forced or not. /// public bool IsForced { get; } + + /// + /// Gets a value indicating whether the ban is an offline ban or not. + /// + public bool IsOffline => Details.OriginalName == "Unknown - offline ban"; } } \ No newline at end of file diff --git a/Exiled.Events/Patches/Events/Player/Banned.cs b/Exiled.Events/Patches/Events/Player/Banned.cs index c2934279f2..ba1a9667aa 100644 --- a/Exiled.Events/Patches/Events/Player/Banned.cs +++ b/Exiled.Events/Patches/Events/Player/Banned.cs @@ -75,8 +75,8 @@ private static IEnumerable Transpiler(IEnumerable.Pool.Return(newInstructions); } diff --git a/Exiled.Events/Patches/Fixes/VoiceChatTpsFix.cs b/Exiled.Events/Patches/Fixes/VoiceChatTpsFix.cs new file mode 100644 index 0000000000..3905946b47 --- /dev/null +++ b/Exiled.Events/Patches/Fixes/VoiceChatTpsFix.cs @@ -0,0 +1,41 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Exiled Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.Patches.Fixes +{ + using System.Collections.Generic; + using System.Reflection.Emit; + + using API.Features.Core.Generic.Pools; + + using HarmonyLib; + + using VoiceChat.Networking; + + /// + /// Fixes method. + /// + [HarmonyPatch(typeof(VoiceTransceiver), nameof(VoiceTransceiver.ServerReceiveMessage))] + internal static class VoiceChatTpsFix + { + private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) + { + List newInstructions = ListPool.Pool.Get(instructions); + + const int offset = -1; + int index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Newarr) + offset; + + // new array length 480 + newInstructions[index].operand = 480; + + foreach (CodeInstruction instruction in newInstructions) + yield return instruction; + + ListPool.Pool.Return(newInstructions); + } + } +} \ No newline at end of file From 450bd748b308eecc5d72c38756815f04cabdeb15 Mon Sep 17 00:00:00 2001 From: xNexusACS <83370388+xNexusACS@users.noreply.github.com> Date: Mon, 28 Oct 2024 21:44:17 +0100 Subject: [PATCH 2/5] PreAuth patch port --- .../Player/PreAuthenticatingEventArgs.cs | 4 +- Exiled.Events/Handlers/Player.cs | 32 +------ .../Events/Player/PreAuthenticating.cs | 91 +++++++++++++++++++ 3 files changed, 95 insertions(+), 32 deletions(-) create mode 100644 Exiled.Events/Patches/Events/Player/PreAuthenticating.cs diff --git a/Exiled.Events/EventArgs/Player/PreAuthenticatingEventArgs.cs b/Exiled.Events/EventArgs/Player/PreAuthenticatingEventArgs.cs index da0845899b..26555d2432 100644 --- a/Exiled.Events/EventArgs/Player/PreAuthenticatingEventArgs.cs +++ b/Exiled.Events/EventArgs/Player/PreAuthenticatingEventArgs.cs @@ -94,9 +94,9 @@ public PreAuthenticatingEventArgs( public ConnectionRequest Request { get; } /// - /// Gets a value indicating whether the player can be authenticated or not. + /// Gets or sets a value indicating whether the player can be authenticated or not. /// - public bool IsAllowed { get; private set; } = true; + public bool IsAllowed { get; set; } = true; /// /// Gets or sets the cached that is returned back to the NwPluginAPI. diff --git a/Exiled.Events/Handlers/Player.cs b/Exiled.Events/Handlers/Player.cs index 30526c8f22..4a9f686b43 100644 --- a/Exiled.Events/Handlers/Player.cs +++ b/Exiled.Events/Handlers/Player.cs @@ -7,7 +7,6 @@ namespace Exiled.Events.Handlers { - using Exiled.API.Features.Pickups; #pragma warning disable IDE0079 #pragma warning disable IDE0060 #pragma warning disable SA1623 // Property summary documentation should match accessors @@ -16,10 +15,6 @@ namespace Exiled.Events.Handlers using Exiled.Events.Features; - using PluginAPI.Core.Attributes; - using PluginAPI.Enums; - using PluginAPI.Events; - /// /// Player related events. /// @@ -1218,30 +1213,7 @@ public static void OnItemRemoved(ReferenceHub referenceHub, InventorySystem.Item /// /// Called before pre-authenticating a . /// - /// - /// - /// - /// - /// - /// - /// - /// - /// Returns the instance. - [PluginEvent(ServerEventType.PlayerPreauth)] - public PreauthCancellationData OnPreAuthenticating( - string userId, - string ipAddress, - long expiration, - CentralAuthPreauthFlags flags, - string country, - byte[] signature, - LiteNetLib.ConnectionRequest request, - int readerStartPosition) - { - PreAuthenticatingEventArgs ev = new(userId, ipAddress, expiration, flags, country, signature, request, readerStartPosition); - PreAuthenticating.InvokeSafely(ev); - - return ev.CachedPreauthData; - } + /// instance. + public static void OnPreAuthenticating(PreAuthenticatingEventArgs ev) => PreAuthenticating.InvokeSafely(ev); } } diff --git a/Exiled.Events/Patches/Events/Player/PreAuthenticating.cs b/Exiled.Events/Patches/Events/Player/PreAuthenticating.cs new file mode 100644 index 0000000000..8362bb354f --- /dev/null +++ b/Exiled.Events/Patches/Events/Player/PreAuthenticating.cs @@ -0,0 +1,91 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Exiled Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.Patches.Events.Player +{ + using System.Collections.Generic; + using System.Reflection.Emit; + + using API.Features.Core.Generic.Pools; + using Exiled.Events.Attributes; + using Exiled.Events.EventArgs.Player; + + using HarmonyLib; + + using LiteNetLib; + + using static HarmonyLib.AccessTools; + + /// + /// Patches . + /// Adds the event. + /// + [EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.PreAuthenticating))] + [HarmonyPatch(typeof(CustomLiteNetLib4MirrorTransport), nameof(CustomLiteNetLib4MirrorTransport.ProcessConnectionRequest))] + internal static class PreAuthenticating + { + private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) + { + List newInstructions = ListPool.Pool.Get(instructions); + + Label ret = generator.DefineLabel(); + newInstructions[newInstructions.Count - 1].labels.Add(ret); + + LocalBuilder ev = generator.DeclareLocal(typeof(PreAuthenticatingEventArgs)); + int index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Ldstr && (string)instruction.operand == "{0};{1};{2};{3}"); + + newInstructions.InsertRange( + index, + new[] + { + // userid + new CodeInstruction(OpCodes.Ldloc_S, 10), + + // ipaddress + new (OpCodes.Ldloc_S, 15), + + // expiration + new (OpCodes.Ldloc_S, 11), + + // flags + new (OpCodes.Ldloc_S, 12), + + // country + new (OpCodes.Ldloc_S, 13), + + // signature + new (OpCodes.Ldloc_S, 14), + + // request + new (OpCodes.Ldarg_1), + + // position + new (OpCodes.Ldloc_S, 9), + + // PreAuthenticatingEventArgs ev = new (userid, ipaddress, expiration, flags, country, signature, request, position) + new (OpCodes.Newobj, GetDeclaredConstructors(typeof(PreAuthenticatingEventArgs))[0]), + new (OpCodes.Dup), + new (OpCodes.Stloc_S, ev.LocalIndex), + + // OnPreAuthenticating(ev) + new (OpCodes.Call, Method(typeof(Handlers.Player), nameof(Handlers.Player.OnPreAuthenticating))), + new (OpCodes.Ldloc_S, ev.LocalIndex), + + // ev.isallowed + new (OpCodes.Callvirt, PropertyGetter(typeof(PreAuthenticatingEventArgs), nameof(PreAuthenticatingEventArgs.IsAllowed))), + + // ret + new (OpCodes.Brfalse_S, ret), + }); + + foreach (CodeInstruction instruction in newInstructions) + yield return instruction; + + ListPool.Pool.Return(newInstructions); + } + } +} \ No newline at end of file From 94cf5195a0ad27b21674de3f922461de8dd837e0 Mon Sep 17 00:00:00 2001 From: xNexusACS <83370388+xNexusACS@users.noreply.github.com> Date: Mon, 28 Oct 2024 21:46:48 +0100 Subject: [PATCH 3/5] Version bump --- EXILED.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EXILED.props b/EXILED.props index 9d3044ecbc..8d8932a786 100644 --- a/EXILED.props +++ b/EXILED.props @@ -15,7 +15,7 @@ - 9.0.0-beta.6 + 9.0.0-beta.7 false From a94cdf75756dc3dc43395e448f9f6f15ef19c250 Mon Sep 17 00:00:00 2001 From: xNexusACS <83370388+xNexusACS@users.noreply.github.com> Date: Mon, 28 Oct 2024 21:56:30 +0100 Subject: [PATCH 4/5] Sending command port --- .../Player/SendingCommandEventArgs.cs | 59 +++++++++++++ Exiled.Events/Handlers/Player.cs | 11 +++ .../Patches/Events/Player/SendingCommand.cs | 85 +++++++++++++++++++ 3 files changed, 155 insertions(+) create mode 100644 Exiled.Events/EventArgs/Player/SendingCommandEventArgs.cs create mode 100644 Exiled.Events/Patches/Events/Player/SendingCommand.cs diff --git a/Exiled.Events/EventArgs/Player/SendingCommandEventArgs.cs b/Exiled.Events/EventArgs/Player/SendingCommandEventArgs.cs new file mode 100644 index 0000000000..cd9db5eb6c --- /dev/null +++ b/Exiled.Events/EventArgs/Player/SendingCommandEventArgs.cs @@ -0,0 +1,59 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Exiled Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.EventArgs.Player +{ + using CommandSystem; + + using Exiled.API.Features; + using Exiled.Events.EventArgs.Interfaces; + + /// + /// Contains all information before a player sends a proper RA command. + /// + public class SendingCommandEventArgs : IPlayerEvent, IDeniableEvent + { + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public SendingCommandEventArgs(Player player, ICommand command, string query) + { + Command = command; + Player = player; + Query = query; + } + + /// + /// Gets or sets a value indicating whether the command can be executed. + /// + public bool IsAllowed { get; set; } = true; + + /// + /// Gets the command that is being executed. + /// + public ICommand Command { get; } + + /// + /// Gets the query of the command. + /// + public string Query { get; } + + /// + /// Gets the player who's sending the command. + /// + public Player Player { get; } + } +} \ No newline at end of file diff --git a/Exiled.Events/Handlers/Player.cs b/Exiled.Events/Handlers/Player.cs index 4a9f686b43..352255fcb5 100644 --- a/Exiled.Events/Handlers/Player.cs +++ b/Exiled.Events/Handlers/Player.cs @@ -553,6 +553,11 @@ public class Player /// public static Event ChangingNickname { get; set; } = new(); + /// + /// Invoked before a 's sends proper RA command. + /// + public static Event SendingCommand { get; set; } = new(); + /// /// Invoked before displaying the hitmarker to the player. /// @@ -1198,6 +1203,12 @@ public static void OnItemRemoved(ReferenceHub referenceHub, InventorySystem.Item /// The instance. public static void OnChangingNickname(ChangingNicknameEventArgs ev) => ChangingNickname.InvokeSafely(ev); + /// + /// Called before a 's sends propper RA command. + /// + /// The instance. + public static void OnSendingCommand(SendingCommandEventArgs ev) => SendingCommand.InvokeSafely(ev); + /// /// Called before displaying the hitmarker to the player. /// diff --git a/Exiled.Events/Patches/Events/Player/SendingCommand.cs b/Exiled.Events/Patches/Events/Player/SendingCommand.cs new file mode 100644 index 0000000000..4ad5ebdf37 --- /dev/null +++ b/Exiled.Events/Patches/Events/Player/SendingCommand.cs @@ -0,0 +1,85 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Exiled Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.Patches.Events.Player +{ + using System; + using System.Collections.Generic; + using System.Reflection.Emit; + + using API.Features; + using API.Features.Core.Generic.Pools; + + using CommandSystem; + + using Exiled.Events.Attributes; + using Exiled.Events.EventArgs.Player; + + using HarmonyLib; + + using RemoteAdmin; + + using static HarmonyLib.AccessTools; + + /// + /// Patches . + /// Adds the event. + /// + [EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.SendingCommand))] + [HarmonyPatch(typeof(CommandProcessor), nameof(CommandProcessor.ProcessQuery))] + internal static class SendingCommand + { + private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) + { + List newInstructions = ListPool.Pool.Get(instructions); + + Label ret = generator.DefineLabel(); + + newInstructions[newInstructions.Count - 1].labels.Add(ret); + LocalBuilder ev = generator.DeclareLocal(typeof(SendingCommandEventArgs)); + const int offset = 2; + int index = newInstructions.FindIndex(instruction => instruction.Calls(Method(typeof(CommandHandler), nameof(CommandHandler.TryGetCommand)))) + offset; + + newInstructions.InsertRange( + index, + new[] + { + // Sender + new CodeInstruction(OpCodes.Ldarg_1), + + // Player.Get(CommandSender) + new CodeInstruction(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(CommandSender) })), + + // command + new CodeInstruction(OpCodes.Ldloc_1), + + // query + new CodeInstruction(OpCodes.Ldarg_0), + + // SendingCommandEventArgs ev = new SendingCommandEventArgs(Player, ICommand, Query) + new CodeInstruction(OpCodes.Newobj, GetDeclaredConstructors(typeof(SendingCommandEventArgs))[0]), + new CodeInstruction(OpCodes.Dup), + new CodeInstruction(OpCodes.Stloc_S, ev.LocalIndex), + + // Handlers.Player.OnSendingCommand(ev) + new CodeInstruction(OpCodes.Call, Method(typeof(Handlers.Player), nameof(Handlers.Player.OnSendingCommand))), + + // isallowed == false + new CodeInstruction(OpCodes.Ldloc_S, ev.LocalIndex), + new CodeInstruction(OpCodes.Callvirt, PropertyGetter(typeof(SendingCommandEventArgs), nameof(SendingCommandEventArgs.IsAllowed))), + + // ret + new CodeInstruction(OpCodes.Brfalse_S, ret), + }); + + foreach (CodeInstruction instruction in newInstructions) + yield return instruction; + + ListPool.Pool.Return(newInstructions); + } + } +} \ No newline at end of file From b1a8480f24ccd17094f04ec1b83a99e979cb3a14 Mon Sep 17 00:00:00 2001 From: xNexusACS <83370388+xNexusACS@users.noreply.github.com> Date: Mon, 28 Oct 2024 22:08:07 +0100 Subject: [PATCH 5/5] Fix Role Behavior Custom Spawnpoint --- .../API/Features/CustomRoles/RoleBehaviour.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Exiled.CustomModules/API/Features/CustomRoles/RoleBehaviour.cs b/Exiled.CustomModules/API/Features/CustomRoles/RoleBehaviour.cs index 60e1a90672..4a23ca940b 100644 --- a/Exiled.CustomModules/API/Features/CustomRoles/RoleBehaviour.cs +++ b/Exiled.CustomModules/API/Features/CustomRoles/RoleBehaviour.cs @@ -479,6 +479,9 @@ protected override void SubscribeEvents() Exiled.Events.Handlers.Player.Handcuffing += HandcuffingBehavior; Exiled.Events.Handlers.Map.PlacingBlood += PlacingBloodBehavior; Exiled.Events.Handlers.Player.ChangingNickname += OnInternalChangingNickname; + Exiled.Events.Handlers.Player.Spawning += OverrideSpawnPoint; + Exiled.Events.Handlers.Player.SpawningRagdoll += OnSpawningRagdoll; + EscapingEventDispatcher.Bind(this, OnEscaping); EscapedEventDispatcher.Bind(this, OnEscaped); } @@ -509,6 +512,11 @@ protected override void UnsubscribeEvents() Exiled.Events.Handlers.Player.Handcuffing -= HandcuffingBehavior; Exiled.Events.Handlers.Map.PlacingBlood -= PlacingBloodBehavior; Exiled.Events.Handlers.Player.ChangingNickname -= OnInternalChangingNickname; + Exiled.Events.Handlers.Player.Spawning -= OverrideSpawnPoint; + Exiled.Events.Handlers.Player.SpawningRagdoll -= OnSpawningRagdoll; + + EscapingEventDispatcher.Unbind(this, OnEscaping); + EscapedEventDispatcher.Unbind(this, OnEscaped); } /// @@ -661,8 +669,8 @@ protected virtual void PickingUpItemBehavior(SearchingPickupEventArgs ev) ev.IsAllowed = false; } - /// - protected virtual void PreventPlayerFromEscaping(Exiled.Events.EventArgs.Player.EscapingEventArgs ev) + /// + protected virtual void PreventPlayerFromEscaping(EscapingEventArgs ev) { if (!Check(ev.Player) || useCustomEscape || wasEscaped || (EscapeSettings is not null && !EscapeSettings.IsEmpty())) return;