Skip to content

Commit 03d563c

Browse files
authored
fix: TargetVisibilityState returing only None & SeenByDetonation (#841)
1 parent adb99a2 commit 03d563c

3 files changed

Lines changed: 19 additions & 11 deletions

File tree

EXILED/Exiled.API/Enums/Scp939VisibilityStates.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,10 @@ public enum Scp939VisibilityState
4343
/// SCP-939 sees another player for a while, after it's out of range.
4444
/// </summary>
4545
SeenByLastTime,
46+
47+
/// <summary>
48+
/// SCP-939 sees another player, who is the last human player in the round.
49+
/// </summary>
50+
SeenByLastHuman,
4651
}
4752
}

EXILED/Exiled.Events/EventArgs/Scp939/ValidatingVisibilityEventArgs.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// -----------------------------------------------------------------------
1+
// -----------------------------------------------------------------------
22
// <copyright file="ValidatingVisibilityEventArgs.cs" company="ExMod Team">
33
// Copyright (c) ExMod Team. All rights reserved.
44
// Licensed under the CC BY-SA 3.0 license.
@@ -11,8 +11,11 @@ namespace Exiled.Events.EventArgs.Scp939
1111

1212
using Exiled.API.Enums;
1313
using Exiled.API.Features.Roles;
14+
1415
using Interfaces;
1516

17+
using PlayerRoles.PlayableScps.HumanTracker;
18+
1619
/// <summary>
1720
/// Contains all information before SCP-939 sees the player.
1821
/// </summary>
@@ -35,7 +38,11 @@ public ValidatingVisibilityEventArgs(Scp939VisibilityState state, ReferenceHub p
3538
Player = Player.Get(player);
3639
Scp939 = Player.Role.As<Scp939Role>();
3740
Target = Player.Get(target);
38-
TargetVisibilityState = state;
41+
TargetVisibilityState = state switch
42+
{
43+
Scp939VisibilityState.SeenByDetonation when !Warhead.IsDetonated && LastHumanTracker.IsLastTarget(target) => Scp939VisibilityState.SeenByLastHuman,
44+
_ => state,
45+
};
3946
IsAllowed = TargetVisibilityState is not(Scp939VisibilityState.NotSeen or Scp939VisibilityState.None);
4047
IsLateSeen = TargetVisibilityState is Scp939VisibilityState.SeenByRange;
4148
}

EXILED/Exiled.Events/Patches/Events/Scp939/ValidatingVisibility.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,22 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
4444
Label ret = generator.DefineLabel();
4545
Label end = generator.DefineLabel();
4646

47-
int offset = 0;
48-
int index = newInstructions.FindIndex(i => i.LoadsConstant(0)) + offset;
47+
int index = newInstructions.FindIndex(i => i.LoadsConstant(0));
4948

5049
newInstructions[index].labels.Add(ret);
5150

5251
newInstructions.InsertRange(index, StaticCallEvent(generator, ev, ret, newInstructions[index], Scp939VisibilityState.None, false));
5352

54-
offset = 0;
55-
index = newInstructions.FindIndex(i => i.LoadsConstant(1)) + offset;
53+
index = newInstructions.FindIndex(i => i.LoadsConstant(1));
5654

5755
newInstructions.InsertRange(index, StaticCallEvent(generator, ev, ret, newInstructions[index], Scp939VisibilityState.SeenAsScp));
5856

59-
offset = 2;
57+
int offset = 4;
6058
index = newInstructions.FindIndex(i => i.Calls(PropertyGetter(typeof(AlphaWarheadController), nameof(AlphaWarheadController.Detonated)))) + offset;
6159

6260
newInstructions.InsertRange(index, StaticCallEvent(generator, ev, ret, newInstructions[index], Scp939VisibilityState.SeenByDetonation));
6361

64-
offset = 0;
65-
index = newInstructions.FindLastIndex(i => i.opcode == OpCodes.Ldloc_3) + offset;
62+
index = newInstructions.FindLastIndex(i => i.opcode == OpCodes.Ldloc_3);
6663

6764
// just pre-check for SeenByLastTime or NotSeen VisibilityState, and then il inject
6865
newInstructions.InsertRange(index, Enumerable.Concat(
@@ -77,8 +74,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
7774
},
7875
CallEvent(generator, ev, ret)));
7976

80-
offset = 0;
81-
index = newInstructions.FindLastIndex(i => i.LoadsField(Field(typeof(Scp939VisibilityController), nameof(Scp939VisibilityController.LastSeen)))) + offset;
77+
index = newInstructions.FindLastIndex(i => i.LoadsField(Field(typeof(Scp939VisibilityController), nameof(Scp939VisibilityController.LastSeen))));
8278

8379
newInstructions.InsertRange(index, StaticCallEvent(generator, ev, ret, newInstructions[index], Scp939VisibilityState.SeenByRange));
8480

0 commit comments

Comments
 (0)