• Welcome to Final Fantasy Hacktics. Please login or sign up.
 
April 27, 2024, 07:42:11 pm

News:

Don't be hasty to start your own mod; all our FFT modding projects are greatly understaffed! Find out how you can help in the Recruitment section or our Discord!


Another ASM question.

Started by Vanya, January 08, 2011, 04:28:10 am

Vanya

Is there a simple way (like one line of code) to make the [Weapon] in ability formulas load the correct weapon formula instead of the generic one that is automatically loaded? Or would this be a bigger hack that would require a table for the weapon formulas?
  • Modding version: Other/Unknown
¯\(°_0)/¯

formerdeathcorps

No, because the weapon formulas are in a sub-sub-routine of the generic weapon formulas.  The weapon number is simply stored as in unit RAM.

Now, what you can do is call the weapon type from unit RAM and then load that specific routine mentioned above, but you'd then skip charge calculations, Zodiac calculations, elemental calculations, and so on.
The destruction of the will is the rape of the mind.
The dogmas of every era are nothing but the fantasies of those in power; their dreams are our waking nightmares.

Vanya

Quote...the weapon formulas are in a sub-sub-routine...


You mean it is part of a larger subroutine and isn't isolated on it's own?


Quote...call the weapon type from unit RAM...


Wait a minute. Can you actually load the weapon type directly? I didn't see that value in the formula hacking list on the wiki.


Quote[01]
00188b64: 27bdffe8 addiu r29,r29,0xffe8
00188b68: afbf0010 sw r31,0x0010(r29)
00188b6c: 0c062144 jal 0x00188510      Physical Evade Calculation
00188b70: 00000000 nop
00188b74: 14400007 bne r2,r0,0x00188b94      Branch if attack is evaded
00188b78: 00000000 nop
00188b7c: 0c06218e jal 0x00188638      Physical Damage Calculation (Weapons)
00188b80: 00000000 nop
00188b84: 14400003 bne r2,r0,0x00188b94      Branch if no damage is dealt
00188b88: 00000000 nop
00188b8c: 0c061fad jal 0x00187eb4      Status Calculation
00188b90: 00000000 nop
00188b94: 8fbf0010 lw r31,0x0010(r29)
00188b98: 27bd0018 addiu r29,r29,0x0018
00188b9c: 03e00008 jr r31
00188ba0: 00000000 nop


The routine that this bolded line goes to is the normal weapon damage routine used for weapons, right?
Couldn't I just make it jump to free space where I can have it load the weapon type based on the equipped weapon and then pass that value to the "Physical Damage Calculation (Weapons)" routine as normal? This is assuming that the problem is that the weapon type value isn't being passed correctly.
  • Modding version: Other/Unknown
¯\(°_0)/¯

formerdeathcorps

Vanya, that routine has 10 sub-routines.  One of the first ones is the weapon check routine (that loads the non-WP XA stats for all the weapons).  Each weapon's formula, then, is a sub-sub-routine under the routine you pointed out.  You don't need to write it in manually because it's already there.
The destruction of the will is the rape of the mind.
The dogmas of every era are nothing but the fantasies of those in power; their dreams are our waking nightmares.

Vanya

Then why doesn't it work for abilities? What is going wrong with it?
Or am I mistaken in my understanding that for formulas it defaults to the Knight Sword formula?
  • Modding version: Other/Unknown
¯\(°_0)/¯

formerdeathcorps

January 12, 2011, 04:22:30 am #5 Last Edit: January 12, 2011, 07:37:19 am by formerdeathcorps
Yeah, the formula is always defaulting to fists and here's why.

Physical Damage Calculation
00188638: 27bdffe8 addiu r29,r29,0xffe8
0018863c: afbf0010 sw r31,0x0010(r29)
00188640: 0c0616a7 jal 0x00185a9c  Has a check if your attack is a weapon attack.  If not, it defaults to zero, which is the fist formula.
00188644: 00000000 nop
00188648: 0c0617e0 jal 0x00185f80
0018864c: 00000000 nop
00188650: 0c0617e9 jal 0x00185fa4
00188654: 00000000 nop
00188658: 0c0621a9 jal 0x001886a4
0018865c: 00000000 nop
00188660: 0c061bf4 jal 0x00186fd0
00188664: 00000000 nop
00188668: 3c028019 lui r2,0x8019
0018866c: 8c422d90 lw r2,0x2d90(r2)
00188670: 00000000 nop
00188674: 90420000 lbu r2,0x0000(r2)
00188678: 00000000 nop
0018867c: 10400005 beq r2,r0,0x00188694
00188680: 34020001 ori r2,r0,0x0001
00188684: 0c061c3f jal 0x001870fc
00188688: 00000000 nop
0018868c: 0c062130 jal 0x001884c0
00188690: 00000000 nop
00188694: 8fbf0010 lw r31,0x0010(r29)
00188698: 27bd0018 addiu r29,r29,0x0018
0018869c: 03e00008 jr r31

