Final Fantasy IV SNES - Critical Hit Bug Fix?

Started by 8.bit.fan, November 15, 2018, 03:12:31 AM

Previous topic - Next topic

chillyfeez

#20
ok, I fired up the ol' ROM and have been playing around a small bit.
Preliminary findings:
- There seems to be no truth to the theory that whips block critical hits. I jacked young Rydia's critical hit rate up to $40 which makes her crit about 90% of the time, and she does so whether or not she is using the whip.
- It is true that a character who starts a battle dead loses critical hits altogether. the byte gets zeroed out. This is weird, but should be an easy fix. More on this as I play around a little.

That's all for now, but obviously there's more to examine (I haven't even looked at autobattles yet). I will update as I find more.

EDIT:
I'm looking back at what Grimoire LD said earlier, and maybe the reason the weapons aren't affecting critical is that I "hacked them in?" Can anybody clarify this point? Exactly what kind of testing has been done to determine that the "no critical" bit does in fact remove critical hits? I'd like to address the issue if it does indeed exist, but I'm a little unsure as to what conditions should be present in order to observe it.

EDIT:
'Kay, now I'm really confused...
Took a Vanilla ROM, added the "No Crit" bit to the Shadow sword, started a new game. Cecil got a critical hit on literally his first player-controlled attack (a random Imp), but since then, Kain has gotten about five critical hits and Cecil hasn't gotten any more. They both have "02" in their critical hit percentage byte in the character record (which is how they seem to start by default). That doesn't seem to have changed at all with the Shadow sword equipped.
Ongoing project: "Final Fantasy IV: A Threat From Within"

Latest Demo

8.bit.fan

Quote from: chillyfeez on November 28, 2018, 10:56:01 PM
ok, I fired up the ol' ROM and have been playing around a small bit.
Preliminary findings:
- There seems to be no truth to the theory that whips block critical hits. I jacked young Rydia's critical hit rate up to $40 which makes her crit about 90% of the time, and she does so whether or not she is using the whip.
- It is true that a character who starts a battle dead loses critical hits altogether. the byte gets zeroed out. This is weird, but should be an easy fix. More on this as I play around a little.

That's all for now, but obviously there's more to examine (I haven't even looked at autobattles yet). I will update as I find more.

EDIT:
I'm looking back at what Grimoire LD said earlier, and maybe the reason the weapons aren't affecting critical is that I "hacked them in?" Can anybody clarify this point? Exactly what kind of testing has been done to determine that the "no critical" bit does in fact remove critical hits? I'd like to address the issue if it does indeed exist, but I'm a little unsure as to what conditions should be present in order to observe it.

EDIT:
'Kay, now I'm really confused...
Took a Vanilla ROM, added the "No Crit" bit to the Shadow sword, started a new game. Cecil got a critical hit on literally his first player-controlled attack (a random Imp), but since then, Kain has gotten about five critical hits and Cecil hasn't gotten any more. They both have "02" in their critical hit percentage byte in the character record (which is how they seem to start by default). That doesn't seem to have changed at all with the Shadow sword equipped.
Very interesting finds chillyfeez!
I guess one easy way to fix the portion of this bug from the weapons' end is to simply remove the 'no critical' bit from them. Should be easy enough. This plus the dead at battle start fix we should be left with the most intriguing part of this bug and that's the auto battle one.
In the year of 200X, a super robot named Mega Man...
http://www.8bitfan.info/
FF4 Ultima Discord: https://discord.gg/4MqjwJt

chillyfeez

Oh, I'm not done looking into the "no critical" bit on weapons. I've just had a limited amount of time to test things so far. If the weapons do indeed block critical hits by a character permanently, I'll figure out how that's done. What's odd is that if this is true, it does not affect the critical hit rate in the character record. It's some "switch" that gets "flipped" elsewhere... But elsewhere in SRAM, because it's supposedly permanent.
By contrast, a character who starts a battle dead has their critical hit rate zeroed out in the character record. That will likely be much easier to fix once I get to the "fixing" step of this process.
Ongoing project: "Final Fantasy IV: A Threat From Within"

Latest Demo

8.bit.fan

Sounds great chillyfeez :)

Btw, where in the SRAM is the critical bit located for each characters?
In the year of 200X, a super robot named Mega Man...
http://www.8bitfan.info/
FF4 Ultima Discord: https://discord.gg/4MqjwJt

Grimoire LD

#24
Wow, I thought the weirdest part of the rumor was the null-crit for being dead, but just as Chillyfeez said, when you start the battle dead your Crit is set to 00. This even extends to outside of battle. I tried to equip-dequip, the critical hit chance is dead. I thought maybe it was some sort of glitch that would clear by reloading the game... nope. I am beginning to wonder if this was intentional...? Let's go back and find the cause...

Alright, there is something interesting going on here. there are two crit values stored in the character in-battle status. One is the default one which changes depending on the weapon type (x2 for conventional, x3 for bow/arrow, no multiplier for bare handed) The other value is the "true crit" rate before the multiplier.  This is set to 00 when you enter battle dead. Ah! Perhaps this might explain it... This value is past normal stats. When a character starts dead, these values are mostly set to 00. The issue is that the "true crit" Byte that is carried outside of battle in this "dead" multiplier section setting it to 00, and because the game uses this value to determine initial crit chance, it becomes 00. This is exactly why everyone but Cecil would lose their crit in the Zeromus fight.

This may be difficult to fix as the game never refreshes this area in battle outside of setting it to 00 for being dead... The game has already written 00 to the natural crit byte.

...Found it! That was difficult, but I found how the data is set to 00.... Alright, this is oddly specific, nothing else changes but Killing the crit rate. Nothing dealing with ATB, no nothing. This... may have been intentional, but it's such a silly design choice if so. It is a one byte change. The instructions also set speed, but that doesn't matter. The game already know the character is dead and resets speed immediately.

$03/94ED B1 80       LDA ($80),y[$7E:2003]   A:0001 X:0040 Y:0003 P:envMxdIzC - Load character
$03/94EF 29 C0       AND #$C0                A:0080 X:0040 Y:0003 P:eNvMxdIzC - Are they dead/petrified?
$03/94F1 D0 7D       BNE $7D    [$9570]      A:0080 X:0040 Y:0003 P:eNvMxdIzC - If so, skip the Speed/Crit Rate Setup
$03/9570 FA          PLX                     A:0080 X:0040 Y:0003 P:eNvMxdIzC

Just change in Headerless ROM (1.1) - 0x194EF to 00 and that will fix this truly bizarre behavior and I bet this will also fix the AI battle's setting crit to 00.


Well, here is another glitch. IF you start the battle with a certain multiplier and switch your weapon the game will not account the new crit multiplier... but it is applied after the battle is over.


So I looked into the weapon crit rates... most weapons set it as 80, but Bows alone also set it to 80, unless it is a Bow and Arrow then it is a different value, A0. Except while dual wielding, it sets crit to x1 multiplier through a C0 exception.

EDIT: And here is an interesting oversight... when you leave battle your crit multiplier is set back to normal. But if you equip another weapon it will change in real time in the battle stats to its multiplied value. I wonder if they originally intended in showing crit chance somewhere?


8.bit.fan

Amazing find Grimoire LD! :)

