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.1.tar.gz (8.3 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.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cri_afs-0.1.1.tar.gz
  • Upload date:
  • Size: 8.3 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.1.tar.gz
Algorithm Hash digest
SHA256 c80f9bdcc0649bbe0602a315ca6866b429315cf776510a38691b81d1f8b6d5c2
MD5 e0a93a10d8c848595fff79ee16e9d121
BLAKE2b-256 a35c4ed5085ebbe8debb8ea7751367f95729816a2f056abdd1a02f30878c9057

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cri_afs-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.7 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 671c75cc82b03473059f06273aa18ddb5dc7ae1dcf9c21dc961cd1a0226d8e79
MD5 e9f9fa3a2fa68421c8e161d219761349
BLAKE2b-256 8d830d497e14053fd0c57abc8062e7a7cb4346ec39e29a6d9aaa92bd6d4feda7

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