Friday, April 4, 2014

Detour: Fixing the Segfault - Part 3

Continued from the previous entry

In the last post, we learned that the code for skipping the introduction movie is different between the demo and the full version of EMI. In this post, we'll delve into how this works in the demo and see if we can fix the problem in ResidualVM.

I first tried to inject my Z button debug script into the main demo file with all of the scripts (MagDemo.lab), but I was only able to get a dialog box in ResidualVM. Undaunted, I tried to modify the _system.lua script to load different scenes depending on the state of the system.buttonHandler variable, which does key mapping. In short, I wanted to see if the default button handler was loaded during the intro cut scene. However, whatever I tried to do, nothing was changing! Even things like removing BOOT, the first function called in the game, weren't having any effect.

As it turns out, the demo has an extra lab file (i9n.lab) which contains a slightly different version of the _system.lua script. This file is apparently loaded after or perhaps instead of the _system.lua script in the main object file. With this sorted, I went back to testing to see what the state of system.buttonHandler was.

As it turns out, in ResidualVM, the default handler is set, likely by the _system.lua script, when it loads the default controls in _control.lua. In the demo, there is no handler! I checked for this using the following test:
  • Inserted code after the call to StartMovie("intro") to save if the buttonHandler was set or not
  • Changed the set that you switch to depending on the state of that variable.
It is likely that the demo uses custom code for handling ESC during the movie. This is also why ResidualVM crashes with a segfault when you press F1, at this point in the demo, nothing is watching for F1. The original designers missed this because it's not possible to reach in the retail demo. It also appears to resemble what happens in the full game as well, with ESC being the only active key while movies are playing.

That said, how can we fix this in ResidualVM?

A simple patch was pushed, but I'm not sure this is the right way to do it. If not, there will be a follow up post describing how to fix the issue the right way!

No comments:

Post a Comment