Tools for modifying the script, executable, and assets (planned) of ToHeart PSE (2003)
This project has been completely overhauled thanks to the VNLocalization project. Previous work relying on the the 97 fantl project tools has been moved to the "legacy-tooling" branch.
Progress: Soon!
The ToHeart PSE script is stored as a series of .DAT files wrapped up in scn.pak. The extract and pack utilities from the 97 fantl project are used to access the individual .DAT files. Each .pak file has eight bytes to spell out "LEAFPACK" followed by a 233 byte rotating key.
Each DAT file stores control commands and text data as one long stream, with all displayed text data stored as CP932 encoded full width (zenkaku) with the bytes flipped. For example, A (full width A) with the hex code 0x8260 is stored as 0x6082.
The remake script is stored in Binary/Text/text.ttb. It is full of a bunch of control characters at the beginning (presumably similar to the ones in PSE, just seperated out to support multiple languages), followed by the entire Japanese script, the entire English script, and the entire Chinese script. There is a complete JSON mapping between languages now.
ToHeart.exe does not seem to serve much purpose other than to open psth.exe which contains the actual game logic, so currently that is the focus of modifications.
The game seems to have two seperate routines for text drawing. One of these is used by the menus/UI and a different one is used by the script files. Text for menus is stored directly in SJIS in the executable without byte flipping.
Through editing the text in the exe, it was discovered that the game contains an entire set of unused half width text characters and a corresponding text drawing routine. However, nowhere in the game (menus or scripts) is this used, as all menu latin text is full width and trying to use ASCII in the script files themselves will usually just cause the game to crash, as these are interpreted as control commands. To solve this issue, I developed a patch that adds instructions right before the text drawing functions to subtract 0x1F from any full width characters, which results in them being passed to the half width drawing function instead, as well as replacing all references to the full width text spacing with half width spacing. The latter is slightly bugged as this now breaks half width text drawing (which worked fine), as there are 49 references to this address and I do not know which ones are for the menus and which ones are for the scripts. This should be able to be fixed eventually. There is also an issue with the currently drawn line in the scripts having the bottom of the text cut off. It is fixed when the next line is drawn. Since the half width text was likely never tested in the scripts this is probably why this behavior occurs. It remains to be seen if this can be fixed, but the advantages in mapping full width to half width largely outweigh this small bug in my opinion, especially since much more text can fit on each page meaning there is a much lower chance of having to move lines to the following page. The script translation is playable without the modded exe, but it will be largely untested and may look off.
UI Assets are stored in sys.pak. They consist of LFB formatted images, which are LZSS compressed bitmaps. Custom tooling has been created to extract and repack these files. Some of these images have text that needs to be translated, while others could have the option to be replaced by PS1 versions (which are slightly different)
The soundtrack is stored in bgmfile.pak in OGG format. While there is no real need for it to be replaced (it is virtually the same as the original 1997 OST), a future enhancement would be the option to use the sequenced PS1 OST or even the GBC demake OST The majority of the songs are split into A and B tracks, with A being the intro that only plays once and B being the main bulk of the song that repeats.