Skip to content

Commit 07b17c2

Browse files
committed
Update that
1 parent 6ebeac5 commit 07b17c2

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace Exiled.Events.Patches.Events.Player
1313
using System;
1414
using System.Collections.Generic;
1515
using System.Linq;
16-
using System.Reflection;
1716
using System.Reflection.Emit;
1817

1918
using API.Enums;
@@ -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;
@@ -94,7 +93,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
9493
newInstructions.RemoveRange(index, 3);
9594
newInstructions.InsertRange(
9695
index,
97-
new CodeInstruction[]
96+
new[]
9897
{
9998
// GrantAllTickets(ev)
10099
new CodeInstruction(OpCodes.Ldloc, ev.LocalIndex).WithLabels(labels),
@@ -128,18 +127,22 @@ 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 CodeInstruction(OpCodes.Stloc_S, fpcRole.LocalIndex).WithLabels(newInstructions[i].labels);
142+
else if (opcode == OpCodes.Ldloc_0)
143+
newInstructions[i] = new CodeInstruction(OpCodes.Ldloc_S, fpcRole.LocalIndex).WithLabels(newInstructions[i].labels);
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++)
@@ -148,4 +151,4 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
148151
ListPool<CodeInstruction>.Pool.Return(newInstructions);
149152
}
150153
}
151-
}
154+
}

0 commit comments

Comments
 (0)