Author Topic: Editing Damage Formulas  (Read 13051 times)

Sega Chief

  • *
  • Posts: 4087
  • These guys is sick
    • View Profile
Editing Damage Formulas
« on: 2015-02-21 01:06:09 »
In short, is this possible? I think that a re-balance of FF7's battles needs something to be done with it's formulas. I've done what I can with fine-tuning, cuts, and other tricks but that can only go so far.

What I was specifically interested in was cutting down the Physical formula's dependency on Level, repurposing formulas for pulling other stats for calcs that use VIT or SPR instead of STR or MAG (I saw Stamina being used in a FF6 mod in place of Vigor/Magic for certain attacks and healing spells which created some interesting depth), adjusting the multipliers for Ultimate Weapon formulas, and giving magic attacks a critical hit check. How viable would any of these be?

nfitc1

  • *
  • Posts: 3011
  • I just don't know what went wrong.
    • View Profile
    • WM/PrC Blog
Re: Editing Damage Formulas
« Reply #1 on: 2015-02-21 13:40:00 »
I can tell you that changing calculations directly requires exe editing. Some of it can be difficult.

All of these are hard coded.

Sega Chief

  • *
  • Posts: 4087
  • These guys is sick
    • View Profile
Re: Editing Damage Formulas
« Reply #2 on: 2015-02-21 22:05:25 »
I can tell you that changing calculations directly requires exe editing. Some of it can be difficult.

All of these are hard coded.

Yeah, I've got a tool that I've used before to make small changes to the exe. What I'm looking for is some addresses or documentation on how the formulas are structured. So for instance is it possible to make the formula reference other stats, change the numbers used for the calculation, or to 'dummy out' parts of it? If there's no info on where the formulas are stored, do you have any recommendations for how to figure out where they are?

paul

  • *
  • Posts: 179
    • View Profile
Re: Editing Damage Formulas
« Reply #3 on: 2015-02-22 00:02:25 »
I love how that page isn't linked to by the FF7 section, I had no idea it existed.

nfitc1

  • *
  • Posts: 3011
  • I just don't know what went wrong.
    • View Profile
    • WM/PrC Blog
Re: Editing Damage Formulas
« Reply #4 on: 2015-02-22 00:05:20 »
Yeah, I've got a tool that I've used before to make small changes to the exe. What I'm looking for is some addresses or documentation on how the formulas are structured. So for instance is it possible to make the formula reference other stats, change the numbers used for the calculation, or to 'dummy out' parts of it? If there's no info on where the formulas are stored, do you have any recommendations for how to figure out where they are?
That page could use some offsets, couldn't it? As for other stats, that's mostly based on whether or not you make it a physical or magical action. There are also some hard-coded considerations in there, but those are documented. I can offer some help if you tell me what you need.

I love how that page isn't linked to by the FF7 section, I had no idea it existed.
Because it's very technical. Most people that come to the wiki don't want that level of detail.

Sega Chief

  • *
  • Posts: 4087
  • These guys is sick
    • View Profile
Re: Editing Damage Formulas
« Reply #5 on: 2015-02-22 04:32:29 »
That page could use some offsets, couldn't it? As for other stats, that's mostly based on whether or not you make it a physical or magical action. There are also some hard-coded considerations in there, but those are documented. I can offer some help if you tell me what you need.

Offsets are the spice of life.

I guess what I'm needing is the addresses for as many of these functions as possible, or some advice on how to track them down and make the changes. I'm hoping the physical formula is easy to change at least, though I can see the multipliers being a problem if there's no space to extend the calculation used for some of them (though a formula adjustment might be enough on it's own; the major problems they cause mostly comes in when damage starts to creep toward 5000).

So what I've been doing is some number crunching and looking for a way to adjust the physical attack formula that isn't too drastic and which a) pushes the emphasis away from character level and more toward the actual character attack instead and b) falls within some nice ranges for progression based more heavily on equipment. Here's what I've got:

[Old Formula]
x = ( Actor's Level * Actor's (M)Attack ) / 32
y = ( Actor's Level + Actor's (M)Attack ) / 32
z = Actor's (M)Attack + ( x * y )
z = z * ( 512 - target's defense ) * Attack's Power
Damage = z / 4096

[Proposed Fix]
x = ( Actor's Level + Actor's (M)Attack) / 2
y = ( Actor's Level + Actor's (M)Attack )/ 32
z = Actor's (M)Attack + ( x * y )
z = z * ( 512 - target's defense ) * Attack's Power
Damage = z / 4096

The value in X loses the multiplication between Lv and Attack, with a smaller division, which makes it scale a lot less while still getting a reasonable value out for the rest of the calculation to use. This is the scaling of physical damage using the proposed formula (hoping I've worked this out right):

[Lv.99 + 200 Attack vs. 100 Defence]
X = 150
Y = 9
Z1 = 1550
Z2 = 10316800
Damage = 2519

[Lv.99 + 200 Attack vs. 200 Defence]
X = 150
Y = 9
Z1 = 1550
Z2 = 7737600
Damage = 1889

[Lv.75 + 200 Attack vs. 100 Defence]
X = 138
Y = 9
Z1 = 1442
Z2 = 9505664
Damage = 2343

[Lv.50 + 200 Attack vs. 100 Defence]
X = 125
Y = 8
Z1 = 1200
Z2 = 7910400
Damage = 1931

[Lv.25 + 200 Attack vs. 100 Defence]
X = 113
Y = 7
Z1 = 991
Z2 = 6532672
Damage = 1595

[Lv.25 + 100 Attack vs. 100 Defence]
X = 63
Y = 4
Z1 = 352
Z2 = 2320384
Damage = 567

[Lv.10 + 200 Attack vs. 100 Defence]

X = 105
Y = 7
Z1 = 935
Z2 = 6163520
Damage = 1505

[Lv.10 + 50 Attack vs. 100 Defence]
X = 55
Y = 2
Z1 = 485
Z2 = 1054720
Damage = 258

So there's a nice upper range of 2500 (excluding multipliers) at the top levels + equipment, while the lower levels deal good chunks of damage with a decent low-high range that makes your set-up much more noticeable during the early stages of the game (whereas before you'd be looking at a difference of maybe 20-50 damage going through Lv.7-20).

Another part of getting physical attacks balanced properly is dealing with the crazy multipliers and reductions that the game adds (and stacks) to damage. As numbers get higher, these reductions/multipliers become more and more potent which makes it nearly impossible to get things under control. Reducing these %s would help things immensely:

Critical Hit:
Damage = Damage * 3 / 2 (1.5% increase)

Berserk:
Damage = Damage * 4 / 3 (1.25 increase)

Long Range Reduction
Damage = Damage / 4 * 3 (25% reduction)

Defend Reduction
Damage = Damage / 4 * 3 (25% reduction)

ficedula

  • *
  • Posts: 2178
    • View Profile
    • http://www.ficedula.co.uk
Re: Editing Damage Formulas
« Reply #6 on: 2015-02-22 09:22:28 »
Random thought: of the built in formula, X5 is pretty simple [base of Damage = (Actor's (M)Attack + Actor's Level) * 6 + (Attack's Power * 22) - which doesn't take many things into account].

It's possible in theory to change the actor's attack and level from an AI script, so you could set your attacks to always use formula 5 with some standard attack power, and then from within the AI script, alter the enemy's Attack value to whatever you wanted to effectively implement your own formula without having to alter the exe. Want to do different damage when the player is level 50+? Check for that in your AI script and increase the enemy attack accordingly.

For that matter, you could also alter the enemy's defence values in their setup scripts based on player level if you wanted to tune how easy they are to harm.

(Plug: that's something I'd like to build support for into Conformer to make it easier to do.... ;)

Of course this is all based on the enemy's AI. I'm not familiar with how much of this, if any, you can do from the player's side of things.

paul

  • *
  • Posts: 179
    • View Profile
Re: Editing Damage Formulas
« Reply #7 on: 2015-02-22 13:03:27 »
That page could use some offsets, couldn't it? As for other stats, that's mostly based on whether or not you make it a physical or magical action. There are also some hard-coded considerations in there, but those are documented. I can offer some help if you tell me what you need.
Because it's very technical. Most people that come to the wiki don't want that level of detail.

Everything on there is very technical so that reason makes no sense to me, if someone can understand all the stuff about file formats then this damage algorithm is simple.

Sega Chief

  • *
  • Posts: 4087
  • These guys is sick
    • View Profile
Re: Editing Damage Formulas
« Reply #8 on: 2015-02-22 13:19:11 »
Random thought: of the built in formula, X5 is pretty simple [base of Damage = (Actor's (M)Attack + Actor's Level) * 6 + (Attack's Power * 22) - which doesn't take many things into account].

It's possible in theory to change the actor's attack and level from an AI script, so you could set your attacks to always use formula 5 with some standard attack power, and then from within the AI script, alter the enemy's Attack value to whatever you wanted to effectively implement your own formula without having to alter the exe. Want to do different damage when the player is level 50+? Check for that in your AI script and increase the enemy attack accordingly.

For that matter, you could also alter the enemy's defence values in their setup scripts based on player level if you wanted to tune how easy they are to harm.

(Plug: that's something I'd like to build support for into Conformer to make it easier to do.... ;)

Of course this is all based on the enemy's AI. I'm not familiar with how much of this, if any, you can do from the player's side of things.

Does X5 check for things like Berserk, Critical hits, and long range though? I thought it was used with a magic formula. And while you can change the actor's level and attack stats in-battle, I'm not sure if you can tell the AI to use a different damage formula; at least, I don't have anything in my OP Code notes about it. Adjusting every character/enemy's attack, defence, and level prior to every attack would take a very long time to implement as a system. Though I could maybe add a calc into the character AI that divides down their Level by some amount so that it's less potent in physical damage calculations but that would mess around with Magical accuracy/evasion, stealing, etc.

nfitc1

  • *
  • Posts: 3011
  • I just don't know what went wrong.
    • View Profile
    • WM/PrC Blog
Re: Editing Damage Formulas
« Reply #9 on: 2015-02-22 20:48:02 »
Does X5 check for things like Berserk, Critical hits, and long range though? I thought it was used with a magic formula. And while you can change the actor's level and attack stats in-battle, I'm not sure if you can tell the AI to use a different damage formula; at least, I don't have anything in my OP Code notes about it. Adjusting every character/enemy's attack, defence, and level prior to every attack would take a very long time to implement as a system. Though I could maybe add a calc into the character AI that divides down their Level by some amount so that it's less potent in physical damage calculations but that would mess around with Magical accuracy/evasion, stealing, etc.
X5 should not do Berserk and Critical. It is only used as a magic formula in a vanilla game, but 15 suddenly becomes physical with physical attack accuracy. If that page doesn't state it checks for something then it doesn't.
There isn't any way to change the action's damage calculation before the action is performed. If you want another action with a different damage calculation then you'll have to create a new one.

Sega Chief

  • *
  • Posts: 4087
  • These guys is sick
    • View Profile
Re: Editing Damage Formulas
« Reply #10 on: 2015-02-22 21:25:40 »
X5 should not do Berserk and Critical. It is only used as a magic formula in a vanilla game, but 15 suddenly becomes physical with physical attack accuracy. If that page doesn't state it checks for something then it doesn't.
There isn't any way to change the action's damage calculation before the action is performed. If you want another action with a different damage calculation then you'll have to create a new one.

I thought so; changing it in AI for every enemy would be far too cumbersome in any case. A lot of enemies are already using AI to adjust stats for other things so it would turn into a bit of a mess.

So is it possible to adjust the formulas stored in the .exe? Do you happen to know the offset they're stored at? Even with just that, I can start looking at it and try to figure it out.

nfitc1

  • *
  • Posts: 3011
  • I just don't know what went wrong.
    • View Profile
    • WM/PrC Blog
Re: Editing Damage Formulas
« Reply #11 on: 2015-02-23 00:45:56 »
So is it possible to adjust the formulas stored in the .exe? Do you happen to know the offset they're stored at? Even with just that, I can start looking at it and try to figure it out.

In some fashion, yes, they can be edited. I know where they are all stored too, but I can't offer those until tomorrow.

Everything on there is very technical so that reason makes no sense to me, if someone can understand all the stuff about file formats then this damage algorithm is simple.

Quite true, but it IS linked to from the damage calculation page. It's not a straight shot. I still have two or three wiki pages of RAM values that aren't linked to anywhere. Check my contributions if you can figure out how to get to my user page.

Husbjörn

  • *
  • Posts: 36
    • View Profile
Re: Editing Damage Formulas
« Reply #12 on: 2015-03-14 22:54:16 »
Random thought: of the built in formula, X5 is pretty simple [base of Damage = (Actor's (M)Attack + Actor's Level) * 6 + (Attack's Power * 22) - which doesn't take many things into account].

I haven't tried it but off the top of my head, wouldn't X4 [MaxHP * (Strength / 32)] be better for that?
You could just set the strength to 32 and then perform whatever damage calculation you like in your script, temporarily store it to the using actor's max hp, perform the attack and then reset the maximum hp back to its original value.

About Conformer, would a minor quality of life update to allow empty / comment-only lines inside functions be a possibility in the not too remote future?
Awesome initiative on that project regardless, I was pondering writing a simple compiler for the battle scripts myself but... well, I would probably never have gotten around to it so great that someone did  ;D

DLPB_

  • Banned
  • *
  • Posts: 11006
    • View Profile
Re: Editing Damage Formulas
« Reply #13 on: 2015-03-17 17:41:33 »
Not sure if this already discussed but... Enemy Target Magic defence is doubled on battle start at 5D08DF (Ally data does not get doubled when they are target).

Urgh... I bet it's doubling all enemy stats too.  Wanna have a peak, NFITC1 :P
« Last Edit: 2015-03-17 17:45:16 by DLPB »

nfitc1

  • *
  • Posts: 3011
  • I just don't know what went wrong.
    • View Profile
    • WM/PrC Blog
Re: Editing Damage Formulas
« Reply #14 on: 2015-03-17 17:59:56 »
Physical Defense is doubled at 5D08CE, but that's the only other one.

DLPB_

  • Banned
  • *
  • Posts: 11006
    • View Profile
Re: Editing Damage Formulas
« Reply #15 on: 2015-03-17 18:10:38 »
Thanks :) Why does it do this?  Is this just like a lame last minute tweak they came up with?

nfitc1

  • *
  • Posts: 3011
  • I just don't know what went wrong.
    • View Profile
    • WM/PrC Blog
Re: Editing Damage Formulas
« Reply #16 on: 2015-03-17 18:36:55 »
Thanks :) Why does it do this?  Is this just like a lame last minute tweak they came up with?
There's literally no point to it as it could be offset by some divisor later in the calculation.

ex:
Code: [Select]
x = ( Actor's Level * Actor's (M)Attack ) / 32
y = ( Actor's Level + Actor's (M)Attack ) / 32
z = Actor's (M)Attack + ( x * y )
z = z * ( 256 - target's defense ) * Attack's Power
Damage = z / 2048
See? By changing the divisor at the last slot there and the defense modifier it will still produce the same results.
f1(x,y,z) = f2(x,y,z)
Unless there's some insane reason that f1 is somehow faster than f2, there is literally no reason to write an algorithm like this.

DLPB_

  • Banned
  • *
  • Posts: 11006
    • View Profile
Re: Editing Damage Formulas
« Reply #17 on: 2015-03-17 19:47:40 »
Also a note.  I had to change these for my mod:

{Menu potion, hi-potion, x-potion, ether, turbo ether to 25, 100, 1000, 10, 100
00716D83 = 6A 19
00716E11 = 6A 64 90 90 90
0071716F = 68 E8 03 00 00
00716EA2 = 6A 0A
00716F30 = 6A 64

{menu HP, MP
#6CBA6A
#6cbbbf

DLPB_

  • Banned
  • *
  • Posts: 11006
    • View Profile
Re: Editing Damage Formulas
« Reply #18 on: 2015-03-18 12:47:22 »
One more note.  This time, how the stupid stat section works.  People may find this useful.

Primary Stats
Code: [Select]
Strength = Base + LvBonus + MateriaBonus + WepArmAccBonus + PowerSource
Agility = Base + LvBonus + MateriaBonus + WepArmAccBonus + SpeedSource
Vitality =  Base + LvBonus + MateriaBonus + WepArmAccBonus + GuardSource
Magic = Base + LvBonus + MateriaBonus + WepArmAccBonus + MagicSource
Intellect = Base + LvBonus + MateriaBonus + WepArmAccBonus + MindSource
Luck = Base + LvBonus + MateriaBonus + WepArmAccBonus + LuckSource

Secondary Stats
Code: [Select]
Attack = Strength + WeaponStrength
Accuracy (%) = WeaponAccuracy
Defence = Vitality + ArmourDefence
Evasion (%) = (Agility / 4) + ArmourEvasion
Magic Attack = Magic
Magic Def = Intellect + ArmourMagicDefence
Magic Evasion (%) = ArmourMagicEvasion

OK, let's just get this out of the way...  Primary stats are largely worthless in working out what your battle strengths are.  The secondary stats are what you should be looking at, but they use the primary stats in their calculations.  Agility and Luck are the exceptions, as they have no secondary stat.

Take the Strength stat as an example...

Code: [Select]
Strength = Base + LvBonus + MateriaBonus + WepArmAccBonus + PowerSource
Base (initial Strength given to you at start of game)
LvBonus (Strength added at each level)
MateriaBonus (Strength added or subtracted by equipped materia)
WepArmAccBonus (Strength added by equipping Weapon / Armour / Accessory.  Note that only Accessories come with a description informing the player of the stat bonus.  This is probably an oversight).
PowerSource (+1 for each source, maximum sources allowed = 255).

So all that is used in determining the Strength stat. 

Next, the secondary stat, Attack:

Code: [Select]
Attack = Strength + WeaponStrength
The Weapon's strength is added.  Note that this is NOT the same as the bonus that was added to Strength.  This is the actual power of the weapon, which you can see in Equip.

The Attack stat, like all secondary stats, is limited to 255.  So what does that mean?  It means that as long as Attack is 255, that's as good as it gets.  Giving your character 255 power sources + other bonuses is worthless if the Attack stat is already 255.

What you have to realize is that the game designers have made this whole system more complicated than it needs to be.  All the stats can be amalgamated together and the final stat menu will look like this:

Code: [Select]
Attack
Attack Accuracy (%)
Defence
Evasion (%)
Magic Attack
Magic Defence
Magic Evasion (%)
Agility
Luck

In most RPGs this is how it is done, except the stats are named as in the Primary stat names of FF7.

Look at it another way...
Code: [Select]
Strength = Base + LvBonus + MateriaBonus + WepArmAccBonus + PowerSource
Code: [Select]
Attack = Strength + WeaponStrength
Can be amalagmated to
Code: [Select]
Attack (or better named "Strength") = Base + LvBonus + MateriaBonus + WepArmAccBonus + PowerSource + WeaponStrength

What I am doing for Reunion is:

-Making Base stats lower

-Massively reducing LvBonus and making it so players gain different bonuses depending on type.  For example, Barrett will gain far more strength than Aerith, who will in turn gain more magic.

-Tweaking MateriaBonus

- Tweaking Accessory Bonus, removing all Weapon bonuses, and possibly removing all armour bonuses.

-Limiting the number of sources a player can collect / use to 10 of each.

- Tweaking Weapon/Armour strength and Accuracy, Evasion, Magic Evasion.




« Last Edit: 2015-03-21 17:56:36 by DLPB »

nfitc1

  • *
  • Posts: 3011
  • I just don't know what went wrong.
    • View Profile
    • WM/PrC Blog
Re: Editing Damage Formulas
« Reply #19 on: 2015-03-18 13:53:57 »
You left out Spirit, btw. In the vanilla game that's all that influences MEvade.

Here's how I think it should be:
Code: [Select]
Strength = Base + LvBonus + PowerSource
Attack = Strength + MateriaBonus + WepArmAccBonus* + WeaponStrength
*I just call this "EquipBonus"

This way the "Primary" stat never decreases and it's Attack that fluctuates.

They probably shouldn't be referred to as "Primary/Secondary" stats, however. That implies (to me) they're all separate stats from each other. I've always called them "Base/Final" stats, but that's just me.

DLPB_

  • Banned
  • *
  • Posts: 11006
    • View Profile
Re: Editing Damage Formulas
« Reply #20 on: 2015-03-18 15:54:47 »
You left out Spirit, btw. In the vanilla game that's all that influences MEvade.

Here's how I think it should be:
Code: [Select]
Strength = Base + LvBonus + PowerSource
Attack = Strength + MateriaBonus + WepArmAccBonus* + WeaponStrength
*I just call this "EquipBonus"

This way the "Primary" stat never decreases and it's Attack that fluctuates.

They probably shouldn't be referred to as "Primary/Secondary" stats, however. That implies (to me) they're all separate stats from each other. I've always called them "Base/Final" stats, but that's just me.

Hmmm... no, that's "Intellect" and it affects Magic def. Magic Evade is entirely from Armour.
« Last Edit: 2015-03-18 18:50:18 by DLPB »

DLPB_

  • Banned
  • *
  • Posts: 11006
    • View Profile
Re: Editing Damage Formulas
« Reply #21 on: 2015-03-19 21:42:37 »
Hey, NFITC1... I went into the Physical Accuracy thing  a little but ran into a problem.  Also cross checked the assembly with terence guide
http://www.gamefaqs.com/ps/197341-final-fantasy-vii/faqs/22395

5DDBB0

 Any of the following will give an automatic 255 Hit%:
  * Back Attacking an enemy
   * Using an Element that the target has Death Weakness to
   * Using an Element that the target has Auto Hit Weakness to
   * Using an Element that the target is Immune to
   * Using an Element that the target Absorbs
   * If the target has any of the following statuses:
        Death, Sleep, Confusion, Stop, Petrify, Manipulate, Paralysed
   * If the target is Covering someone

Code: [Select]
5DDD38
Hit% = ([Attacker's Dex / 4]

5DDD47
+ At%)

UNSURE.  Also unsure why there are more divisions by 4 in function immediately after.
+ Attacker's Df% - Target's Df%

Code: [Select]
5DDD8E
(If Fury status)
Hit% = Hit% - [Hit% * 3 / 10]



Code: [Select]
5DDD9F
if (Hit% < 1) then Hit% = 1
Code: [Select]
5DDDDB
if Random (0..99) < (Attacker'sLuck / 4) then Hit% = 255 (Lucky Hit)

Code: [Select]
5DDE22 (uses same random number as above. Will only reach this stage if enemy does not get a Lucky Hit.  only characters can Lucky Evade.)

if Random(0..99) < (CharacterLuck / 4) then Hit% = 0 (Lucky Evade )

Code: [Select]
5DDE29
Random = [Rnd(0..65535) * 99 / 65535] + 1

Code: [Select]
5DDE37
If (Random < Hit%) Then Attack Hits

1. Need to know which part deals with the UNSURE part...
2. compiler mistake 5DDD2C (mov [ebp-10],eax and then mov eax,[ebp-10])??
3. why "and edx,03" at 5DDD33

Also Magic Accuracy:

Quote
          if target's M_Evade > rand_0 OR
                acc + acc_bonus < rand_1 then

is this

          if target's M_Evade > rand_0 OR
                acc + acc_bonus > rand_1 then
« Last Edit: 2015-03-19 23:06:41 by DLPB »

nfitc1

  • *
  • Posts: 3011
  • I just don't know what went wrong.
    • View Profile
    • WM/PrC Blog
Re: Editing Damage Formulas
« Reply #22 on: 2015-03-20 14:43:51 »
1. Need to know which part deals with the UNSURE part...
I've got this listed as
Code: [Select]
Actor Dex + Action Acc%
2. compiler mistake 5DDD2C (mov [ebp-10],eax and then mov eax,[ebp-10])??
Mistake? I don't know if I'd go that far. Unoptimized certainly, but you won't get better than that from a compiler.

3. why "and edx,03" at 5DDD33
That has to do with the cdq command immediately preceding that line. It's attempting to change the scope of the value that comes out of the function at 0x5C7EB3. I've got documentation on what that means and why it's done, but I've actually never read it. :P

Also Magic Accuracy:

is this

          if target's M_Evade > rand_0 OR
                acc + acc_bonus > rand_1 then
Neither. It's actually:
Code: [Select]
If target's M_Evade > rand_0 then
   GOTO Action Miss
if acc + acc_bonus > rand_1 then
   GOTO Check Complete
ACTION MISS:
   Action misses
CHECK COMPLETE:
Return
If the target's M_Evade is high enough then the action misses. If that check fails then it checks the accuracy. If the accuracy is high enough then it doesn't miss. That's the same logically as what I wrote.

DLPB_

  • Banned
  • *
  • Posts: 11006
    • View Profile
Re: Editing Damage Formulas
« Reply #23 on: 2015-03-20 15:38:52 »
Quote
I've got this listed as
Code: [Select]
Actor Dex + Action Acc%

Ah yeah, what I mean is, how is this done in assembly.  I can't follow it well because there are functions with a div  4 and I can't see why there have to be 3 of them at the start of code (2 from a function that gets called twice).  I want to edit this but without understanding how it's working in assembly I am at a loose end.  I guess if I could find out, but you prob already know :P  Also, Terrence has it different to you.

Edit... I think I might understand it now... Possibly.  Evasion (DF%) is calculated by Agility (dex) / 4, and then the armour stat is added.  I didn't know this.
Quote
Mistake? I don't know if I'd go that far. Unoptimized certainly, but you won't get better than that from a compiler.

What I mean is one of those instructions is redundant?  It's putting the value into ebp from eax and then just putting ebp back into eax again.

mov [ebp-10],eax
mov eax,[ebp-10]

could just be

mov [ebp-10],eax
« Last Edit: 2015-03-20 17:43:27 by DLPB »

nfitc1

  • *
  • Posts: 3011
  • I just don't know what went wrong.
    • View Profile
    • WM/PrC Blog
Re: Editing Damage Formulas
« Reply #24 on: 2015-03-20 18:50:54 »
Quote
What I mean is one of those instructions is redundant?
Yes, but compilers usually aren't in the habit of merging lines of code like that. If I had a snippet like this:

Code: [Select]
int foo = bar();
foo += 2;

Then the assembler would likely turn out something like this:
Code: [Select]
call   bar
mov    foo, eax
mov    eax, foo
add    eax, 2
mov    foo, eax

That's obviously two lines too long for what I want to happen, but it accomplishes the same goal. This is also partly for debugging purposes that it treats each line like its own chunk of isolated code. If I wrote it like:

Code: [Select]
int foo = bar() + 2
Then it would likely give me a more optimized assembler:
Code: [Select]
call   bar
add    eax, 2
mov    foo, eax