forked from ExMod-Team/EXILED
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: PR133 Squashed Scp939EventChange (ExMod-Team#401)
PR133 Squashed Scp939EventChange
- Loading branch information
Showing
7 changed files
with
350 additions
and
26 deletions.
There are no files selected for viewing
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,47 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="Scp939VisibilityStates.cs" company="ExMod Team"> | ||
// Copyright (c) ExMod Team. All rights reserved. | ||
// Licensed under the CC BY-SA 3.0 license. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
namespace Exiled.API.Enums | ||
{ | ||
using Features.Roles; | ||
|
||
/// <summary> | ||
/// Unique identifier for a <see cref="Scp939Role"/>. | ||
/// </summary> | ||
public enum Scp939VisibilityState | ||
{ | ||
/// <summary> | ||
/// SCP-939 doesnt see an other player, by default FPC role logic. | ||
/// </summary> | ||
None, | ||
|
||
/// <summary> | ||
/// SCP-939 doesnt see an player, by basic SCP-939 logic. | ||
/// </summary> | ||
NotSeen, | ||
|
||
/// <summary> | ||
/// SCP-939 sees an other player, who is teammate SCP. | ||
/// </summary> | ||
SeenAsScp, | ||
|
||
/// <summary> | ||
/// SCP-939 sees an other player due the Alpha Warhead detonation. | ||
/// </summary> | ||
SeenByDetonation, | ||
|
||
/// <summary> | ||
/// SCP-939 sees an other player, due the base-game vision range logic. | ||
/// </summary> | ||
SeenByRange, | ||
|
||
/// <summary> | ||
/// SCP-939 sees an other player for a while, after it's out of range. | ||
/// </summary> | ||
SeenByLastTime, | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
EXILED/Exiled.Events/EventArgs/Scp939/CreatedAmnesticCloudEventArgs.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,55 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="CreatedAmnesticCloudEventArgs.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.Scp939 | ||
{ | ||
using API.Features; | ||
|
||
using Exiled.API.Features.Hazards; | ||
using Exiled.API.Features.Roles; | ||
using Interfaces; | ||
|
||
using PlayerRoles.PlayableScps.Scp939; | ||
|
||
using Scp939Role = API.Features.Roles.Scp939Role; | ||
|
||
/// <summary> | ||
/// Contains all information after SCP-939 fully created target <see cref="PlacedAmnesticCloudEventArgs"/>. | ||
/// </summary> | ||
public class CreatedAmnesticCloudEventArgs : IScp939Event, IHazardEvent | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CreatedAmnesticCloudEventArgs" /> class. | ||
/// </summary> | ||
/// <param name="hub"> | ||
/// <inheritdoc cref="ReferenceHub" /> | ||
/// </param> | ||
/// <param name="cloud"> | ||
/// <inheritdoc cref="PlayerRoles.PlayableScps.Scp939.Scp939AmnesticCloudInstance" /> | ||
/// </param> | ||
public CreatedAmnesticCloudEventArgs(ReferenceHub hub, Scp939AmnesticCloudInstance cloud) | ||
{ | ||
Player = Player.Get(hub); | ||
AmnesticCloud = Hazard.Get<AmnesticCloudHazard>(cloud); | ||
Scp939 = Player.Role.As<Scp939Role>(); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public Player Player { get; } | ||
|
||
/// <summary> | ||
/// Gets the <see cref="AmnesticCloudHazard"/> instance. | ||
/// </summary> | ||
public AmnesticCloudHazard AmnesticCloud { get; } | ||
|
||
/// <inheritdoc/> | ||
public Scp939Role Scp939 { get; } | ||
|
||
/// <inheritdoc/> | ||
public Hazard Hazard => AmnesticCloud; | ||
} | ||
} |
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
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
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
71 changes: 71 additions & 0 deletions
71
EXILED/Exiled.Events/Patches/Events/Scp939/CreatedAmnesticCloud.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,71 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="CreatedAmnesticCloud.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.Scp939 | ||
{ | ||
using System.Collections.Generic; | ||
using System.Reflection.Emit; | ||
|
||
using Exiled.API.Features.Pools; | ||
using Exiled.Events.Attributes; | ||
using Exiled.Events.EventArgs.Scp939; | ||
using Exiled.Events.Handlers; | ||
|
||
using HarmonyLib; | ||
|
||
using PlayerRoles.PlayableScps.Scp939; | ||
|
||
using static HarmonyLib.AccessTools; | ||
|
||
/// <summary> | ||
/// Patches <see cref="Scp939AmnesticCloudInstance.State" /> setter. | ||
/// to add the <see cref="Scp939.CreatedAmnesticCloud" /> event. | ||
/// </summary> | ||
[EventPatch(typeof(Scp939), nameof(Scp939.CreatedAmnesticCloud))] | ||
[HarmonyPatch(typeof(Scp939AmnesticCloudInstance), nameof(Scp939AmnesticCloudInstance.State), MethodType.Setter)] | ||
internal static class CreatedAmnesticCloud | ||
{ | ||
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) | ||
{ | ||
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions); | ||
|
||
LocalBuilder hub = generator.DeclareLocal(typeof(ReferenceHub)); | ||
|
||
Label ret = generator.DefineLabel(); | ||
|
||
newInstructions.InsertRange( | ||
newInstructions.Count - 1, | ||
new[] | ||
{ | ||
// if (!ReferenceHub.TryGetHubNetID(_syncOwner, out ReferenceHub owner)) | ||
// return; | ||
new CodeInstruction(OpCodes.Ldarg_0), | ||
new(OpCodes.Ldfld, Field(typeof(Scp939AmnesticCloudInstance), nameof(Scp939AmnesticCloudInstance._syncOwner))), | ||
new(OpCodes.Ldloca_S, hub.LocalIndex), | ||
new(OpCodes.Call, Method(typeof(ReferenceHub), nameof(ReferenceHub.TryGetHubNetID))), | ||
new(OpCodes.Brfalse_S, ret), | ||
|
||
// owner | ||
new(OpCodes.Ldloc_S, hub.LocalIndex), | ||
|
||
// 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))), | ||
}); | ||
|
||
newInstructions[newInstructions.Count - 1].labels.Add(ret); | ||
|
||
for (int z = 0; z < newInstructions.Count; z++) | ||
yield return newInstructions[z]; | ||
|
||
ListPool<CodeInstruction>.Pool.Return(newInstructions); | ||
} | ||
} | ||
} |
Oops, something went wrong.