Perhaps you've already heard that I've been recently developing a mod for the current version of Nuclear Throne. And not "just" a mod, but quite an impressing one:
Adds Steam-based online multiplayer support to the game.
That means invitations, public game list, and no port forwarding.
Easily record and review your runs to learn from mistakes.
Or even attempt to correct them by dropping into the game at any point of a replay.
Nuclear Throne never was a coop-centric game, and thus coop mode didn't receive enough attention, remaining ridden with various small bugs. This mod changes that, fixing pretty much every known issue, and giving coop some much-needed polish.
While fixing coop-related bugs is an obvious choice given the scope of the mod, I didn't stick to just that, and also fixed a handful of other issues with the game. Bugged "crown vaults"? Fixed. Game hanging in certain areas? Fixed. Occasional crashes during an intro to an important boss fight? Also fixed. The full list is long (200+ items) and available in the "readme" document.
So it works, it's nice, and you can download it right now.
Or continue reading on process and potential questions.
A bit of prehistory
In general, this mod's development followed a pattern commonly seen in my works:
- 1. Pick A goal that is considered somewhat impossible, but does look possible to me.
- 2. Slightly underestimate amount of effort required to accomplish the goal.
- 3. Get it done anyway.
In this case, the following happened:
- Needless to say, I do like Nuclear Throne a lot. I've sunk well over a hundred hours into the game over the course of it's development, watched the development closely, and was interested in the game's cooperative mode since it's introduction.
- Last autumn, Wasteland Kings' (jam version of Nuclear Throne) source code became available through GameMaker-themed Humble Bundle deal together with a bunch of other nice games.
- Overwhelmed by curiosity, I've decided to get the bundle and mess with coop games included for a little. This reuslted in Super Crate Box Together and Wasteland Kings Together mods.
WKT being well-received and working nicely for vast majority of players, numerous people suggested that
Vlambeershould hire me to do online multiplayer for the actual game.
In a brief chat following, Vlambeer's Rami Ismail voiced largely-reasonable concerns about whether the approaches used would be viable for NT.
At the time I didn't feel like arguing about the fact that lack of online multiplayer means that many people won't get to play the game in coop at all, so I did not continue the conversation.
Sometime since the end of 2015, I was also looking at different bytecode implementations with intentions of looking for good tricks to use in my own bytecode interpreter.
In part this also involve staring at GameMaker's bytecode format, partially for research, and partially for understanding how things work better. So I made a little tool (shown below) to display tweaked bytecode in the most readable format possible, did some tests, and sometime through this I've thought "well, this doesn't look that terrifying. If I were to tweak some things, could I hack some new code into a game?". And thus...
Deconstructing Nuclear Throne
The next thing that happens is me staring at a 9.5MB \ 233 000 line long bytecode dump of Nuclear Throne, trying to make any sense of what's going on, questioning my intentions.
Should you have an impression that reverse-engineering an existing large game to poke few thousand new lines worth of code into it isn't a bad idea – it very well is.
While for my purposes I would rarely need to actually decrypt snippets of bytecode (either adding new code or replacing snippets with something that would work with netplay), looking for anything in such a giant pile is, to say at least, not very fast.
So for the next long while I was poking this in spare time, concluding in a test mod release on May 21, 2016, and finally being able to get to the actual online multiplayer on May 26, 2016.
Small-scale netplay for a large-scale game
As you may know, Nuclear Throne gets pretty chaotic in late game.
While the game starts with singular enemies and a few projectiles here and there, in mere 10-15 minutes you can already have decades of enemies and hundreds of projectiles (many of which your own) at screen at once.
Obviously, you can't just send that much information on an average internet connection easily.
In this case, a feasible workaround is a "synchronous" \ "lockstep" - like system, where the game is modified to behave completely deterministically (as in, not depending on external factors), therefore reducing the volume of data to be sent to player actions.
Similar approaches are commonly used in emulation software, as well as most fighting games.
However, "synchronous" multiplayer also means input delay, which can hurt a little, particularly with mouse controls (ever tried playing something via TeamViewer\Nvidia GameStream? It hurts).
So the latency is divided between players, critical things (camera, aiming) are handled without delay, and there are additional tricks used to improve the situation where appropriate.
On the technical side, the mod uses Steam API via a native extension that I've made, which is how there are Steam invitations, lobby list, and other things that you'd expect to see in larger games;
As per usual, I made use of code from my existing projects, so certain menus and systems may appear very familiar.
All in all, while the mod requires somewhat-low-latency (100ms delay / 200ms ping) connection for comfortable play, that's already substantially better than needing the second player to come over.
Legal & extras
After having a buggy-but-functional build done after a week of work or so, came the exciting part: waiting for an answer at whether it is legal to release this mod at all.
See, being a likely-first mod of such kind, neither me nor Vlambeer folks could know for sure as to what is right (in legal terms) and what isn't. So I wrote to Rami. And Rami wrote to legal. And, well, this took a little longer than intended, having received the final answer almost 3 weeks later.
But that's okay, since waiting for the response also meant that the mod went through substantially more testing, and got proportionally more bugfixes, and even a few new features.
Perhaps somewhat unsurprisingly, NT having local-only coop meant that fewer people were playing coop at all, and as the result there were much more bugs in that than I've expected.
So I'd look at anything that was reported and could be traced back to anything particular easily.
Not having access to the original source code anyway, anything found to be related to a problem would be tossed out and replaced with a snippet based on freshly written code.
While this isn't an optimal approach, over time I was able to fix pretty much every known issue related to coop, as well as number of bugs from the original game.
For example, the aforementioned infamous "cursed vault" bug, which is basically the game accidentally mashing up two unrelated levels together (not to your advantage), turned out to be caused by the game accidentally dropping a chest onto an "objective" prop, crushing it, and triggering the level index change before the area was even done generating, as result filling the area with enemies and props from the new level.
In the end, the mod is now more stable than the actual game in some aspects, which is pleasing.
Could this be done better?
It would have been nice to support up to 4 players, but, unfortunately, Nuclear Throne was not coded for 4-player support originally, so the game is lacking support for this in UI, code, and balance alike. While this might be doable in future, it would take time to get right.
It would have been nice to have Mac and Linux versions, but that requires additional testing (and making variants of patcher program for Mac and Linux, which hurts a lot), so shall probably come in future. Till then, NT seems to run unusually fine on Wine.
Ideally, the mod should also have had even more going on for lag compensation, to make the game playable even on higher latency connections. Unfortunately, that requires reworking the game's collision systems to an extent, which would be a lot of trouble to do with how this works.
In an even more ideal scenario, it would have been great to integrate a scripting system into it, which, combined with online multiplayer, could quite likely longen the game's lifespan by a lot, but – alas, that is even more work. In fact, a pretty absurd amount of work for something that you aren't a developer of in the first place.
So you've got to do what is practical to do.
Could Vlambeer do this themselves?
This is something that some people were asking me about a lot.
In theory, with enough time, they could do an online multiplayer implementation by themselves.
In practice, the reality is kind of harsh, and while you can try to do online multiplayer without prior experience, you are incredibly likely to mess it up on first try.
By which I mean – if you are considering getting into netcode, please do not start with your commercial game. Things are easier to break than fix.
If you can, consider hiring someone that is actually proficient with this kind of thing.
Or at least seek existing tools/libraries that can help you with not messing up.
So overall while Vlambeer could have tried to do online multiplayer by themselves, it would likely be regrettable for everyone.
So, in conclusion, this was tough, and interesting, and fun.
This post should have been a tad bit longer, but I'm sure that everyone very much want to play it already, so that's it for now.