On this page

← All documentation

Importing an osu! skin

How the osu!mania skin converter works, the skinImport API that mods use to build an importer, the permission it needs and the limits the game enforces.

Prism converts an osu!mania skin into an ordinary Prism skin. The player picks a skin folder or an .osk file on the Skins page, a card shows what will be converted and what Prism cannot do, and Create the skin writes a normal folder under the player's skins, ready to use, edit by hand, customize in the skin editor and export.

The converter is a mod, content/mods/skin-converter (pvng.skin-converter). It is a plain folder written in TypeScript; deleting it removes the feature, and the skins it made stay. The game gives mods the skinImport API so that anyone can write another importer. This page explains both.

Who does what

The work is split on purpose:

  • The mod decides the meaning: which skin.ini key feeds which Prism value, which picture goes in which slot for each number of keys, which warnings to show. It writes the texts of its card in the languages of the interface (en, fr, zh, ko).
  • The game, natively and outside the mod thread, does what a script cannot: read the folder or the archive, parse skin.ini, decode and transform pictures, write the skin folder. The script never receives a byte: only typed, bounded values.

The mod does not supply code either: it describes a skin (SkinDescription, values only), and the game validates it with the rules of every skin, then generates a readable skin.ts of the same shape as content/skins/default/skin.ts. A skin.ts written by a mod would be code run later with a skin's rights.

The permission

The API needs permissions: ["skinImport"] in defineMod. The permission is shown on the Mods page and goes away when the mod is disabled. It is for mods only: a skin or a map script cannot use it (only mods convert skins, not a skin). Without it, every call throws:

`skinImport` needs the `skinImport` permission: declare `permissions: ["skinImport"]`

The API

Call Does
skinImport.register(declaration) Declares an importer: one button in the Actions menu of the Skins page. Only in the mod's setup (`skinImport.register` is only available in a mod's setup), at most 4 per mod.
skinImport.panel(panel) Shows or updates the card of the Skins page (declarative, see the panel).
skinImport.stage({ sourceId, skin, images }) Asks the game to prepare the pictures of the skin, in memory. Returns a request number, or null when the game is busy. The answer is skinImport.staged.
skinImport.create({ stageId }) Asks the game to write the prepared skin as a new folder. Returns a request number or null. The answer is skinImport.created.
skinImport.close() Removes the card and frees the source and the preparation.

And four events:

Event Payload When
skinImport.opened { importerId, locale, source?, error? } The player picked a source and the game read it. source is a SkinSource; locale is the interface language.
skinImport.staged { requestId, stageId?, report?, error? } The pictures were prepared. report lists the files and sizes.
skinImport.created { requestId, id?, error? } The folder was written. id is its name, which may differ from the wanted one (-2, -3).
skinImport.action { id } The player pressed a button of the card. The id dismiss means the card was closed.

Types and the exact signatures are in the SDK reference and in modding.d.ts.

