dwgx@blog:~$dwgx
> cd ../posts

Modding Embodiment of Scarlet Devil: th06-plus with a hitbox indicator and infinite lives

// created

th06-plus is a mod of Touhou 06: Embodiment of Scarlet Devil, forked from GensokyoClub’s th06. The original project reverse engineered EoSD 1.02h line by line back into compilable source, and on top of that foundation I added a few features I wanted for myself. It’s a fork of someone else’s work, so let me say that up front.

The reverse engineering approach is to use the original exe as a reference, decompile it with Ghidra, then go through it function by function with objdiff until the recompiled machine code lines up with the original. It’s pretty archaeological, which is exactly why I keep getting hooked on binary reconstruction.

With the source in hand, adding stuff is easy. I fixed a framerate bug and added a hitbox indicator: hold Shift and a rotating marker is drawn at the player’s center, handy for threading through bullets. Infinite lives auto-refills when you die, purely for watching the danmaku. Localization goes through GB2312 with a bold font; the Chinese th06c_*.DAT files come from a fan patch by thdog.moe, not translated by me. It boots windowed by default.

The toolchain means going back to 2002: the compiler VS2002 and the graphics library DirectX 8.0 are both pulled from the Web Archive. On Linux/macOS it runs under wine; on macOS CrossOver is the better bet since it sidesteps CL.EXE’s heap issues.

Getting it running isn’t complicated. Copy the original exe to resources/game.exe as the reference, then

python scripts/create_devenv.py scripts/dls scripts/prefix
python3 ./scripts/build.py

create_devenv.py fetches the compiler and libraries automatically, torrent included, and build.py generates a ninja script and compiles. For a distributable package there’s release.py.

If you want to join the reverse engineering effort, head to objdiff and pick a function to chew on; everything in config/stubbed.csv is stubbed out awaiting implementation. This time around I didn’t go deep into rewriting functions, mostly setting up the environment and adding features, but walking through this whole decomp flow will teach you how a binary gets taken apart and put back together.