From 1edf414530eeae1d1d3684a0d7151232bddc3985 Mon Sep 17 00:00:00 2001 From: VALERA771 Date: Fri, 16 Aug 2024 16:42:19 +0300 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=90=B1=E2=80=8D=F0=9F=91=A4?= =?UTF-8?q?=F0=9F=90=B1=E2=80=8D=F0=9F=91=A4=F0=9F=90=B1=E2=80=8D?= =?UTF-8?q?=F0=9F=91=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EventArgs/Server/UnbannedEventArgs.cs | 36 ++++++++ .../EventArgs/Server/UnbanningEventArgs.cs | 43 +++++++++ EXILED/Exiled.Events/Handlers/Server.cs | 22 +++++ .../Patches/Events/Server/Unban.cs | 92 +++++++++++++++++++ 4 files changed, 193 insertions(+) create mode 100644 EXILED/Exiled.Events/EventArgs/Server/UnbannedEventArgs.cs create mode 100644 EXILED/Exiled.Events/EventArgs/Server/UnbanningEventArgs.cs create mode 100644 EXILED/Exiled.Events/Patches/Events/Server/Unban.cs diff --git a/EXILED/Exiled.Events/EventArgs/Server/UnbannedEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Server/UnbannedEventArgs.cs new file mode 100644 index 000000000..f1181a3b9 --- /dev/null +++ b/EXILED/Exiled.Events/EventArgs/Server/UnbannedEventArgs.cs @@ -0,0 +1,36 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Exiled Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.EventArgs.Server +{ + /// + /// Contains all information after a player gets unbanned. + /// + public class UnbannedEventArgs + { + /// + /// Initializes a new instance of the class. + /// + /// + /// + public UnbannedEventArgs(string details, BanHandler.BanType banType) + { + BanDetails = BanHandler.ProcessBanItem(details, banType); + BanType = banType; + } + + /// + /// Gets the ban details. + /// + public BanDetails BanDetails { get; } + + /// + /// Gets the ban type. + /// + public BanHandler.BanType BanType { get; } + } +} \ No newline at end of file diff --git a/EXILED/Exiled.Events/EventArgs/Server/UnbanningEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Server/UnbanningEventArgs.cs new file mode 100644 index 000000000..fc8f2638a --- /dev/null +++ b/EXILED/Exiled.Events/EventArgs/Server/UnbanningEventArgs.cs @@ -0,0 +1,43 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Exiled Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.EventArgs.Server +{ + using Exiled.Events.EventArgs.Interfaces; + + /// + /// Contains all information + /// + public class UnbanningEventArgs : IDeniableEvent + { + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// + public UnbanningEventArgs(string banDetails, BanHandler.BanType banType, bool isAllowed = true) + { + BanDetails = BanHandler.ProcessBanItem(banDetails, banType); + BanType = banType; + IsAllowed = isAllowed; + } + + /// + /// Gets or sets the ban details. + /// + public BanDetails BanDetails { get; set; } + + /// + /// Gets the ban type. + /// + public BanHandler.BanType BanType { get; } + + /// + public bool IsAllowed { get; set; } + } +} \ No newline at end of file diff --git a/EXILED/Exiled.Events/Handlers/Server.cs b/EXILED/Exiled.Events/Handlers/Server.cs index 75be4d81c..3f5b71e63 100644 --- a/EXILED/Exiled.Events/Handlers/Server.cs +++ b/EXILED/Exiled.Events/Handlers/Server.cs @@ -111,6 +111,16 @@ public static class Server /// public static Event ReloadedPermissions { get; set; } = new(); + /// + /// Invoked before player is being unbanned. + /// + public static Event Unbanning { get; set; } = new(); + + /// + /// Invoked after player is being unbanned. + /// + public static Event Unbanned { get; set; } = new(); + /// /// Called before waiting for players. /// @@ -210,5 +220,17 @@ public static class Server /// /// The instance. public static void OnSelectingRespawnTeam(SelectingRespawnTeamEventArgs ev) => SelectingRespawnTeam.InvokeSafely(ev); + + /// + /// Called before player is being unbanned. + /// + /// The instance. + public static void OnUnbanning(UnbanningEventArgs ev) => Unbanning.InvokeSafely(ev); + + /// + /// Called after player is being unbanned. + /// + /// The instance. + public static void OnUnbanned(UnbannedEventArgs ev) => Unbanned.InvokeSafely(ev); } } \ No newline at end of file diff --git a/EXILED/Exiled.Events/Patches/Events/Server/Unban.cs b/EXILED/Exiled.Events/Patches/Events/Server/Unban.cs new file mode 100644 index 000000000..d7cb06e23 --- /dev/null +++ b/EXILED/Exiled.Events/Patches/Events/Server/Unban.cs @@ -0,0 +1,92 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Exiled Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.Patches.Events.Server +{ + using System.Collections.Generic; + using System.Reflection.Emit; + + using Exiled.API.Features.Pools; + using Exiled.Events.Attributes; + using Exiled.Events.EventArgs.Server; + using HarmonyLib; + + using static HarmonyLib.AccessTools; + + /// + /// Patches + /// to add and events. + /// + [HarmonyPatch(typeof(BanHandler), nameof(BanHandler.RemoveBan))] + [EventPatch(typeof(Handlers.Server), nameof(Handlers.Server.Unbanning))] + [EventPatch(typeof(Handlers.Server), nameof(Handlers.Server.Unbanned))] + internal class Unban + { + private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) + { + List newInstructions = ListPool.Pool.Get(instructions); + + LocalBuilder ev = generator.DeclareLocal(typeof(UnbanningEventArgs)); + + Label continueLabel = generator.DefineLabel(); + + newInstructions.InsertRange(0, new CodeInstruction[] + { + // id + new(OpCodes.Ldarg_0), + + // type + new(OpCodes.Ldarg_1), + + // true + new(OpCodes.Ldc_I4_1), + + // UnbanningEventArgs ev = new(string, BanHandler.BanType, true); + new(OpCodes.Newobj, GetDeclaredConstructors(typeof(UnbanningEventArgs))[0]), + new(OpCodes.Dup), + new(OpCodes.Dup), + new(OpCodes.Stloc_S, ev.LocalIndex), + + // Handlers.Server.OnUnbanning(ev); + new(OpCodes.Call, Method(typeof(Handlers.Server), nameof(Handlers.Server))), + + // if (!ev.IsAllowed) + // return; + new(OpCodes.Callvirt, PropertyGetter(typeof(UnbanningEventArgs), nameof(UnbanningEventArgs.IsAllowed))), + new(OpCodes.Brtrue_S, continueLabel), + + new(OpCodes.Ret), + + // id = ev.BanDetails.ToString(); + new(OpCodes.Ldloc_S, ev.LocalIndex), + new(OpCodes.Callvirt, PropertyGetter(typeof(UnbanningEventArgs), nameof(UnbanningEventArgs.BanDetails))), + new(OpCodes.Call, Method(typeof(BanDetails), nameof(BanDetails.ToString))), + new(OpCodes.Starg_S, 1), + }); + + newInstructions.InsertRange(newInstructions.Count - 1, new CodeInstruction[] + { + // id + new(OpCodes.Ldarg_0), + + // type + new(OpCodes.Ldarg_1), + + // UnbannedEventArgs ev2 = new(string, BanHandler.BanType); + new(OpCodes.Newobj, GetDeclaredConstructors(typeof(UnbannedEventArgs))[0]), + + // Handlers.Server.OnUnbanned(ev2); + new(OpCodes.Call, Method(typeof(Handlers.Server), nameof(Handlers.Server))) + }); + + for (int z = 0; z < newInstructions.Count; z++) + yield return newInstructions[z]; + + ListPool.Pool.Return(newInstructions); + } + } +} \ No newline at end of file From 1c2eaef9175eee8e79bc82bb1bfdae2e281299df Mon Sep 17 00:00:00 2001 From: VALERA771 Date: Fri, 16 Aug 2024 16:48:34 +0300 Subject: [PATCH 2/4] some fixes --- EXILED/Exiled.Events/EventArgs/Server/UnbanningEventArgs.cs | 2 +- EXILED/Exiled.Events/Patches/Events/Server/Unban.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/EXILED/Exiled.Events/EventArgs/Server/UnbanningEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Server/UnbanningEventArgs.cs index fc8f2638a..aa23690e6 100644 --- a/EXILED/Exiled.Events/EventArgs/Server/UnbanningEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Server/UnbanningEventArgs.cs @@ -10,7 +10,7 @@ namespace Exiled.Events.EventArgs.Server using Exiled.Events.EventArgs.Interfaces; /// - /// Contains all information + /// Contains all information before player is unbanned. /// public class UnbanningEventArgs : IDeniableEvent { diff --git a/EXILED/Exiled.Events/Patches/Events/Server/Unban.cs b/EXILED/Exiled.Events/Patches/Events/Server/Unban.cs index d7cb06e23..3e32f2dfc 100644 --- a/EXILED/Exiled.Events/Patches/Events/Server/Unban.cs +++ b/EXILED/Exiled.Events/Patches/Events/Server/Unban.cs @@ -52,7 +52,7 @@ private static IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable Date: Fri, 16 Aug 2024 17:16:05 +0300 Subject: [PATCH 3/4] fix --- EXILED/Exiled.Events/Patches/Events/Server/Unban.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EXILED/Exiled.Events/Patches/Events/Server/Unban.cs b/EXILED/Exiled.Events/Patches/Events/Server/Unban.cs index 3e32f2dfc..ae3361220 100644 --- a/EXILED/Exiled.Events/Patches/Events/Server/Unban.cs +++ b/EXILED/Exiled.Events/Patches/Events/Server/Unban.cs @@ -80,7 +80,7 @@ private static IEnumerable Transpiler(IEnumerable Date: Sun, 18 Aug 2024 21:29:40 +0300 Subject: [PATCH 4/4] =?UTF-8?q?=E2=98=A0=EF=B8=8F=F0=9F=92=80=F0=9F=92=80?= =?UTF-8?q?=F0=9F=92=80=E2=98=A0=EF=B8=8F=F0=9F=92=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: IRacle <79921583+IRacle1@users.noreply.github.com> --- EXILED/Exiled.Events/Patches/Events/Server/Unban.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EXILED/Exiled.Events/Patches/Events/Server/Unban.cs b/EXILED/Exiled.Events/Patches/Events/Server/Unban.cs index ae3361220..5eb89d224 100644 --- a/EXILED/Exiled.Events/Patches/Events/Server/Unban.cs +++ b/EXILED/Exiled.Events/Patches/Events/Server/Unban.cs @@ -62,7 +62,7 @@ private static IEnumerable Transpiler(IEnumerable