
Super Mario 64 has been decompiled - dimillian
https://gbatemp.net/threads/super-mario-64-has-been-decompiled.542918/
======
lifthrasiir
It should be also noted that the inner working of Super Mario 64 is already
extremely well known due to numerous TAS attempts, so I found this manual
decompilation hardly surprising. A recent video [1] detailing the "one-key"
TAS [2] is mind-blowing.

[1]
[https://www.youtube.com/watch?v=wjge1bVobN0](https://www.youtube.com/watch?v=wjge1bVobN0)

[2] [http://tasvideos.org/3264M.html](http://tasvideos.org/3264M.html)

~~~
t0astbread
Also worth noting here is pannenkoek2012:
[https://www.youtube.com/user/pannenkoek2012](https://www.youtube.com/user/pannenkoek2012)
[https://www.youtube.com/user/pannenkeok2012](https://www.youtube.com/user/pannenkeok2012)

His explanations are mind-blowing as well and fun to watch :)

~~~
Jach
It's also worth pointing to Kaze's videos for what dedication can bring even
without the original source code. You'll find among other things recreations
of later Mario games, or even games like Portal (and mechanics!) implemented
in SM64.
[https://youtube.com/user/KazeBG0/videos](https://youtube.com/user/KazeBG0/videos)

His wiki:
[https://mario64hacks.fandom.com/wiki/Kaze_Emanuar](https://mario64hacks.fandom.com/wiki/Kaze_Emanuar)

~~~
Newtonip
Kaze Emanuar is part of the team that produced this decompilation.

------
noname120
Interestingly, there exists other projects that aim to rebuild exact original
ROM's. For example, Pokémon Ruby and Pokémon Emerald have been
disassembled[1][2] and then slowly converted to C making sure that the hash of
the ROM always stays the same.

[1] [https://github.com/pret/pokeruby](https://github.com/pret/pokeruby)

[2] [https://github.com/pret/pokeemerald](https://github.com/pret/pokeemerald)

~~~
aliswe
Shouldn't this be possible using some AI and/or brute force technique?

~~~
vages
Given infinite time and computing power, yes.

~~~
setr
s/and/or

You just need one :)

~~~
yellowapple
s/s\/and\/or/s\/and\/or\//

Can't forget that trailing slash :)

------
john_alan
Wow. They recreated the source from the IDA output instructions. Holy shit.

~~~
saagarjha
From IDA's decompiled source, presumably, with manual tweaks to make it
compile the same.

~~~
comex
No, they did it by hand.

~~~
Jasper_
The team also had somewhat of an automated decompiler but it's really just a
skeleton to get started from.

[https://github.com/matt-kempster/mips_to_c](https://github.com/matt-
kempster/mips_to_c)

~~~
giancarlostoro
The game modding community never ceases to amaze me. I know of a few
communities that are Reverse Engineering shockwave just to be able to retrieve
original game code, and in some cases create private servers for defunct
games.

Also theres a cool project archiving all Flash and Shockwave games called
BlueMaximas Flashpoint. The people working on preserving these old games are
amazing.

I do fear the death of some of those awesome NewGrounds games.

------
travbrack
Anyone know how much manual work was needed to do this? Did they just use a
tool to generate the C code? The functions unhelpfully have names like
func_802507AC.

~~~
iforgotpassword
It's in the third post or so. Apparently Nintendo didn't turn on any compiler
optimizations so porting the mips assembly back to c and fiddling around a bit
until the original compiler produced identical instructions again was a
feasible thing to do.

~~~
simcop2387
That makes me wonder how much better we can make it perform by turning on
optimizations (and likely fixing undefined behavior in places). There's quite
a few locations in the game where the framerate and gameplay suffer.

~~~
flukus
It was one of the first games and easily outclassed by later releases so I'm
sure there are many optimizations that could be made.

I hope we get the same with Waverace one day, nothing since has matched the
feel of the wave physics in that one, it would be interesting to see what they
did.

~~~
whiddershins
One of the “first games”?

What on earth do you mean?

~~~
noir_lord
From context he likely means the first games for the platform.

I vaguely remember it was a launch title.

~~~
iamnotacrook
Some people need everything explained don't they? "What do you mean first
game? I distinctly remember playing tag at school and that preceded Wave Race
64 by at least 2 years. Please stop spreading FUD".

~~~
noir_lord
Perhaps but it is easy to forget that sometimes they simply either don't
understand or that English may not be their primary language.

I try to assume that such things are genuine questions unless facetiousness is
obvious.

Makes for a more pleasant place that way.

------
JeanAraujo
Best day in pannenkoek's life

~~~
Gene_Parmesan
His video on the Rolling Rocks 0.5 A press clear is one of the most
informative and entertaining technical videos I've ever watched.

I had never heard of the guy before watching that video, but I gleaned from
the comments that there was something about it turning into a meme, and
turning the guy off from making more commentated vidoes? If so, that's a real
shame, because I could watch content from him all day long.

------
edude03
This is cool but seems to be "just" the output from IDA with the functions
renamed in the output? If that's the case I'm wondering why we don't see this
sort of thing more often (other than the effort required of course)

~~~
colechristensen
>It's not an ordinary decompilation generated by IDA. They actually rewrote
all the functions from reading MIPS assembly and compiled it with the original
compiler, adjusting the code until it produced identical output to a vanilla
ROM.

Reverse engineering a reproducible build is quite a bit more than "just"
output.

~~~
elcomet
What more is needed?

~~~
colechristensen
A perfect decompiler would just do it, but writing the exact inverse of a
compilation tool chain would be... Difficult. You would have to have a
different decompiler for each version each tiny little difference.

These guys were capable of figuring out and naming what every function did and
then rewriting each of them over and over and over to get the original tool
chain to output bit for bit the exact same binary as they started with.

Something like taking x-rays of an unknown machine and being able to recreate
perfect pixel replicas of the engineering drawings or listening to a piece of
music and being able to exactly write out the score.

~~~
bluedino
Sounds like a job for a genetic algorithm or machine learning.

~~~
MereInterest
I'd recommend watching this CppCon talk [1] about compiler optioning. It isn't
just that recompilation is hard, or that it is difficult for humans to do. At
a fundamental level, the information is not there at all, because the compiler
can make very impressive optimizations. Machine learning can deal with weak
signals, but it can't deal with no signal.

[1]
[https://www.youtube.com/watch?v=nLv_INgaLq8](https://www.youtube.com/watch?v=nLv_INgaLq8)

------
devit
Surprising that an unoptimized build could be fast enough to not be noticed.

~~~
favorited
Their toolchain might not have been mature enough at that point for the
compiler to optimize reliably. Just means they had to optimize it manually.

~~~
Newtonip
The SDK used the compiler from the IDO 5.3 package which was provided by SGI
for developing in IRIX 5.3 (if you paid the extra for that option).

I think by then it would have already been pretty mature.

------
shmerl
Nintendo freak out in 3, 2, 1...

~~~
m-p-3
Well the code is out there now, and I'm sure many have a copy.

~~~
penagwin
It made it to r/datahoarders and I'm sure the eye will have a copy.

There's no way we're letting this slip. If anybody can't find a copy PM me and
I'll help you track one down.

~~~
joenot443
Alternatively, there's a mirror here at the moment.
[https://anonfile.com/D5rcz5u4n6/sm64_zip](https://anonfile.com/D5rcz5u4n6/sm64_zip)

I imagine it'll get taken down eventually, but I don't see a problem with
letting as many people get their eyes on it in the meantime.

~~~
penagwin
What I mean is that Nintendo is going to DMCA that link, but it's fine, we've
got other copies.

In situations like this I highly recommend anyone with a spare 15.2MB of disk
space to download this just to help preserve it.

------
sayusasugi
From some brief research, a developer reported they're only 60% of the way
there and the audio system hasn't been decompiled yet.

~~~
ekianjo
No, 60% is just about renaming the functions.

~~~
holmium
In this leak, there's still a fair bit of decomp work to be done on the audio
systems.

Otherwise, you are right: the majority of the work left is to document the
functions, to organize the code so that it's easy to mod and play around with,
and to provide high level documentation on the systems/how the decomp was
made. You wouldn't want anyone to think that all you have to do to decomp
something is to run a binary through IDA, right?

Plus, there are more released versions of SM64, and who knows what's in there?

------
slowhadoken
Every link that leads to this file is shady af haha smh

------
soup10
its cool and all, but i've seen this before with other games and what happens
is the people that want to do game development and people that want muck
around with old decompiled source code are two different camps of people so I
wouldn't expect much

~~~
darkpuma
The result is often a classic game running on a modern system without needing
to jump through hoops, which is a huge win to people who enjoy playing the
game in question.

OpenTTD, OpenRCT2, and OpenMW all come to mind, not to mention the many ports
of Id games.

~~~
ekianjo
OpenTTD and al are clean room implementation of the original engines, not
reverse-engineered ones. That's massively different legally speaking.

~~~
Danieru
They are reimplementations but sadly far from clean room. The ASM was often
referenced and even used side by side as the projects migrated to their own
code base.

