forked from Exiled-Official/EXILED
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added the RecontainingEvent with the patch
- Loading branch information
1 parent
04bffe8
commit 2e9f87f
Showing
3 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
EXILED/Exiled.Events/EventArgs/Scp079/RecontainingEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="RecontainingEventArgs.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.Scp079 | ||
{ | ||
using Exiled.API.Features; | ||
using Exiled.Events.EventArgs.Interfaces; | ||
|
||
/// <summary> | ||
/// Contains information before SCP-079 gets recontained. | ||
/// </summary> | ||
public class RecontainingEventArgs : IDeniableEvent | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="RecontainingEventArgs" /> class. | ||
/// </summary> | ||
/// <param name="recontainer">The <see cref="BreakableWindow"/> istance.</param> | ||
public RecontainingEventArgs(BreakableWindow recontainer) | ||
{ | ||
Recontainer = Player.Get(recontainer.LastAttacker); | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="RecontainingEventArgs" /> class. | ||
/// </summary> | ||
/// <param name="recontainer">The player that triggered the SCP-079 recontaining event.</param> | ||
public RecontainingEventArgs(ReferenceHub recontainer) | ||
{ | ||
Recontainer = Player.Get(recontainer); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the Player that started the recontainment process.<br></br> | ||
/// Can be null if <see cref="IsAutomatic"/> is true. | ||
/// </summary> | ||
public Player Recontainer { get; } | ||
|
||
/// <inheritdoc/> | ||
public bool IsAllowed { get; set; } = true; | ||
|
||
/// <summary> | ||
/// Gets a value indicating whether or not the recontained has been made automatically or by triggering the proccess. | ||
/// </summary> | ||
public bool IsAutomatic => Recontainer is null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
EXILED/Exiled.Events/Patches/Events/Scp079/Recontaining.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="Recontaining.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.Scp079 | ||
{ | ||
using System.Collections.Generic; | ||
using System.Reflection.Emit; | ||
|
||
using Exiled.Events.Attributes; | ||
using Exiled.Events.EventArgs.Scp079; | ||
using Exiled.Events.Handlers; | ||
|
||
using HarmonyLib; | ||
|
||
using PlayerRoles.PlayableScps.Scp079; | ||
|
||
using static HarmonyLib.AccessTools; | ||
|
||
/// <summary> | ||
/// Patches <see cref="Scp079Recontainer.Recontain" />. | ||
/// Adds the <see cref="Scp079.Recontaining" /> event. | ||
/// </summary> | ||
[EventPatch(typeof(Scp079), nameof(Scp079.Recontaining))] | ||
[HarmonyPatch(typeof(Scp079Recontainer), nameof(Scp079Recontainer.Recontain))] | ||
internal class Recontaining | ||
{ | ||
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) | ||
{ | ||
int index = 0; | ||
List<CodeInstruction> newInstructions = new(instructions); | ||
|
||
LocalBuilder ev = generator.DeclareLocal(typeof(RecontainingEventArgs)); | ||
|
||
Label proceed = generator.DefineLabel(); | ||
|
||
newInstructions.InsertRange(index, new CodeInstruction[] | ||
{ | ||
// RecontainingEventArgs ev = new(ReferenceHub "attacker") | ||
new(OpCodes.Ldarg_0), | ||
new(OpCodes.Ldfld, PropertyGetter(typeof(Scp079Recontainer), nameof(Scp079Recontainer._activatorGlass))), | ||
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(RecontainingEventArgs))[0]), | ||
new(OpCodes.Starg_S, ev.LocalIndex), | ||
|
||
// Call event | ||
new(OpCodes.Ldarg_S, ev.LocalIndex), | ||
new(OpCodes.Call, Method(typeof(Scp079), nameof(Scp079.OnRecontaining))), | ||
|
||
// if (!ev.IsAllowed) return; | ||
new(OpCodes.Ldarg_S, ev.LocalIndex), | ||
new(OpCodes.Callvirt, Method(typeof(RecontainingEventArgs), nameof(RecontainingEventArgs.IsAllowed))), | ||
new(OpCodes.Brtrue_S, proceed), | ||
|
||
new(OpCodes.Ret), | ||
|
||
new CodeInstruction(OpCodes.Nop).WithLabels(proceed), | ||
}); | ||
|
||
return newInstructions; | ||
} | ||
} | ||
} |