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 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; 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/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/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 30526c8f22..352255fcb5 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. /// @@ -558,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. /// @@ -1203,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. /// @@ -1218,30 +1224,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/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/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 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 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