Author Topic: Developing FF4kster: a comprehensive editor for FF4  (Read 223634 times)

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,676
    • View Profile
Re: Developing a comprehensive editor for FF4
« Reply #915 on: December 22, 2014, 01:12:45 PM »
Indeed Avalanche! I had considered the idea that one of those bits may somehow be related to the alternate battle background (specifically, water) I'm somewhat surprised we never realized that one of those bits was the "Allow Save?" one, considering JCE3000GT released a hack a long time ago which allowed the player to save anywhere. Good thinking on those!

Hmm, you are right PinkPuff, but I believe it deals something with accuracy and damage is simply not calculated in a proper manner when this bit is on. Of the non-damaging spells that don't have it are...

White Magic: Blink, Slow, Fast, Berserk, Wall, Dispel, Peep, Exit, Sight, Float
Black Magic: Warp,
Ninja Magic: Image

It is interesting though... Asura's All-Revive has it on, maybe this has something to do with Life spell targeting as well? That will be worth a little experimentation.

Bizarrely not a Single enemy skill has it as active.

Here are my thoughts on it... the White spells apart from Blink (which may have a functional use not to use the bit), what is special about these spells may be that they're guaranteed to hit, if they can? However that would not explain why my Break skills had a chance to miss even at 127% accuracy. These use different formulas though and it may deal something with that. I still feel it's a safe bet to say "Damage Flag".

This new map editing system is Amazing PinkPuff! It is so slick and efficient, before when I wanted to highlight an area I needed to wait for my CPU to catch up to it, but now everything moves in real time, and the ability to see the palettes of the maps easily helps to choose desired palettes for new areas.

This is a terrific update all-in-all!

 :edit: Hmm, still looks that lingering "Yes/No, changes back to original" is back in Medicines for the Damage Flag, except now it saves the choice until you leave the menu, than it resets. I tested that it still works with Spells though. This also applies to the Impact Flag as well in Medicines.
« Last Edit: December 22, 2014, 02:03:54 PM by Grimoire LD »

avalanche

  • Mom Bomb
  • *
  • Posts: 122
    • View Profile
Re: Developing a comprehensive editor for FF4
« Reply #916 on: December 22, 2014, 02:52:16 PM »
Could I ask which bit you are talking about? I've done some analysis of the spell routine (based on all the hard work of everyone in this thread) and three of the bit 7's in the spell table, translating into psuedocode. Maybe I can offer something. One of them was rather weird as I recall.  There is something in there about allowing life spells through too, but I'll have to check my notes (later today).

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,676
    • View Profile
Re: Developing a comprehensive editor for FF4
« Reply #917 on: December 22, 2014, 03:03:28 PM »
Ah, this bit is here...

 byte 04:
    bits 0-6: elemental damage/status code
    bit 7: unknown


I would Love to see your notes by the way, despite just arriving to the scene you are already solving some old and persistent problems, so please, feel free to post your information.

avalanche

  • Mom Bomb
  • *
  • Posts: 122
    • View Profile
Re: Developing a comprehensive editor for FF4
« Reply #918 on: December 22, 2014, 06:02:58 PM »
Okay here we go.  First for some due credit: I based this heavily on your work, Grimoire.  I tried to fill in some of the missing pieces where (presumably) Geiger's live disassembly naturally jumped over some sections, but I probably missed some. And there were some sections I omitted, but I tried to indicate that below.

The bit in question is used a little over halfway down, after the label for address 03:D0A9.

Code: [Select]

[03:CC46]  Spell Routine (Command 0x02)
           Note: Item (0x1D) routine jumps into this too for most of the work.
----------------------------------------------

Sorry, I did not analyze the first chunk of the routine.
I believe part of it is looping targets to check for valid ones so that
it can calculate the divider used to split damage or healing.

The subroutine called at [03:CD33] for player Summon spells basically maps
to the Enemy Summon equivalent.
It replaces the caster's next subaction at $26D2, and sets $3584 to 1 as a flag.
To be honest, I did not know it overwrote $26D2 when I analyzed most of this,
so I may have some logic errors where the code tests for spell number ranges.

When Asura, it picks one of the 3 Asuras at random, and overwrites the
party target at $26D4 with 0xF8 (presumably to target all party?)

