• Welcome to Smashboards, the world's largest Super Smash Brothers community! Over 250,000 Smash Bros. fans from around the world have come to discuss these great games in over 19 million posts!

    You are currently viewing our boards as a visitor. Click here to sign up right now and start on your path in the Smash community!

Melee Decompiled into C

Fizzi

Smash Ace
Joined
Feb 14, 2008
Messages
802
Location
Brooklyn, NY
Slippi.gg
FIZZI#36
Disclaimer: I'm not 100% sure what I'm doing or if any of this makes sense but I figured I'd bring it up in case it sparked some ideas in people more experienced than me.

I'm not sure if anyone has attempted to do this before but I thought it would be an interesting experiment so I looked into trying to decompile melee. There's a few options for decompiling PowerPC instructions and I ended up finding one that looked easy to use and pretty recent, found here: https://retdec.com/ .

I converted the Start.dol file to a Start.elf and fed it into the website. The website ended up crapping out at some point so I put in a support request. The team that runs the site actually responded to me with the decompiled code which is the file I linked to at the bottom of this post.

I'm not completely sure what the possibilities could be with this file. Perhaps melee's code could be run in some fashion on a different CPU architecture? Perhaps it can be used by developers to aid in understanding complex parts of the code? (there are comments in the C code that refer back to the corresponding assembly instructions)

I'm looking to promote discussion with this post, even if that discussion is simply "this is completely useless".

Decompiled C File:
http://www.mediafire.com/download/7afxvm4rukuxgfw/DecompiledMelee1_02.zip

EDIT: It does look like the code might not be complete? This message can be found in multiple places where I think code was supposed to be: "// Detected a possible infinite recursion (goto support failed); quitting.."
 
Last edited:

zankyou

Smash Lord
Joined
Sep 12, 2014
Messages
1,055
Disclaimer: I'm not 100% sure what I'm doing or if any of this makes sense but I figured I'd bring it up in case it sparked some ideas in people more experienced than me.

I'm not sure if anyone has attempted to do this before but I thought it would be an interesting experiment so I looked into trying to decompile melee. There's a few options for decompiling PowerPC instructions and I ended up finding one that looked easy to use and pretty recent, found here: https://retdec.com/ .

I converted the Start.dol file to a Start.elf and fed it into the website. The website ended up crapping out at some point so I put in a support request. The team that runs the site actually responded to me with the decompiled code which is the file I linked to at the bottom of this post.

I'm not completely sure what the possibilities could be with this file. Perhaps melee's code could be run in some fashion on a different CPU architecture? Perhaps it can be used by developers to aid in understanding complex parts of the code? (there are comments in the C code that refer back to the corresponding assembly instructions)

I'm looking to promote discussion with this post, even if that discussion is simply "this is completely useless".

Decompiled C File:
http://www.mediafire.com/download/7afxvm4rukuxgfw/DecompiledMelee1_02.zip

EDIT: It does look like the code might not be complete? This message can be found in multiple places where I think code was supposed to be: "// Detected a possible infinite recursion (goto support failed); quitting.."
Now that I understand a bit more this looks like it could potentially be incredibly useful. Has anyone tried using this to understand some of the games logic.
 

V1talSigns

Smash Rookie
Joined
May 25, 2015
Messages
1
NNID
V1talSigns
This looks like a step in the right direction, keep trying.
 
Joined
Oct 10, 2011
Messages
1,126
Location
Boise, ID
NNID
dansalvato
Jeez. This will be pretty fun.

I'm going to start naming known functions and global variables, but it kind of takes a while to edit a 150MB file so I don't know how long it will take.
 

zankyou

Smash Lord
Joined
Sep 12, 2014
Messages
1,055
Jeez. This will be pretty fun.

I'm going to start naming known functions and global variables, but it kind of takes a while to edit a 150MB file so I don't know how long it will take.
Theres only about 20500 functions. shouldnt be too hard.
 
Joined
Oct 10, 2011
Messages
1,126
Location
Boise, ID
NNID
dansalvato
Well, I renamed all of the functions that Dolphin automatically generates in its symbol map. I found some cool stuff, but there are also a number of inaccuracies that alarm me. For instance, the number and type of function parameters and local variables frequently appear to be off, which is some of the most important data that could be retrieved. I'm not too sure how useful this will be in the end.
 

zankyou

Smash Lord
Joined
Sep 12, 2014
Messages
1,055
Well, I renamed all of the functions that Dolphin automatically generates in its symbol map. I found some cool stuff, but there are also a number of inaccuracies that alarm me. For instance, the number and type of function parameters and local variables frequently appear to be off, which is some of the most important data that could be retrieved. I'm not too sure how useful this will be in the end.
You wanna put this on the google doc. I dug up this thread because I wanna help out with this stuff. I mainly focus on the file format though.
 

Fizzi

Smash Ace
Joined
Feb 14, 2008
Messages
802
Location
Brooklyn, NY
Slippi.gg
FIZZI#36
Dan Salvato Dan Salvato The team behind the decompiler was actually rather responsive to my support request and seems interested in improving their product. I can forward you the support e-mail in case you're interested in talking to them. It might be possible that with some guidance they can produce a more accurate decompilation.

What e-mail can I send to?
 

Fizzi

Smash Ace
Joined
Feb 14, 2008
Messages
802
Location
Brooklyn, NY
Slippi.gg
FIZZI#36
I'll just post the e-mail here. I certainly think they would appreciate us pointing out what we think are mistakes. If they could help us work towards an accurate decompilation I think it could be rather beneficial to us going forward.

Dear user of our decompiler,

> This might be crazy but the file I fed in is Super Smash Bros Melee for the
> Nintendo Gamecube's Start.elf file.
>
> I have no idea if I would get anything meaningful out of attempting to
> decompile Melee's code but I was hoping to maybe get a file that would help me
> understand the game's code a little better.
>
> In any case, I got an out of memory error, wonder if anything can be done to
> complete the decompilation?

Thank you for a feedback. Your file is a little bit larger and it took us few more minutes to decompile. Furthermore, we had to disable some optimizations, which produced larger code. Anyway, the results are available here:

https://retdec.com/data/apRv58oOD8.zip

Good luck with your project. Feel free to contact us if you have any other suggestions or questions.

Best regards,
The retdec.com team
 
Last edited:
Joined
Oct 10, 2011
Messages
1,126
Location
Boise, ID
NNID
dansalvato
I don't know if there's much feedback I can provide because I don't really know what's expected of decompilers regarding their performance and output. There's probably not much that can be done unless a lot more manual work was put into it, such as providing the standard dev libraries used in the game and better understanding game functions based on how they interact with the standard libraries. In other words, blindly putting it through a decompiler probably won't give very meaningful results no matter how good the decompiler is.
 

c/c++

Smash Rookie
Joined
Apr 23, 2016
Messages
12
Well, I renamed all of the functions that Dolphin automatically generates in its symbol map. I found some cool stuff, but there are also a number of inaccuracies that alarm me. For instance, the number and type of function parameters and local variables frequently appear to be off, which is some of the most important data that could be retrieved. I'm not too sure how useful this will be in the end.
I'd be interested in browsing through this if you still have it....
Keep up the badass work Dan!
 

Absolome

Smash Cadet
Joined
Jan 3, 2014
Messages
68
Location
Asheville, NC
So did this project end up being worth anything or is it really just too messy of a decompilation process to work?
 

SinsOfApathy

Smash Journeyman
Joined
Feb 24, 2015
Messages
474
NNID
Psion312
So did this project end up being worth anything or is it really just too messy of a decompilation process to work?
It's generally completely unwieldy for actually working with, because optimizations and such were turned off. Especially since registers get decompiled as local variables.

For example, the function that returns a character pointer for the slot provided in r3 would be more like 4 lines of code, instead of the 32 vars, 5 globals, etc.. that is returned by the decompiler. Honestly kinda sad, considering I have tons of x86-64 decompilers that return sane code.
 

dandeto

Smash Apprentice
Joined
Feb 19, 2015
Messages
108
Location
Medieval castle
I'm not sure if anyone has attempted to do this before but I thought it would be an interesting experiment so I looked into trying to decompile melee. There's a few options for decompiling PowerPC instructions and I ended up finding one that looked easy to use and pretty recent, found here: https://retdec.com/ .

I converted the Start.dol file to a Start.elf and fed it into the website. The website ended up crapping out at some point so I put in a support request. The team that runs the site actually responded to me with the decompiled code which is the file I linked to at the bottom of this post.

I'm not completely sure what the possibilities could be with this file. Perhaps melee's code could be run in some fashion on a different CPU architecture? Perhaps it can be used by developers to aid in understanding complex parts of the code? (there are comments in the C code that refer back to the corresponding assembly instructions)

I'm looking to promote discussion with this post, even if that discussion is simply "this is completely useless".

Decompiled C File:
http://www.mediafire.com/download/7afxvm4rukuxgfw/DecompiledMelee1_02.zip

EDIT: It does look like the code might not be complete? This message can be found in multiple places where I think code was supposed to be: "// Detected a possible infinite recursion (goto support failed); quitting.."
Hah! I used this decompiler a few months ago.

Fizzi Fizzi Could you PLEASE put the .elf file up for download on media fire? I have a decompiler called "IDA pro" that I would like to use on this file. You said they dropped optimization settings, but my decompiler is content to run for hours on end. It also has a very neat and organized system for writing notes, so I would like to use some of my + Dan's notes to compare the hex with C to see if I can get legit C code. Likely not for the reasons specified above, but I think it would be fun anyway.
 
Last edited:

SinsOfApathy

Smash Journeyman
Joined
Feb 24, 2015
Messages
474
NNID
Psion312
Hah! I used this decompiler a few months ago.

Fizzi Fizzi Could you PLEASE put the .elf file up for download on media fire? I have a decompiler called "IDA pro" that I would like to use on this file. You said they dropped optimization settings, but my decompiler is content to run for hours on end. It also has a very neat and organized system for writing notes, so I would like to use some of my + Dan's notes to compare the hex with C to see if I can get legit C code. Likely not for the reasons specified above, but I think it would be fun anyway.
devkitPro's LibGC supports conversion to ELF and BIN files, and you can load DOL's natively in IDA as a binary file set to PPC assembly. Or you can grab one of the DOL plugins, like delroth's. http://blog.delroth.net/2012/03/gcwii-dol-plugin-built-for-ida-6-1/

IDA also cannot convert PPC x86 ASM with it's Hex-Rays decompiler.

You'd literally be better off hand coding Melee functions in C, because of how the pointer schemes work (and this Decompiled C code is outright garbage without the optimizations turned on, frankly.)
 
Last edited:

dandeto

Smash Apprentice
Joined
Feb 19, 2015
Messages
108
Location
Medieval castle
devkitPro's LibGC supports conversion to ELF and BIN files, and you can load DOL's natively in IDA as a binary file set to PPC assembly. Or you can grab one of the DOL plugins, like delroth's. http://blog.delroth.net/2012/03/gcwii-dol-plugin-built-for-ida-6-1/

IDA also cannot convert PPC x86 ASM with it's Hex-Rays decompiler.

You'd literally be better off hand coding Melee functions in C, because of how the pointer schemes work (and this Decompiled C code is outright garbage without the optimizations turned on, frankly.)
So I can load the DOL, but the ASM is crud? Thanks for all of the info!
 

SinsOfApathy

Smash Journeyman
Joined
Feb 24, 2015
Messages
474
NNID
Psion312
So I can load the DOL, but the ASM is crud? Thanks for all of the info!
All I use is IDA for static debugging of the game, the ASM comes out fine in IDA there's only 1 instruction that it mixes up. I find Dolphin's debugger insufferable most of the time.

What I meant by the Decompiler was that you can't press F5 on a function and get C code, like you can with typical Windows executables.
 
Last edited:
Top Bottom