Editing KTSL2STBIN files - three-houses-research-team/Throne-of-Knowledge GitHub Wiki
Tools
- VGAudio with KTSS support (Credits: Raytwo)
- Foobar with VGMStream extension
- KTSR.bt
- KTSL2STBIN.bt
Important note
For now, this require quite a bit of manual editing, as no tool to make the process less tedious has been made so far.
Depending on the total count of entries in the KTSL2ASBIN file, you'd need to fix quite a lot of offsets ( One fix for each KTSS entry that follows yours )
It is recommended that you only edit the BGM_DLC.ktsl2stbin file until a tool has been made, as it only contains 2 entries.
Guide
Locating your files
First, you'll have to find the KTSL2STBIN file you want to edit and the matching KTSL2ASBIN that contains the relevant informations for it.
- If you wish to replace regular BGMs from the game, the file is located in /nx/sound/BGM.ktsl2stbin. The KTSL2ASBIN uses the ID 0x786D
- If you wish to replace the DLC BGMs, the file is located in the relevant DLC with the name BGM_DLC.ktsl2stbin. The KTSL2ASBIN uses the ID 34542 (When extracting the DATA0.bin in the DLC, the file you're looking for has the ID 743)
- For movies, the KTSL2ASBIN uses the ID 30830.
- For patch3/nx/PATCH_SND.ktsl2stbin, the ID is 33794 (Japanese) or 33795 (English)
Extracting (Optional)
There are multiple ways to extract and listen to files packed in a KTSL2ASBIN.
Cethleann
Later, am too lazy
010 Editor
Open the KTSL2STBIN file in 010 Editor and use the KTSL2STBIN template on it. Select one of the entries in the list below, and then select the "KTSS Section" inside of it. Once you see bytes being highlighted in blue, right click on the selection, "Selection" -> "Save Selection" and give it a name that helps you remember which entry you're working on. Give it the extension ".ktss"
(You can click on the picture to see it in original size)
You can now listen to it in Foobar.
Converting
Prior to reinserting your file into the KTSL2STBIN, you need to convert it to a KTSS file. Extract VGAudio from the 7z archive you downloaded earlier. (Use the one from this article and not the official one, since there is no publicly available build of it with KTSS support yet) Now, put the file you want to convert in the directory next to the executable. Open a command prompt in that directory and use the following command:
VGAudioCli.exe input.wav output.ktss --bitrate "150000" --CBR --opusheader ktss
Of course, replace "input.wav" with the name and extension of your file. Also, the bitrate can be changed.
150000 just seems to strike a good balance between quality and size and seems close to what FETH uses.
Also, depending on the format your original file uses, some looping informations might be packed in and will automatically be included in the KTSS. (This test was made with a ADX file from Persona 3 FES and loops perfectly)
Do note that WAV files do NOT contain looping informations, so if you want to add them in, you'll have to do it by yourself by editing the KTSS file in 010 Editor and using the template.
Once you're done converting your file to KTSS, listen to it in Foobar to make sure it sounds the way it should.
Injection (KTSL2STBIN part)
Now, open the KTSL2STBIN file you want to replace in 010 Editor as well as your converted KTSS file. Use the KTSL2STBIN.bt file provided in the Tools section to parse it.
- You should see a "KTSR Section" followed by multiple entries. Which entry you'll replace is up to you, but there are some things to keep track of prior to replacing.
- Every "Entry" in the file contains a Header followed by a "KTSS Section". Look for the "Link ID" field in the entry, and write it down somewhere, as you'll need it a bit further down the road.
- After that, look at the "Section size" in your KTSS. You'll have to write this value in the "Entry" you're about to edit, in the "KTSS section size" field.
- Take the full size of your KTSS (it is NOT section size) and add 0x40 to it. Write down that value in "KTSS section size" in the entry from the KTSL2STBIN.
- Click on the "KTSS Section" field. It should highlight the entire KTSS for that specific entry. Right click on the selection, and "Delete" it.
- Select the entirety of your KTSS, right click on it and "Copy" it.
- Go back to the KTSL2STBIN, right click and "Paste". Make sure you are currently in INS mode and not OVR mode. (You can check in the bottom right corner of your 010 Editor window)
- Finally, select the entirety of the KTSL2STBIN, check the size of your selection and write it down in "Decompressed size" and "Compressed size" in the KTSR header.
Your KTSL2STBIN is now ready for use. Place it in the appropriate directory for file replacement.
Injection (KTSL2ASBIN) part
This one is more straightforward and should be dealt with quickly.
Open the companion KTSL2ASBIN file for the KTSL2STBIN you're editing in 010 Editor. You can find the ID for those files in the "Locating your files" section of this guide.
Apply the "KTSR.bt" template on it, and do the following:
- Select the "INFO2" section with the index matching your KTSS file in the KTSL2STBIN file. (If you replaced the second KTSS in the KTSL2STBIN file, select the second INFO2 entry)
- If the file you're inserting was at a different sample rate than 48000 Hz, write your sample rate in the appropriate field.
- Write the sample count from your KTSS to the appropriate field.
- Same goes for Loop Start. If your KTSS does not loop, use "0" instead.
- For "KTSS Offset", you need to specify the offset at which your KTSS file starts in the KTSL2STBIN.
- For "KTSS Size", specify the "KTSS Section size" from the KTSL2STBIN.
As mentioned at the beginning of this guide, inserting a KTSS with a different size ended up moving every other KTSS in the KTSL2STBIN container.
This means that for every entry past the one you edited in the KTSL2ASBIN, you'll need to fix the "KTSS Offset" field to indicate the new location of the corresponding KTSS.
Once you're done, replace the original KTSL2ASBIN using your favorite patching method. (INFO editing, Starfall, Aldebaran, ...)
Ending
If you reached the end of this guide, congratulations! If you did everything properly, you should be able to hear your modded music in the game. If not, it is best that you retry doing everything from the "Injection (KTSL2STBIN)" section, as this is the place where you most likely messed up.