Electronic Arts aka. EA did something I wished for, for a long time: They released the source code to their new game “Command & Conquer Remastered Collection” (which is released in exactly 14 hours from now!). Which is extremely generous and I’m very thankful that they did it. When I first opened the coresponding Github repository something hit my eye directly: All files were upper case and with short file names. That is pretty DOS style, but I thought that they did it just for the DOS style. But…

I opened by first file, expecting super modern, almost boring and / or uninteresting C++. But the first method’s header comment was stating that the file was created in 1995.

My heart was beating harder and my eyes focused like a damn lion focuses on a deer after not beeing able to eat for 2 days. That’s not a joke 🙂

I checked some other files with the most interesting file names to check, and it suddenly came to me: This is the original source code to the original Red Alert and Tiberian Dawn!!

I had so many questions especially regarding the some seamingly garbage at the start of a save game file, or how the protocol for chat messages in Red Alert worked, so I can have a cncnet tunnel server with commands, etc. Sadly, I never figured it out. And so much more stuff! But this is the day! This is the day one of my many dreams came true: I can now figure it all out!

First I checked how the save game file’s structure looks like. Turns out that a save game version identifier is saved into every save game file to only load save games that are compatible with this game’s version. This save game version identifier is just the size of all the C++ data classes’ data structure added as appended strings. That’s a pretty interresting approach and the supposed garbage.

How does the network protocol work? I don’t know yet, I sadly don’t have the time to check. I want to figure it out while holding a warm cup of milk chocolate in my left hand, tucked into a warm, cozy blanket. So this has to wait for now. Edit: Some years ago I tried to figure out how the protocol works by examining packets with WireShark. But so many bytes just seemed random and I didn’t have a clue what was going on there. Some guy at the cncnet Forum told me that the data might be compressed and had a CRC checksum in it. Turns out he was exactly right:

CRC check for a packet
Packet compression

Quick facts after quick observation

Code is, in fact, remastered, by taking the original code and modifying it a bit.

Code is written in C++.

Code could still run on DOS, as it still has all the routines to call the DOS DPMI. Although I haven’t found the DOS draw routines yet.

Some code was already created in 1991 (maybe copied from Dune, which was released in 1992). Example: path finding code (which is, in general, very portable between games).

Most code was created in 1993 and 1995.

There were fixes made in 1998.

Some comments predict that the remaster process already began in late 2018.

Code is not very portable because:

  1. Many CPU intensive routines are written in x86 assembly to compensate C++’s slow speeds.
  2. Uses Microsoft specific APIs like DirectDraw, etc.

Code makes use of x86 interrupts (especially for calling DOS DPMI functions like allocating memory)

Repository still contains all the IPX code, both for DOS and Windows 95 (the Windows version was commented out in late 2018)

Code makes use of Intel’s MMX instructions.

Code has encoding issues, especially for german umlauts.

The code does not check if the first CD drive has a CD in it anymore as the code is commented out. Thanks to the developers to have us see how it worked before by not removing the old code. Thank you! Fun fact: It was not possible back then to have the CD in a drive that is not Windows’ first CD drive, as it calls a method named Get_First_CD_Drive(). (Edit: there seems to be an interator, going through more than just the first CD drive)

Game can still be spawned by Westwood Chat and uses WOLAPI.

Main loop has two different endless loops for either the real game or the editor version. So the editor is still in there!

A network game’s sync is checked by doing a CRC of all classes’ data structures to the newest packet.

According to a comment in the code, a save game is created if a multiplayer connection was lost.