th08: byte-perfect decompilation of 東方永夜抄
th08 is a community Touhou decomp project that pries 《東方永夜抄 ~ Imperishable Night》 1.00d back into source, one piece at a time, straight from the binary. I didn’t write it. I forked it to build it myself and read along. The project labels itself highly WIP and it’s still very early, so I treat it as living teaching material and don’t expect it to be complete right now. The repo is at https://github.com/dwgx/th08.
A matching decomp is a different thing from “decompiling something that runs close enough.” The goal is that the recompiled binary matches the original byte for byte. You don’t just write functionally equivalent C++; you have to make the compiler lay out local variables and emit instructions the same way the original did. That layer is exactly what you’re digging into.
So the build environment can’t use a modern toolchain. You have to reconstruct the setup from back then: Visual Studio 2002 plus DirectX 8.0, all old artifacts pulled from the Web Archive. byte-perfect leaves no choice here, you can only use the same compiler the original author used. The build script is written in Python; run it to generate build.ninja, then hand that off to ninja. On Linux/mac you run this old toolchain under wine; on macOS CrossOver is reportedly more stable and sidesteps CL.EXE’s heap problems.
To build it yourself you first need the original th08.exe 1.00d. The project verifies the version with SHA256, and if the version is wrong the whole comparison falls apart. Drop the exe into resources/, run python scripts/create_devenv.py to line up the compiler and libraries, then python3 ./scripts/build.py to produce the recompiled binary.
The core of it is the comparison, using isledecomp’s reccmp. First reccmp-project detect identifies the original and the recompiled build, then reccmp-reccmp --target th08 --html report.html produces an accuracy report that tells you directly which functions match and which are still off. Every function you match moves the progress forward one notch.
One more detail: to control local variable layout on old MSVC7, @EstexNT ported over a var_order pragma. A small tool built just to align compiler behavior like this is the best illustration of how deep a matching decomp actually digs.