Skip to content

Repository files navigation

Ratchet: Deadlocked (PS2) Decompilation

Website Discord Progress report Code Functions

A work-in-progress matching decompilation of Ratchet: Deadlocked (Ratchet: Gladiator in PAL regions; Insomniac Games, 2005) for the PlayStation 2, part of the OpenRAC initiative.

The objective is to produce C/C++ source code that, when compiled with the original toolchain, generates a byte-identical copy of the retail programs: the main program, the front end and the 47 level programs, each read straight from the disc. The primary target is the NTSC-U disc (SCUS_974.65), which the existing C was matched against; the PAL disc, Ratchet: Gladiator (SCES_532.85), is the second version, built and counted the same way, and the same C counts there wherever it builds to the PAL bytes too. Matched code is then refactored toward readable, idiomatic C++ with accurate types and naming, using matching builds as continuous regression tests.

Note

This repository contains no game assets, retail executables, or disassembly. To build, you must provide your own legally obtained copy of the game. Please review LEGAL.md before contributing.


Progress

Progress is published on ByteMatch for both versions (US by default) and on openrac.dev.

Version Region Target ID Code Matched Functions Matched
v1.00 (primary) NTSC-U SCUS_974.65
PAL Europe (Ratchet: Gladiator) SCES_532.85

A function counts as matched on a version when its C, built with its file's own flags, gives that disc's bytes of the function with only the fields its object relocates masked (tools/match_map.py, config/<version>/map.tsv); the fuzzy figure adds what the near misses in nonmatching/ get right. There is no C in the programs' build yet: every program builds byte-identical from its assembly (docs/levels.md), and tools/audit_matches.py checks every function of src/ against the US bytes.

Category US PAL Contents
Main program The main image: engine core, network code, resident menus, and frontbin's own code
Engine core core.text, resident in every level (libgcc and libm apart)
libgcc GCC's runtime, rebuilt from GCC's source (src/libgcc/)
libm newlib's math library, rebuilt from its source (src/libm/)
Network net.text, the same in every program
Resident menus The main image's resident .text (the menus); frontbin links it a second time and is counted with it
frontbin The functions only frontbin has
Level code Every level program's code, each distinct function once
Shared level code In two or more distinct level programs
Level-specific code In one level program only
The counts

NTSC-U (SCUS_974.65)

Functions (exact) Code (exact) Fuzzy
Main program 3,857 of 8,989 321,880 of 2,193,276 bytes (14.68%) 14.96%
Engine core (core.text) 856 of 1,663 83,296 of 288,080 bytes (28.91%) 29.38%
libgcc 26 of 33 6,148 of 10,836 bytes (56.74%) 56.74%
Network (net.text) 792 of 2,441 39,868 of 465,620 bytes (8.56%) 9.22%
Resident menus (.text) 2,179 of 4,827 191,700 of 1,416,572 bytes (13.53%) 13.67%
frontbin's own code 4 of 25 868 of 12,168 bytes (7.13%) 7.13%
Shared level code 1,950 of 5,096 156,652 of 1,980,624 bytes (7.91%) 8.53%
Level-specific code 1,280 of 4,085 103,488 of 1,607,532 bytes (6.44%) 7.11%
Level 00: Multiplayer Menu 891 of 2,810 73,428 of 942,664 bytes (7.79%) 8.64%
Level 01: Dreadzone Station (and 21) 119 of 373 7,556 of 189,416 bytes (3.99%) 3.99%
Level 02: Catacrom Graveyard (and 22) 7 of 34 328 of 26,572 bytes (1.23%) 1.23%
Level 04: Sarathos Swamp (and 24) 4 of 19 224 of 11,708 bytes (1.91%) 1.91%
Level 05: Dark Cathedral (and 25) 24 of 102 1,076 of 59,824 bytes (1.80%) 1.96%
Level 06: Temple Of Shaar (and 26) 8 of 30 492 of 9,312 bytes (5.28%) 5.28%
Level 07: Valix Lighthouse (and 27) 6 of 46 588 of 28,304 bytes (2.08%) 2.08%
Level 08: Mining Facility (and 28) 10 of 48 1,332 of 24,400 bytes (5.46%) 5.46%
Level 10: Torval Ruins (and 30) 7 of 37 312 of 20,140 bytes (1.55%) 1.55%
Level 11: Tempus Station (and 31) 3 of 15 212 of 8,776 bytes (2.42%) 2.42%
Level 13: Maraxus Prison (and 33) 12 of 33 700 of 15,548 bytes (4.50%) 4.50%
Level 14: Ghost Station (and 34) 6 of 29 444 of 14,548 bytes (3.05%) 3.05%
Level 15: Control Level (and 35) 25 of 134 1,496 of 116,336 bytes (1.29%) 1.29%
Level 41: Battledome Tower (all 22 multiplayer maps) 158 of 375 15,300 of 139,984 bytes (10.93%) 12.79%
Total 7,087 of 18,170 582,020 of 5,781,432 bytes (10.07%) 10.57%

