Users browsing this thread: 2 Guest(s)
Breakable Tools - Need Help

#1
Posts: 614
Threads: 49
Thanks Received: 0
Thanks Given: 4
Joined: Feb 2017
Reputation: 25
Status
None
Divergent Paths has been out for several weeks now, and ther is one pretty big bug that is affecting the game, having to do with the breakable Tools asm that Subtraction helpfully coded for me. Gi Nattak figured out a way to reproduce it, and I have been able to refine that method, but I can't figure out how to fix it. Here is the ASM Code:

Code:
check_command:
CMP #$09
BEQ check_command_end
CMP #$01
BEQ check_command_end
CMP #$08
check_command_end:
RTS

org $C1710F
JSL check_command
NOP
NOP
NOP

org $C21887
JSR check_break
NOP

org $C24DA7
JSR check_command_c2
NOP
NOP
NOP

org $C26490  ;  freespace
check_command_c2:
CMP #$09
BEQ check_command_c2_end
CMP #$01
BEQ check_command_c2_end
CMP #$08
check_command_c2_end:
RTS

check_break:
PHA
PHP
JSR $2B63      ;  Multiply A by 30, size of item data block
REP #$10       ;  Set 16-bit X and Y
TAX
LDA $D85012,X  ;  equipment spell byte.  Bit 7: 1 = remove from inventory upon usage, 0 = nope
BPL no_break   ;  if the flag is not set, this tool never breaks
JSR $4B5A
AND #$2A       ;  1/42 chance of breaking
BNE no_break
LDA #$08      
BIT $3EBB      ;  Check bit 4 of $3EBB (loaded from 1DD0 at the beginning of battle).
BNE no_break   ;  If set, tools can't be broken (set via event with B8 3B. Clear with B9 3B)
LDA #$44       ;  "Orge Nix broke!" dialog. Works for most tools but gets clobbered by the Air Anchor "Move and you're dust!"
STA $3401      
SEP #$10       ;  Set 8-bit X and Y
TYX
LDA #$FF
STA $32F4,X    ;  null item index to add to inventory. This means the item will stay deducted from your inventory.
LDA $3018,X
BRA check_break_end

no_break:
LDA #$10
TSB $B1        ;  set flag to re-add item to inventory at the end of the character's turn

check_break_end:
TSB $3A8C      ;  flag character to have any applicable item in $32F4,X added back to inventory when turn is over.
PLP
PLA
SBC #$A2       ;  carry was clear, so subtract 163
STA $B6        ;  save unique Tool index.  0 = NoiseBlaster, 1 = Bio Blaster, etc.
RTS

Here is the bug, and how to reproduce it:
1. Before the battle, sort your inventory. This step isn't necessary, but it makes it easier to find the glitched items in step 3.
2. You must use Tools 12 times. It doesn't matter if the Tool is a breakable one or not, but if a Tool breaks, it doesn't count towards the 12 count. So, your best bet is to use the Debilitator. It also doesn't matter whether Edgar or Gogo is the one that uses Tools, so bring Gogo along to make this go faster.
3. After using the Debilitator 12 times, you will still have the Debilitator, but you will also have 1-2 glitched items in your inventory. We've seen this be either "Dirk: 01" or "Cat Hood: 96, Scimitar: ,6". These items will be lit up as if you can use them as an item. If you get the Scimitar, it will also be classified as a "Tool", and will show up in your Tool menu. Basically, garbage items.
4. At this point, use any Tool. Regardless of whether it breaks or not, it will be deducted from your inventory. This includes the unbreakable tools (Debilitator and Air Anchor), which cannot be obtained again in the game.
5. Finish the battle. The glitched items will still be in your inventory.

The bug, as far as I can tell, is in the section of code labeled "no_break", since it doesn't occur when the Tool breaks. In fact, a Tool breaking most often doesn't count towards the 12 uses, but sometimes it actually resets the 12 count. I looked through the code, and thought that issue might be that the "SEP #$20", setting the X/Y accumulators back to 8-bit, never occurs on the "no_break" branch. I tried adding that into the "no_break" section of code, both at the beginning and the end, but it did not seem to affect this issue.

Any insight would be immensely helpful. I did not intend to ever do a Divergent Paths v1.1, but this bug is big enough that it's necessary.


Projects:
FFVI: Divergent Paths (Completed) - a complete storyline and gameplay hack of FF6 that adds Leo as a playable character
  Find
Quote  

#2
Posts: 377
Threads: 34
Thanks Received: 10
Thanks Given: 7
Joined: Dec 2018
Reputation: 18
Status
Moog
Well, you don't need to worry about the SEP #$20 in this case. Serity's been teaching me about the stack variables and the accumulator and because you used PHP to push it, all that accumulator stuff will be reset with the PLP to pull it back.

I'm inclined to suggest that maybe you should explicitly set $32F4,X with the tool identity in the no_break branch. That would involve preserving that first A, though, before you even multiply it by 30... either in a scratch variable or by loading its value from the stack. The later requires an intimate knowledge of what's on the stack and how tall it is, though, so I'm not sure what value you'd use.

It uses the first in last out method, though... so perhaps it's as simply as LDA $02,S, because A was pushed onto the stack in the subroutine and then P was.

So... you could maybe try this for no_break:
Code:
no_break:
LDA #$10
TSB $B1        ;  set flag to re-add item to inventory at the end of the character's turn
SEP #$10       ;  Set 8-bit X and Y
TYX
LDA $02,S    ; Load A's original value from the stack?
STA $32F4,X    ;  Save as tool to add back to inventory, just to be safe.
LDA $3018,X
  Find
Quote  
[-] The following 1 user says Thank You to C-Dude for this post:
  • PowerPanda (07-05-2021)

#3
Posts: 614
Threads: 49
Thanks Received: 0
Thanks Given: 4
Joined: Feb 2017
Reputation: 25
Status
None
Thanks C-Dude. Unfortunately that crashes the whole battle.


Projects:
FFVI: Divergent Paths (Completed) - a complete storyline and gameplay hack of FF6 that adds Leo as a playable character
  Find
Quote  

#4
Posts: 377
Threads: 34
Thanks Received: 10
Thanks Given: 7
Joined: Dec 2018
Reputation: 18
Status
Moog
Dang, I was really hoping it'd be something simple like that. Sorry.

I do think that it's something to do with not setting $32F4,X in the fail branch (the "don't break this"), because if there's a wrong value in there (like a tools-indexed item instead of the item itself) that could explain why the game is adding in garbage instead of the tool that was used.
  Find
Quote  

#5
Posts: 18
Threads: 3
Thanks Received: 0
Thanks Given: 0
Joined: Apr 2021
Reputation: 0
Status
None
If someone can toss me a valid save with a collection of tools to play with, I can fire this up in a debugger later and have a sniff around.
  Find
Quote  

#6
Posts: 614
Threads: 49
Thanks Received: 0
Thanks Given: 4
Joined: Feb 2017
Reputation: 25
Status
None
(07-05-2021, 06:50 PM)SirNewtonFig Wrote: If someone can toss me a valid save with a collection of tools to play with, I can fire this up in a debugger later and have a sniff around.

Download Divergent Paths, from the link in my signature. In the "Extras" folder, there is a save repository of my final playthrough. You can pick pretty much any of those. I'd recommend taking the final save file, then fighting on the world map surrounding Kefka's Tower. I know that Celes has Stop magic, so if you cast Stop on any of those enemies, you can pretty much just sit there and spam Tools with Edgar and Gogo. Applying Divergent Paths to your rom will also let you play with this code, which begins at C2/6490. There's a bunch of free space after this code, so you can make your fix as long as it needs to be.

Thank you so much for taking a look.


Projects:
FFVI: Divergent Paths (Completed) - a complete storyline and gameplay hack of FF6 that adds Leo as a playable character
  Find
Quote  

#7
Posts: 377
Threads: 34
Thanks Received: 10
Thanks Given: 7
Joined: Dec 2018
Reputation: 18
Status
Moog
I just tested the fix I proposed 256 times with Debilitator (between Tools and Mimic) and I did not encounter the glitch.

Here's the raw HEX version of it, try pasting this at C2/6490 in a hex editor and give it a shot.
Code:
C2/6490:  (Unheadered)
C9 09 F0 06 C9 01 F0 02 C9 08 60 48 08 20 63 2B C2 10 AA BF 12 50 D8 10 20 20 5A 4B 29 2A D0 19 A9 08 2C BB 3E D0 1F A9 44 8D 01 34 E2 10 BB A9 FF 9D F4 32 BD 18 30 80 0D A9 10 04 B1 BB A3 02 9D F4 32 BD 18 30 0C 8C 3A 28 68 E9 A2 85 B6 60

EDIT (7-6-2021): Accidentally pointed one of the No_Breaks to the wrong spot, which was causing 100% tool breakage for fragile tools. The pointer has been corrected in the above block to D0 19, please apply it again.

EDIT (7-7-2021): For people reading through this thread seven years down the line, do NOT stop here! My suggestion was not the solution and this hex will not solve a breakable tools problem.
  Find
Quote  
[-] The following 1 user says Thank You to C-Dude for this post:
  • PowerPanda (07-06-2021)

#8
Posts: 2,548
Threads: 98
Thanks Received: 147
Thanks Given: 156
Joined: Aug 2009
Reputation: 52
Status
Nattak\'d
It seems that with this code change, when you use a Tool which has a chance to break, such as the Noiseblaster, it removes/deducts the tool each use from the inventory 100%, every time, even if the tool didn't break (when the 'tool is broken' text happens at the top), which is not how it's supposed to work... Before, how it was, is that it would deduct the tool after use, and if it didn't break, would give it back to the player on Edgar's next turn, and if it did break, would not give it back - you could see this happening in the inventory between the turn of Edgar using a tool, and his next turn.


We are born, live, die and then do the same thing over again.
Quote  

#9
Posts: 377
Threads: 34
Thanks Received: 10
Thanks Given: 7
Joined: Dec 2018
Reputation: 18
Status
Moog
(07-06-2021, 12:41 AM)Gi Nattak Wrote: It seems that with this code change, when you use a Tool which has a chance to break, such as the Noiseblaster, it removes/deducts the tool each use from the inventory 100%, every time, even if the tool didn't break (when the 'tool is broken' text happens at the top), which is not how it's supposed to work... Before, how it was, is that it would deduct the tool after use, and if it didn't break, would give it back to the player on Edgar's next turn, and if it did break, would not give it back - you could see this happening in the inventory between the turn of Edgar using a tool, and his next turn.

Oops, I messed up the BNE when I was updating the pointers, it's going to the wrong spot!
I fixed it, and I'll edit it into the code block of the other post.
  Find
Quote  

#10
Posts: 614
Threads: 49
Thanks Received: 0
Thanks Given: 4
Joined: Feb 2017
Reputation: 25
Status
None
Thanks, C-Dude. In my quick test, this produced the same results. I wonder if the use of "Mimic" was resetting the counter somehow. Did you test without Mimic?

I'll do further testing later on today, to make sure it wasn't something on my side.


Projects:
FFVI: Divergent Paths (Completed) - a complete storyline and gameplay hack of FF6 that adds Leo as a playable character
  Find
Quote  



Forum Jump:

Users browsing this thread: 2 Guest(s)


Theme by Madsiur2017Custom Graphics by JamesWhite