Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// -----------------------------------------------------------------------
// <copyright file="Scp1576TransmissionEndedEventArgs.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 API.Features;
using API.Features.Items;
using Interfaces;
using InventorySystem.Items.Usables.Scp1576;

/// <summary>
/// Contains all information after a SCP-1576 transmission has ended.
/// </summary>
public class Scp1576TransmissionEndedEventArgs : IPlayerEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="Scp1576TransmissionEndedEventArgs"/> class.
/// </summary>
/// <param name="player"><inheritdoc cref="Player"/></param>
/// <param name="scp1576Item"><inheritdoc cref="Scp1576"/></param>
public Scp1576TransmissionEndedEventArgs(Player player, Scp1576Item scp1576Item)
{
Player = player;
Scp1576 = Item.Get<Scp1576>(scp1576Item);
}

/// <summary>
/// Gets the <see cref="Exiled.API.Features.Player"/> that the transmission ended for.
/// </summary>
public Player Player { get; }

/// <summary>
/// Gets the <see cref="Exiled.API.Features.Items.Scp1576"/> instance.
/// </summary>
public Exiled.API.Features.Items.Scp1576 Scp1576 { get; }
}
}
11 changes: 11 additions & 0 deletions EXILED/Exiled.Events/Handlers/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,11 @@ public class Player
/// </summary>
public static Event<InteractingEmergencyButtonEventArgs> InteractingEmergencyButton { get; set; } = new();

/// <summary>
/// Invoked after transmission has ended.
/// </summary>
public static Event<Scp1576TransmissionEndedEventArgs> Scp1576TransmissionEnded { get; set; } = new();

/// <summary>
/// Called before a player's emotion changed.
/// </summary>
Expand Down Expand Up @@ -1356,5 +1361,11 @@ public static void OnItemRemoved(ReferenceHub referenceHub, InventorySystem.Item
/// </summary>
/// <param name="ev">The <see cref="InteractingEmergencyButtonEventArgs"/> instance.</param>
public static void OnInteractingEmergencyButton(InteractingEmergencyButtonEventArgs ev) => InteractingEmergencyButton.InvokeSafely(ev);

/// <summary>
/// Called after a 1576 transmisiion has ended.
/// </summary>
/// <param name="ev">The <see cref="Scp1576TransmissionEndedEventArgs"/> instance.</param>
public static void OnScp1576TransmissionEnded(Scp1576TransmissionEndedEventArgs ev) => Scp1576TransmissionEnded.InvokeSafely(ev);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// -----------------------------------------------------------------------
// <copyright file="Scp1576TransmissionEnded.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.Events.Patches.Events.Player
{
using System.Collections.Generic;
using System.Reflection.Emit;

using Exiled.API.Features.Pools;
using Exiled.Events.Attributes;
using Exiled.Events.EventArgs.Player;
using HarmonyLib;
using InventorySystem.Items.Usables.Scp1576;

using static HarmonyLib.AccessTools;

/// <summary>
/// Patches <see cref="Scp1576Item.ServerStopTransmitting"/> to add <see cref="Handlers.Player.Scp1576TransmissionEnded"/> event.
/// </summary>
[EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.Scp1576TransmissionEnded))]
[HarmonyPatch(typeof(InventorySystem.Items.Usables.Scp1576.Scp1576Item), nameof(Scp1576Item.ServerStopTransmitting))]
public class Scp1576TransmissionEnded
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

int index = newInstructions.Count - 1;

newInstructions.InsertRange(
index,
new[]
{
// Player.Get(base.Owner)
new CodeInstruction(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Callvirt, PropertyGetter(typeof(Scp1576Item), nameof(Scp1576Item.Owner))),
new CodeInstruction(OpCodes.Call, Method(typeof(API.Features.Player), nameof(API.Features.Player.Get), new[] { typeof(ReferenceHub) })),

// this
new CodeInstruction(OpCodes.Ldarg_0),

// Scp1576TransmissionEndedEventArgs ev = new(Player, this)
new CodeInstruction(OpCodes.Newobj, GetDeclaredConstructors(typeof(Scp1576TransmissionEndedEventArgs))[0]),

// OnScp1576TransmissionEnded(ev)
new CodeInstruction(OpCodes.Call, Method(typeof(Handlers.Player), nameof(Handlers.Player.OnScp1576TransmissionEnded))),
});

for (int i = 0; i < newInstructions.Count; i++)
yield return newInstructions[i];

ListPool<CodeInstruction>.Pool.Return(newInstructions);
}
}
}
Loading