Final Fantasy Hacktics

Modding => Help! => Topic started by: Fantactic on January 09, 2013, 10:14:19 pm

Title: Trying to understand ASM Hacking
Post by: Fantactic on January 09, 2013, 10:14:19 pm
Greetings
First and formost, I would like to express my deepest and sincerest gratitude to the ingenious founders of this site and all benevolent souls who have and continue to dilegently lend and sacrifice there time and energy to better the FFT experience, not only for there own sake, but for that of others. Thank you. this is truly a gift. God Bless.

ahmm.. to the point
a quick question about asm editing. I try to fathom how changing hex code (or hexdecimal or is it call that because they are convertable with each other?) causes anything to happen. But i do get that certain codes may trigger hard-coded things to happen like a graphic.
I just stumbled across this "master windows-1252" and wonder if this is all asm means?

My question is this, if for instance I want to change a weapon formula, would i just write the equation, in asm language (obviously in the correct offset (is that the term?)) and presto bango?? formual successfully changed.
and I assume the control characters do things like call files or trigger this that and the other thing?

I know, I'm a complete noob but i'm trying to understand, I get the feeling I will need to learn ASM Editing in or to get this game the way I want it.

That Call of Power is inspiring!
Title: Re: Trying to understand ASM Hacking
Post by: Kokojo on January 09, 2013, 10:24:47 pm
First, thank you very much!

For ASM and many more complex help, I really recommend going on IRC and asking around our asmer - FDC is often there, as are many more.

Persist!
Title: Re: Trying to understand ASM Hacking
Post by: Glain on January 10, 2013, 12:57:16 pm
Hex is indeed an abbreviation for hexadecimal: a base-16 number.

Unfortunately, you're on the wrong track with that Windows 1252 table.

As for how these hex codes can change the behavior of the game... in the right circumstances, hex numbers can not only represent data, but in code segments they represent machine code (http://en.wikipedia.org/wiki/Machine_code), the game's program code itself!

This machine code is an encoded from of assembly language (http://en.wikipedia.org/wiki/Assembly_language) (ASM).  Assembly language is specific to the computer architecture it's used on; luckily, the PSX processor uses MIPS, a pretty common architecture.  There's a good tutorial for it here (http://programmedlessons.org/AssemblyTutorial/).

If you were to look at how the formulas are implemented, it's not so much writing an equation as a sequence of steps...

You might think of a damage formula as an equation, like:
Damage = PA * (WP + Y)

If we wanted to write a sequence of logical steps that could implement this formula, we might break it down into something like:

add         temp_value, WP, Y                 # Set temp_value = WP + Y
multiply    Damage, PA, temp_value         # Set Damage = PA * temp_value

Turns out the PSX regards performing multiplication and moving the product into a variable as two separate tasks, so we'd break it up like this:

add         temp_value, WP, Y                 # Set temp_value = WP + Y
mult        PA, temp_value                      # Calculate (PA * temp_value)
mflo        Damage                                # Damage = (the multiplication result)

The CPU can only do math on its registers, so we'd have to substitute register numbers for our variables.  Let's say we had loaded up the registers so that $8 = WP, $9 = Y, $10 = PA:

add    $11, $8, $9   
mult   $10, $11         
mflo   $2                 

We could then transform that ASM into the PSX machine code, which would end up as the hexadecimal numbers you see. 

There would be a few other pieces to this puzzle before the formula was complete (loading the register values from memory, saving the result to memory), but it wouldn't be strange to see code like this in a formula.

Hopefully that's not all too confusing... it's a lot of information at once.  As Kokojo said, you can always ask ASMers on IRC for assistance; we're happy to help people trying to learn.
Title: Re: Trying to understand ASM Hacking
Post by: Fantactic on January 13, 2013, 03:31:20 pm
Thank so for the help.
I've been doing some studying and that actually did make sense. but a question, if we set registers to represent WP, Y, etc. must they always be used as such. Also how would you account for varying WP strength, ex: mythril dagger is WP 4 and dagger is WP 3? or is that the Y value?
Also I came across a vid on youtube that showed a "MIPS Reference Data" sheet and how to convert binary to hex and hex to binary. When you talk about converting ASM to machine language is R-type or I-type relevant here, appearently it relates to the command being executed.

And one more, what is proc? i thought i increased the probability of inflicting status effects using weapons, ex: blind knife potentially causes blind 90% of the time. And is it possible to increase the probability?

sorry one more, when I look at some of the forumal sheets, actually most of them, it says things like 0x74 or 0x0A what do i do with that, what does it mean? in the hex editor (HxD) there are 16 slot and 2 digit each totaling 32. 0x74 seems like it could be any one of those??
Title: Re: (No subject)
Post by: Pride on January 13, 2013, 07:23:47 pm
Before any formula data is excuted, there's a well documented routine that stores the value of your held weapon into RAM 0x80193902. So when writing your code:
lui r2,0x8019
lbu r2,0x3902(r2)

This would load your currently held weapon into r2 to be used in your calculations. You could also write a routine to find the value of your currently held weapon from its static location in SCUS but it wouldnt be needed in this case.

I have an ASM hack that allows all weapons and abilities to each have a unique proc rate. With no changes to vanilla play the rate would be 0, 19, or 100.
Title: Re: Trying to understand ASM Hacking
Post by: Glain on January 14, 2013, 12:46:53 pm
As far as converting from assembly language to machine code is concerned, the MIPS instruction type (R-type, I-type, etc.) is indeed relevant, but I have a program that does all that automatically, attached to this thread (http://ffhacktics.com/smf/index.php?topic=7130.0).  You can just type in the assembly and it will convert to hex.