Compatibility

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
No Parameters - Return Nothing             #secondadvent Compatibility patch

Determine Compatibility (see Notes)
Modify Ability XA ( 0x801938ce ) if needed
 - Bad   : XA = 75% of base XA
 - Worst : XA = 50% of base XA
 - Good  : XA = 125% of base XA
 - Best  : XA = 150% of base XA
----------------------------------------------------------------------------------------------------------------
00184964: 27bdfff8 addiu r29,r29,-0x0008    |
00184968: 3406000c ori r6,r0,0x000c         |r6 = 0x0c
0018496c: 3c028019 lui r2,0x8019            |
00184970: 8c422d94 lw r2,0x2d94(r2)         |r2 = Attacker's Data Pointer
00184974: 3c038019 lui r3,0x8019            |
00184978: 8c632d98 lw r3,0x2d98(r3)         |r3 = Target's Data Pointer
0018497c: 94420008 lhu r2,0x0008(r2)        |r2 = Attackers [0x08] & Zodiac (halfword)
00184980: 94630008 lhu r3,0x0008(r3)        |r2 = Target's [0x08] & Zodiac (halfword)
00184984: 00022302 srl r4,r2,0x0c           |r4 = Attacker's Zodiac (Nibble)  Taurus is 0x1 - Serpentarius is 0xc
00184988: 00031b02 srl r3,r3,0x0c           |r3 = Target's Zodiac
0018498c: 00802821 addu r5,r4,r0            |r5 = Attacker's Zodiac
00184990: 10a60061 beq r5,r6,0x00184b18     #If Attacker's Zodiac is Serpentarius /Branch to END
00184994: 00601021 addu r2,r3,r0                |r2 = Target's Zodiac
00184998: 3042ffff andi r2,r2,0xffff            |r2 = Target's Zodiac
0018499c: 1046005e beq r2,r6,0x00184b18         #Branch if Target is Serpentarius /Branch to END
001849a0: 0045102b sltu r2,r2,r5                    |r2 = 0x01
001849a4: 14400002 bne r2,r0,0x001849b0             #If Target's Sign is lower  than Attacker's
001849a8: 00831023 subu r2,r4,r3                    |r2 = Attacker's Zodiac - Target's Zodiac (Zodiac Difference)
001849ac: 00641023 subu r2,r3,r4                        |r2 = Target's Zodiac - Attacker's Zodiac  (Zodiac Difference)
001849b0: 3042ffff andi r2,r2,0xffff                |r2 = Zodiac difference
001849b4: 3c018019 lui r1,0x8019                    |
001849b8: 00220821 addu r1,r1,r2                    |r1 = 80190000 + Zodiac difference (offset)
001849bc: 9024f600 lbu r4,-0x0a00(r1)               |r4 = Compat Modifier (0x8018f600 + Zodiac difference)
001849c0: 34020003 ori r2,r0,0x0003                 |r2 = 0x03
001849c4: 308300ff andi r3,r4,0x00ff                |r3 = Compat Modifier
001849c8: 14620015 bne r3,r2,0x00184a20             #If Compat Mod is Best/Worst /Else Branch keeping r4 as loaded
001849cc: 00000000 nop                                  |
001849d0: 3c028019 lui r2,0x8019                        |
001849d4: 8c422d94 lw r2,0x2d94(r2)                     |r2 = Attacker's Data Pointer
001849d8: 00000000 nop                                  |
001849dc: 90430006 lbu r3,0x0006(r2)                    |r3 =  Attacker's Gender byte
001849e0: 00000000 nop                                  |
001849e4: 30620020 andi r2,r3,0x0020                    |r2 = 0x20 if Attacker is a Monster
001849e8: 1440000d bne r2,r0,0x00184a20                 #If Attacker is a not Monster /If Monster Branch (keeping r4 = 0x01)
001849ec: 34040001 ori r4,r0,0x0001                     |r4 = 0x01 (Bad Compat Mod)
001849f0: 3c028019 lui r2,0x8019                            |
001849f4: 8c422d98 lw r2,0x2d98(r2)                         |r2 = Target data pointer
001849f8: 00000000 nop                                      |
001849fc: 90450006 lbu r5,0x0006(r2)                        |r5 = Target's Gender byte
00184a00: 00000000 nop                                      |
00184a04: 30a20020 andi r2,r5,0x0020                        |r2 = 0x20 <if Target is a monster
00184a08: 14400005 bne r2,r0,0x00184a20                     #If Target is not a Monster /If Monster Branch (keeping r4 = 0x01)
00184a0c: 306300c0 andi r3,r3,0x00c0                            |r3 = Attacker's Gender (0x80 or 0x40)
00184a10: 30a200c0 andi r2,r5,0x00c0                            |r3 = Target's Gender (0x80 or 0x40)
00184a14: 14620002 bne r3,r2,0x00184a20                         #If Target and Attacker are of the same gender /If Different gender Branch (keeping r4 = 0x05)
00184a18: 34040005 ori r4,r0,0x0005                             |r4 = 0x05 (Best Compat Mod)
00184a1c: 34040004 ori r4,r0,0x0004                                 |r4 =0x04 (Worst Compat Mod)
00184a20: 3c078019 lui r7,0x8019                    |
00184a24: 24e738ce addiu r7,r7,0x38ce               |r7 = 0x801938ce (Ability XA pointer)  801938ce
00184a28: 84e20000 lh r2,0x0000(r7)                 |r2 = Ability XA
00184a2c: 00000000 nop                              |
00184a30: 00021840 sll r3,r2,0x01                   |XA * 2
00184a34: 00621821 addu r3,r3,r2                    |XA * 3
00184a38: 000318c0 sll r3,r3,0x03                   |XA * 24
00184a3c: 00622821 addu r5,r3,r2                    |r5 = Ability XA * 25
00184a40: 00403021 addu r6,r2,r0                    |r6 = Ability XA
00184a44: 308300ff andi r3,r4,0x00ff                |r3 = Compat Mod (0x00 - 0x01 - 0x02 - 0x04 or 0x05)
00184a48: 34020002 ori r2,r0,0x0002                 |r2 = 0x02
00184a4c: 1062000f beq r3,r2,0x00184a8c             #If Compat mod is NOT Good (<> 0x02) /If Compat Mod is Good branch to XA Good section
00184a50: 30a2ffff andi r2,r5,0xffff                |r2 = XA * 25
00184a54: 28620003 slti r2,r3,0x0003                    |r2 = 0x01 if Compat is Neutral or Bad
00184a58: 10400005 beq r2,r0,0x00184a70                 #If Compat Mod is Neutral or Bad
00184a5c: 34020001 ori r2,r0,0x0001                         |r2 =0x01
00184a60: 10620018 beq r3,r2,0x00184ac4                     #If Compat Mod is Neutral (by default) /If Compat Mod is Bad branch to XA Bad section
00184a64: 3c0351eb lui r3,0x51eb                                |
00184a68: 080612bf j 0x00184afc                                 >>Jump past XA modification  (just checking XA > 0x00)
00184a6c: 00000000 nop                                          |
00184a70: 34020004 ori r2,r0,0x0004                     |r2 = 0x04
00184a74: 10620019 beq r3,r2,0x00184adc                 #If Compat Mod is not Worst /If Compat is Worst branch to XA worst section
00184a78: 34020005 ori r2,r0,0x0005                         |r2 = 0x05
00184a7c: 1062000a beq r3,r2,0x00184aa8                     #If Compat Mod is not Best /If Compat is Best branch to XA best section
00184a80: 3c0351eb lui r3,0x51eb                                |
00184a84: 080612bf j 0x00184afc                                 >>Jump past XA modification  (just checking XA > 0x00)
00184a88: 00000000 nop                                          |

 -- Modify XA : GOOD section --
