📜 ⬆️ ⬇️

A tale about how I disassembled Supaplex and almost wrote a clone with 3D graphics

Picture to attract attention

I think most people who caught the days of DOS and the early Windows 9x played or at least heard about such a wonderful game like Supaplex. For me personally, this is a legend game. I still remember with trepidation the long winter evenings spent in an attempt to go through some difficult level on the old 286th.

It so happened that I am a programmer. And not just a programmer, but a computer game programmer. So, somewhere in 2008, I started writing the “Kruze murderer” engine (or whatever was cool at that time, I don’t remember). About a year later, I had an insight that my man-hours for a project of the Unreal Engine level would not be enough. And I decided to make an easy, “casual” version of the engine and write a couple of simple toys on it.
')
My choice fell on the Supaplex clone. True, at that time there were already several clones for Windows and other platforms, so it was not interesting to just write everything from scratch. But a seditious thought crawled into my head: what if to disassemble the original Supaplex and make a game with logic “identical to the natural”. Such a task seemed extremely tempting, and I took up its implementation. I ordered a 3D model from one good friend of a freelancer, and while he was busy modeling, I began to study the patient. Immediately I warn you that I don’t remember many details and can forget or lie something, after all, it was quite a long time ago.

Disassembling


A little running ahead, I note that everything I have left on this project (disassembler scripts, prototype sources) I put on the github. Look for the link at the end of the article.

It all started with the fact that the executable file is either packaged or encrypted. After an unsuccessful search for something that could unpack it (although I didn’t look very carefully), it was decided to write my unpacker. Probably cycling in my blood. I don’t remember thoroughly how it worked, but the idea was to emulate CPU instructions to the point when the program started successfully, after which the contents of the memory were saved to disk as an EXE file. This wonderful decompressor can be found in the materials for the article.

I used IDA for disassembling. As far as I remember, I had to re-create the database several times, so instead of it, I used an idc script that appends names to characters. You can also find it on the githaba. If you were interested in digging in the Supaplex guts, but it was difficult to understand the jumble of assembly instructions, this script will help a lot (even if you do not have an IDA, you can use the shifts specified there in any other disassembler).

As I was disassembling, I started compiling C ++ - pseudocode, trying to understand what this or that section of the assembler code does. I dealt with the most complex and incomprehensible blocks with the help of a samopisny debugger, which tracked hit in certain sections of the Supaplex code during the game and informed me about it. In this way, I tested the hypotheses about the purpose of some sites. At a later stage, I began to rewrite parts of the code in C ++, continuing to access other parts of the original, which allowed us to verify the correctness of the disassembly of each block.

The result of all this was the almost pure C ++ code of game logic, with a small inset of goto and variables with strange names like byte_403C3. You will also find it in the materials for the article.

3D version


The prototype looks like this:

Screenshot

A little bit about the engine. The code of the engine itself is quite voluminous, although it is simple and non-functional to ugliness. The original, “big” engine was written using the Qt library. Then for some reason I decided to give it up (I don’t remember the details) and wrote my own replacement for the Qt classes.

For drawing old OpenGL with extensions is used. There is an interesting detail in the engine: if I remember correctly, at that time OpenGL 2.0 and GLSL were not very common (at least my laptop with an Intel video card did not know how). I took from Mesa (open-source implementation of OpenGL) a compiler from GLSL to assembler shaders. As a result, shaders are written in GLSL, but the engine even works on very old hardware.

The game has no menu or at least some user interface. In the resources lies the original levels. Dat from Supaplex. By default, the game starts at the first level, but if you create the file level.cfg in the directory with the binary and write the level number (from 1 to 111) there, the game will start at the selected level. The control is the same as in the original - the arrows move the character (by the way, his name is Murphy) in the selected direction, the space + arrow eats the object in the specified direction without moving the character, prolonged retention of the space sets the red disk (if you have them, of course) . Pressing Esc leads to instant suicide (hello, Roskomnadzor!).

Sources


At the time of development, I used the SVN repository. I perezalil all in Git and a little bit “combed” the code so that it was going not only on Windows, but also on Linux with OSX. Everything is available on github: github.com/zapolnov/superplex3d_prototype , going to CMake. There are also binaries for particularly impatient.

I do not plan to develop this project yet. I translate all my code into public domain, all art is available under the CC Attribution-NonCommercial-ShareAlike license. Sounds and music downloaded from these your Internet and their license is unknown to me.

For obvious reasons, the disassembled code of the game logic (supaplex_game.cpp, as well as its version in the disassembly directory) is provided for informational purposes only, after reading it, you must burn or eat, and forget everything that you see there.

Source: https://habr.com/ru/post/246027/


All Articles