Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Event StartingRecallEventArgs's IsAllowed issue. #2235

Merged
merged 21 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
130 changes: 65 additions & 65 deletions Exiled.Events/EventArgs/Scp049/StartingRecallEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,66 +1,66 @@
// -----------------------------------------------------------------------
// <copyright file="StartingRecallEventArgs.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.Events.EventArgs.Scp049
{
using API.Features;
using Exiled.API.Features.Roles;
using Interfaces;

/// <summary>
/// Contains all information before SCP-049 begins recalling a player.
/// </summary>
public class StartingRecallEventArgs : IScp049Event, IRagdollEvent, IDeniableEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="StartingRecallEventArgs" /> class.
/// </summary>
/// <param name="target">
/// <inheritdoc cref="Target" />
/// </param>
/// <param name="scp049">
/// <inheritdoc cref="Player" />
/// </param>
/// <param name="ragdoll">
/// <inheritdoc cref="Ragdoll" />
/// </param>
/// <param name="isAllowed">
/// <inheritdoc cref="IsAllowed" />
/// </param>
public StartingRecallEventArgs(Player target, Player scp049, Ragdoll ragdoll, bool isAllowed = true)
{
Target = target;
Player = scp049;
Scp049 = scp049.Role.As<Scp049Role>();
Ragdoll = ragdoll;
IsAllowed = isAllowed;
}

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

/// <summary>
/// Gets or sets a value indicating whether the recall can begin.
/// </summary>
public bool IsAllowed { get; set; }

/// <summary>
/// Gets the player who is controlling SCP-049.
/// </summary>
public Player Player { get; }

/// <inheritdoc/>
public Scp049Role Scp049 { get; }

/// <summary>
/// Gets the Ragdoll who's getting recalled.
/// </summary>
public Ragdoll Ragdoll { get; }
}
// -----------------------------------------------------------------------
// <copyright file="StartingRecallEventArgs.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------
namespace Exiled.Events.EventArgs.Scp049
{
using API.Features;
using Exiled.API.Features.Roles;
using Interfaces;
/// <summary>
/// Contains all information before SCP-049 begins recalling a player.
/// </summary>
public class StartingRecallEventArgs : IScp049Event, IRagdollEvent, IDeniableEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="StartingRecallEventArgs" /> class.
/// </summary>
/// <param name="target">
/// <inheritdoc cref="Target" />
/// </param>
/// <param name="scp049">
/// <inheritdoc cref="Player" />
/// </param>
/// <param name="ragdoll">
/// <inheritdoc cref="Ragdoll" />
/// </param>
/// <param name="isAllowed">
/// <inheritdoc cref="IsAllowed" />
/// </param>
public StartingRecallEventArgs(Player player, Ragdoll ragdoll, bool isAllowed = true)

Check failure on line 34 in Exiled.Events/EventArgs/Scp049/StartingRecallEventArgs.cs

View workflow job for this annotation

GitHub Actions / build

{
Ragdoll = ragdoll;
Target = Ragdoll.Owner;

Check failure on line 38 in Exiled.Events/EventArgs/Scp049/StartingRecallEventArgs.cs

View workflow job for this annotation

GitHub Actions / build

Scp049 = player.Role.As<Scp049Role>();

Check failure on line 39 in Exiled.Events/EventArgs/Scp049/StartingRecallEventArgs.cs

View workflow job for this annotation

GitHub Actions / build

Check failure on line 39 in Exiled.Events/EventArgs/Scp049/StartingRecallEventArgs.cs

View workflow job for this annotation

GitHub Actions / build

Player = player;
IsAllowed = isAllowed;
}

Check failure on line 42 in Exiled.Events/EventArgs/Scp049/StartingRecallEventArgs.cs

View workflow job for this annotation

GitHub Actions / build

/// <summary>

Check failure on line 43 in Exiled.Events/EventArgs/Scp049/StartingRecallEventArgs.cs

View workflow job for this annotation

GitHub Actions / build

Element documentation header should be preceded by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1514.md)
/// Gets the player who's getting recalled.
/// </summary>
public Player Target { get; }
/// <summary>
/// Gets or sets a value indicating whether the recall can begin.
/// </summary>
public bool IsAllowed { get; set; }
/// <summary>
/// Gets the player who is controlling SCP-049.
/// </summary>
public Player Player { get; }
/// <inheritdoc/>
public Scp049Role Scp049 { get; }
/// <summary>
/// Gets the Ragdoll who's getting recalled.
/// </summary>
public Ragdoll Ragdoll { get; }
}
}
159 changes: 80 additions & 79 deletions Exiled.Events/Patches/Events/Scp049/StartingRecall.cs
Original file line number Diff line number Diff line change
@@ -1,79 +1,80 @@
// -----------------------------------------------------------------------
// <copyright file="StartingRecall.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

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

using API.Features;
using API.Features.Pools;
using Exiled.Events.Attributes;
using Exiled.Events.EventArgs.Scp049;

using HarmonyLib;

using PlayerRoles.PlayableScps.Scp049;
using PlayerRoles.Ragdolls;

using static HarmonyLib.AccessTools;

/// <summary>
/// Patches <see cref="Scp049ResurrectAbility.ServerValidateBegin" />.
/// Adds the <see cref="Handlers.Scp049.StartingRecall" /> event.
/// </summary>
[EventPatch(typeof(Handlers.Scp049), nameof(Handlers.Scp049.StartingRecall))]
[HarmonyPatch(typeof(Scp049ResurrectAbility), nameof(Scp049ResurrectAbility.ServerValidateBegin))]
internal static class StartingRecall
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

Label retLabel = generator.DefineLabel();

