Base Weapon XA Rewrite

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search

This is essentially a rewrite of FDC's Weapon XA hack to save space or to allow additional new weapon formulas by removing the large branching sequence that was present. As with FDC's hack retains all the original vanilla functions along with giving more access to changing the weapon formulas, removing the Gun formula 01 bug and allows Abilities to properly use Formula 01 without glitches and bugs.

Addresses starting at 0x00185c48 form a lookup table read by the instruction at 0x00185b4c and can be customized to change which weapons use which formula.

00185a9c: 3c038019 lui r3,0x8019		
00185aa0: 946138d6 lhu r1,0x38d6(r3)		Load Ability Formula
00185aa4: 906238d8 lbu r2,0x38d8(r3)		Load Used Weapon ID
00185aa8: 1020000a beq r1,r0,0x00185ad4		Branch if using a Weapon, not an Ability
00185aac: 946338c4 lhu r3,0x38c4(r3)		Load Right and Left Arm equipment
00185ab0: 00000000 nop				
00185ab4: 10600007 beq r3,r0,0x00185ad4		Branch if no equipment is present
00185ab8: 306200ff andi r2,r3,0x00ff		
00185abc: 10400002 beq r2,r0,0x00185ac8		
00185ac0: 2c41007a sltiu r1,r2,0x007a		
00185ac4: 14200003 bne r1,r0,0x00185ad4		Branch if Equipment ID = Weapon ID
00185ac8: 00031a02 srl r3,r3,0x08		Prepare r3 to check other arm equipment
00185acc: 080616ac j 0x00185ab0			
00185ad0: 00000000 nop				
00185ad4: 27bdffe0 addiu r29,r29,0xffe0		Make more room in the stack
00185ad8: afbf0018 sw r31,0x0018(r29)		
00185adc: afb10014 sw r17,0x0014(r29)		
00185ae0: afb00010 sw r16,0x0010(r29)		
00185ae4: 00021840 sll r3,r2,0x01		ID * 2
00185ae8: 00621821 addu r3,r3,r2		ID * 3
00185aec: 00031880 sll r3,r3,0x02		ID * 12
00185af0: 3c018006 lui r1,0x8006		
00185af4: 00230821 addu r1,r1,r3		0x80060000 + ID * 12
00185af8: 90222ebd lbu r2,0x2ebd(r1)		Load Weapon Item type
00185afc: 3c018018 lui r1,0x8018		
00185b00: 00021080 sll r2,r2,0x02		Item Type * 4
00185b04: 00220821 addu r1,r1,r2		0x80180000 + Item type * 4
00185b08: 8c225c48 lw r2,0x5c48(r1)		Load Weapon Formula Offset
00185b0c: 3c018019 lui r1,0x8019		
00185b10: 8c232d94 lw r3,0x2d94(r1)		Load Attacker's Data
00185b14: 00000000 nop				
00185b18: 90660024 lbu r6,0x0024(r3)		Load Attacker's Brave
00185b1c: 90650038 lbu r5,0x0038(r3)		Load Attacker's Speed
00185b20: 90640036 lbu r4,0x0036(r3)		Load Attacker's PA
00185b24: 90630037 lbu r3,0x0037(r3)		Load Attacker's MA
00185b28: 00860018 mult r4,r6			PA * Brave
00185b2c: 00008812 mflo r17			Move to r17
00185b30: 3c10028f lui r16,0x028f		
00185b34: 36105c28 ori r16,r16,0x5c28		
00185b38: 02300019 multu r17,r16		PA * Brave / 100
00185b3c: 00008810 mfhi r17			Move hi to r17
00185b40: 16200002 bne r17,r0,0x00185b4c	Branch if PA * Brave =/= 0
00185b44: 00000000 nop				
00185b48: 34110001 ori r17,r0,0x0001		Set r17 to 1 (to prevent 0 damage dealt)
00185b4c: 90303902 lbu r16,0x3902(r1)		Load Weapon Power
00185b50: 00400008 jr r2			Jump to Weapon Formula
00185b54: 00000000 nop				
00185b58: a42438ce sh r4,0x38ce(r1)		Store PA as XA
00185b5c: 0806170d j 0x00185c34			Jump to end
00185b60: a43138d0 sh r17,0x38d0(r1)		Store PA * Brave / 100 as YA
00185b64: 0806170c j 0x00185c30			Jump to store Weapon Power
00185b68: a42338ce sh r3,0x38ce(r1)		Store MA as XA
00185b6c: 0806170c j 0x00185c30			Jump to store Weapon Power
00185b70: a42438ce sh r4,0x38ce(r1)		Store PA as XA
00185b74: 0806170c j 0x00185c30			Jump to store Weapon Power
00185b78: a43038ce sh r16,0x38ce(r1)		Store Weapon Power as XA
00185b7c: 0806170c j 0x00185c30			Jump to store Weapon Power
00185b80: a43138ce sh r17,0x38ce(r1)		Store PA * Brave / 100 as XA
00185b84: 0806170a j 0x00185c28			Jump to Divide
00185b88: 00852021 addu r4,r4,r5		PA + Speed
00185b8c: 0806170a j 0x00185c28			Jump to Divide
00185b90: 00832021 addu r4,r4,r3		PA + MA
00185b94: 0c063ba8 jal 0x0018eea0		Random Process (return r2 0x0000 ---> 0x7fff)
00185b98: 00000000 nop				
00185b9c: 00820018 mult r4,r2			Random * PA
00185ba0: 00001012 mflo r2			Move to r2
00185ba4: 04410002 bgez r2,0x00185bb0		Branch if PA * Random > 0
00185ba8: 3c018019 lui r1,0x8019		Set r1 to 0x80190000 (0018eea0 reset it)
00185bac: 24427fff addiu r2,r2,0x7fff		Make result positive
00185bb0: 000213c3 sra r2,r2,0x0f		PA * Random / 0x8000
00185bb4: 0806170b j 0x00185c2c			Jump to store XA
00185bb8: 24440001 addiu r4,r2,0x0001		(PA * Random) + 1
00185bbc: 00000000 nop				
00185bc0: 00000000 nop				
00185bc4: 00000000 nop				
00185bc8: 00000000 nop				
00185bcc: 00000000 nop				
00185bd0: 00000000 nop				
00185bd4: 00000000 nop				
00185bd8: 00000000 nop				
00185bdc: 00000000 nop				
00185be0: 00000000 nop				
00185be4: 00000000 nop				
00185be8: 00000000 nop				
00185bec: 00000000 nop				
00185bf0: 00000000 nop				
00185bf4: 00000000 nop				
00185bf8: 00000000 nop				
00185bfc: 00000000 nop				
00185c00: 00000000 nop				
00185c04: 00000000 nop				
00185c08: 00000000 nop				
00185c0c: 00000000 nop				
00185c10: 00000000 nop				
00185c14: 00000000 nop				
00185c18: 00000000 nop				
00185c1c: 00000000 nop				
00185c20: 00000000 nop				
00185c24: 00000000 nop				
00185c28: 00042042 srl r4,r4,0x01		PA + (MA or Sp) / 2
00185c2c: a42438ce sh r4,0x38ce(r1)		Store XA
00185c30: a43038d0 sh r16,0x38d0(r1)		Store Weapon Power as YA
00185c34: 8fbf0018 lw r31,0x0018(r29)		
00185c38: 8fb10014 lw r17,0x0014(r29)		
00185c3c: 8fb00010 lw r16,0x0010(r29)		
00185c40: 03e00008 jr r31			
00185c44: 27bd0020 addiu r29,r29,0x0020		
00185c48: 80185b58 lb r24,0x5b58(r0)		Fist Formula
00185c4c: 80185b84 lb r24,0x5b84(r0)		Knife Formula
00185c50: 80185b84 lb r24,0x5b84(r0)		Ninja Blade Formula
00185c54: 80185b6c lb r24,0x5b6c(r0)		Sword Formula
00185c58: 80185b7c lb r24,0x5b7c(r0)		Knight Sword Formula
00185c5c: 80185b7c lb r24,0x5b7c(r0)		Katana Formula
00185c60: 80185b94 lb r24,0x5b94(r0)		Axe Formula
00185c64: 80185b6c lb r24,0x5b6c(r0)		Rod Formula
00185c68: 80185b64 lb r24,0x5b64(r0)		Staff Formula
00185c6c: 80185b94 lb r24,0x5b94(r0)		Flail Formula
00185c70: 80185b74 lb r24,0x5b74(r0)		Gun Formula
00185c74: 80185b6c lb r24,0x5b6c(r0)		Crossbow Formula
00185c78: 80185b84 lb r24,0x5b84(r0)		Bow Formula
00185c7c: 80185b8c lb r24,0x5b8c(r0)		Instrument Formula
00185c80: 80185b8c lb r24,0x5b8c(r0)		Book Formula
00185c84: 80185b6c lb r24,0x5b6c(r0)		Polearm Formula
00185c88: 80185b64 lb r24,0x5b64(r0)		Pole Formula
00185c8c: 80185b94 lb r24,0x5b94(r0)		Bag Formula
00185c90: 80185b8c lb r24,0x5b8c(r0)		Cloth Formula