News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Final Fantasy II Restored  (Read 7970 times)

redmagejoe

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Final Fantasy II Restored
« on: December 10, 2019, 03:09:14 am »
Bug Fix To-Do List:
  • FIXED Stats @ 99 still run increase routines, causing decreases to their counterparts and message spam. Prevent this check on maxed stats.
  • FIXED HP/MP have no cap, resulting in potential for overflow, and display bugs even before the 2 byte ceiling. Prevent code from raising HP/MP above 9999/999.
  • FIXED Magic spells cast by enemies on entire party add to Firion's Spirit Up counter rather than party's MDef Exp counters.
  • FIXED Gil does not have a cap, overflowing at 16777215 (3 bytes, $FFFFFF). Cap code exists, but was not properly written. Gil should cap at 9,999,999.
  • FIXED Weapon Skill and Spell Levels are checked for increase routines even when maxed. Does not exceed the Lvl 16 cap, but still displays message at end of battle. Spammy, try to prevent this code from running on maxed weapons/spells.
  • FIXED End-of-battle calculation of attack/spell counters, weapon/spell progress modifiers, and battle rank bonus/malus can underflow, resulting in weapons/spells with high skill levels instantly leveling up with a single use in low rank battles. Implement a measure to prevent underflow.
  • Evasion and Magic Defense levels do not increase after the battle which earned the level up. You must initiate one more battle before the increase is applied. Investigate and fix this delay.
  • Combat counters are not capped, leading to a potential for overflow. This goes for all 5 main stat counters (times hit by physical/magic attacks, white/black magic casts, and times attacking physically), and all 16 (per party member) spell slot use counters. Impose caps on these values.
  • Combat engine gives credit for actions from both player characters and enemies before they've happened. Causes party to receive Magic Defense and Evasion credit even if the enemy is killed before it acts. Change counter increment behavior to happen after actions take place. May require significant rewriting of combat routine. Target/cancel exploit should be addressed through a solution.
  • Protect does not affect anyone but the caster, whether target-all'd or targeting an ally. Investigate cause.
  • Dispel does nothing. Unclear what it is supposed to do. Investigate cause, and refer to remakes for intended behavior.
  • Ultima is supposed to scale (in an unclear way) based on the skill levels of your other skills. Investigate cause, and refer to remakes for intended behavior.
  • Aura 8 does not grant Undead protection, and Barrier 8 does not grant Ice protection. Investigate cause.
  • Wall can be exploited by casting it on monsters to ensure that Toad, Break, Death, and Warp work on them. Wall's effects should likely be checked before any routines handling animation or other effects take place. Investigate.
  • Healing items in combat are bound to casting on self, rather than allowing a target to be chosen. This renders Phoenix Down, Gold Needle, and Maiden's Kiss useless in combat. Consider implementing new routine for targetting with these items.
  • Sap only acts on the least significant byte rather than the whole of a target's MP. Do enemies ever have more than 256 MP? If so, investigate and correct.
  • Healing Staff heals Undead as well as hurts them. Consider implementing exception for Undead family, perhaps attached to same routine that causes it, and it alone, to take damage from the item.
  • Ripper appears to display incorrect damage values, which was fixed in remakes. Investigate cause of display and actual damage differing.
  • The middle two characters, Guy and Maria, are biased by the enemy targetting algorithm, taking significantly more enemy focus than Firion or Character #4. Investigate cause and improve RNG, which is likely the cause.
  • Tested: Stats cannot go above 99 with stat-raising equipment in the Anniversary Edition. Cap stats at 99 no matter what for this patch.
  • Tested: Stats can stack bonuses from multiple equipment in the remakes. Giant's Helm + Power Sash + Giant's Glove will yield +30 Strength in the remake. Try to implement this behavior into this patch.

Possible Improvements:
  • IMPLEMENTED Prevent spell and weapon experience for skills at Level 16. This would be an improvement on the remakes, even.
  • Consider tallying attack counter and converting to weapon experience the moment weapons are switched in combat, to more accurately increase weapon experience. See if a JSR can be fit in before the actual change to weapon type changes. This would be an improvement on the remakes, even.
  • Rearrange stat up messages at end of battle to more closely reflect their order in the character stats menu.
  • New title screen using the series standard font/style, used in all current entries and added to Final Fantasy Restored. Seeking interested NES artists who can make use of compression techniques similar to those incorporated by koitsu here. More specific details as presented in koitsu's email to me can be provided on request.
  • Change the 4 Orbs at the top of the Mysidia Tower to increase ALL party members' stats rather than a random one, as it's possible for your fourth temporary party member to get all of the one-time bonuses.
  • Certain key items take up valuable inventory slots long after they are relevant to the game or story, when they should be consumed within the context of the story. There is no way to dispose of them. Consider implementing an item delete of Goddess's Bell once it is used to open Kashuan Keep, the Pass after you use it to gain access to the landed Dreadnought, the Egil's Torch after acquiring Sunfire OR after Sunfire is thrown into the Dreadnought's core, and of course the Sunfire after the same event, White Mask after it is placed upon the Goddess Statue, Black Mask after it is placed upon the Doppelganger, and Pendant after it is used to summon the Wyvern, or after Elina and her son vanish from Deist if there's some interaction they use. Investigate if any of these items still have any even mundane interactions with NPCs, as beyond these points they no longer are crucial to game progression. This will free up to 7 inventory slots of the 11 that key items take up, of your 32 total inventory slots.
  • The flag for Paul's stash is set during the small window during Cyclone's presence, after which you cannot access it if you forgot to speak to him. Consider if this is an acceptable missable, or if this window should be extended to the end of the game.

