Skip to content

About

Utility aplication for browsing, searching and extracting Trainz Assets from CDP files.

Topics

Resources

Stars

11 stars

Watchers

1 watching

Forks

Repository files navigation

CDP Explorer

GitHub release (latest by date) Downloads (Latest Release) GitHub all releases

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 .chump or a .cmpa archive: 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 and its unpacking, without reaching up to the menus
  • Extracts one asset, or the whole pack, as individual .cdp files, 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
  • 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, or config.txt when 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

CDP Explorer screenshot

Getting Started

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.

Command line

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 .chump or a .cmpa archive: 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 .cdp like any other. What the command line extracts is a .cdp in every case; naming the ending is the window's file dialog, which takes either.
  • -o sends the extracted assets elsewhere. No -o means beside the pack, which is what makes cdpexplorer D:\trainz\packs\foo.cdp do the obvious thing.
  • -d / -k are the two listings: the CSV table and the kuid list. A name writes a file, no name or - writes to stdout, none skips it. With neither switch given, both go to stdout - so cdpexplorer 5kuids.cdp -k - is "kuids on stdout", and cdpexplorer 5kuids.cdp -k means the same.
  • -l / --list is 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 --list says what is in the pack, and --list assets.txt puts the same in a file beside the CSV and the kuids.
  • -n lists and writes no asset files, which is what you want when the listing is the point: cdpexplorer 5kuids.cdp -n -d listing.csv. --name-parts decides what an extracted file is called, from KUID, build, username and (none), in the order given, three parts at most. --underscores joins them with _ instead of spaces, and --kuid2 spells the kuid part with its version - kuid2 393457 13 0.cdp where the default is kuid 393457 13.cdp. A kuid whose user id is negative stays short under --kuid2 too: the 127 sitting above a negative id is only its sign, not a version the asset ever had.
  • --on-existing is what happens when that name is taken: rename adds a number (the default, and the safe one), overwrite replaces the file, skip leaves 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. -q silences it, -v adds 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 0 unless 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, ...

