Final Fantasy Hacktics

Modding => Help! => Topic started by: MysticKnightFF5 on January 29, 2012, 08:48:21 pm

Title: Multiple Formula Mods...Can Replace Any Formulas
Post by: MysticKnightFF5 on January 29, 2012, 08:48:21 pm
I'll be honest, I don't care which formulas they replace, as these are the only formulas I intend to use. Though, it would be preferable they stay consecutive in the list.

Dmg_(X+MA) Hit_(Y%)
Dmg_(X+MA) Hit_(Y%) 100% Status
DmgMP_(X+MA) Hit_(Y%)
DmgMP_(X+MA) Hit_(Y%) 100% Status
Heal_(X+MA) Hit_(Y%)
Heal_(X+MA) Hit_(Y%) 100% Status
HealMP_(X+MA) Hit_(Y%)
HealMP_(X+MA) Hit_(Y%) 100% Status
AbsHP_(X+MA) Hit_(Y%)
AbsHP_(X+MA) Hit_(Y%) 100% Status
AbsMP_(X+MA) Hit_(Y%)
AbsMP_(X+MA) Hit_(Y%) 100% Status
Hit_(Y%)
EDIT: HealMP_(X) Hit(Y%)

Please keep formula 4B.
I know this is a lot to ask for, I'm sorry.
Title: Re: Multiple Formula Mods...Can Replace Any Formulas
Post by: MysticKnightFF5 on March 27, 2012, 11:50:09 am
Bump for help >.>"
Title: Re: Multiple Formula Mods...Can Replace Any Formulas
Post by: Rfh on March 29, 2012, 08:53:12 am
Well, I am now trying to edit the formula Hit_(MA+X)% in to Hit_(X)%. It will help you.
Title: Re: Multiple Formula Mods...Can Replace Any Formulas
Post by: MysticKnightFF5 on March 29, 2012, 12:21:52 pm
Yay!
Title: Re: Multiple Formula Mods...Can Replace Any Formulas
Post by: Glain on March 29, 2012, 03:42:02 pm
These are actually too vague to implement. For each one, you'd have to specify things like:

1. Is the ability affected by elemental?
   a. The weapon's, or the ability's?
   b. If so, can the ability be strengthened?

2. What kind of evasion? Physical/magical?

3. What damage type (Physical/magical)? i.e.:
  a. Is it affected by Attack UP, Defense UP, etc (physical)?
  b. Is it affected by Magic Attack UP, etc (magical)?

4. Can it status proc? (For non-100% status; I'd assume yes since you didn't specify NS)

Unfortunately all this stuff has to be done on a per-formula basis.

Is Hit_(Y)% a 100% Status deal? What does it do, if not?
Also, out of curiosity, why use X as the damage modifier and Y as the hit modifier? Isn't it usually the other way around?
Title: Re: Multiple Formula Mods...Can Replace Any Formulas
Post by: MysticKnightFF5 on March 29, 2012, 11:54:33 pm
1) Yes. It does get affected negatively and positively for all damage formulas.

2) Accuracy is the Y value in every formula. The unit's evasion affects nothing.

3) There is no Atk Up or MAtk Up, so physical/magical is moot.

4) Yes.

5) Yes, and it's already made, I know.

6) If they feel like switching that, they can, but it just feels more appropriate to me.
Title: Re: Multiple Formula Mods...Can Replace Any Formulas
Post by: Rfh on March 30, 2012, 10:16:09 am
Well, my first hack is very simple. I removed Store MA and and store MA as X for all formulas that their accuaracy is Hit (MA+X)%. Therefore, the formula is Hit (1+X)%:


  <Patch name=" All formulas that their accuaracy is Hit (MA+X)% become Hit (1+X)%">
    <Description>Affect formulas 0B,0D,0E,12,29,2A,4D,4F,50,51 and 58</Description>
    <Location file="BATTLE_BIN" offset="11ED90">
      00
    </Location>
    <Location file="BATTLE_BIN" offset="11EDA0">
      0000
    </Location>
  </Patch>
