Modding => Help! => Topic started by: Arimala on December 03, 2020, 04:41:25 pm
Title: ASM hack for Formula 2D = Dmg_(PA*(WP+Y)/X) freezing game [Solved]
Post by: Arimala on December 03, 2020, 04:41:25 pm
I am a complete newbie to formula hacking, but like most people I find the swordskills a bit overpowered, so I have been attempting to learn some minor asm hacking to get this much needed formula into my game. I watched Xifanie's tutorials on how to use the FFT Hack Template, and got started from there. I tried adding in the /X later in the formula, after 'lw r2, 0x2D90(r2)' as well as an attempt at putting the command in after 'lbu r2, 0x0000(r2). All the 0's in the lbu command tell me that is almost for sure the wrong place for a div command. These 2 attempts ended in either the game freezing when i selected a target or glitched out damage prediction.
I even attempted saving it in the slot for formula 18. When I did this formula 18 froze the game, and for some reason the swordskills I kept as formula 2D even froze the game.. even though I did not change a thing on those skills or touch the formula. Not sure what that was about.
So I tried inserting the raw code for the Store PA and WP + Y routine with my div and mflo commands in... this version of the hack always ends in the game freezing when I go to select my target.
BATTLE.BIN 0x0018F6C4 E4101580 formula 2D
BATTLE.BIN 0x801510E4 addiu r29, r29, 0xFFE8 0x801510E8 sw r31, 0x0010(r29) 0x801510EC jal 0x80188510 Physical Evade Calculation 0x801510F0 nop 0x801510F4 bne r2, r0, 0x8015118C 0x801510F8 nop 0x801510FC lui r5, 0x8019 0x80151100 lw r5, 0x2D94(r5) Load Attacker's Stats 0x80151104 lui r2, 0x8019 0x80151108 lbu r2, 0x3902(r2) Load Weapon Power 0x8015110C lui r3, 0x8019 0x80151110 lbu r3, 0x38FA(r3) Load Ability Y 0x80151114 lui r4, 0x8019 0x80151118 lbu r4, 0x0036(r4) Load Attacker's PA 0x8015111C lbu r5, 0x38F9(r5) Load Ability's X 0x80151120 addu r2, r2, r3 WP + Y 0x80151124 div r2, r5 0x80151128 mflo r2 (WP + Y) / X 0x8015112C nop 0x80151130 lui r1, 0x8019 0x80151134 sh r2, 0x38D0(r1) Store (WP + Y) / X as YA 0x80151138 lui r1, 0x8019 0x8015113C sh r4, 0x38CE(r1) Store PA as XA 0x80151140 jr r31 0x80151144 nop 0x80151148 jal 0x80185FA4 Element Strengthen Calculation 0x8015114C nop 0x80151150 jal 0x801886A4 Physical Damage Calculation 0x80151154 nop 0x80151158 jal 0x80186FD0 Weapon Elemental = Swordskill Routine (Fixed by Xifanie.) 0x8015115C nop 0x80151160 lui r2, 0x8019 0x80151164 lw r2, 0x2D90(r2) 0x80151168 nop 0x8015116C lbu r2, 0x0000(r2) 0x80151170 nop 0x80151174 beq r2, r0, 0x8015118C 0x80151178 nop 0x8015117C jal 0x801870FC Elemental Absorption 0x80151180 nop 0x80151184 jal 0x80187EB4 Status Proc 0x80151188 nop 0x8015118C lw r31, 0x0010(r29) 0x80151190 nop 0x80151194 jr r31 0x80151198 nop
I find it hard to believe no one has modified formula 2D in some way similar to this.. considering the common opinion within this community is that the swordskills have always been overpowered.
We need more WP, PA formula hacks!
Please help.
edit: all attempts were made with a patched iso and then a fresh iso as well
Title: Re: ASM hack for Formula 2D = Dmg_(PA*(WP+Y)/X) freezing game
Post by: Glain on December 04, 2020, 06:28:00 pm
The freezing is probably because you're corrupting the stack pointer (r29). You're subtracting from it at the start of the routine (the first instruction is really "addiu r29, r29, -0x0018" and then not adding that 0x18 back at the end. The solution is to insert "addiu r29, r29, 0x0018" at the end of your routine before the "jr r31" (or after it).
You are also inexplicably ending your routine after setting XA equal to PA. What is this doing here?
lui r1, 0x8019 # r1 = 0x80190000 lw r5, 0x2D94(r1) # Keep using r1 as the base... lbu r2, 0x3902(r1) lbu r3, 0x38FA(r1)
You would only have to repeat the lui after a routine call (jal).
It also looks like you got your wires crossed here:
0x80151114 lui r4, 0x8019 0x80151118 lbu r4, 0x0036(r4) # Load Attacker's PA Loading from 0x80190036? 0x8015111C lbu r5, 0x38F9(r5) # Load Ability's X Loading from (Attacker base pointer + 0x38F9)?
Title: Re: ASM hack for Formula 2D = Dmg_(PA*(WP+Y)/X) freezing game
Post by: Arimala on December 05, 2020, 07:50:50 am
Hmm I did not notice this... using the formula 2D Dmg (PA*(WP+Y)) on the wiki, "addiu r29, r29, 0x0018" did not get transferred over using import code because on the wiki it says: "27bd 0018 addiu r29,r29,0x 0018" instead of "27bd0018 addiu r29,r29,0x 0018" Is that space there for a reason? Most of the formulas on the wiki seem to be like that, but not all. I guess it is not intended for this use is why.
The first "jr r31" is just from me diving in head first and not knowing enough.. it was copied over from the Store PA and WP + Y routine. Everything is just copied over from the wiki. Started with formula 2D, replaced the "WP + Y as Y" routine with its actual code (https://ffhacktics.com/wiki/Store_PA_and_WP_%2B_Y (https://ffhacktics.com/wiki/Store_PA_and_WP_%2B_Y)) to divide it by X before the other routines. The divide by X code was taken from formula 42:
So if I can just keep using r1 as the base then you are telling me the code on the wiki is less efficient? From what I could see on all the code, anything new loaded in used a new register.
I am confused by the wires crossed bit though. This is taken directly from https://ffhacktics.com/wiki/Store_PA_and_WP_%2B_Y (https://ffhacktics.com/wiki/Store_PA_and_WP_%2B_Y).
lui r4, 0x8019 lbu r4, 0x0036(r4) Load Attacker's PA
and loading ability X is 0x38f9 in all the other formulas from what I saw
It looked so easy with the spreadsheet.. to just insert Load Ability X and then divide by X, guess I have some more reading/browsing to do.
Title: Re: ASM hack for Formula 2D = Dmg_(PA*(WP+Y)/X) freezing game
Post by: Glain on December 05, 2020, 01:54:27 pm
Quote from: Arimala on December 05, 2020, 07:50:50 amHmm I did not notice this... using the formula 2D Dmg (PA*(WP+Y)) on the wiki, "addiu r29, r29, 0x0018" did not get transferred over using import code because on the wiki it says: "27bd 0018 addiu r29,r29,0x 0018" instead of "27bd0018 addiu r29,r29,0x 0018" Is that space there for a reason? Most of the formulas on the wiki seem to be like that, but not all. I guess it is not intended for this use is why.
This is a mistake on the Wiki that stems from the way the formatting was done.
To elaborate, if you use View Source to look at how the code is formatted on basically any of the Wiki pages, you should see that each line actually starts with a space. This makes it so that the code formats the way we want it.
Generally when we put code on the Wiki, we're pasting it from a text file that doesn't have the spaces. So, to add the spaces, there were times when a certain search/replace was done. In this case, "0018" was replaced with " 0018" because the start of each line (the RAM address of the line) started with 0018. That did create the leading spaces, but also the side effects you're seeing.
Quote from: Arimala on December 05, 2020, 07:50:50 amSo if I can just keep using r1 as the base then you are telling me the code on the wiki is less efficient? From what I could see on all the code, anything new loaded in used a new register.
Yes, the code on the Wiki (the game's default code) is less efficient than it could be in many places, a product of the compiler they used. In some cases, very much so.
Quote from: Arimala on December 05, 2020, 07:50:50 amI am confused by the wires crossed bit though. This is taken directly from https://ffhacktics.com/wiki/Store_PA_and_WP_%2B_Y (https://ffhacktics.com/wiki/Store_PA_and_WP_%2B_Y).
Ability X is stored at 0x801938f9. What you're loading is 0x38f9 away from the acting unit's pointer. The acting unit's PA is stored 0x36 bytes away from its pointer, but you're instead loading from 0x80190036.
[0x80151114] lbu r4, 0x0036(r5) # Load PA of acting unit [0x80151118] lui r5, 0x8019 [0x8015111C] lbu r5, 0x38F9(r5) # Load Ability's X
Title: Re: ASM hack for Formula 2D = Dmg_(PA*(WP+Y)/X) freezing game
Post by: Arimala on December 06, 2020, 04:56:13 am
And now it works! (although it is still using the inefficient method) I kept the original code of the store PA and WP + Y routine to make sure I got it to work with X inserted in. I might go back and change it when I am not half asleep, but right now I am just happy it works.
I can use this to balance the sword skills and reconfigure a bunch of custom abilities I had paired with formulas that did not really match up. Finally Cleave will work the way I originally wanted it to.
This might keep me motivated to continue digging into the world of asm.
Thanks a bunch here! I really appreciate the guidance and patience Glain.