GUI

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. Add packs as many times as you like - the listing grows, and the tree down the left says which pack each row came from. Nothing is written to disk unless a menu item asks for it; the one thing remembered without being asked is which packs were opened lately, in recent.json beside the settings, so the File menu can offer them back.

  • File: Open file... (Ctrl+O), Recent files - the packs opened lately, newest first, with Clear list under them; Close all (Ctrl+W). Below a line, Export KUID list..., Export Asset list... and Export Asset details... (Ctrl+E); below another line, Extract as individual CDPs... (Ctrl+X) - every asset on the listing, one file each, into a folder you name - 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, named by the same pattern Settings... names an extracted asset by, with that asset's textures, meshes and scripts inside it in the folders the asset itself holds; then Exit (Alt+F4). Everything under the first line works on the opened packs as a whole - the root of the tree on the left - so whatever the listing has selected, and whatever the two filter boxes have hidden, does not change what is written. The open dialog leads with All supported files (*.cdp *.cdp2 *.chump *.cmpa) and then offers the four kinds apart. A .cdp, .cdp2, .chump or .cmpa dropped anywhere on the window is the same as Open file..., and a pack named on the command line is read before the window even appears, which is what "Open with CDP Explorer" does. An archive opens as one branch of the tree, and its assets come in the order the archive holds them in its records, which need not be the order the same assets sit in a pack. Recent files holds the last ten packs opened, newest first, a pack opened twice named once, and Clear list under them; choosing a name reads that pack exactly as Open file... would, added to what is already listed. A pack that has gone missing - a drive that is away, a download that was tidied up - stays listed but greyed out, rather than promise something that will fail, and two packs of one name are written out in full, because copy.cdp twice over is two entries nobody can tell apart.
  • Edit: Copy KUID list (Ctrl+K), Copy Asset list (Ctrl+L) and Copy Asset details - the whole listing again, in the three shapes the Assets menu copies it in: one run of kuids, one line per asset, or CSV rows in the grid's columns, Filename and all when more than one pack is open; then Settings... (Ctrl+,).
  • Assets, calling itself Asset while one row is picked out, is the menu a right click shows, filled from the same list of commands, so the words and the shortcuts are the same in both places - and the word in the bar says which half is coming before it is opened. One row picked out gives that asset's items
    • Copy KUID (Ctrl+C), Copy Asset (kuid and name together, Ctrl+I), Copy Asset details (the row as CSV text), Extract as individual CDP..., which asks for one file to write and offers both *.cdp and *.cdp2 - one container under either ending, and the ending you type is the ending that gets written - and Unpack files to..., which writes that asset's own files out into a folder of its own. Only a loose .chump cannot be written, so a name ending that way comes out as .cdp. A run of rows gives the listing's items instead: the same three copies for the whole group, with the same two keys on them - Ctrl+C the kuids of every row picked, Ctrl+I the kuid and name of each, one per line - then Export KUID list... and Export Asset list... to a .txt you name, Export Asset details... to a .csv with a header row, Extract as individual CDPs... to a folder, and Unpack files to... to a folder of one folder per asset. The half on show follows the selection, and each of the two keys is written on the item of that half that does the same thing, so Ctrl+C copies one kuid for one row and a list of them for a run; the hidden half stays quiet, and the grid's own Ctrl+C for copying cells is not reached. Extracting and unpacking have no key of their own here: Ctrl+X and Ctrl+U are the File menu's, and they ask about every opened pack rather than the rows picked out. A double-click on a row opens that asset's branch in the tree, its folders with it, so everything the asset holds is in sight - it writes nothing and asks for no name.
  • A right click asks about whatever is under the cursor: one row gets that asset's items, several rows get the listing's. The tree answers at its root, at a file and at an asset's kuid - and a file branch or the root always brings up the listing's items, exports and Extract as individual CDPs... to a folder included, whether the pack holds one asset or fifty, since it is the file being asked about and not a row. A file's branch adds Remove after a line, the one item that is not an asset command. A kuid branch is one asset and gets that asset's items. The folders and files listed under a kuid are part of an asset rather than assets of their own, so their menu holds the one thing there is to ask of them: Unpack to... A folder brings the files it holds out as it stands, under its own name, straight in the folder you choose - no folder named for the asset above it, because the asset is not what was clicked on. One file asks for the name to write it to, starting at its own name, since a texture unpressed is a .tga and a mesh is a .im and what you type is what gets written. The asset's own settings are not one of those branches, because a pack keeps them as the container its files hang under rather than as one of them; unpacking a whole asset brings them out beside the files all the same, and unpacking part of one does not, since a texture has no settings of its own.
  • The columns sort as the text reads, so a build of 1.10 comes after 1.9, not before it.
  • The Author column, between Username and Kind, says who made the asset: the user id half of its kuid with a # in front, so <kuid:474195:10010> is #474195. Two assets by the same maker have the same author, whatever their kuids and versions say. It is a column like any other, so it is on screen, in the "Apply on" dropdown, in the copied rows and in a saved CSV. The numbers become the account names behind them - VVMM instead of #474195 - asked from Auran one id at a time in the background and remembered in local_assets.tdx next to the settings file so the same account is never asked about twice. That asking starts closed: the first run is asked whether it may happen at all, with Yes and No, and Resolve Author IDs to account names in Settings... is the tick that changes the answer afterwards. An id the server has no account for keeps its number. Four ids need no asking whatever the setting says, because they were never accounts: #0 is an asset with nobody written after it and shows as -, #-2 is Trainz's own word for a maker it does not know and shows as unknown, and any other negative id - #-1 on every built-in asset, and the overflowed id a broken kuid carries - shows as Auran. The format of that file, which is the one Trainz uses for the same table, is in tdx-format.md.
  • KUID, Username, Author, Kind, Class and Build are sized to their widest entry as a listing is filled in, and every column - those included - can then be dragged to a width of its own and keeps it: only the next listing sizes them again, so opening another pack or an author number turning into a name moves them, while a sort or a filter leaves them as they were. Era and Region take their width from you alone, and Description soaks up whatever width is left over. The grid has no Filename column. Export Asset details... and Copy Asset details add one when the rows they were given came from more than one pack, and leave it out when they all came from one, where it would say the same thing on every line - the decision is made by the rows, whichever menu asked for them, and the rows the File and Edit menus ask with are every opened pack. A saved file gets the column names above the rows; a copied run does not, so it lines up with the grid.
  • A tree down the left maps what is open: a fixed "All opened files" root, a branch per opened file, that file's asset kuids under it, and under each kuid the files and folders the asset carries, in the order the file lists them - an archive's own order, which is not always the pack's. A .cmpa says something about itself after its name: test.cmpa (v1, b3.3) is the version the archive was written with and the Trainz build that wrote it, read out of the archive's own header. A version 0 archive shows (v0) alone, because that header has no build field - what the assets inside it were built for is a different number, and one per asset - and a .cdp is left plain. A file's branch is added shut, with only its name showing: a pack of a thousand assets would otherwise spill every one of them, and every file inside them, across the window the moment it opened. One click on the branch asks to see them, and opening another file leaves the branches you had open exactly as they were. Only the root is open by itself - it holds the names of the files rather than the contents of one. Picking a file - or anything under it, a kuid, a folder, one file inside an asset - narrows the listing to that one pack; picking the root shows every opened file again. Picking an asset's kuid also selects its row. The tree follows the listing - open a file or Close all and it is rebuilt to match, and a pack you open after picking one is shown whole. And the listing answers back: double-click a row and the tree unfolds that asset's branch, folders and all, with the branch picked out.
  • A file's own branch has one item the rest do not, below a line at the end of its menu: Remove, which takes that pack off the listing - its rows out of the grid, its branch and everything under it out of the tree. The file on disk is left exactly where it is, so Open file... puts every row back; it is the listing that forgets the pack, not the disk. Removing the pack the listing was narrowed to shows the rest again, and a filter typed in the box above the listing stays as it was written.
  • "Filter files:" above the tree hides the branches its text does not name - a file, a kuid, a folder or one file inside an asset - and opens the branch down to whatever it does name, so a match is never shut away. Clearing it brings the branches back as they were opened before, and a file opened afterwards is filtered by the text already written.
  • The "Filter content:" box above the listing keeps only the rows whose text says what you type, and it acts on every keystroke - nothing to apply, nothing to re-run. An X inside the box empties it and brings the whole listing back. "Apply on" picks where the text is looked for: any one of the nine columns, or (the default) all of them at once. The filter is case-insensitive, and a newly opened file's rows fall under whatever filter is already written.
  • The status line says what was read and what could not be; the corner shows how many rows are on screen out of how many were read; the bar between them runs through whichever long job is going - a folder of packs being read in, a run of them being written out, or their files being unpacked - and counts the files it is working through, which for an unpacking is the files inside the assets and each asset's own settings, rather than the assets themselves.
  • Cancel, to the right of that bar, stops either job. It is only on show while something is running, and it stops after the file in hand rather than in the middle of one: what has already been read stays on the listing, what has already been written stays on the disk, and the status line ends by saying how far the run got ("Stopped: 11 of 60 files read."). One job at a time, since one bar and one button can only stand for one: start the other halfway through and the status line says which one is still going.
  • Packs are read in the background, so the window keeps drawing, and each pack's rows and tree branch appear as it is read: a folder of sixty packs fills in under your hands rather than leaving the window frozen until it is all done.
  • Settings... names an extracted asset by a pattern you type: text with $kuid, $username and $build written into it, so $kuid_$username gives kuid 303030 10091_Al_trava_1.cdp - everything else in the pattern is written as it stands, and .cdp is the extension added when a folder full of assets is named by the pattern; one file named by hand in the dialog keeps the ending it was given. The example name right under the box shows what the pattern makes as you type, and the two ticks (--underscores, --kuid2) sit under it. Under them, a group for the files an unpacking writes: Convert config.chump to config.txt picks the shape of an unpacked asset's own settings. Off, they come out as config.chump - the tags as the game stores them, which is what the game reads back; on, as config.txt, the text its own editing folders hold, which a person can read and edit.
  • The same box holds the one setting that reaches out of the program: Resolve Author IDs to account names. With it on, the Author column asks Auran whose account each author id is - one id at a time, in the background, a pause between requests - and the answers are kept in local_assets.tdx beside the settings file, so an account once looked up is never asked about again. The box says how many names that file holds, and Clear the cache empties it: the button only promises, and the file is deleted when OK is pressed, like everything else in the box. A first run is asked the same question up front, before any file is read: a box that says the program can connect to Auran's servers to turn numerical user ids into account names, that nothing but the user ids found in the opened files is sent and that it is sent anonymously, and that the ids are cached locally so a query is made only the first time an id is met.
  • A file that is already in the folder being extracted into is asked about when it is met, rather than settled by a setting beforehand. Already exists says "kuid 303030 10091.cdp already exists. Overwrite it?" with Yes and No, and No is the button already picked, so closing the box keeps the file that is there. When the run would replace several files the box adds Yes to All, No to All and Cancel: one plain Yes or No settles only the file it names and the next is asked again, and Cancel stops the run before anything at all is written. Nothing is asked about a name that is free. An unpacking asks the same boxes, and names each file by where it stands inside the folder chosen - "kuid 5699 3200131\b\block2.bmp already exists." - because two assets can each carry a file called black.tga and two boxes that only said black.tga would be two questions nobody could tell apart. One file unpacked to a name you typed is a plain Yes or No: the name is yours rather than one the program chose, so No keeps your file and writes nothing beside it.
  • The window comes back the size it was closed at, and maximized if it was closed maximized; un-maximizing it goes back to that remembered size rather than to the screen's.

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. A file that is already there is not among them - that answer is given at the moment it is needed, so nothing has to be remembered about it.

