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

[Resonance] New SCP Events & Disguise Prefix To Transpiler #2739

Merged
merged 32 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
56cef01
delete duplicate
xNexusACS Jul 19, 2024
d062c20
Update Warhead.cs
xNexusACS Jul 19, 2024
a735aef
delete duplicate
xNexusACS Jul 19, 2024
70f4902
fix stylecop here
xNexusACS Jul 19, 2024
a2c736d
Merge branch 'dev' into dev
xNexusACS Jul 19, 2024
831ed38
Stylecop again (Pragma)
xNexusACS Jul 19, 2024
e956d62
Merge remote-tracking branch 'origin/dev' into dev
xNexusACS Jul 19, 2024
7a6be4c
stylecop
xNexusACS Jul 19, 2024
bced683
Last Stylecop fixes
xNexusACS Jul 19, 2024
e66944a
Merge branch 'Exiled-Team:dev' into dev
xNexusACS Jul 19, 2024
2647b59
Merge branch 'Exiled-Team:dev' into dev
xNexusACS Jul 19, 2024
c8b8e4f
Merge branch 'Exiled-Team:dev' into dev
xNexusACS Jul 19, 2024
674c907
Merge branch 'Exiled-Team:dev' into dev
xNexusACS Jul 20, 2024
46c6568
Fix Strangling & Rework Disguising Patch
xNexusACS Jul 20, 2024
a6d6dc7
Merge remote-tracking branch 'origin/dev' into dev
xNexusACS Jul 20, 2024
b368e7e
scp173 attacking event
xNexusACS Jul 20, 2024
a7d501c
Fixes and Add Scp096 Attack Event Arg
xNexusACS Jul 20, 2024
42056dc
Missing commentaries
xNexusACS Jul 20, 2024
373a3e5
Fix disguising again
xNexusACS Jul 20, 2024
0fbb38d
Scp096 Attack Transpiler -> Prefix
xNexusACS Jul 20, 2024
4eaa606
Scp0492 Attacking Event
xNexusACS Jul 20, 2024
d578a65
Merge branch 'dev' into dev
xNexusACS Jul 20, 2024
f76f71b
revert strangling fixes
xNexusACS Jul 20, 2024
a4ff1ce
version bump
xNexusACS Jul 20, 2024
d73f302
Merge branch 'dev' into dev
xNexusACS Jul 20, 2024
4e77461
Fix 0492 attacking event
xNexusACS Jul 20, 2024
0dbfdca
Merge branch 'dev' into dev
xNexusACS Jul 20, 2024
389158c
missing commentaries
xNexusACS Jul 20, 2024
cdc6934
Merge remote-tracking branch 'origin/dev' into dev
xNexusACS Jul 20, 2024
10e92b6
fix summary
xNexusACS Jul 20, 2024
004d975
Scp096 Attack prefix -> transpiler
xNexusACS Jul 20, 2024
6fdb724
missing commentary
xNexusACS Jul 20, 2024
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
47 changes: 47 additions & 0 deletions Exiled.Events/EventArgs/Scp0492/AttackingEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// -----------------------------------------------------------------------
// <copyright file="AttackingEventArgs.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.Scp0492
{
using API.Features;
using Exiled.API.Features.Roles;
using Exiled.Events.EventArgs.Interfaces;

/// <summary>
/// Contains all information before a Scp-0492 attacks a player.
/// </summary>
public class AttackingEventArgs : IScp0492Event, IDeniableEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="AttackingEventArgs" /> class.
/// </summary>
/// <param name="player"><see cref="Player"/>.</param>
/// <param name="target"><see cref="Target"/>.</param>
/// <param name="isAllowed"><see cref="IsAllowed"/>.</param>
public AttackingEventArgs(Player player, Player target, bool isAllowed = true)
{
Player = player;
Scp0492 = Player.Role.As<Scp0492Role>();
Target = target;
IsAllowed = isAllowed;
}

/// <inheritdoc/>
public Player Player { get; }

/// <inheritdoc/>
public Scp0492Role Scp0492 { get; }

/// <summary>
/// Gets the player that is going to damaged by a SCP-0492.
/// </summary>
public Player Target { get; }

/// <inheritdoc/>
public bool IsAllowed { get; set; }
}
}
61 changes: 61 additions & 0 deletions Exiled.Events/EventArgs/Scp096/AttackingEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// -----------------------------------------------------------------------
// <copyright file="AttackingEventArgs.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.Scp096
{
using Exiled.API.Features;
using Exiled.API.Features.Roles;
using Exiled.Events.EventArgs.Interfaces;

/// <summary>
/// Contains all information before SCP-096 attacks someone.
/// </summary>
public class AttackingEventArgs : IScp096Event, IDeniableEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="AttackingEventArgs" /> class.
/// </summary>
/// <param name="player"><see cref="Player"/>.</param>
/// <param name="target"><see cref="Target"/>.</param>
/// <param name="humanDamage"><see cref="HumanDamage"/>.</param>
/// <param name="nonTargetDamage"><see cref="NonTargetDamage"/>.</param>
/// <param name="isAllowed"><see cref="IsAllowed"/>.</param>
public AttackingEventArgs(Player player, Player target, float humanDamage, float nonTargetDamage, bool isAllowed = true)
{
Player = player;
Scp096 = Player.Role.As<Scp096Role>();
Target = target;
HumanDamage = humanDamage;
NonTargetDamage = nonTargetDamage;
IsAllowed = isAllowed;
}

/// <inheritdoc/>
public Player Player { get; }

/// <inheritdoc/>
public Scp096Role Scp096 { get; }

/// <summary>
/// Gets the player that is going to be damaged by the SCP-096.
/// </summary>
public Player Target { get; }

/// <summary>
/// Gets or sets the amount of damage of the SCP-096 hit.
/// </summary>
public float HumanDamage { get; set; }

/// <summary>
/// Gets or sets the amount of damage of the SCP-096 if the target is not a target of the SCP-096.
/// </summary>
public float NonTargetDamage { get; set; }

/// <inheritdoc/>
public bool IsAllowed { get; set; }
}
}
47 changes: 47 additions & 0 deletions Exiled.Events/EventArgs/Scp173/AttackingEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// -----------------------------------------------------------------------
// <copyright file="AttackingEventArgs.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.Scp173
{
using API.Features;
using Exiled.API.Features.Roles;
using Exiled.Events.EventArgs.Interfaces;

/// <summary>
/// Contains all information before a Scp-173 snaps a player neck.
/// </summary>
public class AttackingEventArgs : IScp173Event, IDeniableEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="AttackingEventArgs" /> class.
/// </summary>
/// <param name="player"><see cref="Player"/>.</param>
/// <param name="target"><see cref="Target"/>.</param>
/// <param name="isAllowed"><see cref="IsAllowed"/>.</param>
public AttackingEventArgs(Player player, Player target, bool isAllowed = true)
{
Player = player;
Scp173 = Player.Role.As<Scp173Role>();
Target = target;
IsAllowed = isAllowed;
}

/// <inheritdoc/>
public Player Player { get; }

/// <inheritdoc/>
public Scp173Role Scp173 { get; }

/// <summary>
/// Gets the player that is going to be snapped.
/// </summary>
public Player Target { get; }

/// <inheritdoc/>
public bool IsAllowed { get; set; }
}
}
37 changes: 4 additions & 33 deletions Exiled.Events/EventArgs/Scp3114/StranglingEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,65 +10,36 @@ namespace Exiled.Events.EventArgs.Scp3114
using Exiled.API.Features;
using Exiled.Events.EventArgs.Interfaces;