Fixes:
Max Stat Increase Fix by Red Mage Joe (Special Thanks to abw)
Cap Max HP/MP by abw
Enemy Magic Firion Spirit Bug Fix by Red Mage Joe (Special Thanks to abw)
Cap Gil Fix by abw / Red Mage Joe
Weapon Max Level Up_Fix by abw

Resources:
Game Systems Breakdown with Bugs Mentioned
Game Systems Discussion @ GameFAQs
abw's Disassembly
Jiggers's GitHub Disassembly should be open to edits, please help her with contributions, reference abw's disASM, etc!

Jiggers's SRAM Mapping
Code: [Select]
6000
00 - $01 = Pirate Ship Visible, triggers animation/fight scene? $02 = in control of pirate ship
01 - Pirate Ship X position
02 - Pirate Ship Y position
03 - $C0 when riding ship in animation, $10 when in control of pirate ship?
04 - $01 - Airship Visible. $02 = trigger animation? $04 = in control of airship
05 - Airship X position
06 - Airship Y position
07 - Airship Flyover Animation Counter?
08 - $02 = On chocobo! $80 = Chocobo Animation?
09 - Chocobo X position (for animation?)
0A - Chocobo Y position (for animation?)
0B -
0C - Ship Usable
0D - Ship X position
0E - Ship Y position
0F -
10 - Player Overworld Position X (for saving)
11 - Player Overworld Position Y (for saving)
12 - Constantly read when moving in town ($36)
13 -
14 - Giant Airship Visible
15 - Giant Airship X position
16 - Giant Airship Y position
17 -
18 -
19 -
1A - Key Item inventory? $02 when given Scott's Ring
1B -
1C - Gold low byte
1D - Gold middle byte
1E - Gold high byte
1F - Battle Text Speed (-1 from option chosen on game start)
20-3F - Seems to be treasure chest contents. Everything starts full, at $FF. Opening the chest south of the room you start in decrements 6022 to $FE. #256 chests total in the game?

40-5F - Game event flags
6042 - Starts $8B, turns to $8A when given Scott's Ring
6046 - Starts $7F, turns to $7E when using Wild Rose on bartender in third town. Then to $7C when given Scott's Ring. Flags character sprites vanishing?

60-7F - Items
80-8F - Passwords - Password IDs starts at $F1 and ends at $FF

6100 - Character stats, $40 per character
00 - Character ID - portrait, sprite
00: Firion
01: Maria
02: Guy
03: Minwu
04: Josef
05: Gordon
06: Leila
07: Ricard
08: Leon
01 - Ailment
01: Blind
02:
04: Venom
08: Cursed
10: Amnesia
20: Toad
40: Stone
80: Dead
02 - Name Letter 1
03 - Name Letter 2
04 - Name Letter 3
05 - Name Letter 4
06 - Name Letter 5
07 - Name Letter 6
08 - Current HP low byte
09 - Current HP high byte
0A - Max HP low byte
0B - Max HP high byte
0C - Current MP low byte
0D - Current MP high byte
0E - Max MP low byte
0F - Max MP high byte
10 - Strength - not shown in menu
11 - Agility - not shown in menu
12 - Stamina - not shown in menu
13 - Intellect - not shown in menu
14 - Spirit - not shown in menu
15 - M. Power - not shown in menu
16 - Accuracy Lvl
17 - Accuracy %
18 - Attack
19 - Head (Item ID)
1A - Body (Item ID)
1B - Hands (Item ID)
1C - Right Hand (Item ID)
1D - Left Hand (Item ID)
1E - Item 1 (Item ID)
1F - Item 2 (Item ID)
20 - Strength
21 - Agility
22 - Stamina
23 - Intellect
24 - Spirit
25 - M. Power
26 - ?
27 - ?
28 - ?
29 - Defense
2A - Evasion Level
2B - Evasion %
2C - MDef Level
2D - MDef %
2E - ($89)
2F - ($A2)
30-3F - Spell Slots

Weapon and Spell Levels (1 to 16, 00 => 0F)
6200 - Firion's weapon Skills
6240 - Maria's weapon skills
6280 - Guy's weapon skills
62C0 - Character 4's weapon skills
00 - Unarmed level
01 - Unarmed experience
02 - Shield level
03 - Shield experience
04 - Dagger level
05 - Dagger experience
06 - Staff level
07 - Staff experience
08 - Spear level
09 - Spear experience
0A - Sword level
0B - Sword experience
0C - Axe level
0D - Axe experience
0E - Bow level
0F - Bow experience

6210 => 622F - Firion's Spell Levels (6210) and Experience (6211)
6230 => 624F - Maria
6250 => 626F - Guy
6270 => 628F - Char_4

