Qhimm.com Forums

Miscellaneous Forums => Scripting and Reverse Engineering => Topic started by: antd on 2009-05-30 19:04:09

Title: FF7 Critical Hit Formula?
Post by: antd on 2009-05-30 19:04:09
hey, I'm currenty doing a FF7 TAS and I've come to the point where I need to find out a formula to predict when I can get a critical hit.

How would I go about doing this?

I know already know some things. For example, if I attack on frame 10 and it's a critical. Then I can add 65336 to it, and that frame will also result in a critical hit. The pattern repeats itself after 65536!


I have a test battle where I've written down precisely which frame results in a critical hit or 'miss'. I can use that to do RAM searches/comparisons against.
I'm using frame advance, so I can do frame perfect stuff...

Any ideas? :mrgreen:
Title: Re: FF7 Critical Hit Formula?
Post by: Vanit on 2009-06-02 04:54:12
Sadly, there's almost no documentation on this formula. The only thing I've been able to find is this (http://forums.ffonline.com/showthread.php?t=50995) which would be useful for deriving an algorithm. But as for finding out the real one, not so easy.

I'm working on recreating the battle system so I'll be deriving one soon. I'll report back with what I come up with.
Title: Re: FF7 Critical Hit Formula?
Post by: antd on 2009-06-02 06:59:36
Sadly, there's almost no documentation on this formula. The only thing I've been able to find is this (http://forums.ffonline.com/showthread.php?t=50995) which would be useful for deriving an algorithm. But as for finding out the real one, not so easy.

I'm working on recreating the battle system so I'll be deriving one soon. I'll report back with what I come up with.
excellent stuff
Title: Re: FF7 Critical Hit Formula?
Post by: DLPB_ on 2009-06-02 07:03:51
side note. 

performance with vista x64 drops to 25 fps in towns


Dunno if thats with your drivers but I doubt it, it is just something to do with the game or graphics card ....i dunno

It was 27 when recording with xp and now its 25 fps even when its not.

It will run at 30 fps if vsync is off.

edit:  only goes to 25 fps when running at 75 hz  at 60 hz runs ok window mode (still 25fps when recording though).  Didnt do this with xp though?
Title: Re: FF7 Critical Hit Formula?
Post by: Terid__K on 2009-06-02 07:37:24
^ I think you're in the wrong topic buddy.

Title: Re: FF7 Critical Hit Formula?
Post by: Akari on 2009-06-03 19:01:19
Formula is simple.

Damage is doubled if critical.
Critical will always happened if we in lucky girl status or it calculated as follows

in case of enemies:
Code: [Select]
if (random(1-100) <= (attacker_level + attacker_luck - target_level) / 4)
{
// critical
}
in case of player:
Code: [Select]
if (random(1-100) <= (attacker_level + attacker_luck - target_level) / 4 + attacker_weapon_critical)
{
// critical
}
Title: Re: FF7 Critical Hit Formula?
Post by: Vanit on 2009-06-04 13:22:56
attacker_weapon_critical = Attack%?

Also would you happen to know the evasion and hit formulas?
Title: Re: FF7 Critical Hit Formula?
Post by: antd on 2009-06-04 14:28:42
Actually this isn't what I'm asking for :P

I'm specifically asking for the part you call random. It's actually not random at all  :evil:
Well, I've almost figured it out now anyway.

With the formula I'm asking for, you would be able to predict when a critical hit is 'possible'...
Assuming you could play frame by frame.
Title: Re: FF7 Critical Hit Formula?
Post by: Akari on 2009-06-04 17:50:46
attacker_weapon_critical = Attack%?

Also would you happen to know the evasion and hit formulas?

Yes I know them.
Code: [Select]
random = random(1-100);
if (random < attacker_luck / 4)
{
  // we hit
}
elseif (random < target_luck / 4)
{
  // we miss
}
elseif (random(1-100) < (attack_hit% + attacker_dexterity / 4 + attacker_evade - target_evade))
{
  // we hit
}

Note: this functions are for 0x1X type attacks (physical). Others may always hit or use other hit/critical formula's.
Title: Re: FF7 Critical Hit Formula?
Post by: Vanit on 2009-06-05 12:55:19
Thanks Akari. :)
Title: Re: FF7 Critical Hit Formula?
Post by: Vanit on 2009-06-14 09:34:46
I don't suppose you'd know the magic evasion and hit formulas also?
Title: Re: FF7 Critical Hit Formula?
Post by: Akari on 2009-06-14 12:58:16
I don't suppose you'd know the magic evasion and hit formulas also?

Code: [Select]
random = random(1-100);
if (attack_hit% >= 0xff)
{
  // we hit
}
elseif (random < target_magic_evade)
{
  // we miss
}
elseif (random(1-100) + 1 < (attack_hit% + attacker_level - target_level / 2))
{
  // we hit
}
else
{
  // we miss
}
Title: Re: FF7 Critical Hit Formula?
Post by: nfitc1 on 2009-07-08 12:35:31
attacker_weapon_critical = Attack%?

Also would you happen to know the evasion and hit formulas?

Yes I know them.
Code: [Select]
random = random(1-100);
if (random < attacker_luck / 4)
{
  // we hit
}
elseif (random < target_luck / 4)
{
  // we miss
}
elseif (random(1-100) < (attack_hit% + attacker_dexterity / 4 + attacker_evade - target_evade))
{
  // we hit
}

Note: this functions are for 0x1X type attacks (physical). Others may always hit or use other hit/critical formula's.

Isn't it like this for the 0xAX types of the ultimate weapons too?
Title: Re: FF7 Critical Hit Formula?
Post by: Akari on 2009-07-09 02:10:06
attacker_weapon_critical = Attack%?

Also would you happen to know the evasion and hit formulas?

Yes I know them.
Code: [Select]
random = random(1-100);
if (random < attacker_luck / 4)
{
  // we hit
}
elseif (random < target_luck / 4)
{
  // we miss
}
elseif (random(1-100) < (attack_hit% + attacker_dexterity / 4 + attacker_evade - target_evade))
{
  // we hit
}

Note: this functions are for 0x1X type attacks (physical). Others may always hit or use other hit/critical formula's.

Isn't it like this for the 0xAX types of the ultimate weapons too?

Upper 4 bits are used like this:

Code: [Select]
switch (V0)
{
    case 0x01 0x06 0x0A:
    {
        upper_function_00; // add physical hit
        upper_function_02; // add critical hit
    }
    break;

    case 0x02 0x07:
    {
        upper_function_01; // add magical hit
    }
    break;

    case 0x03 0x4 0x5:
    {
        upper_function_03; // do nothing
    }
    break;

    case 0x08:
    {
        upper_function_07; // hit by hit % target level
    }
    break;

    case 0x09:
    {
        upper_function_06;// hit if can be manipulated
    }
    break;

    case 0x0B:
    {
        upper_function_00; // add physical hit
    }
    break;
}

By default all attacks hit normaly. After function call it can add mis flag and critical flag.

Could someone say which attack use battle formula 0x96? I see this formula in wall market but I didn't see attack with this formula.

ps: All this reversing are in SVN now. You can see it there for yourself.
pps: Someone can help with reversing )
Title: Re: FF7 Critical Hit Formula?
Post by: Xelane on 2009-07-09 03:07:50
Can someone please explain to me what all of this data means and how it is read? The reason i'm asking is because I think it might be worthwhile to learn about this stuff.