using PlayerRoles.PlayableScps.Scp3114;

using HumanRole = PlayerRoles.HumanRole;
using Scp3114Role = API.Features.Roles.Scp3114Role;

/// <summary>
/// Contains all information before strangling a player.
/// </summary>
public class StranglingEventArgs : IScp3114Event, IDeniableEvent
{
private readonly Scp3114Strangle strangle;
private Player target = null;

/// <summary>
/// Initializes a new instance of the <see cref="StranglingEventArgs"/> class.
/// </summary>
/// <param name="strangle">The <see cref="Scp3114Strangle"/> instance.</param>
/// <param name="player">The <see cref="API.Features.Player"/> triggering the event.</param>
/// <param name="target">The <see cref="API.Features.Player"/> being targeted.</param>
public StranglingEventArgs(Scp3114Strangle strangle, Player player, Scp3114Strangle.StrangleTarget target)
public StranglingEventArgs(Player player, Player target)
{
this.strangle = strangle;
Scp3114 = player.Role.As<Scp3114Role>();
Player = player;
Target = Player.Get(target.Target);
StrangleTarget = target;
Target = target;
}

/// <inheritdoc />
public Scp3114Role Scp3114 { get; }

/// <inheritdoc />
public Player Player
{
get => target;
set
{
target = value;

if (!target)
{
StrangleTarget = default(Scp3114Strangle.StrangleTarget);
return;
}

StrangleTarget = new(target.ReferenceHub, strangle.GetStranglePosition(target.ReferenceHub.roleManager.CurrentRole as HumanRole), Player.Position);
}
}
public Player Player { get; }

/// <summary>
/// Gets the target player.
/// Gets the target that the skeleton is strangling.
/// </summary>
public Player Target { get; }

/// <summary>
/// Gets the <see cref="Scp3114Strangle.StrangleTarget"/>. This value is updated when <see cref="Target"/> is changed.
/// </summary>
public Scp3114Strangle.StrangleTarget? StrangleTarget { get; private set; }

/// <inheritdoc />
public bool IsAllowed { get; set; } = true;
}
Expand Down
11 changes: 11 additions & 0 deletions Exiled.Events/Handlers/Scp0492.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public class Scp0492
/// </summary>
public static Event<ConsumingCorpseEventArgs> ConsumingCorpse { get; set; } = new();

