Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Mod Compatibility - Items and Equipment
Updated 2 weeks agoAdding Quality for modded items or equipment
Important types
Before we can get into adding items, you should know about a few types commonly used by Quality.
QualityTier
An enum for all the quality tiers added by the mod, frequently used for interfacing with the QualityCatalog.
ItemQualityGroup
Contains all quality versions of an item for easy access, typically consisting of a base item reference and 4 auto-generated ItemDefs. You can think of it like an ItemDef that represents every quality version of an item simultaneously. Also has an ItemIndex equivalent of ItemQualityGroupIndex.
ItemQualityCounts
This helper struct contains an item count for every item in a quality group, used in place of an int item count for things like the GetItemCountsEffective extension method for Inventory.
See InventoryExtensions for other extensions to interact with quality items in an inventory.
QualityCatalog
This is the main catalog for the mod, it contains all quality groups and mappings of items/equipment to QualityTiers.
A common use-case is using it to convert a ItemIndex/PickupIndex into a specific QualityTier. This is done via the GetItemIndexOfQuality/GetPickupIndexOfQuality methods respectively, these return either the given item or pickup index as a certain quality, or the base item/pickup index if that quality isn't registered for it. It will not return an invalid index (assuming a valid index was given to begin with).
Language tokens
Another important thing you should be aware of is how languages tokens are handled by Quality. Tokens are mostly auto-generated in the format: ITEM/EQUIP_[ItemName]_[QualityTier]_NAME/DESC/PICKUP. So for example the description token for Rare Backup Magazine is ITEM_SECONDARYSKILLMAGAZINE_RARE_DESC.
For pickup and description tokens, you can use {0} to insert the base description or pickup string, if you only need to add some more text to the start or end of a description/pickup string to describe your quality effect:
"ITEM_SECONDARYSKILLMAGAZINE_RARE_PICKUP": "{0}\n<sprite name=\"Quality\"> Chance to immediately recharge your Secondary skill.",
"ITEM_SECONDARYSKILLMAGAZINE_RARE_DESC": "{0}\nActivating your <style=cIsUtility>Secondary skill</style> has a <sprite name=\"Quality\"> <style=cIsUtility>25%</style> <style=cStack>(+25% per stack)</style> chance to immediately recharge it.",
Sprites
Quality adds a couple inline sprites you can use in most text displayed in the game.
| Sprite | Usage |
|---|---|
![]() |
<sprite name="Quality"> |
![]() |
<sprite name="QualityUncommon"> |
![]() |
<sprite name="QualityRare"> |
![]() |
<sprite name="QualityEpic"> |
![]() |
<sprite name="QualityLegendary"> |
![]() |
<sprite name="QualityUncommonConsumed"> |
![]() |
<sprite name="QualityRareConsumed"> |
![]() |
<sprite name="QualityEpicConsumed"> |
![]() |
<sprite name="QualityLegendaryConsumed"> |
Adding Quality Items
Adding Quality versions of your own modded items is done via the QualityContentManager class. To register your mod in the initialization, subscribe to the QualityContentManager.LoadContentAsync event.
internal static class QualityCompat
{
private static ItemQualityGroup ExampleItemGroup;
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void Init()
{
QualityContentManager.LoadContentAsync += loadContent_Basic;
RecalculateStatsAPI.GetStatCoefficients += RecalculateStatsAPI_GetStatCoefficients;
}
private static IEnumerator loadContent_Basic(QualityContentLoadArgs args)
{
ExampleItemGroup = args.CreateItemQualityGroup(QualityCompatTesterPlugin.Instance.ExampleItem);
yield break;
}
private static void RecalculateStatsAPI_GetStatCoefficients(CharacterBody sender, RecalculateStatsAPI.StatHookEventArgs args)
{
if (sender.inventory)
{
ItemQualityCounts exampleItem = sender.inventory.GetItemCountsEffective(ExampleItemGroup);
args.armorAdd += (10 * exampleItem.UncommonCount) +
(30 * exampleItem.RareCount) +
(50 * exampleItem.EpicCount) +
(100 * exampleItem.LegendaryCount);
}
}
}
In this example the base ItemDef is created through code in Awake, but these coroutines are run during LoadStaticContentAsync, so you can yield wait until your asset bundle is loaded before creating your item group(s).
Quality will automatically generate all assets needed for your item to have quality variants, such as ItemDefs and icons. But you can also assign the individual quality ItemDefs by using the SetItemDef method on the ItemQualityGroup if you need more control over how the ItemDef is created, but note that this means Quality will hand every part of initialization off to you, meaning you will have to populate the item yourself and also add it to a content pack.
Void item relationships are automatically handled if given an item that is part of a void corruption pair.
Quality items are all included in the effective item count, GetItemCountEffective(MyItem) will return the total number of MyItem, MyItemUncommon, MyItemRare, etc. in the inventory. If you need only the base item count, you can use the extension GetItemCountsEffective(MyItemQualityGroup) and use the BaseItemCount field instead.
IMPORTANT:
If you're using a class like above, with fields that use types in the Quality assembly, you need to take a few extra steps in order to have soft compatibility. The big rule you must follow is that no method that contains any reference to your type(s) with these fields can be executed before you have confirmed Quality is present in the current domain.
So for example this:
private void Awake()
{
if (BepInEx.Bootstrap.Chainloader.PluginInfos.ContainsKey(ItemQualities.ItemQualitiesPlugin.PluginGUID))
{
QualityCompat.Init();
}
}
Will not work because the type is scanned by the runtime regardless of if the Init method its actually executed or not. Instead, you must do something like this:
private void Awake()
{
if (BepInEx.Bootstrap.Chainloader.PluginInfos.ContainsKey(ItemQualities.ItemQualitiesPlugin.PluginGUID))
{
qualityCompatInit();
}
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
private static void qualityCompatInit()
{
QualityCompat.Init();
}
This prevents the runtime from trying to initialize your type unless its absolutely okay to do so. This pattern has to be used anywhere you reference your Compat type (assuming it has the Quality typed fields).
Adding Quality Equipment
Equipments are registered in much the same way as items:
internal static class QualityCompat
{
private static EquipmentQualityGroup ExampleEquipmentGroup;
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void Init()
{
QualityContentManager.LoadContentAsync += loadContent_Basic;
On.RoR2.EquipmentSlot.PerformEquipmentAction += EquipmentSlot_PerformEquipmentAction;
}
private static IEnumerator loadContent_Basic(QualityContentLoadArgs args)
{
ExampleEquipmentGroup = args.CreateEquipmentQualityGroup(QualityCompatTesterPlugin.Instance.ExampleEquipment);
yield break;
}
private static bool EquipmentSlot_PerformEquipmentAction(On.RoR2.EquipmentSlot.orig_PerformEquipmentAction orig, EquipmentSlot self, EquipmentDef equipmentDef)
{
// For better compatibility, Quality will convert all calls to PerformEquipmentAction to always use the base quality of an equipment, so this check is still valid
if (equipmentDef == QualityCompatTesterPlugin.Instance.ExampleEquipment)
{
// Your base equipment's effect
self.characterBody.AddTimedBuff(RoR2Content.Buffs.Cloak, 10f);
// Call this at any point within a PerformEquipmentAction call, it will return the QualityTier of the equipment used.
// Do not use self.GetActiveEquipmentQualityTier() here, since an equipment action may happen independently of what equipment is currently held (such as with Bottled Chaos)
QualityTier qualityTier = self.GetCurrentEquipmentActionQualityTier();
// "QualityTier.None" means the activated equipment was not of quality, so make sure you check this!
if (qualityTier != QualityTier.None)
{
float duration = 0f;
switch (qualityTier)
{
case QualityTier.Uncommon:
duration = 2f;
break;
case QualityTier.Rare:
duration = 3f;
break;
case QualityTier.Epic:
duration = 5f;
break;
case QualityTier.Legendary:
duration = 10f;
break;
}
self.characterBody.AddTimedBuff(RoR2Content.Buffs.HiddenInvincibility, duration);
}
return true;
}
return orig(self, equipmentDef);
}
}
Quality Equipment Quirks
In order to maintain better compatibility, most ways of retrieving a held EquipmentIndex will always return the base equipment, not the quality variant, this is so that direct checks for a specific equipment still work and generally don't need special compatibility.
EquipmentSlot/Inventory methods that return an EquipmentState will keep their quality tiers in them, these methods are mostly used to copy or more equipments around, so it is recommended to use these where you want the quality of an equipment to persist.
EquipmentExtensions also have useful methods for interacting with quality equipments.
Contact
If you think something here is not covered well or at all, please contact me at gorakh (Gorakh#0821) on Discord.








