diff --git a/EXILED/Exiled.API/Features/Core/UserSettings/SettingBase.cs b/EXILED/Exiled.API/Features/Core/UserSettings/SettingBase.cs index e06a03ccd..6b2fbfbbb 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. diff --git a/EXILED/Exiled.API/Features/Player.cs b/EXILED/Exiled.API/Features/Player.cs index eea891c64..8bf776590 100644 --- a/EXILED/Exiled.API/Features/Player.cs +++ b/EXILED/Exiled.API/Features/Player.cs @@ -2781,7 +2781,7 @@ public void AddItem(Firearm item, IEnumerable identifiers) /// The of the item to be added. /// The reason the item was added. /// The that was added. - public Item AddItem(Pickup pickup, ItemAddReason addReason = ItemAddReason.Undefined) => Item.Get(Inventory.ServerAddItem(pickup.Type, addReason, pickup.Serial, pickup.Base)); + public Item AddItem(Pickup pickup, ItemAddReason addReason = ItemAddReason.AdminCommand) => Item.Get(Inventory.ServerAddItem(pickup.Type, addReason, pickup.Serial, pickup.Base)); /// /// Adds an item to the player's inventory. @@ -2791,7 +2791,7 @@ public void AddItem(Firearm item, IEnumerable identifiers) /// The that was added. public Item AddItem(FirearmPickup pickup, IEnumerable identifiers) { - Firearm firearm = Item.Get(Inventory.ServerAddItem(pickup.Type, ItemAddReason.Undefined, pickup.Serial, pickup.Base)); + Firearm firearm = Item.Get(Inventory.ServerAddItem(pickup.Type, ItemAddReason.AdminCommand, pickup.Serial, pickup.Base)); if (identifiers is not null) firearm.AddAttachment(identifiers); @@ -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.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); } } 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/ChangingMicroHIDPickupStateEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Item/ChangingMicroHIDPickupStateEventArgs.cs new file mode 100644 index 000000000..a70c37fde --- /dev/null +++ b/EXILED/Exiled.Events/EventArgs/Item/ChangingMicroHIDPickupStateEventArgs.cs @@ -0,0 +1,58 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.EventArgs.Item +{ + using Exiled.API.Features.Pickups; + + using Interfaces; + using InventorySystem.Items.MicroHID.Modules; + using InventorySystem.Items.Pickups; + + /// + /// Contains all information before MicroHID pickup state is changed. + /// + public class ChangingMicroHIDPickupStateEventArgs : IDeniableEvent, IPickupEvent + { + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public ChangingMicroHIDPickupStateEventArgs(ItemPickupBase microHID, MicroHidPhase newPhase, bool isAllowed = true) + { + MicroHID = Pickup.Get(microHID); + NewPhase = newPhase; + IsAllowed = isAllowed; + } + + /// + /// Gets the MicroHID instance. + /// + public MicroHIDPickup MicroHID { get; } + + /// + /// Gets or sets the new MicroHID state. + /// + public MicroHidPhase NewPhase { get; set; } + + /// + /// Gets or sets a value indicating whether the MicroHID state can be changed. + /// + public bool IsAllowed { get; set; } + + /// + public Pickup Pickup => MicroHID; + } +} \ No newline at end of file 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..2881241cd 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/ChangingMicroHIDStateEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/ChangingMicroHIDStateEventArgs.cs @@ -12,6 +12,8 @@ namespace Exiled.Events.EventArgs.Player using API.Features; using API.Features.Items; using Interfaces; + + using InventorySystem.Items; using InventorySystem.Items.MicroHID; using InventorySystem.Items.MicroHID.Modules; @@ -32,9 +34,9 @@ public class ChangingMicroHIDStateEventArgs : IDeniableEvent, IItemEvent /// /// /// - public ChangingMicroHIDStateEventArgs(Item microHID, MicroHidPhase newPhase, bool isAllowed = true) + public ChangingMicroHIDStateEventArgs(ItemBase microHID, MicroHidPhase newPhase, bool isAllowed = true) { - MicroHID = microHID.As(); + MicroHID = Item.Get(microHID); NewPhase = newPhase; IsAllowed = isAllowed; } @@ -56,5 +58,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/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. 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/Handlers/Item.cs b/EXILED/Exiled.Events/Handlers/Item.cs index 22c8907a2..1c3f8b15e 100644 --- a/EXILED/Exiled.Events/Handlers/Item.cs +++ b/EXILED/Exiled.Events/Handlers/Item.cs @@ -53,6 +53,11 @@ public static class Item /// public static Event UsingRadioPickupBattery { get; set; } = new(); + /// + /// Invoked before a state is changed. + /// + public static Event ChangingMicroHIDPickupState { get; set; } = new(); + /// /// Called before the ammo of an firearm is changed. /// @@ -94,5 +99,11 @@ public static class Item /// /// The instance. public static void OnUsingRadioPickupBattery(UsingRadioPickupBatteryEventArgs ev) => UsingRadioPickupBattery.InvokeSafely(ev); + + /// + /// Called before a state is changed. + /// + /// The instance. + public static void OnChangingMicroHIDPickupState(ChangingMicroHIDPickupStateEventArgs ev) => ChangingMicroHIDPickupState.InvokeSafely(ev); } } \ No newline at end of file diff --git a/EXILED/Exiled.Events/Patches/Events/Player/ChangingMicroHIDState.cs b/EXILED/Exiled.Events/Patches/Events/Player/ChangingMicroHIDState.cs index c45000b67..fdab78241 100644 --- a/EXILED/Exiled.Events/Patches/Events/Player/ChangingMicroHIDState.cs +++ b/EXILED/Exiled.Events/Patches/Events/Player/ChangingMicroHIDState.cs @@ -14,6 +14,7 @@ namespace Exiled.Events.Patches.Events.Player using API.Features.Items; using API.Features.Pools; using Exiled.Events.Attributes; + using Exiled.Events.EventArgs.Item; using Exiled.Events.EventArgs.Player; using HarmonyLib; using InventorySystem.Items.MicroHID; @@ -34,43 +35,43 @@ private static IEnumerable Transpiler(IEnumerable newInstructions = ListPool.Pool.Get(instructions); Label returnLabel = generator.DefineLabel(); + Label pickupLabel = generator.DefineLabel(); + Label continueLabel = generator.DefineLabel(); - LocalBuilder ev = generator.DeclareLocal(typeof(ChangingMicroHIDStateEventArgs)); + LocalBuilder item = generator.DeclareLocal(typeof(MicroHIDItem)); int offset = 1; int index = newInstructions.FindIndex(x => x.opcode == OpCodes.Ret) + offset; newInstructions.InsertRange(index, new[] { - // Item.Get(this.Serial); + // MicroHIDItem item = Item.Get(this._prevItem); + // if (item is null) + // pickup code; + // else + // itemCode; new CodeInstruction(OpCodes.Ldarg_0).MoveLabelsFrom(newInstructions[index]), - new(OpCodes.Ldfld, Field(typeof(CycleController), nameof(CycleController.Serial))), - new(OpCodes.Call, GetDeclaredMethods(typeof(Item)).Find(x => !x.IsGenericMethod && x.IsStatic && x.GetParameters().FirstOrDefault()?.ParameterType == typeof(ushort))), + new(OpCodes.Ldfld, Field(typeof(CycleController), nameof(CycleController._prevItem))), + new(OpCodes.Dup), + new(OpCodes.Stloc_S, item.LocalIndex), + new(OpCodes.Brfalse_S, pickupLabel), - // value - new(OpCodes.Ldarg_1), + // bool allowed = CallItemEvent(microHidItem, phase) + new(OpCodes.Ldloc_S, item.LocalIndex), + new(OpCodes.Ldarga_S, 1), + new(OpCodes.Call, Method(typeof(ChangingMicroHIDState), nameof(ChangingMicroHIDState.CallItemEvent))), - // true - new(OpCodes.Ldc_I4_1), + new CodeInstruction(OpCodes.Br_S, continueLabel), - // ChangerMicroHIDStateEventArgs ev = new(Item.Get(this.Serial), value, true); - new(OpCodes.Newobj, GetDeclaredConstructors(typeof(ChangingMicroHIDStateEventArgs))[0]), - new(OpCodes.Dup), - new(OpCodes.Dup), - new(OpCodes.Stloc_S, ev.LocalIndex), - - // Handlers.Player.OnChangingMicroHIDState(ev); - new(OpCodes.Call, Method(typeof(Handlers.Player), nameof(Handlers.Player.OnChangingMicroHIDState))), + // bool allowed = CallPickupEvent(Serial, phase) + new CodeInstruction(OpCodes.Ldarg_0).WithLabels(pickupLabel), + new(OpCodes.Ldfld, Field(typeof(CycleController), nameof(CycleController.Serial))), + new(OpCodes.Ldarga_S, 1), + new(OpCodes.Call, Method(typeof(ChangingMicroHIDState), nameof(ChangingMicroHIDState.CallPickupEvent))), - // if (!ev.IsAllowed) + // if (!allowed) // return; - new(OpCodes.Callvirt, PropertyGetter(typeof(ChangingMicroHIDStateEventArgs), nameof(ChangingMicroHIDStateEventArgs.IsAllowed))), - new(OpCodes.Brfalse_S, returnLabel), - - // value = ev.NewPhase; - new(OpCodes.Ldloc_S, ev.LocalIndex), - new(OpCodes.Callvirt, PropertyGetter(typeof(ChangingMicroHIDStateEventArgs), nameof(ChangingMicroHIDStateEventArgs.NewPhase))), - new(OpCodes.Starg_S, 1), + new CodeInstruction(OpCodes.Brfalse_S, returnLabel).WithLabels(continueLabel), }); newInstructions[newInstructions.Count - 1].labels.Add(returnLabel); @@ -80,5 +81,24 @@ private static IEnumerable Transpiler(IEnumerable.Pool.Return(newInstructions); } + + private static bool CallItemEvent(MicroHIDItem microHIDItem, ref MicroHidPhase phase) + { + ChangingMicroHIDStateEventArgs ev = new(microHIDItem, phase); + Handlers.Player.OnChangingMicroHIDState(ev); + phase = ev.NewPhase; + return ev.IsAllowed; + } + + private static bool CallPickupEvent(ushort serial, ref MicroHidPhase phase) + { + if (!MicroHIDPickup.PickupsBySerial.TryGetValue(serial, out MicroHIDPickup pickup)) + return true; + + ChangingMicroHIDPickupStateEventArgs ev = new(pickup, phase); + Handlers.Item.OnChangingMicroHIDPickupState(ev); + phase = ev.NewPhase; + return ev.IsAllowed; + } } -} \ No newline at end of file +} 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, 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