The game makes the decisions that matter for safety:

  1. The player picks the source, never the mod. A click on the importer's button sends the pick to the game, which opens the native file dialog, reads the source and sends skinImport.opened. The mod sees no path and no file name but the label of the source.
  2. Read-only and bounded. See the limits.
  3. skin.ini is parsed natively into a typed structure (SkinIni: [General], the [Mania] sections merged by Keys, columns by index, colors as #rrggbbaa, unknown keys listed without their values). Values out of bounds are rejected with a message, never passed on.
  4. The inventory of pictures (SourceImage, at most 4096) gives the normalized name (no extension, no @2x, no -N), size, scale (1 or 2), number of animation frames, byte size, whether it is blank, the box of its visible pixels and its peak color. No pixel.
  5. Picture operations are declarative (ImageOp) and run by the game: source (an element name resolved like osu! does: animation, @2x, .png or .jpg), dest (a relative .png path, with {n} for a sequence), animation, frame, crop, then fit (fits in a box without enlarging) or stretch (exact size). The output is PNG. There is no pixel script and no network.
  6. A skin is described, the game writes it. The description holds the common PlayfieldSpec, a layout per number of keys (keys, a PlayfieldSpec and a LaneSpec per column) and the vertical positions of the HUD. The game checks it with the rules of skins (bounds, paths, images present).
  7. Safe writing. Only in the player's skins folder (PRISM_SKINS_DIR respected, never the shipped folder), through a hidden preparation folder then a rename, under a free id (-2, -3), so an existing skin is never overwritten. Before the rename, the generated skin.ts is loaded in a throwaway engine, as the skin list does.
  8. One job at a time, on a dedicated native thread (skin-import), never during a play. Results come back as events, on the mod's usual budget.

A minimal importer

This mod converts the 4K layout only: it keeps the width of the first column and the first note picture. The converter in the game does the same work for 4K to 9K with many more values.

/// <reference path="../../../mods/sdk/modding.d.ts" />

// Mini skin importer, an example mod: the smallest converter of an osu!mania skin. The player
// picks a folder or an `.osk` file on the Skins page; the game reads it and hands this mod its
// `skin.ini` and its list of pictures as plain values; the mod describes the Prism skin it wants
// (a 4K layout with the width of the first column and its note picture), asks the game to prepare
// it, then to write it. The mod never sees a file or a pixel, and never writes code: the game
// generates the `skin.ts` from the description.
//
// Needs the `skinImport` permission, shown on the Mods page.

/** osu! measures in points of a screen 480 high; Prism in fractions of the screen height. */
const OSU_HEIGHT = 480;
const KEYS = 4;

let requestId: number | null = null;
let stageId: number | null = null;

function show(status: PanelStatus, title: string, detail: string, actions: PanelAction[] = []) {
  skinImport.panel({ title, status, detail, actions });
}

/** The skin to build and the pictures to prepare, or why there is nothing to convert. */
function describe(source: SkinSource): StageRequest | string {
  const section = source.ini?.mania.find((candidate) => candidate.keys === KEYS);
  if (!section) return `The skin has no [Mania] section for ${KEYS} keys.`;
  const reference = section.columns[0]?.noteImage ?? "mania-note1";
  const picture = source.images.find((image) => image.name === reference);
  const laneWidth = (section.columnWidth[0] ?? 30) / OSU_HEIGHT;
  const playfield: PlayfieldSpec = { laneWidth, laneGap: 0 };
  const images: ImageOp[] = [];
  if (picture) {
    playfield.note = "note.png";
    playfield.noteSize = { width: laneWidth, height: laneWidth };
    images.push({ source: reference, dest: "note.png", fit: { maxWidth: 256, maxHeight: 256 } });
  }
  return {
    sourceId: source.sourceId,
    skin: {
      id: "mini-import",
      name: (source.ini?.general.name || source.label || "Imported skin").slice(0, 64),
      author: source.ini?.general.author,
      layouts: [{ keys: KEYS, playfield, lanes: [] }],
    },
    images,
  };
}

export default defineMod({
  id: "example.skin-importer",
  name: "Mini skin importer",
  version: "1.0.0",
  apiVersion: 2,
  permissions: ["skinImport"],
  setup() {
    // Only in `setup`: one button of the Skins page, in the Actions menu.
    skinImport.register({
      id: "mini",
      name: "Convert an osu! skin (mini)",
      description: "Keeps the 4K column width and the first note picture.",
      sources: ["folder", "archive"],
    });

    // The player picked a source and the game read it.
    ctx.on("skinImport.opened", (event: SkinImportOpened) => {
      requestId = null;
      stageId = null;
      if (!event.source) {
        show("error", "Could not read the skin", event.error ?? "Unknown error");
        return;
      }
      const request = describe(event.source);
      if (typeof request === "string") {
        show("error", "Nothing to convert", request);
        return;
      }
      requestId = skinImport.stage(request);
      if (requestId === null) show("error", "The game is busy", "Try again in a moment.");
      else show("working", "Preparing", "Preparing the pictures…");
    });

    // The pictures were prepared: report what will be written and ask the player.
    ctx.on("skinImport.staged", (event: SkinImportStaged) => {
      if (event.requestId !== requestId) return;
      if (event.stageId == null || !event.report) {
        show("error", "Could not prepare the skin", event.error ?? "Unknown error");
        return;
      }
      stageId = event.stageId;
      const kib = Math.round(event.report.totalBytes / 1024);
      show("ready", "Ready", `${event.report.files.length} files, ${kib} KiB.`, [{ id: "create", label: "Create the skin", primary: true }]);
    });

    // A button of the panel (`dismiss` when the player closes it).
    ctx.on("skinImport.action", (event: SkinImportAction) => {
      if (event.id === "dismiss") {
        requestId = null;
        stageId = null;
      } else if (event.id === "create" && stageId !== null) {
        requestId = skinImport.create({ stageId });
        show("working", "Creating", "Writing the skin folder…");
      }
    });

    // The folder was written under its own free name, never over another skin.
    ctx.on("skinImport.created", (event: SkinImportCreated) => {
      if (event.requestId !== requestId) return;
      if (event.id == null) show("error", "Could not create the skin", event.error ?? "Unknown error");
      else show("done", "Done", `The skin ${event.id} is in your skins folder.`, [{ id: "edit", label: "Open in the skin editor", primary: true, editSkin: event.id }]);
    });
  },
});

The flow is always the same: register in setup, opened gives you the source, you describe the skin and call stage, staged tells you the sizes, you show a card with a create button, action brings the click, you call create, and created gives the name of the new skin. A request number tells your handlers which answer belongs to which call.

The card

skinImport.panel takes a declarative description, shown in a modal of the Skins page. The page invents no text, no icon and no color: everything comes from the card, as text (never as HTML). The visual fields are optional and checked in Rust.

Field Content
title, status The title and working, ready, done or error. detail and icon are optional.
badges Colored pills under the title: { text, tone, icon? }, at most 16. tone is ok, warn, bad or info.
tiles Big figures: { label, value, icon?, tone?, meter?, hint? }, at most 6. meter { value, max } adds a gauge, green up to three quarters, amber after, red at the limit unless tone is set.
sections { heading, rows[{ label, value, icon?, tone?, parts? }] }, at most 6 sections of at most 24 rows. parts (at most 8 chips of { text, icon? }) shows the row as chips; value stays the full sentence for screen readers.
notes { level, text, icon? }, at most 48. error and warning stay visible with their icon; info is folded in a closed Details area.
actions Buttons: { id, label, primary?, editSkin? }, at most 4. editSkin: "<id>" makes the page open the skin editor on that skin.

An icon is a name from the closed list of the game (PANEL_ICONS: lucide icons such as check, image-off, scaling, gauge, circle-x), and another name refuses the card. The pick a folder, pick an .osk file and Close buttons belong to the page and are translated by the interface; the importer's declaration takes name (1 to 64 characters) and description (0 to 256) and an optional localized table for en, fr, zh and ko; its id is 1 to 32 characters among a-z, 0-9, -, _, starting with a letter or digit.

Limits

Reading the source (crates/skin_import):

Limit Value
.osk archive 512 MiB
Entries of an archive, or files visited in a folder 8192
One file read (a picture or skin.ini) 64 MiB
Uncompressed total of the pictures and skin.ini 1 GiB
Folder depth 6 levels (links and junctions are ignored)
Path 8 levels, 200 characters
skin.ini 2 MiB, UTF-8 or UTF-16, // comments; at most 64 [Mania] blocks
Pictures listed 4096
Animation frames looked for 64
Size of a picture read 40 megapixels, 65 535 px per side

Writing the skin:

Limit Value
Layouts of a description 8
Pictures of a converted skin 256
Bytes of pictures of a converted skin 16 MiB
One output picture 4 MiB, 2048 px per side
Frames of one animation 32
Budget of a shipped skin 900 KiB: reported (budgetBytes, overBudget) but not enforced; the mod decides whether to reduce
Name, author of a skin 64 characters each; description 1024

A mod's calls keep the usual budget of 30 ms. At most 8 jobs wait in the queue; past that a request is refused as busy and the call returns null.

The converter mod

pvng.skin-converter converts every Keys: 4 to Keys: 9 section it finds into the layouts 4K to 9K of the game, with their own columns, widths and pictures. A key count with no section is not invented: the generated skin.ts uses the closest converted layout (the lowest on a tie) and repeats its columns. Sections 1K to 3K and 10K and above are not converted, and the card counts them. Without a usable [Mania] section the mod uses osu!'s documented default values and the card says so.

The rules are those of content/skins/default/skin.ts, which was converted by hand:

osu! Prism
Unit: a screen 480 points high Sizes are points ÷ 480 (screen heights); x is 0.5.
ColumnWidth laneWidth (and a width per lane when widths differ).
ColumnSpacing laneGap: the gap moves lanes, it never narrows one.
HitPosition receptorY: the bottom of the notes sits on the line.
NoteImage{N} note of lane N; noteSize from the lane width and the picture's ratio.
NoteImage{N}L, NoteImage{N}T holdBody, holdEnd, with holdMatchNoteWidth: true.
KeyImage{N}, KeyImage{N}D receptor, receptorPressed, cropped to their visible part and centered on the receptor line.
Colour{N}, ColourLight{N} laneColor, stageLightColor.
StageLight stageLight, its edge on the hit position.
LightingN, LightingL, LightFramePerSecond hitLight, holdLight ({n}, frames, fps) at LightPosition.
JudgementLine, ColourBarline judgementLine, measureLines.
ScorePosition, ComboPosition The y of the judgement and combo elements.
@2x images, name-0… animations @2x is preferred; an animation becomes a {n} sequence (lights) or its middle picture (hold body).

What Prism cannot do is listed on the card: a hold head different from the note (NoteImage{N}H), a NoteBodyStyle other than 0, animated notes and keys (one picture is kept), StageLeft, StageRight (left out, no border), StageBottom and StageHint, column lines, SpecialStyle, SplitStages, SeparateScore, ColumnRight, WarningArrow, judgement, combo and score pictures, fonts, sounds, the cursor and menu images. UpsideDown converts the positions and the scroll direction but no picture is flipped. ColumnStart is dropped. Uneven column widths are converted.

Over budget, the mod prepares the pictures again at 80 %, 60 % and 45 % of their size until the skin fits in 900 KiB, never changing a placement value, and the card says pictures reduced. Some values are not verified against osu! itself and are marked so in the mod: the defaults without skin.ini, the UpsideDown behavior and the placement of the hold end (holdEndOffset stays 0, adjust it in the skin editor).

The result is a folder like any other: skin.ts, PNG files and a preview. Open in the skin editor ends the card.

Pitfalls

  • Calling skinImport.register outside setup.
  • Forgetting the request number: a late staged of an older source would build the wrong skin. Compare event.requestId with the one stage returned.
  • Using a skin id that is not valid: the description is refused with the rules of every skin. The game finds a free folder name, not a valid id.
  • Expecting a skin to be overwritten: it never is.
  • Writing a converter that takes the source itself: the mod never gets a path, only SkinSource.

See also

Source in the game repository: docs/convertisseur-skin-osu.md,crates/skin_import/src/lib.rs,crates/skin_import/src/source.rs,crates/skin_import/src/stage.rs,crates/skin_import/src/images.rs,crates/modding/src/importers.rs,crates/modding/src/api.rs,content/mods/skin-converter/main.ts,content/mods/skin-converter/convert.ts