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.
- Loading branch information
Showing
14 changed files
with
194 additions
and
14 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
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
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
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
57 changes: 57 additions & 0 deletions
57
EXILED/Exiled.Events/EventArgs/Scp939/PlayingFootstepEventArgs.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,57 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="PlayingFootstepEventArgs.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.Scp939 | ||
{ | ||
using API.Features; | ||
using Exiled.API.Features.Roles; | ||
using Interfaces; | ||
|
||
/// <summary> | ||
/// Contains all information before the footsteps are being shown to SCP-939. | ||
/// </summary> | ||
public class PlayingFootstepEventArgs : IScp939Event, IDeniableEvent | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PlayingFootstepEventArgs" /> class. | ||
/// </summary> | ||
/// <param name="player"> | ||
/// The player who's controlling SCP-939. | ||
/// </param> | ||
/// <param name="target"> | ||
/// The player who's being shown to SCP-939. | ||
/// </param> | ||
/// <param name="isAllowed"> | ||
/// Indicates whether the footstep action is allowed. | ||
/// </param> | ||
public PlayingFootstepEventArgs(Player target, Player player, bool isAllowed = true) | ||
{ | ||
Player = player; | ||
Scp939 = Player.Role.As<Scp939Role>(); | ||
Target = target; | ||
IsAllowed = isAllowed; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the player who's controlling SCP-939. | ||
/// </summary> | ||
public Player Player { get; } | ||
|
||
/// <inheritdoc/> | ||
public Scp939Role Scp939 { get; } | ||
|
||
/// <summary> | ||
/// Gets the player who's being shown to SCP-939. | ||
/// </summary> | ||
public Player Target { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether footsteps are visible. | ||
/// </summary> | ||
public bool IsAllowed { get; set; } | ||
} | ||
} |
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
79 changes: 79 additions & 0 deletions
79
EXILED/Exiled.Events/Patches/Events/Scp939/PlayingFootstep.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,79 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="PlayingFootstep.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.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.FirstPersonControl.Thirdperson; | ||
using PlayerRoles.PlayableScps.Scp939; | ||
using PlayerRoles.PlayableScps.Scp939.Ripples; | ||
using PlayerRoles.Subroutines; | ||
|
||
using static HarmonyLib.AccessTools; | ||
|
||
/// <summary> | ||
/// Patches <see cref="FootstepRippleTrigger.OnFootstepPlayed(AnimatedCharacterModel, float)" /> | ||
/// to add the <see cref="Scp939.PlayingFootstep" /> event. | ||
/// </summary> | ||
[EventPatch(typeof(Scp939), nameof(Scp939.PlayingFootstep))] | ||
[HarmonyPatch(typeof(FootstepRippleTrigger), nameof(FootstepRippleTrigger.OnFootstepPlayed))] | ||
internal static class PlayingFootstep | ||
{ | ||
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) | ||
{ | ||
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions); | ||
|
||
Label ret = generator.DefineLabel(); | ||
|
||
int offset = 3; | ||
int index = newInstructions.FindLastIndex(i => i.Calls(Method(typeof(RippleTriggerBase), nameof(RippleTriggerBase.CheckVisibility)))) + offset; | ||
|
||
newInstructions.InsertRange(index, new CodeInstruction[] | ||
{ | ||
// Player target = Player.Get(characterModel.OwnerHub); | ||
new CodeInstruction(OpCodes.Ldarg_1).MoveLabelsFrom(newInstructions[index]), | ||
new(OpCodes.Callvirt, PropertyGetter(typeof(CharacterModel), nameof(CharacterModel.OwnerHub))), | ||
new(OpCodes.Call, Method(typeof(API.Features.Player), nameof(API.Features.Player.Get), new[] { typeof(ReferenceHub) })), | ||
|
||
// Player player = Player.Get(this.Owner); | ||
new(OpCodes.Ldarg_0), | ||
new(OpCodes.Call, PropertyGetter(typeof(StandardSubroutine<Scp939Role>), nameof(StandardSubroutine<Scp939Role>.Owner))), | ||
new(OpCodes.Call, Method(typeof(API.Features.Player), nameof(API.Features.Player.Get), new[] { typeof(ReferenceHub) })), | ||
|
||
// true; | ||
new(OpCodes.Ldc_I4_1), | ||
|
||
// PlayingFootstepEventArgs ev = (player, scp939, true); | ||
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(PlayingFootstepEventArgs))[0]), | ||
new(OpCodes.Dup), | ||
|
||
// Handlers.Scp939.OnPlayingFootstep(ev); | ||
new(OpCodes.Call, Method(typeof(Scp939), nameof(Scp939.OnPlayingFootstep))), | ||
|
||
// if (!IsAllowed) | ||
// return; | ||
new(OpCodes.Callvirt, PropertyGetter(typeof(PlayingFootstepEventArgs), nameof(PlayingFootstepEventArgs.IsAllowed))), | ||
new(OpCodes.Brfalse_S, ret), | ||
}); | ||
|
||
newInstructions[newInstructions.Count - 1].labels.Add(ret); | ||
|
||
for (int z = 0; z < newInstructions.Count; z++) | ||
yield return newInstructions[z]; | ||
|
||
ListPool<CodeInstruction>.Pool.Return(newInstructions); | ||
} | ||
} | ||
} |
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