The Neverhood support added to ScummVM
A few days ago, on May 15, in ScummVM , a well-known cross-platform set of game engines for point-and-click adventure, a code branch was added with an engine that supports the classic quest genre, the game The Neverhood.
It was one of the most exciting and longest projects in ScummVM. Talk about this masterpiece continued for several years, and forums regularly asked to add support for this game. It took two years to develop the engine, and I want to briefly describe how this happened.
It is worth noting that adding a game to ScummVM is not an easy task at all. Today, for about half of the engines, we managed to get the source from the authors, but even in these cases, the code always needs to be rewritten. So, recently a lot of games have been coming into the project, written originally in Pascal and Assembler, and to add them, everything needs to be translated into C ++. The other half of the engines turned out by hardcore reverse engineering (you can’t say otherwise), when the IDA is adopted, and we slowly begin to mark up the original engine with function names, variables and comments, layer by layer understanding the logic of its operation.
It was the second approach that was forcedly used with The Neverhood. Attempts to contact the authors were not particularly successful, their hands were scratched, and in June 2011 the project was launched.
Project Chronicles
Initial data:
* 800 kb binary code
* Original in C ++
* 7.2 thousand functions
* 340 virtual classes
After two years of working two people, the result was obtained:
* 36 thousand lines of code
* 2 thousand methods
* 320 classes
The first commit was simple:
Author: johndoe Date: Wed Jun 22 22:58:51 2011 +0000 NEVERHOOD: First code with basic detection, nothing else so far
This skeleton is essentially standard, and the development of each engine usually begins with it. Oh, how many attempts to reverse the game for ScummVM at this end! But not this time, not this time. Two days later, code was written for access to the BLB archives, and two days later the graphics were decoded and work began on Module1500, the introduction to the game.
We were not stopped by the fact that the game is a hardcode. Most of the engines for adventure games supported by ScummVM are virtual machines (you can write a separate post about this), and their structure is not too complicated. Sometimes, original developers write game scripts directly in a programming language, which increases the amount and complexity of reversing by dozens of times. Particularly difficult is working with C ++. Compilers of this language often use advanced optimizations, and virtual classes are also translated into assembler as implicit calls, which causes even more headaches. Also, the fact that the IDA and Hex-Rays still do not really know how to work with pluses and it is necessary to use a lot of crutches does not simplify the work.
However, on July 4, the game’s initial splash screen was launched. Although it is a collection of clips in the Smacker format, even for this it was necessary to implement a message system, updating the screen, processing the keyboard, darkening the palette, switching between scenes, in general, writing almost 3 thousand lines of code. A week later, the first scene was completed and work began on the second scene of the game, Scene1002.
Then the scenes were added one after another, every week. By the way, there are 71 of them in the game.
By mid-September 2011, when approximately half of the scenes were realized, refactoring started. The original code, as expected, contained quite a lot of noodles. ScummVM standards are quite high, and to improve the quality of the code, we always work to improve the structure, and often the architecture of the original engines. Neverhood is no exception here, object generators, wrappers were added and many functions were merged together.
Almost no work was carried out from January to July 2012, and in August a dozen more scenes were added and work on the sound began. In Neverhood, sound is encoded with its own proprietary RLE encoder, and up to three sounds must be played simultaneously in addition to background music. By the beginning of October, the corresponding challenges were added to all the scenes of the game, and we began internal alpha testing.
After the second wave of refactoring, when a significant part of the duplicate code was thrown out, and the engine “lost a lot of weight”, preparations began for the branch to merge with the main ScummVM code. To do this, it was necessary to add the menu, the final credits, the Hall of Fame room, as well as the recording and restoration of the state of the game.
On January 21, 2013, after a year and a half of development, it suddenly dawned on us that the original character was called Klaymen, not Klayman, as it would be logical according to the English grammar, and this insight was followed by a massive renaming of variables and classes in the code .
Some more refactoring, bug fixes, and on May 5, 2013 a Pull Request was made to the main ScummVM branch.
Here it is, the history of the project.
Briefly about the future
Work on the engine is far from complete. Now you need to make sure that the game works on all supported platforms, in particular, on big-endian ARM.
Also, unfortunately, the Russian versions of the game are not yet supported, as our translators, as often happens, slightly changed the formats here and there, and the engine in ScummVM crashes after the initial splash screen. We are working on it right now. It is possible that we will work on adding support for the PSX version of the game.
It is still necessary to do some refactoring work, in particular, to remove the global constructors, which are evil. And finally, announce a public beta test.
Links:
ScummVM project site , in order to launch The Neverhood, you need daily build version 1.7.0
Engine source code
How to start the game
The game needs to be copied from the original disk, click the Add Game button in ScummVM, specify the path where the game is copied, and then the game will appear in the list (so far only the English version and demo are working). Next, double-click on the name of the game, the game will start.
Demo can be downloaded from here . You can buy the full game on eBay, Amazon, also still come across on the shelves of our Russification stores.