Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions EXILED/Exiled.Events/EventArgs/Scp106/StalkingEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ public class StalkingEventArgs : IScp106Event, IDeniableEvent
/// Initializes a new instance of the <see cref="StalkingEventArgs"/> class.
/// </summary>
/// <param name="player"><inheritdoc cref="Player"/></param>
/// <param name="isAllowed"><inheritdoc cref="IsAllowed"/></param>
public StalkingEventArgs(Player player, bool isAllowed = true)
public StalkingEventArgs(Player player)
{
Player = player;
Scp106 = player.Role.As<Scp106Role>();
IsAllowed = isAllowed;
IsAllowed = true;
MinimumVigor = Scp106StalkAbility.MinVigorToSubmerge;
}

Expand Down Expand Up @@ -66,6 +65,7 @@ public float Vigor
/// <summary>
/// Gets or sets a value indicating whether SCP-106 can stalk.
/// </summary>
/// <remarks>IsAllowed doesn't indicate whether vigor is sufficient for Stalking. <see cref="MinimumVigor"></see> needs to be changed to override the base game check.</remarks>
public bool IsAllowed { get; set; }
}
}
43 changes: 7 additions & 36 deletions EXILED/Exiled.Events/Patches/Events/Scp106/Stalking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,48 +36,19 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
LocalBuilder ev = generator.DeclareLocal(typeof(StalkingEventArgs));

Label returnLabel = generator.DefineLabel();
int offset = 2;
int index = newInstructions.FindIndex(instruction => instruction.operand == (object)PropertyGetter(typeof(Scp106StalkAbility), nameof(Scp106StalkAbility.StalkActive))) + offset;
int offset = -1;
int index = newInstructions.FindIndex(instruction => instruction.Calls(PropertyGetter(typeof(Scp106VigorAbilityBase), nameof(Scp106VigorAbilityBase.VigorAmount)))) + offset;
newInstructions.InsertRange(
index,
new CodeInstruction[]
{
// Inserted before vigor amount check
// Player.Get(this.Owner);
new CodeInstruction(OpCodes.Ldarg_0).MoveLabelsFrom(newInstructions[index]),
new(OpCodes.Callvirt, PropertyGetter(typeof(Scp106HuntersAtlasAbility), nameof(Scp106HuntersAtlasAbility.Owner))),
new(OpCodes.Callvirt, PropertyGetter(typeof(Scp106StalkAbility), nameof(Scp106StalkAbility.Owner))),
new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),

// true
new(OpCodes.Ldc_I4_1),

// StalkingEventArgs ev = new(Player, isAllowed)
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(StalkingEventArgs))[0]),
new(OpCodes.Dup),
new(OpCodes.Dup),
new(OpCodes.Stloc_S, ev.LocalIndex),

// Handlers.Scp106.OnFinishingRecall(ev)
new(OpCodes.Call, Method(typeof(Handlers.Scp106), nameof(Handlers.Scp106.OnStalking))),

// if (!ev.IsAllowed)
// return;
new(OpCodes.Callvirt, PropertyGetter(typeof(StalkingEventArgs), nameof(StalkingEventArgs.IsAllowed))),
new(OpCodes.Brfalse_S, returnLabel),
});

newInstructions.InsertRange(
newInstructions.Count - 1,
new CodeInstruction[]
{
// Player.Get(this.Owner);
new CodeInstruction(OpCodes.Ldarg_0).MoveLabelsFrom(newInstructions[index]),
new(OpCodes.Callvirt, PropertyGetter(typeof(Scp106HuntersAtlasAbility), nameof(Scp106HuntersAtlasAbility.Owner))),
new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),

// true
new(OpCodes.Ldc_I4_1),

// StalkingEventArgs ev = new(Player, isAllowed)
// StalkingEventArgs ev = new(Player)
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(StalkingEventArgs))[0]),
new(OpCodes.Dup),
new(OpCodes.Dup),
Expand All @@ -87,7 +58,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Call, Method(typeof(Handlers.Scp106), nameof(Handlers.Scp106.OnStalking))),

// if (!ev.IsAllowed)
// return;
// return
new(OpCodes.Callvirt, PropertyGetter(typeof(StalkingEventArgs), nameof(StalkingEventArgs.IsAllowed))),
new(OpCodes.Brfalse_S, returnLabel),
});
Expand All @@ -106,7 +77,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Callvirt, PropertyGetter(typeof(StalkingEventArgs), nameof(StalkingEventArgs.MinimumVigor))),
});

newInstructions[newInstructions.Count - 1].WithLabels(returnLabel);
newInstructions[newInstructions.Count - 1].labels.Add(returnLabel);

for (int z = 0; z < newInstructions.Count; z++)
yield return newInstructions[z];
Expand Down