From fdbab30b8f8d31e3cd973367d4862e17a8526311 Mon Sep 17 00:00:00 2001
From: Unbistrackted <112902220+Unbistrackted@users.noreply.github.com>
Date: Sun, 26 Apr 2026 16:50:32 -0300
Subject: [PATCH 1/5] feat!: Add overloads for AddItem using AttachmentName
Added check inside of ``Firearm::AddAttachment`` to prevent missmatches
Added overload methods for ``Player`` when giving weapon with attachments using ``AttachmentName``
Fixed ``AttachmentIdentifier.TryParse`` giving wrong attachment by creating another overload that takes the weapon type
---
EXILED/Exiled.API/Features/Items/Firearm.cs | 9 +-
EXILED/Exiled.API/Features/Player.cs | 187 ++++++++++++++----
.../Structs/AttachmentIdentifier.cs | 65 ++++--
3 files changed, 200 insertions(+), 61 deletions(-)
diff --git a/EXILED/Exiled.API/Features/Items/Firearm.cs b/EXILED/Exiled.API/Features/Items/Firearm.cs
index 56215591af..759b8895b0 100644
--- a/EXILED/Exiled.API/Features/Items/Firearm.cs
+++ b/EXILED/Exiled.API/Features/Items/Firearm.cs
@@ -13,7 +13,6 @@ namespace Exiled.API.Features.Items
using CameraShaking;
using Enums;
-
using Exiled.API.Features.Items.FirearmModules;
using Exiled.API.Features.Items.FirearmModules.Barrel;
using Exiled.API.Features.Items.FirearmModules.Primary;
@@ -369,9 +368,11 @@ public static Firearm Create(FirearmType type)
/// The to add.
public void AddAttachment(AttachmentIdentifier identifier)
{
+ uint fallbackCode = AvailableAttachments[FirearmType].FirstOrDefault(attId => attId.Name == identifier.Name).Code;
+
// Fallback addedCode onto AvailableAttachments' code in case it's 0
- uint addedCode = identifier.Code == 0
- ? AvailableAttachments[FirearmType].FirstOrDefault(attId => attId.Name == identifier.Name).Code
+ uint addedCode = identifier.Code == 0 || fallbackCode != identifier.Code
+ ? fallbackCode
: identifier.Code;
// Look for conflicting attachment (attachment that occupies the same slot)
@@ -817,4 +818,4 @@ internal override void ReadPickupInfoBefore(Pickup pickup)
}
}
}
-}
+}
\ No newline at end of file
diff --git a/EXILED/Exiled.API/Features/Player.cs b/EXILED/Exiled.API/Features/Player.cs
index 5627e8dc91..5be0f2b651 100644
--- a/EXILED/Exiled.API/Features/Player.cs
+++ b/EXILED/Exiled.API/Features/Player.cs
@@ -2774,7 +2774,7 @@ public Item AddItem(ItemType itemType)
{
if (itemType.GetFirearmType() is not FirearmType.None)
{
- return AddItem(itemType.GetFirearmType(), null);
+ return AddItem(itemType.GetFirearmType(), new List());
}
Item item = Item.Create(itemType, this);
@@ -2784,6 +2784,41 @@ public Item AddItem(ItemType itemType)
return item;
}
+ ///
+ /// Adds the amount of items of the specified type with default durability(ammo/charge) and no mods to the player's inventory.
+ ///
+ /// The item to be added.
+ /// The amount of items to be added.
+ /// An containing the items given.
+ public IEnumerable- AddItem(ItemType itemType, int amount)
+ {
+ List
- items = new(amount > 0 ? amount : 0);
+ if (amount > 0)
+ {
+ for (int i = 0; i < amount; i++)
+ items.Add(AddItem(itemType));
+ }
+
+ return items;
+ }
+
+ ///
+ /// Adds the list of items of the specified type with default durability(ammo/charge) and no mods to the player's inventory.
+ ///
+ /// The list of items to be added.
+ /// An containing the items given.
+ public IEnumerable
- AddItem(IEnumerable items)
+ {
+ List enumeratedItems = ListPool.Pool.Get(items);
+ List
- returnedItems = new(enumeratedItems.Count);
+
+ foreach (ItemType type in enumeratedItems)
+ returnedItems.Add(AddItem(type));
+
+ ListPool.Pool.Return(enumeratedItems);
+ return returnedItems;
+ }
+
///
/// Adds a firearm of the specified type with default durability(ammo/charge) and no mods to the player's inventory.
///
@@ -2808,18 +2843,45 @@ public Item AddItem(FirearmType firearmType, IEnumerable i
}
///
- /// Adds the amount of items of the specified type with default durability(ammo/charge) and no mods to the player's inventory.
+ /// Adds a firearm of the specified type with default durability(ammo/charge) and no mods to the player's inventory.
///
- /// The item to be added.
+ /// The firearm to be added.
+ /// The attachments to be added to the item.
+ /// The given to the player.
+ public Item AddItem(FirearmType firearmType, IEnumerable identifiers)
+ {
+ Item item = Item.Create(firearmType.GetItemType());
+
+ if (item is Firearm firearm)
+ {
+ if (identifiers is not null)
+ firearm.AddAttachment(identifiers);
+ else if (Preferences is not null && Preferences.TryGetValue(firearmType, out AttachmentIdentifier[] attachments))
+ firearm.Base.ApplyAttachmentsCode(attachments.GetAttachmentsCode(), true);
+ }
+
+ AddItem(item);
+
+ return item;
+ }
+
+ ///
+ /// Adds the amount of firearms of the specified type with default durability(ammo/charge) and no mods to the player's inventory.
+ ///
+ /// The item to be added.
/// The amount of items to be added.
+ /// The attachments to be added to the item.
/// An containing the items given.
- public IEnumerable
- AddItem(ItemType itemType, int amount)
+ public IEnumerable
- AddItem(FirearmType firearmType, int amount, IEnumerable identifiers)
{
List
- items = new(amount > 0 ? amount : 0);
+
if (amount > 0)
{
+ IEnumerable attachmentIdentifiers = identifiers.ToList();
+
for (int i = 0; i < amount; i++)
- items.Add(AddItem(itemType));
+ items.Add(AddItem(firearmType, attachmentIdentifiers));
}
return items;
@@ -2832,13 +2894,13 @@ public IEnumerable
- AddItem(ItemType itemType, int amount)
/// The amount of items to be added.
/// The attachments to be added to the item.
/// An containing the items given.
- public IEnumerable
- AddItem(FirearmType firearmType, int amount, IEnumerable identifiers)
+ public IEnumerable
- AddItem(FirearmType firearmType, int amount, IEnumerable identifiers)
{
List
- items = new(amount > 0 ? amount : 0);
if (amount > 0)
{
- IEnumerable attachmentIdentifiers = identifiers.ToList();
+ IEnumerable attachmentIdentifiers = identifiers.ToList();
for (int i = 0; i < amount; i++)
items.Add(AddItem(firearmType, attachmentIdentifiers));
@@ -2850,48 +2912,76 @@ public IEnumerable
- AddItem(FirearmType firearmType, int amount, IEnumerabl
///
/// Adds the list of items of the specified type with default durability(ammo/charge) and no mods to the player's inventory.
///
- /// The list of items to be added.
+ /// The of and of to be added.
/// An containing the items given.
- public IEnumerable
- AddItem(IEnumerable items)
+ public IEnumerable
- AddItem(Dictionary> items)
{
- List enumeratedItems = ListPool.Pool.Get(items);
- List
- returnedItems = new(enumeratedItems.Count);
+ List
- returnedItems = new(items.Count);
- foreach (ItemType type in enumeratedItems)
- returnedItems.Add(AddItem(type));
+ foreach (KeyValuePair> item in items)
+ returnedItems.Add(AddItem(item.Key, item.Value));
- ListPool.Pool.Return(enumeratedItems);
return returnedItems;
}
///
/// Adds the list of items of the specified type with default durability(ammo/charge) and no mods to the player's inventory.
///
- /// The of and of to be added.
+ /// The of and of to be added.
/// An containing the items given.
- public IEnumerable
- AddItem(Dictionary> items)
+ public IEnumerable
- AddItem(Dictionary> items)
{
List
- returnedItems = new(items.Count);
- foreach (KeyValuePair> item in items)
- returnedItems.Add(AddItem(item.Key, item.Value));
+ foreach (KeyValuePair> item in items)
+ returnedItems.Add(AddItem(item.Key, AttachmentIdentifier.Get(item.Key, item.Value)));
return returnedItems;
}
+ ///
+ /// Adds the list of items to the player's inventory.
+ ///
+ /// The of and of to be added.
+ public void AddItem(Dictionary> firearms)
+ {
+ if (firearms.Count > 0)
+ {
+ foreach (KeyValuePair> item in firearms)
+ AddItem(item.Key, item.Value);
+ }
+ }
+
+ ///
+ /// Adds the list of items to the player's inventory.
+ ///
+ /// The of and of to be added.
+ public void AddItem(Dictionary> firearms)
+ {
+ if (firearms.Count > 0)
+ {
+ foreach (KeyValuePair> item in firearms)
+ AddItem(item.Key, item.Value);
+ }
+ }
+
///
/// Adds an item to the player's inventory.
///
/// The item to be added.
- public void AddItem(Item item)
+ /// The attachments to be added to the item.
+ public void AddItem(Firearm item, IEnumerable identifiers)
{
try
{
+ if (identifiers is not null)
+ item.AddAttachment(identifiers);
+
AddItem(item.Base, item);
}
- catch (Exception e)
+ catch (Exception exception)
{
- Log.Error($"{nameof(Player)}.{nameof(AddItem)}(Item): {e}");
+ Log.Error($"{nameof(Player)}.{nameof(AddItem)}(Item): {exception}");
}
}
@@ -2900,7 +2990,7 @@ public void AddItem(Item item)
///
/// The item to be added.
/// The attachments to be added to the item.
- public void AddItem(Firearm item, IEnumerable identifiers)
+ public void AddItem(Firearm item, IEnumerable identifiers)
{
try
{
@@ -2918,10 +3008,18 @@ public void AddItem(Firearm item, IEnumerable identifiers)
///
/// Adds an item to the player's inventory.
///
- /// The of the item to be added.
- /// The reason the item was added.
+ /// The of the item to be added.
+ /// The attachments to be added to of the item.
/// The that was added.
- public Item AddItem(Pickup pickup, ItemAddReason addReason = ItemAddReason.AdminCommand) => Item.Get(Inventory.ServerAddItem(pickup.Type, addReason, pickup.Serial, pickup.Base));
+ public Item AddItem(FirearmPickup pickup, IEnumerable identifiers)
+ {
+ Firearm firearm = Item.Get(Inventory.ServerAddItem(pickup.Type, ItemAddReason.AdminCommand, pickup.Serial, pickup.Base));
+
+ if (identifiers is not null)
+ firearm.AddAttachment(identifiers);
+
+ return firearm;
+ }
///
/// Adds an item to the player's inventory.
@@ -2929,7 +3027,7 @@ public void AddItem(Firearm item, IEnumerable identifiers)
/// The of the item to be added.
/// The attachments to be added to of the item.
/// The that was added.
- public Item AddItem(FirearmPickup pickup, IEnumerable identifiers)
+ public Item AddItem(FirearmPickup pickup, IEnumerable identifiers)
{
Firearm firearm = Item.Get(Inventory.ServerAddItem(pickup.Type, ItemAddReason.AdminCommand, pickup.Serial, pickup.Base));
@@ -2939,6 +3037,30 @@ public Item AddItem(FirearmPickup pickup, IEnumerable iden
return firearm;
}
+ ///
+ /// Adds an item to the player's inventory.
+ ///
+ /// The item to be added.
+ public void AddItem(Item item)
+ {
+ try
+ {
+ AddItem(item.Base, item);
+ }
+ catch (Exception e)
+ {
+ Log.Error($"{nameof(Player)}.{nameof(AddItem)}(Item): {e}");
+ }
+ }
+
+ ///
+ /// Adds an item to the player's inventory.
+ ///
+ /// The of the item to be added.
+ /// The reason the item was added.
+ /// The that was added.
+ public Item AddItem(Pickup pickup, ItemAddReason addReason = ItemAddReason.AdminCommand) => Item.Get(Inventory.ServerAddItem(pickup.Type, addReason, pickup.Serial, pickup.Base));
+
///
/// Adds an item to the player's inventory.
///
@@ -2985,19 +3107,6 @@ public void AddItem(IEnumerable
- items)
AddItem(item);
}
- ///
- /// Adds the list of items to the player's inventory.
- ///
- /// The of and of to be added.
- public void AddItem(Dictionary> firearms)
- {
- if (firearms.Count > 0)
- {
- foreach (KeyValuePair> item in firearms)
- AddItem(item.Key, item.Value);
- }
- }
-
///
/// Gives the player a specific candy. Will give the player a bag if they do not already have one.
///
diff --git a/EXILED/Exiled.API/Structs/AttachmentIdentifier.cs b/EXILED/Exiled.API/Structs/AttachmentIdentifier.cs
index cc27b57a05..33c2dd92af 100644
--- a/EXILED/Exiled.API/Structs/AttachmentIdentifier.cs
+++ b/EXILED/Exiled.API/Structs/AttachmentIdentifier.cs
@@ -12,7 +12,6 @@ namespace Exiled.API.Structs
using System.Linq;
using Exiled.API.Enums;
-
using InventorySystem.Items.Firearms.Attachments;
using InventorySystem.Items.Firearms.Attachments.Components;
@@ -131,16 +130,17 @@ internal AttachmentIdentifier(uint code, AttachmentName name, AttachmentSlot slo
///
/// Converts the string representation of a to its equivalent.
- /// A return value indicates whether the conversion is succeeded or failed.
+ /// A return value indicates whether the conversion succeeded or failed.
///
- /// The to convert.
+ /// The to convert.
/// The converted .
/// if was converted successfully; otherwise, .
- public static bool TryParse(string s, out AttachmentIdentifier identifier)
+ [Obsolete("Use AttachmentIdentifier.TryParse(string, FirearmType, out AttachmentIdentifier) instead. Gives wrong Attachment for certain weapons.", true)]
+ public static bool TryParse(string name, out AttachmentIdentifier identifier)
{
identifier = default;
- foreach (AttachmentIdentifier attId in Features.Items.Firearm.AvailableAttachments.Values.SelectMany(kvp => kvp.Where(kvp2 => kvp2.Name.ToString() == s)))
+ foreach (AttachmentIdentifier attId in Features.Items.Firearm.AvailableAttachments.Values.SelectMany(kvp => kvp.Where(kvp2 => kvp2.Name.ToString() == name)))
{
identifier = attId;
return true;
@@ -150,24 +150,29 @@ public static bool TryParse(string s, out AttachmentIdentifier identifier)
}
///
- /// Gets a by name.
+ /// Converts the string representation of a to its equivalent.
+ /// A return value indicates whether the conversion succeeded or failed.
///
- /// Weapons .
- /// Attachment name.
- /// instance.
- public static AttachmentIdentifier Get(FirearmType type, AttachmentName name) => Features.Items.Firearm.AvailableAttachments[type].FirstOrDefault(identifier => identifier.Name == name);
+ /// The to convert.
+ /// The to get the from.
+ /// The converted .
+ /// if was converted successfully; otherwise, .
+ public static bool TryParse(string name, FirearmType firearm, out AttachmentIdentifier identifier)
+ {
+ identifier = default;
- ///
- /// Gets the all 's for type, by slot.
- ///
- /// Weapons .
- /// Attachment slot.
- /// instance.
- public static IEnumerable Get(FirearmType type, AttachmentSlot slot) => Features.Items.Firearm.AvailableAttachments[type].Where(identifier => identifier.Slot == slot);
+ foreach (AttachmentIdentifier attId in Features.Items.Firearm.AvailableAttachments[firearm].Where(kvp2 => kvp2.Name.ToString() == name))
+ {
+ identifier = attId;
+ return true;
+ }
+
+ return false;
+ }
///
/// Converts the string representation of a to its equivalent.
- /// A return value indicates whether the conversion is succeeded or failed.
+ /// A return value indicates whether the conversion succeeded or failed.
///
/// The to convert.
/// The converted .
@@ -188,6 +193,30 @@ public static bool TryParse(string s, out AttachmentName name)
return false;
}
+ ///
+ /// Gets a by name.
+ ///
+ /// Weapons .
+ /// Attachment name.
+ /// instance.
+ public static AttachmentIdentifier Get(FirearmType type, AttachmentName name) => Features.Items.Firearm.AvailableAttachments[type].FirstOrDefault(identifier => identifier.Name == name);
+
+ ///
+ /// Gets a by name.
+ ///
+ /// Weapons .
+ /// Attachments name.
+ /// instances.
+ public static IEnumerable Get(FirearmType type, IEnumerable names) => Features.Items.Firearm.AvailableAttachments[type].Where(identifier => names.Contains(identifier.Name));
+
+ ///
+ /// Gets the all 's for type, by slot.
+ ///
+ /// Weapons .
+ /// Attachment slot.
+ /// instance.
+ public static IEnumerable Get(FirearmType type, AttachmentSlot slot) => Features.Items.Firearm.AvailableAttachments[type].Where(identifier => identifier.Slot == slot);
+
///
public override bool Equals(object obj) => base.Equals(obj);
From ff475954fdca5cf23b564ae3fc641d256e1f1770 Mon Sep 17 00:00:00 2001
From: Unbistrackted <112902220+Unbistrackted@users.noreply.github.com>
Date: Wed, 29 Apr 2026 14:31:36 -0300
Subject: [PATCH 2/5] feat!: return Lists instead of IEnumerables
---
EXILED/Exiled.API/Features/Player.cs | 38 ++++++++++++----------------
1 file changed, 16 insertions(+), 22 deletions(-)
diff --git a/EXILED/Exiled.API/Features/Player.cs b/EXILED/Exiled.API/Features/Player.cs
index 5be0f2b651..9d7a743780 100644
--- a/EXILED/Exiled.API/Features/Player.cs
+++ b/EXILED/Exiled.API/Features/Player.cs
@@ -2789,8 +2789,8 @@ public Item AddItem(ItemType itemType)
///
/// The item to be added.
/// The amount of items to be added.
- /// An containing the items given.
- public IEnumerable- AddItem(ItemType itemType, int amount)
+ /// An containing the items given.
+ public List
- AddItem(ItemType itemType, int amount)
{
List
- items = new(amount > 0 ? amount : 0);
if (amount > 0)
@@ -2806,16 +2806,14 @@ public IEnumerable
- AddItem(ItemType itemType, int amount)
/// Adds the list of items of the specified type with default durability(ammo/charge) and no mods to the player's inventory.
///
/// The list of items to be added.
- /// An containing the items given.
- public IEnumerable
- AddItem(IEnumerable items)
+ /// An containing the items given.
+ public List
- AddItem(IEnumerable items)
{
- List enumeratedItems = ListPool.Pool.Get(items);
- List
- returnedItems = new(enumeratedItems.Count);
+ List
- returnedItems = new(items.Count());
- foreach (ItemType type in enumeratedItems)
+ foreach (ItemType type in items)
returnedItems.Add(AddItem(type));
- ListPool.Pool.Return(enumeratedItems);
return returnedItems;
}
@@ -2871,17 +2869,15 @@ public Item AddItem(FirearmType firearmType, IEnumerable identif
/// The item to be added.
/// The amount of items to be added.
/// The attachments to be added to the item.
- /// An containing the items given.
- public IEnumerable
- AddItem(FirearmType firearmType, int amount, IEnumerable identifiers)
+ /// An containing the items given.
+ public List
- AddItem(FirearmType firearmType, int amount, IEnumerable identifiers)
{
List
- items = new(amount > 0 ? amount : 0);
if (amount > 0)
{
- IEnumerable attachmentIdentifiers = identifiers.ToList();
-
for (int i = 0; i < amount; i++)
- items.Add(AddItem(firearmType, attachmentIdentifiers));
+ items.Add(AddItem(firearmType, identifiers));
}
return items;
@@ -2893,17 +2889,15 @@ public IEnumerable
- AddItem(FirearmType firearmType, int amount, IEnumerabl
/// The item to be added.
/// The amount of items to be added.
/// The attachments to be added to the item.
- /// An containing the items given.
- public IEnumerable
- AddItem(FirearmType firearmType, int amount, IEnumerable identifiers)
+ /// An containing the items given.
+ public List
- AddItem(FirearmType firearmType, int amount, IEnumerable identifiers)
{
List
- items = new(amount > 0 ? amount : 0);
if (amount > 0)
{
- IEnumerable attachmentIdentifiers = identifiers.ToList();
-
for (int i = 0; i < amount; i++)
- items.Add(AddItem(firearmType, attachmentIdentifiers));
+ items.Add(AddItem(firearmType, identifiers));
}
return items;
@@ -2913,8 +2907,8 @@ public IEnumerable
- AddItem(FirearmType firearmType, int amount, IEnumerabl
/// Adds the list of items of the specified type with default durability(ammo/charge) and no mods to the player's inventory.
///
/// The of and of to be added.
- /// An containing the items given.
- public IEnumerable
- AddItem(Dictionary> items)
+ /// An containing the items given.
+ public List
- AddItem(Dictionary> items)
{
List
- returnedItems = new(items.Count);
@@ -2928,8 +2922,8 @@ public IEnumerable
- AddItem(Dictionary
/// The of and of to be added.
- /// An containing the items given.
- public IEnumerable
- AddItem(Dictionary> items)
+ /// An containing the items given.
+ public List
- AddItem(Dictionary> items)
{
List
- returnedItems = new(items.Count);
From 9c52ce21a96bf7acd97d71fc967088aec45f1864 Mon Sep 17 00:00:00 2001
From: Unbistrackted <112902220+Unbistrackted@users.noreply.github.com>
Date: Wed, 29 Apr 2026 14:32:14 -0300
Subject: [PATCH 3/5] feat!: remove obsolete ``TryParse`` method
---
.../Structs/AttachmentIdentifier.cs | 21 -------------------
1 file changed, 21 deletions(-)
diff --git a/EXILED/Exiled.API/Structs/AttachmentIdentifier.cs b/EXILED/Exiled.API/Structs/AttachmentIdentifier.cs
index 33c2dd92af..40b8cfe7ee 100644
--- a/EXILED/Exiled.API/Structs/AttachmentIdentifier.cs
+++ b/EXILED/Exiled.API/Structs/AttachmentIdentifier.cs
@@ -128,27 +128,6 @@ internal AttachmentIdentifier(uint code, AttachmentName name, AttachmentSlot slo
/// A value representing the subtraction between the two operands.
public static uint operator -(uint left, AttachmentIdentifier right) => left - right.Code;
- ///
- /// Converts the string representation of a to its equivalent.
- /// A return value indicates whether the conversion succeeded or failed.
- ///
- /// The to convert.
- /// The converted .
- /// if was converted successfully; otherwise, .
- [Obsolete("Use AttachmentIdentifier.TryParse(string, FirearmType, out AttachmentIdentifier) instead. Gives wrong Attachment for certain weapons.", true)]
- public static bool TryParse(string name, out AttachmentIdentifier identifier)
- {
- identifier = default;
-
- foreach (AttachmentIdentifier attId in Features.Items.Firearm.AvailableAttachments.Values.SelectMany(kvp => kvp.Where(kvp2 => kvp2.Name.ToString() == name)))
- {
- identifier = attId;
- return true;
- }
-
- return false;
- }
-
///
/// Converts the string representation of a to its equivalent.
/// A return value indicates whether the conversion succeeded or failed.
From 254ec58f64f33380985d028d63c083876668ae8a Mon Sep 17 00:00:00 2001
From: Unbistrackted <112902220+Unbistrackted@users.noreply.github.com>
Date: Wed, 29 Apr 2026 19:55:53 -0300
Subject: [PATCH 4/5] feat(AttachmentIdentifier): add ``Get`` and ``TryGet``
method using attachment code
---
.../Structs/AttachmentIdentifier.cs | 28 ++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/EXILED/Exiled.API/Structs/AttachmentIdentifier.cs b/EXILED/Exiled.API/Structs/AttachmentIdentifier.cs
index 40b8cfe7ee..2ee7edfbb2 100644
--- a/EXILED/Exiled.API/Structs/AttachmentIdentifier.cs
+++ b/EXILED/Exiled.API/Structs/AttachmentIdentifier.cs
@@ -181,13 +181,29 @@ public static bool TryParse(string s, out AttachmentName name)
public static AttachmentIdentifier Get(FirearmType type, AttachmentName name) => Features.Items.Firearm.AvailableAttachments[type].FirstOrDefault(identifier => identifier.Name == name);
///
- /// Gets a by name.
+ /// Gets a IEnumerable of by name.
///
/// Weapons .
/// Attachments name.
/// instances.
public static IEnumerable Get(FirearmType type, IEnumerable names) => Features.Items.Firearm.AvailableAttachments[type].Where(identifier => names.Contains(identifier.Name));
+ ///
+ /// Gets a by the Attachment's code.
+ ///
+ /// Weapons .
+ /// Attachment code.
+ /// instance.
+ public static AttachmentIdentifier Get(FirearmType type, uint code) => Features.Items.Firearm.AvailableAttachments[type].FirstOrDefault(identifier => identifier.Code == code);
+
+ ///
+ /// Gets a IEnumerable of by the Attachment's code.
+ ///
+ /// Weapons .
+ /// Attachments codes.
+ /// instances.
+ public static IEnumerable Get(FirearmType type, IEnumerable codes) => Features.Items.Firearm.AvailableAttachments[type].Where(identifier => codes.Contains(identifier.Code));
+
///
/// Gets the all 's for type, by slot.
///
@@ -196,6 +212,16 @@ public static bool TryParse(string s, out AttachmentName name)
/// instance.
public static IEnumerable Get(FirearmType type, AttachmentSlot slot) => Features.Items.Firearm.AvailableAttachments[type].Where(identifier => identifier.Slot == slot);
+ ///
+ /// Gets a by the Attachment's code.
+ /// A return value indicates whether the conversion succeeded or failed.
+ ///
+ /// The code of the attachment.
+ /// The to get the from.
+ /// The converted .
+ /// if the was found; otherwise, .
+ public static bool TryGet(uint code, FirearmType firearm, out AttachmentIdentifier identifier) => (identifier = Get(firearm, code)).Code != 0;
+
///
public override bool Equals(object obj) => base.Equals(obj);
From 3ae906898e3417d8d1f765b77cdb223ba86982fa Mon Sep 17 00:00:00 2001
From: Unbistrackted <112902220+Unbistrackted@users.noreply.github.com>
Date: Thu, 14 May 2026 13:36:39 -0300
Subject: [PATCH 5/5] fix: format to follow new rules from #822
---
EXILED/Exiled.API/Features/Items/Firearm.cs | 1 +
EXILED/Exiled.API/Structs/AttachmentIdentifier.cs | 1 +
2 files changed, 2 insertions(+)
diff --git a/EXILED/Exiled.API/Features/Items/Firearm.cs b/EXILED/Exiled.API/Features/Items/Firearm.cs
index 969aebc45a..004ea01f91 100644
--- a/EXILED/Exiled.API/Features/Items/Firearm.cs
+++ b/EXILED/Exiled.API/Features/Items/Firearm.cs
@@ -13,6 +13,7 @@ namespace Exiled.API.Features.Items
using CameraShaking;
using Enums;
+
using Exiled.API.Features.Items.FirearmModules;
using Exiled.API.Features.Items.FirearmModules.Barrel;
using Exiled.API.Features.Items.FirearmModules.Primary;
diff --git a/EXILED/Exiled.API/Structs/AttachmentIdentifier.cs b/EXILED/Exiled.API/Structs/AttachmentIdentifier.cs
index 2ee7edfbb2..24b8913996 100644
--- a/EXILED/Exiled.API/Structs/AttachmentIdentifier.cs
+++ b/EXILED/Exiled.API/Structs/AttachmentIdentifier.cs
@@ -12,6 +12,7 @@ namespace Exiled.API.Structs
using System.Linq;
using Exiled.API.Enums;
+
using InventorySystem.Items.Firearms.Attachments;
using InventorySystem.Items.Firearms.Attachments.Components;