From 2e9f87fd99bdc8ae888d749fbd3c9449f5cb5e65 Mon Sep 17 00:00:00 2001 From: FoxWorn3365 Date: Thu, 1 Aug 2024 15:51:16 +0200 Subject: [PATCH 01/10] added the RecontainingEvent with the patch --- .../EventArgs/Scp079/RecontainingEventArgs.cs | 50 ++++++++++++++ EXILED/Exiled.Events/Handlers/Scp079.cs | 11 ++++ .../Patches/Events/Scp079/Recontaining.cs | 65 +++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs create mode 100644 EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs diff --git a/EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs new file mode 100644 index 000000000..f15352343 --- /dev/null +++ b/EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs @@ -0,0 +1,50 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Exiled Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.EventArgs.Scp079 +{ + using Exiled.API.Features; + using Exiled.Events.EventArgs.Interfaces; + + /// + /// Contains information before SCP-079 gets recontained. + /// + public class RecontainingEventArgs : IDeniableEvent + { + /// + /// Initializes a new instance of the class. + /// + /// The istance. + public RecontainingEventArgs(BreakableWindow recontainer) + { + Recontainer = Player.Get(recontainer.LastAttacker); + } + + /// + /// Initializes a new instance of the class. + /// + /// The player that triggered the SCP-079 recontaining event. + public RecontainingEventArgs(ReferenceHub recontainer) + { + Recontainer = Player.Get(recontainer); + } + + /// + /// Gets the Player that started the recontainment process.

+ /// Can be null if is true. + ///
+ public Player Recontainer { get; } + + /// + public bool IsAllowed { get; set; } = true; + + /// + /// Gets a value indicating whether or not the recontained has been made automatically or by triggering the proccess. + /// + public bool IsAutomatic => Recontainer is null; + } +} diff --git a/EXILED/Exiled.Events/Handlers/Scp079.cs b/EXILED/Exiled.Events/Handlers/Scp079.cs index 85da2da7e..b272defea 100644 --- a/EXILED/Exiled.Events/Handlers/Scp079.cs +++ b/EXILED/Exiled.Events/Handlers/Scp079.cs @@ -57,6 +57,11 @@ public static class Scp079 /// public static Event ChangingSpeakerStatus { get; set; } = new(); + /// + /// Invoked before SCP-079 recontainment. + /// + public static Event Recontaining { get; set; } = new(); + /// /// Invoked after SCP-079 recontainment. /// @@ -125,6 +130,12 @@ public static class Scp079 /// The instance. public static void OnChangingSpeakerStatus(ChangingSpeakerStatusEventArgs ev) => ChangingSpeakerStatus.InvokeSafely(ev); + /// + /// Called before SCP-079 is recontained. + /// + /// The instance. + public static void OnRecontaining(RecontainingEventArgs ev) => Recontaining.InvokeSafely(ev); + /// /// Called after SCP-079 is recontained. /// diff --git a/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs b/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs new file mode 100644 index 000000000..80ebfb6fc --- /dev/null +++ b/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs @@ -0,0 +1,65 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Exiled Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.Patches.Events.Scp079 +{ + using System.Collections.Generic; + using System.Reflection.Emit; + + using Exiled.Events.Attributes; + using Exiled.Events.EventArgs.Scp079; + using Exiled.Events.Handlers; + + using HarmonyLib; + + using PlayerRoles.PlayableScps.Scp079; + + using static HarmonyLib.AccessTools; + + /// + /// Patches . + /// Adds the event. + /// + [EventPatch(typeof(Scp079), nameof(Scp079.Recontaining))] + [HarmonyPatch(typeof(Scp079Recontainer), nameof(Scp079Recontainer.Recontain))] + internal class Recontaining + { + private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) + { + int index = 0; + List newInstructions = new(instructions); + + LocalBuilder ev = generator.DeclareLocal(typeof(RecontainingEventArgs)); + + Label proceed = generator.DefineLabel(); + + newInstructions.InsertRange(index, new CodeInstruction[] + { + // RecontainingEventArgs ev = new(ReferenceHub "attacker") + new(OpCodes.Ldarg_0), + new(OpCodes.Ldfld, PropertyGetter(typeof(Scp079Recontainer), nameof(Scp079Recontainer._activatorGlass))), + new(OpCodes.Newobj, GetDeclaredConstructors(typeof(RecontainingEventArgs))[0]), + new(OpCodes.Starg_S, ev.LocalIndex), + + // Call event + new(OpCodes.Ldarg_S, ev.LocalIndex), + new(OpCodes.Call, Method(typeof(Scp079), nameof(Scp079.OnRecontaining))), + + // if (!ev.IsAllowed) return; + new(OpCodes.Ldarg_S, ev.LocalIndex), + new(OpCodes.Callvirt, Method(typeof(RecontainingEventArgs), nameof(RecontainingEventArgs.IsAllowed))), + new(OpCodes.Brtrue_S, proceed), + + new(OpCodes.Ret), + + new CodeInstruction(OpCodes.Nop).WithLabels(proceed), + }); + + return newInstructions; + } + } +} From f3b17ea0b7a17fda1c2d80b71ba8f0b6f22c4e13 Mon Sep 17 00:00:00 2001 From: FoxWorn3365 Date: Thu, 1 Aug 2024 15:57:00 +0200 Subject: [PATCH 02/10] Fixed constructors --- .../EventArgs/Scp079/RecontainingEventArgs.cs | 12 ++++++------ .../Patches/Events/Scp079/Recontaining.cs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs index f15352343..804b152fd 100644 --- a/EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs @@ -18,19 +18,19 @@ public class RecontainingEventArgs : IDeniableEvent /// /// Initializes a new instance of the class. /// - /// The istance. - public RecontainingEventArgs(BreakableWindow recontainer) + /// The player that triggered the SCP-079 recontaining event. + public RecontainingEventArgs(ReferenceHub recontainer) { - Recontainer = Player.Get(recontainer.LastAttacker); + Recontainer = Player.Get(recontainer); } /// /// Initializes a new instance of the class. /// - /// The player that triggered the SCP-079 recontaining event. - public RecontainingEventArgs(ReferenceHub recontainer) + /// The istance. + public RecontainingEventArgs(BreakableWindow recontainer) + : this(recontainer.LastAttacker.Hub) { - Recontainer = Player.Get(recontainer); } /// diff --git a/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs b/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs index 80ebfb6fc..7fe413bf7 100644 --- a/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs +++ b/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs @@ -42,7 +42,7 @@ private static IEnumerable Transpiler(IEnumerable Date: Thu, 1 Aug 2024 16:01:26 +0200 Subject: [PATCH 03/10] consistency --- .../Patches/Events/Scp079/Recontaining.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs b/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs index 7fe413bf7..74daf8e05 100644 --- a/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs +++ b/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs @@ -10,6 +10,7 @@ namespace Exiled.Events.Patches.Events.Scp079 using System.Collections.Generic; using System.Reflection.Emit; + using Exiled.API.Features.Pools; using Exiled.Events.Attributes; using Exiled.Events.EventArgs.Scp079; using Exiled.Events.Handlers; @@ -31,11 +32,11 @@ internal class Recontaining private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) { int index = 0; - List newInstructions = new(instructions); + List newInstructions = ListPool.Pool.Get(instructions); LocalBuilder ev = generator.DeclareLocal(typeof(RecontainingEventArgs)); - Label proceed = generator.DefineLabel(); + Label returnLabel = generator.DefineLabel(); newInstructions.InsertRange(index, new CodeInstruction[] { @@ -52,14 +53,17 @@ private static IEnumerable Transpiler(IEnumerable.Pool.Return(newInstructions); } } } From 711d32eb49947f37ae5f7a2445ab6844e4ba35c9 Mon Sep 17 00:00:00 2001 From: FoxWorn3365 Date: Thu, 1 Aug 2024 16:03:47 +0200 Subject: [PATCH 04/10] fixed logic skill issue --- EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs b/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs index 74daf8e05..0b7802ff5 100644 --- a/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs +++ b/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs @@ -53,9 +53,7 @@ private static IEnumerable Transpiler(IEnumerable Date: Thu, 1 Aug 2024 19:16:33 +0200 Subject: [PATCH 05/10] Removed "useless" constructor --- .../EventArgs/Scp079/RecontainingEventArgs.cs | 11 +---------- .../Patches/Events/Scp079/Recontaining.cs | 2 +- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs index 804b152fd..94f1d370f 100644 --- a/EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs @@ -15,22 +15,13 @@ namespace Exiled.Events.EventArgs.Scp079 /// public class RecontainingEventArgs : IDeniableEvent { - /// - /// Initializes a new instance of the class. - /// - /// The player that triggered the SCP-079 recontaining event. - public RecontainingEventArgs(ReferenceHub recontainer) - { - Recontainer = Player.Get(recontainer); - } - /// /// Initializes a new instance of the class. /// /// The istance. public RecontainingEventArgs(BreakableWindow recontainer) - : this(recontainer.LastAttacker.Hub) { + Recontainer = Player.Get(recontainer?.LastAttacker.Hub); } /// diff --git a/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs b/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs index 0b7802ff5..dfa882d62 100644 --- a/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs +++ b/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs @@ -43,7 +43,7 @@ private static IEnumerable Transpiler(IEnumerable Date: Thu, 1 Aug 2024 19:17:00 +0200 Subject: [PATCH 06/10] corrected the typo --- EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs index 94f1d370f..788eda67e 100644 --- a/EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs @@ -18,7 +18,7 @@ public class RecontainingEventArgs : IDeniableEvent /// /// Initializes a new instance of the class. /// - /// The istance. + /// The instance. public RecontainingEventArgs(BreakableWindow recontainer) { Recontainer = Player.Get(recontainer?.LastAttacker.Hub); From 2a6b04cefc6ac9511809f3259a782ebfd4e6af02 Mon Sep 17 00:00:00 2001 From: FoxWorn3365 Date: Thu, 1 Aug 2024 19:52:37 +0200 Subject: [PATCH 07/10] fixed some typo --- EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs b/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs index dfa882d62..c50ed78b8 100644 --- a/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs +++ b/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs @@ -40,13 +40,13 @@ private static IEnumerable Transpiler(IEnumerable Date: Sun, 4 Aug 2024 01:32:07 +0200 Subject: [PATCH 08/10] final edit for the final request --- .../Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs index 788eda67e..05417e2a0 100644 --- a/EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs @@ -21,7 +21,8 @@ public class RecontainingEventArgs : IDeniableEvent /// The instance. public RecontainingEventArgs(BreakableWindow recontainer) { - Recontainer = Player.Get(recontainer?.LastAttacker.Hub); + Recontainer = Player.Get(recontainer.LastAttacker.Hub); + IsAutomatic = recontainer.LastAttacker.IsSet; } /// @@ -36,6 +37,6 @@ public RecontainingEventArgs(BreakableWindow recontainer) /// /// Gets a value indicating whether or not the recontained has been made automatically or by triggering the proccess. /// - public bool IsAutomatic => Recontainer is null; + public bool IsAutomatic { get; } } } From 003e7b839cc701eb6f412b6e1d447ef61dcd6fa0 Mon Sep 17 00:00:00 2001 From: Yamato <66829532+louis1706@users.noreply.github.com> Date: Sat, 10 Aug 2024 08:56:29 +0200 Subject: [PATCH 09/10] Apply suggestions from code review --- .../Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs index 05417e2a0..11d88c3f1 100644 --- a/EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs @@ -13,7 +13,7 @@ namespace Exiled.Events.EventArgs.Scp079 /// /// Contains information before SCP-079 gets recontained. /// - public class RecontainingEventArgs : IDeniableEvent + public class RecontainingEventArgs : IDeniableEvent, IPlayerEvent { /// /// Initializes a new instance of the class. @@ -21,7 +21,7 @@ public class RecontainingEventArgs : IDeniableEvent /// The instance. public RecontainingEventArgs(BreakableWindow recontainer) { - Recontainer = Player.Get(recontainer.LastAttacker.Hub); + Player = Player.Get(recontainer.LastAttacker.Hub); IsAutomatic = recontainer.LastAttacker.IsSet; } @@ -29,7 +29,7 @@ public RecontainingEventArgs(BreakableWindow recontainer) /// Gets the Player that started the recontainment process.

/// Can be null if is true. ///
- public Player Recontainer { get; } + public Player Player { get; } /// public bool IsAllowed { get; set; } = true; From 0f72c28e85bc0044aeb68b70456712bf54cd1b14 Mon Sep 17 00:00:00 2001 From: Yamato <66829532+louis1706@users.noreply.github.com> Date: Sat, 10 Aug 2024 13:02:04 +0200 Subject: [PATCH 10/10] Apply suggestions from code review Co-authored-by: VALERA771 <72030575+VALERA771@users.noreply.github.com> --- EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs b/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs index c50ed78b8..82e924fbc 100644 --- a/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs +++ b/EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs @@ -44,14 +44,14 @@ private static IEnumerable Transpiler(IEnumerable