Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions EXILED/Exiled.API/Features/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2924,15 +2924,15 @@ 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)
{
acquisitionConfirmationTrigger.AcquisitionAlreadyReceived = false;
}

typeof(InventoryExtensions).InvokeStaticEvent(nameof(InventoryExtensions.OnItemAdded), new object[] { ReferenceHub, itemBase, null });

Inventory.SendItemsNextFrame = true;
return item;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,8 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.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,
Expand All @@ -56,39 +48,47 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new CodeInstruction(OpCodes.Ldloc_1),
new(OpCodes.Ldarg_S, 4),
new(OpCodes.Call, Method(typeof(FixOnAddedBeingCallAfterOnRemoved), nameof(FixOnAddedBeingCallAfterOnRemoved.CallBefore))),
});

// if (itemBase is not AmmoItem)
// skip;
new CodeInstruction(OpCodes.Ldloc_1),
new(OpCodes.Isinst, typeof(AmmoItem)),
new(OpCodes.Brfalse_S, continueLabel),

// call help method for inverse call
// InverseCall(itemBase, inv._hub, pickup)
new(OpCodes.Ldloc_1),
new(OpCodes.Ldarg_0),
new(OpCodes.Ldfld, Field(typeof(Inventory), nameof(Inventory._hub))),
new(OpCodes.Ldarg_S, 4),
new(OpCodes.Call, Method(typeof(FixOnAddedBeingCallAfterOnRemoved), nameof(FixOnAddedBeingCallAfterOnRemoved.InverseCall))),
/*
// Modify this
itemBase2.OnAdded(pickup);
Action<ReferenceHub, ItemBase, ItemPickupBase> onItemAdded = InventoryExtensions.OnItemAdded;
if (onItemAdded != null)
{
onItemAdded(inv._hub, itemBase2, pickup);
}
// To this
Action<ReferenceHub, ItemBase, ItemPickupBase> 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<ReferenceHub, ItemBase, ItemPickupBase>), nameof(Action<ReferenceHub, ItemBase, ItemPickupBase>.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];

ListPool<CodeInstruction>.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);
Expand Down
2 changes: 1 addition & 1 deletion EXILED/Exiled.Loader/AutoUpdateFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public static class AutoUpdateFiles
/// <summary>
/// Gets which SCP: SL version generated Exiled.
/// </summary>
public static readonly Version RequiredSCPSLVersion = new(14, 2, 0, 0);
public static readonly Version RequiredSCPSLVersion = new(14, 2, 0, 1);
}
}
4 changes: 2 additions & 2 deletions EXILED/docs/articles/SCPSLRessources/NW_Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
title: NW Documentation
---

Last Update (14.2.0.0)
Last Update (14.2.0.1)

### Index

Expand Down Expand Up @@ -5797,7 +5797,7 @@ Last Update (14.2.0.0)

<details><summary> <b>Damage Handlers</b></summary>

```md title="Latest Updated: 14.2.0.0"
```md title="Latest Updated: 14.2.0.1"
All available DamageHandlers

+ Symbol ':' literally means "inherits from"
Expand Down
Loading