@@ -13,7 +13,6 @@ namespace Exiled.Events.Patches.Events.Player
13
13
using System ;
14
14
using System . Collections . Generic ;
15
15
using System . Linq ;
16
- using System . Reflection ;
17
16
using System . Reflection . Emit ;
18
17
19
18
using API . Enums ;
@@ -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 ;
@@ -94,7 +93,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
94
93
newInstructions . RemoveRange ( index , 3 ) ;
95
94
newInstructions . InsertRange (
96
95
index ,
97
- new CodeInstruction [ ]
96
+ new [ ]
98
97
{
99
98
// GrantAllTickets(ev)
100
99
new CodeInstruction ( OpCodes . Ldloc , ev . LocalIndex ) . WithLabels ( labels ) ,
@@ -128,18 +127,22 @@ 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 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 ;
143
146
}
144
147
145
148
for ( int z = 0 ; z < newInstructions . Count ; z ++ )
@@ -148,4 +151,4 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
148
151
ListPool < CodeInstruction > . Pool . Return ( newInstructions ) ;
149
152
}
150
153
}
151
- }
154
+ }
0 commit comments