[03:CD3E]
Note: This is where the Item routine (0x1D) jumps in.

Starting around [03:D2CE] is where it looks to be checking for life-like spells.


[CE28]
    if (num_targets == 0)
        FAIL
   
    if (spell targets only ALL of ally or enemy)
        num_targets = 1                    // Clarification: this is the split damage/healing divider

[CE42]
    if (caster is a player)
    {
        if (caster.mp < spell.mp_cost)
            FAIL
        caster.mp -= spell.mp_cost
    }
   
[CE7B]
    if (using a spell, not an item)
    {
        if (caster has Mute and spell < 5F)   // The "verbal" spells, perhaps.
            FAIL
        if (caster has Piggy and spell isn't Piggy)
            FAIL
        if (caster has Toad and spell isn't Toad)
            FAIL
    }
   
[CEB7]
    hitrate = spell.hitrate
    if (spell is a White spell)
        hitrate += caster.will / 2
    else
        hitrate += caster.wisdom / 2
    if (hitrate > 255)
        hitrate = 255
    if (caster has Darkness)
        hitrate /= 2
    if (caster is in slot 0)
        hitrate *= 5 / 4
   
[CF01]
    // I reordered this section a bit to make the logic easier for me to follow
    if (is a weapon spell from the Item routine)
    {
        successful_hit_count = weapon_spell_multiplier  // from table at 0F:9070
    }
    else if (using an item or <byte at $38ED, possibly flag for Grimoire item?>)
    {
        successful_hit_count = 8
    }
    else
    {
        if (spell has solo multiplier bit?)     // top bit of effect index byte
            attack_multiplier = 1
        else if (spell is a White spell)
            attack_multiplier = caster.will / 4 + 1
        else
            attack_multiplier = caster.wisdom / 4 + 1
        successful_hit_count = calculate_multiplier(hitrate, attack_multiplier)
    }
   
   
[CF3E]
    Sorry, unknown stuff I did not complete.
    Part checks for Wall reflecting.
    Part also checks for some target statuses.  Very incomplete notes:
        If target is Hiding or Swoon, allow spell effects 0A (life) and 30 (I think Revive Monster?), but FAIL any others.
        If target is Stone, allow spell effect 0B (heal status), but FAIL any others.
   
[D049]
    // Note the game code uses a 2x biased integer for the elemental and creature "multipliers",
    // so (1 means 1/2x, 2 means 1x, etc)
    // and sets the top bit for absorb.  Here I just use real numbers like 1, -0.5, for simplicity.
    // The game initializes these memory locations for various calculations later; they are unused for the rest here though.
    is_crit = false
    elemental_multiplier = 1x
    creature_multiplier = 1x
   
    if (spell is a player Call spell)
        power = spell.power * 8
    else
        power = spell.power * 4
   
    if (caster and target are both PCs)
        defense = 0
    else
        defense = target.magic_defense

[D0A9]
    evasion = target.magical_evasion
    if (target has Darkness)
        evasion = 2             // I think it sets to 2, but that seems weird. Did they intend 0?
    if (caster is in slot zero)
        evasion *= 5 / 4        // This seems odd. Is it a penalty for spell use in the front?
   
    defense_multiplier = target.magical_defense_multiplier
   
    if (defense_multiplier > 0)
        if (spell has top bit of elemental index byte)      // <-- Here is the bit in question?
            defense_multiplier = 1
           
    if (target has Toad or Charging)
        defense_multiplier = 0
       
    if (target is a monster)
    {
        if (target.magical_defense_multiplier == 255)
        {
            evasion = 99
            defense_multiplier = 99
        }
    }
    successful_evasion_count = calculate_multiplier(evasion, defense_multiplier)
   
[D113]
    if (caster and target are both PCs)
        net_multiplier = successful_hit_count
    else
        net_multiplier = successful_hit_count - successful_evasion_count
   
    <tests $2A35 if non-zero causes a FAIL>
   
    if (net_multiplier <= 0 OR (target.is_boss AND spell has top bit of hit rate byte))
    {
        if ((spell is A0 [Explode]) or (5F <= spell <= 93) or (spell >= A9))
            net_multiplier = 1
        else
            FAIL
    }

[D162]
    // if invincibility is on, and target is a monster.  let monster target itself though
    if (invincibility_counter != 0 AND target is a monster AND caster != target)
    {
        // more simply this means: everything but the Crystal fails.
        if (using a spell)
            FAIL
        if (item is NOT the Crystal)
            FAIL
    }

       
[D17B]
    <Sorry I didn't finish this part>

    Eventually it jumps to the spell effect routine itself.

So, algorithmically, this bit would clamp the defense multiplier to 1 if it was higher.  In theory, this could affect whether the spell hits or misses, as well as any damage or healing that is calculated subsequently if any.  I honestly haven't looked at which spells have any of the 3 bits on yet though, so I will have to hold off making a better higher level description of its purpose.


Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,676
    • View Profile
Re: Developing a comprehensive editor for FF4
« Reply #919 on: December 22, 2014, 07:15:18 PM »
This is some impressive and useful documentation! With this I might be able to think of some way to make my Item Lord command properly differentiate between a Single Targeted Battle Item and an All-Targeted Battle Item.

That this bit would cause Magic Defense Multiplier to always be 1 is strange. What this bit does when activated is it also seems to kill Magic Multipliers if not other multipliers, you should try it out for yourself to see the weirdness in it.

What it does from my experience...

It has a decent chance of missing, even at 127% Accuracy and lowers damage to very low amounts ranging from 40's to mid 1000's depending on the amount of the Power of the spell.

This documentation is on the 02 Routine which is the Damaging Spell Routine (as I'm sure you're aware) but it also screws up damage all around, whether that damage come from HP Sap, Draining HP, and Attack Based on Physical Attack Power, the only damage it seems to deal with properly are fractions of damage or damage based upon the caster's current HP.

avalanche

  • Mom Bomb
  • *
  • Posts: 122
    • View Profile
Re: Developing a comprehensive editor for FF4
« Reply #920 on: December 22, 2014, 09:00:12 PM »
This is some impressive and useful documentation! With this I might be able to think of some way to make my Item Lord command properly differentiate between a Single Targeted Battle Item and an All-Targeted Battle Item.

Are the items the spell-like ones (index B0+)?  For those, there are bits in the item entry.  Come to think of it, the weapon-as-spell has them too via the spell they invoke, I think.


That this bit would cause Magic Defense Multiplier to always be 1 is strange. What this bit does when activated is it also seems to kill Magic Multipliers if not other multipliers, you should try it out for yourself to see the weirdness in it.

What it does from my experience...

It has a decent chance of missing, even at 127% Accuracy and lowers damage to very low amounts ranging from 40's to mid 1000's depending on the amount of the Power of the spell.

You are right, I will have to try it.  I have only looked at the assembly for my assessment, and as you know, the assembly can give quite a keyhole view into what's happening.

I would expect the defense_multiplier being lowered from a higher number to 1 ought to make it more likely to hit, and result in higher damage.  Unless the other bits were set, of course.  The one on the hitrate byte, at $289E in the spell code, has some pretty strange behavior too.  I very possibly got one or more things wrong with the analysis of the routine, for sure.


This documentation is on the 02 Routine which is the Damaging Spell Routine (as I'm sure you're aware) but it also screws up damage all around, whether that damage come from HP Sap, Draining HP, and Attack Based on Physical Attack Power, the only damage it seems to deal with properly are fractions of damage or damage based upon the caster's current HP.

It's the 02 Action routine for all spells, not the 02 spell routine.  So it would affect all the individual spell statistical routines.  Would make sense for the HP-based to not use any multipliers.  The assembly for caster's-HP-based for example explicitly overwrites what I called the net_multiplier to 1 at [03:D9B0].  Anyway, I will have to check out some spells and toggle the bits to see the actual in-game behavior.

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,676
    • View Profile
Re: Developing a comprehensive editor for FF4
« Reply #921 on: December 22, 2014, 09:23:52 PM »
Quote
Are the items the spell-like ones (index B0+)?  For those, there are bits in the item entry.  Come to think of it, the weapon-as-spell has them too via the spell they invoke, I think.

I think there's a slight bit of confusion. In FFIV: Combat Boost (my hack) there's a command called Item Lord which allows you to split any Item in your inventory to effect all allies or enemies, here is where the problem lies... unless the person with Item Lord has the Chemist Ring which doubles the effectiveness of healing items, then splitting healing items is generally useless. It's great for status healing though, especially in this hack.

The issues are as follows though... If they are Stone a multi-targeted Soft does not work and if they are dead a multi-targeted Life Potion does not work. In addition I had wanted the elemental damage items to have single target damage for this, but since their item is innately All Enemies it still does the same damage as if it is hitting All Enemies.

That's what I was thinking your findings may have helped be with a little.

Quote
It's the 02 Action routine for all spells, not the 02 spell routine.  So it would affect all the individual spell statistical routines.  Would make sense for the HP-based to not use any multipliers.  The assembly for caster's-HP-based for example explicitly overwrites what I called the net_multiplier to 1 at [03:D9B0].  Anyway, I will have to check out some spells and toggle the bits to see the actual in-game behavior.


Ah... now I'm confused. What are the other action routines then? This may be the first time I've heard of a numeric order given to the Action Routines. Maybe there's some different terminology going on here...?

avalanche

  • Mom Bomb
  • *
  • Posts: 122
    • View Profile
Re: Developing a comprehensive editor for FF4
« Reply #922 on: December 22, 2014, 09:42:40 PM »
I see.  Definitely a deeper challenge than my "have you tried these obvious bits?" suggestion.  : )

Quote
Ah... now I'm confused. What are the other action routines then? This may be the first time I've heard of a numeric order given to the Action Routines. Maybe there's some different terminology going on here...?

Probably terminology.  You called them Commands here: http://slickproductions.org/forum/index.php?topic=1883.0  00=Fight, etc.  Although now that I check the list I have, they pretty much only have 00=Fight in common...  In any case, it is what you listed as "02 White/Black/Call/Ninja/Spell Item Routines - 03CC46"

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,676
    • View Profile
Re: Developing a comprehensive editor for FF4
« Reply #923 on: December 22, 2014, 09:54:51 PM »
I see.  Definitely a deeper challenge than my "have you tried these obvious bits?" suggestion.  : )

