ShopAPI
Exposes an easy-to-use API to add custom items to the in-game shop.
About this mod Author’s original text
Content Warning Shop API
===
Exposes an easy-to-use API to add custom items to the in-game shop in Content Warning.
See the mod's GitHub repository for detailed setup instructions and usage information.
Features
- Custom items: Opens up the in-game shop to allow custom items to be added. This includes automatically synchronising item prices between players, and registering custom ItemDataEntry types defined in your mod to interface with the game's built-in item synchroniser.
- Synchronisation: Easily synchronise any arbitrary settings between players in a lobby using Steam Lobby Metadata keys via the SynchronisedMetadata class.
- Localisation: Extends and opens up the game's localisation system to allow items to be translated to the supported locales by patching item and shop related localised methods.
Integration
DO NOT bundle the mod's DLL with your own. Ensure that no ShopAPI.dll is included with your build.
Depending on your publishing target, you should instead require it as a dependency on your publishing platform:
Steam Workshop
When publishing on the Steam Workshop, add this Workshop Item as your item's dependency via the "Add/Remove Required Items" option (on your mod's page right hand side panel).
Steam will ensure that the dependency will load before your mod when the game is launched.
(BepInEx)
When building a BepInEx plugin, add this mod as a dependency to your plugin's main file:
[BepInDependency(ShopApiPlugin.MOD_GUID)]
public class YourCustomPlugin: BaseUnityPlugin
{
//...
}
If a specific version is needed, pass ShopApiPlugin.MOD_VER after the GUID.
When publishing, add the mod's Dependency String to the manifest.json file, so mod managers can automatically fetch it.
Usage
Once added as a reference to your project, all classes are available under the ContentWarningShop namespace.
Creating items
Ideally Items should be preconfigured and packed into an AssetBundle, but you can also construct them at runtime if its easier.
Custom Items should have their persistentID, price, purchasable, Category, and icon properties set to work.
If you would like your item to have a chance to be randomly spawned in the Old World like other items, set spawnable to true, and itemType to Item.ItemType.Tool.
Registering items
Items can be registered via the RegisterItem method:
//using ContentWarningShop;
var yourCustomItem = yourAssetBundle.LoadAsset("yourItem");
Shop.RegisterItem(yourCustomItem);
Shop.RegisterCustomDataEntries();
NOTE:
Item prices are automatically synchronised between players on lobby join. The price set by the lobby's host will be used for the entire lobby.
You can check if a custom item has been already registered via the IsItemRegistered method. The list of all registered custom items is also available via the CustomItems property.
If your item uses custom ItemDataEntry types, call the RegisterCustomDataEntries method to fetch and register all custom types defined in your assembly. This will let the game automatically synchronise the items' custom state between players. (See compatibility if you run into issues)
It is enough call this method once per assembly / mod.
Updating item prices
If you need to update an item's price at any point after a lobby has been started, use the UpdateItemPrice method:
var success = Shop.UpdateItemPrice(yourCustomItem, price);
This will re-synchronise the item's price to every player. Note that only the lobby's host can update an item's price, so the method returns a boolean indicating if it was successful (if the local player had permissions).
Synchronising Settings
The SynchronisedMetadata class allows arbitrary settings to be synchronised between players through the use of Steam Lobby Metadata keys. Simply create a new instance with a specific type and key and it will be automatically updated whenever the key's value is changed.
TIP:
Consider prepending your mod's GUID to the key to ensure it won't accidentally collide with
Install & use Install: BepInEx plugin
- The archive from playbuff is the mod itself — usually a BepInEx plugin (a .dll or a plugin folder once unzipped).
- Recommended: use a community mod manager (such as r2modman) — pick this game, import the mod, and the manager sets up BepInEx and its dependencies for you.
- Manual route: install the BepInEx loader in the game folder, then drop the unzipped .dll or plugin folder into BepInEx/plugins/.
- Launch the game — the BepInEx console logs every plugin it loads; seeing this mod in the log means it is installed.
Mods with listed dependencies need those installed too, or they will not load. Options are usually changed in-game or in the plugin's config file.
Install these first, or the mod will not work: