Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
VALERA771 committed Aug 12, 2024
1 parent e2f58c5 commit 2147c94
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions EXILED/Exiled.Events/Patches/Events/Player/EscapingAndEscaped.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Exiled.Events.Patches.Events.Player
{
#pragma warning disable SA1402 // File may only contain a single type
#pragma warning disable IDE0060

using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -22,6 +23,7 @@ namespace Exiled.Events.Patches.Events.Player
using Exiled.API.Features.Roles;
using Exiled.Events.Attributes;
using HarmonyLib;
using PlayerRoles.FirstPersonControl;
using Respawning;

using static HarmonyLib.AccessTools;
Expand Down Expand Up @@ -164,18 +166,22 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

int e = 0;
LocalBuilder fpcRole = generator.DeclareLocal(typeof(FpcStandardRoleBase));

// replace HumanRole to FpcStandardRoleBase
newInstructions.Find(x => x.opcode == OpCodes.Isinst).operand = typeof(FpcStandardRoleBase);

// after this index all invalid exit are considered Custom
int customExit = newInstructions.FindLastIndex(x => x.opcode == OpCodes.Ldarg_0);
for (int i = 0; i < newInstructions.Count; i++)
{
CodeInstruction codeInstruction = newInstructions[i];
if (codeInstruction.opcode == OpCodes.Ldc_I4_0)
{
e++;
if (e > 3)
{
newInstructions[i].opcode = OpCodes.Ldc_I4_5;
}
}
OpCode opcode = newInstructions[i].opcode;
if (opcode == OpCodes.Stloc_0)
newInstructions[i] = new CodeInstruction(OpCodes.Stloc_S, fpcRole.LocalIndex).WithLabels(newInstructions[i].labels);
else if (opcode == OpCodes.Ldloc_0)
newInstructions[i] = new CodeInstruction(OpCodes.Ldloc_S, fpcRole.LocalIndex).WithLabels(newInstructions[i].labels);
else if (opcode == OpCodes.Ldc_I4_0 && i > customExit)
newInstructions[i].opcode = OpCodes.Ldc_I4_5;
}

for (int z = 0; z < newInstructions.Count; z++)
Expand Down

0 comments on commit 2147c94

Please sign in to comment.