Difference between revisions of "Magic Gun Ability Decision"

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
(Created page with " Magic Gun Ability Decision: 00187730: 27bdffe8 addiu r29,r29,0xffe8 00187734: afb00010 sw r16,0x0010(r29) 00187738: 3c108019 lui r16,0x8019 0018773c: 92103904 lbu r16,0x3...")
 
m
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
  Magic Gun Ability Decision:
+
  No Parameters - Returns Nothing
  00187730: 27bdffe8 addiu r29,r29,0xffe8
+
  00187734: afb00010 sw r16,0x0010(r29)
+
Uses The Gun Element to determine which spell type will be cast.
  00187738: 3c108019 lui r16,0x8019
+
Only one element is taken into account. The others will be ignored : First Fire, then Thunder, finally Ice. 
  0018773c: 92103904 lbu r16,0x3904(r16) Load Weapon's Element
+
(Note that Ice is default, everything not fire/thunder will end to cast an ice spell)
  00187740: afbf0014 sw r31,0x0014(r29)
+
  00187744: 0c063ba8 jal 0x0018eea0 Random Process
+
The tier of the cast spell is randomly chosen :
  00187748: 00000000 nop
+
  - 10% of chances to cast tier 3
  0018774c: 00021840 sll r3,r2,0x01 Random * 2
+
  - 30% of chances to cast tier 2
  00187750: 00621821 addu r3,r3,r2 Random * 3
+
  - 60% of chances to cast tier 1
  00187754: 000318c0 sll r3,r3,0x03 Random * 24
+
  00187758: 00621821 addu r3,r3,r2 Random * 25
+
Magic gun ability ID is hardcoded.
  0018775c: 00031880 sll r3,r3,0x02 Random * 100 (or mult r2, r3 with  r3 = 64)
+
Magic gun ability data will be stored in current ability section (0x801938f0 to 0x801938fd)
  00187760: 04610002 bgez r3,0x0018776c Branch if Random is Positive
+
------------------------------------------------------------------------------------------------------
  00187764: 32020080 andi r2,r16,0x0080
+
  00187730: 27bdffe8 addiu r29,r29,-0x0018    |
  00187768: 24637fff addiu r3,r3,0x7fff Random + 7fff
+
  00187734: afb00010 sw r16,0x0010(r29)       |
  0018776c: 1040000b beq r2,r0,0x0018779c Branch if Weapon doesn't have Fire
+
  00187738: 3c108019 lui r16,0x8019           |
  00187770: 00031bc2 srl r3,r3,0x0f Random / 8000 (rand 0..99)
