Repository navigation
Plugins
A plugin tells ctrpass how a game's StreetPass message body is laid out: which fields it has, which values each field allows, and how to make a new body.
With a plugin installed, the game can be read and built with ctrpass title and edited in the desktop app's message editor, without rebuilding ctrpass.
Messages for games without a plugin are still exchanged, stored, imported and exported unchanged. A plugin is only needed to read or build a game's messages values, like the quote in StreetPass Mii Plaza.
ctrpass keeps every key in the key file. A plugin only reads and writes the body. ctrpass signs the message, and it protects any applicable Mii record in the body with the slot 0x31 key itself.
Copy the plugin file into the plugin folder:
| Option | Folder |
|---|---|
| Default |
$XDG_DATA_HOME/ctrpass/titles, usually ~/.local/share/ctrpass/titles
|
CTRPASS_PLUGINS env var |
The folder plugins are stored |
Radio commands run with sudo, and under sudo the default folder is root's. Set CTRPASS_PLUGINS or copy plugins into root's folder too if you build messages as root.
There are two kinds of plugin file:
| Kind | File | Use |
|---|---|---|
| Layout file | .toml |
Every field sits at a fixed spot in a body of fixed size. No code. |
| Module | .wasm |
WebAssembly code reads and writes the body. For formats a layout can't describe, e.g. lists, compression or variable size bodies. |
StreetPass Mii Plaza ships with ctrpass as a built-in layout file, mii-plaza.toml.
- Built-in plugins load first.
- Plugin files load in file name order.
- A plugin file for the same game as a built-in plugin replaces it, with a warning.
- A second plugin file for the same game is an error, and that file is skipped.
A plugin that fails to load is reported with the reason.
# Loaded plugins, plugins that failed to load, and warnings
ctrpass plugins list
# Load one file and make, read and rewrite a body with it, without installing it
ctrpass plugins check my-game.tomlplugins check fails when the values read from a new body don't write back to the same bytes, or when a new body has problems. It uses a made-up identity and Mii key, so it needs no key file.
In the desktop app, the Games page shows Built-in or Plugin next to each game that has an editor, and lists plugins that failed to load under Plugin Errors.
Once installed, a game is used like StreetPass Mii Plaza:
ctrpass title list
ctrpass --keys aes_keys.txt title build "My Game" --set score=1200 -o my-game.bin
ctrpass --keys aes_keys.txt title show my-game.binThe game is found by its title ID in hex or by its name. Building a message needs the game's signing key in the key file. See Making the key file.
Both kinds of plugin start with the same keys:
| Key | Meaning |
|---|---|
api |
Plugin interface version. Must be 1. |
title |
Title ID in hex, such as "00020800". |
name |
Game name, shown in the app and accepted by ctrpass title. |
version |
The plugin's own version. |
author |
Who wrote the plugin. |
message_text |
Text shown with a new message. |
send_mode |
CEC send mode of new messages. Default 0. See CEC Messages. |
message_flags |
Container flags of new messages. Default 3. |
Each field is a [[field]] table in a layout file, or an entry in the fields array of a module's manifest.
| Key | Meaning |
|---|---|
key |
Name used in JSON values and with --set key=value. |
label |
Name shown in forms. |
type |
One of the types below. |
help |
Short text shown with the field. Optional. |
advanced |
true to tuck the field under More in the app. |
| Type | Value | Keys |
|---|---|---|
text |
UTF-16 text |
max characters, forbid characters |
number |
Whole number |
min, max, exclude list, hex to show it in hex |
bytes |
Hex string of len bytes |
len |
image |
Square RGB565 tiled image, as hex |
size in pixels, a multiple of 8 up to 256 |
mii |
96-byte Mii record, as hex |
at: where the protected record sits in the body |
mii_name |
The Mii's name |
mii: key of the Mii field, when there is more than one |
mii_creator |
The Mii's creator name | mii |
mii_id |
The Mii's ID | mii |
mii_mac |
The MAC the Mii was made on | mii |
Numbers can be written as integers or as text, such as max = "0xfffffffffffffffe" for values too large for a TOML integer.
ctrpass handles every mii field itself, in both kinds of plugin. It decrypts the record, applies the mii_* fields, refuses a Mii a console would drop (see Mii Records), and protects it again. A new body gets a Mii made from the store's identity. Plugins never see the key or the protected bytes, and a module's read and write functions never see Mii fields.
Reading or changing a Mii needs the slot 0x31 key in the key file.
ctrpass checks every value against its field before a plugin writes it, and refuses values that break the rules. Values read back from a body that break the rules are listed as problems. The CLI and the app refuse to sign a message that has problems.
A layout file adds the body size and where each field sits. A small example:
api = 1
title = "00ABCD01"
name = "High Scores"
version = "1.0.0"
author = "Someone"
message_text = "New scores"
size = 0x200
[[field]]
key = "player"
label = "Player"
type = "text"
at = 0x10
bytes = 0x20 # room in the body; max defaults to bytes / 2 - 1
[[field]]
key = "score"
label = "Score"
type = "number"
at = 0x04
width = 4 # 1, 2, 4 or 8 bytes
max = 999999
[[computed]]
type = "crc32"
at = 0x00
start = 0x04 # covers 0x04 to the end of the body| Key | Meaning |
|---|---|
at |
Offset of the field in the body. |
bytes |
Text: bytes of room. Text is UTF-16LE, zero padded. |
width |
Number: size in bytes. |
big_endian |
Number: true for big-endian. Little-endian by default. |
copies |
Write the value this many times, stride bytes apart. Default 1. |
stride |
Distance between copies. Defaults to the field's own size. |
read_copy |
Which copy to read, counting from 0. Default 0. |
clear |
[[at, len], ...] ranges zeroed whenever the field is written. |
scale_from |
Image: when only the named image field is set, scale it into this one. |
copies suits games that keep the same text once per language. Mii Plaza writes its country, region and featured software names this way, 16 times, and reads the English copy.
Writing a body changes only the fields given. Bytes no field covers are kept as they are.
[[fill]] # bytes a new body starts with; the rest are zero
at = 0x30
hex = "4e 4f 54 45"
[create]
values = { score = 0 } # image fields also take "standard", ctrpass's default icon
identity = { score = "hat" } # field key = identity valueIdentity values come from the store's seed: mii_id, creator_mac, face_shape, gender, hat, dream and hobby.
A new body is made in this order:
- zero bytes of
size, then each[[fill]]; - a new Mii in every
miifield, from the identity; - the
createvalues, checked and written like any other values; - computed values.
[[check]] # a problem unless the bytes at `at` match one of these
at = 0x30
one_of = ["4e4f5445"]
problem = "the body has no header"| Type | Value | Keys |
|---|---|---|
crc32 |
CRC-32 (IEEE) of a byte range, 4 bytes |
start, end (default: end of body) |
length |
Number of UTF-16 characters in a text field |
field, width
|
count |
Entries of stride bytes that are not all zero |
start, stride, entries, width
|
All take at and big_endian. Computed values are written after every change, checksums last, so a checksum covers the other computed values. A checksum may not cover its own bytes. A computed value that doesn't match the body is listed as a problem.
ctrpass rejects a layout file that has unknown keys, fields past the end of the body, two fields with the same key, a number range that doesn't fit its width, or create values that break their field's rules. TOML errors are reported with their line number.
A module is a WebAssembly file that imports nothing. It runs in an interpreter with no access to files, the network or keys. Each call runs in a fresh instance limited to 64 MiB of memory and a fixed number of instructions, so a plugin that crashes or never returns only fails its own call. Bodies are limited to 0x18000 bytes, the largest a container holds.
A module exports memory and these functions. Inputs are written into the module's memory and passed as a pointer and length:
| Export | Input | Result |
|---|---|---|
ctrpass_alloc(len) -> ptr |
Room for len bytes of input |
|
ctrpass_manifest() -> out |
Manifest and fields, as JSON |
|
ctrpass_create(ptr, len) -> out |
Identity values, as JSON | New body |
ctrpass_read(ptr, len) -> out |
Body | Field values, as a JSON object |
ctrpass_write(ptr, len, ptr, len) -> out |
Body, then values as JSON | New body |
ctrpass_problems(ptr, len) -> out |
Body | JSON array of text |
Pointers and lengths are i32. Each out is an i64 with the result's pointer in the high 32 bits and its length in the low 32. The result's first byte is 0 when the rest is the result, or 1 when the rest is an error message in UTF-8.
Values are JSON: text as strings, numbers as integers, and bytes and images as hex strings. ctrpass_write is only given the values being set. Fields not in them keep their bytes.
sequenceDiagram
participant C as ctrpass
participant M as Module
C->>C: check values against the fields
C->>M: ctrpass_alloc, then copy the body and values in
C->>M: ctrpass_write(body, values)
M-->>C: status 0 and the new body
C->>C: check the body size, then put the Mii in
C->>C: sign the message
examples/note-board is a module written in Rust for a made-up game whose body holds a list of notes and a checksum. Build and check it with:
rustup target add wasm32-unknown-unknown
cargo build --release --target wasm32-unknown-unknown --manifest-path examples/note-board/Cargo.toml
ctrpass plugins check examples/note-board/target/wasm32-unknown-unknown/release/note_board.wasmAny language that builds WebAssembly without imports works the same way.
A plugin is a single file. Share it like any other file. It is advised to always check the contents to a plugin just in case.
How to set up
- Overview and requirements
- Choosing a Wi-Fi adapter
- Building and installing
- Making the key file
- Desktop app
- Command line
- Messages and emulators
- Troubleshooting
Plugins
Protocol
- Overview
- Discovery
- Link setup
- Frames and CCMP
- YY transport
- Exchange flow
- Exchange objects
- CEC messages
- CEC message boxes
- Mii records
- Mii Plaza
- Keys
ctrpass library
Linux