Boom, boom, boom goes a shotgun, firing at…well, so far as I can tell, nothing? There’s a plasma gun on the ground, I guess, and a ghost to the right, but there’s no enemies in front of the player, and while the ghost can be killed, they’re not firing in the ghost’s direction. This is a Spelunky world record run for—*checks notes*—collecting the most money? And the part that people are hyped over involves firing a shotgun into the vacuum of space? Huh.
Few games are ever truly solved, there is always more to learn. 33 years later, for example, people are still trying to achieve the perfect speedrun of the original Super Mario Bros. But over time, the bar is raised ever higher, with more and more time needed to eventually climb over. Progress happens in fits and starts, a wild combination of study and happy accidents.
I’ve played hundreds of hours of Spelunky and know the basics: run, jump, whip, bomb, die. I know there are strange, intricate strategies in order to be really good at Spelunky, to achieve world record runs. That’s normal. But nothing about this video makes sense to me, and so I closed it, until the strangeness of it all started bugging me. I had to know what’s going on.
There is rhyme and reason to this, as it turns out. The explanation is truly baffling, a form of quiet code manipulation fans are still trying to fully understand, unearthed by Spelunky’s self-described “scientists.” It’s a living testament to the way the Spelunky community has prospered nearly seven years after it debuted on Xbox 360. A proper sequel, Spelunky 2, is coming in 2019, but in the meantime, Spelunky continues to have its rewards.
Glitch or not, even the game’s developers are impressed by the dedication.
“What the Spelunky community has done with the game has already blown so far past what we thought was possible,” said designer Derek Yu on a recent episode of the Spelunky podcast The Spelunky Showlike. “I don’t know. For me to now be like ‘Hey, now that’s too much. That’s where I draw the line!’ [laughs] It doesn’t make sense. They’re already way into the stratosphere, I can’t even see them at this point. It’s just another cool thing.”
The world record scene for collecting the most money in Spelunky has been humming along since 2013, with a new record every few months. Since the summer of 2016, it’s been largely dominated by Kinnijup, one of the Spelunky demigods, as he beat his own score again and again. (Try not to sit slack jawed while watching him destroy Spelunky at this year’s AGDQ.)
Don't Get Caught Duping
Years ago, the community discovered a duplication glitch in Spelunky. If you stacked gems on top of one another and collected it all at once, you’d get some of them twice. This was especially important for score (aka money) runs; it meant you could, in theory, collect more money than the game had spawned into the world, opening up new avenues for world record runs. But the glitch was not fully understood, and was difficult to reliably repeat. All the community knew was that sometimes, if you pushed money into a pile, it would duplicate. Other times, it didn’t work.
The mantra in the community, according to Spelunky scientist ContraMuffin, was “pile money together and then hope for the best.” At the time, the use of duping was controversial.
“It was kind of a taboo subject to talk about duping at the time, too,” said Spelunky player d_tea. “Since it could be a big advantage that we knew nothing about how it worked.”
Everything changed earlier this fall, when ContraMuffin and others began debating the duping question. Few things that happen in video games are truly random, it’s just a matter of understanding how it works. Most developers aren’t keen on helping people exploit glitches in code, so it falls upon the community to poke and prod until rules are established.
Another community member, Spef, noticed something weird: if you deployed a rope, a tool to quickly climb around the game’s environment, the glitch disappeared—no duplications. This suggested there were specific actions the player could take to influence the overall outcome.
That’s when the real testing began.
“We took the precaution of making sure our tests were consistent and replicable, even if we didn't understand the dupe yet,” said ContraMuffin. “We were all STEM-inclined so we took to the scientific method very well. We quickly realized with our repeat trials that the dupe was entirely consistent and completely replicable. So there was some pattern to the dupe, we just didn't know what it was.”
Some of the tests were recorded on video, and help illustrate a growing understanding.
This is a controlled environment, not one of Spelunky’s semi-randomized levels. A block, stacks of gold, and that’s it. No other items, no enemies. Nothing to interfere with testing.
(The video is slow on purpose; ContraMuffin was studying the game frame-by-frame.)
Within 24 hours, several things were known and they were able to repeat the glitch with regular success, even if the underlying rules remained fuzzy. The thinking at the time was the order you picked up items was the most important factor in pulling off an item duplication.
“We started calling that order ‘precedence,’” said ContraMuffin. “We originally thought that precedence was the rendering order of items, so we gave the entire phenomenon the name ‘render dupe.’”
So, what’s happening here? It’s a little wonky, but hang with me. When you pick up an item in Spelunky, it disappears. When you pick up a bunch of items at once, they all disappear. But what’s happening underneath the hood is important. When you pick up that item, the code marks it for deletion, but the item’s deletion is not instantaneous; that step actually occurs later in the same frame the game is rendering. That tiny gap creates an opportunity.
By touching the item, it’s been added to a list—a list of items the game plans to destroy. What the game intends is for players to touch an item, receive the appropriate reward, mark the item for deletion, and have it disappear from the game. All of this is supposed to appear as though it happens at once, even though, if you slowed things down, it’s not simultaneous.
By stacking items, the game gets confused on what it should be deleting.
Let’s say you’ve stacked four gems on top of one another. When you pick them up, they’re marked by the game’s code to be deleted. But the glitch causes only two gems to be deleted, while the others survive. Thus, two bonus gems!
Importantly, the glitch repeats upon itself. Those two “bonus” gems are now marked for deletion, but again, the glitch kicks in and only one is destroyed. Thus, another bonus gem. At this point, the game processes the final gem, marks it for deletion—and it’s finally gone.
The final math—4+2+1—means you’ve squeezed seven gems out of four gems.
A Community Reborn
While ContraMuffin and others were struggling with the implications, the community was already off to the races. With a better understanding of duplication, records were exploding. It was no longer a matter of getting a slightly higher score—records were being shattered over and over, as people found ways to better incorporate these revelations into their runs.
It substantially changed the approach of players, too. In the past, it largely didn’t matter where money fell; it only mattered that you picked it up. Now, location was hugely important because duplication required shoving money into a single pile. If a piece of money fell in a strange spot where it can’t be pushed around, that’s a problem. Each stage was a puzzle.
This explains why, in the video at the start of this article, the player is constantly pushing money into piles. What it doesn’t explain is why they were firing a shotgun into the void, and the shotgun is the reason I started looking into this in the first place.
To understand that, we need to go deeper. Way deeper. It’s about to get weird.
A Room Full of Noise
After a slew of testing, other key details emerged. The existence of a rope didn’t stop duplication, but merely reduced its value. Removing the rope helped ensure the duplication glitch was able to process every gem in a pile. Also, it wasn’t just ropes! The presence of certain other items also impacted duplication, while other items had no impact whatsoever. Two other Spelunky scientists, Dan and samcv, dubbed this unexpected and weird effect “noise.”
ContraMuffin and Spef, who discovered the rope oddity, conducted a series of noise tests, hoping to reduce the amount of noise, and increase the chance of duplication. The scientists discovered two kinds of noise: universal and local. Items with universal noise impact the duplication chances of the entire level. Remember the rope causing duplication rates to drop? It produces universal noise! (They even quantified it! Each tile of rope is one unit of noise, a fully deployed rope is seven units of noise.) Other objects producing universal noise can be destroyed, while others can be picked up, which, for whatever reason, removes the noise it produces.
Another new discovery shed some light. The game was regularly and consistently displaying certain objects on the screen in front of gems, and the objects the game was prioritizing also happened to be the objects they’d classified as noise. That didn’t seem like a coincidence.
“The concept that some items must be spawned before certain objects but after other objects seemed to me very similar to the concept of layers in digital art and photo editing,” said ContraMuffin, “so I called the concept ‘layers.’”
The scientists eventually managed to categorize how Spelunky thinks of layers, based on how Spelunky assigns noise to different items. The whole list can be found in this document.
It’s less important to understand each layer than the mere existence of layers.
In Photoshop, it’s possible to shift the layers of an image around at will. In Spelunky, the layers have been pre-determined by the programmer who structured the game’s code. But what if there was a way to change the game’s logic—and its layers—within the game itself?
That’s what brings us full circle, and allows us to explain the original mystery. The reason why a world record run in Spelunky involves endlessly firing a shotgun.
The City of Gold, a secret level full of money, is a treasure trove in Spelunky. There’s so much money in the City of Gold, which makes it crucial to maximize your time (and duplications) in the City of Gold. But it also has mummies running around who, when destroyed, leave mummy wraps. Mummy wraps introduce a ton of noise, and crucially, cannot be destroyed or picked up. Where there’s noise, there’s problems for the duplication glitch. The solution is—guess what—a shotgun.
Why? [deep breath]
A Tale of a Thousand Bullets
One night in October, ContraMuffin was tediously testing out killing mummies, and seeing what he could learn about the noise the mummy wraps were causing.
“I was testing mummy deaths with a shotgun,” he said. “I noticed something peculiar—if I fired at gems in the temple, the bullets flew in front. Using the exact same setup in mines [another level in Spelunky], if I fired at gems, the bullets went behind.”
What ContraMuffin had discovered was the ability to manipulate Spelunky’s code by spawning bullets into the world. Boom, boom, boom. By doing so, it was possible to swap the game’s visible layers, ala Photoshop. This technique was dubbed “insertion switching,” in which you’re swapping what items the game is visually prioritizing, and by extension, duplicating. It's about moving layers up and down.
“We could choose which items would get duped and which to act as noise,” he said.
It takes 1,000 object spawns to cause an insertion switch, and firing the shotgun makes new objects. (There’s a good Twitter thread explaining more of the technical details behind this.)
“1,000 spawns of anything works,” said ContraMuffin. “You could theoretically whip 1,000 times and that'd work. Of course, that's never been confirmed because people have better things to do than stand there and whip 1,000 times. But that's actually why shotguns are preferred—they spawn multiple bullets and multiple smoke plumes.”
“Basically, you want the gems to have duping priority over the mummy wrappings,” said d_tea, the Spelunky player whose run drew me in, “so when the bullets are in front of the cannon, anything that's spawned into the level is at the lowest priority, then once the bullets switch behind the cannon anything spawned is at the highest priority.”
That’s why the player was spamming the shotgun. It was to swap Spelunky’s layers, and prioritize items for duplication, ensuring maximum value. The mystery was solved.
The first score run for Spelunky—a grand total of $2,126,925—was set on February 2, 2013 by vardulon. The number went higher as the days, months, and eventually years rolled on, but at the kind of slow, methodical place reflecting players perfecting perfection. The scene has exploded in the last few months, and while Spelunky demigod Kinnijup has racked up most of the new records—they hit $5,534,700 last week—others sense blood in the water, and this part of the community has become as fierce and competitive as it’s ever been.
Between starting this story and finishing it, in fact, the world record changed from d_tea to Kinnijup, and it won’t be surprising to see if that record is also smashed.
At moments like this, most headlines focus on the high-level players. This is natural. They’re the ones pulling off the wild tricks that look so impressive, and remind us how mortal most of our skills are, even for games we consider ourselves good at. But it overlooks the process that actually lead to those players being able to pull off those feats. Not all game researchers are also high-level players, often leaving them uncredited.
What folks like d_tea and Kinnijup are doing is cool, but it’s not possible without the hard, tedious efforts of ContraMuffin, Spef, and countless others in these communities.
All this reminded me of 2016’s famous “half A press” revelation for Super Mario 64, when lots of people (myself included) had their brains broken after the intricacies of high-level play were explained in layman's terms. Honestly, when I think back to that video, I still get woozy. But part of the reason people flipped out over the notion of “half A presses” is because they weren’t aware how much academic work has been done to understand our favorite games. Super Mario 64 remains unsolved.
It’s natural to focus on The Next Big Game—it’s exciting and new! But games are strange beasts, ideas held together by duct tape. After the credits roll, they still have so much to teach us, and it’s when people, like Spelunky’s scientists, get to work. After games are released, our understanding of what makes them interesting and special is only beginning.
Follow Patrick on Twitter. If you have a tip or a story idea, drop him an email: firstname.lastname@example.org.