Reverse engineering a PS2 game where every word is a picture

· 4 min read

Ultraman Fighting Evolution Rebirth is a PS2 fighting game that only came out in Japan. I wanted to play it in English, which meant finding out how the game stores its text. None of the formats were documented anywhere I could find, so I worked them out from the files themselves.

There is no text

The first finding changed the whole plan. The game has no text engine. Mission objectives, menu labels, move names and memory-card messages are all images: Japanese text drawn into textures ahead of time. The executable and the mission modules contain no text at all.

So translating the game doesn't mean editing strings. It means redrawing pictures and putting them back exactly where they came from.

The data files

Almost everything lives in one big file, FILE1.BIN. Inside it are 170 archives with a simple header: a count, then fixed 0x80-byte entries holding a name, an offset, the space allocated and the actual size. Around them sit loose compressed files and some uncompressed textures, such as the boot warning screen. The other big files hold movies, audio and camera motions.

The compressed files start with DFS\x01, then the uncompressed size and the compressed size. One detail to watch: the compressed size includes the 12-byte header itself.

The compression is classic LZSS

The data after the header is LZSS, in the style of Haruhiko Okumura's well-known implementation: a 4,096-byte ring buffer, matches of up to 18 bytes, and a flag byte in front of every eight items. A flag bit of 1 means a literal byte, 0 means a back-reference, read from the lowest bit up. Each reference is two bytes, with the position split across both:

function decompress(src, size) {
  const ring = new Uint8Array(4096);
  let r = 4078;
  const out = [];
  let i = 0;
  while (out.length < size) {
    const flags = src[i++];
    for (let bit = 0; bit < 8 && out.length < size; bit++) {
      if (flags & (1 << bit)) {
        const byte = src[i++];
        out.push(byte);
        ring[r] = byte;
        r = (r + 1) & 4095;
      } else {
        const b1 = src[i++];
        const b2 = src[i++];
        const pos = b1 | ((b2 & 0xf0) << 4);
        const len = (b2 & 0x0f) + 3;
        for (let k = 0; k < len; k++) {
          const byte = ring[(pos + k) & 4095];
          out.push(byte);
          ring[r] = byte;
          r = (r + 1) & 4095;
        }
      }
    }
  }
  return Uint8Array.from(out);
}

The textures

Textures start with POM\0. The header stores the height before the width, which looks backwards until you notice it. A palette count of 16 means 4 bits per pixel, 256 means 8. The palette is RGBA with PS2-style alpha, where 0x80 means fully opaque, and 256-colour palettes are stored in the PS2's swizzled order, so they have to be unshuffled before the colours make sense. The pixels themselves are plain and linear.

There's even a little archaeology in there: the gaps in the headers contain leftover bytes from memory, apparently written by the developers' own conversion tool.

Making the edits fit

The hardest constraint is space. The archives sit back to back in FILE1.BIN, and a file table inside the executable records where each one starts and how much room it has. Nothing can grow past its slot without moving everything after it.

The way out was compression. I wrote an LZSS encoder with optimal parsing, which looks at every way of splitting the data into literals and references and picks the shortest. It comes out 1 to 3 percent smaller than the original compressor, enough that edited textures fit back into their original slots. Patching in place keeps FILE1.BIN the same size, so the disc image doesn't need rebuilding.

Where it stands

The English text didn't come from me: Toku555 had already made an English texture pack for the PCSX2 emulator, which works by swapping textures as the game runs. To get a version that doesn't need that emulator feature, I mapped 61 of those translated textures onto the game's own files and patched them in, leaving the original disc image untouched. The patched image checks out structurally; playing it through is the next step.

What I took from this: when a format isn't documented, write down every field you confirm, and every assumption you haven't. Details like the swapped width and height, or a size that counts its own header, are exactly the ones that are easy to get wrong.

  • #reverse-engineering
  • #ps2
  • #compression
  • #side-project

Written by Ryan Yovanda