I haz a SpaceChem Mission Viewer

Well, that took a little longer than I anticipated. Anyway ...

 

One of the fun things about SpaceChem is that you can create your own missions and share them with others. For example, this is the one for my 'Fun With Water' mission.

H4sIAGmCA08A/3WPMWvDMBCF/0q42QJJdCjS1slbxg6hg2qfY4MiGekEdY3723tKSohbuhzcx3
vv3q0whbmQ+IwBM5gVZB1XxutphUv02BWPYKBd+hTPGGxrlVJSQgNdLIHAKL29bQ2o/73Hj6U6
j+x8/uNkayy0q3GNevC/OsJk2y+pawRft5qDlNV6X0TWsNFl4V06o7jFghmcz9jAeww9JvEjfr
opM4Yc011T0VAy7kme/UT0CxJ6nGN6xLTMtW7CjC51IzcL7nJ/4CAOLy4jU1dorEehY11g0E/D
MPGztICR2zd6bzBSlwEAAA==

Unfortunately, you can't really tell what the mission is about until you import it. This can be a little tricky if you're not behind a computer on which SpaceChem is installed, like when you're at work. Oh wait, not when you're at work, obviously – because that'd be wrong. But my point is that you can't see what the code does if you're not at your usual computer.

until now ….

 

Presenting: my web-based SpaceChem mission viewer :D

http://www.coranac.com/spacechem/mission-viewer.

Disassembling the code

I had been meaning to do this for a long time now, but never really had the time for it. The main challenge was to discover what the code actually meant. Just from the look of it, it was obvious that it was Base64 encoded. Decoding leads to the following hex string:

# after base64 decoding (in hex)
1F 8B 08 00 69 82 03 4F  00 FF 75 8F 31 6B C3 30  10 85 FF 4A B8 D9 02 49  
74 28 D2 D6 C9 5B C6 0E  A1 83 6A 9F 63 83 22 19  E9 04 75 8D FB DB 7B 4A  
4A 88 5B BA 1C DC C7 7B  EF DE AD 30 85 B9 90 F8  8C 01 33 98 15 64 1D 57  
C6 EB 69 85 4B F4 D8 15  8F 60 A0 5D FA 14 CF 18  6C 6B 95 52 52 42 03 5D  
2C 81 C0 28 BD BD 6D 0D  A8 FF BD C7 8F A5 3A 8F  EC 7C FE E3 64 6B 2C B4  
AB 71 8D 7A F0 BF 3A C2  64 DB 2F A9 6B 04 5F B7  9A 83 94 D5 7A 5F 44 D6  
B0 D1 65 E1 5D 3A A3 B8  C5 82 19 9C CF D8 C0 7B  0C 3D 26 F1 23 7E BA 29  
33 86 1C D3 5D 53 D1 50  32 EE 49 9E FD 44 F4 0B  12 7A 9C 63 7A C4 B4 CC  
B5 6E C2 8C 2E 75 23 37  0B EE 72 7F E0 20 0E 2F  2E 23 53 57 68 AC 47 A1  
63 5D 60 D0 4F C3 30 F1  B3 B4 80 91 DB 37 7A 6F  30 52 97 01 00

Yeah, that helps a lot, doesn't it. If you can read hex a little, you'll notice there's nothing in there that says something like 'Fun With Water' (the title of the mission). I also had a number of other very simple test missions for this with minor differences like 2,4,8 bonders or with/without sensors or fusers and such. Decoding those gave strings of variable lengths that didn't look anything like eachother, and even had varying lengths. This meant that it had to be compressed somehow. but which one? And how to find that out? Well, what you could do is to read the text files that came with spacechem, which mentions zlib (which is used in gzip). So let's try that.

# after zlib/gzip decoding
{"input-zones":{"0":{"inputs":[{"molecule":"Hydrogen;H;11100","count":12}]},"1":{"inputs":[{"molecule":"Oxygen;O;11800","count":12}]}},"output-zones":{"1":{"molecule":"Water;H~02O;11110;21801;22100","count":10}},"has-large-output":false,"bonder-count":4,"has-sensor":false,"has-fuser":false,"has-splitter":false,"has-teleporter":false,"type":"research","name":"Water - Base","author":"cearn","difficulty":0}

Oh hey, that's just a JSON string! :D. I had expected some sort of binay format, but this is much simpler to read and edit. Phew. If you fold it out, it looks like this:

# mission JSON, formatted
{
  "input-zones": {
    "0": {
      "inputs": [
        { "molecule":"Hydrogen;H;11100", "count":12 }
      ]
    },
    "1": {
      "inputs": [
        { "molecule":"Oxygen;O;11800", "count":12 }
      ]
    }
  },
  "output-zones": {
    "1": { "molecule":"Water;H~02O;11110;21801;22100","count":10 }
  },
  "has-large-output": false,
  "bonder-count": 4,
  "has-sensor": false,
  "has-fuser": false,
  "has-splitter": false,
  "has-teleporter": false,
  "type": "research",
  "name": "Water - Base",
  "author": "cearn",
  "difficulty": 0
}

After that, the rest was pretty easy. The molecule string presented a little bit of trouble, but it's just the coordinates of an atom (x and y, 1 digit each), the atomic number (z, 3 digits), and the number of bonds to the right and down (h and v, 1 digit). Furthermore, the count for inputs are in 12ths, e.g. 3 means 3/12 = 25%.

 

During the creation and testing of the viewer, I also made some additional discoveries.

  • You can change the output number for research missions, but not production missions. So no recreating boss missions, unfortunately.
  • Although the in-game editor does not allow the special elements (Θ, Ω, Σ, Δ, moustachium), they are accepted if you enter them manually. That's how I created these missions. Mind you, the game will not accept invalid atomic numbers. It will go bewm if you try.
  • On the other hand, double-bonded hydrogen seemed to work :)
  • The colors of the elements actually have meaning: it indicates the number of maximum bonds.

And that's it. The viewer is still a bit minimal, but it shows the most important things. There's a few instructions at the bottom of the viewer, and you can hover over the graphics to get a few more details on various items. So if you find a mission code and want to see what it's about without firing up the game, give it a try.

2 thoughts on “I haz a SpaceChem Mission Viewer

  1. (UPDATE) GuavaMoment noticed that you can in fact change the output counts, but it only works for research missions. Thanks, Guava!

Leave a Reply

Your email address will not be published. Required fields are marked *