Quote
Ah... now I'm confused. What are the other action routines then? This may be the first time I've heard of a numeric order given to the Action Routines. Maybe there's some different terminology going on here...?

Probably terminology.  You called them Commands here: http://slickproductions.org/forum/index.php?topic=1883.0  00=Fight, etc.  Although now that I check the list I have, they pretty much only have 00=Fight in common...  In any case, it is what you listed as "02 White/Black/Call/Ninja/Spell Item Routines - 03CC46"

Hehe, yes. Different terminology threw me off. Maybe I should take a closer look at that eventually...

In any case it is good to see some of these older issues being cleared up.

Though what is this separate list and how do you differentiate it from mine?

avalanche

  • Mom Bomb
  • *
  • Posts: 122
    • View Profile
Re: Developing a comprehensive editor for FF4
« Reply #924 on: December 22, 2014, 10:08:51 PM »
Quote
Though what is this separate list and how do you differentiate it from mine?

The one I looked at when I said that is from my list of commands the monster AI uses in the attack sequences.  I *think* I got that from http://slickproductions.org/forum/index.php?topic=1713.330 in the post by Dragonsbrethren.  The list from C0-D9 is what I mapped back to 00.  Perhaps this is a totally different list?


Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,676
    • View Profile
Re: Developing a comprehensive editor for FF4
« Reply #925 on: December 22, 2014, 10:21:28 PM »
Ah, no it's the same list, this is the way it is ordered in pretty much every list in a basic sense. The way I have it ordered in my topic is the order it is in the ROM itself. The order you see them in most places is how the routines themselves refer to them. Such as 02 being black, 03 being white, 05 being Dark Wave, etc.


 :edit: Oh right, PinkPuff another "1 off" bug, the Formation Indexes in the AI Scripts are all off by -1. So if the index is actually 220 you would have to put 219 in the Formation Index.
