Skip to content

Commit 3f404c9

Browse files
committed
new ev + previous role
1 parent 81c3652 commit 3f404c9

File tree

4 files changed

+83
-5
lines changed

4 files changed

+83
-5
lines changed

EXILED/Exiled.API/Features/Player.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,9 +577,18 @@ public PlayerPermissions RemoteAdminPermissions
577577
public Role Role
578578
{
579579
get => role ??= Role.Create(RoleManager.CurrentRole);
580-
internal set => role = value;
580+
internal set
581+
{
582+
PreviousRole = role;
583+
role = value;
584+
}
581585
}
582586

587+
/// <summary>
588+
/// Gets the role that player had before changing role.
589+
/// </summary>
590+
public Role PreviousRole { get; private set; }
591+
583592
/// <summary>
584593
/// Gets or sets the player's SCP preferences.
585594
/// </summary>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// -----------------------------------------------------------------------
2+
// <copyright file="EscapedEventArgs.cs" company="Exiled Team">
3+
// Copyright (c) Exiled Team. All rights reserved.
4+
// Licensed under the CC BY-SA 3.0 license.
5+
// </copyright>
6+
// -----------------------------------------------------------------------
7+
8+
namespace Exiled.Events.EventArgs.Player
9+
{
10+
using Exiled.API.Enums;
11+
using Exiled.API.Features;
12+
using Exiled.Events.EventArgs.Interfaces;
13+
14+
/// <summary>
15+
/// Contains all information after player has escaped.
16+
/// </summary>
17+
public class EscapedEventArgs : IPlayerEvent
18+
{
19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="EscapedEventArgs"/> class.
21+
/// </summary>
22+
/// <param name="player"><inheritdoc cref="Player"/></param>
23+
/// <param name="escapeScenario"><inheritdoc cref="EscapeScenario"/></param>
24+
public EscapedEventArgs(Player player, EscapeScenario escapeScenario)
25+
{
26+
Player = player;
27+
EscapeScenario = escapeScenario;
28+
}
29+
30+
/// <inheritdoc/>
31+
public Player Player { get; }
32+
33+
/// <summary>
34+
/// Gets the type of escape.
35+
/// </summary>
36+
public EscapeScenario EscapeScenario { get; }
37+
}
38+
}

EXILED/Exiled.Events/Handlers/Player.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ public class Player
228228
/// </summary>
229229
public static Event<EscapingEventArgs> Escaping { get; set; } = new();
230230

231+
/// <summary>
232+
/// Invoked after a <see cref="API.Features.Player"/> escapes.
233+
/// </summary>
234+
public static Event<EscapedEventArgs> Escaped { get; set; } = new();
235+
231236
/// <summary>
232237
/// Invoked before a <see cref="API.Features.Player"/> begins speaking to the intercom.
233238
/// </summary>
@@ -710,6 +715,12 @@ public class Player
710715
/// <param name="ev">The <see cref="EscapingEventArgs"/> instance.</param>
711716
public static void OnEscaping(EscapingEventArgs ev) => Escaping.InvokeSafely(ev);
712717

718+
/// <summary>
719+
/// Called after a <see cref="API.Features.Player"/> escapes.
720+
/// </summary>
721+
/// <param name="ev">The <see cref="EscapedEventArgs"/> instance.</param>
722+
public static void OnEscaped(EscapedEventArgs ev) => Escaped.InvokeSafely(ev);
723+
713724
/// <summary>
714725
/// Called before a <see cref="API.Features.Player"/> begins speaking to the intercom.
715726
/// </summary>

EXILED/Exiled.Events/Patches/Events/Player/Escaping.cs renamed to EXILED/Exiled.Events/Patches/Events/Player/EscapingAndEscaped.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// -----------------------------------------------------------------------
2-
// <copyright file="Escaping.cs" company="Exiled Team">
2+
// <copyright file="EscapingAndEscaped.cs" company="Exiled Team">
33
// Copyright (c) Exiled Team. All rights reserved.
44
// Licensed under the CC BY-SA 3.0 license.
55
// </copyright>
@@ -29,11 +29,12 @@ namespace Exiled.Events.Patches.Events.Player
2929
using static HarmonyLib.AccessTools;
3030

3131
/// <summary>
32-
/// Patches <see cref="Escape.ServerHandlePlayer(ReferenceHub)"/> for <see cref="Handlers.Player.Escaping" />.
32+
/// Patches <see cref="Escape.ServerHandlePlayer(ReferenceHub)"/> for <see cref="Handlers.Player.Escaping" /> and <see cref="Handlers.Player.Escaped"/>.
3333
/// </summary>
3434
[EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.Escaping))]
35+
[EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.Escaped))]
3536
[HarmonyPatch(typeof(Escape), nameof(Escape.ServerHandlePlayer))]
36-
internal static class Escaping
37+
internal static class EscapingAndEscaped
3738
{
3839
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
3940
{
@@ -98,9 +99,28 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
9899
{
99100
// GrantAllTickets(ev)
100101
new CodeInstruction(OpCodes.Ldloc, ev.LocalIndex).WithLabels(labels),
101-
new(OpCodes.Call, Method(typeof(Escaping), nameof(GrantAllTickets))),
102+
new(OpCodes.Call, Method(typeof(EscapingAndEscaped), nameof(GrantAllTickets))),
102103
});
103104

105+
newInstructions.InsertRange(newInstructions.Count - 1, new CodeInstruction[]
106+
{
107+
// loading EscapingEventArgs instance 2 times
108+
new(OpCodes.Ldloc_S, ev.LocalIndex),
109+
new(OpCodes.Ldloc_S, ev.LocalIndex),
110+
111+
// ev.Player
112+
new(OpCodes.Callvirt, PropertyGetter(typeof(EscapingEventArgs), nameof(EscapingEventArgs.Player))),
113+
114+
// ev.EscapeScenario
115+
new(OpCodes.Callvirt, PropertyGetter(typeof(EscapingEventArgs), nameof(EscapingEventArgs.EscapeScenario))),
116+
117+
// EscapedEventArgs ev2 = new(ev.Player, ev.EscapeScenario);
118+
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(EscapedEventArgs))[0]),
119+
120+
// Handlers.Player.OnEscaped(ev);
121+
new(OpCodes.Call, Method(typeof(Handlers.Player), nameof(Handlers.Player.OnEscaped))),
122+
});
123+
104124
newInstructions[newInstructions.Count - 1].WithLabels(returnLabel);
105125

106126
for (int z = 0; z < newInstructions.Count; z++)

0 commit comments

Comments
 (0)