Box cover of the game
Grachten Racer

Community decomp of the Davilex canal racer from 2000, rebuilt in C++ byte for byte

Matched

0.516% of the game code

Functions
55 / 6,467
Bytes
3,625 / 702,093

How the rebuild works

The whole project on one page. You don't need to know how to program to follow it.

The goal: the same bytes

Davilex never released the source code of Grachten Racer. What is on the CD is GrachtenRacer.exe: the machine code the compiler made from that source in 2000, without the names and comments the programmers wrote.

We write that source code again, in C++, one function at a time. A function counts when our C++, compiled with the same compiler (Visual C++ 6.0 with Service Pack 4), gives exactly the same machine code as the original. Code that only does the same thing is not enough: the instructions have to be the same, in the same order.

Why so strict? Because then nobody has to judge whether a function is right. The comparison is a fact, and when every function matches, the rebuilt source is the game.

In the original exe

fld    dword ptr [esp + 4]
fcomp  dword ptr [0.0]
fnstsw ax
test   ah, 1
je     ...

What we write

if (p_volume < 0.0f) {
    m_volume = 0.0f;
}
The start of one function. The compiler turns those three lines of C++ into these five instructions, and the original has exactly the same five.

The loop

Every function goes through the same steps.

  1. Pick a function from the list of all functions, and claim it so nobody else works on the same one.
  2. Read the machine code of that function in the original exe.
  3. Write C++ that should give the same code.
  4. Compile and compare. A tool called reccmp puts our instructions next to the original's and marks every difference. Change the C++ and compare again, until nothing differs.
  5. Open a pull request on GitHub. A maintainer reads the change, and our own server builds the whole game and checks that no other function got worse.
  6. Merged. The build of the main branch reports to this site, and the progress and the scoreboard update.

One function, two tries

The game has a silent sound system it falls back to when the real one fails. Its SetVolume keeps the volume between 0 and 1. It is 64 bytes, one of the small ones.

Try 1

if (p_volume > 1.0f) {
    p_volume = 1.0f;
}
if (p_volume < 0.0f) {
    p_volume = 0.0f;
}
m_volume = p_volume;

Effective All the instructions are there, but the test for 1 comes before the test for 0. The game would behave the same, but the bytes are not.

Try 2

if (p_volume < 0.0f) {
    m_volume = 0.0f;
}
else if (p_volume > 1.0f) {
    m_volume = 1.0f;
}
else {
    m_volume = p_volume;
}

Matched Test 0 first, and stop after each case. Now every instruction is the same as in the original.

The full walk through, with the comparison output, is in the worked example.

What is hard

Many ways of writing the same thing give different machine code, and only one of them is what the programmers wrote in 2000. Finding it means learning the habits of this compiler. Some we found so far:

  • Writing 4.0f in the code, or giving it a name first, gives two different instructions.
  • Setting up an object's fields in a list before the constructor body, or inside it, changes the order in which they are stored.
  • Reading a field directly, or through a small helper function, changes how the value is passed on.

We keep these in the matching notes, so the next person finds them faster.

The exe also does not contain names. The class names survived (the compiler kept them for its own use), but almost every function, field and variable name is our guess, and the source marks it as one.

Who does the work

People, each with their own copy of the game. Anyone can join: sign in with GitHub, claim a function, and send a pull request.

Some people work with an AI assistant. That is allowed, under the same rules: only an exact match counts, the person runs the comparison and opens the pull request, says that an assistant helped, and answers the review questions. AGENTS.md tells the assistant how this project works.

The numbers

Matched
The function gives exactly the original's instructions
Effective
Same behaviour, but registers or order still differ
Progress
Counted in bytes of game code, so a big function weighs more than a small one
Not counted
1,613 functions of the C runtime and MFC that Microsoft wrote
Game code
6,467 functions · 702,093 bytes

Points: a function is worth its size in bytes, and an effective match half of it. The scoreboard has the details.

What this is, and is not

A fan project to preserve and understand the game. It is not affiliated with Davilex. The repository holds only the C++ we wrote and our tools: no game files, no exe, no music or graphics. To build or play anything, you need your own copy of the game.

Want to help?