/// <summary>
/// Called before 049-2 damages someone.
/// </summary>
public static Event<AttackingEventArgs> Attacking { get; set; } = new();

/// <summary>
/// Called before a player triggers the bloodlust effect for 049-2.
/// </summary>
Expand All @@ -49,5 +54,11 @@ public class Scp0492
/// </summary>
/// <param name="ev"><inheritdoc cref="ConsumingCorpseEventArgs"/> instance.</param>
public static void OnConsumingCorpse(ConsumingCorpseEventArgs ev) => ConsumingCorpse.InvokeSafely(ev);

/// <summary>
/// Invokes before 049-2 hits someone.
/// </summary>
/// <param name="ev"><inheritdoc cref="AttackingEventArgs"/> instance.</param>
public static void OnAttacking(AttackingEventArgs ev) => Attacking.InvokeSafely(ev);
}
}
11 changes: 11 additions & 0 deletions Exiled.Events/Handlers/Scp096.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public static class Scp096
/// </summary>
public static Event<TryingNotToCryEventArgs> TryingNotToCry { get; set; } = new();

/// <summary>
/// Invoked before SCP-096 damages someone.
/// </summary>
public static Event<AttackingEventArgs> Attacking { get; set; } = new();

/// <summary>
/// Called before SCP-096 is enraged.
/// </summary>
Expand Down Expand Up @@ -82,5 +87,11 @@ public static class Scp096
/// </summary>
/// <param name="ev">The <see cref="TryingNotToCryEventArgs" /> instance.</param>
public static void OnTryingNotToCry(TryingNotToCryEventArgs ev) => TryingNotToCry.InvokeSafely(ev);

/// <summary>
/// Called before SCP-096 damages someone.
/// </summary>
/// <param name="ev">The <see cref="AttackingEventArgs"/> instance.</param>
public static void OnAttacking(AttackingEventArgs ev) => Attacking.InvokeSafely(ev);
}
}
11 changes: 11 additions & 0 deletions Exiled.Events/Handlers/Scp173.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public static class Scp173
/// </summary>
public static Event<RemoveObserverEventArgs> RemoveObserver { get; set; } = new();

