From 3aceca79e04d4b085438c2390cf289ea809e001f Mon Sep 17 00:00:00 2001 From: NotZer0Two Date: Sat, 17 Aug 2024 14:03:10 +0200 Subject: [PATCH 1/9] Audio log event --- .../Player/PlayingAudioLogEventArgs.cs | 53 ++++++++++++++ EXILED/Exiled.Events/Handlers/Player.cs | 11 +++ .../Patches/Events/Player/PlayingAudioLog.cs | 70 +++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs create mode 100644 EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs diff --git a/EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs new file mode 100644 index 000000000..630e4ca7c --- /dev/null +++ b/EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs @@ -0,0 +1,53 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Exiled Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.EventArgs.Player +{ + using API.Features; + + using Interfaces; + + /// + /// Contains all information before a player plays the AudioLog. + /// + public class PlayingAudioLogEventArgs : IPlayerEvent, IDeniableEvent + { + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public PlayingAudioLogEventArgs(Player player, byte colliderId, bool isAllowed = true) + { + Player = player; + Type = colliderId; + IsAllowed = isAllowed; + } + + /// + /// Gets or sets a value indicating whether or not the audio will start. + /// + public bool IsAllowed { get; set; } + + /// + /// Gets a value indicating the type of AudioLog. + /// + public byte Type { get; } + + /// + /// Gets the player who's filpping the switch to the generator. + /// + public Player Player { get; } + } +} \ No newline at end of file diff --git a/EXILED/Exiled.Events/Handlers/Player.cs b/EXILED/Exiled.Events/Handlers/Player.cs index aca07ce6e..cfdf89b78 100644 --- a/EXILED/Exiled.Events/Handlers/Player.cs +++ b/EXILED/Exiled.Events/Handlers/Player.cs @@ -208,6 +208,11 @@ public class Player /// public static Event DroppingNothing { get; set; } = new(); + /// + /// Invoked before playing an AudioLog. + /// + public static Event PlayingAudioLog { get; set; } = new(); + /// /// Invoked before picking up an . /// @@ -686,6 +691,12 @@ public class Player /// The instance. public static void OnDroppingNothing(DroppingNothingEventArgs ev) => DroppingNothing.InvokeSafely(ev); + /// + /// Called before a plays an AudioLog. + /// + /// The instance. + public static void OnPlayingAudioLog(PlayingAudioLogEventArgs ev) => PlayingAudioLog.InvokeSafely(ev); + /// /// Called before a picks up an item. /// diff --git a/EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs b/EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs new file mode 100644 index 000000000..1b807bebd --- /dev/null +++ b/EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs @@ -0,0 +1,70 @@ +// ----------------------------------------------------------------------- +// +// 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; + using API.Features.Pools; + using Exiled.Events.Attributes; + using Exiled.Events.EventArgs.Player; + using HarmonyLib; + using MapGeneration.Spawnables; + using static HarmonyLib.AccessTools; + + /// + /// Patch the . + /// Adds the event. + /// + [EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.PlayingAudioLog))] + [HarmonyPatch(typeof(AudioLog), nameof(AudioLog.ServerInteract))] + internal static class PlayingAudioLog + { + private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) + { + List newInstructions = ListPool.Pool.Get(instructions); + + Label retLabel = generator.DefineLabel(); + + newInstructions.InsertRange( + 0, + new CodeInstruction[] + { + // Player player = Player.Get(ReferenceHub); + new(OpCodes.Ldarg_1), + new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })), + + // collidreId + new(OpCodes.Ldarg_2), + + // true + new(OpCodes.Ldc_I4_1), + + // PlayingAudioLogEventArgs ev = new(Player, byte, bool) + new(OpCodes.Newobj, GetDeclaredConstructors(typeof(PlayingAudioLogEventArgs))[0]), + new(OpCodes.Dup), + + // Handlers.Player.OnPlayingAudioLog(ev) + new(OpCodes.Call, Method(typeof(Handlers.Player), nameof(Handlers.Player.OnPlayingAudioLog))), + + // if (!ev.IsAllowed) + // return; + new(OpCodes.Callvirt, PropertyGetter(typeof(PlayingAudioLogEventArgs), nameof(PlayingAudioLogEventArgs.IsAllowed))), + new(OpCodes.Brfalse, retLabel), + }); + + newInstructions[newInstructions.Count - 1].labels.Add(retLabel); + + for (int z = 0; z < newInstructions.Count; z++) + yield return newInstructions[z]; + + ListPool.Pool.Return(newInstructions); + } + } +} \ No newline at end of file From 110bff741abe4c24894ed19a9c13248cff159b6a Mon Sep 17 00:00:00 2001 From: NotZer0Two Date: Sat, 17 Aug 2024 14:07:26 +0200 Subject: [PATCH 2/9] Mistakes --- .../EventArgs/Player/PlayingAudioLogEventArgs.cs | 2 +- EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs index 630e4ca7c..47ee78601 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs @@ -46,7 +46,7 @@ public PlayingAudioLogEventArgs(Player player, byte colliderId, bool isAllowed = public byte Type { get; } /// - /// Gets the player who's filpping the switch to the generator. + /// Gets the player who started the AudioLog. /// public Player Player { get; } } diff --git a/EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs b/EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs index 1b807bebd..02c7212b4 100644 --- a/EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs +++ b/EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs @@ -19,8 +19,8 @@ namespace Exiled.Events.Patches.Events.Player using static HarmonyLib.AccessTools; /// - /// Patch the . - /// Adds the event. + /// Patch the . + /// Adds the event. /// [EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.PlayingAudioLog))] [HarmonyPatch(typeof(AudioLog), nameof(AudioLog.ServerInteract))] From 4f0508fe9a914d64b588dfb522c1579c97bc2fe1 Mon Sep 17 00:00:00 2001 From: NotZer0Two Date: Sat, 17 Aug 2024 14:12:56 +0200 Subject: [PATCH 3/9] Fix build errors --- EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs b/EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs index 02c7212b4..fca4af59f 100644 --- a/EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs +++ b/EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs @@ -16,6 +16,7 @@ namespace Exiled.Events.Patches.Events.Player using Exiled.Events.EventArgs.Player; using HarmonyLib; using MapGeneration.Spawnables; + using static HarmonyLib.AccessTools; /// From ae908ad1cab48468781b9350e53b207676eae410 Mon Sep 17 00:00:00 2001 From: ZeroTwo <63092138+NotZer0Two@users.noreply.github.com> Date: Sat, 17 Aug 2024 16:52:21 +0200 Subject: [PATCH 4/9] Update EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs Co-authored-by: Yamato <66829532+louis1706@users.noreply.github.com> --- EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs b/EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs index fca4af59f..8ba086777 100644 --- a/EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs +++ b/EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs @@ -41,9 +41,6 @@ private static IEnumerable Transpiler(IEnumerable Date: Sat, 17 Aug 2024 16:52:30 +0200 Subject: [PATCH 5/9] Update EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs Co-authored-by: Yamato <66829532+louis1706@users.noreply.github.com> --- .../EventArgs/Player/PlayingAudioLogEventArgs.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs index 47ee78601..8d767b66c 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs @@ -40,11 +40,6 @@ public PlayingAudioLogEventArgs(Player player, byte colliderId, bool isAllowed = /// public bool IsAllowed { get; set; } - /// - /// Gets a value indicating the type of AudioLog. - /// - public byte Type { get; } - /// /// Gets the player who started the AudioLog. /// From 377b69d31a97d8787add5c3a7fa9bfeca2089e8a Mon Sep 17 00:00:00 2001 From: ZeroTwo <63092138+NotZer0Two@users.noreply.github.com> Date: Sat, 17 Aug 2024 16:52:39 +0200 Subject: [PATCH 6/9] Update EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs Co-authored-by: Yamato <66829532+louis1706@users.noreply.github.com> --- .../Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs index 8d767b66c..23e97ed18 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs @@ -28,7 +28,7 @@ public class PlayingAudioLogEventArgs : IPlayerEvent, IDeniableEvent /// /// /// - public PlayingAudioLogEventArgs(Player player, byte colliderId, bool isAllowed = true) + public PlayingAudioLogEventArgs(Player player, bool isAllowed = true) { Player = player; Type = colliderId; From 609b3bb71f5d7ab4cd0a93355c779fb1190eba66 Mon Sep 17 00:00:00 2001 From: ZeroTwo <63092138+NotZer0Two@users.noreply.github.com> Date: Sat, 17 Aug 2024 16:52:46 +0200 Subject: [PATCH 7/9] Update EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs Co-authored-by: Yamato <66829532+louis1706@users.noreply.github.com> --- .../Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs index 23e97ed18..ee626dddd 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs @@ -22,9 +22,6 @@ public class PlayingAudioLogEventArgs : IPlayerEvent, IDeniableEvent /// /// /// - /// - /// - /// /// /// /// From 7b1dd7d2281558c6d510f9fee3caedcd31b55ecc Mon Sep 17 00:00:00 2001 From: ZeroTwo <63092138+NotZer0Two@users.noreply.github.com> Date: Sat, 17 Aug 2024 16:52:56 +0200 Subject: [PATCH 8/9] Update EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs Co-authored-by: Yamato <66829532+louis1706@users.noreply.github.com> --- .../Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs index ee626dddd..cad328ea2 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/PlayingAudioLogEventArgs.cs @@ -28,7 +28,6 @@ public class PlayingAudioLogEventArgs : IPlayerEvent, IDeniableEvent public PlayingAudioLogEventArgs(Player player, bool isAllowed = true) { Player = player; - Type = colliderId; IsAllowed = isAllowed; } From c0afbcda3a761712d5c7fab64826196ebfa9264b Mon Sep 17 00:00:00 2001 From: NotZer0Two Date: Sat, 17 Aug 2024 17:26:53 +0200 Subject: [PATCH 9/9] =?UTF-8?q?=F0=9F=A7=A0=F0=9F=92=AD=F0=9F=98=94?= =?UTF-8?q?=F0=9F=98=9E=F0=9F=93=89=F0=9F=98=AD=F0=9F=A4=94=E2=9E=A1?= =?UTF-8?q?=EF=B8=8F=F0=9F=A7=91=E2=80=8D=E2=9A=95=EF=B8=8F=F0=9F=92=AC?= =?UTF-8?q?=F0=9F=92=8A=F0=9F=93=88=F0=9F=98=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs b/EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs index 8ba086777..c2b0125e1 100644 --- a/EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs +++ b/EXILED/Exiled.Events/Patches/Events/Player/PlayingAudioLog.cs @@ -44,7 +44,7 @@ private static IEnumerable Transpiler(IEnumerable