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. #2226

Closed
wants to merge 18 commits into from
Closed
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
53 changes: 53 additions & 0 deletions .github/workflows/halloween.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Exiled Halloween CI

on:
push:
branches:
- 'halloween-2023'
pull_request:
branches:
- 'halloween-2023'
workflow_dispatch:

env:
EXILED_REFERENCES_URL: https://exiled.host/build_deps/Dev.zip
EXILED_REFERENCES_PATH: ${{ github.workspace }}/References

jobs:

build:

runs-on: windows-latest
# Prevent double running for push & pull_request events from the main repo
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'Exiled-Team/Exiled'

steps:

- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v1.7.2

- name: Setup Nuget
uses: iRebbok/setup-nuget@master

- uses: actions/checkout@v2.3.4

- name: Get references
shell: pwsh
run: |
Invoke-WebRequest -Uri ${{ env.EXILED_REFERENCES_URL }} -OutFile ${{ github.workspace }}/References.zip
Expand-Archive -Path References.zip -DestinationPath ${{ env.EXILED_REFERENCES_PATH }}

- name: Build
env:
EXILED_REFERENCES: ${{ env.EXILED_REFERENCES_PATH }}
shell: pwsh
run: |
./build.ps1 -BuildNuGet
$File = (Get-ChildItem -Path . -Include 'EXILED.*.nupkg' -Recurse).Name
Out-File -FilePath ${{ github.env }} -InputObject "PackageFile=$File" -Encoding utf-8 -Append

- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: Build Results
path: bin/Release
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)
{
Ragdoll = ragdoll;
Target = Ragdoll.Owner;
Scp049 = player.Role.As<Scp049Role>();
Player = player;
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; }
}
}
158 changes: 80 additions & 78 deletions Exiled.Events/Patches/Events/Scp049/StartingRecall.cs
Original file line number Diff line number Diff line change
@@ -1,78 +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 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
{
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();

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) })),

// true
new(OpCodes.Ldc_I4_1),

// StartingRecallEventArgs ev = new StartingRecallEventArgsMod(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 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),

new CodeInstruction(OpCodes.Nop).WithLabels(continueLabel),
});

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

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

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