00184a8c: 3c0351eb lui r3,0x51eb                    |
00184a90: 3463851f ori r3,r3,0x851f                 |r3 = 0x51eb851f  (0,32 * 2^32)
00184a94: 00430019 multu r2,r3                      |XA * 25 * 0.32 * 2^32
00184a98: 00001010 mfhi r2                          |r2 = XA * 8 (XA * 25 * 0.32)
00184a9c: 00021142 srl r2,r2,0x05                   |r2 = XA / 4
00184aa0: 080612be j 0x00184af8                     >>Jump to Store XA section (XA = 125% of base XA)
00184aa4: 00c21021 addu r2,r6,r2                    |r2 = XA + XA / 4 (XA*5/4)

 -- Modify XA : BEST section --
00184aa8: 3463851f ori r3,r3,0x851f                 |r3 = 0x51eb851f  (0,32 * 2^32)
00184aac: 30a2ffff andi r2,r5,0xffff                |r2 = XA*25
00184ab0: 00430019 multu r2,r3                      |XA * 25 * 0.32 * 2^32
00184ab4: 00001010 mfhi r2                          |r2 = XA * 8 (XA * 25 * 0.32)
00184ab8: 00021102 srl r2,r2,0x04                   |r2 = XA / 2
00184abc: 080612be j 0x00184af8                     >>Jump to Store XA section (XA = 150% of base XA)
00184ac0: 00c21021 addu r2,r6,r2                    |r2 = XA + XA / 2 (XA * 3/2)

 -- Modify XA : BAD section --
00184ac4: 3463851f ori r3,r3,0x851f                 |r3 = 0x51eb851f  (0,32 * 2^32)
00184ac8: 30a2ffff andi r2,r5,0xffff                |r2 = Ability XA *25
00184acc: 00430019 multu r2,r3                      |XA * 25 * 0.32 * 2^32
00184ad0: 00001010 mfhi r2                          |r2 = Ability XA *8
00184ad4: 080612bd j 0x00184af4                     >>Jump just before Store XA section (XA will be XA- 25%XA)
00184ad8: 00021142 srl r2,r2,0x05                   |r2 = XA/4

 -- Modify XA : WORST section --
00184adc: 3c0351eb lui r3,0x51eb                    |
00184ae0: 3463851f ori r3,r3,0x851f                 |r3 = 0x51eb851f  (0,32 * 2^32)
00184ae4: 30a2ffff andi r2,r5,0xffff                |r2 = Ability XA *25
00184ae8: 00430019 multu r2,r3                      |XA * 25 * 0.32 * 2^32
00184aec: 00001010 mfhi r2                          |r2 = Ability XA *8
00184af0: 00021102 srl r2,r2,0x04                   |r2 = XA/2  
00184af4: 00c21023 subu r2,r6,r2                >j  | r2 = XA - r2 (r2 = XA/4 if Bad compat  Or XA/2 if Worst compat)

 -- ALL (Ending) section --
00184af8: a4e20000 sh r2,0x0000(r7)             >j  | Store new XA (jumps from good and best section)
00184afc: 3c038019 lui r3,0x8019                >j  | (Neutral jump landing site)
00184b00: 246338ce addiu r3,r3,0x38ce               |r3 = Ability XA pointer
00184b04: 84620000 lh r2,0x0000(r3)                 |r2 = Ability XA
00184b08: 00000000 nop                              |
00184b0c: 1c400002 bgtz r2,0x00184b18               #If XA <= 0x00
00184b10: 34020001 ori r2,r0,0x0001                     |r2 = 0x01
00184b14: a4620000 sh r2,0x0000(r3)                     |Store XA = 1
00184b18: 27bd0008 addiu r29,r29,0x0008    END           
00184b1c: 03e00008 jr r31                   
00184b20: 00000000 nop                      

Notes

If Target or Attacker is Serpentarius Compat is Neutral
Compatibility is defined by Substracting Zodiac signs Nibble : 0x01 = Taurus to 0x0c = Serpentarius

Zodiac difference is used as an offset to load a byte at 0x8018f00 : 
Offset    Value    Compat
0x00      0x00     Neutral (same sign)
0x01      0x00     Neutral
0x02      0x00     Neutral
0x03      0x01     Bad
0x04      0x02     Good
0x05      0x00     Neutral
0x06      0x03     Best/Worst - drives to Gender Comparison 
0x07      0x00     Neutral
0x08      0x02     Good
0x09      0x01     Bad
0x0a      0x00     Neutral
0x0b      0x00     Neutral 

Gender Comparison :
 - Monster (Target or Attacker) : Compat Mod set to 0x01 : Bad 
 - Same Gender : Compat mod set to Worst : 0x04 
 - Different Gender : Compat mod set to Best : 0x05

Return Locations

Battle.bin
001865d8:  Set XA + YA for Status Formulas (Stupid section)
00188628:  Physical XA Modifying Statuses/Support 
0018876c:  Magical Support/Status/Compat
00188818:  MA + X
00188870:  Magical XA * YA
00188b04:  Cluster of Physical Routines
00188d54:  07 Heal_(Weapon)
00189020:  0E Dmg_(Y)% Hit_F(MA+X)% 100% Status Hide Status
001898b8:  28 StealExp_(Lowest of TarCurExp & SP+Y) Hit_(SP+X)%
00189928:  29 OppositeSex: Hit_(MA+X)%
00189a4c:  2A Hit_(MA+X)% // AffectBraveOrFaith(Y)
00189e50:  33 Hit_(PA+X)% 
00189eb4:  34 Heal_(PA*Y) HealMP_(PA*Y/2)
00189f28:  35 Heal_(Y)% Hit_(PA+X)%
0018a194:  42 Dmg_(PA*Y) DmgCas_(PA*Y/X)
0018a510:  51 Hit_(MA+X)%
0018a84c:  58 Generic: Set_Morbol: Hit(MA+X)%