6235
6275
62B5
62F5 - Row ; 0 = back row, 01 = front row, 80 = no character portrait visible in menus

Jiggers's SRAM Mapping (combat)
Code: [Select]
7D7A - Battle Stats, 48 bytes per entity
7D7A offsets:
00 - Evasion Level
01 - Evasion %
02 - Char Stat $29
03 - MDef Level
04 - MDef %
05 - Char Stat $2E
06 - 0 at start, then...?
07 - Always #$14 for players
08 - Ailment
09 - 0 at start, then...?
0A - Current HP low
0B - Current HP high
0C - Current MP low
0D - Current MP high
0E - Max HP low
0F - Max HP high
10 - Max MP low
11 - Max MP high
12 - 0 at start, then Intellect
13 - 0 at start, then Spirit
14 -
15 -
16 -
17 -
18 - Accuracy Lvl
19 - Accuracy %
1A - Attack
1B -
1C -
1D -
1E - Defense
1F - Char Stat $27
20 - Char Stat $28
21 -
22 -
23 -
24 - Char Stat $2F
25 -
26 -
27 -
28 -
29 - Command (00=attack) (FE=flee)
2A - Target (high bit set for targeting enemies)
2B -
2C - Ailment backup
2D - 0 at start, then backup of 09?
2E - ??
2F - ??

7CF3 => 7CF6 - Attack counters
7CF7 => 7D06 - Firion's Spell Slot #(1 => 16) use counter
7D07 => 7D16 - Maria's Spell Slot #(1 => 16) use counter
7D17 => 7D26 - Guy's Spell Slot #(1 => 16) use counter
7D27 => 7D36 - Char_4's Spell Slot #(1 => 16) use counter
7D37 => 7D3A - Hit by Physical counter
7D3B => 7D3E - Hit by Magic counter
7D3F => 7D42 - Black Magic use counter
7D43 => 7D46 - White Magic use counter

Spell ID List
Code: [Select]
C0 - Fire
C1 - Thunder
C2 - Blizzard
C3 - Scourge
C4 - Drain
C5 - Osmose
C6 - Flare
C7 - Sleep
C8 - Stun
C9 - Stop
CA - Confuse
CB - Blind
CC - Curse
CD - Toad
CE - Break
CF - Death
D0 - Warp
D1 - Berserk
D2 - Haste
D3 - Aura
D4 - Cure
D5 - Life
D6 - Basuna
D7 - Esuna
D8 - Barrier
D9 - Blink
DA - Protect
DB - Shell
DC - Wall
DD - Dispel
DE - Mini
DF - Silence
E0 - Sap
E1 - Fog
E2 - Slow
E3 - Swap
E4 - Fear
E5 - Holy
E6 - Teleport
E7 - Ultima
« Last Edit: Today at 06:31:14 pm by redmagejoe »

Cyneprepou4uk

  • Sr. Member
  • ****
  • Posts: 285
  • I am the baldest romhacker
    • View Profile
Re: Final Fantasy II Disassembly?
« Reply #1 on: December 10, 2019, 04:18:01 am »
Kids these days, can't do anything without a disassembly.
iromhacker.ru - NES ROM hacking tutorials for beginners

Lenophis

  • IRC Staff
  • Hero Member
  • *****
  • Posts: 960
  • The return of the sombrero!
    • View Profile
    • Slick Productions
Re: Final Fantasy II Disassembly?
« Reply #2 on: December 10, 2019, 08:57:46 am »
A complete disassembly was not made. I should know. I do have some hacking bytes, but it's not complete, or anything like you're looking for. The only code I've tangled with is what made the DTE Fixer Upper patch. I haven't really hacked FF2 in a while.


https://ff6randomizer.codeplex.com/ - Randomize your FF6 experience!

redmagejoe

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Re: Final Fantasy II Restored
« Reply #3 on: December 12, 2019, 01:13:02 pm »
Kids these days, can't do anything without a disassembly.

