forked from Exiled-Official/EXILED
-
Notifications
You must be signed in to change notification settings - Fork 108
[EXILED::Events] BeingObserved event
#72
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
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7d8eaf6
Scp 173 Being Observed event
6hundred9 457f903
comments
6hundred9 af65d3c
deleted the example for the event
6hundred9 72283a7
being sleep deprived is doing things to me :pray:
6hundred9 ce6c6d2
fix
6hundred9 c76fe12
fix
6hundred9 8a19fa0
a
6hundred9 a061faa
Update Scp173.cs
6hundred9 c1bb53b
Update and rename Scp173BeingObserved.cs to BeingObserved.cs
6hundred9 14ee8e5
build error
6hundred9 d0d5df9
Fix
6hundred9 f18452c
Fix of the fix
6hundred9 ec51b28
.
6hundred9 97b9b6a
Hello machine, pls fix code, thx (PS: NO BUGS)
6hundred9 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
57 changes: 57 additions & 0 deletions
57
EXILED/Exiled.Events/EventArgs/Scp173/BeingObservedEventArgs.cs
This file contains hidden or 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,57 @@ | ||
| // ----------------------------------------------------------------------- | ||
| // <copyright file="BeingObservedEventArgs.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 Exiled.API.Features; | ||
| using Exiled.API.Features.Roles; | ||
| using Exiled.Events.EventArgs.Interfaces; | ||
|
|
||
| /// <summary> | ||
| /// Contains all the information before SCP-173 is observed. | ||
| /// </summary> | ||
| public class BeingObservedEventArgs : IScp173Event, IDeniableEvent | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="BeingObservedEventArgs" /> class. | ||
| /// </summary> | ||
| /// <param name="target"> | ||
| /// The <see cref="Exiled.API.Features.Player"/> instance of the target. | ||
| /// </param> | ||
| /// <param name="scp173"> | ||
| /// The <see cref="Exiled.API.Features.Player"/> instance of the SCP-173. | ||
| /// </param> | ||
| /// <param name="isAllowed"> | ||
| /// Whether or not the target will be counted as observing the SCP-173. | ||
| /// </param> | ||
| public BeingObservedEventArgs(API.Features.Player target, API.Features.Player scp173, bool isAllowed = true) | ||
| { | ||
| Target = target; | ||
| Player = scp173; | ||
| Scp173 = scp173.Role.As<Scp173Role>(); | ||
| IsAllowed = isAllowed; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the player who's observing the SCP-173. | ||
| /// </summary> | ||
| public Player Target { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the player who's being observed. | ||
| /// </summary> | ||
| public Player Player { get; } | ||
|
|
||
| /// <inheritdoc/> | ||
| public Scp173Role Scp173 { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets a value indicating whether or not the player can be counted as observing. | ||
| /// </summary> | ||
| public bool IsAllowed { get; set; } | ||
| } | ||
| } |
This file contains hidden or 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
83 changes: 83 additions & 0 deletions
83
EXILED/Exiled.Events/Patches/Events/Scp173/BeingObserved.cs
This file contains hidden or 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,83 @@ | ||
| // ----------------------------------------------------------------------- | ||
| // <copyright file="BeingObserved.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.Scp173 | ||
| { | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Reflection.Emit; | ||
|
|
||
| using Exiled.API.Features.Pools; | ||
| using Exiled.Events.Attributes; | ||
| using Exiled.Events.EventArgs.Scp173; | ||
| using HarmonyLib; | ||
| using PlayerRoles.PlayableScps.Scp173; | ||
| using PlayerRoles.Subroutines; | ||
| using PluginAPI.Events; | ||
|
|
||
| using static HarmonyLib.AccessTools; | ||
|
|
||
| /// <summary> | ||
| /// Patches <see cref="Scp173ObserversTracker.IsObservedBy" />. | ||
| /// Adds the <see cref="Handlers.Scp173.BeingObserved" /> event. | ||
| /// </summary> | ||
| [EventPatch(typeof(Handlers.Scp173), nameof(Handlers.Scp173.BeingObserved))] | ||
| [HarmonyPatch(typeof(Scp173ObserversTracker), nameof(Scp173ObserversTracker.IsObservedBy))] | ||
| internal static class BeingObserved | ||
| { | ||
| private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) | ||
| { | ||
| List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions); | ||
|
|
||
| Label continueLabel = generator.DefineLabel(); | ||
|
|
||
| const int offset = -4; | ||
| int index = newInstructions.FindIndex(i => i.Is(OpCodes.Call, Method(typeof(EventManager), nameof(EventManager.ExecuteEvent), new Type[] { typeof(IEventArguments) }))) + offset; | ||
|
|
||
| newInstructions.InsertRange( | ||
| index, | ||
| new CodeInstruction[] | ||
| { | ||
| // Player.Get(target) | ||
| new(OpCodes.Ldarg_1), | ||
| new(OpCodes.Call, Method(typeof(API.Features.Player), nameof(API.Features.Player.Get), new[] { typeof(ReferenceHub) })), | ||
|
|
||
| // Player.Get(base.Owner) | ||
| new(OpCodes.Ldarg_0), | ||
| new(OpCodes.Call, PropertyGetter(typeof(StandardSubroutine<Scp173Role>), nameof(StandardSubroutine<Scp173Role>.Owner))), | ||
| new(OpCodes.Call, Method(typeof(API.Features.Player), nameof(API.Features.Player.Get), new[] { typeof(ReferenceHub) })), | ||
|
|
||
| // true | ||
| new(OpCodes.Ldc_I4_1), | ||
|
|
||
| // BeingObservedEventArgs ev = new(Player, Player, bool) | ||
| new(OpCodes.Newobj, GetDeclaredConstructors(typeof(BeingObservedEventArgs))[0]), | ||
| new(OpCodes.Dup), | ||
|
|
||
| // Handlers.Scp173.OnBeingObserved(ev) | ||
| new(OpCodes.Call, Method(typeof(Handlers.Scp173), nameof(Handlers.Scp173.OnBeingObserved))), | ||
|
|
||
| // if (ev.IsAllowed) | ||
| // goto continueLabel | ||
| new(OpCodes.Callvirt, PropertyGetter(typeof(BeingObservedEventArgs), nameof(BeingObservedEventArgs.IsAllowed))), | ||
| new(OpCodes.Brtrue, continueLabel), | ||
|
|
||
| // return false | ||
| new(OpCodes.Ldc_I4_0), | ||
| new(OpCodes.Ret), | ||
|
|
||
| // continueLabel: | ||
| new CodeInstruction(OpCodes.Nop).WithLabels(continueLabel), | ||
| }); | ||
|
|
||
| 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.
Uh oh!
There was an error while loading. Please reload this page.