secondadvent Compatibility patch

A rewrite thanks to SecondAdvent.

This rewrite saves a large amount of space (from 0x80184a2C to 0x80184b23) and gives freedom to change the compatibility damage changes as well as an accessory to neutralize compatibility damage.

00184964: 340600XX ori r6,r0,0x00XX		r6 = Accessory ID (for Neutralization)
00184968: 3c078019 lui r7,0x8019
0018496c: 8ce22d94 lw r2,0x2d94(r7)		Load Attacker's Data Pointer
00184970: 8ce32d98 lw r3,0x2d98(r7)		Load Target's Data Pointer
00184974: 9045001c lbu r5,0x001c(r2)		Load Attacker's Accessory ID
00184978: 9064001c lbu r4,0x001c(r3)		Load Target's Accessory ID
0018497c: 10a60029 beq r5,r6,0x00184a24		Branch if Attacker has Neutralization Accessory
00184980: 3401000c ori r1,r0,0x000c		r1 = 0c (Serpentarius)
00184984: 90450009 lbu r5,0x0009(r2)		Load Attacker's Zodiac
00184988: 10860026 beq r4,r6,0x00184a24		Branch if Target has Neutralization Accessory
0018498c: 00052902 srl r5,r5,0x04		r5 = Attacker's Zodiac
00184990: 90640009 lbu r4,0x0009(r3)		Load Target's Zodiac
00184994: 10a10023 beq r5,r1,0x00184a24		Branch if Attacker is Serpentarius
00184998: 00042102 srl r4,r4,0x04		r4 = Target's Zodiac
0018499c: 10810021 beq r4,r1,0x00184a24		Branch if Target is Serpentarius
001849a0: 0085302b sltu r6,r4,r5
001849a4: 14060002 bne r0,r6,0x001849b0		Branch if Target's Zodiac < Attacker's Zodiac
001849a8: 00a40823 subu r1,r5,r4		r1 = AZ - TZ
001849ac: 00850823 subu r1,r4,r5		r1 = TZ - AZ
001849b0: 84e538ce lh r5,0x38ce(r7)		Load XA
001849b4: 00e13021 addu r6,r7,r1
001849b8: 90c6f600 lbu r6,-0x0a00(r6)		Load Compat Modifier
001849bc: 34010003 ori r1,r0,0x0003		r1 = 3 (Opposing)
001849c0: 90420006 lbu r2,0x0006(r2)		Load Attacker's Gender byte
001849c4: 90630006 lbu r3,0x0006(r3)		Load Target's Gender byte
001849c8: 14c10009 bne r6,r1,0x001849f0		Branch if Compat Mod is not Opposing
001849cc: 00622025 or r4,r3,r2
001849d0: 30840020 andi r4,r4,0x0020
001849d4: 1480000b bne r4,r0,0x00184a04		Branch if either is a Monster
001849d8: 304200c0 andi r2,r2,0x00c0		r2 = Attacker's Gender
001849dc: 306300c0 andi r3,r3,0x00c0		r3 = Target's Gender
001849e0: 14620009 bne r3,r2,0x00184a08		Branch if Genders are Different
001849e4: 34010XXX ori r1,r0,0x0XXX		r1 = XXX (best modifier)
001849e8: 08061282 j 0x00184a08
001849ec: 34010XXX ori r1,r0,0x0XXX		r1 = XXX (worst modifier)
001849f0: 34010XXX ori r1,r0,0x0XXX		r1 = XXX (good modifier)
001849f4: 34020002 ori r2,r0,0x0002		r2 = 2 (Good)
001849f8: 10460003 beq r2,r6,0x00184a08		Branch if they have Good compat
001849fc: 34030001 ori r3,r0,0x0001		r3 = 1 (Bad)
00184a00: 14660008 bne r3,r6,0x00184a24		Branch if they have Neutral compat
00184a04: 34010XXX ori r1,r0,0x0XXX		r1 = XXX (bad modifier)
00184a08: 00250019 multu r1,r5			XA * XXX (X modifier)
00184a0c: 00002812 mflo r5			r5 = XA * XXX
00184a10: 00052a02 srl r5,r5,0x08		XA * XXX / 256
00184a14: 1ca00002 bgtz r5,0x00184a20		Branch if XA is positive
00184a18: 00000000 nop
00184a1c: 34050001 ori r5,r0,0x0001		XA = 1
00184a20: a4e538ce sh r5,0x38ce(r7)		Store XA
00184a24: 03e00008 jr r31
00184a28: 00000000 nop