Romhacking.net

Romhacking => ROM Hacking Discussion => Topic started by: Larry_Wilco on July 16, 2022, 09:08:26 PM

Title: IMG file on SaGa Frontier 2 disk
Post by: Larry_Wilco on July 16, 2022, 09:08:26 PM
Today I told a friend about the translation of Popolocrois and as a result of that he asked me if I could do the same with SaGa Frontier 2 in the future. The truth is that I don't have that game among my favorites, but I was curious to review the files of it.

When I saw the contents of the disk I was surprised that it had no folders or anything, only three files, among which SAGA2.IMG stands out, which is the one that obviously contains everything, which makes me suspect that it is compressed in some way.  None of the ps1 games I had seen before had such a feature, the most striking thing is the file format.  Now I am focused on my current project, but I would like to know if there is anything that can be done about it, to at least leave it registered as a help in case someone wants to translate this game into another language.
Title: Re: IMG file on SaGa Frontier 2 disk
Post by: Jorpho on July 16, 2022, 11:03:00 PM
Someone just had a similar question about FF8, which probably uses a similar format considering it is also from Square.
https://www.romhacking.net/forum/index.php?topic=35165
Title: Re: IMG file on SaGa Frontier 2 disk
Post by: Larry_Wilco on July 17, 2022, 12:49:17 AM
Judging from the link you left and what I've read on other forums, it seems that both Square and Enix loved to compress their game files, although one thing I read a lot about was the possibility of them used LZSS compression, but I'm unsure if this was also the case.
Title: Re: IMG file on SaGa Frontier 2 disk
Post by: MysticLord on July 17, 2022, 04:21:01 AM
No one knows the structure of that file. You have no choice but to open it up and figure it out. I'll take a gander at it.

---

I'm not sure if this is an assembly routine or not - it could be - but from address 0 to 0x1bf there's a bunch of these. Might be RAM addresses. Why?
1. It's clearly little endian.
2. Each address is larger than the previous one.
3. Each address starts with 0x80, which is IIRC the chunk of PS1 RAM dedicated to game stuff.
4. All of the 4 byte little endian numbers are way too big to be file addresses or file sizes, which is what you should be looking for.

Given the fine detail and number of entries, maybe it's a list of ram addresses for a large chunk of the game's subroutines related to various things, and there are different tables for various things like menus, the field, the "overworld" menu, and battles.

0C 56 0B 80
38 56 0B 80
74 56 0B 80
84 56 0B 80
...
00 00 00 00

It's terminated with good ole nop, aka "no operation".

Then there's a smaller table after that, from 0x1c4 to 0x22f.

It helps if you use a hex editor that lets you adjust the number of visible columns, I'm using XVI32 with column count of 8.

---

It doesn't look like SAGA2.IMG has an internal header file, as there are bits of assembly code interspersed with the pointer tables of RAM addresses (easy to tell because most subroutines in PS1 assembly language are split by a nop). You should check to see if there are any pointer tables.

You should look for pointer tables that have a header which lists a very small number that is either the starting file address, the file size, or the number of subfiles present in it's part of the archive. By "look for" I mean "open the file in XVI32, adjust the number of columns, and scan it as you page down for anything that looks right, or different.

After I look at a the top of a file for any patterns (number of subfiles, 2 and 4 byte pointers whose addresses increase as I go down the list), I go the the end of the file and do the same thing. Then I look at the file size and see if that appears in any footer, and I scroll up to the top of the file to see if the file size (or file size minus one) appears in the header.

Many files don't have headers or footers.

Here are a few examples from SaGa Frontier 1.

----

This is definitely some of the character sprite and palette data, and probably some other things no one outside of Square Enix is sure of. It's in B_CDATA. Indices in most commonly used programming languages start counting at zero, so this is the second character (C000.ARC is the first).

/B_CDATA/C001.ARC
# This is header at the very start of the file. All numbers are little endian and base 16 (hexadecimal)
05 00 00 00 # Number of subfiles: 5 in this case
1C 00 00 00 # 1st subfile address
1C C0 00 00 # 2nd subfile address
3C C0 00 00 # 3rd subfile address
AC D9 00 00 # 4th subfile address
E8 DA 00 00 # 5th subfile address
5C EB 00 00 # Size of C001.arc