Title: Re: Multiple Formula Mods...Can Replace Any Formulas
Post by: Glain on March 31, 2012, 07:29:44 pm
So, I started to get interested in the ASM for this, and then before I knew it, I was going through the whole thing... so after quite a bit of coding/testing/etc, this patch should pretty much do it!
ASM: Once you pop, you can't stop? I don't know!

This should replace formulas [21] through [2e] in the order you listed.

I did all my testing in pSX, and got through the final testing with everything seemingly working and without the console window complaining at all, which I find usually means things are right. I didn't explicitly test in ePSXe but it should obviously work there.


  <Patch name="Multiple formula mods: 21 to 2e consecutive">
    <Description>Multiple formula mods: 21 to 2e consecutive</Description>
    <Location file="BATTLE_BIN" offset="EB000">
      E8FFBD27
      1000BFAF
      3021060C
      00000000
      03004014
      00000000
      AD1F060C
      00000000
      1000BF8F
      1800BD27
      0800E003
      00000000
    </Location>
    <Location file="BATTLE_BIN" offset="EB070">
      E8FFBD27
      1000BFAF
      1980083C
      942D098D
      F9380A91
      0300E014
      00000B34
      37002B91
      00000000
      21106A01
      CE3802A5
      FF17060C
      00000000
      1980023C
      CE384294
      1000BF8F
      1800BD27
      0800E003
      00000000
    </Location>
    <Location file="BATTLE_BIN" offset="EB0E0">
      E8FFBD27
      1000BFAF
      1980083C
      FA380591
      902D0A8D
      00000000
      2A0045A1
      3378010C
      64000434
      1980083C
      902D098D
      0100422C
      000022A1
      03004014
      00000000
      06000424
      020024A1
      1000BF8F
      1800BD27
      0800E003
      00000000
    </Location>
    <Location file="BATTLE_BIN" offset="124964">
      5448050C
      00000000
    </Location>
    <Location file="BATTLE_BIN" offset="EB150">
      1980013C
      21082200
      21200000
      21280000
      21300000
      21380000
      21780000
      0800E003
      21C00000
    </Location>
    <Location file="BATTLE_BIN" offset="EB190">
      D0FFBD27
      1000BFAF
      1800B0AF
      1C00B1AF
      2000B2AF
      2400B3AF
      2800B4AF
      2C00B5AF
      21808000
      2188A000
      2190C000
      2198E000
      21A0E001
      21A80003
      08000012
      00000000
      1C48050C
      21386002
      1980083C
      902D088D
      00000000
      20401001
      000002A5
      FE1B060C
      00000000
      3F1C060C
      00000000
      1980083C
      902D088D
      00000000
      250014A1
      3848050C
      00000000
      11004010
      00000000
      0F004012
      00000000
      1980083C
      902D098D
      8C2D0A8D
      04002B95
      06002C95
      08002D95
      0A002E95
      06004BA5
      04004CA5
      0A004DA5
      08004EA5
      01000B34
      00004BA1
      250055A1
      05002016
      00000000
      0048050C
      00000000
      9F480508
      00000000
      AD1F060C
      00000000
      1000BF8F
      1800B08F
      1C00B18F
      2000B28F
      2400B38F
      2800B48F
      2C00B58F
      3000BD27
      0800E003
      00000000
    </Location>
    <Location file="BATTLE_BIN" offset="1225F4">
      81000F24
      64480508
      04000424
    </Location>
    <Location file="BATTLE_BIN" offset="122654">
      81000F24
      04000424
      64480508
      01000524
    </Location>
    <Location file="BATTLE_BIN" offset="12267C">
      21000F24
      64480508
      08000424
    </Location>
    <Location file="BATTLE_BIN" offset="1226B4">
      21000F24
      08000424
      64480508
      01000524
    </Location>
    <Location file="BATTLE_BIN" offset="1226EC">
      41000F24
      64480508
      06000424
    </Location>
    <Location file="BATTLE_BIN" offset="122794">
      41000F24
      06000424
      64480508
      01000524
    </Location>
    <Location file="BATTLE_BIN" offset="122828">
      11000F24
      64480508
      0A000424
    </Location>
    <Location file="BATTLE_BIN" offset="122870">
      11000F24
      0A000424
      64480508
      01000524
    </Location>
    <Location file="BATTLE_BIN" offset="122910">
      81000F24
      40001824
      04000424
      64480508
      01000624
    </Location>
    <Location file="BATTLE_BIN" offset="1229A4">
      81000F24
      40001824
      04000424
      01000524
      64480508
      01000624
    </Location>
    <Location file="BATTLE_BIN" offset="122A90">
      21000F24
      10001824
      08000424
      64480508
      01000624
    </Location>
    <Location file="BATTLE_BIN" offset="122AD8">
      21000F24
      10001824
      08000424
      01000524
      64480508
      01000624
    </Location>
    <Location file="BATTLE_BIN" offset="122B20">
      01000524
      64480508
      08000F24
    </Location>
    <Location file="BATTLE_BIN" offset="122B94">
      11000F24
      0A000424
      64480508
      01000724
    </Location>
  </Patch>



