Author Topic: Only Evasion from Shields is counted  (Read 243 times)

Xardas

  • Guard Leader
  • *
  • Posts: 42
    • View Profile
Only Evasion from Shields is counted
« on: April 03, 2017, 03:27:50 AM »
Today I made a unpleasant discovery. I don't know if this is new to you, but I still want to talk about this.
So the mod I am working for should have equipment other than Shields which boost Evasion. Although being displayed correctly in the Equipment Menu, it has literally no effect in battle. To clarify, I made an armor which gives you 90 Evasion. My characters still got hit every time. Then I added a Shield which gives extra 9, to have a total of 99. In battle, it seemed that the characters behaved like having only 9 Evasion.
Now FFV also seems to have an Evade bug  :wink:

Squall

  • Liquid Flame
  • *
  • Posts: 301
    • View Profile
Re: Only Evasion from Shields is counted
« Reply #1 on: April 03, 2017, 05:19:13 AM »
Its not a bug, its intended behavior.

If you check the gear you will see that only shields have Physical Evasion set. Also if you check how things are stored in the memory:
Code: [Select]
$200E = Headgear
$200F = Bodywear
$2010 = Accessory
$2011 = Right Hand Shield
$2012 = Left Hand Shield
$2013 = Right Hand Weapon
$2014 = Left Hand Weapon
You may notice that the game uses 2 bytes for each hand - weapon and a shield. I will not be surprised if the game take into account only $2011 and $2012 when calculating the evasion, instead of $200F .. $2012

 :edit:
Code: [Select]
Check for Physical Hit
C2/7E23: 20 A2 02     JSR $02A2
C2/7E26: C5 4E        CMP $4E        Check (0..99) < Hit%
C2/7E28: B0 2E        BCS $7E58      Miss if (0..99) >= Hit%
C2/7E2A: A6 49        LDX $49
C2/7E2C: BD 1B 20     LDA $201B,X
C2/7E2F: 1D 71 20     ORA $2071,X
C2/7E32: 29 70        AND #$70       (Target Status2 = Sleep, Charm or Paralyze)
C2/7E34: D0 24        BNE $7E5A      Can't Evade
C2/7E36: BD 1C 20     LDA $201C,X
C2/7E39: 29 10        AND #$10       (Target Status3 = Stop)
C2/7E3B: D0 1D        BNE $7E5A      Can't Evade
C2/7E3D: 20 A2 02     JSR $02A2
C2/7E40: C5 4F        CMP $4F        Check (0..99) < Evade%
C2/7E42: B0 16        BCS $7E5A      Hit if (0..99) >= Evade%
C2/7E44: A6 49        LDX $49
C2/7E46: BD 11 20     LDA $2011,X
C2/7E49: 1D 12 20     ORA $2012,X
C2/7E4C: F0 0A        BEQ $7E58
C2/7E4E: A5 47        LDA $47        (Can't Miss if Attacker = Target)
C2/7E50: C5 48        CMP $48
C2/7E52: F0 06        BEQ $7E5A
C2/7E54: A9 06        LDA #$06
C2/7E56: 85 5D        STA $5D
C2/7E58: E6 56        INC $56        Attack Misses
C2/7E5A: 60           RTS
Yeah you can see it in the code only $2011 and $2012

Xardas

  • Guard Leader
  • *
  • Posts: 42
    • View Profile
Re: Only Evasion from Shields is counted
« Reply #2 on: April 03, 2017, 05:51:19 AM »
I see. It seems rather difficult to add checks for Head, Armor and Accessory to me, as it's not coded as $2011 ... $2012.

But does this also apply to the GBA version? Because there is an Accessory called "Sorceror's Mantle" which boosts your Evasion by 10.

Xardas

  • Guard Leader
  • *
  • Posts: 42
    • View Profile
Re: Only Evasion from Shields is counted
« Reply #3 on: April 03, 2017, 05:34:33 PM »
I haven't looked into the GBA ROM since I "can't read" those yet. So instead, I tested the Sorceror's Mantle ingame. And it seems that it has no impact on dodging, despite of boosting Evasion by 10.
Its not a bug, its intended behavior.
Maybe it was intended in first place, since there is no Evasion boosting Equipment other than Shields in the SNES version. My guess is that the team which worked on the GBA remake forgot or didn't know that only Shield-Evasion is counted, so at least for the GBA version, it is arguably a bug.

By the way, I have the feeling that if Evasion from other pieces of equipment can be made to work, that the game will always use the Shield block animation, even if the character doesn't have one equipped. But I still would prefer that over the current situation ^^

LightPhoenix

  • FF5 Hacker
  • *
  • Posts: 122
    • View Profile
Re: Only Evasion from Shields is counted
« Reply #4 on: April 03, 2017, 09:01:18 PM »
Code: [Select]
Check for Physical Hit
C2/7E23: 20 A2 02     JSR $02A2
C2/7E26: C5 4E        CMP $4E        Check (0..99) < Hit%
C2/7E28: B0 2E        BCS $7E58      Miss if (0..99) >= Hit%
C2/7E2A: A6 49        LDX $49
C2/7E2C: BD 1B 20     LDA $201B,X
C2/7E2F: 1D 71 20     ORA $2071,X
C2/7E32: 29 70        AND #$70       (Target Status2 = Sleep, Charm or Paralyze)
C2/7E34: D0 24        BNE $7E5A      Can't Evade
C2/7E36: BD 1C 20     LDA $201C,X
C2/7E39: 29 10        AND #$10       (Target Status3 = Stop)
C2/7E3B: D0 1D        BNE $7E5A      Can't Evade
C2/7E3D: 20 A2 02     JSR $02A2
C2/7E40: C5 4F        CMP $4F        Check (0..99) < Evade%
C2/7E42: B0 16        BCS $7E5A      Hit if (0..99) >= Evade%
C2/7E44: A6 49        LDX $49
C2/7E46: BD 11 20     LDA $2011,X
C2/7E49: 1D 12 20     ORA $2012,X
C2/7E4C: F0 0A        BEQ $7E58
C2/7E4E: A5 47        LDA $47        (Can't Miss if Attacker = Target)
C2/7E50: C5 48        CMP $48
C2/7E52: F0 06        BEQ $7E5A
C2/7E54: A9 06        LDA #$06
C2/7E56: 85 5D        STA $5D
C2/7E58: E6 56        INC $56        Attack Misses
C2/7E5A: 60           RTS
Yeah you can see it in the code only $2011 and $2012

That code is not where the Evasion stat is calculated.  $4F holds the evasion chance; it is loaded on a per attack basis.

Evasion is calculated as part of the clown fiesta that is the equipment calculation code (home of Mirage Vest, Thornlet, and other bugs).  The specific calculation is at C2/9BCB, and stored into $202C,X.  Note however that this code also only uses Shield Evasion.  If you want to change evasion to use everything, you'll want to do that here.  That way it will always get calculated correctly when stats are recalculated.

Okay, so what is that shield check doing then?

The CMP $4F/BCS is branching if you have hit (note it jumps past setting the miss flag).  The next step is checking if the target has a shield equipped; if they don't, set the miss flag and exit.  Then obviously auto-hit if you're attacking yourself.  Finally, we set a value of 06 to $5D.  You should suspect already what this is - something only set when blocking with a shield equipped.  This is an index to what "evade" animation will play.  Try changing the value to see other animations (for example 00 is nothing and 03 is the cape).

Xardas

  • Guard Leader
  • *
  • Posts: 42
    • View Profile
Re: Only Evasion from Shields is counted
« Reply #5 on: April 04, 2017, 05:25:53 AM »
So I was wrong with my assumption about the animation.  :happy:
Meanwhile I decided to add this in the Wiki's Bug section, I hope Jorgur doesn't mind.
http://slickproductions.org/slickwiki/index.php/FF5_Bugs_and_Glitches#Miscellaneous

x0_000

  • Antlion
  • *
  • Posts: 55
    • View Profile
Re: Only Evasion from Shields is counted
« Reply #6 on: April 04, 2017, 08:21:18 PM »
By the way, I have the feeling that if Evasion from other pieces of equipment can be made to work, that the game will always use the Shield block animation, even if the character doesn't have one equipped. But I still would prefer that over the current situation ^^
The game can sort evasion animation, it has different animations based on whether you evade from Shields, Elven Cloak, Main Gauche and Mineuchi (the samurai skill.)

Squall

  • Liquid Flame
  • *
  • Posts: 301
    • View Profile
Re: Only Evasion from Shields is counted
« Reply #7 on: April 05, 2017, 03:36:38 AM »
Quote
That code is not where the Evasion stat is calculated.  $4F holds the evasion chance; it is loaded on a per attack basis .

Evasion is calculated ... at C2/9BCB, and stored into $202C,X.
Yes I noticed that after Posting the comment. I traced it back to $202C but couldn't go deeper.

Today I checked again and voila: it seems that the gear specific bytes is loaded in a similar manner with a code around C2:9AAD in the RAM with address $4049:
Code: [Select]
$4049 = Headgear
$4055 = Bodywear
$4061 = Accessory
$406D = Right Hand Shield
$4079 = Left Hand Shield
$4085 = Right Hand Weapon
$4091 = Left Hand Weapon

Evasion is with offset 6, so rShield evasion is $4073, lShield is $407F. Thats what the code uses:
Code: [Select]
C2/9BCB: 18           CLC
C2/9BCC: B9 73 40     LDA $4073,Y
C2/9BCF: 79 7F 40     ADC $407F,Y
C2/9BD2: C9 63        CMP #$63
C2/9BD4: 90 02        BCC $9BD8
C2/9BD6: A9 63        LDA #$63
C2/9BD8: 9D 2C 20     STA $202C,X

Xardas

  • Guard Leader
  • *
  • Posts: 42
    • View Profile
Re: Only Evasion from Shields is counted
« Reply #8 on: April 05, 2017, 03:50:37 AM »
Excellent work Squall! Always good to see that more and more stuff gets discovered even these days.
The game can sort evasion animation, it has different animations based on whether you evade from Shields, Elven Cloak, Main Gauche and Mineuchi (the samurai skill.)
I think we all know that...
My assumption (wich I already admited to be wrong!) was, that in case of Evasion via Evasion stat, the game will use shield animation because there is not other means of raising this stat.
Even Claok, Main Gauche, Hardened and "The Samurai Skill" do not raise the Evasion stat. They use specific checks.
Also, Mineuchi is Sword Slap. The dodging skill is Shirahadori. ;)

LightPhoenix

  • FF5 Hacker
  • *
  • Posts: 122
    • View Profile
Re: Only Evasion from Shields is counted
« Reply #9 on: April 06, 2017, 11:17:14 PM »
Which animation is used depends on order of operations in the functions.

(Not strictly true - it's based on checking the Miss Flag ($56).  When it gets set, the function is over.  So the animation byte could theoretically get overwritten after the fact.)

For example: the hit determination at 7EBE calls the Evade/Parry/Elf Cape check before the Shield check.  So those will always take precedence if they trigger.  Within that function, the order is Evade (ability) > Parry (Defender) > Parry (Guardian) > Elf Cape.

You could certainly change that order pretty easily though.

Xardas

  • Guard Leader
  • *
  • Posts: 42
    • View Profile
Re: Only Evasion from Shields is counted
« Reply #10 on: April 08, 2017, 12:02:19 PM »
Interesting.

So, is there any way to "activate" evasion for Hats, Armor and Accessory? (Not a commission - don't get me wrong)

My solution so far is replacing "Right Hand Shield" with "Body Armor", so I can at least make Armor Evasion work. Of course I will (and have to) warn everyone that shields will only work on the Left Hand.

LightPhoenix

  • FF5 Hacker
  • *
  • Posts: 122
    • View Profile
Re: Only Evasion from Shields is counted
« Reply #11 on: April 08, 2017, 04:39:57 PM »
Expand the code at C2/9BCB.  See other code in that area, which does similar things for other stats.

Squall

  • Liquid Flame
  • *
  • Posts: 301
    • View Profile
Re: Only Evasion from Shields is counted
« Reply #12 on: April 20, 2017, 02:05:18 AM »
LightPhoenix, is there a project that you currently work on?

LightPhoenix

  • FF5 Hacker
  • *
  • Posts: 122
    • View Profile
Re: Only Evasion from Shields is counted
« Reply #13 on: April 22, 2017, 02:57:02 PM »
Nothing specific.  I've been very busy with work and life, and have had very little time to work on any big projects.

I (of course) have a big project that is basically rebalancing classes and abilities, and eventually making battles less frequent and more interesting.

I would like to keep working on bugfixes, but a lot of them require more thorough rewrites.  For example, all the equip bugs in battle (Thornlet, Mirage Vest, Mix bugs, a few others) can be fixed by rewriting the recalculation function to take into account stuff.  It's a larger undertaking than it seems at first blush though.

I would love to do more thorough work on understanding C1 and graphics/animation in general.  That's not really a romhack though, just information gathering.  It's been a long time since I've looked at any of that.  Specifically, I really want to get a handle on window drawing.

Squall

  • Liquid Flame
  • *
  • Posts: 301
    • View Profile
Re: Only Evasion from Shields is counted
« Reply #14 on: Yesterday at 01:58:17 AM »
Quote
I would love to do more thorough work on understanding C1 and graphics/animation in general.  That's not really a romhack though, just information gathering.
Wooah I'm getting inpatient to hear about your findings there. Personally graphics/animation is my preferred thing, but when I started I said to myself that I will abstain from platform specific code and focus on FFV algorithms. Of course the temptation is huge, so I did some digging. If you have specific question ask so if I know something I will gladly share.
I dont know what C1 disassembly you will use but I got one from noisercross ... and in my opinion its the best non-comment one. If you cant find it I will try to contact him for permission to share, but I'm afraid I dont have clean, just the one with my notes on it.

Quote
Specifically, I really want to get a handle on window drawing.
I think noisercorss know much about it, because he has implemented some of it in his TextEditor.