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

thprac: forking the Touhou shmup practice tool to study injection

// created

thprac is a practice tool for Touhou shmups. It replaces the game’s own bare-bones practice menu with a new UI that lets you pick spell cards, pick stages, and tweak parameters. I didn’t write it. Ack built it originally, and after he dropped it the touhouworldcup crowd took over maintenance. This repo is a fork; I keep it purely to study the injection off the source.

The interesting part is stuffing code into a closed-source game process. Touhou is a great RE specimen. ZUN wrote everything from th06 through th19, and the memory layout differs in every entry. thprac’s approach is to inject itself into the running game and swap out the original menu directly.

thprac’s new practice menu

There are several injection paths, and the design is pretty clean. Drop the exe into the game directory and it identifies which entry it is from the filename; if the game is already running, thprac.exe --attach finds the process, --attach <pid> targets a specific one, or you can just drag the game exe onto it. There are also switches like --without-vpatch and --without-oilp, because it patches vpatch and OpenInputLagPatch alongside itself. Half the work in any mature injection tool goes into coexisting with the other patches.

What’s actually worth reading is the per-game adaptation. Each entry gets its own set of hooks, since spell cards, bosses, and stage detection are all different. For DDC (th14) it fixes the infamous Marisa laser desync directly in memory; EoSD gets a pause menu that lets you quit and keep the replay; versus titles like PoFV and UDoALG get their own dedicated tool windows. The options you enable during practice are written into the replay and restored automatically on playback.

In-game, Backspace brings up the quick menu, F12 the advanced options, hotkeys are configurable in the launcher, and it works with Wine and Steam Deck. The project is C++, built with msbuild, and ships a loc_json step that compiles the localization json in. I’m not forking it to ship anything; I just wanted to see how someone folds three annoying problems, RE, injection, and per-game differentiated patching, into a single usable tool. Upstream is touhouworldcup/thprac.