Monday Mystery: Digital Archaeology

I'm going to be busy for the next couple of weeks, so this week's mystery is actually a lot of mysteries rolled into one. Behold, The Cutting Room Floor, an entire wikia of the various eldritch things one finds when one unpacks complicated video games and digs around in their gooey innards.

Unlike things like films and novels, finished video games often contain echoes of their unfinished selves. Sometimes things are left in by accident; sometimes, it's left in on purpose, because some other feature uses a common segment of the code or some of the assets, and removing everything the game doesn't use would break a lot of stuff that it does. Back in the olden days, when cartridge and disk space were at a premium,. programmers would leave short messages that could only be found by another programmer disassembling the source code. Nowadays, it's more common to find unused 3D models or maps floating around, and to see traces of old structures in the way files are named and grouped together on the disc.

Often, what you find is the remains of a debugging system. Games are complicated and time consuming to test. If you had to play all the way through to the last level the normal way to test your latest tweaks, it would take forever, and the extent to which your levels get debugged would be inversely related to how long it took your beta tester to slog through the prior bits of the game, which is no bueno -- people hate it when they're just about to slaughter the Demon King and the game spits up a fatal error.

It's especially a problem when testing games that are supposed to take 40-80 hours of play to complete, like most decent console RPGs. Programming-wise, most RPGs are complicated rat's nests of conditional checks -- usually called "event flags" -- interspersed with huge wadges of dialogue text. (The battle systems are not all that terrifying in comparison; they're mostly math and a random number generator, which are compact and easy for a computer to handle.) All of the flags start out set to "false" by default, and the game determines where you are in the story, and what cutscenes and blocks of dialogue to serve you, by checking to see whether specific flags have been flipped to "true".

For example: You, the Legendary Hero, meet Lord Jonathan Farthingale Plot-Relevance III, who tasks you to go find the Holy Macguffin. Every time you talk to His Lordship, the game checks the status of the flags OnMacguffinQuest, EndMacguffinQuest, and AfterMacguffinQuest, in reverse order, roughly like this:

IF AfterMacguffinQuest = true, THEN give the player the dialogue sequence from after the quest is over and the Macguffin has been delivered; 
ELSEIF EndMacguffinQuest = true, THEN give the player the dialogue sequence that happens when you hand the Macguffin over to Lord Plot-Relevance; 
ELSEIF OnMacguffinQuest = true, THEN give the player the short dialogue that reminds them that they need the Macguffin, and where they need to go to get it;  
ELSEIF all of these checks fail, THEN give the player the long dialogue that introduces the Macguffin quest and explains all about what it is and where they go and how to get the damnable thing.

The first time you meet Lord Plot-Relevance, all of the checks fail, and the game falls all the way through the loop and gives you the long intro dialogue that covers what the Macguiffin is and why you need one and where you go to get it yadda yadda yadda. The long cutscene, basically. And at the end of that dialogue, it flips the flag OnMacguffinQuest from "false" to "true".

The second time you talk to His Lordship, the first two checks fail, but the second one passes, so instead of the initial long scene, the game branches to the brief reminder text that reads like you've accepted the quest and just need a refresher on where to go.

Once you have slogged through the Forest of Death And Blood and have won a fight with Evil Boss Monster, the game activates a post-battle script that 1) puts the Macguffin in your inventory, 2) pops up a dialogue box telling you that you now have the Macguffin, and 3) sets the flag EndMacguffinQuest to "true".

The next time you go talk to Lord Plot-Relevance, the first check fails, but the second one passes, and the game branches to the dialogue chunk that happens when you present His Lordship with the requested Holy Macguffin. At the end of this scene, the game sets the flag AfterMacguffinQuest to "true".

After that, any time you talk to Lord Plot-Relevance, the first check passes, and the game will forever repeat whatever bland platitudes His Lordship gives you after you've finished your work for him and he has no further use for you.