+
  0018773c: 92103904 lbu r16,0x3904(r16)     |{{f/load|<nowiki>r16 = Current Ability Weapon's Element</nowiki>}} {{f/std|  0x80193904 / 80193904}}
  00187774: 306400ff andi r4,r3,0x00ff
+
  00187740: afbf0014 sw r31,0x0014(r29)       |
  00187778: 2c82000a sltiu r2,r4,0x000a
+
  00187744: 0c063ba8 jal 0x0018eea0           |{{f/jal|Random_Process,_gives_a_number_between_0-7fff|Random Process}}  Returns r2 between 0x00 and 0x7fff
  0018777c: 10400003 beq r2,r0,0x0018778c Branch if Random > a (90% chance to branch)
+
  00187748: 00000000 nop                     |
  00187780: 2c820028 sltiu r2,r4,0x0028
+
  0018774c: 00021840 sll r3,r2,0x01           |{{f/std|Random * 2}}
  00187784: 08061dfb j 0x001877ec
+
  00187750: 00621821 addu r3,r3,r2           |{{f/std|Random * 3}}
  00187788: 34030012 ori r3,r0,0x0012 r3 = 12 (Firaga, 10% chance )
+
  00187754: 000318c0 sll r3,r3,0x03           |{{f/std|Random * 24}}
  0018778c: 10400017 beq r2,r0,0x001877ec Branch if Random > 28 (60% chance  to branch)
+
  00187758: 00621821 addu r3,r3,r2           |{{f/std|Random * 25}}
  00187790: 34030010 ori r3,r0,0x0010 r3 = 10 (Fire, 60% chance)
+
  0018775c: 00031880 sll r3,r3,0x02           |{{f/std|Random * 100}}
  00187794: 08061dfb j 0x001877ec
+
  00187760: 04610002 bgez r3,0x0018776c       {{f/Cond|If Random < 0x00}}
  00187798: 34030011 ori r3,r0,0x0011 r3 = 11 (Fira, 30% chance)
+
  00187764: 32020080 andi r2,r16,0x0080       |{{f/std|r2 <> 0x00 if Weapon Element is Fire}}
  0018779c: 32020040 andi r2,r16,0x0040
+
  00187768: 24637fff addiu r3,r3,0x7fff           |{{f/std|Make random positive}}
  001877a0: 1040000a beq r2,r0,0x001877cc Branch if Weapon doesn't have  Lightning
+
  0018776c: 1040000b beq r2,r0,0x0018779c     {{f/Cond|If Weapon Element has Fire}}
  001877a4: 306400ff andi r4,r3,0x00ff
+
  00187770: 00031bc2 srl r3,r3,0x0f               |{{f/std|<nowiki>r3 = Random between 0 and 99</nowiki>}} {{f/std| (100 x Random / [Max possible random + 1])}}
  001877a8: 2c82000a sltiu r2,r4,0x000a
+
  00187774: 306400ff andi r4,r3,0x00ff           |{{f/std|<nowiki>r4 = Random number in a byte (useless if everything is ok)</nowiki>}}
  001877ac: 10400003 beq r2,r0,0x001877bc Branch if Ranfom > a
+
  00187778: 2c82000a sltiu r2,r4,0x000a           |{{f/std|<nowiki>r2 = 0x01 if Random < 10</nowiki>}}
  001877b0: 2c820028 sltiu r2,r4,0x0028
+
  0018777c: 10400003 beq r2,r0,0x0018778c         {{f/Cond|If Random < 10}}
  001877b4: 08061dfb j 0x001877ec
+
  00187780: 2c820028 sltiu r2,r4,0x0028           |{{f/std|<nowiki>r2 = 0x01 if Random < 40</nowiki>}}
  001877b8: 34030016 ori r3,r0,0x0016 r3 = 16 (Thundaga)
+
  00187784: 08061dfb j 0x001877ec                     {{f/jump|jump to Store Ability data (Fire 3)}}
  001877bc: 1040000b beq r2,r0,0x001877ec Branch if Random > 28
+
  00187788: 34030012 ori r3,r0,0x0012                 |{{f/std|<nowiki>r3 = 0x12 (Fire 3)</nowiki>}}
  001877c0: 34030014 ori r3,r0,0x0014 r3 = 14 (Thunder)
+
  0018778c: 10400017 beq r2,r0,0x001877ec         {{f/Cond|If Random < 40}} /Else Branch to Store Ability data with '''Fire'''
  001877c4: 08061dfb j 0x001877ec
+
  00187790: 34030010 ori r3,r0,0x0010             |{{f/std|<nowiki>r3 = 0x10 (Fire)</nowiki>}}
  001877c8: 34030015 ori r3,r0,0x0015 r3 = 15 (Thundara)
+
  00187794: 08061dfb j 0x001877ec                     {{f/jump|jump to Store Ability data (Fire 2)}}
  001877cc: 2c82000a sltiu r2,r4,0x000a
+
  00187798: 34030011 ori r3,r0,0x0011                 |{{f/std|<nowiki>r3 = 0x11 (Fire 2)</nowiki>}}
  001877d0: 10400003 beq r2,r0,0x001877e0 Branch if Random > a
+
  0018779c: 32020040 andi r2,r16,0x0040       |{{f/std|r2 <> 0x00 if Weapon Element is Lightning}}
  001877d4: 2c820028 sltiu r2,r4,0x0028
+
  001877a0: 1040000a beq r2,r0,0x001877cc     {{f/Cond|If Weapon Element has Lightning}}
  001877d8: 08061dfb j 0x001877ec
+
  001877a4: 306400ff andi r4,r3,0x00ff           |{{f/std|<nowiki>r4 = Random number in a byte (useless if everything is ok)</nowiki>}}
  001877dc: 3403001a ori r3,r0,0x001a r3 = 1a (Blizzaga)
+
  001877a8: 2c82000a sltiu r2,r4,0x000a           |{{f/std|<nowiki>r2 = 0x01 if Random < 10</nowiki>}}
  001877e0: 10400002 beq r2,r0,0x001877ec Branch if Random > 28
+
  001877ac: 10400003 beq r2,r0,0x001877bc         {{f/Cond|If Random < 10}}
  001877e4: 34030018 ori r3,r0,0x0018 r3 = 18 (Blizzard)
+
  001877b0: 2c820028 sltiu r2,r4,0x0028           |{{f/std|<nowiki>r2 = 0x01 if Random < 40</nowiki>}}
  001877e8: 34030019 ori r3,r0,0x0019 r3 = 19 (Blizzara)
+
  001877b4: 08061dfb j 0x001877ec                     {{f/jump|jump to Store Ability data (Bolt 3)}}
  001877ec: 3c058019 lui r5,0x8019
+
  001877b8: 34030016 ori r3,r0,0x0016                 |{{f/std|<nowiki>r3 = 0x16 (Bolt 3)</nowiki>}}
  001877f0: 24a538d6 addiu r5,r5,0x38d6
+
  001877bc: 1040000b beq r2,r0,0x001877ec         {{f/Cond|If Random < 40}} /Else Branch to Store Ability data with '''Bolt'''
  001877f4: 000320c0 sll r4,r3,0x03 Ability ID * 8
+
  001877c0: 34030014 ori r3,r0,0x0014             |{{f/std|<nowiki>r3 = 14 (Bolt)</nowiki>}}
  001877f8: 00832023 subu r4,r4,r3 Ability ID * 7
+
  001877c4: 08061dfb j 0x001877ec                     {{f/jump|jump to Store Ability data (Bolt 2)}}
  001877fc: 00042040 sll r4,r4,0x01 Ability ID * 14
+
  001877c8: 34030015 ori r3,r0,0x0015                 |{{f/std|<nowiki>r3 = 0x15 (Bolt 2)</nowiki>}}
  00187800: a4a30000 sh r3,0x0000(r5) Store Used Ability ID
+
                                            {{f/Cond|If Weapon Element is Ice}}  (In fact it could be every other element - or even no elements)
  00187804: 24a5001a addiu r5,r5,0x001a r5 = 801938f0 (Current Action Ability Data start)
+
  001877cc: 2c82000a sltiu r2,r4,0x000a           |{{f/std|<nowiki>r2 = 0x01 if Random < 10</nowiki>}}
  00187808: 3c028019 lui r2,0x8019
+
  001877d0: 10400003 beq r2,r0,0x001877e0         {{f/Cond|If Random < 10}}
  0018780c: 8c422d94 lw r2,0x2d94(r2) Load Attacker's Data Pointer
+
  001877d4: 2c820028 sltiu r2,r4,0x0028           |{{f/std|<nowiki>r2 = 0x01 if Random < 40</nowiki>}}
  00187810: 3406000e ori r6,r0,0x000e r6 = e (Loop Limit)
+
  001877d8: 08061dfb j 0x001877ec                     {{f/jump|jump to Store Ability data (Bolt 3)}}
  00187814: a4430170 sh r3,0x0170(r2) Store Last Attack? = Ability ID
+
  001877dc: 3403001a ori r3,r0,0x001a                 |{{f/std|<nowiki>r3 = 0x1a (Ice 3)</nowiki>}}
  00187818: 3c028006 lui r2,0x8006
+
  001877e0: 10400002 beq r2,r0,0x001877ec         {{f/Cond|If Random < 40}} /Else Branch to Store Ability data with '''Ice'''
  0018781c: 2442fbf0 addiu r2,r2,-0x0410 r2 = 5fbf0 (Ability Data)
+
  001877e4: 34030018 ori r3,r0,0x0018             |{{f/std|<nowiki>r3 = 18 (Ice)</nowiki>}}
  00187820: 0c017895 jal 0x0005e254 Load X into Y (Ability Data -> Current Action Data)
+
  001877e8: 34030019 ori r3,r0,0x0019                 |{{f/std|<nowiki>r3 = 19 (Ice 2)</nowiki>}}
  00187824: 00822021 addu r4,r4,r2 r4 = Ability Data Pointer
+
  00187828: 8fbf0014 lw r31,0x0014(r29)
+
{{f/loc|--- Store Magic gun Ability data section ---}}
  0018782c: 8fb00010 lw r16,0x0010(r29)
+
  001877ec: 3c058019 lui r5,0x8019                  
  00187830: 27bd0018 addiu r29,r29,0x0018
+
  001877f0: 24a538d6 addiu r5,r5,0x38d6       |{{f/adr|<nowiki>r5 = Current Ability used ability ID pointer</nowiki>}} {{f/std| 0x801938d6 / 801938d6}}
  00187834: 03e00008 jr r31
+
  001877f4: 000320c0 sll r4,r3,0x03           |{{f/std|Magic Gun Ability ID * 8}}
  00187838: 00000000 nop
+
  001877f8: 00832023 subu r4,r4,r3           |{{f/std|Magic Gun Ability ID * 7}}
 +
  001877fc: 00042040 sll r4,r4,0x01           |{{f/std|<nowiki>r4 = Magic Gun Ability ID * 14</nowiki>}}
 +
  00187800: a4a30000 sh r3,0x0000(r5)         |{{f/store|Store Magic Gun Ability ID as Current Ability Used Ability ID}}
 +
  00187804: 24a5001a addiu r5,r5,0x001a       |{{f/adr|<nowiki>r5 = Current Ability : Start of Ability data pointer</nowiki>}} {{f/std| 0x801938f0 / 801938f0}}
 +
  00187808: 3c028019 lui r2,0x8019           |
 +
  0018780c: 8c422d94 lw r2,0x2d94(r2)         |{{f/adr|<nowiki>r2 =  Attacker's Data Pointer</nowiki>}}
 +
  00187810: 3406000e ori r6,r0,0x000e         |{{f/std|<nowiki>r6 = 0x0e</nowiki>}}
 +
  00187814: a4430170 sh r3,0x0170(r2)         |{{f/store|<nowiki>Store Last Attack? = Ability ID</nowiki>}}
 +
  00187818: 3c028006 lui r2,0x8006           |
 +
  0018781c: 2442fbf0 addiu r2,r2,-0x0410     |{{f/std|<nowiki>r2 = 0x8005fbf0 (Start of Ability Data 2 Table)</nowiki>}}
 +
  00187820: 0c017895 jal 0x0005e254           |{{f/jal|Store_X_Byte_into_Y|Store_X_Byte_into_Y}}  Store Magic Gun Ability Data (Range to MP cost) in Current Ability data (0x801938f0 to 0x801938fd)
 +
  00187824: 00822021 addu r4,r4,r2           |{{f/adr|<nowiki>r4 = Magic Gun Ability Data Pointer</nowiki>}}
 +
  00187828: 8fbf0014 lw r31,0x0014(r29)      
 +
  0018782c: 8fb00010 lw r16,0x0010(r29)      
 +
  00187830: 27bd0018 addiu r29,r29,0x0018    
 +
  00187834: 03e00008 jr r31                  
 +
  00187838: 00000000 nop                    
 +
=== Hard coded mechanics ===
 +
Ability ID of Fire 1/2/3 Ice 1/2/3 Lightning 1/2/3 are hardcoded here.
 +
Setting another spell in place of one of those ones will make it cast by the magic gun (provided that there's no further checks)
 +
=== Return Locations ===
 +
'''Battle.bin'''
 +
00188c34: [[04 Magic Gun]]

Latest revision as of 13:09, 1 July 2023

No Parameters - Returns Nothing

Uses The Gun Element to determine which spell type will be cast.
Only one element is taken into account. The others will be ignored : First Fire, then Thunder, finally Ice.   
(Note that Ice is default, everything not fire/thunder will end to cast an ice spell)

The tier of the cast spell is randomly chosen :
  - 10% of chances to cast tier 3
  - 30% of chances to cast tier 2
  - 60% of chances to cast tier 1

Magic gun ability ID is hardcoded. 
Magic gun ability data will be stored in current ability section (0x801938f0 to 0x801938fd) 
------------------------------------------------------------------------------------------------------
00187730: 27bdffe8 addiu r29,r29,-0x0018    |
00187734: afb00010 sw r16,0x0010(r29)       |
00187738: 3c108019 lui r16,0x8019           |
0018773c: 92103904 lbu r16,0x3904(r16)      |r16 = Current Ability Weapon's Element   0x80193904 / 80193904
00187740: afbf0014 sw r31,0x0014(r29)       |
00187744: 0c063ba8 jal 0x0018eea0           |-->Random Process  Returns r2 between 0x00 and 0x7fff
00187748: 00000000 nop                      |
0018774c: 00021840 sll r3,r2,0x01           |Random * 2
00187750: 00621821 addu r3,r3,r2            |Random * 3
00187754: 000318c0 sll r3,r3,0x03           |Random * 24
00187758: 00621821 addu r3,r3,r2            |Random * 25
0018775c: 00031880 sll r3,r3,0x02           |Random * 100
00187760: 04610002 bgez r3,0x0018776c       #If Random < 0x00
00187764: 32020080 andi r2,r16,0x0080       |r2 <> 0x00 if Weapon Element is Fire
00187768: 24637fff addiu r3,r3,0x7fff           |Make random positive
0018776c: 1040000b beq r2,r0,0x0018779c     #If Weapon Element has Fire
00187770: 00031bc2 srl r3,r3,0x0f               |r3 = Random between 0 and 99  (100 x Random / [Max possible random + 1])
00187774: 306400ff andi r4,r3,0x00ff            |r4 = Random number in a byte (useless if everything is ok)
00187778: 2c82000a sltiu r2,r4,0x000a           |r2 = 0x01 if Random < 10
0018777c: 10400003 beq r2,r0,0x0018778c         #If Random < 10
00187780: 2c820028 sltiu r2,r4,0x0028           |r2 = 0x01 if Random < 40
00187784: 08061dfb j 0x001877ec                     >>jump to Store Ability data (Fire 3)
00187788: 34030012 ori r3,r0,0x0012                 |r3 = 0x12 (Fire 3)
0018778c: 10400017 beq r2,r0,0x001877ec         #If Random < 40 /Else Branch to Store Ability data with Fire
00187790: 34030010 ori r3,r0,0x0010             |r3 = 0x10 (Fire)
00187794: 08061dfb j 0x001877ec                     >>jump to Store Ability data (Fire 2)
00187798: 34030011 ori r3,r0,0x0011                 |r3 = 0x11 (Fire 2)
0018779c: 32020040 andi r2,r16,0x0040       |r2 <> 0x00 if Weapon Element is Lightning
001877a0: 1040000a beq r2,r0,0x001877cc     #If Weapon Element has Lightning
001877a4: 306400ff andi r4,r3,0x00ff            |r4 = Random number in a byte (useless if everything is ok)
001877a8: 2c82000a sltiu r2,r4,0x000a           |r2 = 0x01 if Random < 10
001877ac: 10400003 beq r2,r0,0x001877bc         #If Random < 10
001877b0: 2c820028 sltiu r2,r4,0x0028           |r2 = 0x01 if Random < 40
001877b4: 08061dfb j 0x001877ec                     >>jump to Store Ability data (Bolt 3)
001877b8: 34030016 ori r3,r0,0x0016                 |r3 = 0x16 (Bolt 3)
001877bc: 1040000b beq r2,r0,0x001877ec         #If Random < 40 /Else Branch to Store Ability data with Bolt
001877c0: 34030014 ori r3,r0,0x0014             |r3 = 14 (Bolt)
001877c4: 08061dfb j 0x001877ec                     >>jump to Store Ability data (Bolt 2)
001877c8: 34030015 ori r3,r0,0x0015                 |r3 = 0x15 (Bolt 2)
                                            #If Weapon Element is Ice  (In fact it could be every other element - or even no elements)
001877cc: 2c82000a sltiu r2,r4,0x000a           |r2 = 0x01 if Random < 10
001877d0: 10400003 beq r2,r0,0x001877e0         #If Random < 10
001877d4: 2c820028 sltiu r2,r4,0x0028           |r2 = 0x01 if Random < 40
001877d8: 08061dfb j 0x001877ec                     >>jump to Store Ability data (Bolt 3)
001877dc: 3403001a ori r3,r0,0x001a                 |r3 = 0x1a (Ice 3)
001877e0: 10400002 beq r2,r0,0x001877ec         #If Random < 40 /Else Branch to Store Ability data with Ice
001877e4: 34030018 ori r3,r0,0x0018             |r3 = 18 (Ice)
001877e8: 34030019 ori r3,r0,0x0019                 |r3 = 19 (Ice 2)

--- Store Magic gun Ability data section ---
001877ec: 3c058019 lui r5,0x8019                    
001877f0: 24a538d6 addiu r5,r5,0x38d6       |r5 = Current Ability used ability ID pointer  0x801938d6 / 801938d6
001877f4: 000320c0 sll r4,r3,0x03           |Magic Gun Ability ID * 8
001877f8: 00832023 subu r4,r4,r3            |Magic Gun Ability ID * 7
001877fc: 00042040 sll r4,r4,0x01           |r4 = Magic Gun Ability ID * 14
00187800: a4a30000 sh r3,0x0000(r5)         |Store Magic Gun Ability ID as Current Ability Used Ability ID
00187804: 24a5001a addiu r5,r5,0x001a       |r5 = Current Ability : Start of Ability data pointer  0x801938f0 / 801938f0
00187808: 3c028019 lui r2,0x8019            |
0018780c: 8c422d94 lw r2,0x2d94(r2)         |r2 =  Attacker's Data Pointer
00187810: 3406000e ori r6,r0,0x000e         |r6 = 0x0e
00187814: a4430170 sh r3,0x0170(r2)         |Store Last Attack? = Ability ID
00187818: 3c028006 lui r2,0x8006            |
0018781c: 2442fbf0 addiu r2,r2,-0x0410      |r2 = 0x8005fbf0 (Start of Ability Data 2 Table)
00187820: 0c017895 jal 0x0005e254           |-->Store_X_Byte_into_Y  Store Magic Gun Ability Data (Range to MP cost) in Current Ability data (0x801938f0 to 0x801938fd)
00187824: 00822021 addu r4,r4,r2            |r4 = Magic Gun Ability Data Pointer
00187828: 8fbf0014 lw r31,0x0014(r29)       
0018782c: 8fb00010 lw r16,0x0010(r29)       
00187830: 27bd0018 addiu r29,r29,0x0018     
00187834: 03e00008 jr r31                   
00187838: 00000000 nop                      

Hard coded mechanics

Ability ID of Fire 1/2/3 Ice 1/2/3 Lightning 1/2/3 are hardcoded here.
Setting another spell in place of one of those ones will make it cast by the magic gun (provided that there's no further checks)

Return Locations

Battle.bin
00188c34: 04 Magic Gun