forked from Exiled-Official/EXILED
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: PR 133 / Added Scp079 Signal Event (#400)
Squashed PR 133:
- Loading branch information
Showing
6 changed files
with
190 additions
and
123 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
EXILED/Exiled.Events/EventArgs/Scp079/LosingSignalEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="LosingSignalEventArgs.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.Scp079 | ||
{ | ||
using Exiled.API.Features; | ||
using Exiled.Events.EventArgs.Interfaces; | ||
|
||
/// <summary> | ||
/// Contains all information before SCP-079 loses a signal by SCP-2176. | ||
/// </summary> | ||
public class LosingSignalEventArgs : IScp079Event, IDeniableEvent | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="LosingSignalEventArgs" /> class. | ||
/// </summary> | ||
/// <param name="player"> | ||
/// <inheritdoc cref="Player" /> | ||
/// </param> | ||
public LosingSignalEventArgs(ReferenceHub player) | ||
{ | ||
Player = Player.Get(player); | ||
Scp079 = Player.Role.As<API.Features.Roles.Scp079Role>(); | ||
IsAllowed = true; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the player who's controlling SCP-079. | ||
/// </summary> | ||
public Player Player { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether or not SCP-079 will lose his signal. | ||
/// </summary> | ||
public bool IsAllowed { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public API.Features.Roles.Scp079Role Scp079 { get; } | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
EXILED/Exiled.Events/EventArgs/Scp079/LostSignalEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="LostSignalEventArgs.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.Scp079 | ||
{ | ||
using Exiled.API.Features; | ||
using Exiled.Events.EventArgs.Interfaces; | ||
|
||
/// <summary> | ||
/// Contains all information before SCP-079 loses a signal by SCP-2176. | ||
/// </summary> | ||
public class LostSignalEventArgs : IScp079Event | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="LostSignalEventArgs" /> class. | ||
/// </summary> | ||
/// <param name="player"> | ||
/// <inheritdoc cref="Player" /> | ||
/// </param> | ||
public LostSignalEventArgs(ReferenceHub player) | ||
{ | ||
Player = Player.Get(player); | ||
Scp079 = Player.Role.As<API.Features.Roles.Scp079Role>(); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the player who's controlling SCP-079. | ||
/// </summary> | ||
public Player Player { get; } | ||
|
||
/// <inheritdoc/> | ||
public API.Features.Roles.Scp079Role Scp079 { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +0,0 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="StartingSpeakerEventArgs.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.Scp079 | ||
{ | ||
using Exiled.API.Features; | ||
using Exiled.API.Features.Roles; | ||
using Exiled.Events.EventArgs.Interfaces; | ||
|
||
/// <summary> | ||
/// Contains all information before SCP-079 uses a speaker. | ||
/// </summary> | ||
public class StartingSpeakerEventArgs : IScp079Event, IDeniableEvent | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="StartingSpeakerEventArgs" /> class. | ||
/// </summary> | ||
/// <param name="player"> | ||
/// <inheritdoc cref="Player" /> | ||
/// </param> | ||
/// <param name="room"> | ||
/// <inheritdoc cref="Room" /> | ||
/// </param> | ||
/// <param name="auxiliaryPowerCost"> | ||
/// <inheritdoc cref="AuxiliaryPowerCost" /> | ||
/// </param> | ||
/// <param name="isAllowed"> | ||
/// <inheritdoc cref="IsAllowed" /> | ||
/// </param> | ||
public StartingSpeakerEventArgs(Player player, Room room, float auxiliaryPowerCost, bool isAllowed = true) | ||
{ | ||
Player = player; | ||
Scp079 = player.Role.As<Scp079Role>(); | ||
Room = room; | ||
AuxiliaryPowerCost = auxiliaryPowerCost; | ||
IsAllowed = isAllowed; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the player who's controlling SCP-079. | ||
/// </summary> | ||
public Player Player { get; } | ||
|
||
/// <inheritdoc/> | ||
public Scp079Role Scp079 { get; } | ||
|
||
/// <summary> | ||
/// Gets the room that the speaker is located in. | ||
/// </summary> | ||
public Room Room { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets the amount of auxiliary power required to use a speaker through SCP-079. | ||
/// </summary> | ||
public float AuxiliaryPowerCost { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether SCP-079 can use the speaker. | ||
/// </summary> | ||
public bool IsAllowed { get; set; } | ||
} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +0,0 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="StoppingSpeakerEventArgs.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.Scp079 | ||
{ | ||
using Exiled.API.Features; | ||
using Exiled.API.Features.Roles; | ||
using Exiled.Events.EventArgs.Interfaces; | ||
|
||
/// <summary> | ||
/// Contains all information before SCP-079 finishes using a speaker. | ||
/// </summary> | ||
public class StoppingSpeakerEventArgs : IScp079Event, IDeniableEvent | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="StoppingSpeakerEventArgs" /> class. | ||
/// </summary> | ||
/// <param name="player"> | ||
/// <inheritdoc cref="Player" /> | ||
/// </param> | ||
/// <param name="room"> | ||
/// <inheritdoc cref="Room" /> | ||
/// </param> | ||
/// <param name="isAllowed"> | ||
/// <inheritdoc cref="IsAllowed" /> | ||
/// </param> | ||
public StoppingSpeakerEventArgs(Player player, Room room, bool isAllowed = true) | ||
{ | ||
Player = player; | ||
Scp079 = player.Role.As<Scp079Role>(); | ||
Room = room; | ||
IsAllowed = isAllowed; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the player who's controlling SCP-079. | ||
/// </summary> | ||
public Player Player { get; } | ||
|
||
/// <inheritdoc/> | ||
public Scp079Role Scp079 { get; } | ||
|
||
/// <summary> | ||
/// Gets the room that the speaker is located in. | ||
/// </summary> | ||
public Room Room { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether SCP-079 can stop using the speaker. | ||
/// </summary> | ||
public bool IsAllowed { get; set; } | ||
} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="Lost.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.Scp079 | ||
{ | ||
using System.Collections.Generic; | ||
using System.Reflection.Emit; | ||
|
||
using API.Features.Pools; | ||
using Exiled.Events.Attributes; | ||
using Exiled.Events.EventArgs.Scp079; | ||
using Exiled.Events.Handlers; | ||
|
||
using HarmonyLib; | ||
|
||
using PlayerRoles; | ||
using PlayerRoles.PlayableScps.Scp079; | ||
|
||
using static HarmonyLib.AccessTools; | ||
|
||
/// <summary> | ||
/// Patches <see cref="Scp079LostSignalHandler.ServerLoseSignal(float)" />. | ||
/// Adds the <see cref="Scp079.LosingSignal" /> and <see cref="Scp079.LostSignal"/> event. | ||
/// </summary> | ||
[EventPatch(typeof(Scp079), nameof(Scp079.LosingSignal))] | ||
[EventPatch(typeof(Scp079), nameof(Scp079.LostSignal))] | ||
[HarmonyPatch(typeof(Scp079LostSignalHandler), nameof(Scp079LostSignalHandler.ServerLoseSignal))] | ||
internal static class Lost | ||
{ | ||
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) | ||
{ | ||
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions); | ||
|
||
Label ret = generator.DefineLabel(); | ||
|
||
newInstructions.InsertRange( | ||
0, | ||
new[] | ||
{ | ||
// Role._lastOwner | ||
new CodeInstruction(OpCodes.Ldarg_0), | ||
new(OpCodes.Callvirt, PropertyGetter(typeof(Scp079LostSignalHandler), nameof(Scp079LostSignalHandler.Role))), | ||
new(OpCodes.Ldfld, Field(typeof(PlayerRoleBase), nameof(PlayerRoleBase._lastOwner))), | ||
|
||
// LosingSignalEventArgs ev = new(Role._lastOwner) | ||
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(LosingSignalEventArgs))[0]), | ||
new(OpCodes.Dup), | ||
|
||
// Scp079.OnLosingSignal(ev) | ||
new(OpCodes.Call, Method(typeof(Scp079), nameof(Scp079.OnLosingSignal))), | ||
|
||
// if (!ev.IsAllowed) | ||
// return; | ||
new(OpCodes.Callvirt, PropertyGetter(typeof(LosingSignalEventArgs), nameof(LosingSignalEventArgs.IsAllowed))), | ||
new(OpCodes.Brfalse_S, ret), | ||
}); | ||
|
||
newInstructions.InsertRange( | ||
newInstructions.Count - 1, | ||
new[] | ||
{ | ||
// Role._lastOwner | ||
new CodeInstruction(OpCodes.Ldarg_0), | ||
new(OpCodes.Callvirt, PropertyGetter(typeof(Scp079LostSignalHandler), nameof(Scp079LostSignalHandler.Role))), | ||
new(OpCodes.Ldfld, Field(typeof(PlayerRoleBase), nameof(PlayerRoleBase._lastOwner))), | ||
|
||
// LostSignalEventArgs ev = new(Role._lastOwner) | ||
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(LostSignalEventArgs))[0]), | ||
|
||
// Scp079.OnLosingSignal(ev) | ||
new(OpCodes.Call, Method(typeof(Scp079), nameof(Scp079.OnLostSignal))), | ||
}); | ||
|
||
newInstructions[newInstructions.Count - 1].labels.Add(ret); | ||
|
||
for (int z = 0; z < newInstructions.Count; z++) | ||
yield return newInstructions[z]; | ||
|
||
ListPool<CodeInstruction>.Pool.Return(newInstructions); | ||
} | ||
} | ||
} |