From Luma's Workshop
Jump to navigation Jump to search
This page is in progress and may contain incomplete information or editor's notes.


Decompiling is the process of taking assembly code and turning it back into a higher level language such as C or C++. It is essentially the reverse of compiling. Matching decompilation is the process of decompiling, but having the compiled code match the original assembly 1:1. While matching decompilation is harder than normal decompiling, it can become easier when you understand the patterns of the compiler used. This page aims to let new people understand how this process works, and hopefully be able to get new people into decompilation! While you do not need to be an expert at C or C++ to decompile, it is recommended that you have some experience before attempting decompilation. It is also very recommended that you have some prior knowledge of PowerPC assembly, as that is the key to understanding how a function works. This document is a good way to learn or refresh knowledge of the PowerPC architecture. This document is also good to learn some of the patterns that CodeWarrior does.

Getting Set Up

To begin decompiling Super Mario Galaxy, you first need to set up the environment. You will need the following tools:

After you have acquired all of these, setting up Petari is very simple.

  1. With a new command prompt open, type in git clone This will clone the repository into a directory called "Petari".
  2. In this new "Petari" folder, place the SMG1 Korean main.dol into this folder, and rename it to baserom.dol.
  3. Open a new command prompt in the "Petari" folder.
  4. Run the command python This will verify your DOL and install all of the libraries used, and the compilers we use to compile the code.
  5. Run the command python This will build the entire project. If you see any warnings, do not worry about them.


To properly utilize and use Petari, it is necessary to understand the structure of the environment. Petari is structured in a way that makes it easy to access and use.

Folder Name Description
archive The folder that gets created when -link is ran. Contains an archive of the object files in each library.
build The folder that gets created when is ran. Contains the compiled object files.
csv Contains CSV files that store the status of functions being matched.
data Contains map files and the percentage badges for the GitHub repo.
docs The folder that gets created when is ran. Contains all of the Markdown documentation for matching status.
include Contains all of the header files for Super Mario Galaxy specific code.
libs Contains this folder structure but for different libraries used by the game.
scripts Various scripts used in IDA for generating headers.
source Contains all of the source files for Super Mario Galaxy specific code.


Super Mario Galaxy uses a lot of libraries for certain functionality such as heaps, layouts, OS specific code, and more. Each library described in the table below are statically linked to the game, so every library's used code is inside of the main.dol.

Non-SMG Libraries

Name Language Description
JSystem C++ Contains classes for backend things, such as heaps and linked lists.
MetroTRK C Target Resident Kernel, for debugging.
MSL_C C & C++ Contains standard library functions and types.
nw4r C++ Contains classes for sounds, layouts, and more. (SMG only uses the layouts and some math functions)
Runtime C & C++ Contains functions that relate to CodeWarrior's runtime code generation (ctor / dtor lists, etc)
RVL_SDK C Contains functions that relate to the Wii's "OS".
RVLFaceLib C Contains functions that relate to Miis.

SMG Libraries

All of Super Mario Galaxy's libraries are written in C++.

Header text Header text
Animation Library for animation playing.
AreaObj Library for invisible areas that can be accessed by players in the game.
AudioLib N/A
Boss Library for all of the bosses and mini-bosses in the game.
Camera Library for all camera types.
Demo Library for all cutscenes.
Effect Library for all effect rendering.
Enemy Library for all enemies.
GameAudio N/A
Gravity Library for all of the gravity types in the game.
LiveActor Library for LiveActor, which is an actor that can switch states.
Map Library for map classes that do not directly interact with the player. (ie switches)
MapObj Library for all of the map objects in the game.
NameObj Library for the most basic form of an object in the game.
NPC Library for all of the non-playable characters.
NWC24 Library for the mail system in the game.
Player Library for all of the player related functions.
RhythmLib N/A
Ride Library for all of the actors that can be controlled by the player.
Scene Library for all of the game scene related code.
Screen Library for all of the layouts in the game.
Speaker Library for the sound effect playing done on the Wiimote.
System Library for a lot of the game's backend systems.
Util Library for utility functions and classes.