EDIT: Here's an untested ASM hack to fix this.  I may have messed up my registers since I wrote this at 4:30 AM, but it should work.  Also, I don't exactly remember where my assigned ASM space is, but those niceties can be fixed later.

0x185a9c
00 C8 03 0C -- jal 0xF2000
00 00 00 00 -- nop

0xF2000
19 80 02 3C -- lui r2, 0x8019
94 2D 42 8C -- lw r2, 0x2d94 (r2)
00 00 00 00 -- nop
91 00 42 90 -- lbu r2, 0x0091 (r2)
02 00 42 30 -- andi r2, r2, 0x0002
05 00 40 10 -- beq r2, r0, 0xF202C
00 00 00 00 -- nop
19 80 02 3C -- lui r2, 0x8019
D8 38 42 90 -- lbu r2, 0x38d8 (r2)
25 C8 03 08 -- j 0xF2064
00 00 00 00 -- nop
19 80 02 3C -- lui r2, 0x8019
C4 38 42 90 -- lbu r2, 0x38c4 (r2)
CA 00 43 2C -- sltiu r3, r2, 0x00CA
0A 00 60 14 -- bne r3, r0, 0xF2064
00 00 00 00 -- nop
19 80 03 3C -- lui r3, 0x8019
C5 38 63 90 -- lbu r3, 0x38c5 (r3)
CA 00 62 2C -- sltiu r2, r3, 0x00CA
04 00 40 10 -- beq r2, r0, 0xF2060
00 00 00 00 -- nop
20 10 03 00 -- add r2, r3, r0
25 C8 03 08 -- j 0xF2064
00 00 00 00 -- nop
20 10 00 00 -- add r2, r0, r0
08 00 E0 03 -- jr 31
00 00 00 00 -- nop
The destruction of the will is the rape of the mind.
The dogmas of every era are nothing but the fantasies of those in power; their dreams are our waking nightmares.

Celdia

Just to pre-empt a bit here...where the hell would we put all this to test it?
  • Modding version: PSX
  • Discord username: Celdia#0

Vanya

I believe those addresses are in Battle.bin if I'm not mistaken.
  • Modding version: Other/Unknown
¯\(°_0)/¯

formerdeathcorps

January 12, 2011, 04:13:10 pm #8 Last Edit: January 12, 2011, 04:37:02 pm by formerdeathcorps
Thanks for pointing out the most obvious error: the first was a RAM offset, and the second was a ROM offset.  This just goes to show why I shouldn't code so late in the evening.

The following will now all be written in RAM offsets, since all you have to do to test is to type this into your debugger.

0x185a9c (BATTLE.BIN offset is 0x11EA9C)
00 64 05 08 -- j 0x159000
00 00 00 00 -- nop

0x159000 (BATTLE.BIN offset is 0xF2000)
19 80 02 3C -- lui r2, 0x8019
D6 38 42 94 -- lhu r2, 0x38d6 (r2)
00 00 00 00 -- nop
06 00 40 10 -- beq r2, r0, 0x159028
00 00 00 00 -- nop
19 80 02 3C -- lui r2, 0x8019
D8 38 42 90 -- lbu r2, 0x38d8 (r2)
00 00 00 00 -- nop
18 64 05 08 -- j 0x159060
00 00 00 00 -- nop
19 80 02 3C -- lui r2, 0x8019
C4 38 42 90 -- lbu r2, 0x38c4 (r2)
CA 00 43 2C -- sltiu r3, r2, 0x00CA
0A 00 60 14 -- bne r3, r0, 0x159060
00 00 00 00 -- nop
19 80 03 3C -- lui r3, 0x8019
C5 38 63 90 -- lbu r3, 0x38c5 (r3)
CA 00 62 2C -- sltiu r2, r3, 0x00CA
04 00 40 10 -- beq r2, r0, 0x15905C
00 00 00 00 -- nop
20 10 60 00 -- add r2, r3, r0
18 64 05 08 -- j 0x159060
00 00 00 00 -- nop
20 10 00 00 -- add r2, r0, r0
A9 16 06 08 -- j 0x185aa4
00 00 00 00 -- nop

EDIT: I just tested this.  At the least, it shouldn't freeze your game and works for normal attacks.  What needs to be tested now is:
1) Use 2 different weapons to attack
2) Equip 2 different weapons, but use a hacked Formula 01 spell.  It should take the damage formula and WP of the RH weapon.
3) Equip a weapon and shield, but use a hacked Formula 01 spell.  It should take the damage formula and WP of the weapon, regardless of which hand it's in or whether the unit has two swords or not.
The destruction of the will is the rape of the mind.
The dogmas of every era are nothing but the fantasies of those in power; their dreams are our waking nightmares.

Vanya

I hope this works because it'll open up the possibility for a bunch of new weapon based attacks that can cause status effects and not be limited to the weapon's normal range.
  • Modding version: Other/Unknown
¯\(°_0)/¯

formerdeathcorps

