[][discord] <- click here to join discord server.
This is a modified version of [th06](https://github.com/GensokyoClub/th06) by GensokyoClub.
## Modifications
This fork includes the following modifications:
- **Fixed frame rate bug** - Fixed the bug where the game would run at incorrect speed
- **Built-in hitbox indicator** - Press Shift to show a rotating hitbox indicator centered on the player
- **Infinite lives** - Player automatically gains a life on death
- **Chinese localization** - Full Chinese text support with GB2312 charset and SimHei font
- **Default windowed mode** - Game starts in windowed mode by default
### Chinese Localization Data
The Chinese localized DAT files (`th06c_*.DAT`) are from [thdog.moe](https://cn.thdog.moe/%E5%9B%BD%E9%99%85%E5%88%86%E6%B5%811/%E4%B8%9C%E6%96%B9Project/%E5%AE%98%E6%96%B9%E6%B8%B8%E6%88%8F/%E6%95%B4%E6%95%B0%E4%BD%9C/%5Bth06%5D%20%E4%B8%9C%E6%96%B9%E7%BA%A2%E9%AD%94%E4%B9%A1%20(%E6%B1%89%E5%8C%96%E7%89%88+%E6%97%A5%E6%96%87%E7%89%88)%201.02h.zip).
Original project description:
This project aims to perfectly reconstruct the source code of [Touhou Koumakyou ~ the Embodiment of Scarlet Devil 1.02h](https://en.touhouwiki.net/wiki/Embodiment_of_Scarlet_Devil) by Team Shanghai Alice.
## Installation
### Executable
This project requires the original `東方紅魔郷.exe` version 1.02h (SHA256 hashsum 9f76483c46256804792399296619c1274363c31cd8f1775fafb55106fb852245, you can check hashsum on windows with command `certutil -hashfile SHA256`.)
Copy `東方紅魔郷.exe` to `resources/game.exe`.
### Dependencies
The build system has the following package requirements:
- `python3` >= 3.4
- `msiextract` (On linux/macos only)
- `wine` (on linux/macos only, prefer CrossOver on macOS to avoid possible CL.EXE heap issues)
- `aria2c` (optional, allows for torrent downloads, will automatically install on Windows if selected.)
The rest of the build system is constructed out of Visual Studio 2002 and DirectX 8.0 from the Web Archive.
#### Configure devenv
This will download and install compiler, libraries, and other tools.
If you are on windows, and for some reason want to download dependencies manually,
run this command to get the list of files to download:
```
python scripts/create_devenv.py scripts/dls scripts/prefix --no-download
```
But if you want everything to be downloaded automatically, run it like this instead:
```
python scripts/create_devenv.py scripts/dls scripts/prefix
```
And if you want to use torrent to download those dependencies, use this:
```
python scripts/create_devenv.py scripts/dls scripts/prefix --torrent
```
On linux and mac, run the following script:
```
# NOTE: On macOS if you use CrossOver.
# export WINE=/wine
./scripts/create_th06_prefix
```
#### Building
Run the following script:
```
python3 ./scripts/build.py
```
This will automatically generate a ninja build script `build.ninja`, and run
ninja on it.
#### Creating Release Package
To create a distributable release package:
```
python3 ./scripts/release.py
```
This will:
1. Clean unnecessary files from the build directory (object files, debug symbols, etc.)
2. Create a zip archive containing only the essential game files
Options:
- `--no-clean` - Skip cleaning build directory
- `--no-zip` - Skip creating zip archive
- `-o PATH` - Specify output path for zip
- `-n NAME` - Specify release name (default: th06e-release)
## Contributing
### Reverse Engineering
You can find an XML export of our Ghidra RE in the companion repository
[th06-re], in the `xml` branch. This repo is updated nightly through
[`scripts/export_ghidra_database.py`], and its history matches the checkin
history from our team's Ghidra Server.
If you wish to help us in our Reverse Engineering effort, please contact
@roblabla on discord so we can give you an account on the Ghidra Server.
### Reimplementation
The easiest way to work on the reimplementation is through the use of
[`objdiff`](https://github.com/encounter/objdiff). Here's how to get started:
1. First, follow the instruction above to get a devenv setup.
2. Copy the original `東方紅魔郷.exe` file (version 1.02h) to the
`resources/` folder, and rename it into `game.exe`. This will be used as the source to compare the
reimplementations against.
3. Download the latest version of objdiff.
4. Run `python3 scripts/export_ghidra_objs.py --import-csv`. This will extract
from `resources/game.exe` the object files that objdiff can compare against.
5. Finally, run objdiff and open the th06 project.
#### Choosing a function to decompile
The easiest is to look at the `config/stubbed.csv` files. Those are all
functions that are automatically stubbed out. You should pick one of them, open
the associated object file in objdiff, and click on the function of interest.
Then, open the correct `cpp` file, copy/paste the declaration, and start
hacking! It may be useful to take the ghidra decompiler output as a base. You
can find this output in the [th06-re] repository.
# Credits
We would like to extend our thanks to the following individuals for their
invaluable contributions:
- @EstexNT for porting the [`var_order` pragma](scripts/pragma_var_order.cpp) to
MSVC7.