So, changing 0x194EF to 00 will fix the issue for a new game. But what about saves with characters' critical rate already zeroed out?

I'll check this out in the hex editor when I get the chance! :)
In the year of 200X, a super robot named Mega Man...
http://www.8bitfan.info/
FF4 Ultima Discord: https://discord.gg/4MqjwJt

Grimoire LD

#26
Unfortunately the game writes Critical Hit Rates back and forth. The "true crit rate" is written into the out-of-battle crit rate (then multiplied accordingly), which is then written to the "true crit rate" when the next battle begins Unless the character is dead, then that instruction is entirely skipped (which my hack fixes by removing that dead/petrified check) so the 00 is written into the out-of-battle stats and that is written to the character's "true crit rate" when they are next revived inside or outside of battle. The moment a dead character enters battle, Crit is lost forever. However, by changing this you can prevent the glitch from occurring any longer. I suspect that this "Speed Freeze" may be the reason Adult Rydia has no crit, but I would have to test that.

As for the weapons... all I did was increase Rydia's natural critical hit rate to 0A (therefore weapons would be 20) and both Whips and the Silence Staff worked fine and critted on occasion. Perhaps it was an incorrect observation borne of an unknown weapon bit (that we still don't know what it does)

8.bit.fan

Interesting...because once I removed the 'no crit' bit from the new weapons for my Ultima hack Edge started doing critical with them. Seems like the algorithm is more complex than it seems...
In the year of 200X, a super robot named Mega Man...
http://www.8bitfan.info/
FF4 Ultima Discord: https://discord.gg/4MqjwJt

