Skip to main content

Reader/writer for the CRI AFS archive format used in PS2/Dreamcast/GameCube games

Project description

cri-afs

Reader/writer for the CRI AFS archive format used in PS2 / Dreamcast / GameCube games.

If this helped you, consider buying me a coffee

CRI AFS is the bulk archive format CRI Middleware shipped with their authoring tools. It's a flat container of fixed-offset sub-files (typically 0x800-aligned to CD sectors), with an optional trailing filename TOC. Examples of games shipping .AFS archives:

  • Magna Carta: Tears of Blood (SHIP.AFS, MUSIC.AFS, LINEAR.AFS, FILE.AFS)
  • Burnout, Burnout 2/3
  • Various Sega and CRI-licensed PS2/Dreamcast titles

Round-trips byte-identically when given the original TOC metadata.

Install

pip install cri-afs

Usage

Command line

# Inspect an AFS file (entry table, type histogram, sample names)
cri-afs info SHIP.AFS

# Extract every entry to a directory
cri-afs extract SHIP.AFS --out ship_extracted/

# Pack a directory back into an AFS
cri-afs pack ship_extracted/ -o SHIP.AFS

Python API

from cri_afs import Afs, write_afs

# Read
afs = Afs.open("SHIP.AFS")
print(f"{len(afs.entries)} entries")
names = afs.read_filename_toc()

with open("SHIP.AFS", "rb") as fh:
    blob = afs.read_entry(0, fh)   # raw bytes of sub-file 0

# Write
entries = [(name, blob) for name, blob in zip(names, payloads)]
write_afs("OUT.AFS", entries, toc_metadata=afs.read_toc_metadata())

Format

0x00  4   magic       "AFS\0"
0x04  4   entry_count
0x08  N*8 entries     (offset: u32, size: u32) per entry
...   8   toc_pointer (toc_offset: u32, toc_size: u32)
                      — pad to 0x800 alignment —
              per entry: blob, padded up to 0x800
              trailing filename TOC: 32-byte filename + 16-byte metadata per entry

The trailing filename TOC is optional in the spec but present in practice for every CRI-shipped AFS. read_toc_metadata() returns the per-entry 16-byte metadata (timestamp/size fields the engine ignores at runtime but expects to be present); pass it to write_afs(toc_metadata=...) for a byte-identical round-trip.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cri_afs-0.1.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cri_afs-0.1.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file cri_afs-0.1.0.tar.gz.

File metadata

  • Download URL: cri_afs-0.1.0.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for cri_afs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 83d4b21f0050cf403425f04d92354c6a857fbfd553a931329fc16a4fe1b87816
MD5 e66bbaa7743e92df79ee49ef9b41e68f
BLAKE2b-256 9e2cf1fd8ace7ab642ad1d0ec97d7825e700172d19e79a9ef2d92fd054d16720

See more details on using hashes here.

File details

Details for the file cri_afs-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cri_afs-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for cri_afs-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bfc582b604550fed1ace0abad1f95e5504b575b643461450ac37acb0d9d7fd3d
MD5 3cb79dc6a63ead2f6fea0552df768186
BLAKE2b-256 5725a47c8791cb8b8c17d10963b588e4e2edb25974ea9709a77df728d812af98

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page