Skip to content

feat!: Add overloads for AddItem using AttachmentName#811

Open
Unbistrackted wants to merge 5 commits intoExMod-Team:devfrom
Unbistrackted:attachments-fix
Open

feat!: Add overloads for AddItem using AttachmentName#811
Unbistrackted wants to merge 5 commits intoExMod-Team:devfrom
Unbistrackted:attachments-fix

Conversation

@Unbistrackted
Copy link
Copy Markdown

Description

Describe the changes

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

What is the current behavior? (You can also link to an open issue here)
AttachmentIdentifier.TryParse gives wrong AttachmentIdentifier for certain weapons due to them having the same attachment name with different codes

What is the new behavior? (if this is a feature change)

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

Other information:
Moved some of the methods to be closer to each other so it's easy to find

Props to @PUDGE133 for finding the bug


Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentations

Submission checklist

  • I have checked the project can be compiled
  • I have tested my changes and it worked as expected

Patches (if there are any changes related to Harmony patches)

  • I have checked no IL patching errors in the console

Other

  • Still requires more testing

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
Copy link
Copy Markdown

@Someone-193 Someone-193 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR generally looks good, I just have a few nitpicks here and there. Just to confirm, you haven't removed or significantly changed any important methods right? Just making sure for Exiled 10 I don't get pinged with people being mad they cant find a method that used to exist lol

Comment thread EXILED/Exiled.API/Features/Player.cs Outdated
/// <param name="itemType">The item to be added.</param>
/// <param name="amount">The amount of items to be added.</param>
/// <returns>An <see cref="IEnumerable{Item}"/> containing the items given.</returns>
public IEnumerable<Item> AddItem(ItemType itemType, int amount)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bro you should just return a list if that's what you have internally

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied and pasted the overloads and changed it to accomodate the AttachmentName 😭

https://github.com/ExMod-Team/EXILED/blob/master/EXILED/Exiled.API/Features/Player.cs#L2828

I'm going to change it

Comment thread EXILED/Exiled.API/Features/Player.cs Outdated
/// <returns>An <see cref="IEnumerable{Item}"/> containing the items given.</returns>
public IEnumerable<Item> AddItem(IEnumerable<ItemType> items)
{
List<ItemType> enumeratedItems = ListPool<ItemType>.Pool.Get(items);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using a pooled list for a single foreach loop 😭
You could just remove the listpool here, and also make this return a list as well

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/ExMod-Team/EXILED/blob/master/EXILED/Exiled.API/Features/Player.cs#L2848

It was like that before, I didn't even noticed 😭

Imma change this

/// <param name="identifier">The converted <see cref="string"/>.</param>
/// <returns><see langword="true"/> if <see cref="string"/> was converted successfully; otherwise, <see langword="false"/>.</returns>
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)]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove this method, breaking changes are allowed on dev for Exiled 10

Comment thread EXILED/Exiled.API/Features/Player.cs Outdated
/// <param name="items">The <see cref="Dictionary{TKey, TValue}"/> of <see cref="ItemType"/> and <see cref="IEnumerable{T}"/> of <see cref="AttachmentName"/> to be added.</param>
/// <returns>An <see cref="IEnumerable{Item}"/> containing the items given.</returns>
public IEnumerable<Item> AddItem(Dictionary<FirearmType, IEnumerable<AttachmentIdentifier>> items)
public IEnumerable<Item> AddItem(Dictionary<FirearmType, IEnumerable<AttachmentName>> items)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can make this return a list

Comment thread EXILED/Exiled.API/Features/Player.cs Outdated
/// <param name="items">The <see cref="Dictionary{TKey, TValue}"/> of <see cref="ItemType"/> and <see cref="IEnumerable{T}"/> of <see cref="AttachmentIdentifier"/> to be added.</param>
/// <returns>An <see cref="IEnumerable{Item}"/> containing the items given.</returns>
public IEnumerable<Item> AddItem(IEnumerable<ItemType> items)
public IEnumerable<Item> AddItem(Dictionary<FirearmType, IEnumerable<AttachmentIdentifier>> items)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can make this return a list

Comment thread EXILED/Exiled.API/Features/Player.cs Outdated
/// <param name="identifiers">The attachments to be added to the item.</param>
/// <returns>An <see cref="IEnumerable{Item}"/> containing the items given.</returns>
public IEnumerable<Item> AddItem(FirearmType firearmType, int amount, IEnumerable<AttachmentIdentifier> identifiers)
public IEnumerable<Item> AddItem(FirearmType firearmType, int amount, IEnumerable<AttachmentName> identifiers)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can make this return a list

@Unbistrackted
Copy link
Copy Markdown
Author

Unbistrackted commented Apr 29, 2026

PR generally looks good, I just have a few nitpicks here and there. Just to confirm, you haven't removed or significantly changed any important methods right? Just making sure for Exiled 10 I don't get pinged with people being mad they cant find a method that used to exist lol

The only thing I can see ppl being upset is the Firearm::AddAttachment checking for AttachmentIdentifier code's missmatches using the AttachmentName, since if you manually created the AttachmentIdentifier (which is bad) with a hard coded attachment code but didn't care abt AttachmentName, it will only take into consideration the AttachmentName to get the right one

I mean AttachmentName should be the correct way of getting a specific attachment, but ppl do whatever they want with their code so idk

@Unbistrackted
Copy link
Copy Markdown
Author

Unbistrackted commented Apr 29, 2026

Also do you know if a method for getting the AttachmentIdentifier via the attachment's code exists? Didn't find it but I'm legally blind lmao. If it doesn't exists, might be useful for those ppl that I talked abt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants