øAslickproductions.org/forum/index.php?PHPSESSID=5f0fck550j2m4m2fpbtkj2vkm1&topic=248.msg2063e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/index48e8.htmlslickproductions.org/forum/index.php?PHPSESSID=5f0fck550j2m4m2fpbtkj2vkm1&action=profile;u=6;area=showposts;start=3225e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/index48e8.html.zx¬¡h^ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÈ0Pd_zOKtext/htmlISO-8859-1gzip0|Ö_zÿÿÿÿÿÿÿÿWed, 11 Mar 2020 08:47:01 GMT0ó°° ®0®P®€§²ð®«¡h^ÿÿÿÿÿÿÿÿß9_z FF6 - possible bug

Author Topic: FF6 - possible bug  (Read 11076 times)

Lenophis

  • Forum Overlord
  • *
  • Posts: 1,688
  • Gender: Male
  • I sad
    • View Profile
    • Slick Productions
FF6 - possible bug
« on: January 27, 2008, 03:02:57 AM »
Ok, there's a potential bug out there to crush. If you set an item to cast a spell in battle, and turn off the "break after use" flag, there's potential that the item will not ever get re-added to your inventory. From the sounds of it, number of them remaining hasn't mattered, so it sounds like it could just happen at random. This is the function that re-adds items:

Code: [Select]
(Add/restore characters' items to inventory.  This function is called:
 - At the end of a character's turn when they Steal or Metamorph something.
 - At the end of battle for all characters, to account for items they tried to use
   during the battle, but were thwarted by being killed/etc (the game depletes items
   upon *issuing* the command, so it'll be gone from inventory even if the command
   never executed).
 - It can also be used to restore a "bottomless" item at the end of a character's
   turn.  [The game does support equipment that doesn't deplete when you use it as
   an Item, though no such equipment exists.])

C2/62C7: A2 06        LDX #$06
C2/62C9: BD 18 30     LDA $3018,X
C2/62CC: 1C 8C 3A     TRB $3A8C     (clear this character's "add my items to inventory"
                                     flag)
C2/62CF: F0 19        BEQ $62EA     (if it wasn't set, then skip this character)
C2/62D1: BD F4 32     LDA $32F4,X
C2/62D4: C9 FF        CMP #$FF      (does this character have a valid item to add to
                                     inventory?)
C2/62D6: F0 12        BEQ $62EA     (branch if not)
C2/62D8: 20 DC 54     JSR $54DC
C2/62DB: A9 01        LDA #$01
C2/62DD: 8D 75 2E     STA $2E75
C2/62E0: A9 05        LDA #$05
C2/62E2: 20 11 64     JSR $6411
C2/62E5: A9 FF        LDA #$FF
C2/62E7: 9D F4 32     STA $32F4,X   (null the item to add to inventory)
C2/62EA: CA           DEX
C2/62EB: CA           DEX
C2/62EC: 10 DB        BPL $62C9     (loop for all 4 party members)
C2/62EE: 60           RTS

If memory serves, any items will also be added when the person that used gets gets their ATB refilled. Not 100% on that. In any event, that's about all the info I have, provided from Gil. This is posted in case anybody may know anything. I, for one, have no clue what could be causing it.

119 bugs fixed and counting.

Lenophis

  • Forum Overlord
  • *
  • Posts: 1,688
  • Gender: Male
  • I sad
    • View Profile
    • Slick Productions
Re: FF6 - possible bug
« Reply #1 on: January 29, 2008, 03:01:22 PM »
Ok, in an attempt to find the cause, I've stumbled onto something that seems odd.

$32F4 is the array of "items to be re-added." Whenever an item is stolen, it is put in this array, and then added. Keeping an eye on it, it is blanked immediately after an item is used, whether the "don't deplete item" is set or not. This indicates that the item is being re-added immediately after it is used, but we know this to be false. The item doesn't reappear in inventory until the character that uses it gets their ATB refilled. This suggests a behavior similar to "Control doesn't update with MP cost," but it's different because the item isn't always being re-added.

The code looks pretty solid, so I'm not sure why it's being inconsistent. *keeps digging*

119 bugs fixed and counting.

Deathlike2

  • FF4 R&D Master
  • *
  • Posts: 3,538
  • I'm looking at you, bitch!
    • View Profile
Re: FF6 - possible bug
« Reply #2 on: January 29, 2008, 03:20:45 PM »
Well, isn't it worth pointing out that this array is borked regarding the Thief Glove+Offering?

Maybe it is doing something similar there.
Working on the next Yet To Be Named FF4 "Hardtype" Hack Download Latest: v1.48

Video Demos: #1 #2 #3

Lenophis

  • Forum Overlord
  • *
  • Posts: 1,688
  • Gender: Male
  • I sad
    • View Profile
    • Slick Productions
Re: FF6 - possible bug
« Reply #3 on: January 29, 2008, 03:28:19 PM »
Well, isn't it worth pointing out that this array is borked regarding the Thief Glove+Offering?
Yeah, since there's only one byte per character, only the first item stolen can be added. Since all this does is one item at a time, it shouldn't be a factor. Then again, this is Square we're talking about. :tongue:

Quote
Maybe it is doing something similar there.
That's why I was trying various ways to replicate the bug, (other characters using items, ending battle before items could be used, etc) and I haven't been able to replicate it yet. Gil hadn't used Imzog's Multi-steal fix before this post, and had lost many rods and shields. He has since used that patch, but I haven't asked him if it's been happened again though.

119 bugs fixed and counting.

assassin

  • Bane of Retards
  • *
  • Posts: 1,033
  • space bears are not gentle!
    • View Profile
    • My Barren Webpage
Re: FF6 - possible bug
« Reply #4 on: January 30, 2008, 02:51:48 AM »
Quote
The item doesn't reappear in inventory until the character that uses it gets their ATB refilled.

i don't think you need to have their ATB refilled, but rather change from one character to another with X or Y.  iirc, the Item List you see can't update while you're just sitting on a character's main battle menu as somebody else is altering the Item inventory.  so it's the same deal with Stolen items.   X/Y triggers the "refresh".

Lenophis

  • Forum Overlord
  • *
  • Posts: 1,688
  • Gender: Male
  • I sad
    • View Profile
    • Slick Productions
Re: FF6 - possible bug
« Reply #5 on: January 30, 2008, 02:57:47 AM »
i don't think you need to have their ATB refilled, but rather change from one character to another with X or Y.  iirc, the Item List you see can't update while you're just sitting on a character's main battle menu as somebody else is altering the Item inventory.  so it's the same deal with Stolen items.   X/Y triggers the "refresh".
Yeah, that was explained to me earlier tonight. Kejar's pretty sure that if the inventory were to be updated immediately after $32F4's array is written to, the bug will be crushed. I haven't tested it yet, but that's what I'll try, and ask Gil to try as well.

119 bugs fixed and counting.

assassin

  • Bane of Retards
  • *
  • Posts: 1,033
  • space bears are not gentle!
    • View Profile
    • My Barren Webpage
Re: FF6 - possible bug
« Reply #6 on: January 30, 2008, 03:03:05 AM »
as for bugs related to Item inventory re-adding, there's at least one.  goddamned mnrogar.com is down again, so i'll have to recall one from memory:

Tell somebody to use an item (e.g. Potion), but have them be killed by an attack before they can actually execute their turn.  There's a catch-all that'll add their unconsumed item back to inventory at the end of battle.  Ah, but have the character use another item before finishing battle, and the variable that holds the item to add back gets cleared, making you lose the Potion.  Or if you have the character be killed before they can actually use the second item (e.g. a Tonic), the Tonic will get added back to inventory at the end of battle, but the initial Potion is gone for good.

Entroper

  • FF4 Hacker
  • *
  • Posts: 235
  • Gender: Male
    • View Profile
Re: FF6 - possible bug
« Reply #7 on: January 30, 2008, 07:40:58 AM »
This stuff smacks of procedural spaghetti C code.

Kejardon

  • Pandora's Masking Tape
  • *
  • Posts: 1
    • View Profile
Re: FF6 - possible bug
« Reply #8 on: January 30, 2008, 09:26:50 AM »
Tell somebody to use an item (e.g. Potion), but have them be killed by an attack before they can actually execute their turn.  There's a catch-all that'll add their unconsumed item back to inventory at the end of battle.  Ah, but have the character use another item before finishing battle, and the variable that holds the item to add back gets cleared, making you lose the Potion.  Or if you have the character be killed before they can actually use the second item (e.g. a Tonic), the Tonic will get added back to inventory at the end of battle, but the initial Potion is gone for good.

That's the one I just stumbled onto last night. As Leno said, I think it can be fixed by having the variable that holds the unconsumed item being added back to inventory every time it's written to. But I have confirmed that items that are marked as reusable can be lost this way, so it might also be the cause of Gil's bug.

Lenophis

  • Forum Overlord
  • *
  • Posts: 1,688
  • Gender: Male
  • I sad
    • View Profile
    • Slick Productions
Re: FF6 - possible bug
« Reply #9 on: January 31, 2008, 01:57:05 AM »
Ok, my attempt to fix the bug instead caused it to occur more frequently (maybe even 100%, I dunno, what's 1/1?) :tongue: This is where I tried to put it:

Code: [Select]
Item
C2/1897: 9C 14 34     STZ $3414   (Set ignore damage modification)
C2/189A: A9 80        LDA #$80
C2/189C: 14 B3        TRB $B3     (Set Ignore Clear)
C2/189E: BB           TYX
C2/189F: A9 01        LDA #$01
C2/18A1: 8D 12 34     STA $3412
C2/18A4: AD 7D 3A     LDA $3A7D
C2/18A7: 20 C1 19     JSR $19C1
C2/18AA: A9 10        LDA #$10
C2/18AC: 14 B1        TRB $B1     (clear "don't deplete from Item inventory" flag)
C2/18AE: D0 05        BNE $18B5   (branch if it was set)
C2/18B0: A9 FF        LDA #$FF
C2/18B2: 9D F4 32     STA $32F4,X  (null item index to add to inventory.  this means
                                    the item will stay deducted from your inventory.)
C2/18B5: BD 18 30     LDA $3018,X
C2/18B8: 0C 8C 3A     TSB $3A8C      (set this character's "add item to inventory" bit)

My hook was at C2/18B5, and C2/18B8 was NOP'ed out and included in the hook. After that, I saved the indexes and processor, then called $62C7.

*currently out of ideas*

119 bugs fixed and counting.

Lenophis

  • Forum Overlord
  • *
  • Posts: 1,688
  • Gender: Male
  • I sad
    • View Profile
    • Slick Productions
Re: FF6 - possible bug
« Reply #10 on: January 31, 2008, 01:01:27 PM »
Ok, I found where the item is initially being adding to the reserve.

Code: [Select]
C2/4DA7: C9 01        CMP #$01
C2/4DA9: F0 04        BEQ $4DAF   (Branch if Item)
C2/4DAB: C9 08        CMP #$08
C2/4DAD: D0 05        BNE $4DB4   (Branch if not Throw)
C2/4DAF: EB           XBA
C2/4DB0: 99 F4 32     STA $32F4,Y (store as item to add back to inventory.  this can
                                   happen with:
                                   1) Equipment Magic that doesn't destroy the item
                                      [no items have this, but the game supports it]
                                   2) the item user's turn never happens.  perhaps the
                                      character who acted before them won the battle.)
C2/4DB3: EB           XBA

Simply adding a hook there wouldn't work though. As Kejar pointed it out to me last night, it'd make all items bottomless. $3A8C isn't tweaked until the item is actually used though. It seems like this is where it needs to be done, but I'm currently unsure as to how. Any ideas?

119 bugs fixed and counting.

Deathlike2

  • FF4 R&D Master
  • *
  • Posts: 3,538
  • I'm looking at you, bitch!
    • View Profile
Re: FF6 - possible bug
« Reply #11 on: January 31, 2008, 04:39:56 PM »
It sounds to me that you need to completely redo the battle engine or something.

Maybe it's just me, but there seems to be problems regarding when something updates (most of these bugs documented of course).

The only thing I can think of is running some sort of trace to look for the item usage code.. or specifically command execution...
Working on the next Yet To Be Named FF4 "Hardtype" Hack Download Latest: v1.48

Video Demos: #1 #2 #3

Lenophis

  • Forum Overlord
  • *
  • Posts: 1,688
  • Gender: Male
  • I sad
    • View Profile
    • Slick Productions
Re: FF6 - possible bug
« Reply #12 on: January 31, 2008, 05:17:27 PM »
Maybe it's just me, but there seems to be problems regarding when something updates (most of these bugs documented of course).
It appears this is one of those bugs.

Quote
The only thing I can think of is running some sort of trace to look for the item usage code.. or specifically command execution...
When you confirm to use the item, this code is run:

Code: [Select]
C2/4D89: DA           PHX
C2/4D8A: 5A           PHY
C2/4D8B: 9B           TXY
C2/4D8C: C9 17        CMP #$17   
C2/4D8E: D0 02        BNE $4D92   (Branch if not X-Magic)
C2/4D90: A9 02        LDA #$02    (Set command to Magic)

C2/4D92: C9 19        CMP #$19   
C2/4D94: D0 11        BNE $4DA7   (Branch if not Summon)
C2/4D96: 48           PHA
C2/4D97: EB           XBA
C2/4D98: C9 FF        CMP #$FF    (Check if no Esper equipped)
C2/4D9A: D0 03        BNE $4D9F
C2/4D9C: B9 44 33     LDA $3344,Y
C2/4D9F: EB           XBA
C2/4DA0: B9 18 30     LDA $3018,Y
C2/4DA3: 0C 2E 3F     TSB $3F2E   
C2/4DA6: 68           PLA

C2/4DA7: C9 01        CMP #$01
C2/4DA9: F0 04        BEQ $4DAF   (Branch if Item)
C2/4DAB: C9 08        CMP #$08
C2/4DAD: D0 05        BNE $4DB4   (Branch if not Throw)
C2/4DAF: EB           XBA
C2/4DB0: 99 F4 32     STA $32F4,Y (store as item to add back to inventory.  this can
                                   happen with:
                                   1) Equipment Magic that doesn't destroy the item
                                      [no items have this, but the game supports it]
                                   2) the item user's turn never happens.  perhaps the
                                      character who acted before them won the battle.)
C2/4DB3: EB           XBA

