FF6 Hacking
Making Inviz Edge editable in FF3USME - Printable Version

+- FF6 Hacking (https://www.ff6hacking.com/forums)
+-- Forum: Discussion Forums (https://www.ff6hacking.com/forums/forum-5.html)
+--- Forum: Magitek Research Facility (https://www.ff6hacking.com/forums/forum-9.html)
+--- Thread: Making Inviz Edge editable in FF3USME (/thread-3877.html)



Making Inviz Edge editable in FF3USME - C-Dude - 09-08-2019

So I learned that Shadow Edge and Inviz Edge (the two status buff skeans) are hard-coded like the tools, and this was frustrating me because I wanted to make them do different things in the item editor and those things were not transferring into the game.

After fiddling around with it for a while, I learned that the code controlling items, thrown items, and tools has a branch for tools that keeps item data (like statuses to set) from being loaded, no doubt because each tool does not use this information and instead uses those bytes for targeting.

The exception, of course, is Shadow Edge and Inviz Edge, which are literally checked and set like items after tools/throw skips over the item initialization.  To make them more flexible, I shifted the item initialization block forward 5 bytes and made it into a subroutine, so that Shadow Edge and Inviz Edge could call it after the tool skip.

The result?  Now Shadow Edge and Inviz Edge are editable like standard items, while remaining skeans called by the Throw menu.

Here's my changes, built off Assassin's disassembly of C2
[spoiler]
Code:
=========================================
Shadow Edge and Inviz Edge Editor Fix
(To allow FF3USME editing of these items)
=========================================
Through some careful hex rearrangement, I've converted item initialization into
a nested subroutine so that the item-based Skeans (those that don't just cast spells)
can be edited in FF3USME's item editor.

Relevant Hex Addresses
C2/2A37 - C2/2AF1

Modified Hex
C2/2A74 - C2/2AF1 (Mostly shift of existing code)

Values in this range were shifted to accomodate a subroutine call.  Any other patches
that modify this area of the code will thus be incompatible without adjustment.

Basically, instead of manually setting the functions of Inviz Edge and Shadow Edge
with hard-coded values, after the tool skip the code will check if those items are
being thrown, and if so go back and collect their item data as if they
were used from the Item menu.

I've conducted cursory testing of this with items, thrown items, and tools, and
it seems to work as intended.  No promises, though.

======
Hex
======
(Item usage setup.  Used for non-Magic: Items, Thrown objects, and Tools)
(Going in: A = Item number.
  Carry flag = Command >= 2.  It's set for Throw or Tools, but not plain Item.)

...
C2/2A74: B0 6C        BCS $2AE2      (branch if Throw or Tools)
                                    [Branch lengthened to skip injected commands]
C2/2A76: 20 7B 2A     JSR $2A7B (Regular Item loop)
C2/2A79: 80 67        BRA $2AE2    (Skip doing Regular Item loop again)
                                    [The lines that follow were originally the bulk of the item subroutine]
                                    [Now the subroutine has its own embedded subroutine...]
                                    [to allow the two 'item' skeans to function as regular items]
C2/2A7B-C2/2ADE:    Starts with A9 01        LDA #$01
                    Ends with 0C A2 11     TSB $11A2
                                    [This hex is unchanged, it is simply shifted forward 5 bytes from Vanilla to make room]
C2/2AE1: 60           RTS                (End regular item data collection)
                                    [This closes the subroutine.  By making the above block a subroutine, we can call it repeatedly...]
                                    [without needing to replicate it.  If we were to try to add more skeans that work like items...]
                                    [we could add a jump at the following section and do more item ID check.]
                                    [Then the function of those items could be specified in the Editor...]
                                    [...though to have them animate, they need to still be ITEMS]
C2/2AE2: A3 01        LDA $01,S
C2/2AE4: C9 AE        CMP #$AE      (Item number 174 - is this Inviz Edge?)
C2/2AE6: F0 04        BEQ $2AED     (Branch if so)
C2/2AE8: C9 AF          CMP #$AF        (Item number 175 - is this Shadow Edge?)
C2/2AEA: D0 03          BNE $2AEF        (Branch if not.  This may seem incongruous,)
                                    (but it is to check both item values without loading A twice)
C2/2AEC: 20 7B 2A     JSR $217B        (Regular Item loop)
C2/2AEF: 80 01        BRA #$01        [This setup uses three fewer bytes than Vanilla]
C2/2AF1: EA              NOP            [So we fill them with a short hop to join up with the original code]
[/spoiler]

And here's the raw hex.  It's smaller than the original vanilla code, so it can be applied in-line.  Thus far I haven't encountered any aberrant behavior from items, thrown items, or tools, but you never know if there's some lurking bug hiding in the mix.
Code:
================
Raw Modified Hex
================
C2/2A74-C2/2AF1

-- -- -- -- B0 6C 20 7B 2A 80 67 A9 01 1C A2 11
BF 1B 50 D8 0A B0 05 69 90 8D A9 11 C2 20 BF 15
50 D8 8D AA 11 BF 17 50 D8 8D AC 11 E2 20 BF 13
50 D8 85 FE 06 FE 90 05 A9 80 0C A4 11 06 FE 06
FE 90 05 A9 04 0C A4 11 06 FE 90 07 A9 80 0C A3
11 04 FE 06 FE 90 05 A9 01 0C A4 11 06 FE 06 FE
90 05 A9 08 0C A2 11 AD AA 11 10 05 A9 0C 0C A2
11 60 A3 01 C9 AE F0 04 C9 AF D0 03 20 7B 2A 80
01 EA -- -- -- -- -- -- -- -- -- -- -- -- -- --
Obviously if your hack modifies this data (most likely if you use that patch that overhauls how Tools work), there will be conflicts.  Still, I thought this was significant enough to share with the community.  It's not technically a bug fix, but it does make these two items easier to work with in the editor.