There's actually a bug in the previous one.  If you have only a weapon in your left hand, using Formula 01 would still default to fists.  This should fix it.

0x185a9c (BATTLE.BIN offset is 0x11EA9C)
00 64 05 08 -- j 0x159000
00 00 00 00 -- nop

0x159000 (BATTLE.BIN offset is 0xF2000)
19 80 02 3C -- lui r2, 0x8019
D6 38 42 94 -- lhu r2, 0x38d6 (r2)
00 00 00 00 -- nop
06 00 40 10 -- beq r2, r0, 0x159028
00 00 00 00 -- nop
19 80 02 3C -- lui r2, 0x8019
D8 38 42 90 -- lbu r2, 0x38d8 (r2)
00 00 00 00 -- nop
1B 64 05 08 -- j 0x15906C
00 00 00 00 -- nop
19 80 02 3C -- lui r2, 0x8019
C4 38 42 90 -- lbu r2, 0x38c4 (r2)
00 00 00 00 -- nop
04 00 40 10 -- beq r2, r0, 0x159048
00 00 00 00 -- nop
CA 00 43 2C -- sltiu r3, r2, 0x00CA
0A 00 60 14 -- bne r3, r0, 0x15906C
00 00 00 00 -- nop
19 80 03 3C -- lui r3, 0x8019
C5 38 63 90 -- lbu r3, 0x38c5 (r3)
CA 00 62 2C -- sltiu r2, r3, 0x00CA
04 00 40 10 -- beq r2, r0, 0x159068
00 00 00 00 -- nop
20 10 60 00 -- add r2, r3, r0
1B 64 05 08 -- j 0x15906C
00 00 00 00 -- nop
20 10 00 00 -- add r2, r0, r0
A9 16 06 08 -- j 0x185aa4
00 00 00 00 -- nop
The destruction of the will is the rape of the mind.
The dogmas of every era are nothing but the fantasies of those in power; their dreams are our waking nightmares.

Dokurider

Okay so I tested this hack out last night

I patched Cure 1 to Formula 01 and brought three priests to battle, one that was two swording a 6 WP Staff and a 4 WP Staff, had 18 MA, other had just a shield on, had a brave of 75 and a PA of 14, and the last one had a 6 WP staff equipped on the left hand, 15 MA. They all did their normal damage. Patched Cure 1 did fist formula damage.

Vanya

Did you try it out the bug-fixed one?
  • Modding version: Other/Unknown
¯\(°_0)/¯

Pride

Yes he did, fdc was instructing him in testing it out. Unless fdc was having him test the bugged one (unlikely).
  • Modding version: PSX
Check out my ASM thread. Who doesn't like hax?

Vanya

I only ask because Doku said "last night" and the bugfix version was only posted an hour before his report.
  • Modding version: Other/Unknown
¯\(°_0)/¯

formerdeathcorps

Quote from: Vanya on January 13, 2011, 02:09:18 pm
I only ask because Doku said "last night" and the bugfix version was only posted an hour before his report.


I instructed Doku to use my fixed version in his testing, so it should be correct.
The destruction of the will is the rape of the mind.
The dogmas of every era are nothing but the fantasies of those in power; their dreams are our waking nightmares.

Celdia

I hope no one minds but I'm just gonna stick this here for easy C&P into BATTLE.BIN



1980023C
D6384294
00000000
06004010
00000000
1980023C
D8384290
00000000
1B640508
00000000
1980023C
C4384290
00000000
04004010
00000000
CA00432C
0A006014
00000000
1980033C
C5386390
CA00622C
04004010
00000000
20106000
1B640508
00000000
20100000
A9160608
00000000

  • Modding version: PSX
  • Discord username: Celdia#0

formerdeathcorps

January 16, 2011, 03:46:28 am #17 Last Edit: January 16, 2011, 07:05:49 pm by formerdeathcorps
Thanks to Celdia, we've found a bug.

This cannot be used with magic guns because dealt damage = displayed damage x 4 and that the infamous Zodiac glitch occurs with all guns.  Fixing the Zodiac glitch is my next priority.

EDIT: No more Zodiac glitch for Weapon Formulas (Fixes 01, 02, 05, 06, 07):

0x185C8C in RAM (or 0x11EC8C in BATTLE.BIN)
1D 64 05 08

0x159074 in RAM (or 0xF2074 in BATTLE.BIN)
0A 00 02 34
05 00 82 14
00 00 00 00
19 80 02 3C
02 39 43 90
00 00 00 00
CE 38 43 A4
08 00 E0 03
00 00 00 00
The destruction of the will is the rape of the mind.
The dogmas of every era are nothing but the fantasies of those in power; their dreams are our waking nightmares.

Spiteful Sprite

Impressive, formerdeathcorps.  Your work is always interesting.  Thanks for the fix.
The bullet holes were rubies on her chest, blood glowing on her ivory skin.  She was so beautiful.  The killer was smiling.

Vanya

  • Modding version: Other/Unknown
¯\(°_0)/¯