Each distinct function counts once: frontbin's copy of the menus is the main image's, and a level function counts once however many of the 47 levels have it. 321,880 bytes (5.57%) are in units with nothing left to decompile.

PAL (SCES_532.85)

Functions (exact) Code (exact) Fuzzy
Main program 4,132 of 8,952 413,964 of 2,202,184 bytes (18.80%) 19.07%
Engine core (core.text) 888 of 1,666 89,748 of 288,232 bytes (31.14%) 31.61%
libgcc 26 of 33 6,148 of 10,836 bytes (56.74%) 56.74%
Network (net.text) 791 of 2,441 39,848 of 465,620 bytes (8.56%) 9.22%
Resident menus (.text) 2,425 of 4,797 277,660 of 1,422,048 bytes (19.53%) 19.64%
frontbin's own code 2 of 15 560 of 15,448 bytes (3.63%) 3.63%
Shared level code 2,064 of 5,089 180,820 of 2,008,632 bytes (9.00%) 9.59%
Level-specific code 1,366 of 4,093 122,108 of 1,600,040 bytes (7.63%) 8.19%
Level 00: Multiplayer Menu 939 of 2,834 81,832 of 943,896 bytes (8.67%) 9.34%
Level 01: Dreadzone Station (and 21) 132 of 371 11,352 of 190,296 bytes (5.97%) 5.97%
Level 02: Catacrom Graveyard (and 22) 7 of 29 328 of 21,232 bytes (1.54%) 1.54%
Level 04: Sarathos Swamp (and 24) 5 of 19 600 of 11,868 bytes (5.06%) 5.06%
Level 05: Dark Cathedral (and 25) 27 of 102 2,064 of 60,096 bytes (3.43%) 3.59%
Level 06: Temple Of Shaar (and 26) 11 of 30 1,272 of 9,316 bytes (13.65%) 13.65%
Level 07: Valix Lighthouse (and 27) 6 of 44 588 of 27,640 bytes (2.13%) 2.13%
Level 08: Mining Facility (and 28) 12 of 48 1,636 of 24,900 bytes (6.57%) 6.57%
Level 10: Torval Ruins (and 30) 8 of 37 452 of 20,276 bytes (2.23%) 2.23%
Level 11: Tempus Station (and 31) 4 of 15 500 of 8,800 bytes (5.68%) 5.68%
Level 13: Maraxus Prison (and 33) 14 of 33 1,344 of 15,872 bytes (8.47%) 8.47%
Level 14: Ghost Station (and 34) 7 of 23 1,000 of 8,884 bytes (11.26%) 11.26%
Level 15: Control Level (and 35) 33 of 134 3,244 of 116,624 bytes (2.78%) 2.78%
Level 41: Battledome Tower (all 22 multiplayer maps) 161 of 374 15,896 of 140,340 bytes (11.33%) 13.18%
Total 7,562 of 18,134 716,892 of 5,810,856 bytes (12.34%) 12.80%

Each distinct function counts once: frontbin's copy of the menus is the main image's, and a level function counts once however many of the 47 levels have it. 413,964 bytes (7.12%) are in units with nothing left to decompile.

Levels

