Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// -----------------------------------------------------------------------
// <copyright file="ReceivingVoiceMessageEventArgs.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.Events.EventArgs.Player
{
using Exiled.API.Features;
using Exiled.Events.EventArgs.Interfaces;
using PlayerRoles.Voice;
using VoiceChat.Networking;

/// <summary>
/// Contains all information before a player receives a voice message.
/// </summary>
public class ReceivingVoiceMessageEventArgs : IPlayerEvent, IDeniableEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="ReceivingVoiceMessageEventArgs" /> class.
/// </summary>
/// <param name="receiver">The player receiving the voice message.</param>
/// <param name="sender">The player sending the voice message.</param>
/// <param name="voiceModule">The senders voice module.</param>
/// <param name="voiceMessage">The voice message being sent.</param>
public ReceivingVoiceMessageEventArgs(Player receiver, Player sender, VoiceModuleBase voiceModule, VoiceMessage voiceMessage)
{
Sender = sender;
Player = receiver;
VoiceMessage = voiceMessage;
VoiceModule = voiceModule;
}

/// <summary>
/// Gets the player receiving the voice message.
/// </summary>
public Player Player { get; }

/// <summary>
/// Gets the player sending the voice message.
/// </summary>
public Player Sender { get; }

/// <summary>
/// Gets or sets the <see cref="Sender"/>'s <see cref="VoiceMessage" />.
/// </summary>
public VoiceMessage VoiceMessage { get; set; }

/// <summary>
/// Gets the <see cref="Sender"/>'s <see cref="VoiceModuleBase" />.
/// </summary>
public VoiceModuleBase VoiceModule { get; }

/// <summary>
/// Gets or sets a value indicating whether the player can receive the voice message.
/// </summary>
public bool IsAllowed { get; set; } = true;
}
}
19 changes: 13 additions & 6 deletions EXILED/Exiled.Events/EventArgs/Player/TransmittingEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace Exiled.Events.EventArgs.Player

using PlayerRoles.Voice;

using VoiceChat.Networking;

/// <summary>
/// Contains all information regarding the player using the radio.
/// </summary>
Expand All @@ -23,24 +25,29 @@ public class TransmittingEventArgs : IPlayerEvent, IDeniableEvent
/// <param name="player">
/// <inheritdoc cref="Player" />
/// </param>
/// <param name="voiceMessage">
/// <inheritdoc cref="VoiceMessage" />
/// </param>
/// <param name="voiceModule">
/// <inheritdoc cref="VoiceModule" />
/// </param>
/// <param name="isAllowed">
/// <inheritdoc cref="IsAllowed" />
/// </param>
public TransmittingEventArgs(Player player, VoiceModuleBase voiceModule, bool isAllowed = true)
public TransmittingEventArgs(Player player, VoiceMessage voiceMessage, VoiceModuleBase voiceModule)
{
Player = player;
VoiceMessage = voiceMessage;
VoiceModule = voiceModule;
IsAllowed = isAllowed;
}

/// <summary>
/// Gets the player who's transmitting.
/// </summary>
public Player Player { get; }

/// <summary>
/// Gets or sets the <see cref="Player"/>'s <see cref="VoiceMessage" />.
/// </summary>
public VoiceMessage VoiceMessage { get; set; }

/// <summary>
/// Gets the <see cref="Player"/>'s <see cref="VoiceModuleBase" />.
/// </summary>
Expand All @@ -49,6 +56,6 @@ public TransmittingEventArgs(Player player, VoiceModuleBase voiceModule, bool is
/// <summary>
/// Gets or sets a value indicating whether the player can transmit.
/// </summary>
public bool IsAllowed { get; set; }
public bool IsAllowed { get; set; } = true;
}
}
12 changes: 4 additions & 8 deletions EXILED/Exiled.Events/EventArgs/Player/VoiceChattingEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,17 @@ public class VoiceChattingEventArgs : IPlayerEvent, IDeniableEvent
/// <param name="player">
/// <inheritdoc cref="Player" />
/// </param>
/// <param name="voiceMessage">
/// <inheritdoc cref="VoiceMessage" />
/// </param>
/// <param name="voiceModule">
/// <inheritdoc cref="VoiceModule" />
/// </param>
/// <param name="isAllowed">
/// <inheritdoc cref="IsAllowed" />
/// <param name="voiceMessage">
/// <inheritdoc cref="VoiceMessage" />
/// </param>
public VoiceChattingEventArgs(Player player, VoiceMessage voiceMessage, VoiceModuleBase voiceModule, bool isAllowed = true)
public VoiceChattingEventArgs(Player player, VoiceModuleBase voiceModule, VoiceMessage voiceMessage)
{
Player = player;
VoiceMessage = voiceMessage;
VoiceModule = voiceModule;
IsAllowed = isAllowed;
}

