• Welcome to Final Fantasy Hacktics. Please login or sign up.
April 03, 2020, 04:43:15 am


Use of ePSXe before 2.0 is highly discouraged. Mednafen/RetroArch is recommended for playing/testing, pSX is recommended for debugging.

Darkholme's ASM Hacks

Started by Darkholme, September 06, 2016, 06:31:51 am


September 06, 2016, 06:31:51 am Last Edit: September 07, 2016, 03:02:27 am by Darkholme
So far it's just the one.

It's a change-up of Glain's "Gear-Level Bugfix/More Selective Equipment" Very small change to his code, but one that makes it do the exact opposite of his hack.

The idea is that I want to have more tightly balanced weapons, and as a result, the weapons you have access to at level 1 should still be viable (though not optimal) even at level 99. As such, I want the NPCs to make use of it. Each job will also have access to a wider variety of weapon types that still make sense for the job.

  <Patch name="Random Unit Equipment Less Picky">
      Random unit equipment will now be way less picky.
      All valid items should be added to the potential list.
    <Location file="SCUS_942_21" offset="4D53C" mode="ASM">
      li      t7,0                  # ItemFound = false (initialize)
    <Location file="SCUS_942_21" offset="4D5F0" mode="ASM">
      li      t7,1                  # ItemFound = true
      addiu   t1,t1,1               # Increment list index
SKP:  move    t4,v1
      move    v1,t1
    <Location file="SCUS_942_21" offset="4D628" mode="ASM">
      addiu   s0,t1,1               # Length = list index + 1
      beq     t7,zero,0x5ce60       # If (no item found), skip

Basically, Glain's hack fixes an error in the existing gear selection function, which was making the game think all items after the first category were whole new categories, rather than choosing from the best level-appropriate item out of each category.

My change to the main check in his hack should make it consider each allowable item individually, such that a level 40 character has the same odds of having an ice-brand as he does of having a broadsword, for projects such as Mine where the old items don't become worthless as you level up.

If you're looking to test it yourself, I also attached a .fftpatch that should let you see it in action quickly and easily.

Most of the time it works perfectly, but once in a while I'm getting items in invalid slots, like you can see in the attachments. Anybody have any idea what's causing this behavior?


What's the PA on that leather helmet? Sounds painful.
  • Modding version: PSX
<@Angel> Teach a man to fish and he'll open up a fishery to compete against yours.

Journey of the Five Youtube ChannelThe Lion War Current Status
Jot5 Leader :: Eventer :: OtherTLW Leader :: Eventer :: Other


Okay, so I finally figured this out by trying it in the pSX debugger.  The first entry of the found item array is your problem.  It always goes uninitialized here, so if it gets picked then you're getting some arbitrary value for the ID of the item to be equipped.

It basically comes down to this:
* The "previous item level" starts at zero.
* The current index of the found item array also starts at zero.
* When adding a new entry to the found item array, the routine increments the current index of the array before saving using that index (i.e., it saves to the next element of the array, not the current)
* This means overwriting the current item entry, as opposed to adding a new entry, is the only way for the first entry to be initialized.
* That's normally okay, though, because the routine will normally never add a new entry to the array before overwriting the current entry at least once. There is a branch that will skip incrementing the list index if the "previous item level" (initialized to zero) is less than the current item level, which it always will be on the first found item.
* ...And, the kicker: you overwrote that branch with a nop.

Essentially, you need a way to skip incrementing the list index for the first entry, but not any other time.  Fortunately, we have the "item found" variable in t7, and you can check if that's zero.  If, instead of overwriting that branch with a nop, you replace it with:

beq t7,zero,SKP

Then everything seems to work.

Alternatively, I also suspect you may be able to fix this by initializing the current item index (t1/r9) to -1 instead of 0 at 0x5cd24 (i.e. addiu t1, zero, -1).  That way, it would increment the list index every time but that would actually be correct since -1 would become 0 for the first entry.  I haven't actually tested that though.
  • Modding version: Other/Unknown