« Last Edit: December 23, 2014, 01:31:56 AM by Grimoire LD »

Pinkpuff

  • Flan Princess
  • *
  • Posts: 923
  • Find a Megalixir in Unprecedented Crisis!
    • View Profile
Re: Developing a comprehensive editor for FF4
« Reply #926 on: December 23, 2014, 07:43:30 AM »
The medicine flags have been fixed on my local copy; next time I upload, that should be working. The formation index thing has been added to the large list of stuff to fix in the Monster Editor which I promise I will tackle eventually  :tongue:

In the meantime I still can't figure out why the animated tiles aren't previewing correctly. I'm not trying to animate them per se (yet), just trying to get it to preview at least the first frame. As far as I can tell it's reading from exactly where it should... It starts at the "animations offset" for the tileset and looks (Major Index) * 16 + (Minor Index) tiles in to find the tile for each corner... is that not the correct procedure?
Let's dance!

avalanche

  • Mom Bomb
  • *
  • Posts: 122
    • View Profile
Re: Developing a comprehensive editor for FF4
« Reply #927 on: December 23, 2014, 10:05:57 AM »
That looks correct, it's exactly what I am doing for the handful of tilesets for which I found a base address.  The animation base address I listed is in the ROM with the header.  Perhaps too obvious, but was the major index shifted right 2 bits?