The author names that setting collects are kept next to them, in %APPDATA%\CDPExplorer\local_assets.tdx. That file is not JSON, because it is the record stream Trainz uses for the same table; what is in it, and how it is laid out, is written down in tdx-format.md. Clearing the cache in Settings... deletes the file.

And beside both, in %APPDATA%\CDPExplorer\recent.json, the packs the window was last asked to open - ten names at most, newest first, which is what File > Recent files reads. It is a file of its own rather than a key in settings.json because it changes every time a pack is opened while the settings are settled once and read a thousand times; it is written by the window only, so a terminal run leaves it alone. A list that cannot be read or written costs a line in the status bar and nothing else: the list is a convenience, never a reason a pack will not open.

Project layout

src/cdpexplorer/chump.py       the .cdp, .cdp2 and .chump reader and writer:
                               read_assets, write_asset, asset_contents
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/                         696 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 .cdp either way, which is the shape a pack is read back in.

Tests

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. 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.

Building

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.

File format specifications

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 to a name you type is written under either of the two that a pack goes by.

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.

Related software

  • Chump Editor - edit config.chump and config.txt files
  • TZarchiver - extract and create .tzarc archives
  • Kuid Lister - create lists of KUIDs from plain text
  • Kuid2Hash - convert KUIDs to binary and get the hash folder

Issues and feature requests

For any bugs, issues or feature requests, use the Issues tab in GitHub.

License

This project is licensed under the MIT License - see LICENSE.md for details.

Acknowledgments

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.

About

Utility aplication for browsing, searching and extracting Trainz Assets from CDP files.

Topics

Resources

Stars

11 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages