Decompilation of Paper Mario - Mirror of https://github.com/pmret/papermario
Go to file
2020-08-19 12:55:02 +01:00
.github/workflows ci: require matched asm files are deleted 2020-08-19 01:53:24 +01:00
.vscode add vscode editor settings and build tasks 2020-08-15 17:27:08 +01:00
asm Merge branch 'master' into coverage 2020-08-19 02:00:00 +01:00
include match functions which use floats 2020-08-18 10:28:13 +01:00
src add NON_MATCHING 2020-08-19 02:45:26 +01:00
tools move coverage.py to root directory 2020-08-19 12:55:02 +01:00
.clang-format Refactoring stuff 2020-08-12 21:56:23 -04:00
.clang-tidy Refactoring stuff 2020-08-12 21:56:23 -04:00
.editorconfig add editorconfig 2020-08-15 17:27:08 +01:00
.gitattributes tell github *.h files are written in C 2020-08-17 13:45:46 +01:00
.gitignore add vscode editor settings and build tasks 2020-08-15 17:27:08 +01:00
.gitmodules generate common_structs.h from star rod database 2020-08-14 21:10:34 +01:00
checksum.sha1 Refactoring stuff 2020-08-12 21:56:23 -04:00
coverage.py move coverage.py to root directory 2020-08-19 12:55:02 +01:00
diff_settings.py meow 2020-08-12 22:56:47 -04:00
diff.py Refactoring stuff 2020-08-12 21:56:23 -04:00
docker-compose.yml gud changes 2020-04-24 00:26:17 -04:00
docker-sync.yml gud changes 2020-04-24 00:26:17 -04:00
Dockerfile Update Dockerfile 2020-05-12 00:45:15 -04:00
format.sh Refactoring stuff 2020-08-12 21:56:23 -04:00
install.sh add dependency: lib32-glibc 2020-08-18 09:41:36 +01:00
Jenkinsfile Jenkins test 3 2020-08-15 00:20:15 -04:00
Makefile support make -B flag 2020-08-15 03:52:44 +01:00
papermario.ld actually fix assembler bug, make sure it compiles. 2020-08-14 22:24:08 -04:00
README.md move coverage.py to root directory 2020-08-19 12:55:02 +01:00
undefined_syms.txt add misc global vars from SR database 2020-08-17 13:40:21 +01:00

Paper Mario

This is a WIP decompilation of Paper Mario (USA). It builds the following ROM:

  • papermario.z64 md5: a722f8161ff489943191330bf8416496

Discord: Paper Mario Modding

Setup

You'll need Linux, a Linux VM, or Windows 10 (WSL) to work on this project.

Clone the repository

$ git clone https://github.com/ethteck/papermario.git
$ cd papermario

Install build dependencies

$ ./install.sh

Our install script does not yet support distros other than Ubuntu, Arch, and their derivatives. Please consider contributing to the script if you use another distro!

Base ROM

You'll need a Paper Mario (USA) ROM to work on this project. Copy it into the root directory of the repository with the name baserom.z64.

Install tools and extract ROM

$ make setup

Compile the game

$ make

If you get OK, you're all set! Otherwise, please feel free to reach out to us in our Discord channel.

Contributing

Dependencies

There are a few additional dependencies needed when contributing to this project. You can install them with ./install.sh --extra.

Rebuilding

Setting the PM_HEADER_REBUILD environment variable will cause make to rebuild all .c files whenever a .h file is modified.

$ PM_HEADER_REBUILD=1 make

If you use Visual Studio Code, you can use Run Build Task (Ctrl+Shift+B) to run make. Any errors or warnings generated by the compiler will show up in the Problems tab.

Matching a function

Setup

Once you've created a successful (OK) build, copy build/ to expected/build/:

$ mkdir -p expected
$ cp -r build expected

Roughly converting assembly to C

Decide on a function to match. These can be found in the subdirectories of asm/nonmatchings/. Currently, functions which use float constants, data sections, or jump tables are unmatchable.

Take the relevant .s file and pass it to mips_to_c (web version).

If mips_to_c gives you an error about branch-likely instructions, edit the .s file and rename any branch-likely instructions to their unlikely equivalent (i.e. remove the l suffix). Add a nop after the branches and move the instruction that was originally in the delay slot (directly after the branch instruction) to the start of the target label. Don't commit the edited assembly.

Open up the relevant .c file and replace the function's INCLUDE_ASM macro with the output from mips_to_c. Run the following command to attempt to compile, replacing function_name with the name of the function you're working with:

./diff.py -mwo function_name

Fix any errors and rerun diff.py. This will involve typing the function signature correctly, which you will probably find in Star Rod's library database. See also common_structs.h.

Once a successful build is made, diff.py will show you the difference between the original game's assembly (on the left) and what your C code generated (on the right).

Matching the function

You're on your own now. Get your C code compiling to match the original assembly! diff.py, when running, will automatically recompile your code whenever you save the .c file.

If you use Visual Studio Code, you can use Run Test Task to run diff.py and show you errors and warnings from the compiler inline. You might want to attach Run Test Task to a keybinding, as you'll be using it often.

Once you've matched a function, delete its assembly file. Run ./coverage.py --delete-matched to do this automatically.

FAQ

  • If you received the following error when running make:
sha1sum -c checksum.sha1
sha1sum: 'papermario.z64'$'\r': No such file or directory
: FAILED open or read
sha1sum: WARNING: 1 listed file could not be read
Makefile:118: recipe for target 'verify' failed
make: *** [verify] Error 1

💡 Solution

This is a Windows line ending issue run git checkout checksum.sha1 to fix it.