forked from Exiled-Official/EXILED
-
Notifications
You must be signed in to change notification settings - Fork 67
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
Added the SCP-079 Recontaining event #21
Merged
+120
−0
Merged
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2e9f87f
added the RecontainingEvent with the patch
FoxWorn3365 f3b17ea
Fixed constructors
FoxWorn3365 18db618
consistency
FoxWorn3365 711d32e
fixed logic skill issue
FoxWorn3365 d2fd8be
Removed "useless" constructor
FoxWorn3365 91fc11e
corrected the typo
FoxWorn3365 2a6b04c
fixed some typo
FoxWorn3365 3bc31d6
final edit for the final request
FoxWorn3365 093368b
Merge branch 'dev' into dev
louis1706 5caab7b
Merge branch 'dev' into dev
louis1706 003e7b8
Apply suggestions from code review
louis1706 0f72c28
Apply suggestions from code review
louis1706 9189cae
Merge branch 'dev' into dev
VALERA771 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
louis1706 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
/// <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> | ||
/// Initializes a new instance of the <see cref="RecontainingEventArgs" /> class. | ||
/// </summary> | ||
/// <param name="recontainer">The <see cref="BreakableWindow"/> istance.</param> | ||
public RecontainingEventArgs(BreakableWindow recontainer) | ||
: this(recontainer.LastAttacker.Hub) | ||
{ | ||
} | ||
|
||
/// <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; } | ||
louis1706 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// <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; | ||
FoxWorn3365 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
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
67 changes: 67 additions & 0 deletions
67
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,67 @@ | ||
// ----------------------------------------------------------------------- | ||
// <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.API.Features.Pools; | ||
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 = ListPool<CodeInstruction>.Pool.Get(instructions); | ||
|
||
LocalBuilder ev = generator.DeclareLocal(typeof(RecontainingEventArgs)); | ||
|
||
Label returnLabel = generator.DefineLabel(); | ||
|
||
newInstructions.InsertRange(index, new CodeInstruction[] | ||
{ | ||
// RecontainingEventArgs ev = new(ReferenceHub "attacker") | ||
louis1706 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
new(OpCodes.Ldarg_0), | ||
new(OpCodes.Ldfld, PropertyGetter(typeof(Scp079Recontainer), nameof(Scp079Recontainer._activatorGlass))), | ||
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(RecontainingEventArgs))[1]), | ||
new(OpCodes.Starg_S, ev.LocalIndex), | ||
louis1706 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Call event | ||
louis1706 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
new(OpCodes.Ldarg_S, ev.LocalIndex), | ||
louis1706 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
new(OpCodes.Call, Method(typeof(Scp079), nameof(Scp079.OnRecontaining))), | ||
|
||
// if (!ev.IsAllowed) return; | ||
new(OpCodes.Ldarg_S, ev.LocalIndex), | ||
louis1706 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
new(OpCodes.Callvirt, Method(typeof(RecontainingEventArgs), nameof(RecontainingEventArgs.IsAllowed))), | ||
new(OpCodes.Brfalse_S, returnLabel), | ||
}); | ||
|
||
newInstructions[newInstructions.Count - 1].WithLabels(returnLabel); | ||
|
||
for (int z = 0; z < newInstructions.Count; z++) | ||
yield return newInstructions[z]; | ||
|
||
ListPool<CodeInstruction>.Pool.Return(newInstructions); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add IPlayerEvent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do it tomorrow