Romhacking.net

Romhacking => ROM Hacking Discussion => Topic started by: 8.bit.fan on November 15, 2018, 03:12:31 am

Title: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: 8.bit.fan on November 15, 2018, 03:12:31 am
Hi Everyone!

So lately I've been reading up on and learning more about FF4's mechanics and algorithms, and one of the bugs I've noticed that still hasn't been addressed is the Critical Hit bug that causes players to PERMANENTLY lose the ability to do critical hits in the game! Crazy!

So, has anyone attempted to fix this critical(pun intended) bug for the game? It seems that the different ways that a player could lose the ability for good is just crazy and would be nice to have a fix for it.

Here are some info that I found on this issue:

"Some weapons prevent critical hits from occurring at all, and there's a bug where this bit is not unset when the weapon is removed."
https://gamefaqs.gamespot.com/snes/588330-final-fantasy-iv/faqs/54945

"Lose Critical Attack Ability: There are two ways to lose critical attack ability. The first is to be in the group and be in a position where in the next "auto-fight" (such as when Tellah fights Edward or Cecil fights Kain) the character's spot is not taken up by one of the NPC fighters. Meaning that in the case where Golbez and FuSoYa are fighting against Zemus, if there is a character on the team that still has crit, he can keep his critical attack by being in the same position as either one of those characters. Or he would lose it if he was in a different position. However, it was later also discovered that the characters that aren't in the "auto-fight" will retain critical attacks IF and only if the group on the right dies.

The second way to lose critical attack ability is to be dead when a fight starts. In both these cases there is no way to regain critical strike ability. Not by saving and reseting the game, powering off, sleeping in an inn, leaving the party, or any other number of ways you could think of. The ability to critical strike is lost forever if either of these conditions are met."
http://tasvideos.org/2033S.html

http://ziggyny.blogspot.com/2012/01/final-fantasy-iv-bugs.html
https://gamefaqs.gamespot.com/boards/522596-final-fantasy-ii/59917210

Does anyone have any idea on how the bug can be fixed?

Cheers!  :beer:

8-bit fan
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on November 18, 2018, 07:10:59 am
Never knew this bug existed.
I spent a lot of time researching how to fuck with FFIV, but not much on how to fix it.
People on the slick forum used to reference various bugs regularly and I would just kinda smile and nod.
I'm a bit surprised it was never addressed. There are a lot of bugfix patches out there for ffiv...
That being said, given a complete list of instances that trigger the bug, I'm sure I could create a patch (or isolate a way) to fix it.
Do those links provided in the OP list all of the triggers for the bug?
Might take a bit of time. I work retail, and it is now officially Thanksgiving week, which means I'm about to spend about a month and a half exhausted.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: 8.bit.fan on November 19, 2018, 01:45:08 am
Never knew this bug existed.
I spent a lot of time researching how to fuck with FFIV, but not much on how to fix it.
People on the slick forum used to reference various bugs regularly and I would just kinda smile and nod.
I'm a bit surprised it was never addressed. There are a lot of bugfix patches out there for ffiv...
That being said, given a complete list of instances that trigger the bug, I'm sure I could create a patch (or isolate a way) to fix it.
Do those links provided in the OP list all of the triggers for the bug?
Might take a bit of time. I work retail, and it is now officially Thanksgiving week, which means I'm about to spend about a month and a half exhausted.
Hey chillyfeez!
If you're capable and up for it that would be tremendous!!
But seeing that you're busy with work so no worries...just whenever you're feeling up for it! :)

To be honest, the instances that are mentioned in the links above are somewhat confusing to me. On one of the scenarios, a character would have to be in the same slot as the character of the auto battle, but that's impossible because the character in the auto battle would be in the same slot as when he/she was in your party. For example, in the Edward vs Tellah fight, Tellah is in the same slot as when he was in your party, so none of your other party members can be in the same slot! So...I don't get it. What do you think about this?

As far as an exhaustive list of auto battles, I think I can get that for you off of ff4kster if you need. Let me know! :)

Cheers! :beer:
8-bit fan
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on November 19, 2018, 09:20:28 am
Well, I can get a list of all of the autobattles, too, but does it ONLY happen during autobattles? Your OP seemed to indicate there are a bunch of different ways it can occur.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: 8.bit.fan on November 20, 2018, 12:23:46 am
Well, I can get a list of all of the autobattles, too, but does it ONLY happen during autobattles? Your OP seemed to indicate there are a bunch of different ways it can occur.
Think another way to permanently lose ability to critical is to equip a weapon that has the 'no critical' bit, once you do you lose the ability to critical even if you swap the weapon back to one that can critical. So for example - Adult Rydia rejoins the party with the whip equipped, which has the 'no critical' bit, so no matter what Adult Rydia can never do critical. Another example is if Cecil still has the ability to critical at endgame, if you equip him with the Ragnarok, he will permanently lose the ability to critical because the Ragnarok has the 'no critical' bit.

November 20, 2018, 12:25:31 am - (Auto Merged - Double Posts are not allowed before 7 days.)
Oh and another way to permanently lose the critical ability is if a character is dead at the start of a battle. So for example, if Edge is killed in a battle, and you don't revive him before the start of the next battle, he'll lose the ability to critical permanently.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on November 20, 2018, 10:33:27 am
Hmm... based on the varied ways the "bug" can occur, it is likely the product of three separate coding oversights, based primarily on the fact that the character's critical hit percentage is stored in the character record in RAM and is not supposed to ever change. This, it is loaded from ROM when the character first joins, but that byte of ROM is never referenced again.
Come to think of it, I'll bet all subsequent entries in the final fantasy series avoided a similar issue by tying critical hit percentage to the weapon instead of the character.

So okay, when I get a chance I'll look into figuring out exactly when the percentage gets zeroed out (that is, isolate the exact time the bugs occur). Then we can work on fixing it/ them.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on November 21, 2018, 01:31:09 am
I looked, heaven knows, I looked. In the character's stats there is a Critical Hit Byte which is never deactivated. It is dependent on an initial value, then depending on the weapon's strength (then if you have two weapons it x4) or Bow and Arrow the value changes, but it is never set to 0. I could not find what really caused this in the programming. I am also still a little unsure how accurate all of those "Critical Hit Lost" issues are. I know that it is related to an unknown weapon bit, but I cannot say more beyond that.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on November 21, 2018, 09:55:17 am
Oh, so the character's critical byte is never zeroed out at all?

Interesing.

Something must change in SRAM somewhere... Maybe setting a breakpoint to a particular weapon' s byte that contains the "No critical" bit then equipping only that weapon...

Is the bit that we're assuming is the "no critical" bit the unknown bit 1 here, 8bit?
http://rb.thundaga.com/data/weapon_bits.txt
That is, does that look like an accurate list of the weapons that permanently disable criticals?

I haven't had a chance to do anything yet, but the mystery is getting intriguing.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on November 21, 2018, 03:57:50 pm
To my recollection it is Bit1 that is responsible for it, yes. It's a shame that Slickproductions appears to be down permanently, thankfully I had the good sense to archive my hacking topic (until page 23) and my AI Indexes, let's see here...

What makes this glitch so difficult to pindown is if you hack the equipment in, there is no problem. Equip/Dequip it all still works fine. The Silence Staff addsx2 Crit Chance along with all other normal weapon types. So... I don't know what is happening there.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: 8.bit.fan on November 21, 2018, 05:15:23 pm
Hey chillyfeez and Grimoire LD!

So I did some testing and yes, bit 1 is the one responsible for no-critical on a weapon. I added bit 1 to many of the endgame ultimate weapons for my hack because I thought it had 'ultimate weapon properties' as Ragnarok has it also. Silly me. So, after realizing this whole no-critical thing, I updated my hack by removing that bit to the weapons and lo, Edge started doing critical with the Ultima Weapon! So, perhaps that information IS WRONG about permanently losing critical if you equip a weapon that has the no-critical bit 1?
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on November 21, 2018, 05:39:47 pm
For the record, Lenophis says slick isn't down permanently, just indefinitely.
Apparently the server it's hosted on is an old and terrible machine and he is working slowly but surely on transferring the db to something more viable for the 21st century.
This all from a recent discussion on the slick productions discord channel.

When you say, "if you hack the equipment in..." Do you mean that if I use ff4kster to create a new weapon that has that bit, that new weapon won't permanently disable criticals, but weapons that have the bit set in vanilla will do so?
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on November 21, 2018, 07:12:15 pm
I meant a clean FFII rom with no changes. I used Rydia to test this, with geiger I switched a Rod in the inventory for the Silence Staff and equipped it, saw it increased Critical Hit chance by 1 (perhaps it was x2, but Rydia starts with a 1% crit chance.) I changed the critical hit chance manually in battle and there were no issues to be found.

I am glad to know that Slick is not down permanently and that Lenophis is still looking for a solution to the problem. I did not know there was a discord. Things have been very busy (I am only posting because I don't have school) but it is good to know all the same. We really do have a lot to learn from FFIV:Enterprise in terms of where we take the future of FFIV hacking.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on November 21, 2018, 11:57:42 pm
Wait, what's FFIV:Enterprise?
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: vivify93 on November 22, 2018, 12:39:09 am
I assume he means FFIV: Free Enterprise, a randomizer that gives you the Enterprise to start with. Lots of strides in FFIV hacking have been made thanks to them as well as the Lunarian Shuffle; I know that there's a hack in the works for detailed equip menu info, designed for Lunarian Shuffle.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on November 22, 2018, 08:38:02 am
Oh yeah, right. I do know of Free Enterprise.
I don't think I'm familiar with Lunarian shuffle.
Detailed equip menu would be pretty sweet. I did this once as a way to address the issue of no in-game equipment info:
https://youtu.be/mKXhlxPgvLA

... Sorry about hijacking your thread, 8bit  :-[
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: 8.bit.fan on November 23, 2018, 02:56:57 pm
No worries Chillyfeez ;)
I'm actually enjoying all the different discussions on the game :)
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Rodimus Primal on November 23, 2018, 03:07:19 pm
Interesting. So if it happens to be weapons that are set to Bit 1, then is it only THOSE weapons that cannot do critical hits? Perhaps it has to do with the coding of just that Bit.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Swordmaster on November 23, 2018, 08:54:43 pm
What I am about to say could very well be incorrect, as human memory is notoriously unreliable.  However, if I am recalling correctly, there are a few minor differences between an untouched FF2US ROM and one that has been loaded into FF4kster.  The only thing I can recall at the moment, however, is the behavior of the Cockatrice Summon.  In an untouched ROM, it only petrifies.  After being loaded into FF4kster, it causes 1 HP of damage in addition to petrification.  It's been a long time since I've played the untouched ROM, so I could just be misremembering.  My point, though, is that FF4kster may need to be ruled out as the culprit for the Critical Hit Bug.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on November 23, 2018, 11:38:44 pm
You are right that ff4kster makes changes to the ROM even if the user makes no edits.

However...

This topic on gamefaqs (https://gamefaqs.gamespot.com/boards/522596-final-fantasy-ii/59917210) is from 2011. Pinkpuff didn't start working on ff4kster until 2012.
So the bug definitely is not related to or caused by ff4kster.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Swordmaster on November 24, 2018, 06:05:58 pm
Ah, sou desu ka...  Thanks, chillyfeez.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: 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.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: 8.bit.fan on November 29, 2018, 03:09:21 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.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on November 29, 2018, 04:49:49 pm
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.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: 8.bit.fan on November 29, 2018, 05:57:07 pm
Sounds great chillyfeez :)

Btw, where in the SRAM is the critical bit located for each characters?
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on November 29, 2018, 06:08:16 pm
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?

Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: 8.bit.fan on November 29, 2018, 06:48:22 pm
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! :)
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on November 29, 2018, 06:56:29 pm
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)
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: 8.bit.fan on November 29, 2018, 07:57:11 pm
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...
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on November 29, 2018, 10:38:01 pm
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?
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on November 29, 2018, 10:42:38 pm
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.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: 8.bit.fan on November 29, 2018, 11:02:09 pm
Wait, just tried changing 0x194EF to 00 and the game glitches when I start...
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on November 29, 2018, 11:37:20 pm
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.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on November 29, 2018, 11:44:30 pm
Bah! I'm sorry. It is 0x194F0, sorry about that.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on November 29, 2018, 11:45:09 pm
haha - I JUST noticed that, too! I was about to edit my post...
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: 8.bit.fan on November 30, 2018, 12:16:24 am
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...
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on November 30, 2018, 12:56:59 am
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).
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: 8.bit.fan on November 30, 2018, 01:05:02 am
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...
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on November 30, 2018, 01:10:51 am
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.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: 8.bit.fan on November 30, 2018, 01:37:45 am
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.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on November 30, 2018, 01:40:07 am
Could you send me your save file? I can clarify that in an instant.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: 8.bit.fan on November 30, 2018, 01:52:55 am
Sure thing:
http://www.8bitfan.info/files/Final%20Fantasy%20IV%20-%20Ultima%20v1.10a%20-%20try%20fix%20critical.srm

It's the second slot.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on November 30, 2018, 02:09:15 am
Thanks, let's see here...

Yep, crit is dead for both Cecil and Rydia. I take it that Tellah was in that last slot that Edward is now currently in? (As he normally tends to be) well, this might be trickier than I thought... its too late to look into it now, but at least I know I solved it for the dead-in-next-battle problem.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: 8.bit.fan on November 30, 2018, 02:14:08 am
Yup, Edward is in Tellah's spot.
Hmmm...
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on November 30, 2018, 04:41:32 pm
Got it!

So, long story short, if The character's ID/Handedness is 00 at the start of a battle (As inactive characters' will be during an autobattle), the game skips copying their basic critical hit percentage (7E:202D,x) into their effective critical hit percentage (7E:2041,x). The number at 2041 gets copied back to 202D, which gets copied back to 102D regardless at the end of the battle. So if 2041 is never changed from zero, then that zero gets copied into the permanent character record. So, within the instructions of how to handle a blanked-out character, there is a JMP instruction that jumps right past what we want:
Code: [Select]
$03/94E7 4C 70 95    JMP $9570  [$03:9570]   What we want to do is jump to the point where that value is copied into 2041, so we just change the "70" at 394E8 to a "23." The end result is this:
Code: [Select]
$03/94E7 4C 23 95    JMP $9523  [$00:9523]   Anyway, that will fix our issue with inactive characters losing their critical.
In regular ROM (unheadered), this change will be at 01/94E8.
 :thumbsup:
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on November 30, 2018, 04:56:50 pm
Grand work Chillyfeez! I almost bet that these weird "death-start-of-battle" and Auto-battle glitch killed Crits long before anyone really noticed and as a result they came up with alternative reasons why that may have happened with more reasonable ideas like an unknown weapon bit.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on November 30, 2018, 05:15:35 pm
Yeah, Rydia's crit would be permanently killed right after the octomamm battle. If nothing else, most of the rest of the final party would lose it during edge's debut.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: 8.bit.fan on November 30, 2018, 05:20:43 pm
Amazing work Chillyfeez!!  :D :thumbsup:

So, please bear with me as I'm not very proficient with hex, do I only need to make the change you just posted by changing the "70" at 394E8 to a "23"? Or would I need to also make the change posted by Grimoire LD earlier by changing 0x194F0 to 00?

Any pointers would be much appreciated!! :)

Oh and also, this wouldn't 'revive' a critical-dead characters right? I'd have to start a new game?

This is amazing! You should submit a patch to the site!  :thumbsup:
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on November 30, 2018, 05:57:49 pm
I think you'd have to do both Grimoire's thing and my thing to fix both issues (he fixed start-dead, I fixed blanked-during-autobattle). But yeah, changing the one byte for each fix should do the trick. For all known critical-killing situations.

As before, you will have to start a new game to enjoy the benefits of this fix.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: 8.bit.fan on November 30, 2018, 06:01:38 pm
Awesome and thanks chillyfeez!! :D

Will check it out when I get the chance tonight or this weekend.

Will you and/or Grimoire LD submit a patch for the fix? Would be a great addition to all the other bug fix patches for FF4 already. ;)
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on November 30, 2018, 06:20:11 pm
As it's only two isolated bytes, I don't think I'd make a patch just for that. It could easily be bundled into an existing bug fix patch though.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: 8.bit.fan on December 04, 2018, 01:20:49 pm
Ok just got a chance to test this out quickly last night.
I went all the way up to Tellah vs Edward again and I was able to critical with Cecil afterwards! So looks like the autobattle issue is fixed as well! :)

I'll do more extensive testing later when I have the time...

Thanks again for the great work chillyfeez and Grimoire LD!! :D

Cheers!! :beer:
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: vivify93 on December 04, 2018, 01:30:13 pm
I read all the way through the thread, and I'm a little confused as to what bytes to change. Do I need to do this in ASM at all? I'd like to implement this in Project II.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: 8.bit.fan on December 04, 2018, 04:19:30 pm
Hey vivify93! :)

Yes, you'll need to make the 2 changes in a HEX editor.
Let me know if you need help. Feel free to send me the rom file then I can edit and send it back to you. :)

Cheers! :beer:
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on December 04, 2018, 04:30:07 pm
I read all the way through the thread, and I'm a little confused as to what bytes to change. Do I need to do this in ASM at all? I'd like to implement this in Project II.

You'll need to open your ROM (no header) in a hex editor and change the following two bytes:

0194E8
change from "70" to "23"

0194F0
change from "C0" to "00"

Changing these two bytes is changing ASM. When you edit a ROM you're either editing data or assembly. When you edit the text, or a graphical tile, or a tile arrangement within a town, or character stats, etc., those are data edits. Changing the way the console interprets those data is changing assembly. This happens to be the latter.
 :thumbsup:
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: vivify93 on December 04, 2018, 10:04:48 pm
Thanks Chillyfeez! I'll launch a new version of Project II in a bit. Does Rodimus know about this fix btw?
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on December 04, 2018, 11:35:54 pm
I think? I posted on the namingway topic that we had been working on this and had figured it out. He said he had seen but was waiting to be sure it worked. I assured him that it would, but the conversation sort of stopped there.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: POWCo-op on December 05, 2018, 03:39:56 am
Even though it's only two bytes, I think it affects so many people that I would be hugely appreciative if someone made a patch for this.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: vivify93 on December 05, 2018, 09:17:48 am
If Chillyfeez isn't really feelin' it, I could make the patch and credit him?
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: 8.bit.fan on December 05, 2018, 11:44:17 am
Credit Grimoire LD also for fixing the first part of the bug. :)
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on December 05, 2018, 02:10:53 pm
That's fine. If there's demand for it there's no need to withhold a patch. Grimoire definitely deserves equal credit.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: vivify93 on December 05, 2018, 02:11:42 pm
Alright, I think I have a rough draft of the readme started... Anyone have the time to look over it? I wrote things down as I understood them.

Final Fantasy IV - Critical Hit Bug Fix

by Grimoire LD and chillyfeez

No ownership is claimed by the two mod authors over Final Fantasy IV or the franchise from which it originates. Please credit the authors if you use this fix in your mod.

------------

There are several possible ways for a character to permanently lose their ability to perform critical hits.

"Some weapons prevent critical hits from occurring at all, and there's a bug where this bit is not unset when the weapon is removed."

(source: https://gamefaqs.gamespot.com/snes/588330-final-fantasy-iv/faqs/54945)

"Lose Critical Attack Ability: There are two ways to lose critical attack ability. The first is to be in the group and be in a position where in the next 'auto-fight' (such as when Tellah fights Edward or Cecil fights Kain) the character's spot is not taken up by one of the NPC fighters. Meaning that in the case where Golbez and FuSoYa are fighting against Zemus, if there is a character on the team that still has crit, he can keep his critical attack by being in the same position as either one of those characters. Or he would lose it if he was in a different position. However, it was later also discovered that the characters that aren't in the 'auto-fight' will retain critical attacks IF and only if the group on the right dies.

The second way to lose critical attack ability is to be dead when a fight starts. In both these cases there is no way to regain critical strike ability. Not by saving and reseting the game, powering off, sleeping in an inn, leaving the party, or any other number of ways you could think of. The ability to critical strike is lost forever if either of these conditions are met."

(source: http://tasvideos.org/2033S.html)

This patch fixes the incorrect behavior by:
1. Removing the restriction on critical hits in auto-fights
2. Continuing to write critical hit data for teammates who are incapacitated when a battle begins

Unfortunately, since this data is saved to your save file, there's no way for existing saves to recover lost critical hit abilities.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: POWCo-op on December 05, 2018, 04:08:52 pm
In the last line, you could say written to your save file to avoid repetition. This patch will make playing FF4 more enjoyable!
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on December 05, 2018, 05:09:13 pm
Afaik, criticals aren't restricted in autobattles, the game just skips over writing critical percentages for characters who don't participate in them (which causes the permanent loss).
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: vivify93 on December 05, 2018, 09:46:44 pm
here's the updated end of the readme:

This patch fixes the incorrect behavior by:
1. Writing critical hit percentages for characters who aren't participating in auto-battles, instead of skipping them like before
2. Continuing to write critical hit data for teammates who are incapacitated when a battle begins

Unfortunately, since this data is written to your save file, there's no way for existing saves to recover lost critical hit abilities. Players will have to start a new game in order for the fix to work.


btw does this fix weapons with the "no crit" byte set making characters lose their crit ability?
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on December 05, 2018, 10:20:03 pm
To our knowledge... there is no such thing. Chillyfeez and I have both tested this, I by doing little more than increasing Natural critical hit rate, equipping those "critical hit-less" weapons did not prevent critical hits at all. It is our thought that due to the easy loss of crits through being dead or Not being in the same spot as the fighter in an auto-battle, may have caused these rumors to appear.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: vivify93 on December 06, 2018, 09:04:38 pm
alright, awesome. submitted to the site. i just need to update credits and add chillyfeez as a co-author

edit - it's live on the site. FFII US v1.1 only, headered or unheadered. https://www.romhacking.net/hacks/4256/ submitted an update with chillyfeez as a co-author, and submitted credits.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Rodimus Primal on December 07, 2018, 11:15:04 pm
alright, awesome. submitted to the site. i just need to update credits and add chillyfeez as a co-author

edit - it's live on the site. FFII US v1.1 only, headered or unheadered. https://www.romhacking.net/hacks/4256/ submitted an update with chillyfeez as a co-author, and submitted credits.

Excellent! Glad the fix is simple enough and it works. I'm going to add it to the next update of Namingway Edition. Are you doing so for Project II?

Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: vivify93 on December 08, 2018, 01:47:54 pm
Yes, I am! Before I make another big update, though, I was waiting to see if Crow was going to release a version of his equipment screen mod for vanilla FFIV, and see if it's compatible with it.

(https://i.imgur.com/VC0DypA.png)

If it is, it's definitely going on Project II as well!  :D
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on December 08, 2018, 10:50:44 pm
Yeah, that is an awesome thing.
If he does make a patch for vanilla, though, be careful. There's no doubt some custom assembly involved in drawing those windows, and that means there's a chance it would clash with User Options.
If that ends up being the case, I might be able to move some User Options stuff somewhere else in ROM for you.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: vivify93 on December 08, 2018, 11:06:46 pm
That's very true. We'll have to play it by ear. Thank you!
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: teahouser on December 09, 2018, 09:12:09 pm
This was a very interesting thread to follow. You were able to pinpoint the bug in the code and fix the problem that nobody has addressed in decades, very impressive.

I was going to do a playthrough of ff IV soon,can I use this patch on an already patched Namingway version?
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: vivify93 on December 09, 2018, 09:19:34 pm
yes you can!
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on December 09, 2018, 11:01:39 pm
This was a very interesting thread to follow. You were able to pinpoint the bug in the code and fix the problem that nobody has addressed in decades, very impressive.

Grimoire LD and I spent the better part of three years dissecting FFIV. The most remarkable part of all this is probably that we hadn't addressed the issue sooner.
;)
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Crow! on December 10, 2018, 03:33:56 pm
Regarding my stat screen mod shown above, it does in fact use almost all of the unused data immediately after the menu display data - 0xde68 through 0xe2ff gets used.  Hacks that add new options to the customization screen would likely have used that particular ROM region, which would create a conflict.

When I eventually release that mod for public use (atm it's a The Lunarian Shuffle exclusive), I'll be releasing the ASM as well as the raw data, so someone who needs an option screen hack as well and knows what they're doing could offload some of the subroutines and data to another section of the ROM - expanding the ROM by one bank would work, if nothing else.

In other news, I think I'll add an option to fix various stat glitches, including this one, the permanence of Long Range (looks like Dragoon ZERO already tackled this one), the Adamant armor permanent weaknesses glitch,  and the failure of enemies to load the evasion and magic evasion they are supposed to have.

-------

Edit: turns out the Adamant armor problem wasn't too hard to fix.

Code: [Select]
Here is the root of the Adamant unequipping problem.  It loads extreme resistances, and if it finds any, it sets the opposites, plus the "extreme" flag, into the extreme weaknesses byte.
However, the game does nothing whatsoever if it finds no extreme weaknesses, thus leaving the old values there!
$03/9a78 ldy #$0026
$03/9a7b lda ($80),y << Loads extreme resistances
$03/9a7d sta $a9
$03/9a7f jsr $9da8 << This subroutine picks opposite elements: Fire and Ice are swapped, as are Holy and Darkness.
$03/9a82 beq $9a8b << This will fire if there was no Holy, Dark, Ice, or Fire stuff in the resistances
$03/9a84 ldy #$0021
$03/9a87 ora #$80 << Throw in an "extreme" flag.  I actually don't know if this does anything.
$03/9a89 sta ($80),y << Here is where it gets set.
$03/9a8b ldy #$0022 << Destination of the branch; goes on to edit other stuff.

So, in cases where beq fires, what we want to do is put a 0 into the extreme weakness flag.  This can be achieved by simply rearranging the commands as follows:

ldy #$0026
lda ($80),y
sta $a9
ldy #$0021
jsr $9da8
beq $+WriteExtremeWeakness
ora #$80
WriteExtremeWeakness:
sta ($80),y
ldy #$0022

Subroutine $9da8 does not touch Y, so loading Y earlier is fine.  The only thing the game now skips when there are no extreme weaknesses to write is OR-ing in the "extremeness" flag.

TL;DR: apply this code to 0x19a7f on an unheadered, v1.1 ROM:
A0 21 00 20 A8 9D F0 02 09 80 91 80

--------

Edit 2: And while we're at it, making enemy evasion work wasn't too hard once I figured out enough about what the game was actually doing.

NOTE: This might make the game a lot harder!  I'm not really sure just how big the impact of enemies having their intended evasion is.  Future releases of the game consistently chose not to restore this evasion, which might suggest that it would have been overbearing.

Code: [Select]
The culprit this time appears to be a simple typo by Square in the battle loading routine.  Essentially the same typo is made in the physical as well as magical defense loading routines.  Here's the erroneous physical one:
$03/90ce lda $291c
$03/90d1 sta $2028,x
$03/90d4 lda $291d
$03/90d7 sta $202a,x  << Oops!
$03/90da lda $291e
$03/90dd sta $202a,x

And here's magic evade:
$03/90e6 lda $291c
$03/90e9 sta $2022,x
$03/90ec lda $291d
$03/90ef sta $2024,x  << Oops!
$03/90f2 lda $291e
$03/90f5 sta $2024,x

The byte order goes evade multiplier, evade rate, then defense.  The middle byte is being written on the last byte, then immediately overwritten by the correct last byte, leaving every enemy without its proper evade rate, although they do have the correct evade multiplier.

The code we want is:
$03/90d7 sta $2029,x
...
$03/90ef sta $2023,x

The fix to this, then is only two bytes.  On an unheadered v1.1 US ROM, the bytes to change are:
0x190d8 = 0x29
0x190f0 = 0x23
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on December 11, 2018, 09:49:44 am
I think we looked at enemy evasion once on slick and after playing with it a bit collectively decided that it was better off left alone. Harder, yes, but not in a fun challenge way. In a simply needlessly frustrating way.

User Options would most likely move to a new place in ROM more easily than Crow's equipment screen. It's just a collection of relatively simple tweaks that in most cases are just a matter of a single subroutine jump (except the ATB counter - that's a frigging mess).
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: 8.bit.fan on December 12, 2018, 07:56:51 pm
Just want to say great work again on fixing this bug chillyfeez and Grimoire!  :woot!:

And that inventory display is amazing Crow!
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on December 13, 2018, 09:52:57 pm
I must say I exclaimed out loud "That is so cool!" When I saw your custom equipment menu. Though I wonder what those values next to the character's portrait mean... oh they're stats, brilliant! I look forward to trying that out in time.

It is such a shame that Slickproductions is still down. Well, the Adamant Armor fix is here as the only patch I've submitted, but you have a cleaner code to fix this.

As Chillyfeez mentioned I fixed up evasion long ago. I was never of the opinion as Chillyfeez and Deathlike2 were that it made things needlessly frustrating. I felt it was something they meant to have, as all strategy guides from early on mentioned these evasion chances. It is also the only reason for enemies to have Defense Multipliers because in the base game enemy Defense is ridiculously low, aside from Flans.

It is fixed throughout Combat Boost and while it makes a different it makes the game a lot less focused on just straight-attacking without strategy, Since Evasion Chance is by multiplier so say... the turtles in Antlion cave have a 90% chance to evade. That means they will only evade the first multiplier while the second one will strike through (as long as that hit in hit calculation) decreasing the damage roughly by half.



Regarding my stat screen mod shown above, it does in fact use almost all of the unused data immediately after the menu display data - 0xde68 through 0xe2ff gets used.  Hacks that add new options to the customization screen would likely have used that particular ROM region, which would create a conflict.

When I eventually release that mod for public use (atm it's a The Lunarian Shuffle exclusive), I'll be releasing the ASM as well as the raw data, so someone who needs an option screen hack as well and knows what they're doing could offload some of the subroutines and data to another section of the ROM - expanding the ROM by one bank would work, if nothing else.

In other news, I think I'll add an option to fix various stat glitches, including this one, the permanence of Long Range (looks like Dragoon ZERO already tackled this one), the Adamant armor permanent weaknesses glitch,  and the failure of enemies to load the evasion and magic evasion they are supposed to have.

-------

Edit: turns out the Adamant armor problem wasn't too hard to fix.

Code: [Select]
Here is the root of the Adamant unequipping problem.  It loads extreme resistances, and if it finds any, it sets the opposites, plus the "extreme" flag, into the extreme weaknesses byte.
However, the game does nothing whatsoever if it finds no extreme weaknesses, thus leaving the old values there!
$03/9a78 ldy #$0026
$03/9a7b lda ($80),y << Loads extreme resistances
$03/9a7d sta $a9
$03/9a7f jsr $9da8 << This subroutine picks opposite elements: Fire and Ice are swapped, as are Holy and Darkness.
$03/9a82 beq $9a8b << This will fire if there was no Holy, Dark, Ice, or Fire stuff in the resistances
$03/9a84 ldy #$0021
$03/9a87 ora #$80 << Throw in an "extreme" flag.  I actually don't know if this does anything.
$03/9a89 sta ($80),y << Here is where it gets set.
$03/9a8b ldy #$0022 << Destination of the branch; goes on to edit other stuff.

So, in cases where beq fires, what we want to do is put a 0 into the extreme weakness flag.  This can be achieved by simply rearranging the commands as follows:

ldy #$0026
lda ($80),y
sta $a9
ldy #$0021
jsr $9da8
beq $+WriteExtremeWeakness
ora #$80
WriteExtremeWeakness:
sta ($80),y
ldy #$0022

Subroutine $9da8 does not touch Y, so loading Y earlier is fine.  The only thing the game now skips when there are no extreme weaknesses to write is OR-ing in the "extremeness" flag.

TL;DR: apply this code to 0x19a7f on an unheadered, v1.1 ROM:
A0 21 00 20 A8 9D F0 02 09 80 91 80

--------

Edit 2: And while we're at it, making enemy evasion work wasn't too hard once I figured out enough about what the game was actually doing.

NOTE: This might make the game a lot harder!  I'm not really sure just how big the impact of enemies having their intended evasion is.  Future releases of the game consistently chose not to restore this evasion, which might suggest that it would have been overbearing.

Code: [Select]
The culprit this time appears to be a simple typo by Square in the battle loading routine.  Essentially the same typo is made in the physical as well as magical defense loading routines.  Here's the erroneous physical one:
$03/90ce lda $291c
$03/90d1 sta $2028,x
$03/90d4 lda $291d
$03/90d7 sta $202a,x  << Oops!
$03/90da lda $291e
$03/90dd sta $202a,x

And here's magic evade:
$03/90e6 lda $291c
$03/90e9 sta $2022,x
$03/90ec lda $291d
$03/90ef sta $2024,x  << Oops!
$03/90f2 lda $291e
$03/90f5 sta $2024,x

The byte order goes evade multiplier, evade rate, then defense.  The middle byte is being written on the last byte, then immediately overwritten by the correct last byte, leaving every enemy without its proper evade rate, although they do have the correct evade multiplier.

The code we want is:
$03/90d7 sta $2029,x
...
$03/90ef sta $2023,x

The fix to this, then is only two bytes.  On an unheadered v1.1 US ROM, the bytes to change are:
0x190d8 = 0x29
0x190f0 = 0x23
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on December 14, 2018, 12:27:27 pm
I guess "needlessly frustrating" is an oversimplification.
I guess my real feeling is that it just makes the game a lot more tedious. My biggest problem with FFIV has always been the pacing of the battle system. If you turn battle speed up too high, it's damn near impossible (later in the game, unless you grind). If you turn the speed down, it's easier to formulate an appropriate strategy for each battle, but things take for-freaking-ever. Turning on enemy evasion, while it does force more strategizing, increases the "forever" -ness of the battles.
I also am of the opinion that one should not do anything that compromises the effect of melee combat without also "fixing" either the psyche spell or the price of ethers.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Crow! on December 16, 2018, 11:44:17 am
I tried out evasion and decided to ditch it.  My issue was that the vanilla numbers for evasion really, really punish you for trying to use Magic against bosses.  My best guess is that they were noticing bosses were taking more hits from e.g. Slow than they were expecting given the evasion numbers they had put in, and rather than realizing their evasion didn't work, they tried jacking up just the MEvade numbers to about 4x what would make logical sense in an effort to make it do what they expected.

Net result is that early game bosses have about 6x as much MEvade as your end-game mages do, and it goes up from there.  Physical evasion, meanwhile, is generally slightly behind what your own shield wielding characters have at any stage.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on December 16, 2018, 05:20:21 pm
Which is all especially weird considering they could have just made certain spells (like slow,if they wanted) not work on bnosses at all.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on December 16, 2018, 10:33:00 pm
Haha! That is quite a theory. So you think that the current issue with M. Evade is because the developers didn't Actually know that their system had this bug, so they just kept increasing the numbers expecting some sort of change? That is an intriguing idea and may explain why M. Evade does seem higher across the board.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Giud on April 27, 2019, 09:11:57 am
Been messing around with FF IV (GBA) lately and just stumbled upon this thread. It's great how you guys were able to solve this issue, but what if I wanted to actually disable criticals in the GBA game? I'm not sure how they're handled in this version of the game, maybe some of the FF IV experts could chime in on that. 
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on April 28, 2019, 05:42:30 am
In the original FFIV each character had their own hidden Critical Hit Ratio, some characters got less, while others got more and this was either x2 or x4 depending on whether they had one or two weapons. Cid, for instance, had the highest Critical Hit Ratio. If you wanted to eliminate Crits you would set all character's Critical Hit Ratio to 0 as 0 x anything still equals 0.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Giud on April 28, 2019, 06:48:28 am
In the original FFIV each character had their own hidden Critical Hit Ratio, some characters got less, while others got more and this was either x2 or x4 depending on whether they had one or two weapons. Cid, for instance, had the highest Critical Hit Ratio. If you wanted to eliminate Crits you would set all character's Critical Hit Ratio to 0 as 0 x anything still equals 0.

Hm, is this critical hit ratio stored together with the other character stats or is it stored somewhere else?
On the european GBA version, character stats begin at F5D90 and as far as I can tell, there's no critical hit stat. Maybe I just missed it. Then again, maybe they changed the way how criticals work is this version of the game.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on April 28, 2019, 06:58:31 am
I really wish I hadn't lost my notes... as far as I recall it should be x1D in the character stats as far as I recall, at least for the SNES version. What is that listed in the GBA version?
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Giud on April 28, 2019, 07:12:18 am
I really wish I hadn't lost my notes... as far as I recall it should be x1D in the character stats as far as I recall, at least for the SNES version. What is that listed in the GBA version?

Not sure, I found that GBA offset by searching the starting character experience numbers. The character stats structure on GBA goes like this:
Byte 0: Initial Level
Byte 1: Hand (0x00 none?, 0x01 = Right Handed, 0x02 = Left Handed, 0x03 = Ambidextrous)
Byte 2-3: HP
Byte 4-5: MP
Byte 6: STR
Byte 7: Speed/Agility
Byte 8: Stamina
Byte 9: Intelligence
Byte 10: Wisdom
Byte 11: ????
Byte 12-15: XP
Byte 16-17: Item on Right Hand
Byte 18-19: Total of item on Right Hand
Byte 20-21: Item on Left Hand
Byte 22-23: Total of item on Left Hand
Byte 26-27: Item on Body
Byte 28-29: Item on arms
Byte 30: ????
Byte 31: ????
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on April 28, 2019, 07:26:23 am
It may be byte 30 or 31 on this chart then. The over 255 weapons/armor throws things off a bit from the original. For Cecil/Kain it should be a 01, you will see a higher amount when it comes to Cid.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Giud on April 28, 2019, 07:38:37 am
Ok, I'll make some changes and see if there's a difference.
EDIT: seems like both byte 30 and 31 have a value of 0.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on April 28, 2019, 07:57:12 am
Hmm, they may have changed it completely then. What is the mystery byte after stats in the GBA version?
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Giud on April 28, 2019, 08:00:12 am
That would be 0 again.
EDIT: there's also this japanese site that has the character stats http://x11.s11.xrea.com/ff4chrparam.txt (http://x11.s11.xrea.com/ff4chrparam.txt)
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on April 28, 2019, 08:12:39 am
Then they may be stored differently... that's bizarre.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Giud on April 28, 2019, 08:15:42 am
Looking at that japanese doc, it seems like the second to last column could be it. But where the heck is that byte located?
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on April 28, 2019, 08:24:07 am
Ah right, I read that wrong. Critical Hit Effect is dependent on the weapon and the Critical Hit Rate is right next to it. Is this for the GBA version?
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Giud on April 28, 2019, 08:32:59 am
Ah right, I read that wrong. Critical Hit Effect is dependent on the weapon and the Critical Hit Rate is right next to it. Is this for the GBA version?

Yep, GBA. Does that mean I would have to disable crits for each individual weapon? 
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on April 28, 2019, 08:56:01 am
Not at all. Every character has a set critical hit rate by default. If you nullify that, then that will nullify crits all together, after all 0 x 2/4 is still 0.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Giud on April 28, 2019, 09:02:12 am
Not at all. Every character has a set critical hit rate by default. If you nullify that, then that will nullify crits all together, after all 0 x 2/4 is still 0.

That's good, but the problem is locating that stat so I can change it to 0. It seems like they stored it somewhere else in the GBA version or am I way off base here?
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on April 28, 2019, 09:11:56 am
It... should be in the same place if that document is indeed referring to the GBA version.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Giud on April 28, 2019, 09:21:00 am
It... should be in the same place if that document is indeed referring to the GBA version.

Looking at that document again, it seems like that's just the attack multiplier. Is it possible that this data is stored on the save file, instead of the ROM?
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on April 28, 2019, 10:35:36 am
Last I checked a multiplier doesn't go above 16, haha. The CH should just be short for "Critical Hit".

No, it shouldn't be elsewhere, logically speaking... it's recalculated whenever you equip/dequip a weapon out of battle which means it should be in the main character stats, at least that's how it works in the original game. Maybe they did change it for some reason in this? I can't really say.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Giud on April 28, 2019, 10:52:18 am
So the critical hit rate for Cecil and Kain should be 2, for Cid it is 5, Edge 8 etc.But I don't see it where the rest of the stats are. Seems like every unknown byte is just a 0. Ugh, frustrating...

April 29, 2019, 05:16:52 am - (Auto Merged - Double Posts are not allowed before 7 days.)
Well, I wanted to see if I could find the crit modifier on the og, Snes version. Sure enough, it's right there with the rest of the stats, 102D in wram, right next to the critical hit effect. But, on the GBA they are nowhere to be seen. I don't understand why they decided to move those two around.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Lancet on May 11, 2019, 12:27:53 am
Hello, I was researching this critical hit issue and found this topic. If those who have investigated this bug are able, I have a couple of questions related more to playing the game without any fix for this bug. Also possibly worth saying is I'm actually looking at this on the Final Fantasy Chronicles port of FF4, not SNES or GBA.

Due to the auto-battle aspect of the bug, am I correct in concluding that Rydia will never be able to cause critical hits after the Tellah vs Bard auto-battle, since she can obviously never be in Tellah's slot for that battle? And that due to Edge vs. Rubicant auto-battle, only one character out of Cecil, Kain, Rosa, and Rydia* can keep their criticals? Thus, for an endgame party, only Edge and one other person could possibly have critical hits still enabled?

Second, which byte(s) exactly in character data is the one that is permanently affected by this? It seems like it is 102D and 102E that get zeroed by the dead-entering-battle effect, so are those the permanent data that are affected by this glitch?

Finally, does anyone have a convenient list of each character's actual starting critical rate for the byte(s) affected by the glitch? (Bonus question: outside of this glitch, do these permanent data on the character's base critical rate ever change?)

Any help would be much appreciated.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on May 12, 2019, 05:01:25 am
By all appearances, that seems to be the case. With weirdness like this it makes it easy to tell how the critical hit kill equipment theory came into being. People had thought it was a flaw in an unset bit, it turns out it was a flaw with the auto-battle system and the end-of-battle sequence. Much of the final team will lose their ability to use Critical Hits due to this bug.

It appears to be 202D and 202E which is then carried out of battle back to 2D and 2E and set as 00 from thereon out.

This page has the amount http://x11.s11.xrea.com/ff4chrparam.txt it's the second to last value on every line. Of note is that whenever you equip a weapon you double your chance to crit per hit, and when you equip two weapons you quadruple the chance. The reason the glitch destroys all of that is because 0 x 2 or 4 is still 0.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on May 12, 2019, 09:54:58 am
Holy cow, that website, Grimoire. So much good stuff once Google translate kicks in!
His long have you known about that?
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on May 12, 2019, 12:48:38 pm
It was only mentioned in the last page, I was shown it then. Is there more of use on the website than just the character stats then?
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on May 12, 2019, 01:41:09 pm
There's all sorts of patches, for one thing. Author claims there was an abandoned plan to have monsters run away when their level is significantly lower, and has a patch to reactivate that. Plus an atb meter. It's for ffivj, so won't patch cleanly into ffiius, but I may be able to study it and replicate.
Yeah, just take that url and clip off everything before the slash.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Lancet on May 12, 2019, 05:41:26 pm
By all appearances, that seems to be the case. With weirdness like this it makes it easy to tell how the critical hit kill equipment theory came into being. People had thought it was a flaw in an unset bit, it turns out it was a flaw with the auto-battle system and the end-of-battle sequence. Much of the final team will lose their ability to use Critical Hits due to this bug.

It appears to be 202D and 202E which is then carried out of battle back to 2D and 2E and set as 00 from thereon out.

This page has the amount http://x11.s11.xrea.com/ff4chrparam.txt it's the second to last value on every line. Of note is that whenever you equip a weapon you double your chance to crit per hit, and when you equip two weapons you quadruple the chance. The reason the glitch destroys all of that is because 0 x 2 or 4 is still 0.

What are the two different "critical" values, then? According to that table and from what I've seen in cheat engine, DK Cecil and Kain have a value of 2 for 2D and 20 for 2E. So what do those two values do exactly? Are they both related to critical hits? They're both zeroed when the battle ends if a character entered the battle KO'd.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on May 12, 2019, 10:52:32 pm
According to another document on that site, the first value is the critical hit rate, and the second value is the critical hit bonus. I'm sure the "bonus" value is part of a calculation. It would be silly late-game if Cecil's critical hits only added ~35 damage.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Grimoire LD on May 13, 2019, 06:36:54 am
How interesting, I'll check that out later. Yes, that is one of the unused formulas, in the current game the monster just dies and says, "Monster ran away". In fact, I re-added it with a "Fear" spell formula. There may have been a piece of data regarding a monster's level against the party's own, but I never found it, so there may have been some code which was glitched that failed those checks at all turns. (It's FFIV, it wouldn't surprise me).

Its a bonus based on the weapon you have equipped and it is a %buff, but Critical Hit damage is different from normal damage as it takes the normal damage, and increases it by a % of 0 to whatever the max is dependent on the weapon equipped. As memory serves Critical Hit damage % is x2 the power of the weapons, but I can't quite recall.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Lancet on May 14, 2019, 05:22:40 am
Thank you for the clarifications. It's been a big help in understanding how critical hits work. =)
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Gedankenschild on May 16, 2019, 06:20:20 pm
Wow, that Japanese site really has some interesting patches!
The ATB bar one looks nice. Would be interesting to compare the ASM of some of them to the ones done by you guys (like B-button dash).
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on May 18, 2019, 01:24:42 am
I spent a little bit of time recently dissecting the ATB hack that's there. It's pretty ingenious and not too complicated. It won't patch properly into any US version of the game, but I think I might be able to replicate it for User Options.
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Gedankenschild on May 29, 2019, 11:28:57 am
Nice!
I just now realized the "Item fix" patch also contains a fix for the critical hit bug. Though I'm not sure what exactly it fixes and how... :-[

That page says it has last been updated in 2010. I can't believe all of this stuff has been sitting there for so long and pretty much no one over here learned about it until now...
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Giud on May 30, 2019, 01:22:31 pm
Nice!
I just now realized the "Item fix" patch also contains a fix for the critical hit bug. Though I'm not sure what exactly it fixes and how... :-[

That page says it has last been updated in 2010. I can't believe all of this stuff has been sitting there for so long and pretty much no one over here learned about it until now...

Thank God for Google Translate,though  ;D I've been looking at that FFIV Advance analyzer and it has a lot of useful data, but it doesn't have the event data offsets which I desperately need :'(
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: chillyfeez on May 30, 2019, 10:39:48 pm
Thank God for Google Translate,though  ;D I've been looking at that FFIV Advance analyzer and it has a lot of useful data, but it doesn't have the event data offsets which I desperately need :'(
That must be documented somewhere. I don't really know ffiva like I do the SNES version, but I'm pretty sure there are people out there who have messed around with it...
Title: Re: Final Fantasy IV SNES - Critical Hit Bug Fix?
Post by: Giud on May 31, 2019, 03:45:30 am
That must be documented somewhere. I don't really know ffiva like I do the SNES version, but I'm pretty sure there are people out there who have messed around with it...

Sadly, FFIV Advance seems to be under-documented, especially compared to FFVa and FFVIa. The problem with event data is that they've changed the event codes so just looking for the same hex values from the SNES game doesn't really do anything.