---

Now let's look at the monster data files. They're all in B_MDATA. M000.ARC is Rocky.

/B_MDATA/M000.ARC
# This is header at the very start of the file. All numbers are little endian and base 16 (hexadecimal)
0A 00 00 00 # Number of subfiles, 10 in this case
30 00 00 00 # 1st subfile
30 80 00 00 # 2nd subfile
30 82 00 00 # 3rd subfile
1C 8D 00 00 # 4th subfile
1C 0D 01 00 # 5th subfile
8C 0D 01 00 # 6th subfile
5C 0F 01 00 # 7th subfile
74 0F 01 00 # 8th subfile
60 10 01 00 # 9th subfile
A0 10 01 00 # 10th subfile
B4 10 01 00 # Size of M000.ARC
So from this we know how *.ARC files work.

---

Let's look at battle events in SaGa Frontier, which are in:
/B_PROG/EVENT.BIN
/B_PROG/EVENT2.BIN

Each file has a set of 128 pointers, each 2 bytes long.

00 01 # 1st subfile, starting at 0x0100 in EVENT.BIN and ending at the address of the next subfile minus 1.
02 01 # 2nd subfile, starting at 0x0102 in EVENT.BIN and ending at the address of the next subfile minus 1.
A2 01 # 3rd subfile, starting at 0x01a2 in EVENT.BIN and ending at the address of the next subfile minus 1.
FE 04 # 4th subfile, starting at 0x04Fe in EVENT.BIN and ending at the address of the next subfile minus 1.
...
20 76 # 128th subfile, starting at 0x7620 in EVENT.BIN and ending at the end of file minus 1.

*.BIN generally means "compiled binary file" and it isn't consistently used in SaGa Frontier with this layout, so there's no useful context to be had from file suffixes here.

---

Here's another mystery file with a different header format.
/M_HERO/HERO00A.PEP
0C 00 # File address where 1st data entry starts
84 04 # File address where 2nd data entry starts
C4 05 # File address where 3rd data entry starts
34 0D # File address where 4th data entry starts
58 0D # File address where 5th data entry starts
00 00 # Unknown, always 00 00

---

And another mystery file.

/MIMF/IMF000.IMG
28 00 00 00 # File address where 1st subfile starts
30 00 00 00 # File address where 2nd subfile starts
54 00 00 00 # ...
58 00 00 00 # ...
68 00 00 00 # ...
28 01 00 00 # ...
F4 1F 00 00 # ...
F0 26 00 00 # ...
10 27 00 00 # ...
EC 46 00 00 # File address where 10th subfile starts

This one is interesting because if you look at the end of each subfile, you see each subfile is terminated by "00 00", which seems to indicate it needs a terminator somehow.

What needs that? Usually data of varying length, which includes things like promotion and recruitment tables in Ogre Battle MOTBQ and event scripting in many games.

Why would it need that when it can figure out the ending address from the index of the next subfile listing and of course the file size? Probably because they coded it to not store that information, or because scripts can run over a period of time, stop, and I assume branch to other scripts.

---

You don't need to know assembly language to figure out things, but you should know some of it's conventions for the system you're dealing with. Things like endianness, word size, the smallest unit of data it can load into a register at one time, word placement (not the right phrase, I forgot), nop opcode format, and a few characters from the ASCII table.

PS1 tidbits:
* Little endian
* Word size is 4 bytes
* Words must start at addresses divisible by 4 (ending in 0, 4, 8, C)
* Nop is "00 00 00 00"
* In ASCII space is 0x20, null is 0x00.

---

You should hassle and join FFVD's SaGa Frontier modding discord.
https://www.ffvdgames.com/portfolio/projects/sf1-modding/
https://discord.gg/tbCBX3UnZQ

I think they have the programs Zach Keene used to rip some of the more important data tables (items, arts, characters, etc) from the game on their discord somewhere, you should ask them about it.

---

Finally, you may find you need to move stuff around to make room. Well, good luck, but here's how you start.