C2/4DB4: C9 0F        CMP #$0F
C2/4DB6: D0 23        BNE $4DDB   (Branch if not Slot)
C2/4DB8: 48           PHA         (save command #)
C2/4DB9: EB           XBA           (get our Slot index)
C2/4DBA: AA           TAX
C2/4DBB: BF 4A 4E C2  LDA $C24E4A,X   (get spell # used by this Slot combo)
C2/4DBF: E0 02        CPX #$02
C2/4DC1: B0 0F        BCS $4DD2       (branch if it's Bahamut or higher -- i.e. neither form
                                       of Joker Doom)
C2/4DC3: 48           PHA             (save spell #)
C2/4DC4: BF 52 4E C2  LDA $C24E52,X   (get Joker Doom targeting)
C2/4DC8: 95 B8        STA $B8,X       (if X is 0 [7-7-Bar], mark all party members in $B8
                                       if X is 1 [7-7-7], mark all enemies in $B9)
C2/4DCA: A5 B8        LDA $B8
C2/4DCC: 4D 40 3A     EOR $3A40     
C2/4DCF: 85 B8        STA $B8         (toggle whether characters acting as enemies are targeted.
                                       e.g. Shadow in Colosseum or Gau returning from Veldt leap)
C2/4DD1: 68           PLA             (restore spell #)
C2/4DD2: C9 FF        CMP #$FF
C2/4DD4: D0 03        BNE $4DD9   (branch if not Bar-Bar-Bar)
C2/4DD6: 20 DC 37     JSR $37DC   (Pick random esper)
C2/4DD9: EB           XBA
C2/4DDA: 68           PLA         (restore command #)

C2/4DDB: C9 13        CMP #$13
C2/4DDD: D0 0D        BNE $4DEC   (Branch if not Dance)
C2/4DDF: 48           PHA
C2/4DE0: EB           XBA
C2/4DE1: 99 E1 32     STA $32E1,Y
C2/4DE4: 8D 6F 3A     STA $3A6F
C2/4DE7: 20 9C 05     JSR $059C   (Pick dance and dance move)
C2/4DEA: EB           XBA
C2/4DEB: 68           PLA

C2/4DEC: C9 10        CMP #$10
C2/4DEE: D0 0A        BNE $4DFA   (Branch if not Rage)
C2/4DF0: 48           PHA
C2/4DF1: EB           XBA
C2/4DF2: 99 A8 33     STA $33A8,Y (Which rage is being used)
C2/4DF5: 20 D1 05     JSR $05D1   (Picks a Rage [when Muddled/Berserked/etc], and picks
                                   the Rage move)
C2/4DF8: EB           XBA
C2/4DF9: 68           PLA

C2/4DFA: C9 0A        CMP #$0A
C2/4DFC: D0 15        BNE $4E13   (Branch if not Blitz)
C2/4DFE: 48           PHA
C2/4DFF: EB           XBA
C2/4E00: 48           PHA
C2/4E01: 30 0D        BMI $4E10   (If no blitz selected)
C2/4E03: AA           TAX
C2/4E04: 20 57 1E     JSR $1E57
C2/4E07: 2C 28 1D     BIT $1D28
C2/4E0A: D0 04        BNE $4E10   (Branch if selected blitz is known)
C2/4E0C: A9 FF        LDA #$FF
C2/4E0E: 83 01        STA $01,S   (replace spell/attack # with null)
C2/4E10: 68           PLA
C2/4E11: EB           XBA
C2/4E12: 68           PLA

C2/4E13: A2 04        LDX #$04
C2/4E15: DF 3C 4E C2  CMP $C24E3C,X   (does our command match one that needs its
                                       spell # calculated?)
C2/4E19: D0 0B        BNE $4E26       (branch if not)
C2/4E1B: EB           XBA
C2/4E1C: 18           CLC
C2/4E1D: 7F 41 4E C2  ADC $C24E41,X   (add the first spell # for this command to our
                                       current index.  ex - for Pummel, Blitz #0, we'd
                                       end up with 55h.)
C2/4E21: 90 02        BCC $4E25       (branch if the spell # didn't overflow)
C2/4E23: A9 EE        LDA #$EE        (load Battle as spell #)
C2/4E25: EB           XBA             (put spell # in top of A, and look at command # again)
C2/4E26: CA           DEX
C2/4E27: 10 EC        BPL $4E15       (loop for all 5 commands)

C2/4E29: 48           PHA
C2/4E2A: 18           CLC             (clear Carry)
C2/4E2B: 20 17 52     JSR $5217       (X = A DIV 8, A = 2 ^ (A MOD 8) )
C2/4E2E: 3F 46 4E C2  AND $C24E46,X   (compare to bitfield of commands that need to retarget)
C2/4E32: F0 04        BEQ $4E38       (Branch if command doesn't need to retarget)
C2/4E34: 64 B8        STZ $B8   
C2/4E36: 64 B9        STZ $B9         (clear targets)
C2/4E38: 68           PLA
C2/4E39: 7A           PLY
C2/4E3A: FA           PLX
C2/4E3B: 60           RTS

When the item is used, this code is run:

Code: [Select]
Item
C2/1897: 9C 14 34     STZ $3414   (Set ignore damage modification)
C2/189A: A9 80        LDA #$80
C2/189C: 14 B3        TRB $B3     (Set Ignore Clear)
C2/189E: BB           TYX
C2/189F: A9 01        LDA #$01
C2/18A1: 8D 12 34     STA $3412
C2/18A4: AD 7D 3A     LDA $3A7D
C2/18A7: 20 C1 19     JSR $19C1
C2/18AA: A9 10        LDA #$10
C2/18AC: 14 B1        TRB $B1     (clear "don't deplete from Item inventory" flag)
C2/18AE: D0 05        BNE $18B5   (branch if it was set)
C2/18B0: A9 FF        LDA #$FF
C2/18B2: 9D F4 32     STA $32F4,X  (null item index to add to inventory.  this means
                                    the item will stay deducted from your inventory.)
C2/18B5: BD 18 30     LDA $3018,X
C2/18B8: 0C 8C 3A     TSB $3A8C      (set this character's "add item to inventory" bit)
C2/18BB: A5 B5        LDA $B5    (Command #)
C2/18BD: 90 24        BCC $18E3  (Carry is set (by the $19C1 call) for:
  - Skeans/Tools that don't use a spell
                                  - normal Item usage
                                  which means it isn't set for:
                                  - Equipment Magic or Skeans/Tools that do use a spell )
 
C2/18BF: C9 02        CMP #$02   (Carry will be set if Command >=2, which means it'll
                                  be set for Throw and Tools, but not plain Item --
                                  or apparently Item Magic, which also uses Command 1)

C2/18C1: AD 11 34     LDA $3411
C2/18C4: 20 37 2A     JSR $2A37
C2/18C7: AD AA 11     LDA $11AA
C2/18CA: 89 C2        BIT #$C2    (Check if Dead, Petrify or Zombie attack)
C2/18CC: D0 12        BNE $18E0   (if so, branch)
C2/18CE: C2 20        REP #$20    (Set 16-bit Accumulator)
C2/18D0: AD 74 3A     LDA $3A74
C2/18D3: 0D 42 3A     ORA $3A42
C2/18D6: 25 B8        AND $B8
C2/18D8: 85 B8        STA $B8
C2/18DA: E2 20        SEP #$20    (Set 8-bit Accumulator)
C2/18DC: A9 04        LDA #$04
C2/18DE: 14 B3        TRB $B3
C2/18E0: 4C 7B 31     JMP $317B

C2/18E3: C9 01        CMP #$01    (is command Item?)
C2/18E5: D0 07        BNE $18EE   
C2/18E7: E6 B5        INC $B5     (if so, bump it up to Magic, as we've reached this
                                   point thanks to Equipment Magic)
C2/18E9: AD 10 34     LDA $3410
C2/18EC: 85 B6        STA $B6
C2/18EE: 64 BD        STZ $BD
C2/18F0: 20 51 29     JSR $2951
C2/18F3: A9 02        LDA #$02
C2/18F5: 0C A3 11     TSB $11A3   (Set Not reflectable)
C2/18F8: A9 20        LDA #$20
C2/18FA: 0C A4 11     TSB $11A4   (Set unblockable)
C2/18FD: A9 08        LDA #$08
C2/18FF: 14 BA        TRB $BA     (Clear "can target dead/hidden targets")
C2/1901: 9C A5 11     STZ $11A5   (Set MP cost to 0)
C2/1904: 4C 7B 31     JMP $317B

My first attempt to fix it was at the item use, but that turned out to be less than successful.

119 bugs fixed and counting.

Deathlike2

  • FF4 R&D Master
  • *
  • Posts: 3,538
  • I'm looking at you, bitch!
    • View Profile
Re: FF6 - possible bug
« Reply #13 on: January 31, 2008, 05:43:20 PM »
Ok, my attempt to fix the bug instead caused it to occur more frequently (maybe even 100%, I dunno, what's 1/1?) :tongue: This is where I tried to put it:

Code: [Select]
Item
C2/1897: 9C 14 34     STZ $3414   (Set ignore damage modification)
C2/189A: A9 80        LDA #$80
C2/189C: 14 B3        TRB $B3     (Set Ignore Clear)
C2/189E: BB           TYX
C2/189F: A9 01        LDA #$01
C2/18A1: 8D 12 34     STA $3412
C2/18A4: AD 7D 3A     LDA $3A7D
C2/18A7: 20 C1 19     JSR $19C1
C2/18AA: A9 10        LDA #$10
C2/18AC: 14 B1        TRB $B1     (clear "don't deplete from Item inventory" flag)
C2/18AE: D0 05        BNE $18B5   (branch if it was set)
C2/18B0: A9 FF        LDA #$FF
C2/18B2: 9D F4 32     STA $32F4,X  (null item index to add to inventory.  this means
                                    the item will stay deducted from your inventory.)
C2/18B5: BD 18 30     LDA $3018,X
C2/18B8: 0C 8C 3A     TSB $3A8C      (set this character's "add item to inventory" bit)

My hook was at C2/18B5, and C2/18B8 was NOP'ed out and included in the hook. After that, I saved the indexes and processor, then called $62C7.

*currently out of ideas*

Logic bug? I need to see the original code+changes in one section... with changes/removals bolded or whatever.
Working on the next Yet To Be Named FF4 "Hardtype" Hack Download Latest: v1.48

Video Demos: #1 #2 #3

assassin

  • Bane of Retards
  • *
  • Posts: 1,033
  • space bears are not gentle!
    • View Profile
    • My Barren Webpage
Re: FF6 - possible bug
« Reply #14 on: January 31, 2008, 09:56:05 PM »
It's very difficult to address, because in the case of a character dying before they can use the item, there's no practical way to check, "Was their turn unable to execute?".  It's not like you know for a fact that their turn will have completed within X seconds if it's going to complete at all, as there are so many possible intervening factors.  Besides, a timer would be tedious and difficult to set up anyway.

Quote from: Lenophis
Ok, I found where the item is initially being adding to the reserve.

Code: [Select]
Code:
C2/4DA7: C9 01        CMP #$01
C2/4DA9: F0 04        BEQ $4DAF   (Branch if Item)
C2/4DAB: C9 08        CMP #$08
C2/4DAD: D0 05        BNE $4DB4   (Branch if not Throw)
C2/4DAF: EB           XBA
C2/4DB0: 99 F4 32     STA $32F4,Y (store as item to add back to inventory.  this can
                                   happen with:
                                   1) Equipment Magic that doesn't destroy the item
                                      [no items have this, but the game supports it]
                                   2) the item user's turn never happens.  perhaps the
                                      character who acted before them won the battle.)
C2/4DB3: EB           XBA
Simply adding a hook there wouldn't work though. As Kejar pointed it out to me last night, it'd make all items bottomless. $3A8C isn't tweaked until the item is actually used though. It seems like this is where it needs to be done, but I'm currently unsure as to how. Any ideas?

how about _before_ C2/4DB0, you preserve A, check the character's current $32F4,Y value, and if it isn't FFh, then call a routine to put its contents back into inventory?  (you'd want to code a custom version of C2/62C7 to focus on one character, as calling the entire function would mess with other characters' $32F4 values.)  that oughta take care of any aborted Item usages from the character's previous turns.  as you said, you wouldn't be able to use $3A8C here, but i think that'll be alright, unless $32F4 somehow gets misleading garbage in it.

still, there's the matter of if a character is killed while attempting to use Tonic, then they are revived, why should they have to wait til the end of battle to get that Tonic back into inventory?  it's not like the Tonic rolled meters away from them and they have to scour the ground for it.  obviously, the end-of-battle check serves as a catch-all, but there's no good reason that restoral shouldn't happen sooner/immediately.

at one point, i think Imzogelmo suggested cutting off all the ways a character can be taken out of commission (e.g. dying, being petrified, being Sneezed, etc, etc), and adding an item restoral call to each one.  if the character died before they can use an item, it's presumably still on their person, so the party shouldn't even have to wait for the character to be revived just so they can have access to the item -- rigor mortis aside.