Those of you who program, particularly if you program for the kind of end user that enjoys cheating like video gamers do, might notice that my pseudocode up there is not particularly robust. It only checks to see if the latest flag in the sequence is set, for example, without also making sure the prior flags are set as well. The event that set the flag for "I have the Macguffin and next time I see His Lordship I need to get the delivery cutscene" also puts a Macguffin in my inventory, but it doesn't check to see if I already have one, and doesn't check to see if I've been to the Forest of Death And Blood, or fought Evil Boss Monster. The flag check that happens when I go talk to His Lordship checks the event flag, but doesn't check to make sure that I still have a Macguffin in my inventory, either -- nor does it check to see if I have only one, and it doesn't remember to remove a Macguffin from my inventory. And the fallthrough case, when all of the event flag checks fail, defaults to giving me the script chunk that assumes I haven't heard about the quest at all yet, regardless of whether I have one or two or 256 Macguffins already stuffed into my knapsack.

This is where debug rooms come in.

It is a bitch to test a game as big as an RPG. The way they usually do it is by using the game engine itself to create a room or a map somewhere, populated with random characters, who use the dialogue system to build menus that let you screw with various options directly.  You find things like animation tests, where you can view character models and cycle them through all their various actions, and sound tests, where you can play arbitrary music tracks and sound effects from the game. Generally there's a video player or cutscene viewer, depending on whether the game uses pre-rendered video or scripts within the game engine for non-interactive plot scenes, and some form of map select, which dumps you directly into your choice of the various towns, dungeons, and overworld locations in the game world. Some of the menu options let you set event flags one by one, by which means you can break the hell out of lazy scripting like the stuff I did above, and give His Lordship a Macguffin you don't have, or give him 256 of them and claim your reward 256 times over.

Usually there are some quick options that flip all the convenient godmode switches, like "give me all possible party members" or "max out my HP/MP/gold and give me all the best equipment", that are used for quickly testing out things like dungeons and battle scripts without constantly worrying about dying. These can get interesting, because they set a whole bunch of stuff at once, without regard to plot sequence. "Give me all party members" gives you all party members, including the ones who, for plot reasons, cannot end up in the same party in a normal playthrough. The game engine itself doesn't care -- "you can't get this character if you've already recruited this other character" is a thing controlled with the event flags -- but if it's a thing that can't happen in normal play, there may be no code in place to handle it.

Maybe nothing weird happens, if there's a harmless default option for the game to use when it can't think of anything else. Maybe the game crashes and you have to remember not to put them in a party together when you're screwing around with the debug room. Or maybe you discover that there is code in place to handle that combination -- you can't access it when playing the game normally, because the plot prevents those circumstances from coming about, but at some point in the game's development, it was possible, and someone sat down and wrote the code for it before the story changed and the feature was axed.

Sometimes they remember to remove most of the debugger before shipping the final game, but most often, they just disable access by removing the option to branch to the debug room from the starting menu. You can generally get in with a GameShark, or similar RAM-altering device. The debuggers in localized versions of games can be nigh-indecipherable if they were originally in kana/kanji, and the Japanese font has been removed from the export. They're almost all full of black holes and fatal errors, because getting the debugger interface to work all pretty is frankly kind of a low priority -- it's easier to just tell the testers 'well don't do that then'. They tend to be full of in-jokes and office breakroom silliness.

Mostly what you find are curiosities like test enemies, unused items, and old versions of maps, with the occasional early version of scenes that were cut from the final game. Occasionally, though, you hit the motherlode. SaGa Frontier, which is already a mind-boggling tangle of seven interconnected stories as-shipped, originally had an eighth scenario. The assets and scripting are largely still on the commercial disc; it was cut so late in development that they didn't have the time to figure out what they could delete without breaking anything else, so whatever they'd gotten done just lingers there, inaccessible, lurking in the file structure. Xenogears has remnants of what was meant to be on the second disc before time ran short, and they defaulted to exposition monologues. Fallout 3 and Resident Evil 2 both had first attempts (known to fans as "Van Buren" and "Resident Evil 1.5", respectively), completely different from the released game, that got to maybe 50% complete and then were scrapped and started over from scratch.

You guys have at TCRF while I go recover from the everything, and simultaneously try to tech a show for Watch City without falling down.

Check the category label for more Monday Mysteries!

Comments