From 4f066adbf613979586fd6a6855c2df968b6c8746 Mon Sep 17 00:00:00 2001 From: Yamato Date: Mon, 23 Dec 2024 15:50:39 +0100 Subject: [PATCH 1/7] fix water error being show --- EXILED/Exiled.API/Features/Components/CollisionHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EXILED/Exiled.API/Features/Components/CollisionHandler.cs b/EXILED/Exiled.API/Features/Components/CollisionHandler.cs index 2cd1cd220..54d117fe4 100644 --- a/EXILED/Exiled.API/Features/Components/CollisionHandler.cs +++ b/EXILED/Exiled.API/Features/Components/CollisionHandler.cs @@ -56,7 +56,7 @@ private void OnCollisionEnter(Collision collision) Log.Error("Grenade is null!"); if (collision is null) Log.Error("wat"); - if (collision.collider) + if (!collision.collider) Log.Error("water"); if (collision.collider.gameObject == null) Log.Error("pepehm"); From 3bb0d04362ccfe23f6de51541495366e5778599c Mon Sep 17 00:00:00 2001 From: VALERA771 <72030575+VALERA771@users.noreply.github.com> Date: Tue, 24 Dec 2024 13:22:24 +0300 Subject: [PATCH 2/7] uh fix (#329) --- .../Exiled.API/Features/Core/UserSettings/SettingBase.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/EXILED/Exiled.API/Features/Core/UserSettings/SettingBase.cs b/EXILED/Exiled.API/Features/Core/UserSettings/SettingBase.cs index 840128485..6ed7fce26 100644 --- a/EXILED/Exiled.API/Features/Core/UserSettings/SettingBase.cs +++ b/EXILED/Exiled.API/Features/Core/UserSettings/SettingBase.cs @@ -328,7 +328,13 @@ internal static void OnSettingUpdated(ReferenceHub hub, ServerSpecificSettingBas } setting = list.Find(x => x.Id == settingBase.SettingId); - setting.OriginalDefinition.OnChanged?.Invoke(player, setting); + + if (setting.OriginalDefinition == null) + { + Settings.Add(Create(settingBase.OriginalDefinition)); + } + + setting.OriginalDefinition?.OnChanged?.Invoke(player, setting); } } } \ No newline at end of file From 88ce337ae8cb175cbc1d94565a1f6dc9a5d7cca3 Mon Sep 17 00:00:00 2001 From: Inzi <98975836+InziDeveloperMode@users.noreply.github.com> Date: Tue, 24 Dec 2024 12:20:40 +0100 Subject: [PATCH 3/7] Update SettingBase.cs (#332) --- EXILED/Exiled.API/Features/Core/UserSettings/SettingBase.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EXILED/Exiled.API/Features/Core/UserSettings/SettingBase.cs b/EXILED/Exiled.API/Features/Core/UserSettings/SettingBase.cs index 6ed7fce26..6a9e65215 100644 --- a/EXILED/Exiled.API/Features/Core/UserSettings/SettingBase.cs +++ b/EXILED/Exiled.API/Features/Core/UserSettings/SettingBase.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------- // // Copyright (c) ExMod Team. All rights reserved. // Licensed under the CC BY-SA 3.0 license. @@ -131,7 +131,7 @@ public string HintDescription public Action OnChanged { get; set; } /// - /// Tries ti get the setting with the specified id. + /// Tries to get the setting with the specified id. /// /// Player who has received the setting. /// Id of the setting. From cbe1a06b0bb38242b0fdca05b3947a0debde4f55 Mon Sep 17 00:00:00 2001 From: VALERA771 <72030575+VALERA771@users.noreply.github.com> Date: Tue, 24 Dec 2024 18:28:33 +0300 Subject: [PATCH 4/7] fix: several bug fixes (#334) * fix: possible admin chat fix * fix: several fixes * IItemEvent now contain IPlayerEvent * InteractingElevatorFix not being call inside elevator * InteractingElevator::IsCalledFromInside --------- Co-authored-by: Yamato --- .../EventArgs/Interfaces/IItemEvent.cs | 2 +- .../Item/ChargingJailbirdEventArgs.cs | 2 +- .../EventArgs/Item/SwingingEventArgs.cs | 2 +- .../EventArgs/Player/ChangedItemEventArgs.cs | 2 +- .../Player/ChangingDisruptorModeEventArgs.cs | 6 +- .../Player/ChangingMicroHIDStateEventArgs.cs | 3 + .../Player/ChangingRadioPresetEventArgs.cs | 2 +- .../EventArgs/Player/DroppingItemEventArgs.cs | 2 +- .../Player/InteractingElevatorEventArgs.cs | 11 ++- .../EventArgs/Player/ItemAddedEventArgs.cs | 2 +- .../EventArgs/Player/ItemRemovedEventArgs.cs | 2 +- .../Player/ThrowingRequestEventArgs.cs | 2 +- .../Player/ThrownProjectileEventArgs.cs | 2 +- .../Player/UsingMicroHIDEnergyEventArgs.cs | 3 + .../Scp914/UpgradingInventoryItemEventArgs.cs | 2 +- .../Events/Player/InteractingElevator.cs | 72 +++++++++++++++++-- .../Events/Player/SendingAdminChatMessage.cs | 4 +- 17 files changed, 101 insertions(+), 20 deletions(-) diff --git a/EXILED/Exiled.Events/EventArgs/Interfaces/IItemEvent.cs b/EXILED/Exiled.Events/EventArgs/Interfaces/IItemEvent.cs index 5e838badd..c2fcb61da 100644 --- a/EXILED/Exiled.Events/EventArgs/Interfaces/IItemEvent.cs +++ b/EXILED/Exiled.Events/EventArgs/Interfaces/IItemEvent.cs @@ -12,7 +12,7 @@ namespace Exiled.Events.EventArgs.Interfaces /// /// Event args used for all related events. /// - public interface IItemEvent : IExiledEvent + public interface IItemEvent : IPlayerEvent { /// /// Gets the triggering the event. diff --git a/EXILED/Exiled.Events/EventArgs/Item/ChargingJailbirdEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Item/ChargingJailbirdEventArgs.cs index 7e7a6e58b..342d4b311 100644 --- a/EXILED/Exiled.Events/EventArgs/Item/ChargingJailbirdEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Item/ChargingJailbirdEventArgs.cs @@ -14,7 +14,7 @@ namespace Exiled.Events.EventArgs.Item /// /// Contains all information before a player charges a . /// - public class ChargingJailbirdEventArgs : IPlayerEvent, IItemEvent + public class ChargingJailbirdEventArgs : IItemEvent { /// /// Initializes a new instance of the class. diff --git a/EXILED/Exiled.Events/EventArgs/Item/SwingingEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Item/SwingingEventArgs.cs index 0a63b6c9b..0d97d9da1 100644 --- a/EXILED/Exiled.Events/EventArgs/Item/SwingingEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Item/SwingingEventArgs.cs @@ -14,7 +14,7 @@ namespace Exiled.Events.EventArgs.Item /// /// Contains all information before a player swings a . /// - public class SwingingEventArgs : IPlayerEvent, IItemEvent, IDeniableEvent + public class SwingingEventArgs : IItemEvent, IDeniableEvent { /// /// Initializes a new instance of the class. diff --git a/EXILED/Exiled.Events/EventArgs/Player/ChangedItemEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/ChangedItemEventArgs.cs index 5d99086af..238125690 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/ChangedItemEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/ChangedItemEventArgs.cs @@ -17,7 +17,7 @@ namespace Exiled.Events.EventArgs.Player /// /// Contains all information after a player's held item changes. /// - public class ChangedItemEventArgs : IPlayerEvent, IItemEvent + public class ChangedItemEventArgs : IItemEvent { /// /// Initializes a new instance of the class. diff --git a/EXILED/Exiled.Events/EventArgs/Player/ChangingDisruptorModeEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/ChangingDisruptorModeEventArgs.cs index dd33c9426..68fe52816 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/ChangingDisruptorModeEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/ChangingDisruptorModeEventArgs.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------- // // Copyright (c) ExMod Team. All rights reserved. // Licensed under the CC BY-SA 3.0 license. @@ -8,6 +8,7 @@ namespace Exiled.Events.EventArgs.Player { using Exiled.API.Enums; + using Exiled.API.Features; using Exiled.API.Features.Items; using Exiled.Events.EventArgs.Interfaces; @@ -37,5 +38,8 @@ public ChangingDisruptorModeEventArgs(Item firearm, bool mode) /// Gets a new disruptor's fire mode. /// public DisruptorMode NewMode { get; } + + /// + public Player Player => Item.Owner; } } \ No newline at end of file diff --git a/EXILED/Exiled.Events/EventArgs/Player/ChangingMicroHIDStateEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/ChangingMicroHIDStateEventArgs.cs index 1274608ef..f472a7096 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/ChangingMicroHIDStateEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/ChangingMicroHIDStateEventArgs.cs @@ -56,5 +56,8 @@ public ChangingMicroHIDStateEventArgs(Item microHID, MicroHidPhase newPhase, boo /// public Item Item => MicroHID; + + /// + public Player Player => MicroHID.Owner; } } \ No newline at end of file diff --git a/EXILED/Exiled.Events/EventArgs/Player/ChangingRadioPresetEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/ChangingRadioPresetEventArgs.cs index b48a8b764..c00696a75 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/ChangingRadioPresetEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/ChangingRadioPresetEventArgs.cs @@ -21,7 +21,7 @@ namespace Exiled.Events.EventArgs.Player /// /// Contains all information before radio preset is changed. /// - public class ChangingRadioPresetEventArgs : IPlayerEvent, IItemEvent, IDeniableEvent + public class ChangingRadioPresetEventArgs : IItemEvent, IDeniableEvent { /// /// Initializes a new instance of the class. diff --git a/EXILED/Exiled.Events/EventArgs/Player/DroppingItemEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/DroppingItemEventArgs.cs index 4ff31bde6..cf15df90d 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/DroppingItemEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/DroppingItemEventArgs.cs @@ -19,7 +19,7 @@ namespace Exiled.Events.EventArgs.Player /// /// Contains all information before a player drops an item. /// - public class DroppingItemEventArgs : IPlayerEvent, IItemEvent, IDeniableEvent + public class DroppingItemEventArgs : IItemEvent, IDeniableEvent { private bool isAllowed = true; diff --git a/EXILED/Exiled.Events/EventArgs/Player/InteractingElevatorEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/InteractingElevatorEventArgs.cs index b8bda532d..5a3edb3ad 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/InteractingElevatorEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/InteractingElevatorEventArgs.cs @@ -28,14 +28,18 @@ public class InteractingElevatorEventArgs : IPlayerEvent, IDeniableEvent /// /// /// + /// + /// + /// /// /// /// - public InteractingElevatorEventArgs(Player player, ElevatorChamber elevator, bool isAllowed = true) + public InteractingElevatorEventArgs(Player player, ElevatorChamber elevator, bool isCalledFromInside, bool isAllowed = true) { Player = player; Lift = Lift.Get(elevator); Elevator = elevator; + IsCalledFromInside = isCalledFromInside; IsAllowed = isAllowed; } @@ -54,6 +58,11 @@ public InteractingElevatorEventArgs(Player player, ElevatorChamber elevator, boo /// public bool IsAllowed { get; set; } + /// + /// Gets a value indicating whether the player as interact with the elevator from the inside. + /// + public bool IsCalledFromInside { get; } + /// /// Gets the player who's interacting with the elevator. /// diff --git a/EXILED/Exiled.Events/EventArgs/Player/ItemAddedEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/ItemAddedEventArgs.cs index 68c5aca0d..694188c1c 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/ItemAddedEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/ItemAddedEventArgs.cs @@ -17,7 +17,7 @@ namespace Exiled.Events.EventArgs.Player /// /// Contains all information after adding an item to a player's inventory. /// - public class ItemAddedEventArgs : IPlayerEvent, IItemEvent, IPickupEvent + public class ItemAddedEventArgs : IItemEvent, IPickupEvent { /// /// Initializes a new instance of the class. diff --git a/EXILED/Exiled.Events/EventArgs/Player/ItemRemovedEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/ItemRemovedEventArgs.cs index ef0dc9a53..f14eb31d2 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/ItemRemovedEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/ItemRemovedEventArgs.cs @@ -17,7 +17,7 @@ namespace Exiled.Events.EventArgs.Player /// /// Contains all information after removing an item from a player's inventory. /// - public class ItemRemovedEventArgs : IPlayerEvent, IItemEvent, IPickupEvent + public class ItemRemovedEventArgs : IItemEvent, IPickupEvent { /// /// Initializes a new instance of the class. diff --git a/EXILED/Exiled.Events/EventArgs/Player/ThrowingRequestEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/ThrowingRequestEventArgs.cs index 586cc15f5..ee1b36558 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/ThrowingRequestEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/ThrowingRequestEventArgs.cs @@ -17,7 +17,7 @@ namespace Exiled.Events.EventArgs.Player /// /// Contains all information before receving a throwing request. /// - public class ThrowingRequestEventArgs : IPlayerEvent, IItemEvent + public class ThrowingRequestEventArgs : IItemEvent { /// /// Initializes a new instance of the class. diff --git a/EXILED/Exiled.Events/EventArgs/Player/ThrownProjectileEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/ThrownProjectileEventArgs.cs index 7da1528af..14ab42de1 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/ThrownProjectileEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/ThrownProjectileEventArgs.cs @@ -18,7 +18,7 @@ namespace Exiled.Events.EventArgs.Player /// /// Contains all information after a player throws a grenade. /// - public class ThrownProjectileEventArgs : IPlayerEvent, IItemEvent, IPickupEvent + public class ThrownProjectileEventArgs : IItemEvent, IPickupEvent { /// /// Initializes a new instance of the class. diff --git a/EXILED/Exiled.Events/EventArgs/Player/UsingMicroHIDEnergyEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/UsingMicroHIDEnergyEventArgs.cs index 86e76a2e7..cbf292d86 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/UsingMicroHIDEnergyEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/UsingMicroHIDEnergyEventArgs.cs @@ -55,5 +55,8 @@ public UsingMicroHIDEnergyEventArgs(MicroHIDItem microHIDitem, float newEnergy, /// Gets or sets a value indicating whether the MicroHID energy can be changed. /// public bool IsAllowed { get; set; } + + /// + public Player Player => MicroHID.Owner; } } \ No newline at end of file diff --git a/EXILED/Exiled.Events/EventArgs/Scp914/UpgradingInventoryItemEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Scp914/UpgradingInventoryItemEventArgs.cs index b4f27aa5f..667320e57 100644 --- a/EXILED/Exiled.Events/EventArgs/Scp914/UpgradingInventoryItemEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Scp914/UpgradingInventoryItemEventArgs.cs @@ -16,7 +16,7 @@ namespace Exiled.Events.EventArgs.Scp914 /// /// Contains all information before SCP-914 upgrades an item. /// - public class UpgradingInventoryItemEventArgs : IPlayerEvent, IItemEvent, IDeniableEvent + public class UpgradingInventoryItemEventArgs : IItemEvent, IDeniableEvent { /// /// Initializes a new instance of the class. diff --git a/EXILED/Exiled.Events/Patches/Events/Player/InteractingElevator.cs b/EXILED/Exiled.Events/Patches/Events/Player/InteractingElevator.cs index c51ecb5cf..39382fd68 100644 --- a/EXILED/Exiled.Events/Patches/Events/Player/InteractingElevator.cs +++ b/EXILED/Exiled.Events/Patches/Events/Player/InteractingElevator.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.Emit; @@ -19,16 +20,15 @@ namespace Exiled.Events.Patches.Events.Player using Interactables.Interobjects; - using Mirror; - using static HarmonyLib.AccessTools; /// - /// Patches . + /// Patches . /// Adds the event. + /// This event only get call when interact on the outside button. /// [EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.InteractingElevator))] - [HarmonyPatch(typeof(ElevatorChamber), nameof(ElevatorChamber.ServerInteract))] + [HarmonyPatch(typeof(ElevatorDoor), nameof(ElevatorDoor.ServerInteract))] internal class InteractingElevator { private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) @@ -39,6 +39,65 @@ private static IEnumerable Transpiler(IEnumerable.Pool.Return(newInstructions); + } + } + + /// + /// Patches . + /// Adds the event. + /// This event only get call when interact on the inside button. + /// + [EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.InteractingElevator))] + [HarmonyPatch(typeof(ElevatorChamber), nameof(ElevatorChamber.ServerInteract))] + internal class InteractingElevator2 + { + private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) + { + List newInstructions = ListPool.Pool.Get(instructions); + + Label returnLabel = generator.DefineLabel(); + + newInstructions[newInstructions.Count - 1].labels.Add(returnLabel); + // InteractingElevatorEventArgs ev = new(Player.Get(referenceHub), elevatorChamber, true); // // Handlers.Player.OnInteractingElevator(ev); @@ -57,7 +116,10 @@ private static IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable instruction.opcode == OpCodes.Ldloca_S) + offset; + int offset = 3; + int index = newInstructions.FindIndex(instruction => instruction.Calls(Method(typeof(Misc), nameof(Misc.SanitizeRichText)))) + offset; newInstructions.InsertRange( index, From b94e64650f7fa1ea31d4e3044a27141fb519c664 Mon Sep 17 00:00:00 2001 From: IRacle <79921583+IRacle1@users.noreply.github.com> Date: Tue, 24 Dec 2024 23:16:22 +0300 Subject: [PATCH 5/7] fix: Player comparing (`GetHashCode`) (#340) * fix: player compairing * a little --- EXILED/Exiled.API/Features/Player.cs | 2 +- EXILED/Exiled.Events/EventArgs/Player/SpawningEventArgs.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/EXILED/Exiled.API/Features/Player.cs b/EXILED/Exiled.API/Features/Player.cs index eea891c64..778f94133 100644 --- a/EXILED/Exiled.API/Features/Player.cs +++ b/EXILED/Exiled.API/Features/Player.cs @@ -3714,7 +3714,7 @@ public override bool Equals(object obj) /// public override int GetHashCode() { - return ReferenceHub.GetHashCode(); + return base.GetHashCode(); } /// diff --git a/EXILED/Exiled.Events/EventArgs/Player/SpawningEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/SpawningEventArgs.cs index bc543dc58..785ff5a3c 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/SpawningEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/SpawningEventArgs.cs @@ -68,7 +68,7 @@ public SpawningEventArgs(Player player, Vector3 position, float rotation, Player /// Gets the player's old role. /// [Obsolete("Removed because the method is no longer provide OldRole since version 14.0. Use Player.Role instead")] - public Role OldRole { get; } + public Role OldRole => Player.Role; /// /// Gets the player's new role. From 74272b1a20ecc9f77e9cbeed9522d0ef8d15affd Mon Sep 17 00:00:00 2001 From: IRacle <79921583+IRacle1@users.noreply.github.com> Date: Tue, 24 Dec 2024 23:33:41 +0300 Subject: [PATCH 6/7] refactor: remove `SlownessFix` (#337) --- .../Patches/Fixes/SlownessFix.cs | 67 ------------------- 1 file changed, 67 deletions(-) delete mode 100644 EXILED/Exiled.Events/Patches/Fixes/SlownessFix.cs diff --git a/EXILED/Exiled.Events/Patches/Fixes/SlownessFix.cs b/EXILED/Exiled.Events/Patches/Fixes/SlownessFix.cs deleted file mode 100644 index 3036cb3cc..000000000 --- a/EXILED/Exiled.Events/Patches/Fixes/SlownessFix.cs +++ /dev/null @@ -1,67 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright (c) ExMod Team. All rights reserved. -// Licensed under the CC BY-SA 3.0 license. -// -// ----------------------------------------------------------------------- - -namespace Exiled.Events.Patches.Fixes -{ - using System.Collections.Generic; - using System.Reflection.Emit; - - using Exiled.API.Features.Pools; - using HarmonyLib; - using PlayerRoles.FirstPersonControl; - using UnityEngine; - - using static HarmonyLib.AccessTools; - - /// - /// Patches getter to fix Slowness effect. - /// reported to NW (https://git.scpslgame.com/northwood-qa/scpsl-bug-reporting/-/issues/378). - /// - [HarmonyPatch(typeof(FpcMotor), nameof(FpcMotor.DesiredMove), MethodType.Getter)] - internal class SlownessFix - { - private static IEnumerable Transpiler(IEnumerable instructions) - { - List newInstructions = ListPool.Pool.Get(instructions); - - int offset = 1; - int index = newInstructions.FindLastIndex(x => x.operand == (object)Field(typeof(FpcMotor), nameof(FpcMotor._lastMaxSpeed))) + offset; - - newInstructions.Insert(index, new(OpCodes.Call, Method(typeof(Mathf), nameof(Mathf.Abs), new[] { typeof(float) }))); - - for (int z = 0; z < newInstructions.Count; z++) - yield return newInstructions[z]; - - ListPool.Pool.Return(newInstructions); - } - } - - /// - /// Patches method to fix Slowness effect. - /// reported to NW (https://git.scpslgame.com/northwood-qa/scpsl-bug-reporting/-/issues/378). - /// - [HarmonyPatch(typeof(FpcMotor), nameof(FpcMotor.UpdatePosition))] -#pragma warning disable SA1402 // File may only contain a single type - internal class SlownessFixPosition -#pragma warning restore SA1402 // File may only contain a single type - { - private static IEnumerable Transpiler(IEnumerable instructions) - { - List newInstructions = ListPool.Pool.Get(instructions); - - int offset = 1; - int index = newInstructions.FindIndex(x => x.Calls(PropertyGetter(typeof(FpcMotor), nameof(FpcMotor.Speed)))) + offset; - - newInstructions.Insert(index, new(OpCodes.Call, Method(typeof(Mathf), nameof(Mathf.Abs), new[] { typeof(float) }))); - - for (int z = 0; z < newInstructions.Count; z++) - yield return newInstructions[z]; - - ListPool.Pool.Return(newInstructions); - } - } -} \ No newline at end of file From e3c7be2de5b3dc04b49075a3d74166dc71a172e1 Mon Sep 17 00:00:00 2001 From: VALERA771 <72030575+VALERA771@users.noreply.github.com> Date: Wed, 25 Dec 2024 16:47:03 +0300 Subject: [PATCH 7/7] feat: Speaker update (#319) * feat: * refactor: playback client-sided, no? --- EXILED/Exiled.API/Features/Toys/Speaker.cs | 34 +++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/EXILED/Exiled.API/Features/Toys/Speaker.cs b/EXILED/Exiled.API/Features/Toys/Speaker.cs index c51b8bcb7..2ca0b2907 100644 --- a/EXILED/Exiled.API/Features/Toys/Speaker.cs +++ b/EXILED/Exiled.API/Features/Toys/Speaker.cs @@ -7,10 +7,14 @@ namespace Exiled.API.Features.Toys { + using System.Collections.Generic; + using AdminToys; using Enums; using Exiled.API.Interfaces; using UnityEngine; + using VoiceChat.Networking; + using VoiceChat.Playbacks; /// /// A wrapper class for . @@ -44,7 +48,7 @@ internal Speaker(SpeakerToy speakerToy) public float Volume { get => Base.NetworkVolume; - set => Base.NetworkVolume = value; + set => Base.NetworkVolume = Mathf.Clamp01(value); } /// @@ -86,6 +90,15 @@ public float MinDistance set => Base.NetworkMinDistance = value; } + /// + /// Gets or sets the controller ID of speaker. + /// + public byte ControllerId + { + get => Base.NetworkControllerId; + set => Base.NetworkControllerId = value; + } + /// /// Creates a new . /// @@ -108,5 +121,24 @@ public static Speaker Create(Vector3? position, Vector3? rotation, Vector3? scal return speaker; } + + /// + /// Plays audio through this speaker. + /// + /// An instance. + /// Targets who will hear the audio. If null, audio will be sent to all players. + public static void Play(AudioMessage message, IEnumerable targets = null) + { + foreach (Player target in targets ?? Player.List) + target.Connection.Send(message); + } + + /// + /// Plays audio through this speaker. + /// + /// Audio samples. + /// The length of the samples array. + /// Targets who will hear the audio. If null, audio will be sent to all players. + public void Play(byte[] samples, int? length = null, IEnumerable targets = null) => Play(new AudioMessage(ControllerId, samples, length ?? samples.Length), targets); } }