A. Create status proc subroutine

[0x152000] > [0xeb000]

addiu r29,r29,-0x18
sw r31,0x10(r29)
jal 0x1884c0         # Status proc roll (19%)
nop
bne r2,r0,(RETURN)      # If roll succeeds...
nop
jal 0x187eb4         # Apply status
nop
(RETURN):
lw r31,0x10(r29)
addiu r29,r29,0x18
jr r31
nop

B. Create Modifier + X subroutine - return value (Modifier=MA when r7=0, 0 otherwise)

[0x152070] > [0xeb070]

addiu r29,r29,-0x18
sw r31,0x10(r29)
lui r8,0x8019
lw r9,0x2d94(r8)      # Load Actor
lbu r10,0x38f9(r8)      # Load Ability X

bne r7,r0,(PAST_MA_LOAD)   # Set Modifier = 0
ori r11,r0,0
lbu r11,0x0037(r9)      # Modifier = Actor MA, if r7 is not 0
nop

(PAST_MA_LOAD):
addu r2,r11,r10         
sh r2,0x38ce(r8)      # Save Modifier + X
jal 0x185ffc         # Elemental Strengthen (Ability)
nop
lui r2,0x8019
lhu r2,0x38ce(r2)      # Load result and return it
lw r31,0x10(r29)
addiu r29,r29,0x18
jr r31
nop

C. Hit (Y%) subroutine - set and return hit status

[0x1520e0] > [0xeb0e0]

addiu r29,r29,-0x18
sw r31,0x10(r29)
lui r8,0x8019
lbu r5,0x38fa(r8)      # Load Ability Y
lw r10,0x2d90(r8)
nop
sb r5,0x002a(r10)      # Save [Hit %] = Y
jal 0x5e0cc         # Roll (0-99) with threshold = Y (Y% under)
ori r4,r0,100
lui r8,0x8019
lw r9,0x2d90(r8)
sltiu r2,r2,1         # result = 1 if roll was under threshold (success), otherwise 0
sb r2,0x0000(r9)      # Save result

bne r2,r0,(RETURN)      # If missed, set action's evade type to Miss
nop
addiu r4,r0,6
sb r4,0x0002(r9)

(RETURN):
lw r31,0x10(r29)
addiu r29,r29,0x18
jr r31            # Return result
nop

D. Subroutine to Zero out r4,r5,r6,r7,r15,r24 with call

[0x18b964] > [0x124964]

jal 0x152150
nop

[0x152150] > [0xeb150]

lui r1,0x8019
addu r1,r1,r2
addu r4,r0,r0
addu r5,r0,r0
addu r6,r0,r0
addu r7,r0,r0
addu r15,r0,r0
jr r31
addu r24,r0,r0

E. Create meta-routine (template): r4 = Location to save; r5 = 100% Status? r6 = Do Drain; r7 = Don't use MA; r15 = Action Type; r24 = Drain Action Type

[0x152190] > [0xeb190]

addiu r29,r29,-0x30
sw r31,0x10(r29)
sw r16,0x18(r29)
sw r17,0x1c(r29)
sw r18,0x20(r29)
sw r19,0x24(r29)
sw r20,0x28(r29)
sw r21,0x2c(r29)

addu r16,r4,r0         # Save parameters
addu r17,r5,r0
addu r18,r6,r0
addu r19,r7,r0
addu r20,r15,r0
addu r21,r24,r0