newInstructions.InsertRange(0, new CodeInstruction[]
{
// Player target = Player.Get(ragdoll.Info.OwnerHub);
new(OpCodes.Ldarg_1),
new(OpCodes.Ldfld, Field(typeof(BasicRagdoll), nameof(BasicRagdoll.Info))),
new(OpCodes.Ldfld, Field(typeof(RagdollData), nameof(RagdollData.OwnerHub))),
new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),

// Player player = Player.Get(this.Owner);
new(OpCodes.Ldarg_0),
new(OpCodes.Callvirt, PropertyGetter(typeof(Scp049ResurrectAbility), nameof(Scp049ResurrectAbility.Owner))),
new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),

// Ragdoll doll = Rangdoll.Get(ragdoll);
new(OpCodes.Ldarg_1),
new(OpCodes.Call, Method(typeof(Ragdoll), nameof(Ragdoll.Get), new[] { typeof(BasicRagdoll) })),

// true
new(OpCodes.Ldc_I4_1),

// StartingRecallEventArgs ev = new(target, player, doll, true);
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(StartingRecallEventArgs))[0]),
new(OpCodes.Dup),

// Handlers.Scp049.OnStartingRecall(ev);
new(OpCodes.Call, Method(typeof(Handlers.Scp049), nameof(Handlers.Scp049.OnStartingRecall))),

// if (!ev.IsAllowed)
// return;
new(OpCodes.Callvirt, PropertyGetter(typeof(StartingRecallEventArgs), nameof(StartingRecallEventArgs.IsAllowed))),
new(OpCodes.Brfalse_S, retLabel),
});
newInstructions[newInstructions.Count - 1].WithLabels(retLabel);

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

ListPool<CodeInstruction>.Pool.Return(newInstructions);
}
}
}
// -----------------------------------------------------------------------
// <copyright file="StartingRecall.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

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

using API.Features;
using API.Features.Pools;
using Exiled.Events.Attributes;
using Exiled.Events.EventArgs.Scp049;

using HarmonyLib;

using PlayerRoles.PlayableScps.Scp049;

using static HarmonyLib.AccessTools;

/// <summary>
/// Patches <see cref="Scp049ResurrectAbility.ServerValidateBegin" />.
/// Adds the <see cref="Handlers.Scp049.StartingRecall" /> event.
/// </summary>
[EventPatch(typeof(Handlers.Scp049), nameof(Handlers.Scp049.StartingRecall))]
[HarmonyPatch(typeof(Scp049ResurrectAbility), nameof(Scp049ResurrectAbility.ServerValidateBegin))]
internal static class Scp049ResurrectAbilityPatch

Check failure on line 30 in Exiled.Events/Patches/Events/Scp049/StartingRecall.cs

View workflow job for this annotation

GitHub Actions / build

{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

Label continueLabel = generator.DefineLabel();
Label retLabel = generator.DefineLabel();
louis1706 marked this conversation as resolved.
Show resolved Hide resolved
XKaguya marked this conversation as resolved.
Show resolved Hide resolved

newInstructions.InsertRange(0, new CodeInstruction[]
{
// Player player = Player.Get(this.Owner);
new(OpCodes.Ldarg_0),
new(OpCodes.Callvirt, PropertyGetter(typeof(Scp049ResurrectAbility), nameof(Scp049ResurrectAbility.Owner))),
new(OpCodes.Call, Method(typeof(Exiled.API.Features.Player), nameof(Exiled.API.Features.Player.Get), new[] { typeof(ReferenceHub) })),

// Ragdoll doll = Ragdoll.Get(ragdoll);
new(OpCodes.Ldarg_1),
new(OpCodes.Call, Method(typeof(Ragdoll), nameof(Ragdoll.Get), new[] { typeof(BasicRagdoll) })),

Check failure on line 48 in Exiled.Events/Patches/Events/Scp049/StartingRecall.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'BasicRagdoll' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 48 in Exiled.Events/Patches/Events/Scp049/StartingRecall.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'BasicRagdoll' could not be found (are you missing a using directive or an assembly reference?)

// true
new(OpCodes.Ldc_I4_1),

// StartingRecallEventArgs ev = new StartingRecallEventArgs(player, doll, true);
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(StartingRecallEventArgs))[0]),
new(OpCodes.Dup),

// Handlers.Scp049.OnStartingRecall(ev);
new(OpCodes.Call, Method(typeof(Handlers.Scp049), nameof(Handlers.Scp049.OnStartingRecall))),

// if (!ev.IsAllowed)
// return 1;
// else
// continue;
new(OpCodes.Callvirt, PropertyGetter(typeof(StartingRecallEventArgs), nameof(StartingRecallEventArgs.IsAllowed))),
new(OpCodes.Brtrue_S, continueLabel),
new(OpCodes.Ldc_I4_1),
new CodeInstruction(OpCodes.Ret).WithLabels(retLabel),
louis1706 marked this conversation as resolved.
Show resolved Hide resolved
XKaguya marked this conversation as resolved.
Show resolved Hide resolved

Check failure on line 68 in Exiled.Events/Patches/Events/Scp049/StartingRecall.cs

View workflow job for this annotation

GitHub Actions / build

new CodeInstruction(OpCodes.Nop).WithLabels(continueLabel),
XKaguya marked this conversation as resolved.
Show resolved Hide resolved
});

newInstructions[newInstructions.Count - 1].WithLabels(retLabel);
XKaguya marked this conversation as resolved.
Show resolved Hide resolved

XKaguya marked this conversation as resolved.
Show resolved Hide resolved
for (int z = 0; z < newInstructions.Count; z++)
yield return newInstructions[z];

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