Skip to main content

Compress and decompress Racjin game archives (CFC.DIG / CDDATA.DIG)

Project description

racjin

Python implementation of the Racjin compression algorithm used in PS2/PSP/Wii game archives.

Handles CFC.DIG and CDDATA.DIG archive files found in games by Racjin and other Japanese studios.

If this helped you, consider buying me a coffee

Supported Games

  • Fullmetal Alchemist and the Broken Angel (PS2)
  • Fullmetal Alchemist 2: Curse of the Crimson Elixir (PS2)
  • Fullmetal Alchemist 3: Kami o Tsugu Shoujo (PS2)
  • Naruto: Uzumaki Chronicles 1 & 2 (PS2)
  • Bleach: Soul Carnival 2 (PSP)
  • Naruto Shippuden: Legends: Akatsuki Rising (PSP)
  • Naruto Shippuden: Ultimate Ninja Impact (PSP)
  • Other titles using the same archive format

Installation

pip install .

Or for development:

pip install -e .

CLI Usage

Extract an entire archive

# Auto-detects format and endianness
racjin extract CDDATA.DIG output/

# Specify format explicitly
racjin extract CFC.DIG output/ --format cfc

# For Wii/GameCube (big-endian)
racjin extract CDDATA.DIG output/ --big-endian

Compress / decompress individual files

# Decompress (requires known decompressed size)
racjin decompress compressed.bin decompressed.bin --size 577152

# Compress
racjin compress input.bin compressed.bin

Python API

from racjin import compress, decompress

# Decompress
with open("compressed.bin", "rb") as f:
    compressed_data = f.read()

decompressed = decompress(compressed_data, expected_size)

# Compress
with open("input.bin", "rb") as f:
    original_data = f.read()

compressed = compress(original_data)

# Round-trip
assert decompress(compress(data), len(data)) == data

Algorithm

The Racjin compression uses 9-bit tokens packed into a bitstream:

  • Bit 8 = 1: Literal byte (lower 8 bits stored directly)
  • Bit 8 = 0: Back-reference using a context-sensitive sliding window
    • Bits 3-7: 5-bit frequency index
    • Bits 0-2: 3-bit length (actual length = value + 1, max 8 bytes)
    • Window is a 8192-entry table indexed by (freq_index + last_byte * 32)

Tokens are folded using a rotating bit shift (0-7), packing 8 tokens (72 bits) into 9 bytes.

Archive Formats

Three structure variants are supported:

Format Field Layout Notes
cfc offset, comp_size, section_count|flags, decomp_size Most common (post-2005)
cddata offset, decomp_size, section_count, comp_size All sizes in sectors (2004-era)
cddata-old offset, size, section_count No compression (pre-2004)

All offsets are in 2048-byte disc sectors.

Credits

Algorithm reverse-engineered by Raw-man (C++ implementation). This is a Python port.

License

GPL-3.0 (same as the reference implementation)

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

racjin-1.0.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

racjin-1.0.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file racjin-1.0.0.tar.gz.

File metadata

  • Download URL: racjin-1.0.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for racjin-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2110a39cc8c7fb729986c8dde649e6d585efbe8ef6015a53d4903af878645219
MD5 9351a1e60942f21162f1e15fec6e276a
BLAKE2b-256 c626f8a8b675611d60483cc13bd224ddeb0ea70eb7e480d1cc9268418d2f7164

See more details on using hashes here.

File details

Details for the file racjin-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: racjin-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for racjin-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 044bd098d3a3b58ab0980be26d7941f78e33269aecce389c6fabd7f8bbeed8ba
MD5 833fc2c81b75a944fa54fbaa36c12303
BLAKE2b-256 00b9051cff0df66b75480b5fec5a100b832e5fb913c85a9a9240ed5ad5428f88

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