Browser for Trainz .cdp packs: it lists every asset inside one and writes any
of them back out as a pack of its own, or takes the files out of them - the
textures, meshes, scripts and sounds an asset carries - as ordinary files. A
.cdp2 - the name Trainz Classics gives a pack it downloads - is the same kind
of file and opens the same way, and
so does a .cmpa: a CMP archive, the bundle Content Manager Plus writes as one
small pack per asset rather than one pack for the lot.
Features:
- Lists the assets of a
.cdp, a.cdp2, a loose.chumpor a.cmpaarchive: kuid, kuid2, username, author, kind, class, build, region, era, description and the pack they came from - Filters the listing as you type, across every column or one you pick, and copies a kuid, an asset or a whole list to the clipboard
- Right-click a row, an asset's branch, one of an asset's files or a whole pack for its copies, its exports, its extraction, its packing and its unpacking, without reaching up to the menus
- Extracts one asset, or the whole pack, as individual
.cdpfiles, with the file name built from whichever parts of the asset you choose, and asks about a file that is already in the folder before replacing it - Packs a run of assets back into a single
.cdpor.cdp2of your own naming - the rows you picked, one whole pack, or everything that is open - taken out of as many files as you like and written as one pack the game reads. A run that uses one kuid twice, the same asset open in two packs, is refused by name rather than written as a pack the game cannot load - Unpacks the files inside the assets instead: one file, one of an asset's
folders, one asset or every asset opened. An asset, a pack or the whole listing
gives a folder per asset named by the same pattern, with the folders the asset
holds made again inside it; a folder clicked on in the tree comes across as it
stands, with no folder named for the asset above it. Each asset comes with its
own settings beside its files -
config.chump, the tags as the game keeps them, orconfig.txtwhen Settings... is ticked to write the text form - since a folder of meshes and textures without them is not an asset the game can load - Reads several packs into one listing in the background, one pack at a time, and says which pack it could not read and why
- Shows a bar in the status line while packs are being read or written out, with a Cancel button beside it, so a long run can be stopped at any point
- Exports the listing, or the rows you picked out of it, as CSV
- Comes as a window and as a command line, both reading the packs and writing assets out the same way
From a terminal:
pip install -e ".[gui]"
cdpexplorer-gui # open the listing window
cdpexplorer 5kuids.cdp # extract the pack beside itself, list on stdout
cdpexplorer 5kuids.cdp -n # just list what is inside
Or, from a checkout, without installing anything (only needs Python 3.9+, and PyQt6 for the window):
python cdpexplorer_gui_entry.py
python cdpexplorer_cli_entry.py 5kuids.cdp -n
Prebuilt Windows builds come as a portable zip and a per-user MSI; Linux gets
.deb and .pkg.tar.zst, macOS a .dmg. See
Releases.
usage: CDPExplorerCLI [-h] [-o DIR] [-d [CSV]] [-k [TXT]] [-l [TXT]] [-n]
[--name-parts PARTS] [--underscores] [--kuid2]
[--on-existing {rename,overwrite,skip}] [-q] [-v] [-V]
[cdp]
List the assets of a Trainz CDP pack or CMPA archive, and extract them as
their own CDP files.
positional arguments:
cdp the .cdp, .cdp2, .chump or .cmpa file to open
options:
-h, --help show this help message and exit
-o, --output DIR where to write the extracted assets (default: the
folder the CDP file is in)
-d, --details [CSV] write the listing as a CSV file here; with no name or
'-' it goes to stdout, and 'none' skips it
-k, --kuids [TXT] write the kuid list here; with no name or '-' it goes
to stdout, and 'none' skips it
-l, --list [TXT] write the asset list - one line per asset, its kuid
then its name - here; with no name or '-' it goes to
stdout, and 'none' skips it (default: skipped)
-n, --no-extract only list the pack, and write no asset files
--name-parts PARTS comma separated parts of an extracted file's name,
chosen from KUID, build, username, (none) (default:
KUID)
--underscores join the name parts with underscores instead of spaces
--kuid2 name an asset by its kuid2 form, which carries the
version too
--on-existing {rename,overwrite,skip}
what to do when a file of that name is already there
(default: rename)
-q, --quiet say nothing on stderr
-v, --verbose name every file that was written
-V, --version print the version and stop
example: CDPExplorerCLI test.cdp --output D:\temp --details D:\temp\test.csv
--kuids D:\temp\kuid_list.txt
The default one-liner extracts: cdpexplorer 5kuids.cdp unpacks the pack into the
folder the pack is in and prints both listings on stdout.
- The file named can be a
.cdp, a.cdp2, a loose.chumpor a.cmpaarchive: what a file is comes from its first bytes, so a pack renamed by hand or by a download is still read for what it holds, and an asset extracted from an archive comes out as a.cdplike any other. What the command line extracts is a.cdpin every case; naming the ending is the window's file dialog, which takes either. -osends the extracted assets elsewhere. No-omeans beside the pack, which is what makescdpexplorer D:\trainz\packs\foo.cdpdo the obvious thing.-d/-kare the two listings: the CSV table and the kuid list. A name writes a file, no name or-writes to stdout,noneskips it. With neither switch given, both go to stdout - socdpexplorer 5kuids.cdp -k -is "kuids on stdout", andcdpexplorer 5kuids.cdp -kmeans the same.-l/--listis the third listing, the one the window's Export Asset list... writes: one line per asset, its kuid then the name a person calls it by -<kuid:303030:10091> Al_trava_1. Same three answers as the others, but it waits to be asked for, so an ordinary run does not end with a page of names:cdpexplorer 5kuids.cdp -n --listsays what is in the pack, and--list assets.txtputs the same in a file beside the CSV and the kuids.-nlists and writes no asset files, which is what you want when the listing is the point:cdpexplorer 5kuids.cdp -n -d listing.csv.--name-partsdecides what an extracted file is called, fromKUID,build,usernameand(none), in the order given, three parts at most.--underscoresjoins them with_instead of spaces, and--kuid2spells the kuid part with its version -kuid2 393457 13 0.cdpwhere the default iskuid 393457 13.cdp. A kuid whose user id is negative stays short under--kuid2too: the 127 sitting above a negative id is only its sign, not a version the asset ever had.--on-existingis what happens when that name is taken:renameadds a number (the default, and the safe one),overwritereplaces the file,skipleaves it alone. A terminal run has nobody to ask, so this switch is the answer; the window asks about each file when it meets one.- Anything said about the run - how many assets were read, progress, where the
files went - goes to stderr, so the listings on stdout stay clean and
pipeable.
-qsilences it,-vadds one line per file written. - Taking the files out of an asset - the textures, meshes and scripts it carries - is the window's work: the command line writes assets and stops there.
- The exit code is
0unless something could not be read or written; a pack with nothing in it is not an error, a pack that is not a pack is. - With no arguments at all it prints this help and stops.
cdpexplorer 5kuids.cdp # extract, list on stdout
cdpexplorer 5kuids.cdp -n -d - -k - # look, write nothing
cdpexplorer 5kuids.cdp -n --list # kuid and name, one line each
cdpexplorer 5kuids.cdp -n -d listing.csv -k kuids.txt # two files, no extracting
cdpexplorer 5kuids.cdp -o D:\temp # extract to D:\temp
cdpexplorer 5kuids.cdp --name-parts KUID,username --underscores
# kuid_303030_10091_Al_trava_1.cdp, kuid_5699_223000_1w_ancor.cdp, ...
cdpexplorer 5kuids.cdp --name-parts username --on-existing overwrite
# 1w ancor.cdp, Al_trava_1.cdp, ...
The window is one table: a row per asset, nine columns across the top, a pack's assets in the order the pack holds them until a column header is clicked. Any number of packs can be open at once - the listing grows, and the tree down the left says which pack each row came from. Nothing is written to disk until a menu item asks for it; the only thing remembered unasked is which packs were opened lately, so the File menu can offer them back.
- File: Open file... (Ctrl+O), Recent files, Close all (Ctrl+W); Export
KUID list..., Export Asset list... and Export Asset details... (Ctrl+E);
Extract as individual CDPs... (Ctrl+X) - one file per asset into a folder you
name - Pack to CDP... (Ctrl+P) - the whole listing into one pack you name, as
a
.cdpor a.cdp2- and Unpack all files to... (Ctrl+U), which takes the files out of the assets instead of the assets out of the pack: a folder per asset, holding its textures, meshes and scripts; then Exit. Everything past the opening works on the opened packs as a whole, so what the listing has selected and what the filters have hidden does not change what is written. Files dropped anywhere on the window open as Open file... does, and a pack named on the command line is read before the window appears. - Edit: Copy KUID list (Ctrl+K), Copy Asset list (Ctrl+L) and Copy Asset details - the listing in the three shapes it is copied in: one run of kuids, one line per asset, or CSV rows; then Settings... (Ctrl+,).
- Assets, calling itself Asset while one row is picked out, holds the same commands a right click shows, so the words and the shortcuts match in both places, and which half is on show follows the selection. Both halves copy the same three ways - a run of kuids (Ctrl+C), one line per asset (Ctrl+I), the rows as CSV - and both extract and unpack, one asset into one file or the picked run into a folder. The run's half adds Pack to CDP..., which writes that run into one file instead: one asset on its own does not offer it, because one asset is one pack and extracting it already writes that file. A right click asks about whatever is under the cursor: a row or an asset's kuid branch is one asset, a file branch or the tree's root is a whole pack, and a file branch adds Remove, the one item that is not an asset command - it takes the pack off the listing and leaves the file on disk. The folders and files an asset carries are part of it rather than assets of their own, so their menu holds only Unpack to...
- Tools: Statistics..., and three ways of finding the same asset more than
once among everything that is open.
- Statistics... graphs the assets six ways - By Author, By Kind, By Class, By
Build, By Region, By Era - counting every opened asset whether a filter
hides its row or not. The window is modeless, so the listing stays usable
beside it, and double-clicking a bar narrows the listing to exactly the
assets that made that bar. Export graph... saves the tab on show as a PNG,
Export data... its numbers as a
Category,CountCSV. - Find duplicate assets lists every kuid another open asset uses too. Find
assets with multiple versions lists one asset met in two versions, however
either is spelled:
<kuid:123:1234>beside<kuid2:123:1234:2>. Find conflicting assets lists every kuid whose copies say different things about themselves - another username, kind, class, build, region, era or description - which means the packs do not hold the same asset after all. All three count every opened pack, sort the listing by KUID, and put a phrase in the filter box -Duplicate KUIDs,Multiple versions,Conflicting assets- whose X brings the whole listing back.
- Statistics... graphs the assets six ways - By Author, By Kind, By Class, By
Build, By Region, By Era - counting every opened asset whether a filter
hides its row or not. The window is modeless, so the listing stays usable
beside it, and double-clicking a bar narrows the listing to exactly the
assets that made that bar. Export graph... saves the tab on show as a PNG,
Export data... its numbers as a
Around those menus:
- The tree down the left maps what is open: the "All opened files" root, a
branch per pack, that pack's asset kuids, and the files and folders each
asset carries. Picking a file - or anything under it - narrows the listing to
that one pack; picking the root shows every pack again, and double-clicking a
row unfolds the tree to that asset. A
.cmpasays which version wrote it after its name. - Two filter boxes: "Filter files:" hides the tree branches its text does not name, and "Filter content:" keeps only the rows whose text says what you type, acting on every keystroke. "Apply on" looks in one column or, by default, all nine, and the X in either box undoes it.
- The Author column is the user id half of the kuid -
#474195- until the account names behind those ids are asked for. That asking starts closed: the first run is asked whether it may happen at all, and Settings... is the tick that changes the answer. What is found is cached inlocal_assets.tdx, the record stream Trainz uses for the same table - see tdx-format.md. - Columns sort as the text reads, so a build of
1.10comes after1.9, and every column can be dragged to a width of its own. The grid has no Filename column; the copies andExport Asset details...add one when the rows they were given came from more than one pack. - Packs are read in the background, one at a time, so the window keeps drawing while a folder of them fills in. The status line says what was read and what could not be, and a bar with a Cancel button runs through reading, writing and unpacking. A file already in the folder being written to is asked about when it is met, rather than settled by a setting beforehand.
- Settings... decides what an extracted asset is called - a pattern with
$kuid,$usernameand$buildwritten into it - and whether an unpacked asset's own settings come out asconfig.chump, as the game stores them, or asconfig.txt, the text a person can read and edit.
The settings are stored in:
%APPDATA%\CDPExplorer\settings.json (Windows)
~/.config/CDPExplorer/settings.json (elsewhere)
They are the naming rules, whether to ask for author names, and the window's
size and maximized state, which the command line ignores: a terminal run is
named by its switches, so the same command does the same thing on any machine.
What the window keeps beside them is the author names it has looked up, in
local_assets.tdx, and the last ten packs it was asked to open, in
recent.json; the command line writes neither.
src/cdpexplorer/chump.py the .cdp, .cdp2 and .chump reader and writer:
read_assets, write_asset, asset_contents,
extract_assets, pack_assets
src/cdpexplorer/cmpa.py the .cmpa archive: a chump document per asset,
read with chump.py's tag reader
src/cdpexplorer/lzss.py the coder an asset's files are written in: decode_blob
src/cdpexplorer/asset.py Asset: the tags a row shows; ten columns
for a CSV, nine for the grid
src/cdpexplorer/kuid.py kuid: the 8 bytes, and the <kuid>/<kuid2> spellings
src/cdpexplorer/filenames.py NameStyle: what an extracted file is called
src/cdpexplorer/export.py the two listings: CSV and the kuid list
src/cdpexplorer/extraction.py extract_to(): the one way an asset is written as a pack
src/cdpexplorer/unpack.py unpack_to(): the files inside an asset, as files
src/cdpexplorer/chumptext.py the text form of a config.chump, as the game writes it
src/cdpexplorer/settings.py settings.json: what is remembered between runs
src/cdpexplorer/recent.py recent.json: the packs opened lately, for the menu
src/cdpexplorer/authors.py local_assets.tdx: the account names behind author
ids, and the page that says what they are
src/cdpexplorer/paths.py where that folder is, per system
src/cdpexplorer/cli.py command line
src/cdpexplorer/gui/ PyQt6 window: window.py, table.py, open.py,
extract.py, unpack.py, authors.py, filter.py,
tree.py, settings_dialog.py, about.py, resources.py
cdpexplorer_cli_entry.py entry points used by PyInstaller
cdpexplorer_gui_entry.py
tests/ 770 tests
tests/test_files/ sample packs and archives (.cdp, .cdp2, .cmpa),
their expected listings, and the config.txt the
game wrote for one of them
build.py PyInstaller exes, dmg, deb, pkg.tar.zst
installer/ WiX v5 per-user MSI (Windows)
hooks/ PyInstaller hooks
assets/ the icon
The window and the command line both go through extraction.py, so an extracted
pack is written the same way by both; chump.py is the only thing that reads or
writes a chump block - cmpa.py walks an archive's records and asks chump.py
for the tags inside them - and filenames.py is the only thing that decides a
name. An unpacking goes the other way: chump.py and cmpa.py hand over each
asset's files as the pack stores them, lzss.py takes the coding off one at a
time, and unpack.py decides where each lands - so one unreadable file costs one
line in the report rather than the whole asset.
The gui/ package is the only part that imports Qt, which is why the CLI builds
into a 10 MB exe with no Qt in it at all.
chump.py decides what a file is from its first four bytes, never from its
name: ACS$ is one chump document holding a whole pack, crak is a CMPA archive
- a chump document per asset, each with its own record header - and is handed to
cmpa.py, which reads it with the same tag reader and the same pack writer. Anything else is refused. That is what lets a pack named.cdp2, or an archive renamed to.cdp, open for what it holds rather than for what it is called. Each asset remembers the span of the file it came from - the container tag in a pack, the record header and its document in an archive - so it can be written out again without the file being read a second time, and comes out as a.cdpeither way, which is the shape a pack is read back in.extract_assetswraps each asset in a pack of its own;pack_assetswraps a run of them in one pack, itscontents-tablenaming every asset inside, and the assets of a run may come from as many files as were opened - an archive's asset gets the container tag a pack would have held it in, written around the tags the archive keeps loose.
pip install -e ".[test]"
python -m pytest
The samples in tests/test_files are ground truth: each pack is read and its
assets compared to the files beside it - the .csv listing, the _kuids.txt
comma-separated kuid list and the _assets.txt one-line-per-asset list the old
program wrote - and every asset is then extracted and read back out of the file
it was written to. A run of a pack's assets is also written into a pack of its
own and read back: same listing, same files inside each asset, and one kuid
listed once in the contents-table. Those expectation files are kept byte-exact
by .gitattributes, so don't let an editor rewrite them.
One sample carries the other ending: sig_shunt.cdp2 is four signals in a pack
the game downloaded under that name, and it is an ordinary CHUMP pack underneath,
which is what a real .cdp2 turned out to be. The container is decided by the
first four bytes, never by the name, so the reader takes .cdp2 wherever a file
is accepted and the tests read that sample like any other.
Another sample is the other kind of file: 5kuids.cmpa holds the same five
assets as 5kuids.cdp, written by Content Manager Plus as one CHUMP document per
asset with a 12-byte record header in front of each - which is what a .cmpa
is. Same tags, same files, same bytes inside them, so the archive's listing, its
copies and its extractions are checked against the pack's, and against the three
expectation files beside it, order aside: an archive is walked through its
records, and CMP wrote the two scenery assets together where the pack has a piece
of track between them. The damaged archives the format note lists - cut short,
half written, the size field lying - are written out in the tests rather than
carried in the repository.
The GUI tests drive a real window off-screen - menus, sort orders, the filter box and its dropdown, both dialogs, drag and drop, the Recent files menu and the list it reads out of the settings folder - so the window is covered too, not just the reader. Without PyQt6 installed they skip.
The files inside the assets are checked two ways, since a decoder has no proof
but its output: the worked examples of lzss-format.md spelled out byte by byte,
and the samples' own files - a JPEG, a bitmap, an IM and a TGA header, where a
tree decoded one bit wrong would give noise - each coming out at the length its
own header declares. The pack and the archive of the same five assets have to
answer with the same bytes at every path. What an unpacking writes is then
checked against the names the window would have asked about beforehand: the same
files in the same folders, the asset's own folders among them, one damaged file
costing one line of the report rather than the asset, and each asset's settings
among the files asked about - under config.chump or, when the setting is on,
under config.txt.
Those settings have a sample of their own: wozek lxd2_config.txt is the
config.txt the game wrote for that same asset out of that same pack, into its
own editing folder. Rendering the pack's tags has to come out that file byte for
byte, which is the only way to pin down a layout nobody wrote down - the value in
column 40, two spaces for every level of containers, an empty container with
nothing between its braces, and a blank line carrying its own indent over every
container. The rules are spelled out separately beside that one comparison, so
a rule broken somewhere rare says which rule it broke.
PyInstaller cannot cross-compile, so build.py builds what its host OS
supports:
| Host | Artifact | Needs |
|---|---|---|
| Windows | dist/CDPExplorer-<ver>-windows.zip (both exes) |
pip install -e ".[gui,build]" |
| Windows | dist/CDPExplorer-<ver>.msi |
WiX v5, pwsh installer/build.ps1 |
| macOS | dist/CDPExplorer-<ver>-macos.dmg |
hdiutil |
| Linux | dist/cdpexplorer_<ver>_amd64.deb |
fpm |
| Linux | dist/cdpexplorer-<ver>-x86_64.pkg.tar.zst |
fpm |
python build.py # everything this host can do
python build.py --only exe # or dmg, deb, zst
pwsh installer/build.ps1 # MSI; expects the exes build.py just made
The window and the command line are two programs, and on Windows they are two
exes: one built --windowed has no console to write listings to, one built
--console flashes a terminal open when double-clicked. So CDPExplorer.exe
is the window and CDPExplorerCli.exe is the thing typed in a terminal.
The version is written in three places - pyproject.toml,
cdpexplorer.__version__ and installer/Product.wxs - and they have to agree;
build.py compares the first two before it starts.
The installer installs for the current user only, no elevation: both exes
under %LOCALAPPDATA%\Programs\CDPExplorer, a Start Menu shortcut for the
window, the folder added to the user PATH so cdpexplorercli works from any
terminal, and an entry in Add/Remove Programs. Rebuilding the same version is
fine - it replaces the old install.
The name is spelled two ways on purpose. CDP Explorer, with a space, is what
a person reads: the window title, the Start Menu shortcut, the Add/Remove
Programs entry. CDPExplorer, without one, is what a person types:
CDPExplorer.exe, the install folder, the settings folder.
The Chump (CDP) file format was determined by reverse-engineering and is described here: Chump File Format Specification
The CMPA archive format - the bundle Content Manager Plus writes, holding one CHUMP document per asset - was determined by reverse-engineering and is described here: CMPA File Format Specification
The coding the files inside an asset are stored in - LZSS with an adaptive Huffman tree, one blob per file, each declared with the length it has to come out at - was determined by reverse-engineering, checked against the sample packs and the packs' own texture descriptions, and is described here: LZSS File Format Specification
The binary KUID format was determined by reverse-engineering and is described here: KUID Format Specification
The table of account names behind the author ids - the same record stream Trainz
keeps in its own assets.tdx, and the file this program keeps beside its
settings - is described here: Trainz User Name Table
A .cdp2 is not a second container. The extension is described as a Trainz
Classics Content Dispatcher Pack 2, and the file this program was checked
against says the same: it starts with ACS$ and holds the usual tags of a pack -
assets, contents-table, kuid-table, obsolete-table, kind "archive",
package-version, username. It turned out to hold the very same ten assets as
a .cdp in the same folder, byte for byte, in a different order and with
username unknown where the other had username leventeb. Nothing here asks
what a file is called, so a pack opens the same way under any of these endings,
and an asset extracted or a run of assets packed to a name you type is written
under either of the two that a pack goes by - the kind the save dialog is left on
when the name does not say which.
A .cmpa is a second container, and a simple one: crak, a short header, then
one CHUMP document per asset with a 12-byte record header in front of each - the
asset's kuid, and where the next record starts - and eight FF bytes to end on.
That is what lets a thousand assets be listed, or skipped, without parsing any of
them, and what lets an archive of a gigabyte and a half open at all. Its assets
carry the same tags, the same files and the same bytes inside them as a pack's
do, so the listing, the tree, the copies and the exports need no second set of
rules; extracting one asset writes an ordinary .cdp, since an archive is a way
of carrying assets rather than a shape to hand one over in. Two things are the
archive's own: each asset is named by its record header, and the listing follows
the records, which is not always the order a pack of the same assets uses. A
truncated or half-written archive still gives up the assets that were written; a
record that is whole but does not add up says which file it is about.
- Chump Editor - edit
config.chumpandconfig.txtfiles - TZarchiver - extract and create
.tzarcarchives - Kuid Lister - create lists of KUIDs from plain text
- Kuid2Hash - convert KUIDs to binary and get the hash folder
For any bugs, issues or feature requests, use the Issues tab in GitHub.
This project is licensed under the GPLv3 License - see LICENSE for details.
This project was possible by doing reverse engineering on the Chump file format (CDP) and no official information was given in regards to this file format from Auran/N3V.