/// <summary>
/// Invoked before SCP-173 snaps a player neck.
/// </summary>
public static Event<AttackingEventArgs> Attacking { get; set; } = new();

/// <summary>
/// Called before players near SCP-173 blink.
/// </summary>
Expand Down Expand Up @@ -82,5 +87,11 @@ public static class Scp173
/// </summary>
/// <param name="ev">The <see cref="AddingObserverEventArgs" /> instance.</param>
public static void OnRemoveObserver(RemoveObserverEventArgs ev) => RemoveObserver.InvokeSafely(ev);

/// <summary>
/// Called before SCP-173 snaps a player neck.
/// </summary>
/// <param name="ev">The <see cref="AttackingEventArgs"/> instance.</param>
public static void OnAttacking(AttackingEventArgs ev) => Attacking.InvokeSafely(ev);
}
}
76 changes: 76 additions & 0 deletions Exiled.Events/Patches/Events/Scp0492/Attacking.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// -----------------------------------------------------------------------
// <copyright file="Attacking.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.Scp0492
{
using System.Collections.Generic;
using System.Reflection.Emit;

using Exiled.API.Features.Core.Generic.Pools;
using Exiled.Events.Attributes;
using Exiled.Events.EventArgs.Scp0492;
using HarmonyLib;
using PlayerRoles.PlayableScps.Scp049.Zombies;
using PlayerRoles.PlayableScps.Subroutines;

using static HarmonyLib.AccessTools;

using Player = Exiled.API.Features.Player;

/// <summary>
/// Patches <see cref="ScpAttackAbilityBase{T}.ServerPerformAttack" />.
/// Adds the <see cref="Handlers.Scp0492.Attacking" /> event.
/// </summary>
[EventPatch(typeof(Handlers.Scp0492), nameof(Handlers.Scp0492.Attacking))]
[HarmonyPatch(typeof(ScpAttackAbilityBase<ZombieRole>), nameof(ScpAttackAbilityBase<ZombieRole>.ServerPerformAttack))]
internal static class Attacking
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

Label retLabel = generator.DefineLabel();

const int offset = -4;
int index = newInstructions.FindIndex(instruction => instruction.Calls(Method(typeof(HashSet<ReferenceHub>), nameof(HashSet<ReferenceHub>.Add)))) + offset;

newInstructions.InsertRange(index, new CodeInstruction[]
{
// Player::Get(ScpAttackAbilityBase<ZombieRole>::Owner)
new CodeInstruction(OpCodes.Ldarg_0).MoveLabelsFrom(newInstructions[index]),
new(OpCodes.Callvirt, PropertyGetter(typeof(ScpAttackAbilityBase<ZombieRole>), nameof(ScpAttackAbilityBase<ZombieRole>.Owner))),
new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),

// Player::Get(hitboxIdentity)
new(OpCodes.Ldloc_3),
new(OpCodes.Callvirt, PropertyGetter(typeof(HitboxIdentity), nameof(HitboxIdentity.TargetHub))),
new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),

// true
new(OpCodes.Ldc_I4_1),

// AttackingEventArgs args = new(player, target, true)
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(AttackingEventArgs))[0]),
new(OpCodes.Dup),

// Scp0492::OnAttacking(args)
new(OpCodes.Call, Method(typeof(Handlers.Scp0492), nameof(Handlers.Scp0492.OnAttacking))),

// if (!args.IsAllowed) return
new(OpCodes.Callvirt, PropertyGetter(typeof(AttackingEventArgs), nameof(AttackingEventArgs.IsAllowed))),
new(OpCodes.Brfalse_S, retLabel),
});

newInstructions[newInstructions.Count - 1].labels.Add(retLabel);

foreach (CodeInstruction instruction in newInstructions)
yield return instruction;

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