forked from Exiled-Official/EXILED
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* π±βπ€π±βπ€π±βπ€ * some fixes * fix * β οΈπππβ οΈπ Co-authored-by: IRacle <79921583+IRacle1@users.noreply.github.com> --------- Co-authored-by: IRacle <79921583+IRacle1@users.noreply.github.com>
- Loading branch information
Showing
4 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
EXILED/Exiled.Events/EventArgs/Server/UnbannedEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
ο»Ώ// ----------------------------------------------------------------------- | ||
// <copyright file="UnbannedEventArgs.cs" company="Exiled Team"> | ||
// Copyright (c) Exiled Team. All rights reserved. | ||
// Licensed under the CC BY-SA 3.0 license. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
namespace Exiled.Events.EventArgs.Server | ||
{ | ||
/// <summary> | ||
/// Contains all information after a player gets unbanned. | ||
/// </summary> | ||
public class UnbannedEventArgs | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="UnbannedEventArgs"/> class. | ||
/// </summary> | ||
/// <param name="details"><inheritdoc cref="BanDetails"/></param> | ||
/// <param name="banType"><inheritdoc cref="BanType"/></param> | ||
public UnbannedEventArgs(string details, BanHandler.BanType banType) | ||
{ | ||
BanDetails = BanHandler.ProcessBanItem(details, banType); | ||
BanType = banType; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the ban details. | ||
/// </summary> | ||
public BanDetails BanDetails { get; } | ||
|
||
/// <summary> | ||
/// Gets the ban type. | ||
/// </summary> | ||
public BanHandler.BanType BanType { get; } | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
EXILED/Exiled.Events/EventArgs/Server/UnbanningEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
ο»Ώ// ----------------------------------------------------------------------- | ||
// <copyright file="UnbanningEventArgs.cs" company="Exiled Team"> | ||
// Copyright (c) Exiled Team. All rights reserved. | ||
// Licensed under the CC BY-SA 3.0 license. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
namespace Exiled.Events.EventArgs.Server | ||
{ | ||
using Exiled.Events.EventArgs.Interfaces; | ||
|
||
/// <summary> | ||
/// Contains all information before player is unbanned. | ||
/// </summary> | ||
public class UnbanningEventArgs : IDeniableEvent | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="UnbanningEventArgs"/> class. | ||
/// </summary> | ||
/// <param name="banDetails"><inheritdoc cref="BanDetails"/></param> | ||
/// <param name="banType"><inheritdoc cref="BanType"/></param> | ||
/// <param name="isAllowed"><inheritdoc cref="IsAllowed"/></param> | ||
public UnbanningEventArgs(string banDetails, BanHandler.BanType banType, bool isAllowed = true) | ||
{ | ||
BanDetails = BanHandler.ProcessBanItem(banDetails, banType); | ||
BanType = banType; | ||
IsAllowed = isAllowed; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the ban details. | ||
/// </summary> | ||
public BanDetails BanDetails { get; set; } | ||
|
||
/// <summary> | ||
/// Gets the ban type. | ||
/// </summary> | ||
public BanHandler.BanType BanType { get; } | ||
|
||
/// <inheritdoc/> | ||
public bool IsAllowed { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
ο»Ώ// ----------------------------------------------------------------------- | ||
// <copyright file="Unban.cs" company="Exiled Team"> | ||
// Copyright (c) Exiled Team. All rights reserved. | ||
// Licensed under the CC BY-SA 3.0 license. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
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; | ||
|
||
/// <summary> | ||
/// Patches <see cref="BanHandler.RemoveBan"/> | ||
/// to add <see cref="Handlers.Server.Unbanning"/> and <see cref="Handlers.Server.Unbanned"/> events. | ||
/// </summary> | ||
[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<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) | ||
{ | ||
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.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.OnUnbanning))), | ||
|
||
// 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 CodeInstruction(OpCodes.Ldloc_S, ev.LocalIndex).WithLabels(continueLabel), | ||
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.OnUnbanned))), | ||
}); | ||
|
||
for (int z = 0; z < newInstructions.Count; z++) | ||
yield return newInstructions[z]; | ||
|
||
ListPool<CodeInstruction>.Pool.Return(newInstructions); | ||
} | ||
} | ||
} |