Jump to content

Mod Loader/Reference/Fabric API

From WikiName

FabricModApi registers fabrics from a BepInEx plugin. For a fabric you can make in the game or describe with mod.json, see Make a fabric.

Set up a plugin

Reference DressmakerMods.dll, Assembly-CSharp.dll, UnityEngine.CoreModule.dll, and UnityEngine.AssetBundleModule.dll from the game installation. Add a BepInEx dependency on yuu.dressmaker.mods. Fabric registration needs Mod Loader 0.6.73 or newer; custom types and tags need 0.6.77 or newer.

Call the API on Unity's main thread. Register fabrics inside FabricModApi.WhenReady, after the loader has read content packs. The callback runs immediately if fabrics are already ready.

using BepInEx;
using DressmakerMods;

[BepInPlugin("example.fabrics", "Example Fabrics", "1.0.0")]
[BepInDependency("yuu.dressmaker.mods", "0.6.73")]
public sealed class ExampleFabrics : BaseUnityPlugin
{
    private void Start()
    {
        FabricModApi.WhenReady(() =>
            FabricModApi.RegisterFromBase(
                Fabric.CottonBlack.name,
                "example.fabrics", "shop-cotton", "Shop Cotton",
                Paths.PluginPath,
                definition => definition.Cost = 15));
    }
}

RegisterFromBase copies the base fabric's type, colors, tags, texture, material, price, unlock level, and notes for fields you leave unset. The example changes only the price. Keep the mod ID and local ID when you update: saved inventories and dresses can refer to example.fabrics.shop-cotton.

Methods

Member Use
bool IsReady
void WhenReady(Action callback)
Wait for manifest fabrics to load. Registration methods require this state.
Fabric Register(string modId, FabricDefinition definition, string assetDirectory) Register a fabric without copying a base.
Fabric RegisterFromBase(string baseFabricId, string modId, string localId, string displayName, string assetDirectory, Action<FabricDefinition> configure = null) Copy a native or modded fabric and change selected fields.
Fabric FindFabric(string id)
Fabric[] GetFabrics()
Find by full ID, or get a copy of the current fabric list. An unknown ID returns null.
FabricType RegisterType(string modId, string localId, string displayName)
ItemTag RegisterTag(string modId, string localId, string displayName)
Make a type or tag with the full ID modId.localId. Call before registering fabrics that use it.
FabricType FindType(string id)
ItemTag FindTag(string id)
Find native or custom types and tags by full ID.
FabricShaderBundle LoadShaderBundle(string bundlePath, string shaderAssetName) Load a shader from an AssetBundle. The handle has a Shader property and Dispose().

FabricDefinition

For Register, set Id, Name, FabricType, Colors, TagWeights, Cost, and UnlockLevel. Supply an image with Texture or RuntimeTexture, and a shader with Material.Shader or RuntimeShader. Material also accepts color, numbers, keywords, texture maps, scales, offsets, and render queue. The file-backed fields are listed in Fabric pack fields.

RuntimeTexture, RuntimeShader, and ConfigureMaterial are C# properties; they are ignored in JSON. ConfigureMaterial receives a new material, so it does not change the base fabric. Use Unity's SetFloat, SetColor, SetVector, SetTexture, keywords, or renderQueue for properties supported by the chosen shader.

Custom types and tags

Register these inside WhenReady before registering a fabric that uses them. Keep the IDs when you update a published mod.

using System.Collections.Generic;

FabricModApi.WhenReady(() =>
{
    FabricType leather = FabricModApi.RegisterType("example.leathers", "Leather", "Leather");
    ItemTag leatherTag = FabricModApi.RegisterTag("example.leathers", "Leather", "Leather");
    FabricModApi.RegisterFromBase(Fabric.CottonBlack.name,
        "example.leathers", "brown-leather", "Brown Leather", assetFolder,
        definition =>
        {
            definition.FabricType = leather.name;
            definition.TagWeights = new List<FabricTagDefinition> {
                new FabricTagDefinition { Tag = leatherTag.name, Weight = 50f }
            };
        });
});

Shader bundles

Build the AssetBundle for Dressmaker's Unity version and the player's platform. LoadShaderBundle checks that the named shader exists and is supported by the current graphics device. Keep the handle until your plugin unloads, then dispose it.

private FabricShaderBundle shaderBundle;

private void Start()
{
    string assetFolder = System.IO.Path.Combine(Paths.PluginPath, "ExampleSheerFabric");
    string bundlePath = System.IO.Path.Combine(assetFolder, "fabric-shaders");
    shaderBundle = FabricModApi.LoadShaderBundle(
        bundlePath, "Assets/Shaders/SheerFabric.shader");
    FabricModApi.WhenReady(() =>
        FabricModApi.RegisterFromBase(Fabric.CottonBlack.name,
            "example.sheer", "sheer-cotton", "Sheer Cotton", assetFolder,
            definition => definition.RuntimeShader = shaderBundle.Shader));
}

private void OnDestroy() { shaderBundle?.Dispose(); }

The plugin owns its RuntimeTexture and RuntimeShader. Keep them alive while registered fabrics use them. A registered fabric stays until Dressmaker exits; there is no runtime unregister method. A failed registration is discarded so you can correct it and retry.

Where a shader appears

The shop bolt and preview use Fabric.material directly. Cutting, mannequin, and finished-garment views often copy matching properties onto a garment material with its own shader. Test cutting, sewing, mannequin, and saved-dress reloads. An effect that must cover all of those views may need renderer-specific patches.

Back to the Mod Loader guide