beq r16,r0,(AFTER_STORE)   # If ([Saved r4] == 0), Skip the action modification
nop

jal 0x152070         # Load Modifier + X (r7 = boolean: Don't Use MA)
addu r7,r19,r0
lui r8,0x8019
lw r8,0x2d90(r8)      # Load Action
nop
add r8,r8,r16
sh r2,0x0000(r8)      # *(&Action + Location) = Modifier + X

(AFTER_STORE):
jal 0x186ff8         # Apply ability elemental
nop
jal 0x1870fc         # Elemental Absorb
nop

lui r8,0x8019         # Save attack type (in case absorb overwrote it)
lw r8,0x2d90(r8)
nop
sb r20,0x25(r8)

jal 0x1520e0         # Hit: Y%
nop
beq r2,r0,(PAST_DRAIN)      # If (Miss), Skip Drain
nop

beq r18,r0,(PAST_DRAIN)      # If ([Saved r6] == 0), Skip Drain
nop

lui r8,0x8019
lw r9,0x2d90(r8)      # Load action
lw r10,0x2d8c(r8)      # Load drain action

lhu r11,0x0004(r9)      # Load Action HP Damage
lhu r12,0x0006(r9)      # Load Action HP Healing
lhu r13,0x0008(r9)      # Load Action MP Damage
lhu r14,0x000a(r9)      # Load Action MP Healing

sh r11,0x0006(r10)      # Drain Action HP Healing = Action HP Damage
sh r12,0x0004(r10)      # Drain Action HP Damage = Action HP Healing
sh r13,0x000a(r10)      # Drain Action MP Healing = Action MP Damage
sh r14,0x0008(r10)      # Drain Action MP Damage = Action MP Healing
ori r11,r0,1
sb r11,0x0000(r10)      # Set Drain Action to Hit
sb r21,0x0025(r10)      # Set Drain Action Type

(PAST_DRAIN):
bne r17,r0,(GUARANTEE_STATUS)   # If ([Saved r5] != 0)
nop

jal 0x152000         #    Conditional status proc (19%)
nop
j (RETURN)
nop            # Else

(GUARANTEE_STATUS):
jal 0x187eb4         #    Apply status (100%)
nop

(RETURN):
lw r31,0x10(r29)
lw r16,0x18(r29)
lw r17,0x1c(r29)
lw r18,0x20(r29)
lw r19,0x24(r29)
lw r20,0x28(r29)
lw r21,0x2c(r29)
addiu r29,r29,0x30
jr r31
nop

F. Formulas!

1. Dmg_(X+MA) Hit_(Y%)
[21] : [0x1895f4] > [0x1225f4]
addiu r15,r0,0x81
j 0x152190
addiu r4,r0,4

2. Dmg_(X+MA) Hit_(Y%) 100% Status
[22] : [0x189654] > [0x122654]
addiu r15,r0,0x81
addiu r4,r0,4
j 0x152190
addiu r5,r0,1

3. DmgMP_(X+MA) Hit_(Y%)
[23] : [0x18967c] > [0x12267c]
addiu r15,r0,0x21
j 0x152190
addiu r4,r0,8

4. DmgMP_(X+MA) Hit_(Y%) 100% Status
[24] : [0x1896b4] > [0x1226b4]
addiu r15,r0,0x21
addiu r4,r0,8
j 0x152190
addiu r5,r0,1

5. Heal_(X+MA) Hit_(Y%)
[25] : [0x1896ec] > [0x1226ec]
addiu r15,r0,0x41
j 0x152190
addiu r4,r0,6

6. Heal_(X+MA) Hit_(Y%) 100% Status
[26] : [0x189794] > [0x122794]
addiu r15,r0,0x41
addiu r4,r0,6
j 0x152190
addiu r5,r0,1

7. HealMP_(X+MA) Hit_(Y%)
[27] : [0x189828] > [0x122828]
addiu r15,r0,0x11
j 0x152190
addiu r4,r0,10

8. HealMP_(X+MA) Hit_(Y%) 100% Status
[28] : [0x189870] > [0x122870]
addiu r15,r0,0x11
addiu r4,r0,10
j 0x152190
addiu r5,r0,1

