Skip to content

Commit

Permalink
Revert "[Exiled::Events] [Exiled::API] New event + new property (E…
Browse files Browse the repository at this point in the history
…xMod-Team#31)"

This reverts commit 043d9a9.
  • Loading branch information
louis1706 committed Nov 17, 2024
1 parent ef20dea commit d8fa348
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 136 deletions.
11 changes: 1 addition & 10 deletions EXILED/Exiled.API/Features/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -589,18 +589,9 @@ public PlayerPermissions RemoteAdminPermissions
public Role Role
{
get => role ??= Role.Create(RoleManager.CurrentRole);
internal set
{
PreviousRole = role.Type;
role = value;
}
internal set => role = value;
}

/// <summary>
/// Gets the role that player had before changing role.
/// </summary>
public RoleTypeId PreviousRole { get; private set; }

/// <summary>
/// Gets or sets the player's SCP preferences.
/// </summary>
Expand Down
70 changes: 0 additions & 70 deletions EXILED/Exiled.Events/EventArgs/Player/EscapedEventArgs.cs

This file was deleted.

11 changes: 0 additions & 11 deletions EXILED/Exiled.Events/Handlers/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,6 @@ public class Player
/// </summary>
public static Event<EscapingEventArgs> Escaping { get; set; } = new();

/// <summary>
/// Invoked after a <see cref="API.Features.Player"/> escapes.
/// </summary>
public static Event<EscapedEventArgs> Escaped { get; set; } = new();

/// <summary>
/// Invoked before a <see cref="API.Features.Player"/> begins speaking to the intercom.
/// </summary>
Expand Down Expand Up @@ -739,12 +734,6 @@ public class Player
/// <param name="ev">The <see cref="EscapingEventArgs"/> instance.</param>
public static void OnEscaping(EscapingEventArgs ev) => Escaping.InvokeSafely(ev);

/// <summary>
/// Called after a <see cref="API.Features.Player"/> escapes.
/// </summary>
/// <param name="ev">The <see cref="EscapedEventArgs"/> instance.</param>
public static void OnEscaped(EscapedEventArgs ev) => Escaped.InvokeSafely(ev);

/// <summary>
/// Called before a <see cref="API.Features.Player"/> begins speaking to the intercom.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// -----------------------------------------------------------------------
// <copyright file="EscapingAndEscaped.cs" company="Exiled Team">
// <copyright file="Escaping.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
Expand All @@ -8,7 +8,6 @@
namespace Exiled.Events.Patches.Events.Player
{
#pragma warning disable SA1402 // File may only contain a single type
#pragma warning disable IDE0060

using System;
using System.Collections.Generic;
Expand All @@ -19,8 +18,8 @@ namespace Exiled.Events.Patches.Events.Player
using API.Enums;
using API.Features;
using API.Features.Pools;

using EventArgs.Player;
using Exiled.API.Features.Roles;
using Exiled.Events.Attributes;
using HarmonyLib;
using PlayerRoles.FirstPersonControl;
Expand All @@ -29,12 +28,11 @@ namespace Exiled.Events.Patches.Events.Player
using static HarmonyLib.AccessTools;

/// <summary>
/// Patches <see cref="Escape.ServerHandlePlayer(ReferenceHub)"/> for <see cref="Handlers.Player.Escaping" /> and <see cref="Handlers.Player.Escaped"/>.
/// Patches <see cref="Escape.ServerHandlePlayer(ReferenceHub)"/> for <see cref="Handlers.Player.Escaping" />.
/// </summary>
[EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.Escaping))]
[EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.Escaped))]
[HarmonyPatch(typeof(Escape), nameof(Escape.ServerHandlePlayer))]
internal static class EscapingAndEscaped
internal static class Escaping
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
Expand All @@ -44,7 +42,6 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
Label returnLabel = generator.DefineLabel();

LocalBuilder ev = generator.DeclareLocal(typeof(EscapingEventArgs));
LocalBuilder role = generator.DeclareLocal(typeof(Role));

int offset = -2;
int index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Newobj) + offset;
Expand Down Expand Up @@ -100,44 +97,9 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
{
// GrantAllTickets(ev)
new CodeInstruction(OpCodes.Ldloc, ev.LocalIndex).WithLabels(labels),
new(OpCodes.Call, Method(typeof(EscapingAndEscaped), nameof(GrantAllTickets))),
new(OpCodes.Call, Method(typeof(Escaping), nameof(GrantAllTickets))),
});

offset = 4;
index = newInstructions.FindIndex(x => x.Is(OpCodes.Stfld, Field(typeof(Escape.EscapeMessage), nameof(Escape.EscapeMessage.EscapeTime)))) + offset;

newInstructions.InsertRange(index, new CodeInstruction[]
{
// role = ev.Player.Role
new(OpCodes.Ldloc_S, ev.LocalIndex),
new(OpCodes.Callvirt, PropertyGetter(typeof(EscapingEventArgs), nameof(EscapingEventArgs.Player))),
new(OpCodes.Callvirt, PropertyGetter(typeof(Player), nameof(Player.Role))),
new(OpCodes.Stloc_S, role.LocalIndex),
});

newInstructions.InsertRange(newInstructions.Count - 1, new CodeInstruction[]
{
// ev.Player
new(OpCodes.Ldloc_S, ev.LocalIndex),
new(OpCodes.Callvirt, PropertyGetter(typeof(EscapingEventArgs), nameof(EscapingEventArgs.Player))),

// escapeScenario
new(OpCodes.Ldloc_1),

// role
new(OpCodes.Ldloc_S, role.LocalIndex),

// ev.RespawnTickets.Key
new(OpCodes.Ldloc_S, ev.LocalIndex),
new(OpCodes.Callvirt, PropertyGetter(typeof(EscapingEventArgs), nameof(EscapingEventArgs.RespawnTickets))),

// EscapedEventArgs ev2 = new(ev.Player, ev.EscapeScenario, role, float, SpawnableTeamType);
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(EscapedEventArgs))[0]),

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

newInstructions[newInstructions.Count - 1].WithLabels(returnLabel);

for (int z = 0; z < newInstructions.Count; z++)
Expand All @@ -158,7 +120,6 @@ private static void GrantAllTickets(EscapingEventArgs ev)
/// Replaces last returned <see cref="EscapeScenario.None"/> to <see cref="EscapeScenario.CustomEscape"/>.
/// </summary>
[EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.Escaping))]
[EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.Escaped))]
[HarmonyPatch(typeof(Escape), nameof(Escape.ServerGetScenario))]
internal static class GetScenario
{
Expand Down Expand Up @@ -190,4 +151,4 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
ListPool<CodeInstruction>.Pool.Return(newInstructions);
}
}
}
}

0 comments on commit d8fa348

Please sign in to comment.