Each level carries its own program: its code, data and dispatch tables, loaded over the main image's menus when the level starts. Each disc has 47 of them but only 14 distinct programs: the 12 split-screen campaign levels are byte-identical copies of their single-player levels, and all 22 multiplayer maps run one program (level 41's). Their functions are counted once each: under Shared level code when two or more distinct programs have them, else in their level's own row; a function the resident menus have too is counted there (docs/levels.md).

Per level
Level Name Same program as US PAL
00 Multiplayer Menu
01 Dreadzone Station
02 Catacrom Graveyard
04 Sarathos Swamp
05 Dark Cathedral
06 Temple Of Shaar
07 Valix Lighthouse
08 Mining Facility
10 Torval Ruins
11 Tempus Station
13 Maraxus Prison
14 Ghost Station
15 Control Level
21 Dreadzone Station (split screen) 01 (level 01's) (level 01's)
22 Catacrom Graveyard (split screen) 02 (level 02's) (level 02's)
24 Sarathos Swamp (split screen) 04 (level 04's) (level 04's)
25 Dark Cathedral (split screen) 05 (level 05's) (level 05's)
26 Temple Of Shaar (split screen) 06 (level 06's) (level 06's)
27 Valix Lighthouse (split screen) 07 (level 07's) (level 07's)
28 Mining Facility (split screen) 08 (level 08's) (level 08's)
30 Torval Ruins (split screen) 10 (level 10's) (level 10's)
31 Tempus Station (split screen) 11 (level 11's) (level 11's)
33 Maraxus Prison (split screen) 13 (level 13's) (level 13's)
34 Ghost Station (split screen) 14 (level 14's) (level 14's)
35 Control Level (split screen) 15 (level 15's) (level 15's)
41 Battledome Tower
42 Catacrom Graveyard (multiplayer) 41 (level 41's) (level 41's)
44 Sarathos Swamp (multiplayer) 41 (level 41's) (level 41's)
45 Dark Cathedral (multiplayer) 41 (level 41's) (level 41's)
46 Temple Of Shaar (multiplayer) 41 (level 41's) (level 41's)
47 Valix Lighthouse (multiplayer) 41 (level 41's) (level 41's)
48 Mining Facility (multiplayer) 41 (level 41's) (level 41's)
50 Torval Ruins (multiplayer) 41 (level 41's) (level 41's)
51 Tempus Station (multiplayer) 41 (level 41's) (level 41's)
53 Maraxus Prison (multiplayer) 41 (level 41's) (level 41's)
54 Ghost Station (multiplayer) 41 (level 41's) (level 41's)
61 Battledome Tower (multiplayer, split screen) 41 (level 41's) (level 41's)
62 Catacrom Graveyard (multiplayer, split screen) 41 (level 41's) (level 41's)
64 Sarathos Swamp (multiplayer, split screen) 41 (level 41's) (level 41's)
65 Dark Cathedral (multiplayer, split screen) 41 (level 41's) (level 41's)
66 Temple Of Shaar (multiplayer, split screen) 41 (level 41's) (level 41's)
67 Valix Lighthouse (multiplayer, split screen) 41 (level 41's) (level 41's)
68 Mining Facility (multiplayer, split screen) 41 (level 41's) (level 41's)
70 Torval Ruins (multiplayer, split screen) 41 (level 41's) (level 41's)
71 Tempus Station (multiplayer, split screen) 41 (level 41's) (level 41's)
73 Maraxus Prison (multiplayer, split screen) 41 (level 41's) (level 41's)
74 Ghost Station (multiplayer, split screen) 41 (level 41's) (level 41's)

Quick Start

Prerequisites

  • Linux & macOS: Docker or Podman (uses the prebuilt Wine container via GitHub Container Registry), and Python 3.10+.
  • Windows: Git Bash, Python 3.10+, and community toolchain mirrors. The compilers run natively (no Wine or container needed). The venv's interpreter is venv/Scripts/python.exe: use it wherever these docs say venv/bin/python.

