øAslickproductions.org/forum/index.php?PHPSESSID=5f0fck550j2m4m2fpbtkj2vkm1&topic=2382.msg27653e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/indexd5cb-3.htmlslickproductions.org/forum/index.php?PHPSESSID=5f0fck550j2m4m2fpbtkj2vkm1&topic=2230.135e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/indexd5cb-3.html.zx,,h^ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÈà•¤ÇôOKtext/htmlISO-8859-1gzip@øÕÇôÿÿÿÿÿÿÿÿWed, 11 Mar 2020 00:25:40 GMT0ó°° ®0®P®€§²ð®+,h^ÿÿÿÿÿÿÿÿ}#Çô Zone Eater event bug

Author Topic: Zone Eater event bug  (Read 392 times)

13375K31C43R

  • Ultros
  • *
  • Posts: 675
  • Gender: Male
    • View Profile
    • Leet Sketcher's Final Fantasy III Patches
Zone Eater event bug
« on: July 29, 2017, 01:33:58 AM »
I want to address the event bug shown here. Looking at the event code for the ceiling drop, it's set to an invisible timer that expires after a couple of seconds and calls an event subroutine upon expiry that makes the ceiling fall. Looking at the assembly code, the subroutine is called at the bottom of the event stack, and the event stack pointer is set there. That tells me that we might have a threading issue here; the event code that is supposed to run when the player steps on the exit tile either gets ignored because the ceiling fall routine is called first, or is interrupted by the timer thread and its place in the event stack is overwritten by the ceiling fall event.

One idea I have to address this is, instead of calling a timer-expiry routine at the bottom event stack, push it to the top and run it before finishing the currently running event. If that were the case, then I would expect the same scenario as shown in the video to still show the ceiling falling, but then the player moves to the other room as expected (by the event trigger that is placed there; it's not an exit tile, I already tried replacing the event trigger with an exit and it didn't fix the problem). The only problem that might cause is, some events are probably meant to be interrupted by a timer-trigger event and it might break the game if they are not (e.g. the Opera House). I can't think of any that are definitely contingent upon this, but I want to get some input from my peers about this.
"Do not meddle in the affairs of wizards, for they are subtle and quick to anger." -Gildor from The Lord of the Rings

13375K31C43R

  • Ultros
  • *
  • Posts: 675
  • Gender: Male
    • View Profile
    • Leet Sketcher's Final Fantasy III Patches
Re: Zone Eater event bug
« Reply #1 on: July 29, 2017, 02:15:44 AM »
Actually, I've tried following the exact same movement pattern as shown in the video, and even on a vanilla ROM, despite moving as fast as I can without Sprint Shoes, I cannot reproduce the bug. :hmm:
"Do not meddle in the affairs of wizards, for they are subtle and quick to anger." -Gildor from The Lord of the Rings

Tenkarider

  • Guard Leader
  • *
  • Posts: 50
    • View Profile
Re: Zone Eater event bug
« Reply #2 on: July 29, 2017, 08:32:10 AM »
what about hiding a layer 1 tile, in the tiles near to the exits, that don't allow the player to pass through them?

assassin

  • Bane of Retards
  • *
  • Posts: 1,033
  • space bears are not gentle!
    • View Profile
    • My Barren Webpage
Re: Zone Eater event bug
« Reply #3 on: July 29, 2017, 08:51:03 AM »
did you try reproducing it with Terra as lead?  iirc, at least parts of it were dependent on her:
http://mnrogar.slickproductions.org/phpBB3/search.php?st=0&sk=t&sd=d&keywords=ceiling

13375K31C43R

  • Ultros
  • *
  • Posts: 675
  • Gender: Male
    • View Profile
    • Leet Sketcher's Final Fantasy III Patches
Re: Zone Eater event bug
« Reply #4 on: July 29, 2017, 03:51:50 PM »
did you try reproducing it with Terra as lead?  iirc, at least parts of it were dependent on her:

Wow, you're right! I read that Terra, for whatever reason, takes an extra step when the ceiling falls, which can result in anything from her walking off the edge, to the aforementioned event bug, to the event shown in the attached screenshot. You'll notice she's actually standing in a safe spot, yet she still died. Even if you try to change direction, she'll still walk in the direction she was already facing, yet she'll face the direction you tell her to while doing so, meaning she can walk backwards or sideways.
"Do not meddle in the affairs of wizards, for they are subtle and quick to anger." -Gildor from The Lord of the Rings

13375K31C43R

  • Ultros
  • *
  • Posts: 675
  • Gender: Male
    • View Profile
    • Leet Sketcher's Final Fantasy III Patches
Re: Zone Eater event bug
« Reply #5 on: July 29, 2017, 04:10:10 PM »
Here's an even worse case. She's now even more obviously clear of the ceiling and yet I still died. Obviously the fact that she's this far out is because she took an extra step, but even if she hadn't, she'd still be on a safe spot, and yet would still die. This is because the timer-triggered event of the ceiling fall happens before the event trigger on the safe tile that lets the game know she is safe.
"Do not meddle in the affairs of wizards, for they are subtle and quick to anger." -Gildor from The Lord of the Rings

