Skip to content

Commit

Permalink
fix: ModifyEventNameBeforeRelease and Added new argument (#407)
Browse files Browse the repository at this point in the history
ModifyEventBeforeRelease
  • Loading branch information
louis1706 authored Jan 20, 2025
1 parent 7b0213b commit 8375829
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// -----------------------------------------------------------------------
// <copyright file="CreatedAmnesticCloudEventArgs.cs" company="ExMod Team">
// <copyright file="UpdatedCloudStateEventArgs.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
Expand All @@ -18,20 +18,23 @@ namespace Exiled.Events.EventArgs.Scp939
using Scp939Role = API.Features.Roles.Scp939Role;

/// <summary>
/// Contains all information after SCP-939 fully created target <see cref="PlacedAmnesticCloudEventArgs"/>.
/// Contains all information after <see cref="PlacedAmnesticCloudEventArgs"/> got updated state.
/// </summary>
public class CreatedAmnesticCloudEventArgs : IScp939Event, IHazardEvent
public class UpdatedCloudStateEventArgs : IScp939Event, IHazardEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="CreatedAmnesticCloudEventArgs" /> class.
/// Initializes a new instance of the <see cref="UpdatedCloudStateEventArgs" /> class.
/// </summary>
/// <param name="hub">
/// <inheritdoc cref="ReferenceHub" />
/// </param>
/// <param name="cloudState">
/// <inheritdoc cref="Scp939AmnesticCloudInstance.CloudState" />
/// </param>
/// <param name="cloud">
/// <inheritdoc cref="PlayerRoles.PlayableScps.Scp939.Scp939AmnesticCloudInstance" />
/// <inheritdoc cref="Scp939AmnesticCloudInstance" />
/// </param>
public CreatedAmnesticCloudEventArgs(ReferenceHub hub, Scp939AmnesticCloudInstance cloud)
public UpdatedCloudStateEventArgs(ReferenceHub hub, Scp939AmnesticCloudInstance.CloudState cloudState, Scp939AmnesticCloudInstance cloud)
{
Player = Player.Get(hub);
AmnesticCloud = Hazard.Get<AmnesticCloudHazard>(cloud);
Expand All @@ -46,6 +49,11 @@ public CreatedAmnesticCloudEventArgs(ReferenceHub hub, Scp939AmnesticCloudInstan
/// </summary>
public AmnesticCloudHazard AmnesticCloud { get; }

/// <summary>
/// Gets the <see cref="Scp939AmnesticCloudInstance.CloudState"/>.
/// </summary>
public Scp939AmnesticCloudInstance.CloudState NewState { get; }

/// <inheritdoc/>
public Scp939Role Scp939 { get; }

Expand Down
10 changes: 5 additions & 5 deletions EXILED/Exiled.Events/Handlers/Scp939.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public static class Scp939
public static Event<PlacedAmnesticCloudEventArgs> PlacedAmnesticCloud { get; set; } = new();

/// <summary>
/// Invoked after SCP-939 fully spawned <see cref="AmnesticCloudHazard"/>.
/// Invoked after SCP-939 <see cref="AmnesticCloudHazard"/> is state updated.
/// </summary>
public static Event<CreatedAmnesticCloudEventArgs> CreatedAmnesticCloud { get; set; } = new();
public static Event<UpdatedCloudStateEventArgs> UpdatedCloudState { get; set; } = new();

/// <summary>
/// Invoked before SCP-939 plays a stolen voice.
Expand Down Expand Up @@ -99,10 +99,10 @@ public static class Scp939
public static void OnPlacedAmnesticCloud(PlacedAmnesticCloudEventArgs ev) => PlacedAmnesticCloud.InvokeSafely(ev);

/// <summary>
/// Called after SCP-939 fully spawned <see cref="AmnesticCloudHazard"/>.
/// Called after <see cref="AmnesticCloudHazard"/> is state updated.
/// </summary>
/// <param name="ev">The <see cref="CreatedAmnesticCloudEventArgs" /> instance.</param>
public static void OnCreatedAmnesticCloud(CreatedAmnesticCloudEventArgs ev) => CreatedAmnesticCloud.InvokeSafely(ev);
/// <param name="ev">The <see cref="UpdatedCloudStateEventArgs" /> instance.</param>
public static void OnUpdatedCloudState(UpdatedCloudStateEventArgs ev) => UpdatedCloudState.InvokeSafely(ev);

/// <summary>
/// Called before SCP-939 plays a stolen voice.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ namespace Exiled.Events.Patches.Events.Scp939

/// <summary>
/// Patches <see cref="Scp939AmnesticCloudInstance.State" /> setter.
/// to add the <see cref="Scp939.CreatedAmnesticCloud" /> event.
/// to add the <see cref="Scp939.UpdatedCloudState" /> event.
/// </summary>
[EventPatch(typeof(Scp939), nameof(Scp939.CreatedAmnesticCloud))]
[EventPatch(typeof(Scp939), nameof(Scp939.UpdatedCloudState))]
[HarmonyPatch(typeof(Scp939AmnesticCloudInstance), nameof(Scp939AmnesticCloudInstance.State), MethodType.Setter)]
internal static class CreatedAmnesticCloud
{
Expand All @@ -52,12 +52,15 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
// owner
new(OpCodes.Ldloc_S, hub.LocalIndex),

// CloudState
new(OpCodes.Ldarg_1),

// this
new(OpCodes.Ldarg_0),

// Scp939.OnCreatedAmnesticCloud(new CreatedAmnesticCloudEventArgs(owner, this));
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(CreatedAmnesticCloudEventArgs))[0]),
new(OpCodes.Call, Method(typeof(Scp939), nameof(Scp939.OnCreatedAmnesticCloud))),
// Scp939.OnCreatedAmnesticCloud(new UpdatedCloudStateEventArgs(owner, CloudState, this));
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(UpdatedCloudStateEventArgs))[0]),
new(OpCodes.Call, Method(typeof(Scp939), nameof(Scp939.OnUpdatedCloudState))),
});

newInstructions[newInstructions.Count - 1].labels.Add(ret);
Expand Down

0 comments on commit 8375829

Please sign in to comment.