News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Need some help editing Saturn TOC to expand files...  (Read 6805 times)

MrFwibbles

  • Jr. Member
  • **
  • Posts: 34
    • View Profile
Need some help editing Saturn TOC to expand files...
« on: March 08, 2012, 07:15:10 pm »
I've been looking at Grandia: Digital Museum recently and one of the first major problems I've (expectedly) ran into is that there isn't enough room within each file to edit in a decent translation. After having no joy with Sephiroth1311's PSX TOC modifying program, I went hunting for his Italian guide to doing it with a hex editor, and opened my ISO and followed along with the help of Google Translate. It all seemed to go smoothly:


(highlights added as reference notes for myself)

and CDmage was reporting the random new filesize I decided to give to this file (505,000 bytes). After saving, recompiling and mounting the ISO, Windows was happy with it but the SSF emulator wouldn't start the game (it was able to load from a save state and then work as normal, however). When I tried this last night, I tried a new file size of 508,000 and after mounting the image, Windows was giving me an error message whenever I tried to open the FIELD/ folder containing the file I'm trying to expand. I guess this is possibly because I was overwriting part of another file by overexpanding the one I was working with.

The game doesn't seem to have any "index" (though it does have IDX files if that's what that refers to) or "second TOC" (E800.MDT only matched once in an ISO search). The TOC changing guide mentions a formula for calculating the maximum file size, but I can't make sense of it:

Quote
LBA = 1 file to expand
LBA = 2 to the next file to be expanded
(LBA 2 - LBA 1) * 2048 = maximum result

...Well, the LBA of the file I'm trying to expand is 31,115 but how do I know what is "the next file to be expanded"? From the example I understood that it means the file listed previously in the TOC. This leaves me with -237568 bytes as my maximum file size, which obviously isn't right.

Does anyone know how to calculate the maximum filesize like this for Saturn games (Mode 1/2352 ISOs), or am I approaching this in the wrong way?

Edit: Yeah, the ISO stops working if I import a file that's even 1 byte bigger than the original. Also, when I mount the ISO after making my changes, Windows reports that the edited file is still the original size. There must be a check going on somewhere, right?
« Last Edit: March 08, 2012, 08:03:12 pm by MrFwibbles »

Auryn

  • Hero Member
  • *****
  • Posts: 649
    • View Profile
Re: Need some help editing Saturn TOC to expand files...
« Reply #1 on: March 08, 2012, 08:19:12 pm »


Even if your google translation isn't perfect, you should get the idea just from the numbers on that guide.
Anyway the correct translation should be (and using the example above):
LBA1 = LBA of the file to expand = window.bin = 615
LBA2 = LBA of the next file after the one you want to expand = Kernel.bin = 622
If you have folders, be sure to check the LBA of the files inside the folders as well.

And yes, I am the same Auryn mentioned in that guide.

By the way, yes, it should work for Saturn as well even if nor Sephiroth (i think) nor me ever tried with it.


MrFwibbles

  • Jr. Member
  • **
  • Posts: 34
    • View Profile
Re: Need some help editing Saturn TOC to expand files...
« Reply #2 on: March 08, 2012, 09:08:28 pm »
How do you conclude that KERNEL.BIN is the next file? Is it because it has the next biggest LBA in the folder, or because it was the one that came before the one you wanted to expand in the TOC? And why would the ISO stop booting in the emulator if I was only making the file 1 byte bigger? You do have to change the hexadecimal values in both forwards and backwards formats, right?

Edit: Eh, it looks like there's some kind of checksum going on somewhere. As soon as I change one byte that represents the file size, regardless of whether or not I import a file in CDmage, the entire ISO will no longer start up in the emulator.
« Last Edit: March 08, 2012, 11:07:08 pm by MrFwibbles »

CUE

  • Jr. Member
  • **
  • Posts: 86
    • View Profile
    • Nasío pa'jakear
Re: Need some help editing Saturn TOC to expand files...
« Reply #3 on: March 09, 2012, 03:31:42 am »
Quote from: MrFwibbles
How do you conclude that KERNEL.BIN is the next file? ...
YAMADA.BIN - Start at sector 614, size=80 -> 80 / 2048 = 0.04 -> rounded = 1 sector -> 614 + 1 = 615 is the next sector (LBA)
WINDOW.BIN - Start at sector 615, size=13900 -> 13900/2048=6.78 -> rounded = 7 sectors -> 615 + 7 = 622 is the next sector (LBA)
...