13375K31C43R

  • Ultros
  • *
  • Posts: 675
  • Gender: Male
    • View Profile
    • Leet Sketcher's Final Fantasy III Patches
Re: Zone Eater event bug
« Reply #6 on: July 29, 2017, 04:12:14 PM »
Here's another screenshot that shows Celes dying even though she's safe, because the event that flags her as safe hasn't triggered yet.
"Do not meddle in the affairs of wizards, for they are subtle and quick to anger." -Gildor from The Lord of the Rings

13375K31C43R

  • Ultros
  • *
  • Posts: 675
  • Gender: Male
    • View Profile
    • Leet Sketcher's Final Fantasy III Patches
Re: Zone Eater event bug
« Reply #7 on: July 29, 2017, 06:50:33 PM »
One way to fix this might simply be to make tile-based event triggers happen before timer-based event triggers. I tried swapping the JSRs to those two subroutines, but the only problem was that when I stepped on a "safe" tile, it was only safe because it had an event trigger on it, and then the ceiling refused to fall until I stepped off. So we'd probably need a flag to ensure event triggers only happen once, or maybe a JSR to the function that calls the currently loaded event code before checking for timer-based events.
"Do not meddle in the affairs of wizards, for they are subtle and quick to anger." -Gildor from The Lord of the Rings

13375K31C43R

  • Ultros
  • *
  • Posts: 675
  • Gender: Male
    • View Profile
    • Leet Sketcher's Final Fantasy III Patches
Re: Zone Eater event bug
« Reply #8 on: July 31, 2017, 03:43:29 AM »
OK, I found a very satisfactory way to get a tile-based event script to trigger before the ceiling falls, and it's enough to fix the bug that allows Terra to bypass the exit tile and meander, along with the delayed action bug that allows Celes (or anyone) to die in a safe zone. I will release a patch for it ASAP, and in the meantime all that leaves is the issue of Terra moving an extra tile.

I'm currently in the middle of debugging that, and I've just found that $0886,Y is the wild card, where Y is the pointer index to the party leader's sprite data.
"Do not meddle in the affairs of wizards, for they are subtle and quick to anger." -Gildor from The Lord of the Rings

13375K31C43R

  • Ultros
  • *
  • Posts: 675
  • Gender: Male
    • View Profile
    • Leet Sketcher's Final Fantasy III Patches
Re: Zone Eater event bug
« Reply #9 on: July 31, 2017, 04:16:18 AM »
I think I have found the problem. I already found that $0886,Y is the variable on which Terra's extra step is contingent. Turns out Terra gets slightly different treatment than all other party members, as evidenced by these two bits of code:

Code: [Select]
C0/49F6:    9C 86 08       STZ $0886
Code: [Select]
C0/4A15:    A9 01           LDA #$01
C0/4A17:    8D 86 08      STA $0886

The latter is part of the step processing function (which includes step count, Tintinabar, and save point flag handling). Part of this function is also called by my Save Point Switch patch, and in fact the latter code snippet comes right before the point from which Save Point Switch starts calling the function. The former is part of the section of code that's called when the party is not told to move by controller input. Why these functions mess with Terra's flags and no one else's is beyond me.
"Do not meddle in the affairs of wizards, for they are subtle and quick to anger." -Gildor from The Lord of the Rings

assassin

  • Bane of Retards
  • *
  • Posts: 1,033
  • space bears are not gentle!
    • View Profile
    • My Barren Webpage
Re: Zone Eater event bug
« Reply #10 on: July 31, 2017, 10:58:50 AM »
weird.. if the second snippet causes Terra's extra step, any idea what equivalent issue (if any) results from the first one?  either a Terra-only error, or maybe everybody but her failing to stop when they should.

also curious is how many places this variable is written to, but only two read from it.

13375K31C43R

  • Ultros
  • *
  • Posts: 675
  • Gender: Male
    • View Profile
    • Leet Sketcher's Final Fantasy III Patches
Re: Zone Eater event bug
« Reply #11 on: July 31, 2017, 12:36:33 PM »
weird.. if the second snippet causes Terra's extra step, any idea what equivalent issue (if any) results from the first one?  either a Terra-only error, or maybe everybody but her failing to stop when they should.

I can't think of a moment in the game when anyone except Terra fails to stop, and remember that those two snippets are part of the directional input processing, meaning that it can't be from event scripts, it all has to do with the D-pad. My best guess is, if the devs thought they needed the second snippet for whatever reason (which I don't think they do), they would also need the first snippet to control the second, i.e. make it so Terra can in fact stop. I just tested with only the first snippet NOP'd out and didn't see a difference. Again, what puzzles me is why Terra would even need any special treatment.

also curious is how many places this variable is written to, but only two read from it.

I don't know if there are any writes that should concern us, other than the two Terra-only ones. The rest are all general, and they clear the variable in places like right before a movement queue, or when a map is loaded.
"Do not meddle in the affairs of wizards, for they are subtle and quick to anger." -Gildor from The Lord of the Rings