Matching decompilation · PlayStation 2

Legaia 2: Duel Saga decompilation

PAL · SLES-50891An ongoing effort to rebuild Legaia 2: Duel Saga as readable C that compiles to the original game's exact bytes.

  • 20.19% of the code
  • 4,385 functions matched
  • executable rebuilds byte-identical
Lang, the main character of Legaia 2: Duel Saga

Progress

How much of the game is decompiled, and every unit. A function counts only when its source compiles to the original bytes. That source is C, apart from the VU0 routines (file-scope assembly in src/vu0_asm.c and src/vu0_asm2.c) and single hardware instructions inline in C. Numbers come from the project's report, generated 2026-11-16.

  • CODE20.19%
  • FUNCTIONS70.1%
  • FUZZY20.35%
  • DATA0.11%
  • UNITS142 / 154
20.19%
of the game's code decompiled
408,304 of 2,022,208 bytes
4,385 / 6,255
functions matched (70.1%)
20.35%
fuzzy match (partial matches count too)
near-miss drafts score by how many instructions already agree
0.11%
of the data decompiled (1,769,920 bytes)
2,000 done1,767,920 to do

Categories 2

Game code (attributed to a .cpp file)16.64%
1,357 of 2,042 functions, 113,872 of 684,140 bytes
Other code (SDK, libraries, unattributed)22.00%
3,028 of 4,213 functions, 294,432 of 1,338,068 bytes

Recent commits

  • 4e9181dAI.md: session 32 notes2026-11-16
  • 95cca53Match sceSifResetIop (0x2ed9a0) and 0x2cb268, reach 20.19%2026-11-16
  • 04c6237Match sceSifInitCmd, sceSifInitRpc, 188b88, 2cb108, 29ff70, reach 20.16%2026-11-16
  • 231c794AI.md: session 31c notes and open near misses2026-11-15
  • bd17c62Match rsound 0x10c168 and 0x10c690, reach 20.08%2026-11-15
  • fae32c4Match sound event handler 0x2d3190, reach 20.05%2026-11-15

How the matches were made

Matched functions by origin. Every one compiles to the original bytes; all are C except the libvu0 routines, which are assembly.

  • 2,471 hand-written C
  • 1,090 generated from instruction patterns
  • 825 Ghidra output that already matches

Units

Each rectangle is one unit (a source file of the original game, or a block of code between known files). Its area is the unit's code size; the colour is how much of it is matched. Hover for details, click or press Enter for the full card.

0% low higher matched part of a unit / 100%
Show as a table
UnitFunctionsMatched bytesMatched

Milestones

  1. Identify the compiler doneThe game's code was built with ee-gcc 2.9-ee-991111-01, -O2 -G8. 4,385 functions now compile byte-identical with it.
  2. Rebuild the executable doneThe whole .text is split per source file and rebuilt; the result matches the original byte for byte.
  3. Match functions in C in progressEach function is rewritten until it compiles to the same bytes, then switched over to C. Right now 20.19% of the code and 70.1% of the functions are done.

Format tools

Besides the code, the repository contains Python tools that read the game's data from your own disc image. None of the game's files are included.

ToolWhat it does
fs_tool.pyList and extract the game's archive straight from the ISO
lzss.pyDecompress .lzs files and archives
pac_tool.pySplit .pac map packages into chunks
tex_tool.pyConvert texture sets to PNG
tmd_tool.pyConvert .tmd models to Wavefront OBJ
adpcm.py, sq2mid.pyAudio streams to WAV; music sequences to MIDI
battle_script.pyBattle script opcode reference and viewer
mov_tool.py, efp_tool.py, msg_tool.pyAnimation clips, effect packs, message containers
pss_demux.pySplit the movie file into video and audio

Format notes are in the docstring at the top of each tool in tools/.

Setup

You need Python 3, Clang, LLD (ld.lld), the game's compiler ee-gcc 2.9-ee-991111-01 (from decomp.me's compiler archive) and your own Legaia 2: Duel Saga (PAL) disc image.

Linux

git clone https://github.com/WeAreTommyBruh/Legaia2-Decomp.git
mkdir -p ~/tools/ee-gcc2.9-991111-01
curl -L https://github.com/decompme/compilers/releases/download/compilers/ee-gcc2.9-991111-01.tar.xz \
  | tar xJ -C ~/tools/ee-gcc2.9-991111-01

The compiler is a 32-bit Linux program. On a 64-bit system install the 32-bit runtime libraries first (Debian/Ubuntu shown):

sudo dpkg --add-architecture i386
sudo apt update
sudo apt install libc6:i386

Then put the disc image in the repository root as SLES_50891.ISO and rebuild the executable:

python3 tools/asm_build.py all     # rebuild + byte-identical check; the last line must say MATCH
python3 tools/report.py            # report/report.json, the numbers on this page

Windows

Install WSL (wsl --install) with Ubuntu or Debian, then follow the Linux steps.

About

This project is written almost entirely by AI. I check nearly everything myself to make sure there is nothing wrong.

Reverse engineering and matching decompilation take a long time: expect many months, possibly a year. There is no rush, so the project will be finished when it is finished.

The project was made by WeAreTommyBruh.