-
Notifications
You must be signed in to change notification settings - Fork 5
Patching Explained
These notes explain how the patching actually works, and how the game resources are structured.
The patching is done in several steps. The simplified list of them would be as follows:
- Unpack files from the iso image. The 3 types of files which will interest us will we the .afs packages, the init.bin file, and the "executable" EBOOT.BIN file.
- Extract and decompress the resources from the mac.afs (contains the text from the scenes) and etc.afs (contains fonts) game packages.
- Decompress the init.bin file. (Contains additional game text, like tips, some menus, chapter titles)
- Replace the game text and fonts.
- Patch the init.bin and EBOOT.BIN.
- Compress and package the game resources to corresponding .afs archives, and compress the init.bin.
- Package everything back to an iso.
These all will be executed upon running the make.sh
shell script.
See repack_afs.c
for unpacking and packing implementation. This is a somewhat modified version of rogerpepitone's source code, which was used for packing and unpacking afs in the PC version of the game.
To Roger, if you ever see this page: Thank you! Your code helped a lot to bootstrap this project!
The game uses the LZSS algorithm. The storage format is simple: a 32-bit int, storing the size of the decompressed data, followed by the compressed data. See also: compressbip.c
, decompressbip.c
, lzss.c
.
EBOOT.BIN is an elf (Executable Linux Format) file with a psp flavour.
Creating assembly patches is fairly easy using the amazing armips assembler. It's much harder and time consuming to spot what exactly needs to be changed.
All assembly patches can be looked up in src/boot-patches.asm
. At the moment, there are patches for the most critical issues, like character and line spacing and increased buffer size for the choice text. Some issues are still left unresolved, only because it requires a lot of effort to spot them.
All strings have a strict position in memory, and I don't have any tools to relocate them. So, whatever goes after or before the string should not be overlapped, meaning that strings have size constraints, deriving from the sizes of the original jap strings.
The python script which I use for substituting the strings is in text/apply-boot-translation.py
, and the text itself, that it uses is in the ext/other-psp/BOOT.BIN.psp.txt
. The script goes through every line, looking for the following format:
;<addr_in_EBOOT(optional)>;<length>;<jap_text>
<translated_text(optional)>
Then it will overwrite the text at that position (or search and replace if no position), gracefully skipping and warning about the lines that don't fit into the length restriction. Blank translated_text will be skipped.