Setup & Build

  1. Clone the repository:

    git clone https://github.com/OpenRAC/rac-deadlocked-decomp.git
    cd rac-deadlocked-decomp
  2. Provide your original executable: Copy SCUS_974.65 from your disc image into baserom/:

    # Expected SHA-1: aa91b1c3b9b1a244320c47580b77342ef9856e95
    cp /path/to/SCUS_974.65 baserom/SCUS_974.65
  3. Generate the disassembly and fetch toolchains:

    bash tools/setup_asm.sh                 # unpack, split, splat -> asm/
    git clone https://github.com/AngheloAlf/SN-Systems-ProDG_for_PS2_3.01 toolchain/sn-prodg-3.01
    git clone https://github.com/AngheloAlf/sce_ps2_sdk_24 toolchain/sn-prodg-24
  4. Build and verify:

    # Windows (native):
    bash tools/build.sh
    
    # Linux & macOS (via container):
    bash tools/docker/run.sh bash tools/build.sh
    
    # Then compare every function with retail:
    venv/bin/python tools/audit_matches.py
    # and write the progress reports (needs the dumps, see below):
    python3 tools/match_map.py --write && python3 tools/progress.py --write

Both discs: the programs, their build and the count

Each disc's programs are read from your own baserom/SCUS_974.65.iso (or baserom/SCES_532.85.iso with --version pal; the SHA-1s are in config/<version>/programs.tsv and levels.tsv), built from their assembly, and counted (docs/levels.md):

python3 tools/levels.py dump                           # baserom/us/ (add --version pal for baserom/pal/)
python3 tools/build_levels.py --asm -P 16              # 49 targets, one MATCH each (ee-as/ee-ld; Linux, or the container)
JOBS=16 bash tools/docker/run.sh bash tools/build.sh   # then build_libgcc.sh, build_libm.sh
python3 tools/match_map.py --write                     # where src/ matches (and --version pal)
python3 tools/progress.py --write                      # progress/report.json and its table (and --version pal)
python3 tools/check_func.py func_L01_XXXXXXXX try.c    # one function against its US bytes (--version pal: PAL)

For detailed documentation:

  • docs/WORKFLOW.md – Setup in full, and the step-by-step function matching guide
  • docs/TOOLCHAIN.md – Compiler, flags, assembler passes, libraries and the container
  • docs/RESEARCH.md – How the retail executable is packed and taken apart
  • docs/levels.md – Both discs' programs, their build, how the functions are counted, and the old against the new totals
  • docs/OVERLAYS.md – The 47 US level overlays the existing C was matched against

Contributing

Contributions are warmly welcome! Whether you are interested in decompiling functions, researching engine quirks, or improving documentation:


Credits

This project builds upon years of dedicated reverse-engineering research and tooling by the community:

  • rac1-decomp – Repository layout, README, progress workflow and report generator, toolchain notes, the libgcc build recipe, and tools/ps2eeas_nops.py / tools/ps2eeas_dli.py (the nops and constant sequences of SN's assembler).
  • rac3-uya-decomp-pal – The PAL treatment this repository follows: reading the levels from the disc, the function inventory (rac1-decomp's rules), the catalogue and the report (tools/inventory.py, tools/level_catalogue.py, tools/progress.py are adapted from it).
  • rac3-uya-decomp by vetusmagnus – Up Your Arsenal, the closest engine relative. Compiler research (SN ee-gcc 2.95.3 v1.36) and the -fopt-stack, -G8 and global-declaration findings.
  • OpenRAC – Status of Deadlocked, sourcing policy, and the sibling decompilations of the engine family.
  • Lombyte by mateuszklysz – R&C1 NTSC decomp, checked for Deadlocked coverage (none).
  • Wrench by chaoticgd – PS2 Ratchet & Clank modding tools; its documentation of the packed image (docs/file_loading.md, "WAD Compression") and the executable's layout, and the level overlays it unpacks.
  • GCC and newlib – The library sources in src/libgcc/ and src/libm/ (see THIRD_PARTY_NOTICES.md).
  • Decompilation Tooling & Ecosystem:

License

  • Code written for this project is licensed under the GNU General Public License v3.0.
  • Reconstructed libraries and third-party components retain their original licenses (see THIRD_PARTY_NOTICES.md and LEGAL.md).
  • Ratchet: Deadlocked is a registered trademark of Sony Interactive Entertainment. This project is not affiliated with or endorsed by Sony or Insomniac Games.