9. AbsHP_(X+MA) Hit_(Y%)
[29] : [0x189910] > [0x122910]
addiu r15,r0,0x81
addiu r24,r0,0x40
addiu r4,r0,4
j 0x152190
addiu r6,r0,1

10. AbsHP_(X+MA) Hit_(Y%) 100% Status
[2a] : [0x1899a4] > [0x1229a4]
addiu r15,r0,0x81
addiu r24,r0,0x40
addiu r4,r0,4
addiu r5,r0,1
j 0x152190
addiu r6,r0,1

11. AbsMP_(X+MA) Hit_(Y%)
[2b] : [0x189a90] > [0x122a90]
addiu r15,r0,0x21
addiu r24,r0,0x10
addiu r4,r0,8
j 0x152190
addiu r6,r0,1

12. AbsMP_(X+MA) Hit_(Y%) 100% Status
[2c] : [0x189ad8] > [0x122ad8]
addiu r15,r0,0x21
addiu r24,r0,0x10
addiu r4,r0,8
addiu r5,r0,1
j 0x152190
addiu r6,r0,1

13. Hit_(Y%)
[2d] : [0x189b20] > [0x122b20]
addiu r5,r0,1
j 0x152190
addiu r15,r0,0x08

14. HealMP_(X) Hit(Y%)
[2e] : [0x189b94] > [0x122b94]
addiu r15,r0,0x11
addiu r4,r0,10
j 0x152190
addiu r7,r0,1
Title: Re: Multiple Formula Mods...Can Replace Any Formulas
Post by: Pride on March 31, 2012, 08:04:44 pm
Doesn't really matter but you could have repointed the formulas then using a jump. Works just the same though.