Max filesize in the same "space": round(SIZE/2048) * 2048 ('2048' is the sector size, 0x800):
- for YAMAHA.BIN -> round(80//2048) * 2048 = 1 * 2048 = 2048 bytes
- for WINDOW.BIN -> round(13900//2048) * 2048 = 7 * 2048 = 14336 bytes

Quote from: MrFwibbles
...After saving, recompiling and mounting the ISO, ...
How do you do?
All others files are in the same position (LBA)? Check the file "CDDA1" in the root, a CD DA file pointing to the music track. The game can crash if this LBA is modified.

Can you convert your MODE1 ISO in a MODE0 ISO with the music track in another file (MP3/WAV format)? I have a tool to modify a MODE0 image with modified files, even changing the number of sectors occupied.


~~~ ADDED ~~~
- for E800.MDT -> round(0x7B000/2048) * 2048 = 246 * 2048 = 0x7B000 bytes, the file has the max space allowed, you can't add more bytes !!!
« Last Edit: March 09, 2012, 03:42:19 am by CUE »

Auryn

  • Hero Member
  • *****
  • Posts: 649
    • View Profile
Re: Need some help editing Saturn TOC to expand files...
« Reply #4 on: March 09, 2012, 03:38:05 pm »
Quote
How do you conclude that KERNEL.BIN is the next file? Is it because it has the next biggest LBA in the folder,
No.
Quote
If you have folders, be sure to check the LBA of the files inside the folders as well.

It is the next file because it's the next LBA in the whole disk.

What CUE say, it's ok but if the Saturn is like the PS1, there are almost always empty sectors between the files.

Well, if there is a checksum, you need to find where that is.

MrFwibbles

  • Jr. Member
  • **
  • Posts: 34
    • View Profile
Re: Need some help editing Saturn TOC to expand files...
« Reply #5 on: March 09, 2012, 06:41:58 pm »
Thank you for the explanations. I think I understand it now, but there's still something funny going on.

From what I understand, if (file size) / 2048 = a whole number, then the file can't be expanded. This is unfortunately the case for all of the .MDT files (where the game contains most of its dialogue), but not for FIELD\TEXT2.BIN:

- for TEXT2.BIN -> 26192 bytes (6650 hex)/ 2048 = 12.789
   LBA 193339    -> rounded = 13 sectors
                      -> 13 * 2048 = 26624 bytes (6800 hex)

So I padded my copy of this file to 26624 bytes in Translhextion, and edited the reverse/normal hex referring to the file size in the ISO. Then I tried mounting the ISO and seeing if the game would start like this. Nothing. At this point I opened it in CDmage and imported the file I'd expanded earlier, then saved the change. Mounted again, back to the emulator, still not loading.

Assuming I'd done something wrong, I made a new copy of the ISO and tried using Sephiroth 1311/Phoenix's program again (being sure the LBA matched because the game has 2 files called TEXT2.BIN in separate folders), and it reported that everything was successful and it had chaged the TOC and ECC/EDC (I'm not sure what ECC/EDC is). The game still wouldn't load. I can replace the files after editing them, but as soon as I increase the size of a file, the game stops working. What could be causing this?

Quote
How do you do?
All others files are in the same position (LBA)? Check the file "CDDA1" in the root, a CD DA file pointing to the music track. The game can crash if this LBA is modified.
I'm just doing what I wrote above. I'm not changing any LBAs as far as I know. Yeah, the LBA for CDDA1 is 193,769 on both the original and modified ISOs, it hasn't been touched.

Quote
Can you convert your MODE1 ISO in a MODE0 ISO with the music track in another file (MP3/WAV format)? I have a tool to modify a MODE0 image with modified files, even changing the number of sectors occupied.
I wouldn't know where to start with that, and doesn't Grandia use a special kind of compression for its audio? Digital Museum is based on the original game's code.

CUE

  • Jr. Member
  • **
  • Posts: 86
    • View Profile
    • Nasío pa'jakear
Re: Need some help editing Saturn TOC to expand files...
« Reply #6 on: March 10, 2012, 02:51:00 am »
Hmmmm, I have the game in ISO/MP3 format (ISO for the data track, MP3 for the music track) and  I expanded FIELD\TEXT2.BIN from 26192 bytes (0x6650) to 26624 bytes (0x6800) to fill the latest sector with random data. I replaced the file into the ISO and the game run fine in SSF Ver0.12 beta R3. Now I need finish the tool to allow replace a file with other of any size.

The EDC (Error Detection Code) is a sector CRC checksum to check if the sector data is corrupt. The ECC( Error Correction Code) is used to correct the corrupt data.

MrFwibbles

  • Jr. Member
  • **
  • Posts: 34
    • View Profile
Re: Need some help editing Saturn TOC to expand files...
« Reply #7 on: March 10, 2012, 01:49:20 pm »
CUE, did you get my PMs? I sent 2 but they're not showing up in my sent box.

CUE

  • Jr. Member
  • **
  • Posts: 86
    • View Profile
    • Nasío pa'jakear
Re: Need some help editing Saturn TOC to expand files...
« Reply #8 on: March 11, 2012, 11:11:48 am »
CUE, did you get my PMs? I sent 2 but they're not showing up in my sent box.
Yes.

I'm working in a tool to replace files in a MODE0/MODE1 CD image, similar as PSX-MODE2:


MODE0 is finished. I think the next week will be totally finished.

March 17, 2012, 04:50:55 am - (Auto Merged - Double Posts are not allowed before 7 days.)
Tool added: http://www.romhacking.net/utilities/852/

To change the cuesheet file:
- get the file LBA (file "CDDA1" in Grandia Digital Museum)
- convert to minutes/seconds/fractions
- change the values in the file (".cue" extension)

Example:
Code: [Select]
CDDA1 LBA = 193769
min = lba / (60 * 75) = 43;  // integer division
mod = lba % (60 * 75) = 269; // remainder division
sec = mod / 75 = 3;          // integer division
fra = mod % 75 = 44;         // remainder division

Edit the cuesheet file and change INDEX 01 with the new min/sec/fra values ("isoname" is the cd image name):
Code: [Select]
FILE "isoname" BINARY
  TRACK 01 MODE1/2352
    INDEX 01 00:00:00
  TRACK 02 AUDIO
    INDEX 01 43:03:44
« Last Edit: March 17, 2012, 04:50:55 am by CUE »

CyberWarriorX

  • Jr. Member
  • **
  • Posts: 42
    • View Profile
    • CyberWarriorX.com
Re: Need some help editing Saturn TOC to expand files...
« Reply #9 on: March 19, 2012, 01:24:12 pm »
Hey CUE, any plans on adding support for games with two data tracks?

CUE

  • Jr. Member
  • **
  • Posts: 86
    • View Profile
    • Nasío pa'jakear
Re: Need some help editing Saturn TOC to expand files...
« Reply #10 on: March 20, 2012, 06:08:53 am »
No, sorry. I'm full with other projects.  :(

What system uses CD games with 2 data tracks?

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 6747
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Need some help editing Saturn TOC to expand files...
« Reply #11 on: March 20, 2012, 01:14:51 pm »
PCE-CD, possibly.
"My watch says 30 chickens" Google, 2018

CyberWarriorX

  • Jr. Member
  • **
  • Posts: 42
    • View Profile
    • CyberWarriorX.com
Re: Need some help editing Saturn TOC to expand files...
« Reply #12 on: March 21, 2012, 03:00:35 pm »
No prob. Just figured I'd ask since it's up your alley.

Several Saturn games use 2 data tracks. Just off the top of my head: All the Langrisser games, Lunar SSSC, Snatcher, Nights. Basically the first track is MODE1, second track MODE2, and then any following tracks are audio tracks. File table for both tracks is located in the first data track. The whole point of it was to allow for ADPCM, MPEG to be stored as form 2 data while maintaining compatibility. Here's a sample cue file I have for Lunar SSSC:

Code: [Select]
FILE "LUNARSSSC.BIN" BINARY
  TRACK 01 MODE1/2352
    INDEX 01 00:00:00
  TRACK 02 MODE2/2352
    PREGAP 00:03:00
    INDEX 01 07:55:41
  TRACK 03 AUDIO
    PREGAP 00:02:00
    INDEX 01 54:20:22
  TRACK 04 AUDIO
    INDEX 00 56:44:70
    INDEX 01 56:46:69

CUE

  • Jr. Member
  • **
  • Posts: 86
    • View Profile
    • Nasío pa'jakear
Re: Need some help editing Saturn TOC to expand files...
« Reply #13 on: March 21, 2012, 05:54:12 pm »
These games use MODE2/FORM2 tracks, same as PSX. I can't replace the files because I don't know how to assign values  to the byte CODING_INFO (sector byte 0x013) without check the MPEG/AUDIO file. The tool never checks the files, just replace.

CyberWarriorX

  • Jr. Member
  • **
  • Posts: 42
    • View Profile
    • CyberWarriorX.com
Re: Need some help editing Saturn TOC to expand files...
« Reply #14 on: March 21, 2012, 11:11:55 pm »
These games use MODE2/FORM2 tracks, same as PSX. I can't replace the files because I don't know how to assign values  to the byte CODING_INFO (sector byte 0x013) without check the MPEG/AUDIO file. The tool never checks the files, just replace.


Pretty much, aside from some small differences in the file table, etc. as I've already mentioned. Alright, I just figured I'd ask since you mentioned your utility.

Sephiroth 1311

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: Need some help editing Saturn TOC to expand files...
« Reply #15 on: March 22, 2012, 02:59:48 am »
MrFwibbles, have you tried using ECCRegen to regenerate the ECC field, after manually editing the ISO file?
I've never worked on a Saturn game, but I think that MIGHT be a thing to try. The original PSX too would crash without regenerating the ECC field, even if PSX emulators don't.

I'm surprised I didn't write about ECCRegen on my guide, but I wrote it so many years ago and I was much less experienced back then... but I'm happy that it was of use to someone else!

What do you think, should I make an English translation?
Sephiroth 1311
****************
member of SadNES cITy
1st italian ROM translation group
http://www.sadnescity.it *********************** "Do you want to leave to your own eyes Only dreams that won't awaken you?" "Yes, Your Honour, but I want greater ones."

CUE

  • Jr. Member
  • **
  • Posts: 86
    • View Profile
    • Nasío pa'jakear
Re: Need some help editing Saturn TOC to expand files...
« Reply #16 on: March 22, 2012, 04:22:09 am »
But ECCRegen only recalculate the EDC/ECC, and not update the TOC when the modified file has a different number of sectors. It's the same problem with CD-Mage.