GSOC Update: Week 9

This is quite soon after the last update, but I feel this is an appropriate moment for an update. I have added the various Sound functions, including Voice, Music and Sound Effects.

I have also played through a few more levels, and fixed a Lua bugs, so the game won’t crash until MAP20 at the very least.

Current Problems

While Voice and Music are working fine, the Sound Effects code currently has a bug where the data for each sound effect gets corrupted after playing through it once. Running it through the debugger, it seems that the AudioStream holding the Sound Effect data either automatically gets deallocated or corrupted, since the system can read it no longer. I have spent quite a few hours trying to deduce where it is getting deallocated, and I can’t seem to find it.

One of the few remaining portions left is syncSoundSettings(). It is the default method via which ScummVM saves the Sound configuration for the game. I haven’t looked into it yet, which would be my next goal.

I’m not completely sure whether or not there is a problem with MAP19, but I can’t seem to beat it without cheating through the debug interface.


  1. Added Voice, Music and Sound Effects code
  2. Fixed crash with Deliveries with no GFX
  3. Added additional output to the Debug Interface
  4. Removed unused code

Thanks to Eugene(sev) and Arnaud(Strangerke) for help in cleaning up the codebase, testing support for demo versions of the game and pointing out potential mistranslations in the codebase.


  1. Fix the AudioStream bug
  2. Implement syncSoundSettings()
  3. Start adding support for different MPC files

GSOC Update: Week 8

I spent most of this week resolving memory bugs and playtesting the game levels.

The game still isn’t playable from beginning to end right now, but progress has been made. I estimate that you start from the beginning, you could definitely play up till MAP14-19 before you a bug stops you. Also, I’m not completely certain whether or not all the endings in the game are currently achievable.

Current Problems

I have managed to run Sound through the main hdb.cpp file, but the methods defined in the original are not as simple. They involve multiple structs, and functions for each of them. This is my top priority for now.

There are two kinds of sound data in the MPC file: MP3 and WAV. The MP3 files are working fine, but the WAV data in the archive is empty. It seems that all the data values have been set to 0. I’m not sure where to find those sound files, but they need to be found: all the sound effects are in the WAV format!

Finally, I have only tested the engine on the Windows Full-version. I still have to test out PPC and Linux versions, and add support for the compressed and voiceless versions of the game. This shouldn’t be too hard as long as I can find their data files. Moreover, I know that the current engine won’t work with the demo versions of the game. So I have to support those as well.


  1. Fixed memory leaks
  2. Removed redundant code
  3. Added Patches to MAP10, 11, 15 and more
  4. Fixed problem with Animating Bridges
  5. Fixed moving floats
  6. Fixed aiFatFrogTongueDraw()
  7. Fixed crash caused by LIGHTBARREL in Slime
  8. Fixed indexing problem in the Teleporter code

Thanks to Eugene(sev) for help with the uninitialized reads, simplifying the save system and fixing bugs such as the Loading Screen, the Waypoint system and adding patches for different maps. Thanks to Arnaud(Strangerke) for fixing compilation issues with MSVC9 and pointing out flaws in the Teleporter code.


  1. Complete Sound system
  2. Find missing sound data
  3. Start adding support for different MPC files

GSOC Update: Week 7

By the end of this week, almost all of the STUBs – save for the ones related to Sound – in my codebase have been resolved.

The game is getting in pretty good shape now, but it is still far from the point where you could start from the beginning and have a reasonable chance of beating the game. There are three major issues right now.

Current Problems

For starters, HDB is eating up a lot of unnecessary memory, so I’ll be patching up on all the uninitialized reads and memory leaks I have inadvertently caused.

Secondly, the game is riddled with bugs. Not the game crashing kind, but subtle bugs that ruin the experience. Examples include the enemies being unable to hit the player(though I bet certain players would call this a feature), some paths being blocked for no apparent reason, and most importantly, the first level in uncompletable right now.