Sorry :(

I would like to figure out how people who make the disassemblies in the first place do this stuff, how they tear down these binaries built on esoteric, low-level language. The concept just fascinates me, it does, but I just don't have the time anymore (and probably the patience even if I did) to dedicate to the projects. It saddens me, because I always used to think this sort of thing is what I'd be doing as my primary activity. Alas, at best I can scrounge up enough free time to make tweaks and very minor hacks. Things that I feel I have the experience, or at least the aptitude to figure out and dedicate my resources to rather than taking time away from these profound romhacks some of the members of this community are giving their 100% on. I always feel guilty then when I hit a roadblock like this, but it's such a shame when I think that, from a programming standpoint, it MUST be an easy fix, if only I had the means to analyze it.

tl;dr I'm too inexperienced and lacking in time to try to dissect the binary, and I realize at best what I do is tweaks but I'd really like to try and fix some things in that list.

A complete disassembly was not made. I should know. I do have some hacking bytes, but it's not complete, or anything like you're looking for. The only code I've tangled with is what made the DTE Fixer Upper patch. I haven't really hacked FF2 in a while.

That's a bummer. If I were to try and figure out where to begin finding the addresses I'm looking for then... I guess I would have to set a breakpoint and analyze the RAM addresses being read/written to?
« Last Edit: January 19, 2020, 04:44:05 pm by redmagejoe »

Bregalad

  • Hero Member
  • *****
  • Posts: 2661
    • View Profile
Re: Final Fantasy II Disassembly?
« Reply #4 on: December 13, 2019, 02:24:41 am »
There's a disassembly of Final Fantasy around. A lot of code in Final Fantasy 2 and 3 is reused code from Final Fantasy. So although this is not a full solution, it will give you a nice idea how many thing works in the game. Even the RAM map is similar.

Jiggers

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • My Ko-Fi Page
Re: Final Fantasy II Disassembly?
« Reply #5 on: December 13, 2019, 04:24:04 pm »
I might not mind helping out once there's a disassembly. I looked into how to make one and... couldn't really figure it out either. I got the assembly code out in a big list, but it also tried to turn data into code, and I couldn't tell where one bank ended and the next began...

I need a break from my own things, so I might take a look at FF2 and map out some RAM, that'll help someone get started maybe?

One thing you'll want to do is make sure that a disassembly can be re-assembled after edits. I've been absolutely spoiled by FF1's, but its SO much easier to work with than trying to make changes where you can't just shift the whole game by 2 bytes and change every single pointer and jump address in the process.
I know exactly what I'm doing. I just don't know what effect it's going to have.

I wrote some NES music! Its a legal ROM file. - I got a Ko-Fi page too.

redmagejoe

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Re: Final Fantasy II Restored
« Reply #6 on: December 13, 2019, 04:28:00 pm »
Any help at all in any form would be appreciated. It would be a great boon not just to fixes I'd like to try to make to the game, but for future hacking of the game.
« Last Edit: January 19, 2020, 04:44:13 pm by redmagejoe »

abw

  • Sr. Member
  • ****
  • Posts: 324
    • View Profile
Re: Final Fantasy II Disassembly?
« Reply #7 on: December 13, 2019, 06:24:13 pm »
One thing you'll want to do is make sure that a disassembly can be re-assembled after edits. I've been absolutely spoiled by FF1's, but its SO much easier to work with than trying to make changes where you can't just shift the whole game by 2 bytes and change every single pointer and jump address in the process.
Yeah, but try asking Disch how much time it took to create that disassembly :(.

NES ROMs are tricky things to disassemble. Mostly that's due to mappers, but there are other reasons too.

Assuming you've played the game through in FCEUX at some point, did you happen to have FCEUX's Code/Data Logger running (preferably on the unaltered Japanese ROM, preferably without making any changes via the debugger/hex editor/etc.)?

The reason I ask is that one of my various WIP pet projects is a NES disassembler that uses FCEUX's CDL file to automatically distinguish between code and data (and stuff that is both code and data) and the ROM's iNES header to do some primitive mapper-based things like dividing the ROM into banks based on the mapper's (smallest) bank size and working out the RAM addresses for each of those banks (or at least trying to). With manual work, you can also incorporate comments and labels into the generated disassembly and tell it about things like pointers/pointer tables and what bytes that the CDL didn't log are for. You can see an example from Dragon Warrior II on the wiki.

Actually, a quick search of the internet turned up https://taotao54321.github.io/appsouko/work/CDL/pub/, which appears to have a mostly complete CDL file of "FF2", which I'm hoping means "Final Fantasy II". I plugged it in and played the game for a couple of minutes and FCEUX didn't change anything, so maybe it's legit? How does this look?

redmagejoe

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Re: Final Fantasy II Restored
« Reply #8 on: December 13, 2019, 06:28:38 pm »
Actually, a quick search of the internet turned up https://taotao54321.github.io/appsouko/work/CDL/pub/, which appears to have a mostly complete CDL file of "FF2", which I'm hoping means "Final Fantasy II". I plugged it in and played the game for a couple of minutes and FCEUX didn't change anything, so maybe it's legit? How does this look?

https://taotao54321.github.io/appsouko/work/CDL/pub/FF2.txt
@rom_md5 374ed97be8bfd628f6b359a720549ecd

Went to my ROM repo and found the Final Fantasy II (J) [!] and ran it through RHDN's online Hasher-js.
ROM MD5   374ED97BE8BFD628F6B359A720549ECD

We have a match! Good find, abw! :)
« Last Edit: January 19, 2020, 04:44:22 pm by redmagejoe »

Jiggers

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • My Ko-Fi Page
Re: Final Fantasy II Disassembly?
« Reply #9 on: December 13, 2019, 08:35:44 pm »
Here's my SRAM testing so far:

Code: [Select]
6000
00 - $01 = Pirate Ship Visible, triggers animation/fight scene? $02 = in control of pirate ship
01 - Pirate Ship X position
02 - Pirate Ship Y position
03 - $C0 when riding ship in animation, $10 when in control of pirate ship?
04 - $01 - Airship Visible. $02 = trigger animation? $04 = in control of airship
05 - Airship X position
06 - Airship Y position
07 - Airship Flyover Animation Counter?
08 - $02 = On chocobo! $80 = Chocobo Animation?
09 - Chocobo X position (for animation?)
0A - Chocobo Y position (for animation?)
0B -
0C - Ship Usable
0D - Ship X position
0E - Ship Y position
0F -
10 - Player Overworld Position X (for saving)
11 - Player Overworld Position Y (for saving)
12 - Constantly read when moving in town ($36)
13 -
14 - Giant Airship Visible
15 - Giant Airship X position
16 - Giant Airship Y position
17 -
18 -
19 -
1A - Key Item inventory? $02 when given Scott's Ring
1B -
1C - Gold low byte
1D - Gold middle byte
1E - Gold high byte
1F - Battle Text Speed (-1 from option chosen on game start)
20-3F - Seems to be treasure chest contents. Everything starts full, at $FF. Opening the chest south of the room you start in decrements 6022 to $FE. #256 chests total in the game?

40-5F - Game event flags
6042 - Starts $8B, turns to $8A when given Scott's Ring
6046 - Starts $7F, turns to $7E when using Wild Rose on bartender in third town. Then to $7C when given Scott's Ring. Flags character sprites vanishing?

60-7F - Items
80-8F - Passwords - Password IDs starts at $F1 and ends at $FF

6100 - Character stats, $40 per character
00 - Character ID - portrait, sprite
00: Firion
01: Maria
02: Guy
03: Minwu
04: Josef
05: Gordon
06: Leila
07: Ricard
08: Leon
01 - Ailment
01: Blind
02:
04: Venom
08: Cursed
10: Amnesia
20: Toad
40: Stone
80: Dead
02 - Name Letter 1
03 - Name Letter 2
04 - Name Letter 3
05 - Name Letter 4
06 - Name Letter 5
07 - Name Letter 6
08 - Current HP low byte
09 - Current HP high byte
0A - Max HP low byte
0B - Max HP high byte
0C - Current MP low byte
0D - Current MP high byte
0E - Max MP low byte
0F - Max MP high byte
10 - Strength - not shown in menu
11 - Agility - not shown in menu
12 - Stamina - not shown in menu
13 - Intellect - not shown in menu
14 - Spirit - not shown in menu
15 - M. Power - not shown in menu
16 - Min Accuracy %
17 - Max Accuracy %
18 - Attack
19 - Head (Item ID)
1A - Body (Item ID)
1B - Hands (Item ID)
1C - Right Hand (Item ID)
1D - Left Hand (Item ID)
1E - Item 1 (Item ID)
1F - Item 2 (Item ID)
20 - Strength
21 - Agility
22 - Stamina
23 - Intellect
24 - Spirit
25 - M. Power
26 - Defense
27 -
28 -
29 -
2A - Min Evasion %
2B - Max Evasion %
2C - Min M. Resist %
2D - Max M. Resist %
2E -
2F -
30-3F - Known spell slots (Usable spell IDs start at $C0, end at $E7?)

Weapon skills:
$10 per character, in $40 byte intervals
Levels are -1, where 00 = level 1
Both should cap at $63

6200 - Firion's weapon Skills
6240 - Maria's weapon skills
6280 - Guy's weapon skills
62C0 - Character 4's weapon skills?
00 - Unarmed level
01 - Unarmed experience
02 - Shield level
03 - Shield experience
04 - Dagger level
05 - Dagger experience
06 - Staff level
07 - Staff experience
08 - Spear level
09 - Spear experience
0A - Sword level
0B - Sword experience
0C - Axe level
0D - Axe experience
0E - Bow level
0F - Bow experience

6235
6275
62B5
62F5 - Row ; 0 = back row, 01 = front row, 80 = no character portrait visible in menus
« Last Edit: December 14, 2019, 07:01:30 pm by Jiggers »
I know exactly what I'm doing. I just don't know what effect it's going to have.

I wrote some NES music! Its a legal ROM file. - I got a Ko-Fi page too.

redmagejoe

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Re: Final Fantasy II Restored
« Reply #10 on: December 13, 2019, 08:39:29 pm »
Quote
Weapon skills:
$10 per character, in $40 byte intervals
Levels are -1, where 00 = level 1
Both should cap at $63
Shouldn't the levels cap at 0F, for 15? Max spell and weapon levels are 16.

On that note, having tampered with SRAM myself a bit to "fix" overmaxed HP, I thought it might be helpful to outline what hex values are needed as "caps" that the game doesn't already impose. While the game DOES prevent stats like Strength, Agility, Stamina, Spirit, Intellect, and presumably M.Power from going above 99, it still does level-up checks on them.

Spirit, Strength, and Intellect, at least, need to have their checks for leveling up skipped when they are at $63 (99), since there's no reason for them to be continuing to try to level up, and it results in you often losing Strength, Intellect, and Stamina accordingly. This can be applied to M.Power, Stamina and Agility as well, but they don't have any unwanted side effects of continuing to "level up" other than it being inconsistent were the other 3 stats fixed.

Weapon Skills aren't problematic either, other than the end-of-battle spam. Since they are using -1 value and starting at $00, $0F should translate to 16, at which point the check for weapon levels should not happen anymore, but they still do. There's also some sort of underflow bug based on battle rank with the weapon levels specifically at $0D and $0E, resulting in a single attack on a Rank 1 battle immediately leveling up the weapon skill.

Spell levels do appear to cap properly, as the experience counter will still go up to 98 or 99, but will never go up beyond that. Scratch that, spells will also "level up" even at 16 if used enough times in battle, though it will simply reset the experience counter back to 00 in the magic window. This game just simply does not have hard caps for most things, with only a few mechanics in place to ensure that weapon and spell levels don't increment above 16 and stats don't increment above 99, while the math is still being calculated and messages displayed as if there were no caps.

Evasion and Magic Defense should cap at 16 (whether that's $0F or $10 I don't know), and I haven't tested if they can still go up. There'd be no easy way to test that, as there's no message stating they go up and you'd only be able to tell from looking at your stat windows 2 battles later.

For HP and MP, having already modified my SRAM to fix overmax, I can say that HP should cap at $0F27 (low byte then high byte) for 9999, and MP should cap at $E703 for 999. Currently it seems likely that these values would continue to level up to $FFFF and would no doubt overflow.
« Last Edit: January 19, 2020, 04:45:00 pm by redmagejoe »

Jiggers

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • My Ko-Fi Page
Re: Final Fantasy II Disassembly?
« Reply #11 on: December 13, 2019, 09:40:17 pm »
Shouldn't the levels cap at 0F, for 15? Max spell and weapon levels are 16.

Oh, yeah, probably! Last time I played FF2 was I think the Wanderswan version over 10 years ago, so I'm not as familiar with its systems. I guessed 99 was the level cap since that's the highest number there's room to print on the status screen.

Quote
Evasion and Magic Defense should cap at 16 (whether that's $0F or $10 I don't know), and I haven't tested if they can still go up. There'd be no easy way to test that, as there's no message stating they go up and you'd only be able to tell from looking at your stat windows 2 battles later.

For all this stuff, what I'd do to find where the routines are change them, is: Starting on the overworld, find one character's evasion stat in Mesen's memory viewer, right click and set a breakpoint on read, then get into a battle. There's probably a bit of code that copies over stats to temporary battle stats. So then you step through it until you see the evasion stat written to somewhere else in memory shortly after that? If it doesn't break there, even better: just set a "write" breakpoint on the same evasion stat, and when it goes up in or after battle, that's the thing that does it! And if its temporary battle stats, set the "write" breakpoint on the new location.

Right now I can't even figure out how to get Chaos Rush's translation patched in without graphical errors...
I know exactly what I'm doing. I just don't know what effect it's going to have.

I wrote some NES music! Its a legal ROM file. - I got a Ko-Fi page too.

redmagejoe

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Re: Final Fantasy II Restored
« Reply #12 on: December 13, 2019, 09:58:57 pm »
Here's an IPS you can just slap on the (J) [!] ROM. It's a patch I just pulled using Lunar. Everything works and is retranslated, though it doesn't have the (sometimes buggy) NeoDemiforce title screen.

https://drive.google.com/open?id=1jB61-EFQaoZkxCZnxld4vp0gV9SH8in_
« Last Edit: January 19, 2020, 04:46:39 pm by redmagejoe »

abw

  • Sr. Member
  • ****
  • Posts: 324
    • View Profile
Re: Final Fantasy II Disassembly?
« Reply #13 on: December 13, 2019, 11:17:37 pm »
It looks like there are a couple of things already documented on the wiki.

A quick search in my generated disassembly for $6100 turns up (among lots of other things) what looks like code for initializing party stats ($00:$8F80 - $00:$8FBF does appear to contain character #1's initial stats) and other stuff:
Code: [Select]
0x001C7F|$00:$9C6F:A2 3F    LDX #$3F   
; control flow target (from $9CA2)
0x001C81|$00:$9C71:BD 80 8F LDA $8F80,X
0x001C84|$00:$9C74:9D 00 61 STA $6100,X
0x001C87|$00:$9C77:BD 00 90 LDA $9000,X
0x001C8A|$00:$9C7A:9D 40 61 STA $6140,X
0x001C8D|$00:$9C7D:BD 80 90 LDA $9080,X
0x001C90|$00:$9C80:9D 80 61 STA $6180,X
0x001C93|$00:$9C83:BD 80 8F LDA $8F80,X
0x001C96|$00:$9C86:9D C0 61 STA $61C0,X
0x001C99|$00:$9C89:BD C0 8F LDA $8FC0,X
0x001C9C|$00:$9C8C:9D 00 62 STA $6200,X
0x001C9F|$00:$9C8F:BD 40 90 LDA $9040,X
0x001CA2|$00:$9C92:9D 40 62 STA $6240,X
0x001CA5|$00:$9C95:BD C0 90 LDA $90C0,X
0x001CA8|$00:$9C98:9D 80 62 STA $6280,X
0x001CAB|$00:$9C9B:BD C0 8F LDA $8FC0,X
0x001CAE|$00:$9C9E:9D C0 62 STA $62C0,X
0x001CB1|$00:$9CA1:CA      DEX       
0x001CB2|$00:$9CA2:10 CD    BPL $9C71 
0x001CB4|$00:$9CA4:60      RTS       

Later on, there's what looks like possibly some code for capping stats at 99 (#$63), which the CDL didn't log, so I guess our awesome taotao friend didn't manage/bother to max those stats:
Code: [Select]
; indirect control flow target
0x03A1BF|$0E:$A1AF:A9 10    LDA #$10   
0x03A1C1|$0E:$A1B1:D0 0A    BNE $A1BD 
; indirect control flow target
0x03A1C3|$0E:$A1B3:A9 11    LDA #$11   
0x03A1C5|$0E:$A1B5:D0 06    BNE $A1BD 
; indirect control flow target
0x03A1C7|$0E:$A1B7:A9 14    LDA #$14   
0x03A1C9|$0E:$A1B9:D0 02    BNE $A1BD 
; indirect control flow target
0x03A1CB|$0E:$A1BB:A9 13    LDA #$13   
; control flow target (from $A1B1, $A1B5, $A1B9)
0x03A1CD|$0E:$A1BD:85 80    STA $80   
0x03A1CF|$0E:$A1BF:A5 F0    LDA $F0   
0x03A1D1|$0E:$A1C1:29 C0    AND #$C0   
0x03A1D3|$0E:$A1C3:05 80    ORA $80   
0x03A1D5|$0E:$A1C5:AA      TAX       
0x03A1D6|$0E:$A1C6:BD 00 61 LDA $6100,X
0x03A1D9|$0E:$A1C9:18      CLC       
0x03A1DA|$0E:$A1CA:69 0A    ADC #$0A   
0x03A1DC|$0E:$A1CC:C9 64    CMP #$64   
0x03A1DE|$0E:$A1CE:90 02    BCC $A1D2 

; code -> unknown
0x03A1E0|$0E:$A1D0:A9 63    ; LDA #$63   
0x03A1E1|$0E:$A1D1:63      ; INVALID OPCODE

; unknown -> code
; control flow target (from $A1CE)
0x03A1E2|$0E:$A1D2:9D 00 61 STA $6100,X
0x03A1E5|$0E:$A1D5:BD 10 61 LDA $6110,X
0x03A1E8|$0E:$A1D8:18      CLC       
0x03A1E9|$0E:$A1D9:69 0A    ADC #$0A   
0x03A1EB|$0E:$A1DB:C9 64    CMP #$64   
0x03A1ED|$0E:$A1DD:90 02    BCC $A1E1 

; code -> unknown
0x03A1EF|$0E:$A1DF:A9 63    ; LDA #$63   
0x03A1F0|$0E:$A1E0:63      ; INVALID OPCODE

; unknown -> code
; control flow target (from $A1DD)
0x03A1F1|$0E:$A1E1:9D 10 61 STA $6110,X

redmagejoe

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Re: Final Fantasy II Restored
« Reply #14 on: December 13, 2019, 11:24:17 pm »
I can also provide my .sav if anyone would like more tangible resources to play with. I currently have everyone at 99 Strength, Agility, Stamina, and Spirit, with Intellect being between 1 and 3 due to the aforementioned gripe about maxed stats leveling up and decreasing other stats. Firion has 9999 HP (was 10030 until I "fixed" it in SRAM) and 999 MP ("fixed"), while the other two characters have ~7400 and 247, and ~6400 and 999 ("fixed"). This was achieved through some extremely obsessive and tedious leveling for the purposes of testing the limits of the game systems. I imagine this might be helpful rather than having to artificially manipulate those stats, though I suppose that isn't in and of itself a difficult task.



Here's the .sav. Characters have above-listed stats, and most of the spells in the game. Cure is at 16 on Firion and Guy, in case that is of benefit to testing spell leveling or experience.

https://drive.google.com/open?id=10j57hRiNoy-tCxq3YoyTwaP5CCJZC8Zs
« Last Edit: January 19, 2020, 04:46:26 pm by redmagejoe »

Jiggers

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • My Ko-Fi Page
Re: Final Fantasy II Disassembly?
« Reply #15 on: December 14, 2019, 06:59:35 pm »
Thanks for the patch! Is it a bug that the flowing text (Programmed by Nasir and so on) has like a whole line of each letter across the screen as it draws in?

Another possible bug is that after being given Scott's ring, and asking "Wild Rose" a second time, will loop all his previous dialogue again, including the ring giving message? Perhaps a forced exit from dialogue when sprites vanish, after pressing any button... unless that would break something else.

I found a few more SRAM bytes, and the $20 bytes that I thought might be game event flags certainly must be. Instead of using up $100 bytes and only using 2 bits or so per byte like FF1, they just crammed it all in there, which I guess is how they made room for 4 save slots, with each save being $300 bytes. I'll update my other post with the things I find as I slog through the game's beginning...
« Last Edit: December 14, 2019, 08:18:05 pm by Jiggers »
I know exactly what I'm doing. I just don't know what effect it's going to have.

I wrote some NES music! Its a legal ROM file. - I got a Ko-Fi page too.

redmagejoe

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Re: Final Fantasy II Restored
« Reply #16 on: December 14, 2019, 07:02:02 pm »
That weird drawing effect is, I think, the intended behavior of the title screen. It's just not a very "pretty" title screen, which is why a new one was made for the Neodemiforce patch. Would be nice to get that as a standalone patch someday. Also I provided my .sav if you get to a point where you want to see how it's handling stat behaviors past the beginning game slog.
« Last Edit: January 19, 2020, 04:46:16 pm by redmagejoe »

abw

  • Sr. Member
  • ****
  • Posts: 324
    • View Profile
Re: Final Fantasy II Disassembly?
« Reply #17 on: December 15, 2019, 04:35:56 pm »
I put a few hours into creating an updated version of my disassembly, marking in some CHR, the main dialogue, unused code paths, a bunch of pointer tables, probably most of the inter-bank references, formatting some of the larger data blocks, a teeny-tiny bit of documentation on a couple of routines (mostly the ones involving bank swaps), stuff like that. It's still pretty rough, but should make any code changes that you want easier to make.

redmagejoe

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Re: Final Fantasy II Restored
« Reply #18 on: December 15, 2019, 05:15:26 pm »
I put a few hours into creating an updated version of my disassembly, marking in some CHR, the main dialogue, unused code paths, a bunch of pointer tables, probably most of the inter-bank references, formatting some of the larger data blocks, a teeny-tiny bit of documentation on a couple of routines (mostly the ones involving bank swaps), stuff like that. It's still pretty rough, but should make any code changes that you want easier to make.

This is great, abw. I'm going to start looking through this and see if I can work with what's provided while I've got some downtime between work projects. The main issue is knowing where to even begin looking to make changes, I'll admit. Once I have an idea of where the relevant routines are for handling stat level up checks at the end of battle, I'll have a much better idea how to move forward.



Found an issue with the ChaosRush translation that can very easily be fixed, but... I noticed that using DTE, he made some spell names use 5 spaces instead of 4, and as a result, in battle any spells above level 9 will be pushed out of the box that displays during the cast. So Scourge 16 becomes [Scrge 1]. This is an easy enough fix, where the space after a spell name is removed so that in the case of 5-character spells it would be [Scrge1 ] or [Scrge16], and for other spells that already only use 4 spaces, it would be [Cure1  ] to [Cure16 ]. Doesn't look too troublesome, but I'd need to find where the combat display boxes handle spell names and levels to adjust that. Removing the space would be easier than trying to check the spell level and formatting based upon that. It wouldn't look too inconsistent with NES era formatting I don't think.



I discovered potentially another bug. When one's Agility and thus Evasion are high enough, and Shield skill is high/maxed, it appears that one of two things are happening. Either Evasion % is rolling over, or it is somehow going above 99% and is only displaying the two least significant digits in the stat window; this seems less likely given the other bugs in this game involving lack of caps.

To elaborate, with Level 16 Shields, 99 Agility, and Dragon Shield equipped on, say, Guy, who has Level 8 Evasion, he goes from 8-99% without the shield equipped to 8-05% with the shield equipped.



D'oh, and apparently I missed the extremely small window to access Paul's Secret Stash. I guess you have to talk to him right after the Cyclone appears and say Cyclone to open it up, but I'm not sure how it's managed. Does it become an object you can permanently interact with? Does it become an open door you can walk through? Does it allow you to interact with it until the access window closes? I'm curious now where the flag is for this value, as I'd like to see if it's possible to manipulate that, or the one involving talking to Paul about the Cyclone all the way up to the end of the game. Another consideration for a patch.
« Last Edit: January 19, 2020, 04:46:08 pm by redmagejoe »

abw

  • Sr. Member
  • ****
  • Posts: 324
    • View Profile
Re: Final Fantasy II Disassembly?
« Reply #19 on: December 23, 2019, 02:32:07 pm »
This is great, abw. I'm going to start looking through this and see if I can work with what's provided while I've got some downtime between work projects. The main issue is knowing where to even begin looking to make changes, I'll admit. Once I have an idea of where the relevant routines are for handling stat level up checks at the end of battle, I'll have a much better idea how to move forward.
Like Jiggers said, if you already know a RAM address (e.g. character stats start at $6100) related to the code you're looking for and you already know approximately when the code you're looking for runs, setting a breakpoint on that address and then playing through the part of the game where the code runs is probably the best way to go. (And if you don't know a RAM address, you can also use a trace logger and PPU breakpoint and backtrack from when something related to the code you're looking for appears on screen.)

For character stats, I did just that, setting a write breakpoint on $6110-$6115 and playing until Firion gained a stat. The breakpoint fired at $05:$A8A0, and poking around that section of the disassembly suggests $05:$A874-$05:$A903 is the code for increasing Spirit/Strength/Intellect at the expense of Strength/Intellect/Stamina (capped at 99 for increases and 1 for decreases). $05:$A7E9-$05:$A841 looks like it handles HP/MP increases (no caps, so probably with enough grinding you could overflow the 16-bit storage and end up with 0 Max HP!), and $05:$A842-$05:$A86C is probably for skill level increases (capped at 15). All those routines get called from code starting around $05:$A5F1 (or possibly earlier, I haven't really looked). I added some more rough notes to my disassembly, so hopefully that will help a bit!