An example.  In the House (5) tileset, tile 17 (hex) is the clock tile.  Its top left corner subtile bytes are 24 15.
15 => 001(0 01)(00)
So its major index is 1, and minor is 0, so the address of the first frame for it is FC4C0 + ( 24dec * (major * 16dec + minor) ) = FC640 (which overlaps with the Castle tileset by the way so it can share the clock).

Oh, maybe I wasn't clear that the 16 was in decimal not hex?


I should take a stab with Geiger's to find whether the game uses a table or some other math formula to locate those base addresses so we can find the others.


Unrelated question, is the way spell animations are stored well known?  I have done a bit of deciphering on them, and want to know if it would be new useful information to post what I have.  It might be lengthy..

chillyfeez

  • FF4 Hacker
  • *
  • Posts: 1,234
  • Gender: Male
  • Go ahead, ask me about Angel Feathers!
    • View Profile
Re: Developing a comprehensive editor for FF4
« Reply #928 on: December 23, 2014, 11:12:00 AM »
Unrelated question, is the way spell animations are stored well known?  I have done a bit of deciphering on them, and want to know if it would be new useful information to post what I have.  It might be lengthy..
Not much has been documented. I delved into it a bit once for myself trying to make some custom spell animations, but I kept very few notes. Furthermore, I'm not really very well versed in how SNES actually interprets graphical data, so whereas I can look at the ASM and notice patterns and pointers, a lot of the finer points of it all elude me.
Any notes you have would definitely be useful and appreciated (but in a new thread).

On a tangential note - do you happen to know anything at all about world map graphics? Like, where the graphical data and/or tile assembly data are?

avalanche

  • Mom Bomb
  • *
  • Posts: 122
    • View Profile
Re: Developing a comprehensive editor for FF4
« Reply #929 on: December 23, 2014, 11:59:57 AM »
Quote
Not much has been documented. I delved into it a bit once for myself trying to make some custom spell animations, but I kept very few notes. Furthermore, I'm not really very well versed in how SNES actually interprets graphical data, so whereas I can look at the ASM and notice patterns and pointers, a lot of the finer points of it all elude me.
Any notes you have would definitely be useful and appreciated (but in a new thread).

Will do.  It will have to wait until after the holidays, but I'll post what I have found about them.  Pretty interesting stuff.

Quote
On a tangential note - do you happen to know anything at all about world map graphics? Like, where the graphical data and/or tile assembly data are?

Are you referring to the 16x16 graphics themselves?  I'm afraid not, I just made a tileset PNG manually from some other sources at some point.  All I could point out is what ye olde FF4.txt says:
Code: [Select]
A0200-A07FF (148000-1485FF) World Map Tile Formation Data
A0800-A0AFF (148600-1488FF) World Map Tile Palette Pointers
A0B00-A0C7F (148900-148A7F) World Map Palette Data
A0C80-A0F7F (148A80-148D7F) World Map Tile Properties Data
...
E8200-ED5BF (1D8000-1DD3BF) World Map Tile Graphic Data (also used to construct pointers to town gfx)
I just scanned through the entire ROM in 3 bpp format and didn't see them.  FF4.txt lists it at E8200 but that looks pretty tabular to me.  Are they 4 bpp?