/// <summary>
Expand All @@ -60,6 +56,6 @@ public VoiceChattingEventArgs(Player player, VoiceMessage voiceMessage, VoiceMod
/// <summary>
/// Gets or sets a value indicating whether the player can voicechat.
/// </summary>
public bool IsAllowed { get; set; }
public bool IsAllowed { get; set; } = true;
}
}
15 changes: 9 additions & 6 deletions EXILED/Exiled.Events/Features/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ private record AsyncRegistration(CustomAsyncEventHandler handler, int priority);

private readonly List<AsyncRegistration> innerAsyncEvent = new();

private bool patched;

/// <summary>
/// Initializes a new instance of the <see cref="Event"/> class.
/// </summary>
Expand All @@ -60,6 +58,11 @@ public Event()
/// </summary>
public static IReadOnlyList<Event> List => EventsValue;

/// <summary>
/// Gets a value indicating whether the Harmony patch for this event has been applied.
/// </summary>
public bool Patched { get; private set; } = !Events.Instance.Config.UseDynamicPatching;

/// <summary>
/// Subscribes a <see cref="CustomEventHandler"/> to the inner event, and checks patches if dynamic patching is enabled.
/// </summary>
Expand Down Expand Up @@ -124,10 +127,10 @@ public void Subscribe(CustomEventHandler handler, int priority)
{
Log.Assert(Events.Instance is not null, $"{nameof(Events.Instance)} is null, please ensure you have exiled_events enabled!");

if (Events.Instance.Config.UseDynamicPatching && !patched)
if (Events.Instance.Config.UseDynamicPatching && !Patched)
{
Events.Instance.Patcher.Patch(this);
patched = true;
Patched = true;
}

if (handler == null)
Expand Down Expand Up @@ -163,10 +166,10 @@ public void Subscribe(CustomAsyncEventHandler handler, int priority)
{
Log.Assert(Events.Instance is not null, $"{nameof(Events.Instance)} is null, please ensure you have exiled_events enabled!");

if (Events.Instance.Config.UseDynamicPatching && !patched)
if (Events.Instance.Config.UseDynamicPatching && !Patched)
{
Events.Instance.Patcher.Patch(this);
patched = true;
Patched = true;
}

if (handler == null)
Expand Down
17 changes: 10 additions & 7 deletions EXILED/Exiled.Events/Features/Event{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ private record AsyncRegistration(CustomAsyncEventHandler<T> handler, int priorit

private readonly List<AsyncRegistration> innerAsyncEvent = new();

private bool patched;

/// <summary>
/// Initializes a new instance of the <see cref="Event{T}"/> class.
/// </summary>
Expand All @@ -65,6 +63,11 @@ public Event()
/// </summary>
public static IReadOnlyDictionary<Type, Event<T>> Dictionary => TypeToEvent;

/// <summary>
/// Gets a value indicating whether the Harmony patch for this event has been applied.
/// </summary>
public bool Patched { get; private set; } = !Events.Instance.Config.UseDynamicPatching;

/// <summary>
/// Subscribes a target <see cref="CustomEventHandler{TEventArgs}"/> to the inner event and checks if patching is possible, if dynamic patching is enabled.
/// </summary>
Expand Down Expand Up @@ -129,10 +132,10 @@ public void Subscribe(CustomEventHandler<T> handler, int priority)
{
Log.Assert(Events.Instance is not null, $"{nameof(Events.Instance)} is null, please ensure you have exiled_events enabled!");

if (Events.Instance.Config.UseDynamicPatching && !patched)
if (Events.Instance.Config.UseDynamicPatching && !Patched)
{
Events.Instance.Patcher.Patch(this);
patched = true;
Patched = true;
}

if (handler == null)
Expand Down Expand Up @@ -168,10 +171,10 @@ public void Subscribe(CustomAsyncEventHandler<T> handler, int priority)
{
Log.Assert(Events.Instance is not null, $"{nameof(Events.Instance)} is null, please ensure you have exiled_events enabled!");

if (Events.Instance.Config.UseDynamicPatching && !patched)
if (Events.Instance.Config.UseDynamicPatching && !Patched)
{
Events.Instance.Patcher.Patch(this);
patched = true;
Patched = true;
}

if (handler == null)
Expand Down Expand Up @@ -296,4 +299,4 @@ internal void InvokeAsync(T arg)
}
}
}
}
}
17 changes: 17 additions & 0 deletions EXILED/Exiled.Events/Handlers/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,11 @@ public class Player
/// </summary>
public static Event<VoiceChattingEventArgs> VoiceChatting { get; set; } = new();

/// <summary>
/// Invoked before a <see cref="API.Features.Player"/> receives a voice message.
/// </summary>
public static Event<ReceivingVoiceMessageEventArgs> ReceivingVoiceMessage { get; set; } = new();

/// <summary>
/// Invoked before a <see cref="API.Features.Player"/> makes noise.
/// </summary>
Expand Down Expand Up @@ -897,6 +902,9 @@ public class Player
/// <param name="ev">The <see cref="ReloadingWeaponEventArgs"/> instance.</param>
public static void OnReloadingWeapon(PlayerReloadingWeaponEventArgs ev)
{
if (!ReloadingWeapon.Patched)
return;

ReloadingWeaponEventArgs exiledEv = new(ev.FirearmItem.Base, ev.IsAllowed);
ReloadingWeapon.InvokeSafely(exiledEv);
ev.IsAllowed = exiledEv.IsAllowed;
Expand Down Expand Up @@ -1010,6 +1018,9 @@ public static void OnReloadingWeapon(PlayerReloadingWeaponEventArgs ev)
/// <param name="ev">The <see cref="UnloadingWeaponEventArgs"/> instance.</param>
public static void OnUnloadingWeapon(PlayerUnloadingWeaponEventArgs ev)
{
if (!UnloadingWeapon.Patched)
return;

UnloadingWeaponEventArgs exiledEv = new(ev.FirearmItem.Base, ev.IsAllowed);
UnloadingWeapon.InvokeSafely(exiledEv);
ev.IsAllowed = exiledEv.IsAllowed;
Expand Down Expand Up @@ -1045,6 +1056,12 @@ public static void OnUnloadingWeapon(PlayerUnloadingWeaponEventArgs ev)
/// <param name="ev">The <see cref="VoiceChattingEventArgs"/> instance.</param>
public static void OnVoiceChatting(VoiceChattingEventArgs ev) => VoiceChatting.InvokeSafely(ev);

/// <summary>
/// Invoked before a <see cref="API.Features.Player"/> receives a voice message.
/// </summary>
/// <param name="ev">The <see cref="ReceivingVoiceMessageEventArgs"/> instance.</param>
public static void OnReceivingVoiceMessage(ReceivingVoiceMessageEventArgs ev) => ReceivingVoiceMessage.InvokeSafely(ev);

/// <summary>
/// Called before a <see cref="API.Features.Player"/> makes noise.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions EXILED/Exiled.Events/Handlers/Scp127.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public static class Scp127
/// <param name="ev">The <see cref="Scp127TalkingEventArgs"/> instance.</param>
public static void OnTalking(Scp127TalkingEventArgs ev)
{
if (!Talking.Patched)
return;

TalkingEventArgs eventArgs = new(API.Features.Items.Item.Get<API.Features.Items.Scp127>(ev.Scp127Item.Base), ev.VoiceLine, ev.Priority, ev.IsAllowed);
Talking.InvokeSafely(eventArgs);

Expand All @@ -64,6 +67,9 @@ public static void OnTalked(Scp127TalkedEventArgs ev)
/// <param name="ev">The <see cref="Scp127GainingExperienceEventArgs"/> instance.</param>
public static void OnGainingExperience(Scp127GainingExperienceEventArgs ev)
{
if (!GainingExperience.Patched)
return;

GainingExperienceEventArgs eventArgs = new(API.Features.Items.Item.Get<API.Features.Items.Scp127>(ev.Scp127Item.Base), ev.ExperienceGain, ev.IsAllowed);
GainingExperience.InvokeSafely(eventArgs);

Expand Down
Loading
Loading