https://www.romhacking.net/forum/index.php?topic=35311.msg432336#msg432336
Title: Re: IMG file on SaGa Frontier 2 disk
Post by: Larry_Wilco on August 16, 2022, 06:48:54 PM
I have good news. Although the American version has the texts encrypted or something that prevents them from being found normally, the friend I mentioned at the beginning of this forum and whom I will call "Pedro" from now on told me that there were German and French translations of this game, so he asked me to search in them, and to my surprise it turns out that THE FRENCH VERSION OF SAGA FRONTIER 2 HAS PERFECTLY EDITABLE TEXTS (with the corresponding table), and at least at first glance it seems that is complete.
The only problem I would see is that I can't find the game font to edit the French characters, but Pedro says that if I find the way and edit the font, he would be responsible for the Spanish translation. I already tried with jPSXdec and time2view but in none of them do I find the TIM image of the text, despite the fact that when opening the VRAM with no$PSX it tells me that it does indeed exist. If someone can do me the favor of giving me directions, I would greatly appreciate it, since the SaGa series does not have any game translated into Spanish (not even the Remasters) and it seems that the new remastered of this game for PS4 is not going to be the exception.

https://drive.google.com/file/d/1vBelHZ6ynlZJLqLs4hdyh57digPFZNAY/view?usp=drivesdk
Title: Re: IMG file on SaGa Frontier 2 disk
Post by: MysticLord on August 16, 2022, 08:43:09 PM
You could try opening the SCUS file in Tile Molester, but you need to fiddle with the settings before you start looking for the fonts. I don't know what the settings the font requires, but it's needed everywhere so it could well be in that file.
Title: Re: IMG file on SaGa Frontier 2 disk
Post by: Larry_Wilco on August 16, 2022, 09:50:55 PM
Well, I try with Tile Molester with the SLES archive (PAL version) and this was the best result I got:

https://drive.google.com/file/d/16yt1Shk9yh8-DiFjbpMKYB1vQrpRM2q9/view?usp=sharing

I really don't know what to think.
Title: Re: IMG file on SaGa Frontier 2 disk
Post by: MysticLord on August 17, 2022, 06:13:53 AM
I think that's the PS1 system font? Doesn't look like the SF2 font at all.
Title: Re: IMG file on SaGa Frontier 2 disk
Post by: Larry_Wilco on August 17, 2022, 07:41:39 AM
I agree.  In this case,  what can I do?  This is the first time I come across something like this.  Is it possible that someone from Romhacking can help me with this?  I just need the font so that it can be edited, if it turns out, a Spanish translation of this game would be possible.
Title: Re: IMG file on SaGa Frontier 2 disk
Post by: MysticLord on August 17, 2022, 06:58:01 PM
Quote from: Larry_Wilco on August 17, 2022, 07:41:39 AMI agree.  In this case,  what can I do?  This is the first time I come across something like this.  Is it possible that someone from Romhacking can help me with this?  I just need the font so that it can be edited, if it turns out, a Spanish translation of this game would be possible.
You need someone who knows MIPS and how to use a debugger to dig into the code and figure out where the font is. That person unfortunately isn't me.
Title: Re: IMG file on SaGa Frontier 2 disk
Post by: Larry_Wilco on August 17, 2022, 08:05:45 PM
well, anyway thanks for all. Do you know where I could find, either on Romhacking or elsewhere on the internet, someone who can help me with that? I admit that this game is not to my liking, but I was already attracted by the possibility that I can receive a translation.
Title: Re: IMG file on SaGa Frontier 2 disk
Post by: MysticLord on August 18, 2022, 06:31:01 AM
Quote from: Larry_Wilco on August 17, 2022, 08:05:45 PMwell, anyway thanks for all. Do you know where I could find, either on Romhacking or elsewhere on the internet, someone who can help me with that? I admit that this game is not to my liking, but I was already attracted by the possibility that I can receive a translation.
You can post a very specific ad in the help wanted board of this forum, and you could try FFVD's SaGa modding discord.

https://discord.gg/hyRgt8Fpy8

Neither will likely produce results, but it costs nothing to ask except your time.

However the SaGa series are being remastered so now is the best time to ask, as this will drum up interest.