Final Fantasy Hacktics

Modding => Help! => Topic started by: Vanya on January 08, 2011, 04:28:10 am

Title: Another ASM question.
Post by: Vanya on January 08, 2011, 04:28:10 am
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?
Title: Re: Another ASM question.
Post by: formerdeathcorps on January 08, 2011, 06:06:29 am
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.
Title: Re: Another ASM question.
Post by: Vanya on January 10, 2011, 12:59:05 am
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.
Title: Re: Another ASM question.
Post by: formerdeathcorps on January 10, 2011, 02:35:37 am
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.
Title: Re: Another ASM question.
Post by: Vanya on January 10, 2011, 06:47:04 pm
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?
Title: Re: Another ASM question.
Post by: formerdeathcorps on January 12, 2011, 04:22:30 am
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
Title: Re: Another ASM question.
Post by: Celdia on January 12, 2011, 08:35:32 am
Just to pre-empt a bit here...where the hell would we put all this to test it?
Title: Re: Another ASM question.
Post by: Vanya on January 12, 2011, 01:55:47 pm
I believe those addresses are in Battle.bin if I'm not mistaken.
Title: Re: Another ASM question.
Post by: formerdeathcorps on January 12, 2011, 04:13:10 pm
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.
Title: Re: Another ASM question.
Post by: Vanya on January 12, 2011, 05:08:47 pm
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.
Title: Re: Another ASM question.
Post by: formerdeathcorps on January 13, 2011, 03:01:30 am
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
Title: Re: Another ASM question.
Post by: Dokurider on January 13, 2011, 04:20:24 am
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.
Title: Re: Another ASM question.
Post by: Vanya on January 13, 2011, 04:36:28 am
Did you try it out the bug-fixed one?
Title: Re: Another ASM question.
Post by: Pride on January 13, 2011, 04:58:47 am
Yes he did, fdc was instructing him in testing it out. Unless fdc was having him test the bugged one (unlikely).
Title: Re: Another ASM question.
Post by: 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.
Title: Re: Another ASM question.
Post by: formerdeathcorps on January 13, 2011, 03:53:33 pm
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.
Title: Re: Another ASM question.
Post by: Celdia on January 15, 2011, 06:23:42 pm
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

Title: Re: Another ASM question.
Post by: formerdeathcorps on January 16, 2011, 03:46:28 am
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
Title: Re: Another ASM question.
Post by: Spiteful Sprite on January 16, 2011, 07:20:55 am
Impressive, formerdeathcorps.  Your work is always interesting.  Thanks for the fix.
Title: Re: Another ASM question.
Post by: Vanya on January 16, 2011, 07:46:15 am
Nice job, dude! ^_^
Title: Re: Another ASM question.
Post by: Celdia on January 16, 2011, 08:51:23 am
Well done and thank you, FDC. :)
Title: Re: Another ASM question.
Post by: pokeytax on January 16, 2011, 09:40:01 am
Quote from: formerdeathcorps on January 16, 2011, 03:46:28 amNo more Zodiac glitch for Weapon Formulas


Excellent... it's about time someone hammered this one out!
Title: Re: Another ASM question.
Post by: Celdia on January 16, 2011, 10:13:26 am
I am either doing something wrong or I have to rescind my previous statement. This newest fix isn't working. Almost every skill is now showing 00% hit chance on everything or my best yet is 04% hit for 000 damage. One attempt at targeting a unit in combat simply crashed the emulator altogether. Going to try something else for the time being.

Edit: Okay. Went back and rechecked all my work, got things working normally then re-applied your hacks for this. When I tried to target someone with a skill using Formula 01 the game just crashed. I don't know if it will help any but it reads as "Opcode 3f UNK (PC 00159074) (7990,106)" under ePSXe.
Title: Re: Another ASM question.
Post by: formerdeathcorps on January 16, 2011, 04:14:55 pm
EDIT: After more checking, I realized I typed in the wrong ROM offset.  It's fixed now, Celdia.