From d03181fc4d4b32b200b9ef92135e10ff32759554 Mon Sep 17 00:00:00 2001
From: Misaka-ZeroTwo <45165615+Misaka-ZeroTwo@users.noreply.github.com>
Date: Fri, 26 Jul 2024 17:36:42 +0800
Subject: [PATCH 1/5] Update labeler.yml
---
.github/labeler.yml | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/.github/labeler.yml b/.github/labeler.yml
index 34ff31f3fa..6e4b185880 100644
--- a/.github/labeler.yml
+++ b/.github/labeler.yml
@@ -13,27 +13,27 @@ Scripts: # Add the 'Scripts' label
regarding-events: # Add the 'Events' label
- changed-files:
- - any-glob-to-any-file: Exiled.Events/** # Any Modifications to events
+ - any-glob-to-any-file: EXILED/Exiled.Events/** # Any Modifications to events
regarding-api: # Add the 'API' label
- changed-files:
- - any-glob-to-any-file: Exiled.API/** # Any modifications to the API
+ - any-glob-to-any-file: EXILED/Exiled.API/** # Any modifications to the API
regarding-transpiler: # Add the 'transpiler' label
- changed-files:
- - any-glob-to-any-file: Exiled.Events/Patches/**/* # Any modifications to transpiler files
+ - any-glob-to-any-file: EXILED/Exiled.Events/Patches/**/* # Any modifications to transpiler files
CustomModules: # Add the 'CustomModules' label
- changed-files:
- - any-glob-to-any-file: Exiled.CustomModules/** # Any modifications to CustomModules
+ - any-glob-to-any-file: EXILED/Exiled.CustomModules/** # Any modifications to CustomModules
Installer: # Add the 'Installer' label
- changed-files:
- - any-glob-to-any-file: Exiled.Installer/** # Any modifications to the Installer
+ - any-glob-to-any-file: EXILED/Exiled.Installer/** # Any modifications to the Installer
Localization: # Add the 'Localization' label
- changed-files:
- - any-glob-to-any-file: Localization/** # Any modifications to Localization
+ - any-glob-to-any-file: EXILED/Localization/** # Any modifications to Localization
GitHub_Actions: # Add the 'GitHub' label
- changed-files:
From 5b21478494fe37ba567138fc271ad4de88a33bbe Mon Sep 17 00:00:00 2001
From: Misaka_ZeroTwo <45165615+Misaka-ZeroTwo@users.noreply.github.com>
Date: Sun, 28 Jul 2024 02:00:49 +0800
Subject: [PATCH 2/5] RemovingHandcuffs event
---
EXILED/Exiled.API/Enums/UncuffReason.cs | 35 +++++
.../Player/RemovingHandcuffsEventArgs.cs | 10 +-
.../Events/Player/ProcessDisarmMessage.cs | 133 +++++++++++++++++-
3 files changed, 176 insertions(+), 2 deletions(-)
create mode 100644 EXILED/Exiled.API/Enums/UncuffReason.cs
diff --git a/EXILED/Exiled.API/Enums/UncuffReason.cs b/EXILED/Exiled.API/Enums/UncuffReason.cs
new file mode 100644
index 0000000000..2e62067f56
--- /dev/null
+++ b/EXILED/Exiled.API/Enums/UncuffReason.cs
@@ -0,0 +1,35 @@
+// -----------------------------------------------------------------------
+//
+// Copyright (c) Exiled Team. All rights reserved.
+// Licensed under the CC BY-SA 3.0 license.
+//
+// -----------------------------------------------------------------------
+
+namespace Exiled.API.Enums
+{
+ ///
+ /// Reasons that player gets uncuffed.
+ ///
+ public enum UncuffReason
+ {
+ ///
+ /// Uncuffed by a player.
+ ///
+ Player,
+
+ ///
+ /// Uncuffed due to the distance between cuffer and target.
+ ///
+ OutOfRange,
+
+ ///
+ /// Uncuffed due to the cuffer no longer alive.
+ ///
+ CufferDied,
+
+ ///
+ /// Uncuffed by admin or plugin.
+ ///
+ CustomUncuff,
+ }
+}
diff --git a/EXILED/Exiled.Events/EventArgs/Player/RemovingHandcuffsEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/RemovingHandcuffsEventArgs.cs
index c6a90a8355..1d3a663e1e 100644
--- a/EXILED/Exiled.Events/EventArgs/Player/RemovingHandcuffsEventArgs.cs
+++ b/EXILED/Exiled.Events/EventArgs/Player/RemovingHandcuffsEventArgs.cs
@@ -7,6 +7,7 @@
namespace Exiled.Events.EventArgs.Player
{
+ using API.Enums;
using API.Features;
using Exiled.Events.EventArgs.Interfaces;
@@ -20,11 +21,13 @@ public class RemovingHandcuffsEventArgs : IPlayerEvent, IDeniableEvent
///
/// The cuffer player.
/// The target player to be uncuffed.
+ /// The reason of removing handcuffs.
/// Indicates whether the event can be executed or not.
- public RemovingHandcuffsEventArgs(Player cuffer, Player target, bool isAllowed = true)
+ public RemovingHandcuffsEventArgs(Player cuffer, Player target, UncuffReason uncuffReason, bool isAllowed = true)
{
Player = cuffer;
Target = target;
+ UncuffReason = uncuffReason;
IsAllowed = isAllowed;
}
@@ -42,5 +45,10 @@ public RemovingHandcuffsEventArgs(Player cuffer, Player target, bool isAllowed =
/// Gets the cuffer player.
///
public Player Player { get; }
+
+ ///
+ /// Gets the reason of removing handcuffs.
+ ///
+ public UncuffReason UncuffReason { get; }
}
}
\ No newline at end of file
diff --git a/EXILED/Exiled.Events/Patches/Events/Player/ProcessDisarmMessage.cs b/EXILED/Exiled.Events/Patches/Events/Player/ProcessDisarmMessage.cs
index bd83c19e9e..0ce5d9e284 100644
--- a/EXILED/Exiled.Events/Patches/Events/Player/ProcessDisarmMessage.cs
+++ b/EXILED/Exiled.Events/Patches/Events/Player/ProcessDisarmMessage.cs
@@ -7,6 +7,7 @@
namespace Exiled.Events.Patches.Events.Player
{
+ #pragma warning disable SA1402 // File may only contain a single type
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
@@ -55,10 +56,13 @@ private static IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable.Pool.Return(newInstructions);
}
}
+
+ ///
+ /// Patches .
+ /// Invokes event.
+ ///
+ [EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.RemovingHandcuffs))]
+ [HarmonyPatch(typeof(DisarmedPlayers), nameof(DisarmedPlayers.ValidateEntry))]
+ internal static class Uncuff
+ {
+ private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator)
+ {
+ List newInstructions = ListPool.Pool.Get(instructions);
+ Label returnLabel = generator.DefineLabel();
+
+ int offset = 2;
+ int index = newInstructions.FindLastIndex(
+ instruction => instruction.Calls(Method(typeof(ReferenceHub), nameof(ReferenceHub.TryGetHubNetID)))) + offset;
+
+ newInstructions.InsertRange(
+ index,
+ new[]
+ {
+ // Player.Get(Cuffer)
+ new CodeInstruction(OpCodes.Ldloc_1),
+ new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),
+
+ // Player.Get(Target)
+ new(OpCodes.Ldloc_0),
+ new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),
+
+ // UncuffReason.CufferDied
+ new(OpCodes.Ldc_I4_2),
+
+ // true
+ new(OpCodes.Ldc_I4_1),
+
+ // RemovingHandcuffsEventArgs ev = new(Cuffer, Target, UncuffReason.CufferDied, true)
+ new(OpCodes.Newobj, GetDeclaredConstructors(typeof(RemovingHandcuffsEventArgs))[0]),
+ new(OpCodes.Dup),
+
+ // Handlers.Player.OnRemovingHandcuffs(ev)
+ new(OpCodes.Call, Method(typeof(Handlers.Player), nameof(Handlers.Player.OnRemovingHandcuffs))),
+
+ // if (!ev.IsAllowed)
+ // return true;
+ new(OpCodes.Callvirt, PropertyGetter(typeof(RemovingHandcuffsEventArgs), nameof(RemovingHandcuffsEventArgs.IsAllowed))),
+ new(OpCodes.Brfalse_S, returnLabel),
+ });
+
+ offset = 5;
+ index = newInstructions.FindLastIndex(
+ instruction => instruction.Calls(PropertyGetter(typeof(PlayerRoles.PlayerRoleManager), nameof(PlayerRoles.PlayerRoleManager.CurrentRole)))) + offset;
+
+ newInstructions.InsertRange(
+ index,
+ new[]
+ {
+ // Player.Get(Cuffer)
+ new CodeInstruction(OpCodes.Ldloc_1),
+ new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),
+
+ // Player.Get(Target)
+ new(OpCodes.Ldloc_0),
+ new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),
+
+ // UncuffReason.CufferDied
+ new(OpCodes.Ldc_I4_2),
+
+ // true
+ new(OpCodes.Ldc_I4_1),
+
+ // RemovingHandcuffsEventArgs ev = new(Cuffer, Target, UncuffReason.CufferDied, true)
+ new(OpCodes.Newobj, GetDeclaredConstructors(typeof(RemovingHandcuffsEventArgs))[0]),
+ new(OpCodes.Dup),
+
+ // Handlers.Player.OnRemovingHandcuffs(ev)
+ new(OpCodes.Call, Method(typeof(Handlers.Player), nameof(Handlers.Player.OnRemovingHandcuffs))),
+
+ // if (!ev.IsAllowed)
+ // return true;
+ new(OpCodes.Callvirt, PropertyGetter(typeof(RemovingHandcuffsEventArgs), nameof(RemovingHandcuffsEventArgs.IsAllowed))),
+ new(OpCodes.Brfalse_S, returnLabel),
+ });
+
+ offset = 3;
+ index = newInstructions.FindLastIndex(
+ instruction => instruction.Calls(PropertyGetter(typeof(UnityEngine.Vector3), nameof(UnityEngine.Vector3.sqrMagnitude)))) + offset;
+
+ newInstructions.InsertRange(
+ index,
+ new[]
+ {
+ // Player.Get(Cuffer)
+ new CodeInstruction(OpCodes.Ldloc_1),
+ new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),
+
+ // Player.Get(Target)
+ new(OpCodes.Ldloc_0),
+ new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),
+
+ // UncuffReason.OutOfRange
+ new(OpCodes.Ldc_I4_1),
+
+ // true
+ new(OpCodes.Ldc_I4_1),
+
+ // RemovingHandcuffsEventArgs ev = new(Cuffer, Target, UncuffReason.OutOfRange, true)
+ new(OpCodes.Newobj, GetDeclaredConstructors(typeof(RemovingHandcuffsEventArgs))[0]),
+ new(OpCodes.Dup),
+
+ // Handlers.Player.OnRemovingHandcuffs(ev)
+ new(OpCodes.Call, Method(typeof(Handlers.Player), nameof(Handlers.Player.OnRemovingHandcuffs))),
+
+ // if (!ev.IsAllowed)
+ // return true;
+ new(OpCodes.Callvirt, PropertyGetter(typeof(RemovingHandcuffsEventArgs), nameof(RemovingHandcuffsEventArgs.IsAllowed))),
+ new(OpCodes.Brfalse_S, returnLabel),
+ });
+
+ newInstructions[newInstructions.Count - 2].labels.Add(returnLabel);
+
+ for (int z = 0; z < newInstructions.Count; z++)
+ yield return newInstructions[z];
+
+ ListPool.Pool.Return(newInstructions);
+ }
+ }
}
\ No newline at end of file
From 967d20a5364192b33a47c042d5f29d8fc2285ae3 Mon Sep 17 00:00:00 2001
From: Misaka_ZeroTwo <45165615+Misaka-ZeroTwo@users.noreply.github.com>
Date: Sun, 28 Jul 2024 02:06:13 +0800
Subject: [PATCH 3/5] Update UncuffReason.cs
---
EXILED/Exiled.API/Enums/UncuffReason.cs | 5 -----
1 file changed, 5 deletions(-)
diff --git a/EXILED/Exiled.API/Enums/UncuffReason.cs b/EXILED/Exiled.API/Enums/UncuffReason.cs
index 2e62067f56..6b3018fdac 100644
--- a/EXILED/Exiled.API/Enums/UncuffReason.cs
+++ b/EXILED/Exiled.API/Enums/UncuffReason.cs
@@ -26,10 +26,5 @@ public enum UncuffReason
/// Uncuffed due to the cuffer no longer alive.
///
CufferDied,
-
- ///
- /// Uncuffed by admin or plugin.
- ///
- CustomUncuff,
}
}
From ea9930978a3f2d0565f132abffa096d8e627f10d Mon Sep 17 00:00:00 2001
From: Misaka_ZeroTwo <45165615+Misaka-ZeroTwo@users.noreply.github.com>
Date: Tue, 6 Aug 2024 19:03:41 +0800
Subject: [PATCH 4/5] New event
---
.../Player/RemovedHandcuffsEventArgs.cs | 47 ++++++++
.../Player/RemovingHandcuffsEventArgs.cs | 3 +-
EXILED/Exiled.Events/Handlers/Player.cs | 11 ++
.../Events/Player/ProcessDisarmMessage.cs | 111 ++++++++++++++++--
4 files changed, 160 insertions(+), 12 deletions(-)
create mode 100644 EXILED/Exiled.Events/EventArgs/Player/RemovedHandcuffsEventArgs.cs
diff --git a/EXILED/Exiled.Events/EventArgs/Player/RemovedHandcuffsEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/RemovedHandcuffsEventArgs.cs
new file mode 100644
index 0000000000..06468b5d1c
--- /dev/null
+++ b/EXILED/Exiled.Events/EventArgs/Player/RemovedHandcuffsEventArgs.cs
@@ -0,0 +1,47 @@
+// -----------------------------------------------------------------------
+//
+// Copyright (c) Exiled Team. All rights reserved.
+// Licensed under the CC BY-SA 3.0 license.
+//
+// -----------------------------------------------------------------------
+
+namespace Exiled.Events.EventArgs.Player
+{
+ using API.Enums;
+ using API.Features;
+ using Exiled.Events.EventArgs.Interfaces;
+
+ ///
+ /// Contains all information after freeing a handcuffed player.
+ ///
+ public class RemovedHandcuffsEventArgs : IPlayerEvent
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The cuffer player.
+ /// The target player to be uncuffed.
+ /// The reason of removing handcuffs.
+ public RemovedHandcuffsEventArgs(Player cuffer, Player target, UncuffReason uncuffReason)
+ {
+ Player = cuffer;
+ Target = target;
+ UncuffReason = uncuffReason;
+ }
+
+ ///
+ /// Gets the target player to be cuffed.
+ ///
+ public Player Target { get; }
+
+ ///
+ /// Gets the cuffer player.
+ ///
+ public Player Player { get; }
+
+ ///
+ /// Gets the reason of removing handcuffs.
+ ///
+ public UncuffReason UncuffReason { get; }
+ }
+}
\ No newline at end of file
diff --git a/EXILED/Exiled.Events/EventArgs/Player/RemovingHandcuffsEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/RemovingHandcuffsEventArgs.cs
index 1d3a663e1e..c375bb4b7f 100644
--- a/EXILED/Exiled.Events/EventArgs/Player/RemovingHandcuffsEventArgs.cs
+++ b/EXILED/Exiled.Events/EventArgs/Player/RemovingHandcuffsEventArgs.cs
@@ -37,8 +37,9 @@ public RemovingHandcuffsEventArgs(Player cuffer, Player target, UncuffReason unc
public Player Target { get; }
///
- /// Gets or sets a value indicating whether or not the player can be handcuffed.
+ /// Gets or sets a value indicating whether or not the player can be handcuffed. Denying the event will only have an effect when is until next major update.
///
+ /// TODO: Update docs and patches
public bool IsAllowed { get; set; }
///
diff --git a/EXILED/Exiled.Events/Handlers/Player.cs b/EXILED/Exiled.Events/Handlers/Player.cs
index aca07ce6e1..016bdf644c 100644
--- a/EXILED/Exiled.Events/Handlers/Player.cs
+++ b/EXILED/Exiled.Events/Handlers/Player.cs
@@ -223,6 +223,11 @@ public class Player
///
public static Event RemovingHandcuffs { get; set; } = new();
+ ///
+ /// Invoked after freeing a handcuffed .
+ ///
+ public static Event RemovedHandcuffs { get; set; } = new();
+
///
/// Invoked before a escapes.
///
@@ -704,6 +709,12 @@ public class Player
/// The instance.
public static void OnRemovingHandcuffs(RemovingHandcuffsEventArgs ev) => RemovingHandcuffs.InvokeSafely(ev);
+ ///
+ /// Called after freeing a handcuffed .
+ ///
+ /// The instance.
+ public static void OnRemovedHandcuffs(RemovedHandcuffsEventArgs ev) => RemovedHandcuffs.InvokeSafely(ev);
+
///
/// Called before a escapes.
///
diff --git a/EXILED/Exiled.Events/Patches/Events/Player/ProcessDisarmMessage.cs b/EXILED/Exiled.Events/Patches/Events/Player/ProcessDisarmMessage.cs
index 0ce5d9e284..a3805d33db 100644
--- a/EXILED/Exiled.Events/Patches/Events/Player/ProcessDisarmMessage.cs
+++ b/EXILED/Exiled.Events/Patches/Events/Player/ProcessDisarmMessage.cs
@@ -27,10 +27,11 @@ namespace Exiled.Events.Patches.Events.Player
///
/// Patches .
- /// Adds the and events.
+ /// Adds the , , and events.
///
[EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.Handcuffing))]
[EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.RemovingHandcuffs))]
+ [EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.RemovedHandcuffs))]
[HarmonyPatch(typeof(DisarmingHandlers), nameof(DisarmingHandlers.ServerProcessDisarmMessage))]
internal static class ProcessDisarmMessage
{
@@ -47,6 +48,7 @@ private static IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable
/// Patches .
- /// Invokes event.
+ /// Invokes and event.
///
[EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.RemovingHandcuffs))]
+ [EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.RemovedHandcuffs))]
[HarmonyPatch(typeof(DisarmedPlayers), nameof(DisarmedPlayers.ValidateEntry))]
internal static class Uncuff
{
@@ -138,6 +161,7 @@ private static IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable
Date: Tue, 6 Aug 2024 19:10:43 +0800
Subject: [PATCH 5/5] docs
---
.../EventArgs/Player/RemovedHandcuffsEventArgs.cs | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/EXILED/Exiled.Events/EventArgs/Player/RemovedHandcuffsEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/RemovedHandcuffsEventArgs.cs
index 06468b5d1c..ee152fb347 100644
--- a/EXILED/Exiled.Events/EventArgs/Player/RemovedHandcuffsEventArgs.cs
+++ b/EXILED/Exiled.Events/EventArgs/Player/RemovedHandcuffsEventArgs.cs
@@ -20,8 +20,8 @@ public class RemovedHandcuffsEventArgs : IPlayerEvent
/// Initializes a new instance of the class.
///
/// The cuffer player.
- /// The target player to be uncuffed.
- /// The reason of removing handcuffs.
+ /// The target player was uncuffed.
+ /// The reason for removing the handcuffs.
public RemovedHandcuffsEventArgs(Player cuffer, Player target, UncuffReason uncuffReason)
{
Player = cuffer;
@@ -30,7 +30,7 @@ public RemovedHandcuffsEventArgs(Player cuffer, Player target, UncuffReason uncu
}
///
- /// Gets the target player to be cuffed.
+ /// Gets the target player to be cuffed.
///
public Player Target { get; }
@@ -40,8 +40,8 @@ public RemovedHandcuffsEventArgs(Player cuffer, Player target, UncuffReason uncu
public Player Player { get; }
///
- /// Gets the reason of removing handcuffs.
+ /// Gets the reason for removing handcuffs.
///
public UncuffReason UncuffReason { get; }
}
-}
\ No newline at end of file
+}