diff --git a/EXILED/Exiled.API/Features/Player.cs b/EXILED/Exiled.API/Features/Player.cs index e9e0f5a3e6..ea317a5d5d 100644 --- a/EXILED/Exiled.API/Features/Player.cs +++ b/EXILED/Exiled.API/Features/Player.cs @@ -2924,6 +2924,8 @@ public Item AddItem(ItemBase itemBase, Item item = null, ItemAddReason addReason Inventory.UserInventory.Items[item.Serial] = itemBase; + typeof(InventoryExtensions).InvokeStaticEvent(nameof(InventoryExtensions.OnItemAdded), new object[] { ReferenceHub, itemBase, null }); + item.ChangeOwner(item.Owner, this); if (itemBase is IAcquisitionConfirmationTrigger acquisitionConfirmationTrigger) @@ -2931,8 +2933,6 @@ public Item AddItem(ItemBase itemBase, Item item = null, ItemAddReason addReason acquisitionConfirmationTrigger.AcquisitionAlreadyReceived = false; } - typeof(InventoryExtensions).InvokeStaticEvent(nameof(InventoryExtensions.OnItemAdded), new object[] { ReferenceHub, itemBase, null }); - Inventory.SendItemsNextFrame = true; return item; } diff --git a/EXILED/Exiled.Events/Patches/Fixes/FixOnAddedBeingCallAfterOnRemoved.cs b/EXILED/Exiled.Events/Patches/Fixes/FixOnAddedBeingCallAfterOnRemoved.cs index 7b432fefce..95ec63e4cc 100644 --- a/EXILED/Exiled.Events/Patches/Fixes/FixOnAddedBeingCallAfterOnRemoved.cs +++ b/EXILED/Exiled.Events/Patches/Fixes/FixOnAddedBeingCallAfterOnRemoved.cs @@ -37,16 +37,8 @@ private static IEnumerable Transpiler(IEnumerable newInstructions = ListPool.Pool.Get(instructions); - Label continueLabel = generator.DefineLabel(); - - int offset = -1; - int index = newInstructions.FindLastIndex(instruction => instruction.Calls(PropertyGetter(typeof(NetworkBehaviour), nameof(NetworkBehaviour.isLocalPlayer)))) + offset; - - // set label for code right after OnAdded/OnItemAdded, to skip that part for ammo - Label afterAmmoLabel = newInstructions[index].labels[0]; - - offset = -2; - index = newInstructions.FindIndex(instruction => instruction.Calls(Method(typeof(ItemBase), nameof(ItemBase.OnAdded)))) + offset; + int offset = -2; + int index = newInstructions.FindIndex(instruction => instruction.Calls(Method(typeof(ItemBase), nameof(ItemBase.OnAdded)))) + offset; newInstructions.InsertRange( index, @@ -56,26 +48,40 @@ private static IEnumerable Transpiler(IEnumerable onItemAdded = InventoryExtensions.OnItemAdded; + if (onItemAdded != null) + { + onItemAdded(inv._hub, itemBase2, pickup); + } + // To this + Action onItemAdded = InventoryExtensions.OnItemAdded; + if (onItemAdded != null) + { + onItemAdded(inv._hub, itemBase2, pickup); + } + itemBase2.OnAdded(pickup); + */ + int opCodesToMove = 3; + offset = -2; - // move after basegame OnAdded/OnItemAdded - new(OpCodes.Br_S, afterAmmoLabel), + int indexOnAdded = newInstructions.FindIndex(instruction => instruction.Calls(Method(typeof(ItemBase), nameof(ItemBase.OnAdded)))) + offset; + offset = 1; - new CodeInstruction(OpCodes.Nop).WithLabels(continueLabel), - }); + int indexInvoke = newInstructions.FindIndex(instruction => instruction.Calls(Method(typeof(Action), nameof(Action.Invoke)))) + offset; + + // insert new OnAdded before the Event InventoryExtensions.OnItemAdded + newInstructions.InsertRange(indexInvoke, newInstructions.GetRange(indexOnAdded, opCodesToMove)); + + // move Label to not skip the OnAdded + newInstructions[indexInvoke].MoveLabelsFrom(newInstructions[indexInvoke + opCodesToMove]); + + // remove the old OnAdded + newInstructions.RemoveRange(indexOnAdded, opCodesToMove); for (int z = 0; z < newInstructions.Count; z++) yield return newInstructions[z]; @@ -83,12 +89,6 @@ private static IEnumerable Transpiler(IEnumerable.Pool.Return(newInstructions); } - private static void InverseCall(ItemBase item, ReferenceHub referenceHub, ItemPickupBase pickup) - { - Exiled.API.Extensions.ReflectionExtensions.InvokeStaticEvent(typeof(InventoryExtensions), nameof(InventoryExtensions.OnItemAdded), new object[] { referenceHub, item, pickup }); - item.OnAdded(pickup); - } - private static void CallBefore(ItemBase itemBase, ItemPickupBase pickupBase) { Item item = Item.Get(itemBase); diff --git a/EXILED/Exiled.Loader/AutoUpdateFiles.cs b/EXILED/Exiled.Loader/AutoUpdateFiles.cs index 990fa0ca9f..a4e454cb3a 100644 --- a/EXILED/Exiled.Loader/AutoUpdateFiles.cs +++ b/EXILED/Exiled.Loader/AutoUpdateFiles.cs @@ -17,6 +17,6 @@ public static class AutoUpdateFiles /// /// Gets which SCP: SL version generated Exiled. /// - public static readonly Version RequiredSCPSLVersion = new(14, 2, 0, 0); + public static readonly Version RequiredSCPSLVersion = new(14, 2, 0, 1); } } \ No newline at end of file diff --git a/EXILED/docs/articles/SCPSLRessources/NW_Documentation.md b/EXILED/docs/articles/SCPSLRessources/NW_Documentation.md index f9be26f3be..f797797370 100644 --- a/EXILED/docs/articles/SCPSLRessources/NW_Documentation.md +++ b/EXILED/docs/articles/SCPSLRessources/NW_Documentation.md @@ -17,7 +17,7 @@ title: NW Documentation --- -Last Update (14.2.0.0) +Last Update (14.2.0.1) ### Index @@ -5797,7 +5797,7 @@ Last Update (14.2.0.0)
Damage Handlers -```md title="Latest Updated: 14.2.0.0" +```md title="Latest Updated: 14.2.0.1" All available DamageHandlers + Symbol ':' literally means "inherits from"