http://ffhacktics.com/wiki/Formula_Table
Title: Re: Multiple Formula Mods...Can Replace Any Formulas
Post by: Pickle Girl Fanboy on March 31, 2012, 08:28:45 pm
Are the addresses listed RAM or something else?
Title: Re: Multiple Formula Mods...Can Replace Any Formulas
Post by: Glain on March 31, 2012, 08:57:08 pm
Heh, at first I was trying to make sense of the ASM in the formula table, then realized it was just data. I knew about the offset table (though I wasn't sure where it was at first), but I didn't see the need to reroute anything.

One thing that I forgot was that [38] doesn't even have a formula at all; it just wires itself directly to the apply status routine. If you try to change [38], you actually change that. Gah. (Mainly why I ended up doing [21] - [2e] instead of [31] - [3e]).

Yeah, those are RAM addresses. BATTLE.BIN is -0x67000.
Title: Re: Multiple Formula Mods...Can Replace Any Formulas
Post by: MysticKnightFF5 on April 01, 2012, 12:12:40 am
Quote from: Glain on March 31, 2012, 07:29:44 pm
So, I started to get interested in the ASM for this, and then before I knew it, I was going through the whole thing... so after quite a bit of coding/testing/etc, this patch should pretty much do it!
ASM: Once you pop, you can't stop? I don't know!

This should replace formulas [21] through [2e] in the order you listed.

I did all my testing in pSX, and got through the final testing with everything seemingly working and without the console window complaining at all, which I find usually means things are right. I didn't explicitly test in ePSXe but it should obviously work there.


  <Patch name="Multiple formula mods: 21 to 2e consecutive">
    <Description>Multiple formula mods: 21 to 2e consecutive</Description>
    <Location file="BATTLE_BIN" offset="EB000">
      E8FFBD27
      1000BFAF
      3021060C
      00000000
      03004014
      00000000
      AD1F060C
      00000000
      1000BF8F
      1800BD27
      0800E003
      00000000
    </Location>
    <Location file="BATTLE_BIN" offset="EB070">
      E8FFBD27
      1000BFAF
      1980083C
      942D098D
      F9380A91
      0300E014
      00000B34
      37002B91
      00000000
      21106A01
      CE3802A5
      FF17060C
      00000000
      1980023C
      CE384294
      1000BF8F
      1800BD27
      0800E003
      00000000
    </Location>
    <Location file="BATTLE_BIN" offset="EB0E0">
      E8FFBD27
      1000BFAF
      1980083C
      FA380591
      902D0A8D
      00000000
      2A0045A1
      3378010C
      64000434
      1980083C
      902D098D
      0100422C
      000022A1
      03004014
      00000000
      06000424
      020024A1
      1000BF8F
      1800BD27
      0800E003
      00000000
    </Location>
    <Location file="BATTLE_BIN" offset="124964">
      5448050C
      00000000
    </Location>
    <Location file="BATTLE_BIN" offset="EB150">
      1980013C
      21082200
      21200000
      21280000
      21300000
      21380000
      21780000
      0800E003
      21C00000
    </Location>
    <Location file="BATTLE_BIN" offset="EB190">
      D0FFBD27
      1000BFAF
      1800B0AF
      1C00B1AF
      2000B2AF
      2400B3AF
      2800B4AF
      2C00B5AF
      21808000
      2188A000
      2190C000
      2198E000
      21A0E001
      21A80003
      08000012
      00000000
      1C48050C
      21386002
      1980083C
      902D088D
      00000000
      20401001
      000002A5
      FE1B060C
      00000000
      3F1C060C
      00000000
      1980083C
      902D088D
      00000000
      250014A1
      3848050C
      00000000
      11004010
      00000000
      0F004012
      00000000
      1980083C
      902D098D
      8C2D0A8D
      04002B95
      06002C95
      08002D95
      0A002E95
      06004BA5
      04004CA5
      0A004DA5
      08004EA5
      01000B34
      00004BA1
      250055A1
      05002016
      00000000
      0048050C
      00000000
      9F480508
      00000000
      AD1F060C
      00000000
      1000BF8F
      1800B08F
      1C00B18F
      2000B28F
      2400B38F
      2800B48F
      2C00B58F
      3000BD27
      0800E003
      00000000
    </Location>
    <Location file="BATTLE_BIN" offset="1225F4">
      81000F24
      64480508
      04000424
    </Location>
    <Location file="BATTLE_BIN" offset="122654">
      81000F24
      04000424
      64480508
      01000524
    </Location>
    <Location file="BATTLE_BIN" offset="12267C">
      21000F24
      64480508
      08000424
    </Location>
    <Location file="BATTLE_BIN" offset="1226B4">
      21000F24
      08000424
      64480508
      01000524
    </Location>
    <Location file="BATTLE_BIN" offset="1226EC">
      41000F24
      64480508
      06000424
    </Location>
    <Location file="BATTLE_BIN" offset="122794">
      41000F24
      06000424
      64480508
      01000524
    </Location>
    <Location file="BATTLE_BIN" offset="122828">
      11000F24
      64480508
      0A000424
    </Location>
    <Location file="BATTLE_BIN" offset="122870">
      11000F24
      0A000424
      64480508
      01000524
    </Location>
    <Location file="BATTLE_BIN" offset="122910">
      81000F24
      40001824
      04000424
      64480508
      01000624
    </Location>
    <Location file="BATTLE_BIN" offset="1229A4">
      81000F24
      40001824
      04000424
      01000524
      64480508
      01000624
    </Location>
    <Location file="BATTLE_BIN" offset="122A90">
      21000F24
      10001824
      08000424
      64480508
      01000624
    </Location>
    <Location file="BATTLE_BIN" offset="122AD8">
      21000F24
      10001824
      08000424
      01000524
      64480508
      01000624
    </Location>
    <Location file="BATTLE_BIN" offset="122B20">
      01000524
      64480508
      08000F24
    </Location>
    <Location file="BATTLE_BIN" offset="122B94">
      11000F24
      0A000424
      64480508
      01000724
    </Location>
  </Patch>



A. Create status proc subroutine

[0x152000] > [0xeb000]

addiu r29,r29,-0x18
sw r31,0x10(r29)
jal 0x1884c0         # Status proc roll (19%)
nop
bne r2,r0,(RETURN)      # If roll succeeds...
nop
jal 0x187eb4         # Apply status
nop
(RETURN):
lw r31,0x10(r29)
addiu r29,r29,0x18
jr r31
nop

B. Create Modifier + X subroutine - return value (Modifier=MA when r7=0, 0 otherwise)

[0x152070] > [0xeb070]

addiu r29,r29,-0x18
sw r31,0x10(r29)
lui r8,0x8019
lw r9,0x2d94(r8)      # Load Actor
lbu r10,0x38f9(r8)      # Load Ability X

bne r7,r0,(PAST_MA_LOAD)   # Set Modifier = 0
ori r11,r0,0
lbu r11,0x0037(r9)      # Modifier = Actor MA, if r7 is not 0
nop

(PAST_MA_LOAD):
addu r2,r11,r10         
sh r2,0x38ce(r8)      # Save Modifier + X
jal 0x185ffc         # Elemental Strengthen (Ability)
nop
lui r2,0x8019
lhu r2,0x38ce(r2)      # Load result and return it
lw r31,0x10(r29)
addiu r29,r29,0x18
jr r31
nop

C. Hit (Y%) subroutine - set and return hit status

[0x1520e0] > [0xeb0e0]

addiu r29,r29,-0x18
sw r31,0x10(r29)
lui r8,0x8019
lbu r5,0x38fa(r8)      # Load Ability Y
lw r10,0x2d90(r8)
nop
sb r5,0x002a(r10)      # Save [Hit %] = Y
jal 0x5e0cc         # Roll (0-99) with threshold = Y (Y% under)
ori r4,r0,100
lui r8,0x8019
lw r9,0x2d90(r8)
sltiu r2,r2,1         # result = 1 if roll was under threshold (success), otherwise 0
sb r2,0x0000(r9)      # Save result

bne r2,r0,(RETURN)      # If missed, set action's evade type to Miss
nop
addiu r4,r0,6
sb r4,0x0002(r9)

(RETURN):
lw r31,0x10(r29)
addiu r29,r29,0x18
jr r31            # Return result
nop

D. Subroutine to Zero out r4,r5,r6,r7,r15,r24 with call

[0x18b964] > [0x124964]

jal 0x152150
nop

[0x152150] > [0xeb150]

lui r1,0x8019
addu r1,r1,r2
addu r4,r0,r0
addu r5,r0,r0
addu r6,r0,r0
addu r7,r0,r0
addu r15,r0,r0
jr r31
addu r24,r0,r0

E. Create meta-routine (template): r4 = Location to save; r5 = 100% Status? r6 = Do Drain; r7 = Don't use MA; r15 = Action Type; r24 = Drain Action Type

[0x152190] > [0xeb190]

addiu r29,r29,-0x30
sw r31,0x10(r29)
sw r16,0x18(r29)
sw r17,0x1c(r29)
sw r18,0x20(r29)
sw r19,0x24(r29)
sw r20,0x28(r29)
sw r21,0x2c(r29)

addu r16,r4,r0         # Save parameters
addu r17,r5,r0
addu r18,r6,r0
addu r19,r7,r0
addu r20,r15,r0
addu r21,r24,r0

beq r16,r0,(AFTER_STORE)   # If ([Saved r4] == 0), Skip the action modification
nop

jal 0x152070         # Load Modifier + X (r7 = boolean: Don't Use MA)
addu r7,r19,r0
lui r8,0x8019
lw r8,0x2d90(r8)      # Load Action
nop
add r8,r8,r16
sh r2,0x0000(r8)      # *(&Action + Location) = Modifier + X

(AFTER_STORE):
jal 0x186ff8         # Apply ability elemental
nop
jal 0x1870fc         # Elemental Absorb
nop

lui r8,0x8019         # Save attack type (in case absorb overwrote it)
lw r8,0x2d90(r8)
nop
sb r20,0x25(r8)

jal 0x1520e0         # Hit: Y%
nop
beq r2,r0,(PAST_DRAIN)      # If (Miss), Skip Drain
nop

beq r18,r0,(PAST_DRAIN)      # If ([Saved r6] == 0), Skip Drain
nop

lui r8,0x8019
lw r9,0x2d90(r8)      # Load action
lw r10,0x2d8c(r8)      # Load drain action

lhu r11,0x0004(r9)      # Load Action HP Damage
lhu r12,0x0006(r9)      # Load Action HP Healing
lhu r13,0x0008(r9)      # Load Action MP Damage
lhu r14,0x000a(r9)      # Load Action MP Healing

sh r11,0x0006(r10)      # Drain Action HP Healing = Action HP Damage
sh r12,0x0004(r10)      # Drain Action HP Damage = Action HP Healing
sh r13,0x000a(r10)      # Drain Action MP Healing = Action MP Damage
sh r14,0x0008(r10)      # Drain Action MP Damage = Action MP Healing
ori r11,r0,1
sb r11,0x0000(r10)      # Set Drain Action to Hit
sb r21,0x0025(r10)      # Set Drain Action Type

(PAST_DRAIN):
bne r17,r0,(GUARANTEE_STATUS)   # If ([Saved r5] != 0)
nop

jal 0x152000         #    Conditional status proc (19%)
nop
j (RETURN)
nop            # Else

(GUARANTEE_STATUS):
jal 0x187eb4         #    Apply status (100%)
nop

(RETURN):
lw r31,0x10(r29)
lw r16,0x18(r29)
lw r17,0x1c(r29)
lw r18,0x20(r29)
lw r19,0x24(r29)
lw r20,0x28(r29)
lw r21,0x2c(r29)
addiu r29,r29,0x30
jr r31
nop

F. Formulas!

1. Dmg_(X+MA) Hit_(Y%)
[21] : [0x1895f4] > [0x1225f4]
addiu r15,r0,0x81
j 0x152190
addiu r4,r0,4

2. Dmg_(X+MA) Hit_(Y%) 100% Status
[22] : [0x189654] > [0x122654]
addiu r15,r0,0x81
addiu r4,r0,4
j 0x152190
addiu r5,r0,1

3. DmgMP_(X+MA) Hit_(Y%)
[23] : [0x18967c] > [0x12267c]
addiu r15,r0,0x21
j 0x152190
addiu r4,r0,8

4. DmgMP_(X+MA) Hit_(Y%) 100% Status
[24] : [0x1896b4] > [0x1226b4]
addiu r15,r0,0x21
addiu r4,r0,8
j 0x152190
addiu r5,r0,1

5. Heal_(X+MA) Hit_(Y%)
[25] : [0x1896ec] > [0x1226ec]
addiu r15,r0,0x41
j 0x152190
addiu r4,r0,6

6. Heal_(X+MA) Hit_(Y%) 100% Status
[26] : [0x189794] > [0x122794]
addiu r15,r0,0x41
addiu r4,r0,6
j 0x152190
addiu r5,r0,1

7. HealMP_(X+MA) Hit_(Y%)
[27] : [0x189828] > [0x122828]
addiu r15,r0,0x11
j 0x152190
addiu r4,r0,10

8. HealMP_(X+MA) Hit_(Y%) 100% Status
[28] : [0x189870] > [0x122870]
addiu r15,r0,0x11
addiu r4,r0,10
j 0x152190
addiu r5,r0,1

9. AbsHP_(X+MA) Hit_(Y%)
[29] : [0x189910] > [0x122910]
addiu r15,r0,0x81
addiu r24,r0,0x40
addiu r4,r0,4
j 0x152190
addiu r6,r0,1

10. AbsHP_(X+MA) Hit_(Y%) 100% Status
[2a] : [0x1899a4] > [0x1229a4]
addiu r15,r0,0x81
addiu r24,r0,0x40
addiu r4,r0,4
addiu r5,r0,1
j 0x152190
addiu r6,r0,1

11. AbsMP_(X+MA) Hit_(Y%)
[2b] : [0x189a90] > [0x122a90]
addiu r15,r0,0x21
addiu r24,r0,0x10
addiu r4,r0,8
j 0x152190
addiu r6,r0,1

12. AbsMP_(X+MA) Hit_(Y%) 100% Status
[2c] : [0x189ad8] > [0x122ad8]
addiu r15,r0,0x21
addiu r24,r0,0x10
addiu r4,r0,8
addiu r5,r0,1
j 0x152190
addiu r6,r0,1

13. Hit_(Y%)
[2d] : [0x189b20] > [0x122b20]
addiu r5,r0,1
j 0x152190
addiu r15,r0,0x08

14. HealMP_(X) Hit(Y%)
[2e] : [0x189b94] > [0x122b94]
addiu r15,r0,0x11
addiu r4,r0,10
j 0x152190
addiu r7,r0,1


OMIGOSH OMIGOSH OMIGOSH THANK YOOOOOU!