Author Topic: FF4A - Where'd all the extra room go? (Newbie Complaints/Question)  (Read 4595 times)

Edea

  • FF4 Hacker
  • *
  • Posts: 21
  • Gender: Female
  • It slices, it dices, it casts Fire 2!
    • View Profile
This topic might be on the irritating side for those who know what they're doing when looking at a .gba file (i.e. everyone except me, apparently), so just bear with me as I am in need of assistance  :happy:.

OK, so very recently (like, yesterday) I decided to try the FF4 Advance GBA version of the game and see if I liked it.  It's a bit on the slow side as far as battles/graphics, but I haven't gotten anywhere near the extra parts of the game that are new (such as the Lunar Ruins), so I guess I'll keep going...more to the point of the thread, I decided I wanted to transfer some of my old ROM edits over to this particular incarnation.  Now, I wasn't surprised to learn that .smc and .gba have some differences by any means (this is the first time I've ever looked at a .gba file), but I thought at least there'd be a similar 'indexing scheme,' such that, say, the Job Command and Spell Learning lists in the .gba are in the same or at least a similar order to the ones in the .smc file.

No.  No soup for me.  I finally find the stupid Job Command list on my own, after discovering that, yes, the order the commands are stored in the ROM had changed (along with almost everything else, right down to how many bytes were involved with each separate field of the level-up data (this went up from five to sixteen), and apparently trying to find the character's names is a no-go). 

So Rydia is '00 04 07 08 02' rather than '00 02 03 04 01.'  OK, I guess that's not a problem...wait, where's all of the space after the command lists?  This section of the data flows straight into another set of values that I have no identity for (certainly not the copious quantities of 'FF' that usually succeeded these things). 

Also, the two sections of the ROM in the .smc that used to control which magic menu went to which character for the purpose of learning spells (FFFFFF|FFFFFF|020304|0506FF|FFFFFF|etc.); no idea where they are for the .gba file, tried looking for them using different arrangements of menu values (I don't even know if it's 3 bytes/char anymore or not). 

I've gleaned a fair amount of information about other aspects of the .gba file from datacrystal.org and romhacking.net, but these particular parts are being annoyingly elusive; also, the 'Spells Learned by Leveling Up' data is likewise completely sandwiched in by 'relevant' values, and not the big filler space I was used to. 

I'm beginning to think the only way to work around this is to find whatever points to that location in the ROM and redirect that to somewhere way near the end of the file, and just rewrite it from scratch.  At least .gba files are easy to expand so you can actually relocate blocks of data, but I haven't ever had to find where the game stores whatever it is that points to the start of the 'spells learned' table before (so I...kinda don't know where to start :/).  Is this making a mountain out of a molehill/is there some much easier way to edit the commands so people aren't stuck with 3 or 4 instead of 5?  Should I just stick with the SNES versions (which I've had no problems editing)?

Deathlike2

  • Moderator
  • *
  • Posts: 3,538
  • I'm looking at you, bitch!
    • View Profile
Re: FF4A - Where'd all the extra room go? (Newbie Complaints/Question)
« Reply #1 on: November 26, 2008, 06:09:53 PM »
It's just a guess here but many of those tables have been expanded or "reorganized" into a "dumbed down system". I mean, the developers were at least clever in original game, to maximize their space usage via tables. In this case, these tables are expanded into a more "powerful" version (you could do more in terms of manipulation), but consumes a lot of wasteful space.

Anyways, I'm sure if you try some simple combinations to find what you need.

It's best to try with Rydia's spell list or something highly recognizable.

If you were to hazard a guess to the format, it would be like this...
Character ID (1 byte), Level Learned (1 byte), Spell Learned (1 byte)

Then you just pray...  :tongue:
Working on the next Yet To Be Named FF4 "Hardtype" Hack Download Latest: v1.48

Video Demos: #1 #2 #3

Edea

  • FF4 Hacker
  • *
  • Posts: 21
  • Gender: Female
  • It slices, it dices, it casts Fire 2!
    • View Profile
Re: FF4A - Where'd all the extra room go? (Newbie Complaints/Question)
« Reply #2 on: November 26, 2008, 06:42:32 PM »
Hehe, k, I'll start with that...

Deathlike2

  • Moderator
  • *
  • Posts: 3,538
  • I'm looking at you, bitch!
    • View Profile
Re: FF4A - Where'd all the extra room go? (Newbie Complaints/Question)
« Reply #3 on: November 26, 2008, 06:52:42 PM »
Well, Character ID would probably be a leadoff value (but not duplicated)

I'm not sure how the original formats the spell levels, but doesn't it resemble something like..

Character ID, level, spell index where Character ID is just some sort of marker, and the level and spell index are the rest of the table for that character.
Working on the next Yet To Be Named FF4 "Hardtype" Hack Download Latest: v1.48

Video Demos: #1 #2 #3

Edea

  • FF4 Hacker
  • *
  • Posts: 21
  • Gender: Female
  • It slices, it dices, it casts Fire 2!
    • View Profile
Re: FF4A - Where'd all the extra room go? (Newbie Complaints/Question)
« Reply #4 on: November 27, 2008, 04:11:04 PM »
Well...I have now discovered why the 'spells learned by levelling up' section takes up so much room.  Apparently Square Enix thought it'd be a wise idea to use '00' as a terminating value for each spell learned in the data itself, rather than have the architecture for determining how to read the 'level gained-spell learned' system of ordering the bytes elsewhere in the ROM (the way the SNES files do it).  End result: tons of wasted space writing '00' over and over again.  Removing these causes a character with an active spell menu to 'learn' every single byte upon gaining their next level (some of the bytes actually produce text messages rather than actual spells if the hex values are high enough) until the next byte called is '00.'  Calling an 'FF' does not stop this from continuing (probably the text message bytes that pop up in battle while 'learning' the spells).

Also, the pointers for character magic menus are no longer in a 'WhWh|BlBl|CaCa' format; instead, starting at $ee600, each 16-byte 'line' of hex values corresponds to one character's magic menus with respect to both starting off with spells ($ee600 - $ee6df) and learning them through levelling up ($ee6e0 - $ee7bf).  For some reason, Paladin Cecil and Adult Rydia are now at the very bottom of the list (and Rosa is right after Kain) rather than the lists simply being arranged in the order you obtain the characters using them.  The first four bytes of a given line constitute the pointer for the first magic menu of that character (W.Magic), the second four bytes are the same for the second menu (B. Magic), the third set is for Summons, and the last set is for Ninjutsu (yes, that is now officially separate from B.Magic).  Here's an example line for Edge:

00 00 00 00|00 00 00 00|00 00 00 00|DF E8 0E 08

This is his 'starting magic' line, $ee6a0.  The first three are obviously empty, while the fourth has the pointer for his Ninjutsu menu with regards to determining which spells he starts off with, $ee8df.  Going to that address, we see the number '$42'  That happens to be the identifier for the Flame Ninjutsu.  Unlike learning spells through levelling up, starting off with spells does not require the insertion of '00' between each byte.

These areas of data have nothing to do with spells learned through events in the game; I've yet to find those.

Probably the easiest way to try and create some breathing room in that area of the .gba file is to make characters learn multiple spells at the same level or start off with more of them learned, which removes a lot of '00' values and would allow for new pointers to be set.  One very clear set of targets for this treatment would be Palom and Porom; you have them for a very limited portion of the normal game, and by the time you get them back they should have most of their spells anyway.  However, they take up an atrocious amount of space in this section.  Simply starting them off with more spells that they would have gotten at level 11-12, etc. anyway, and making them learn multiple spells at earlier/later levels, opens up some free workspace for editing other magic menus. 

At the moment this is all I've found (it's probably been found already, but at least I managed to (hopefully) understand this on my own ;_;); I would guess manipulating the higher bytes of the pointers (which at the moment are always '0E 08') could allow one to have new values entered at rather bizarre (and more ideal) locations, but I don't know how to manipulate the pointer properly as I don't understand what address specification '0E 08' stands for, while the lower two bytes were pretty obvious (would I change just the '0E', change the '08', or both?). 

Deathlike2

  • Moderator
  • *
  • Posts: 3,538
  • I'm looking at you, bitch!
    • View Profile
Re: FF4A - Where'd all the extra room go? (Newbie Complaints/Question)
« Reply #5 on: November 27, 2008, 04:25:12 PM »
Here's another way of analyzing what you found.

Those changes you mention are probably part of how the GBA port addresses "learning duplicate spells".. if you were to change a character's level (with a cheat device), you could "relearn" those spells... in the SNES version, this would turn up as duplicate spell entries in the spell list, whereas in FF4A, that doesn't occur.

I'm sure someone could've written that better though.
Working on the next Yet To Be Named FF4 "Hardtype" Hack Download Latest: v1.48

Video Demos: #1 #2 #3

Edea

  • FF4 Hacker
  • *
  • Posts: 21
  • Gender: Female
  • It slices, it dices, it casts Fire 2!
    • View Profile
Re: FF4A - Where'd all the extra room go? (Newbie Complaints/Question)
« Reply #6 on: November 27, 2008, 05:00:19 PM »
Yay!   :childish:

I changed Rydia's White Magic pointer to "60 FB 26 08."  I assumed this would point to a location far away from the normal spell learning data ($26fb60), an area filled with nothing but '00' values (hopefully this area isn't used for anything important).  I wrote the following string there and saved it:

26fb5f: "FF"
26fb60: "03 0E 0F 00 04 17 18 00 07 01 02 00 FF".

Booted up the game, and Rydia learned Cure and Cura at level 3.  She also learned Sight and Float at level 4 (I stopped playing after seeing that).  All spells appeared in the correct menu, unglitched.  Well, looks like the space issue is solved...actually, that means the spell menus for FF4A characters are MORE customizable than FF4j, as now you can have more than 3 spell menus provided you're willing to give up Fight or Item.  Also, I guess the pointers in this game simply use values equal to the address they point to (that makes sense).

Now to try figuring out how the pointers for Command menus work (as this is yet another area of restrictive space in the file).

Deathlike2

  • Moderator
  • *
  • Posts: 3,538
  • I'm looking at you, bitch!
    • View Profile
Re: FF4A - Where'd all the extra room go? (Newbie Complaints/Question)
« Reply #7 on: November 27, 2008, 05:44:18 PM »
That shouldn't be surprising...  :tongue:

I'd say the whole point of expanding the damn tables is for hacking.. if not for future FF4 ports or "expansion mods" or whatever...
Working on the next Yet To Be Named FF4 "Hardtype" Hack Download Latest: v1.48

Video Demos: #1 #2 #3

Phoenix

  • FF4 Hacker
  • *
  • Posts: 456
    • View Profile
    • Phoenix Hacks
Re: FF4A - Where'd all the extra room go? (Newbie Complaints/Question)
« Reply #8 on: November 28, 2008, 09:49:34 AM »
Your findings are quite interesting . . . I agree that it's odd the structure of the tables has changed. I wonder if that was intentionally planned out, or due to a difference in SNES versus GBA compilers.

I can think of one other benefit for this: like your Rydia, characters are able to learn multiple spells for one level. That wasn't possible in the SNES version. The spell numbers were also hard-coded to the lists (which is why I made the Adding Spells to Spell Lists patch) so the GBA version does seem more flexible.

Dragonsbrethren

  • Forum Overlord
  • *
  • Posts: 1,820
    • View Profile
    • Dragonsbrethren Industries
Re: FF4A - Where'd all the extra room go? (Newbie Complaints/Question)
« Reply #9 on: November 28, 2008, 09:53:55 AM »
The GBA version of FF6 is nearly identical data-wise to the SNES version, and I'd expect FF5 to be as well (I'm not familiar with FF5 at all to check). FF4a is based on the WSC version, and given all of the new bugs I'd say a good deal of the game was done from scratch, rather than porting the original code.

Edea

  • FF4 Hacker
  • *
  • Posts: 21
  • Gender: Female
  • It slices, it dices, it casts Fire 2!
    • View Profile
Re: FF4A - Where'd all the extra room go? (Newbie Complaints/Question)
« Reply #10 on: November 28, 2008, 08:13:33 PM »
Bad news time:  that dummy spell list from the SNES version?  It went bye-bye; the only available spell lists are all in use by at least one character already.  Go to $f2cb8 in the .gba file for the list orders of each character; "00 FF FF FF" is Cecil, then "FF FF FF FF" is Kain, and then "01 FF FF FF" is Rosa, for example.  Also, I've once again come up against the 'inactive spell list' problem (the one solved by Phoenix for the SNES version, where there was code in the $a0000 block that detailed which spell lists were active for each character), and this time the data format isn't replicated.  I dunno what that means for Rydia getting her White menu back, but I know for a fact that Dark Knight Cecil cannot use Paladin Cecil's White menu with the information gathered so far.  Guess more huntin' needs to be done.

EDIT: ...wait a minute.  In-battle, it works.  o_O  only the out-of-battle menu says 'Can't use magic.'  Wha....?

Deathlike2

  • Moderator
  • *
  • Posts: 3,538
  • I'm looking at you, bitch!
    • View Profile
Re: FF4A - Where'd all the extra room go? (Newbie Complaints/Question)
« Reply #11 on: November 28, 2008, 08:25:46 PM »
If you remembered any of the prior discussion revolving around this, the battle menu is not exclusively connected to the out-of-battle spell menus.
Working on the next Yet To Be Named FF4 "Hardtype" Hack Download Latest: v1.48

Video Demos: #1 #2 #3

Edea

  • FF4 Hacker
  • *
  • Posts: 21
  • Gender: Female
  • It slices, it dices, it casts Fire 2!
    • View Profile
Re: FF4A - Where'd all the extra room go? (Newbie Complaints/Question)
« Reply #12 on: November 28, 2008, 08:35:08 PM »
Well, yes, but I thought what I'd found WAS the out-of-battle spell menu data.  Guess not; whoops :blush:

Edea

  • FF4 Hacker
  • *
  • Posts: 21
  • Gender: Female
  • It slices, it dices, it casts Fire 2!
    • View Profile
Re: FF4A - Where'd all the extra room go? (Newbie Complaints/Question)
« Reply #13 on: November 29, 2008, 09:39:26 PM »
*Sigh*, found it.  I must say this version actually -saves- space, but I had no idea using this approach was going to produce a hit (so it was a lucky guess).

Go to $d1978 in the .gba file.  You'll see this series:

"00 00 01 07 00 03 00 00 02 01 08 03 01 06 03"

'01' is White Magic, '02' is Black Magic, '04' is Summons, and '08' is Ninjutsu.  Simply add the values together to get the number of spell menus you want for each character (1 byte/character) out of battle.  The bytes are in the usual FF4A character order (Dark Knight Cecil, Kain, Rosa, Young Rydia, Cid, Tellah, Edward, Yang, Palom, Porom, Edge, FuSoYa, Paladin Cecil, Adult Rydia, Golbez).

The Shell spell was successfully entered into DKC's '00' White menu (the only normally used by Paladin Cecil) out-of-battle after levelling up, once I changed the first '00' byte to '01.'  I also tried giving him Black Magic with a brand new menu designation ('03' for $d1978, '00 0C FF FF' for his actual magic lists, redirected the appropriate pointers), and something strange happened: the new menu technically works (the spells I specified go into the menu/start off there), but there's some strange garbage in there as well (such as Mega Flare).  Still investigating.

EDIT: Causes a crash after opening the Item menu, now looking for a way to add new lists beyond '0B' (which is Edge's Ninjutsu list).  Tested '0D'; it actually opens a fully functioning and unglitched spell menu, but then there's these five items that appear in the Item menu that are basically big collections of gibberish; you can't Trash them, and trying to Sort them crashes the game.  Also, got the European versions, thanks Deathlike2.
« Last Edit: November 29, 2008, 10:55:11 PM by Edea »

Deathlike2

  • Moderator
  • *
  • Posts: 3,538
  • I'm looking at you, bitch!
    • View Profile
Re: FF4A - Where'd all the extra room go? (Newbie Complaints/Question)
« Reply #14 on: November 29, 2008, 10:21:45 PM »
I'm not sure if you can make better progress there, but there are a few issues (I could be wrong).

There are some cheats for the game to manipulate the spell lists, which sounds nice, except that monster spells cannot be used.. (they must've been recoded with special checks or something).

If anything, you will probably have to do a lot of work to get a "special spell list" available and working.

Oh, and one other thing. I would suggest you work on the Euro version of the game instead of the US... if only to avoid all the evil bugs that exists.

Here's my link to the source: http://www.gamefaqs.com/portable/gbadvance/file/929937/41243

Quote from: Linked Cheats FAQ
-Rydia is the only one that can use summons.  Enemy abilities don't work at
 all unlike the SNES version.  White and Black magic can be swapped, meaning
 Black can be in a White magic menu and vice versa.  Same thing goes with
 Twin and Ninja Magic (Now the casting time for "Twin" magic doesn't have to be
 so attrocious, just hack it into their menu and the casting time will be a lot
 shorter).
« Last Edit: November 29, 2008, 10:31:57 PM by Deathlike2 »
Working on the next Yet To Be Named FF4 "Hardtype" Hack Download Latest: v1.48

Video Demos: #1 #2 #3