8
8
namespace Exiled . Events . Patches . Events . Player
9
9
{
10
10
#pragma warning disable SA1402 // File may only contain a single type
11
- #pragma warning disable IDE0060
12
11
13
12
using System ;
14
13
using System . Collections . Generic ;
@@ -23,7 +22,7 @@ namespace Exiled.Events.Patches.Events.Player
23
22
using EventArgs . Player ;
24
23
using Exiled . Events . Attributes ;
25
24
using HarmonyLib ;
26
-
25
+ using PlayerRoles . FirstPersonControl ;
27
26
using Respawning ;
28
27
29
28
using static HarmonyLib . AccessTools ;
@@ -128,23 +127,26 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
128
127
{
129
128
List < CodeInstruction > newInstructions = ListPool < CodeInstruction > . Pool . Get ( instructions ) ;
130
129
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 ) ;
132
137
for ( int i = 0 ; i < newInstructions . Count ; i ++ )
133
138
{
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 ;
143
146
}
144
147
145
148
for ( int z = 0 ; z < newInstructions . Count ; z ++ )
146
149
yield return newInstructions [ z ] ;
147
-
148
150
ListPool < CodeInstruction > . Pool . Return ( newInstructions ) ;
149
151
}
150
152
}
0 commit comments