@@ -25,7 +25,7 @@ namespace Exiled.Events.Patches.Events.Player
25
25
using static HarmonyLib . AccessTools ;
26
26
27
27
/// <summary>
28
- /// Patches <see cref="InventoryExtensions.ServerAddItem(Inventory, ItemType, ushort, ItemPickupBase)"/>.
28
+ /// Patches <see cref="InventoryExtensions.ServerAddItem(Inventory, ItemType, ItemAddReason, ushort, ItemPickupBase)"/>.
29
29
/// Adds the <see cref="Handlers.Player.AddingItem"/> event.
30
30
/// </summary>
31
31
[ EventPatch ( typeof ( Handlers . Player ) , nameof ( Handlers . Player . AddingItem ) ) ]
@@ -40,28 +40,34 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
40
40
int index = newInstructions . FindIndex ( i => i . opcode == OpCodes . Ldarg_3 ) + offset ;
41
41
42
42
Label ret = generator . DefineLabel ( ) ;
43
+ LocalBuilder ev = generator . DeclareLocal ( typeof ( AddingItemEventArgs ) ) ;
43
44
44
- newInstructions . InsertRange ( index , new CodeInstruction [ ]
45
+ newInstructions . InsertRange ( index , new [ ]
45
46
{
46
47
new CodeInstruction ( OpCodes . Ldarg_0 ) . MoveLabelsFrom ( newInstructions [ index ] ) ,
47
48
new ( OpCodes . Ldfld , Field ( typeof ( Inventory ) , nameof ( Inventory . _hub ) ) ) ,
48
49
new ( OpCodes . Call , Method ( typeof ( Player ) , nameof ( Player . Get ) , new [ ] { typeof ( ReferenceHub ) } ) ) ,
49
50
new ( OpCodes . Ldloc_1 ) ,
50
51
new ( OpCodes . Call , Method ( typeof ( Item ) , nameof ( Item . Get ) , new [ ] { typeof ( ItemBase ) } ) ) ,
51
- new ( OpCodes . Ldarg_3 ) ,
52
+ new ( OpCodes . Ldarg_S , 4 ) ,
52
53
new ( OpCodes . Call , Method ( typeof ( Pickup ) , nameof ( Pickup . Get ) , new [ ] { typeof ( ItemPickupBase ) } ) ) ,
53
54
new ( OpCodes . Ldc_I4_1 ) ,
54
55
new ( OpCodes . Newobj , GetDeclaredConstructors ( typeof ( AddingItemEventArgs ) ) [ 0 ] ) ,
55
56
new ( OpCodes . Dup ) ,
57
+ new ( OpCodes . Dup ) ,
58
+ new ( OpCodes . Stloc_S , ev . LocalIndex ) ,
56
59
new ( OpCodes . Call , Method ( typeof ( Handlers . Player ) , nameof ( Handlers . Player . OnAddingItem ) ) ) ,
57
60
new ( OpCodes . Callvirt , PropertyGetter ( typeof ( AddingItemEventArgs ) , nameof ( AddingItemEventArgs . IsAllowed ) ) ) ,
58
61
new ( OpCodes . Brfalse_S , ret ) ,
62
+ new ( OpCodes . Ldloc_S , ev . LocalIndex ) ,
63
+ new ( OpCodes . Callvirt , PropertyGetter ( typeof ( AddingItemEventArgs ) , nameof ( AddingItemEventArgs . AddReason ) ) ) ,
64
+ new ( OpCodes . Starg_S , 3 ) ,
59
65
} ) ;
60
66
61
67
newInstructions [ newInstructions . Count - 1 ] . labels . Add ( ret ) ;
62
68
63
- for ( int z = 0 ; z < newInstructions . Count ; z ++ )
64
- yield return newInstructions [ z ] ;
69
+ foreach ( CodeInstruction instruction in newInstructions )
70
+ yield return instruction ;
65
71
66
72
ListPool < CodeInstruction > . Pool . Return ( newInstructions ) ;
67
73
}
0 commit comments