Introduction to Decompiled Super Mario 64 Modding

What is Decompiled Super Mario 64?

The term decompiled means to reverse the compiling process of taking sourcecode and turning it into binary instructions. In the case for Super Mario 64, the decompiled sourcecode is almost 100% matching for game code as a result of the developers not using any compiler optimizations.

The primary difference between the two methods of modding is how one would go about adding custom programming to the game. Typically, for binary hacking (editing the rom itself) one would have to write their custom programming in MIPS assembly. This has the disadvantages of:

  1. Being very unfriendly to newcomers
  2. Potentially becoming unoptimized quickly
However, in the sourcecode (decompiled) environment, most work is going to be done in C. This has the advantages of:
  1. Being very easy to read and follow through for newcomers and experienced programmers alike.
  2. Many low level things (such as deciding what registers are used to store data in) are simply abstracted from C and are done by the compiler for you.

Below you will find a single function both in C and optimized MIPS assembly (disassembled through radare2) respectively.

s32 save_file_get_total_star_count(s32 fileIndex, s32 minCourse, s32 maxCourse)

{

 s32 count = 0;

 for (i = 0; minCourse <= maxCourse; minCourse++)

  count += save_file_get_course_star_count(fileIndex, minCourse);

 return save_file_get_course_star_count(fileIndex, -1) + count;

}


;-- save_file_get_total_star_count:

0x80270524 27bdffd8 addiu sp, sp, -0x28

0x80270528 afb30020 sw s3, 0x20(sp)

0x8027052c afb2001c sw s2, 0x1c(sp)

0x80270530 afb10018 sw s1, 0x18(sp)

0x80270534 afb00014 sw s0, 0x14(sp)

0x80270538 00c5082a slt at, a2, a1

0x8027053c 00a08025 move s0, a1

0x80270540 00c09025 move s2, a2

0x80270544 00809825 move s3, a0

0x80270548 afbf0024 sw ra, 0x24(sp)

0x8027054c 14200008 bnez at, 0x80270570

0x80270550 00008825 move s1, zero

0x80270554 02602025 move a0, s3

0x80270558 0c09c11f jal sym.save_file_get_course_star_count

0x8027055c 02002825 move a1, s0

0x80270560 26100001 addiu s0, s0, 1

0x80270564 0250082a slt at, s2, s0

0x80270568 1020fffa beqz at, 0x80270554

0x8027056c 02228821 addu s1, s1, v0

0x80270570 02602025 move a0, s3

0x80270574 0c09c11f jal sym.save_file_get_course_star_count

0x80270578 2405ffff addiu a1, zero, -1

0x8027057c 8fbf0024 lw ra, 0x24(sp)

0x80270580 00511021 addu v0, v0, s1

0x80270584 8fb10018 lw s1, 0x18(sp)

0x80270588 8fb00014 lw s0, 0x14(sp)

0x8027058c 8fb2001c lw s2, 0x1c(sp)

0x80270590 8fb30020 lw s3, 0x20(sp)

0x80270594 03e00008 jr ra

0x80270598 27bd0028 addiu sp, sp, 0x28

Differences Compared to Binary Hacking

Aside from the programming differences mentioned in the section above, the primary differences is that everything is in plain text. Even levelscripts and geoscripts.

cd sm64_source

make -C tools

make