forked from Exiled-Official/EXILED
-
Notifications
You must be signed in to change notification settings - Fork 102
feat: Adds a new event for when SCP-1576 stops being used #699
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
599f679
Adds a event that is called after player stops talking with 1576
michcio15 ab779b5
Simplify initialization of TransmissionEnded event.
michcio15 a02199e
should be no more warnings when build
michcio15 a389632
Apply suggestions from code review
michcio15 d46ad62
added the suggestions to make it more exiled like
michcio15 46af72a
Moved to Player Handler
michcio15 4f74c2c
Update Scp1576TransmissionEnded.cs
michcio15 10dd33b
Merge branch 'dev' into master
louis1706 890384b
Merge branch 'dev' into master
michcio15 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
41 changes: 41 additions & 0 deletions
41
EXILED/Exiled.Events/EventArgs/Player/Scp1576TransmissionEndedEventArgs.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,41 @@ | ||
| // ----------------------------------------------------------------------- | ||
| // <copyright file="Scp1576TransmissionEndedEventArgs.cs" company="ExMod Team"> | ||
| // Copyright (c) ExMod Team. All rights reserved. | ||
| // Licensed under the CC BY-SA 3.0 license. | ||
| // </copyright> | ||
| // ----------------------------------------------------------------------- | ||
|
|
||
| namespace Exiled.Events.EventArgs.Player | ||
| { | ||
| using API.Features; | ||
| using API.Features.Items; | ||
| using Interfaces; | ||
| using InventorySystem.Items.Usables.Scp1576; | ||
|
|
||
| /// <summary> | ||
| /// Contains all information after a SCP-1576 transmission has ended. | ||
| /// </summary> | ||
| public class Scp1576TransmissionEndedEventArgs : IPlayerEvent | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="Scp1576TransmissionEndedEventArgs"/> class. | ||
| /// </summary> | ||
| /// <param name="player"><inheritdoc cref="Player"/></param> | ||
| /// <param name="scp1576Item"><inheritdoc cref="Scp1576"/></param> | ||
| public Scp1576TransmissionEndedEventArgs(Player player, Scp1576Item scp1576Item) | ||
| { | ||
| Player = player; | ||
| Scp1576 = Item.Get<Scp1576>(scp1576Item); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the <see cref="Exiled.API.Features.Player"/> that the transmission ended for. | ||
| /// </summary> | ||
| public Player Player { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the <see cref="Exiled.API.Features.Items.Scp1576"/> instance. | ||
| /// </summary> | ||
| public Exiled.API.Features.Items.Scp1576 Scp1576 { get; } | ||
| } | ||
| } | ||
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
59 changes: 59 additions & 0 deletions
59
EXILED/Exiled.Events/Patches/Events/Player/Scp1576TransmissionEnded.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,59 @@ | ||
| // ----------------------------------------------------------------------- | ||
| // <copyright file="Scp1576TransmissionEnded.cs" company="ExMod Team"> | ||
| // Copyright (c) ExMod Team. All rights reserved. | ||
| // Licensed under the CC BY-SA 3.0 license. | ||
| // </copyright> | ||
| // ----------------------------------------------------------------------- | ||
|
|
||
| namespace Exiled.Events.Patches.Events.Player | ||
| { | ||
| using System.Collections.Generic; | ||
| using System.Reflection.Emit; | ||
|
|
||
| using Exiled.API.Features.Pools; | ||
| using Exiled.Events.Attributes; | ||
| using Exiled.Events.EventArgs.Player; | ||
| using HarmonyLib; | ||
| using InventorySystem.Items.Usables.Scp1576; | ||
|
|
||
| using static HarmonyLib.AccessTools; | ||
|
|
||
| /// <summary> | ||
| /// Patches <see cref="Scp1576Item.ServerStopTransmitting"/> to add <see cref="Handlers.Player.Scp1576TransmissionEnded"/> event. | ||
| /// </summary> | ||
| [EventPatch(typeof(Handlers.Player), nameof(Handlers.Player.Scp1576TransmissionEnded))] | ||
| [HarmonyPatch(typeof(InventorySystem.Items.Usables.Scp1576.Scp1576Item), nameof(Scp1576Item.ServerStopTransmitting))] | ||
| public class Scp1576TransmissionEnded | ||
| { | ||
| private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) | ||
| { | ||
| List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions); | ||
|
|
||
| int index = newInstructions.Count - 1; | ||
|
|
||
| newInstructions.InsertRange( | ||
| index, | ||
| new[] | ||
| { | ||
| // Player.Get(base.Owner) | ||
| new CodeInstruction(OpCodes.Ldarg_0), | ||
| new CodeInstruction(OpCodes.Callvirt, PropertyGetter(typeof(Scp1576Item), nameof(Scp1576Item.Owner))), | ||
| new CodeInstruction(OpCodes.Call, Method(typeof(API.Features.Player), nameof(API.Features.Player.Get), new[] { typeof(ReferenceHub) })), | ||
|
|
||
| // this | ||
| new CodeInstruction(OpCodes.Ldarg_0), | ||
|
|
||
| // Scp1576TransmissionEndedEventArgs ev = new(Player, this) | ||
| new CodeInstruction(OpCodes.Newobj, GetDeclaredConstructors(typeof(Scp1576TransmissionEndedEventArgs))[0]), | ||
|
|
||
| // OnScp1576TransmissionEnded(ev) | ||
| new CodeInstruction(OpCodes.Call, Method(typeof(Handlers.Player), nameof(Handlers.Player.OnScp1576TransmissionEnded))), | ||
| }); | ||
|
|
||
| for (int i = 0; i < newInstructions.Count; i++) | ||
| yield return newInstructions[i]; | ||
|
|
||
| ListPool<CodeInstruction>.Pool.Return(newInstructions); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.