Author Topic: Fixing the Infinite Arrow Glitch  (Read 2313 times)

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,684
    • View Profile
Fixing the Infinite Arrow Glitch
« on: September 28, 2013, 10:35:30 AM »
I had thought a topic such as this (bug fixes and the like) deserve their own topics for ease of use for people that are looking purely for the fixes (not to mention fixes in general are a larger deal than disassembling)

Okay, well I finally have the means to fix the Arrow Glitch. Just yesterday I was disassembling the Attack Routines and saw references to Arrows. For our purposes here is the relevant information...

Code: [Select]
03/C972 38 SEC A:0001 X:0008 Y:0000 P:envMxdiZc - Set Carry Flag.
$03/C973 BD DC 32 LDA $32DC,x[$7E:32E4] A:0001 X:0008 Y:0000 P:envMxdiZC - Load A from Right Hand Quantity.
$03/C976 E9 01 SBC #$01 A:0032 X:0008 Y:0000 P:envMxdizC - -1 to A. (-1 Arrow)
$03/C978 D0 0E BNE $0E    [$C988] A:0031 X:0008 Y:0000 P:envMxdizC  - If not 00 branch to 03C988.
----------------------------------------------------------------------------------------------------------
$03/C97A A5 CD LDA $CD    [$00:00CD] A:0000 X:0008 Y:0000 P:envMxdiZC - Load A from CD.
$03/C97C AA TAX A:0001 X:0008 Y:0000 P:envMxdizC - Transfer A to X.
$03/C97D BD DC 38 LDA $38DC,x[$7E:38DD] A:0001 X:0001 Y:0000 P:envMxdizC - Load A from 7E38DD.
$03/C980 1A INC A A:0000 X:0001 Y:0000 P:envMxdiZC - +1 to A.
$03/C981 05 AB ORA $AB    [$00:00AB] A:0001 X:0001 Y:0000 P:envMxdizC - Check it against address AB.
$03/C983 9D DC 38 STA $38DC,x[$7E:38DD] A:0001 X:0001 Y:0000 P:envMxdizC - Store A in 7E38DD. (This will make the game realize next turn to decrement the arrow and quantity to 0)
$03/C986 80 03 BRA $03    [$C98B] A:0001 X:0001 Y:0000 P:envMxdizC - Branch to 03C98B

As can be seen the game goes Out Of Its Way to keep that +1 Arrow in the quantity (this is likely to prevent a reset-byte glitch which would make it 255 Arrows) . But they never had to take this path in the first place. When a character's turn starts the game checks if a 01 Arrow has been used and if it has it erases both Arrow and Quantity in a separate location (7E32XX section). Then it adds 1 to the value at 7E38DX (Dependent on Slot) and if that is 1 erases Arrow and Quantity. A more efficient way to do this would have just been to write a JSR to the erasing value at 03A848. The only problem with this is that the game read the Empty Hand after the damage but before the graphics processing so you will be attacking with Fists, dealing appropriate Weapon Damage, but that's the only glitch associated with this and a lot less gamebreaking if someone wanted to make a Saga Style mod where all weapons have "durability". I'll take a small graphical glitch over that nonsense anyday

To make this work correctly change...

$03/C97A   A5 CD   LDA $CD    [$00:00CD]   A:0000   X:0008   Y:0000   P:envMxdiZC - Load A from CD.
$03/C97C   AA    TAX   A:0001   X:0008   Y:0000   P:envMxdizC - Transfer A to X.

To...

$03/C97A   20 48 A8   JSR $A848  [$03:A848]   A:0000   X:0008   Y:0000   P:envMxdiZC - Jump to Subroutine - Arrow/Quantity Erasing Routine.

The rest of that "wait and see" routine past the 00 Arrow check above is unnecessary if this is taken into account. And can be modified to include anything the hacker would like.

While it's not perfect. It's better than what is in place currently, I would say.




« Last Edit: September 28, 2013, 10:42:04 AM by Grimoire LD »

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,684
    • View Profile
Re: Fixing the Infinite Arrow Glitch
« Reply #1 on: January 02, 2015, 01:31:11 PM »
Very late update but I've discovered a glitch with my fix that I should have noticed a long time ago!

I didn't properly nullify the "turn-start check" for the Arrows and this was causing an error where the character in the first slot would lose their weapon because a value that was set for the arrow-user (to lose the last arrow on the next turn) was never cleared.

To fix this all you need to do is null

$03/C983   9D DC 38   STA $38DC,x[$7E:38DC]   A:0019   X:0000   Y:0001   P:envMxdizc

And that will fix the error.

JCE3000GT

  • Master of FF4
  • *
  • Posts: 1,429
  • Gender: Male
  • Vladof
    • View Profile
    • BlitzKrieg Innovations
Re: Fixing the Infinite Arrow Glitch
« Reply #2 on: January 02, 2015, 05:23:43 PM »
Does your bug fix include fixing this:

https://www.youtube.com/watch?v=pdrC89XAblk
https://www.youtube.com/watch?v=ivN5VTV_64w

I'm at work so I cannot test it.  :(

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,684
    • View Profile
Re: Fixing the Infinite Arrow Glitch
« Reply #3 on: January 02, 2015, 06:12:37 PM »
Umm... let's find out...

No, no it did not. That is a rather strange phenomenon. Clearly something wrong is being written into the amount of either hand. I'll check that out, but since this is somewhat menu based, I doubt it will be a simple fix.

Yeah, what a complicated piece of work... it looks to be some screw up in the decrement, but nothing I do will actually show me what is going on. According to the system it is being neither Read or Written to, when I'm seeing it actively seen as both (because it is read when the value is recorded because every time you repeat the glitch in the same battle the game decrements the FF to FE and FD and so on.

The easiest solution would be to just not allow an already selected cursor up to the hand menu, but only can be manipulated from within the hand menu itself. That would require a very specific check. Granted this is a bit difficult to make happen accidentally so I'm not too concerned about it.

JCE3000GT

  • Master of FF4
  • *
  • Posts: 1,429
  • Gender: Male
  • Vladof
    • View Profile
    • BlitzKrieg Innovations
Re: Fixing the Infinite Arrow Glitch
« Reply #4 on: January 02, 2015, 07:25:09 PM »
Intetesting analysis!  The only reason to really fix this is abuse if someone makes a rom hack where they want a challenge and it a very hard difficulty.  I wasn't able to fix this while working on my FF2us HardType.  :(

Funny thing about my glitch is you can only do it if the items in the menu are even horizontally.  It works with either hand but you cannot leave the R/L-hand menu and go back in during/in-the-middle of the removal.  Make sense?

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,684
    • View Profile
Re: Fixing the Infinite Arrow Glitch
« Reply #5 on: January 02, 2015, 07:30:10 PM »
Intetesting analysis!  The only reason to really fix this is abuse if someone makes a rom hack where they want a challenge and it a very hard difficulty.  I wasn't able to fix this while working on my FF2us HardType.  :(

Funny thing about my glitch is you can only do it if the items in the menu are even horizontally.  It works with either hand but you cannot leave the R/L-hand menu and go back in during/in-the-middle of the removal.  Make sense?

Indeed, but why it happens is absolutely beyond me, I've also noticed sometimes that the item that I started with and put away would duplicate itself as well. Why this only happens when the two are lined up next to one another is so peculiar.

JCE3000GT

  • Master of FF4
  • *
  • Posts: 1,429
  • Gender: Male
  • Vladof
    • View Profile
    • BlitzKrieg Innovations
Re: Fixing the Infinite Arrow Glitch
« Reply #6 on: January 02, 2015, 08:05:28 PM »
^ This is also a mystery to me.  Interestingly I found this glitch completely by accident shortly after I bought the game new.  I may be old but my memory is sharp, I actually remember where in the game I was when I did it, needless to say it was odd. 

Another aspect of this is if you have exactly 256 of that item in the current item list and use -Sort- they all disappear. 

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,684
    • View Profile
Re: Fixing the Infinite Arrow Glitch
« Reply #7 on: January 02, 2015, 08:12:10 PM »
^ This is also a mystery to me.  Interestingly I found this glitch completely by accident shortly after I bought the game new.  I may be old but my memory is sharp, I actually remember where in the game I was when I did it, needless to say it was odd. 

Another aspect of this is if you have exactly 256 of that item in the current item list and use -Sort- they all disappear.

I had noticed that as well. I imagine because FF is some sort of terminator in the normal coding it would cause the item to disappear. I imagine it's not included as anything more than a safeguard of sorts.

JCE3000GT

  • Master of FF4
  • *
  • Posts: 1,429
  • Gender: Male
  • Vladof
    • View Profile
    • BlitzKrieg Innovations
Re: Fixing the Infinite Arrow Glitch
« Reply #8 on: January 02, 2015, 09:43:12 PM »
I agree.  I usually did that for Excaliburs for Edge to throw so I would sell or trash at least one so I would lose them when I sorted. 

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,684
    • View Profile
Re: Fixing the Infinite Arrow Glitch
« Reply #9 on: January 29, 2015, 06:47:13 PM »
Well as it turns out it seems that my Infinite Arrow Fix only ended up creating more bugs... so as sad as I am to say it, none of it is a valid alternative, the game looks at too much and focuses too much on certain numbers in this case to safely change. If I could just make the original code to look at the Bow-Wielder as soon as the attack is used and not at their next turn, I could accomplish this, but for now I have to say that this was a failure.

JCE3000GT

  • Master of FF4
  • *
  • Posts: 1,429
  • Gender: Male
  • Vladof
    • View Profile
    • BlitzKrieg Innovations
Re: Fixing the Infinite Arrow Glitch
« Reply #10 on: January 31, 2015, 07:34:46 PM »
:(