dm2-tools (Python bindings)
Pythonic bindings for the Dungeon Master II: The Legend of Skullkeep asset
parsers, layered over the dm2-ffi C ABI via ctypes. Every function takes
bytes in and returns bytes / dict / str / bool out; failures raise
dm2_tools.Dm2Error.
Install
pip install ./bindings/python
This runs a hatchling build hook that invokes
cargo build -p dm2-ffi --release against the workspace and bundles the
resulting cdylib (libdm2_ffi.dylib / libdm2_ffi.so / dm2_ffi.dll) into
the wheel under dm2_tools/_lib/. A Rust toolchain must be installed and on
PATH to install this way. Python 3.11 or newer is required.
Tagged releases attach prebuilt wheels for x86-64 Linux (manylinux) and x86-64
Windows, which need no Rust toolchain — one wheel per platform covers every
supported Python, since the library is loaded through ctypes rather than
linked against a specific interpreter. macOS and other architectures build
from a checkout as above.
Development / override
For local iteration without reinstalling, the module also looks for the native library at:
dm2_tools/_lib/<lib>(bundled, present after a real install)- the path in the
DM2_FFI_LIBenvironment variable, if set <repo-root>/target/release/<lib>(the plaincargo buildoutput — used automatically when running the package straight out of a checkout)
Set DM2_FFI_LIB=/path/to/libdm2_ffi.so (or .dylib / .dll) to point at a
specific build.
Usage
import dm2_tools
dump = dm2_tools.save_to_json(save_bytes) # -> dict
dump["gameplay"]["champions"][0]["cur_hp"] = 999
edited = dm2_tools.save_from_json(dump) # -> bytes
JSON-returning functions parse the C ABI's UTF-8 JSON payload with
json.loads and return a plain dict; JSON-consuming functions accept a
plain dict and serialize it with json.dumps before calling in.
API
| Function | Signature | Notes |
|---|---|---|
version() |
() -> str |
Native library version (matches this package's version). |
save_to_json(data) |
bytes -> dict |
Self-contained lossless savegame dump. |
save_from_json(dump) |
dict -> bytes |
Rebuild savegame bytes from a save_to_json dump. |
save_info_json(data) |
bytes -> dict |
Lossy, human-readable gameplay-only savegame view. |
dungeon_to_json(data) |
bytes -> dict |
Self-contained lossless dungeon.dat dump. |
dungeon_from_json(dump) |
dict -> bytes |
Rebuild dungeon.dat bytes from a dungeon_to_json dump. |
dungeon_skproject_json(data) |
bytes -> dict |
Lossy skproject-compatible dungeon.dat dump. |
graphics_header_json(data) |
bytes -> dict |
Small header summary of a graphics.dat (format version, byte order, entry count). |
graphics_decode_png(data, cls1, cls2, cls4) |
(bytes, int, int, int) -> bytes |
Decode the image at class tuple (cls1, cls2, 0x01, cls4) to PNG bytes. |
music_detect(data) |
bytes -> str |
Sniff a standalone music file's container format. |
music_hmp_to_smf(data) |
bytes -> bytes |
Convert a DOS HMI/HMP stream to a Standard MIDI File. |
music_render_mod_wav(data) |
bytes -> bytes |
Render an Amiga ProTracker module to a stereo WAV. |
music_snd_to_wav(data) |
bytes -> bytes |
Decode a Mac 'snd ' resource payload to a mono WAV. |
ftl_info_json(data) |
bytes -> dict |
Small summary of an FTL 68k module container. |
ftl_roundtrip_ok(data) |
bytes -> bool |
True if the FTL module re-emits byte-exact. |
resfork_list(data) |
bytes -> list[dict] |
List a Mac resource fork's resources (type_code, id, name, payload_len). |
resfork_extract(data, type_code, id) |
(bytes, bytes|str, int) -> bytes |
Extract one resource's payload by (type_code, id). type_code may be 4 raw bytes or a 4-character str (encoded as Mac Roman). |
All exceptions raised by the above are dm2_tools.Dm2Error.
Testing
python -m pytest -q
Tests that need workspace fixtures look for them at <repo-root>/fixtures/
(override with DM2_FIXTURES_DIR); anything whose fixture isn't present
skips cleanly rather than failing.
Scope
Out of scope for this package, intentionally deferred:
- Publishing to PyPI.
- Prebuilt / multi-platform wheels (CI-built manylinux, macOS universal2, Windows, …). Installing always compiles the cdylib locally via Cargo.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dm2_tools-0.2.1-py3-none-win_amd64.whl.
File metadata
- Download URL: dm2_tools-0.2.1-py3-none-win_amd64.whl
- Upload date:
- Size: 3.4 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3245ebf53eb74f54f521761d324b86605e09db3988fcfcfd1d3188e501e0245
|
|
| MD5 |
c82b3681184b465cc96e632d43ebf6c4
|
|
| BLAKE2b-256 |
9086cf8dd8603e89ae1bf6737b123522a8a43a40cd35224261fe5227b8c3b1b6
|
File details
Details for the file dm2_tools-0.2.1-py3-none-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: dm2_tools-0.2.1-py3-none-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 849.1 kB
- Tags: Python 3, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc3f34e3741f8735c6876fffc540cc94cb55507436e5395675c7cc2b91b44d19
|
|
| MD5 |
66129457737b8cba473bd540dd6d570c
|
|
| BLAKE2b-256 |
c35874753b30526ce39ef91f94601dcf7d86bbff0d7c808dda5e8af868dc2048
|