chillyfeez

So, Grimoire... is this solved?
Looks like you fixed the dead entry problem, and you concur with my observation that there is no bug with the weapon bit. Do we still need to test autobattles?
Ongoing project: "Final Fantasy IV: A Threat From Within"

Latest Demo

Grimoire LD

I think just to make sure it would be good to test the auto-battles. I did test Rydia's return, thinking that perhaps that somehow killed the critical byte for her (and the false implication that Whips were responsible) but there was no issue there. I did not test the auto-battles though.

8.bit.fan

Wait, just tried changing 0x194EF to 00 and the game glitches when I start...
In the year of 200X, a super robot named Mega Man...
http://www.8bitfan.info/
FF4 Ultima Discord: https://discord.gg/4MqjwJt

chillyfeez

#31
Did you change it using a hex editor or using Geiger's?
If you're using Geiger's, it would be 394EF.

Further support for the notion that the "No Critical" bit is no such thing - the game pretty much never even looks at it. When a weapon is equipped, the only bit in that byte that is addressed by the game is the long range bit. The long range bit is checked twice more every time a battle starts, once after the battle ends, and every time the weapon is equipped during battle, but no other bit in that byte is ever checked during most situations in normal gameplay. I imagine if the player is in the Magnes cave, the magnetic bit is checked regularly, and when Edge uses the Throw command, the throwable bit is checked, but I don't ever see bits 0 through 4 ever getting checked. They seem to be remnants of scrapped plans.
Ongoing project: "Final Fantasy IV: A Threat From Within"

Latest Demo

Grimoire LD

Bah! I'm sorry. It is 0x194F0, sorry about that.

chillyfeez

haha - I JUST noticed that, too! I was about to edit my post...
Ongoing project: "Final Fantasy IV: A Threat From Within"

Latest Demo

8.bit.fan

Cool! Ok so I made the change at 0x194F0 but I still can't seem to critical with the characters that had been no-critical'd...basically only Edge can do critical at endgame in this particular save file that I have...
In the year of 200X, a super robot named Mega Man...
http://www.8bitfan.info/
FF4 Ultima Discord: https://discord.gg/4MqjwJt

chillyfeez

If their critical was already zeroed out, then Grimoire's fix won't undo that. The zeroed out crit percentage is already written to your save file. This fix will only stop the game from messing with an as-yet unadulterated character (you'd have to start a new game).
Ongoing project: "Final Fantasy IV: A Threat From Within"

Latest Demo

8.bit.fan

Ahhh...that makes sense. Thanks! :)

Ok cool. I guess once we can confirm this also fixes the autobattle issue then we should be good to go, yeah? ...let's see if I have a save just before Tellah vs Edward...
In the year of 200X, a super robot named Mega Man...
http://www.8bitfan.info/
FF4 Ultima Discord: https://discord.gg/4MqjwJt

Grimoire LD

Yeah, the other bits appear to be completely unused. There is a check I have located for Long Range, but that is it. As Chillyfeez says Magnetism is probably called in Cave Magnes, but bits 1-4 look to go unused. Well that is good news if a hacker ever wanted to add a little more pizzazz to weapons at some point. A little disappointing though to see remnants of an unused plan for some weapons. Unfortunately the weapons they are attached to give little sense as to what their original plans may have been.

8.bit.fan

Ok tested after the Tellah Edward autobattle and critical appears to be gone. I did about 20 battles afterwards and no critical from Cecil at all.
In the year of 200X, a super robot named Mega Man...
http://www.8bitfan.info/
FF4 Ultima Discord: https://discord.gg/4MqjwJt

Grimoire LD

Could you send me your save file? I can clarify that in an instant.