if you want to decomp my sweater —

Ocarina of Time has been fully decompiled into human-readable code

Unspooled C code could eventually lead to PC ports, new mods, and more.

Screenshot from video game shows sprite fascinated by a doodad.
Enlarge / Artist's conception of voders staring in awe at the raw C code that generates Ocarina of Time.

A team of volunteer coders has reportedly completed its nearly two-year-long quest to fully decompile a version of The Legend of Zelda: The Ocarina of Time, turning the executable ROM back into human-readable (and editable) C code.

"We thought for a time that we may never be able to match every function completely, so this is an incredibly exciting accomplishment," Zelda Reverse Engineering Team (ZRET) member Kenix wrote on the project's Discord server Sunday. "Dozens of people helped work on this project, and together we were able to achieve something amazing."

The final decompiled functions still need to be merged with the ZRET Github repository before the open source project is officially considered 100 percent complete, Kenix wrote. Once that submission is reviewed, though, the team should be able to run its tens of thousands of lines of C code through a compiler (alongside graphics and sound assets derived from a legitimate cartridge) to generate a bit-for-bit copy of the original Ocarina of Time ROM.

A progress graph shows the march toward 100 percent decompilation over the course of nearly two years.
Enlarge / A progress graph shows the march toward 100 percent decompilation over the course of nearly two years.

That full decompilation is the result of at least 21 months of work by a team of coders that walked me through the painstaking process last year. While automated software tools can help with that work, getting to human-readable C code means parsing each one of the game's more than 15,000 functions by hand, figuring out the purpose of each portion, and cleaning up the code to remove any obfuscation or logic errors introduced in the process.

Ports of call?

A similar decompilation project for Super Mario 64, completed in 2019, eventually led to multiple high-resolution PC ports of the game. Such ports will probably come from the Ocarina of Time decompilation as well.

But ZRET member Rozlette told Ars last year that the process of going from C code to a PC build is "not as easy as just [saying] 'compile it for Windows.' There is a lot of code that deals with talking to N64 hardware. The N64 render pipeline is very different than modern OpenGL, for example."

In any case, Kenix told Ars that such ports are "outside of the scope of what we do" at ZRET. Instead, the team told Ars it was interested in studying the code to understand more about the game's inner workings and creation. The decompiled code could also make it easier to create new gameplay mods and randomizers that could expand appreciation of the game even further.

A hidden room from a debug version of <em>Ocarina of Time</em> that helped unlock some reverse-engineering secrets to the game.
A hidden room from a debug version of Ocarina of Time that helped unlock some reverse-engineering secrets to the game.
"I do it because of my childhood love for the game," Rozlette told Ars last year about their decompilation work. "It feels like a big puzzle to me where each function is a piece. It's very rewarding to me when I work at an unknown function of code and then realize I recognize what this does in the game, like, 'Hey! This is the function that spawns rupees when you cut grass!'"

While the decompilation effort may have hit "100%," the team still has plenty of work to do, Kenix writes. "We have been working on decompiling the Master Quest Debug version of the game. However, Ocarina of Time has over a dozen other versions, which we plan to also decompile and support in the project."

The decompiled code also still needs additional documentation, reorganization, and variable renaming to make the underlying code easier for others to work with. And work continues on related decompilation projects for Majora's Mask and Minish Cap, which are respectively roughly 24 and 48 percent complete according to ZRET's public tracker.

Still, Sunday's announcement represents a major milestone for hobbyists working tirelessly to unravel and rebuild a game they love. Their success will hopefully serve as inspiration to those working to decompile other N64 games and other titles in a similar fashion.

Channel Ars Technica