Finally, I haven’t played through most of the stages and I’m willing to bet that there is still a lot of Lua 4.0 code in the Level code that needs to be patched. I don’t have enough Lua experience to tell this just from reading the files, so I’ll have to test out the game to find out wherever the Lua interpreter is crashing.


  1. Implemented Menu System
  2. Implemented the in-game Debug Mode
  3. Added support for the Quit Key
  4. Augumented the Command Line Level Select to choose between Action Mode and Puzzle Mode
  5. Implemented the Fade Functions
  6. Implemented the Snow Rendering Functions
  7. Implemented the Progress Bar/Loading Screen
  8. Added the Weapons Code so Guy can now attack and stun the enemies


  1. Fix Memory Leaks
  2. Fix gameplay bugs
  3. Add Lua patches

GSOC Update: Week 6

So, I spent most of this implementing Pushing, unstubbing Bots-NPC code and implementing the Save System. Here is a gist of the accomplishments. However, loading the savefiles directly from the command line doesn’t work right now.


  1. Added all the Bots code, all the Callback Functions and most of the NPC code
  2. Added Extendable Bridges, along with the useTarget function for Use interactions
  3. Implemented Pushing
  4. Added stubbed Sound and Menu system
  5. Added Save/Load system with saveGameState and loadGameState functions

Also, sev added the code for skipping certain quests and loading Game Levels from the command line. Along with the Save system, this should make testing specific parts of the game much easier.

Save System

While the Save system was implemented through the conventional ScummVM method, it still took a fair bit of trial and error to get it working.

The biggest problem I had was how to save the different structs and function pointers. The original saved the different structs directly, without thinking about the endianess of the data member. To remedy this problem, I had to use the ScummVM read and write methods and greatly split the original code.

Since the structs were being saved directly, the pointers and function pointers were being written as well, which would have been useless upon loading the save. Hence, separate code needed to be added to cache the structs and functions those pointers pointed to.


  1. Implement Menu System
  2. Implement the Fade Functions
  3. Implement the Snow Functions
  4. Implement the Progress Bar

GSOC Update: Week 5

Continuing the work that I started last week, I have implmeneted most of the functionality in AI and Window, and mostly completed a new sub-system: Input.

The openning cinematic is completely running, all the input controls except the Quit Key and the Pause Key have been implemented, NPCs, Bots and objects like crates have been introduced, and the player can now talk to NPCs. Here it is:


While most of this week went according to plan, I ran into a few weird bugs that sev had to point out for me. Here are they:

The CineCommand Problem

Shortly after writing the previous blogpost, I ran into a bit of trouble. I noticed that Lua was loading the wrong string for the dialog text, and fixed that which directly caused the game to crash.

After a few hours going over why it was crashing(which among other things involved printing the Lua Stack), sev pointed out that I had been using a preallocated char arrays of 32 length, while trying to load messages as long as 80+ characters. This had led to a memory overwrite, and caused the crash. Changing the CineCommand struct to use a const char * fixed the crash.

Dialog Spacing

In a stupid blunder, I had been miscalulating the whitespace in the dialog messages. Instead of simply adding the designated number of pixels, I was multiplying them leading to a large amount of unnecessary whitespace.

Foreground and Background indices

If one recalls the previous blogpost, one would know I have a tendency to declare values as unsigned variables. This led to another problem recently, when I realized that certain tiles are designed to as to have a -1 index value. This type mismatch had to be corrected.

The Clock That Wouldn’t Disappear

In the openning cinematic, there is a clock that needs to vanish after it is thrown. However, it wasn’t disappearing. sev pointed out that I had been using the _cine[i]->x, _cine[i]->y positions rather than the _cineBlitList[i]->x, _cineBlitList[i]->y positions for the clock, hence its appearance.

The Copy/Paste Error

I had made a nasty copy/paste error. When making a nester for-loop, I had copy-pasted the outer-loop without changing the indices of the new loop. This didn’t show any problems at first, but would definitely cause trouble later.

Changing indice mid-loop

One of the slightly-inconvenient problems I have started to face involves altering an array while iterating over it. Doing so while using an iterator has caused to be trouble some, since it would lead to one or the other pointer error. The best approach seems to be to rewrite those loops without the use of iterators.


  1. Add Sound System
  2. Add the remaining Bots and NPC code
  3. Implement Pushing
  4. Find and patch Lua problems