Writing Controller Mods

A mod package is a folder of files that teaches OJD about a controller, like an add-on pack for a game. You make it once and share it. Anyone can install it with one command and remove it again. It changes nothing inside the signed app.

Important

Apple signs the list of products that the Xbox USB driver claims. A mod package can’t add a controller to that list.

A mod package is a folder of records and profiles with a manifest, for sharing controller support with others. One command adds or removes it from ~/Library/Application Support/OpenJoystickDriver/Packages, and the signed app stays untouched. Write the manifest, then run ojd mod validate and ojd mod install.

flowchart LR
    f[Folder with manifest] -->|"ojd mod validate"| ok[Checked]
    ok -->|"ojd mod install"| pk[Packages folder]
    pk -->|"service picks it up"| ojd[OJD]

Contents

Package Layout

A package adds files to the ones OpenJoystickDriver (OJD) already reads. It holds only settings files, never programs, so it can’t run anything on your Mac. A record for a raw-USB controller works only when macOS lets OJD open the device.

A package is a folder with a mod.plist manifest and up to four subfolders:

ojd-sample/
  mod.plist
  Controllers/1209-0001.plist
  Profiles/sample-pad.plist
  VirtualDevices/1209-0001.plist
  • Controllers/ holds controller records. Name a Controller file vvvv-pppp.plist (lowercase hexadecimal). Name a ControllerPatch file vvvv-pppp.patch.plist, model-vvvv-pppp.patch.plist, or all.patch.plist.
  • Profiles/ holds profiles (format).
  • VirtualDevices/ holds VirtualDevice files, which choose the virtual gamepad that games see. Name each file vvvv-pppp.plist for a model, or vvvv-pppp-U-UNIT.plist for one controller (UNIT is the 16-character unit ID from ojd controller show).
  • Protocols/ holds protocol descriptions that Controller files can name. Name each file FamilyName.plist after its UpperCamelCase family. See Define a Family With a Description.

The sample package ojd-sample is in docs/sdk/sample. It adds a generic HID pad, a Start-to-space profile, and a virtual gamepad. Its ID 1209:0001 is a pid.codes test ID. In a package you share, use real vendor and product numbers (VID and PID).

Every file is an XML property list. plutil -lint FILE.plist checks one.

OJD refuses any file, folder, or link outside the layout. It skips hidden and .js files and never runs or copies a script. To make documents with a script, use ojd generate.

The Manifest

mod.plist names the package and lists every file. This is the sample manifest:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
 <key>apiVersion</key>
 <string>openjoystickdriver/v1alpha4</string>
 <key>author</key>
 <string>OpenJoystickDriver</string>
 <key>controllers</key>
 <array>
  <string>1209-0001.plist</string>
 </array>
 <key>kind</key>
 <string>ModPackage</string>
 <key>name</key>
 <string>ojd-sample</string>
 <key>profiles</key>
 <array>
  <string>sample-pad.plist</string>
 </array>
 <key>requires</key>
 <dict>
  <key>minimum</key>
  <string>0.6.0</string>
 </dict>
 <key>version</key>
 <string>1.0.0</string>
 <key>virtualDevices</key>
 <array>
  <string>1209-0001.plist</string>
 </array>
</dict>
</plist>
  • apiVersion: openjoystickdriver/v1alpha4. OJD rejects any other version.
  • kind: ModPackage.
  • name: Lowercase letters, digits, and hyphens.
  • version: SemVer without a v prefix.
  • author: Non-empty text.
  • requires: The OJD versions the package runs on. minimum is the first version. below is the first version too high (optional). Prereleases follow SemVer order.
  • controllers, patches: The Controller and ControllerPatch files in Controllers/.
  • profiles, virtualDevices: The files in Profiles/ and VirtualDevices/.
  • protocols: The files in Protocols/. OJD refuses a file with E5002 or E5003 when its family is built in or its file name isn’t its family name. It also refuses one that sets no display name or no defaults.input.layouts.

An included list must name a file, and at least one list must be included. OJD refuses a mod.plist with any other key, such as records or personas, with E4001. It refuses a Controller file under patches or a ControllerPatch file under controllers with E4003.

Every file in a subfolder must be in the manifest, and every file in the manifest must be in its subfolder. Otherwise OJD refuses the package. Each listed file must be valid for its kind.

OJD skips a package whose requires leaves out the running version. ojd mod list shows E4002. A development build has no SemVer version. It uses every package, but ojd mod validate and ojd mod install refuse every package on it.

Precedence and Clashes

A package is a read-only layer between the bundled catalog and your own files. A package Controller file is for a model with no bundled record. A package ControllerPatch changes a bundled or packaged record. For the same model, your files win over a package, and your ControllerPatch wins over the package record and package patches.

Think of three stacked sheets of tracing paper. OJD reads from the bottom up, and the top sheet wins where they overlap:

flowchart BT
    B[Bundled catalog, inside the app] --> P[Mod packages, read-only]
    P --> Y[Your own files: they win]
  • ojd mod install and ojd mod validate refuse a package whose controller, patch, or virtual gamepad covers a model that your files or another package hold. They also refuse a protocol description with a file name already held, and a profile with an ID or name already held. The code is E4004. --force does not override it.
  • A clash can appear after install, such as when you add a record later. Your file wins. Among packages, the first by name wins. ojd record list names each ignored package record and the reason. OJD doesn’t report an ignored package profile. ojd status and ojd diagnose list each ignored virtual gamepad file.
  • If you remove a package that defines a model your ControllerPatch patches, OJD lists the patch as a problem and skips it.

Package Profiles Are Read-Only

You can activate a profile that a package ships, but not change it. OJD refuses a change with E3029. Duplicate the profile and edit the copy.

Manage Packages With ojd mod

These commands need no running service. The running service watches ~/Library/Application Support/OpenJoystickDriver/Packages and applies changes without a restart.

ojd mod validate FOLDER
ojd mod install FOLDER [--force] [--dry-run]
ojd mod list
ojd mod remove NAME [--force] [--dry-run]
  • mod validate: Checks the manifest, requires, the files, and clashes without installing. It exits with code 1 and the E4xxx or E5001 code when it refuses the package.
  • mod install: Checks the package and copies it to Packages/NAME. An installed package of the same name gives E4005 unless you pass --force. --force never overrides requires, a clash, or an invalid file. --dry-run writes nothing.
  • mod list: Lists installed packages with version, author, and files. An unused package shows its reason and code.
  • mod remove: Deletes only that package’s folder. It asks first on a terminal, and needs --force otherwise. It exits with code 1 and E4006 when the package isn’t installed. --dry-run deletes nothing.

You can add and remove a package in the Library area of the app, too:

The Library area. A red arrow points to the toolbar buttons, and the box names them from left to right: add, check a file, test on a packet capture, and remove. A second arrow points to the Installed and Built-in lists

To try the sample, run ojd mod validate and ojd mod install with the sample folder path. Then run ojd mod list, and ojd mod remove ojd-sample to clean up.

Error Codes lists E4001 to E4007. Run ojd explain E4004 to read a code.

Add Rumble With a Patch

A generic gamepad with motors stays still until a record names its rumble report. macOS doesn’t drive those motors. A ControllerPatch can add the report to a bundled HIDDescriptor mode in session.rumble. The patch can live in your own Controllers folder or in a package. Add Rumble to a Controller lists every key.

This patch gives the DragonRise 0079:0006 pad the report that Linux hid-dr.c writes: command 0x51, the weak motor at byte 2, and the strong motor at byte 4. Each motor report is followed by the FA FE commit report, and F3 00 stops the motors. Save it as 0079-0006.patch.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
 <key>apiVersion</key>
 <string>openjoystickdriver/v1alpha4</string>
 <key>kind</key>
 <string>ControllerPatch</string>
 <key>patch</key>
 <dict>
  <key>modes</key>
  <array>
   <dict>
    <key>id</key>
    <string>default</string>
    <key>session</key>
    <dict>
     <key>rumble</key>
     <dict>
      <key>bytes</key>
      <string>51 00 00 00 00 00 00</string>
      <key>followUp</key>
      <array>
       <string>FA FE 00 00 00 00 00</string>
      </array>
      <key>highFrequency</key>
      <dict>
       <key>byte</key>
       <integer>2</integer>
      </dict>
      <key>lowFrequency</key>
      <dict>
       <key>byte</key>
       <integer>4</integer>
      </dict>
      <key>report</key>
      <dict>
       <key>id</key>
       <integer>0</integer>
       <key>kind</key>
       <string>Output</string>
       <key>length</key>
       <integer>7</integer>
      </dict>
      <key>stop</key>
      <string>F3 00 00 00 00 00 00</string>
     </dict>
    </dict>
   </dict>
  </array>
 </dict>
 <key>selector</key>
 <dict>
  <key>productID</key>
  <integer>6</integer>
  <key>vendorID</key>
  <integer>121</integer>
 </dict>
</dict>
</plist>

Before you edit the record, send the bytes by hand to learn which report the pad takes:

ojd controller send 0079:0006 "51 00 C8 00 C8 00 00"
ojd controller send 0079:0006 "FA FE 00 00 00 00 00"

The first command starts the motors and the second stops them. ojd controller send writes each report once, with no patch installed.

Pads sold under 0079:0006 differ inside: some have no motors, and some have a different report descriptor. Set length to the output report size your pad’s descriptor gives. Then check the patch on the pad:

  1. Run ojd record validate 0079-0006.patch.plist, then ojd record install 0079-0006.patch.plist.
  2. In a second window, run ojd controller capture 0079:0006 to see each Tx report OJD sends.
  3. Run ojd controller rumble 0079:0006 --left 200 --right 200.

If the motors stay still while Tx reports appear, the pad needs a different report. Open an issue with the capture and the report descriptor, so the patch can join the bundled catalog once a motor is felt on hardware.

Further Reading