Feel free to say no (like u need my permission anyway...) it's just something i'd hope to understand
Title: Re: FF7 Critical Hit Formula?
Post by: Satoh on 2009-07-26 08:36:32
Can someone please explain to me what all of this data means and how it is read? The reason i'm asking is because I think it might be worthwhile to learn about this stuff.

Feel free to say no (like u need my permission anyway...) it's just something i'd hope to understand

I think I'm ok to post... it hasn't been 30 days...?

I'll try, but there's more to this than just understanding programming logic, which is all I can explain for you.

Code: [Select]
switch (V0)This looks up the value stored in V0
Code: [Select]
{
    case 0x01 0x06 0x0A:
    {
If V0 is hexadecimal number 1, 6, or A...
Code: [Select]
        upper_function_00; // add physical hit
        upper_function_02; // add critical hit
    }
do these two operations and then...
Code: [Select]
    break;
Stop processing this Switch. (until it is called again by another function)
Code: [Select]

    case 0x02 0x07:
    {
        upper_function_01; // add magical hit
    }
    break;

    case 0x03 0x4 0x5:
    {
        upper_function_03; // do nothing
    }
    break;

    case 0x08:
    {
        upper_function_07; // hit by hit % target level
    }
    break;

    case 0x09:
    {
        upper_function_06;// hit if can be manipulated
    }
    break;

    case 0x0B:
    {
        upper_function_00; // add physical hit
    }
    break;
}

These are the same basic process, but checking for different values and doing different operations as a result.


Imagine this...

Code: [Select]
Switch (YourName)
{
     case "Bob":
     {
     print "Hello Bob.";
     }
     break;

     case "George":
     {
     print "I don't like the name George."
     }
     break;
}

That is the same type of code, and it tells the computer to say one thing or another based on what YourName is. (Sorry if that's more basic than you intended me to answer...) But for further info on programming you should look into something like Beginner's C++ or Python tutorials... (for just learning the logic, you can pick it up fairly quickly with something simple like Game Maker, but don't expect to program the next FF game in that...)

Good luck... and I hope I didn't break thread too much...