Modding => PSX FFT Hacking => Topic started by: formerdeathcorps on June 15, 2011, 05:22:11 pm
Title: Weapon Hacking Part I
Post by: formerdeathcorps on June 15, 2011, 05:22:11 pm
OK, I just rewrote the weapon XA routine because it was a mess.
XA can be: PA MA (PA+SP)*.5 (PA+MA)*.5 [PA*Br*.01] RN{1+[PA/2], PA+[PA/2]} (yes, before you ask, I did hack that last one in to replace the old RN{1...PA} formula because nobody liked the axe/bag/flail formula) It also leaves some extra space for people who want to hack new formulas/make older ones more complex. For anyone interested, you can now make a quick spreadsheet that can make any weapon type use any existing formula type. All you have to do is change the branch offsets to the start of the appropriate formula type.
The following documentation is mostly SA's, though I fixed a few bits (code is now in little-endian). All the offsets posted are RAM so you must subtract 0x67000 to get the BATTLE.BIN offset (which is 0x11EA9C).
00185a9c: 1980023C lui r2,0x8019 00185aa0: D8384290 lbu r2,0x38d8(r2) Load Used Weapon ID 00185aa4: E8FFBD27 addiu r29,r29,0xffe8 00185aa8: 1400BFAF sw r31,0x0014(r29) 00185aac: 1000B0AF sw r16,0x0010(r29) 00185ab0: 40180200 sll r3,r2,0x01 ID * 2 00185ab4: 21186200 addu r3,r3,r2 ID * 3 00185ab8: 80180300 sll r3,r3,0x02 ID * 12 00185abc: 0680013C lui r1,0x8006 00185ac0: 21082300 addu r1,r1,r3 80060000 + ID * 12 00185ac4: BD2E2390 lbu r3,0x2ebd(r1) Load Used Weapon Item Type 00185ac8: 1980023C lui r2,0x8019 00185acc: 942D428C lw r2,0x2d94(r2) Load Attacker's Data Pointer 00185ad0: 1980013C lui r1,0x8019 00185ad4: 36005090 lbu r16,0x0036(r2) Load Attacker's PA 00185ad8: 37004690 lbu r6,0x0037(r2) Load Attacker's MA 00185adc: 24004590 lbu r5,0x0024(r2) Load Attacker's Brave 00185ae0: 38004490 lbu r4,0x0038(r2) Load Attacker's SP 00185ae4: 32006010 beq r3,r0,0x00185bb0 Branch if bare-fisted 00185ae8: 01000234 ori r2,r0,0x0001 r2 = 1 00185aec: 2A006210 beq r3,r2,0x00185b98 Branch if Used Weapon is a Knife 00185af0: 02000234 ori r2,r0,0x0002 r2 = 2 00185af4: 28006210 beq r3,r2,0x00185b98 Branch if Used Weapon is a Ninjato 00185af8: 03000234 ori r2,r0,0x0003 r2 = 3 00185afc: 29006210 beq r3,r2,0x00185ba4 Branch if Used Weapon is a Sword 00185b00: 04000234 ori r2,r0,0x0004 r2 = 4 00185b04: 34006210 beq r3,r2,0x00185bd8 Branch if Used Weapon is a Knight Sword 00185b08: 05000234 ori r2,r0,0x0005 r2 = 5 00185b0c: 32006210 beq r3,r2,0x00185bd8 Branch if Used Weapon is a Katana 00185b10: 06000234 ori r2,r0,0x0006 r2 = 6 00185b14: 3B006210 beq r3,r2,0x00185c04 Branch if Used Weapon is a Axe 00185b18: 07000234 ori r2,r0,0x0007 r2 = 7 00185b1c: 21006210 beq r3,r2,0x00185ba4 Branch if Used Weapon is a Rod 00185b20: 08000234 ori r2,r0,0x0008 r2 = 8 00185b24: 1E006210 beq r3,r2,0x00185ba0 Branch if Used Weapon is a Staff 00185b28: 09000234 ori r2,r0,0x0009 r2 = 9 00185b2c: 35006210 beq r3,r2,0x00185c04 Branch if Used Weapon is a Flail 00185b30: 0A000234 ori r2,r0,0x000a r2 = 10 00185b34: 15006210 beq r3,r2,0x00185b8c Branch if Used Weapon is a Gun 00185b38: 0B000234 ori r2,r0,0x000b r2 = 11 00185b3c: 19006210 beq r3,r2,0x00185ba4 Branch if Used Weapon is a Crossbow 00185b40: 0C000234 ori r2,r0,0x000c r2 = 12 00185b44: 14006210 beq r3,r2,0x00185b98 Branch if Used Weapon is a Bow 00185b48: 0D000234 ori r2,r0,0x000d r2 = 13 00185b4c: 0D006210 beq r3,r2,0x00185b84 Branch if Used Weapon is a Instrument 00185b50: 0E000234 ori r2,r0,0x000e r2 = 14 00185b54: 0B006210 beq r3,r2,0x00185b84 Branch if Used Weapon is a Book 00185b58: 0F000234 ori r2,r0,0x000f r2 = 15 00185b5c: 11006210 beq r3,r2,0x00185ba4 Branch if Used Weapon is a Spear 00185b60: 10000234 ori r2,r0,0x0010 r2 = 16 00185b64: 0E006210 beq r3,r2,0x00185ba0 Branch if Used Weapon is a Stick 00185b68: 11000234 ori r2,r0,0x0011 r2 = 17 00185b6c: 25006210 beq r3,r2,0x00185c04 Branch if Used Weapon is a Bag 00185b70: 12000234 ori r2,r0,0x0012 r2 = 18 00185b74: 03006210 beq r3,r2,0x00185b84 Branch if Used Weapon is a Veil 00185b78: 00000000 nop 00185b7c: 1F170608 j 0x00185c7c Jump to WP = YA 00185b80: 00000000 nop 00185b84: 1D170608 j 0x00185c74 Jump to Halving 00185b88: 21100602 addu r2,r16,r6 PA + MA if Veil, Book, or Instrument 00185b8c: 02392290 lbu r2,0x3902(r1) Load WP 00185b90: 1F170608 j 0x00185c7c Jump to WP = YA 00185b94: CE3822A4 sh r2,0x38ce(r1) XA = WP, if Gun 00185b98: 1D170608 j 0x00185c74 Jump to Halving 00185b9c: 21100402 addu r2,r16,r4 PA + SP if Knife, Ninjato, or Bow 00185ba0: 1F170608 j 0x00185c7c Jump to WP = YA 00185ba4: CE3826A4 sh r6,0x38ce(r1) XA = MA, if Staff, Stick 00185ba8: 1F170608 j 0x00185c7c Jump to WP = YA 00185bac: CE3830A4 sh r16,0x38ce(r1) XA = PA, if Sword, Rod, Crossbow, Spear 00185bb0: 1800B000 mult r5,r16 Brave * PA 00185bb4: 12180000 mflo r3 r3 = Brave * PA 00185bb8: 8F02023C lui r2,0x028F 00185bbc: 285C4234 ori r2,r2,0x5C28 00185bc0: 19006200 multu r3,r2 Brave * PA * 0.01 00185bc4: 10100000 mfhi r2 r2 = Brave * PA * 0.01 00185bc8: 2D004014 bne r2,r0,0x00185c80 Branch if YA > 0 00185bcc: CE3830A4 sh r16,0x38ce(r1) Store XA = PA 00185bd0: 20170608 j 0x00185c80 ELSE, Jump to end 00185bd4: 01000224 addiu r2,r0,0x0001 r2 = 1 (minimum of 1 YA) 00185bd8: 1800B000 mult r5,r16 Brave * PA 00185bdc: 12180000 mflo r3 r3 = Brave * PA 00185be0: 8F02023C lui r2,0x028F 00185be4: 285C4234 ori r2,r2,0x5C28 00185be8: 19006200 multu r3,r2 Brave * PA * 0.01 00185bec: 10100000 mfhi r2 r2 = Brave * PA * 0.01 00185bf0: 02004014 bne r2,r0,0x00185bfc Branch if YA > 0 00185bf4: 00000000 nop 00185bf8: 01000224 addiu r2,r0,0x0001 ELSE, r2 = 1 (minimum of 1 YA) 00185bfc: 1F170608 j 0x00185c7c Jump to set WP 00185c00: CE3822A4 sh r2,0x38ce(r1) Store r2 as XA 00185c04: A83B060C jal 0x0018eea0 Random Process 00185c08: 00000000 nop 00185c0c: 18000202 mult r16,r2 PA * 0->7fff 00185c10: 12100000 mflo r2 r2 = PA * Random 00185c14: 02004104 bgez r2,0x00185c2c Branch if PA * Random >= 0 00185c18: 1980013C lui r1,0x8019 00185c1c: FF7F4224 addiu r2,r2,0x7fff Make result positive 00185c20: C3130200 sra r2,r2,0x0f PA * 0->7fff / 8000h (0->PA - 1) 00185c24: 01004224 addiu r2,r2,0x0001 r2 = (1->PA) 00185c28: 42181000 srl r3,r16,0x01 r3 = [PA / 2] 00185c2c: 21104300 addu r2,r2,r3 r2 = {1 + [PA / 2]->PA + [PA / 2]} 00185c30: 1F170608 j 0x00185c7c Jump to WP = YA 00185c34: CE3822A4 sh r2,0x38ce(r1) Store r2 as XA
0x185c38-0x185c73 can be used for new formulas.
00185c74: 43100200 sra r2,r2,0x01 PA + ?? / 2 (MA or SP, depending on Weapon) 00185c78: CE3822A4 sh r2,0x38ce(r1) Store XA = PA + ?? / 2 00185c7c: 02392290 lbu r2,0x3902(r1) Load WP 00185c80: 1400BF8F lw r31,0x0014(r29) 00185c84: D03822A4 sh r2,0x38d0(r1) YA = WP 00185c88: 1000B08F lw r16,0x0010(r29) 00185c8c: 0800E003 jr r31 00185c90: 1800BD27 addiu r29,r29,0x0018
Title: Re: Weapon Hacking Part I
Post by: formerdeathcorps on June 16, 2011, 09:01:29 am
All right, here's another variant of the above routine. This one, unfortunately, has no free-space, but it consolidates both the routines from http://ffhacktics.com/smf/index.php?topic=6548.0 without any more writes to Kanji space.
Given below is just the code in ASM and hex, so it is easy to C/P or analyze this.
RAM Offset: 0x185A9C lui r3,0x8019 lhu r1,0x38d6(r3) lbu r2,0x38d8(r3) beq r1,r0,0x00185ad4 lhu r3,0x38c4(r3) nop beq r3,r0,0x00185ad4 andi r2,r3,0x00ff beq r2,r0,0x00185ac8 sltiu r1,r2,0x007a bne r1,r0,0x00185ad4 srl r3,r3,0x08 j 0x00185ab0 nop addiu r29,r29,0xffe8 sw r31,0x0014(r29) sw r16,0x0010(r29) sll r3,r2,0x01 addu r3,r3,r2 sll r3,r3,0x02 lui r1,0x8006 addu r1,r1,r3 lbu r3,0x2ebd(r1) lui r2,0x8019 lw r2,0x2d94(r2) lui r1,0x8019 lbu r16,0x0036(r2) lbu r6,0x0037(r2) lbu r5,0x0024(r2) lbu r4,0x0038(r2) beq r3,r0,0x00185be0 ori r2,r0,0x0001 beq r3,r2,0x00185bc8 ori r2,r0,0x0002 beq r3,r2,0x00185bc8 ori r2,r0,0x0003 beq r3,r2,0x00185bd4 ori r2,r0,0x0004 beq r3,r2,0x00185c08 ori r2,r0,0x0005 beq r3,r2,0x00185c08 ori r2,r0,0x0006 beq r3,r2,0x00185c34 ori r2,r0,0x0007 beq r3,r2,0x00185bd4 ori r2,r0,0x0008 beq r3,r2,0x00185bd0 ori r2,r0,0x0009 beq r3,r2,0x00185c34 ori r2,r0,0x000a beq r3,r2,0x00185bbc ori r2,r0,0x000b beq r3,r2,0x00185bd4 ori r2,r0,0x000c beq r3,r2,0x00185bc8 ori r2,r0,0x000d beq r3,r2,0x00185bb4 ori r2,r0,0x000e beq r3,r2,0x00185bb4 ori r2,r0,0x000f beq r3,r2,0x00185bd4 ori r2,r0,0x0010 beq r3,r2,0x00185bd0 ori r2,r0,0x0011 beq r3,r2,0x00185c34 ori r2,r0,0x0012 beq r3,r2,0x00185bb4 nop j 0x00185c7c nop j 0x00185c74 addu r2,r16,r6 lbu r2,0x3902(r1) j 0x00185c7c sh r2,0x38ce(r1) j 0x00185c74 addu r2,r16,r4 j 0x00185c7c sh r6,0x38ce(r1) j 0x00185c7c sh r16,0x38ce(r1) mult r5,r16 mflo r3 lui r2,0x028f ori r2,r2,0x5c28 multu r3,r2 mfhi r2 bne r2,r0,0x00185cb0 sh r16,0x38ce(r1) j 0x00185c80 addiu r2,r0,0x0001 mult r5,r16 mflo r3 lui r2,0x028f ori r2,r2,0x5c28 multu r3,r2 mfhi r2 bne r2,r0,0x00185c2c nop addiu r2,r0,0x0001 j 0x00185c7c sh r2,0x38ce(r1) jal 0x0018eea0 nop mult r16,r2 mflo r2 bgez r2,0x00185c50 lui r1,0x8019 addiu r2,r2,0x7fff sra r2,r2,0x0f addiu r2,r2,0x0001 srl r3,r16,0x01 addu r2,r2,r3 j 0x00185c7c sh r2,0x38ce(r1) nop nop nop sra r2,r2,0x01 sh r2,0x38ce(r1) lbu r2,0x3902(r1) lw r31,0x0014(r29) sh r2,0x38d0(r1) lw r16,0x0010(r29) jr r31 addiu r29,r29,0x0018
Known bugs: 1) Displayed pre-attack damage on flails/axes/bags is still normal 2) Guns now take evasion if you use Formula 01 3) Revised routine cannot use Formula 01 for damage on non-attack skills correctly if setup is RH: Nothing/LH: Shield (this I'll try to fix)
Title: Re: Weapon Hacking Part I
Post by: FFMaster on June 25, 2011, 12:50:24 am
The revised version should be a grab for anyone planning to use formula 01 or 02 for abilities. It fixes the Gun bug, meaning no abuse for 999 damage anymore.
Title: Re: Weapon Hacking Part I
Post by: FFMaster on June 25, 2011, 08:19:30 am
Running it in Arena, it seems to be causing some crashes. Happened twice so far, once for a Gobbledeguck, and once for a Mime. It has not happen to player controlled units yet. Not sure about vanilla though.
Title: Re: Weapon Hacking Part I
Post by: FFMaster on June 27, 2011, 02:46:48 am
OK, FDC and I have managed to fix the crashing. Here is another revised code!
Title: Re: Weapon Hacking Part I
Post by: LastingDawn on June 27, 2011, 10:46:34 am
Now This needs a spreadsheet! But would it really be easy to make a spreadsheet of this? Hmm... all in all it seems a bit... complex for ordinary people to easily use, any thoughts to making this into a spreadsheet Raven by chance?
All in all great work there fellows!
Title: Re: Weapon Hacking Part I
Post by: formerdeathcorps on June 27, 2011, 10:50:21 pm
Quote from: LastingDawn on June 27, 2011, 10:46:34 am Now This needs a spreadsheet! But would it really be easy to make a spreadsheet of this? Hmm... all in all it seems a bit... complex for ordinary people to easily use, any thoughts to making this into a spreadsheet Raven by chance?
It's complex because I don't have a data table. What you want to edit are where the beq commands are branching to.
Title: Re: Weapon Hacking Part I
Post by: FFMaster on June 28, 2011, 07:46:38 pm
Hack is still crashing for fists on ePSXe. Doesn't happen on the exact same ISO for psxfin. Not sure about pSX.
And it only happens for fist attacks.
EDIT: Seems like it only happens in my Arena ISO. I'll work out what is wrong later. The hack works fine in a vanilla ISO.
Title: Re: Weapon Hacking Part I
Post by: formerdeathcorps on June 29, 2011, 09:02:25 am
FFM noticed that Martial Arts boosts all attacks other than weapon attacks using 01. Here's a fix.
NOTE: This overrides every single existing hack that addresses 2 Hands, Martial Arts, or ATTACK UP. This also overrides the ability for martial arts to boost STEAL, PUNCH ART, or Throw Stone if you are equipping a weapon.
I deliberately coded the above hack with free-space so for those of you who want to write routines that allow for 2 Hands/Martial Arts/ATKUP having different multipliers, there's plenty of space for you to do so. There's also enough space at the end to write a check for a new physical support ability.
Title: Re: Weapon Hacking Part I
Post by: RavenOfRazgriz on June 29, 2011, 02:43:32 pm
This bit kinda sucks, you lose a noteable bit of character customization with it. (Mostly, the choice to go random dipshit with Ice Brand / Ice Shield / etc... Primary Skillset / Punch Art or Steal / etc... for the higher Punch Art boost over Attack UP or the choice to for whatever reason use an Equip X Monk, etc.) Is there no particular way to fix it without over 9000 headaches?
This looks like it's near the point I can finally begin putting it to spreadsheet though.
Title: Re: Weapon Hacking Part I
Post by: Pride on June 29, 2011, 07:13:27 pm
FDC.... Punch Art, Steal, Throw Stone, and a few other formulas aren't checked in that section for Martial Arts. They are checked in the second section for Martial Arts at ram 0018614c.