Skip to content

Commit 8f5d098

Browse files
committed
Added support to SCPs for escaping-related events.
1 parent 7f55936 commit 8f5d098

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

EXILED/Exiled.Events/Patches/Events/Player/Escaping.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace Exiled.Events.Patches.Events.Player
99
{
1010
#pragma warning disable SA1402 // File may only contain a single type
11-
#pragma warning disable IDE0060
1211

1312
using System;
1413
using System.Collections.Generic;
@@ -23,7 +22,7 @@ namespace Exiled.Events.Patches.Events.Player
2322
using EventArgs.Player;
2423
using Exiled.Events.Attributes;
2524
using HarmonyLib;
26-
25+
using PlayerRoles.FirstPersonControl;
2726
using Respawning;
2827

2928
using static HarmonyLib.AccessTools;
@@ -128,23 +127,26 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
128127
{
129128
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);
130129

131-
int e = 0;
130+
LocalBuilder fpcRole = generator.DeclareLocal(typeof(FpcStandardRoleBase));
131+
132+
// replace HumanRole to FpcStandardRoleBase
133+
newInstructions.Find(x => x.opcode == OpCodes.Isinst).operand = typeof(FpcStandardRoleBase);
134+
135+
// after this index all invalid exit are considered Custom
136+
int customExit = newInstructions.FindLastIndex(x => x.opcode == OpCodes.Ldarg_0);
132137
for (int i = 0; i < newInstructions.Count; i++)
133138
{
134-
CodeInstruction codeInstruction = newInstructions[i];
135-
if (codeInstruction.opcode == OpCodes.Ldc_I4_0)
136-
{
137-
e++;
138-
if (e > 3)
139-
{
140-
newInstructions[i].opcode = OpCodes.Ldc_I4_5;
141-
}
142-
}
139+
OpCode opcode = newInstructions[i].opcode;
140+
if (opcode == OpCodes.Stloc_0)
141+
newInstructions[i] = new(OpCodes.Stloc_S, fpcRole.LocalIndex);
142+
else if (opcode == OpCodes.Ldloc_0)
143+
newInstructions[i] = new(OpCodes.Ldloc_S, fpcRole.LocalIndex);
144+
else if (opcode == OpCodes.Ldc_I4_0 && i > customExit)
145+
newInstructions[i].opcode = OpCodes.Ldc_I4_5;
143146
}
144147

145148
for (int z = 0; z < newInstructions.Count; z++)
146149
yield return newInstructions[z];
147-
148150
ListPool<CodeInstruction>.Pool.Return(newInstructions);
149151
}
150152
}

0 commit comments

Comments
 (0)