Continued from the previous entry
Sorry, no pictures for this one!
With the previous patch for equality when checking if an actor was in a sector, I thought the work was completed. Unfortunately, it was pointed out that in the original engine for Grim Fandango, the sector check is done using strstr to check the sector name by substring. Also, with some help from the #ResidualVM IRC channel, I found out that ResidualVM originally DID use equality, but it was changed to a substring check due to a bug in GRIM. Uh oh!
First, I took a look at the problematic scenes in EMI and GRIM to figure out why this bug is happening exactly. Next, the source for EMI needed to be checked to see what its behavior was when running the Lua command IsActorInSector, which is where the broken behavior was. And finally, I needed to resolve the issue for both games.
In the sets themselves, I identified the original problem as returning the incorrect sector when picking the sector by name, with pph_close and pph_closer as the example of two colliding sectors. So, out of curiosity, how often does this happen in EMI? As it turns out, really often! There’s cases where different sectors even have the same name! How did I find this? I started by first converting the binary set information to text:
- mkdir artAll
- cd artAll
- unlab ../artAll.m4b
- mkdir Sets
- cd Sets
- for i in *.setb; do n=$(basename $i | cut -f1 -d.); setb2set $i > $n.set; done
With the converted sets, I could now inspect the sectors that they used:
- grep sector *.set | grep -v section: | grep -v numsectors > ../sectorlist && mv ../sectorlist .
With this information and this script, I collected some statistics:
- GRIM (3142 total sectors):
- None of the sectors have duplicate names
- 605 of the sectors are substrings of another (including duplicates)
- EMI (2228 total sectors):
- 140 of the sectors have duplicate names
- 506 of the sectors are substrings of another (including duplicates)
Well, that’s interesting. Both games have sectors that are named so that some sectors are substrings of other sectors! However, this bug is specifically about changing between setups when the actor triggers the setup change by changing sectors. So, I also checked all of the setups for substrings and found:
- GRIM (384 total setups):
- 1 of the setups has duplicate names
- 2 of the setups are substrings of another (including duplicates)
- EMI (326 total setups):
- 0 of the setups have duplicate names
- 28 of the setups are substrings of another (including duplicates)
It’s important to note that in the case of the bug, only the camera sectors are checked, so let’s run the same test, but filtering for only camera sectors:
- GRIM (210 total camera sectors)
- 0 of the camera sectors are substrings
- EMI (182 total camera sectors)
- 73 of the camera sectors are substrings
I also checked the setups more closely in EMI, and it turns out that while there are plenty of setups named with substrings, the only setups that the player who is controlling Guybrush can walk between are in the set pph (i.e. pph_close and pph_closer). All of the other setups are unused or switched to by the Lua directly (as in the set pla with pla_judges and pla_judges_close).
So, I’ve identified that there’s really quite a bit of overlap, but not much in GRIM when it comes to camera sectors, while there are a lot of overlaps in EMI’s camera sectors which is causing this bug. However, I’ve shown that the only scene in EMI that this effects is the set pph.
In the next post, I’ll discuss the original binaries and the solution to this problem, this post is getting long enough!