The enhancement patch system lets you bundle any set of source-code changes into a portableDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/n64decomp/sm64/llms.txt
Use this file to discover all available pages before exploring further.
.patch file in git diff format. Anyone with the decompilation can apply your patch in seconds using tools/apply_patch.sh, and revert it just as easily. This page walks through the complete workflow, from making your first change to submitting a pull request.
Prerequisites
- A working SM64 decompilation setup with the
masterbranch checked out gitavailable on yourPATHclang-formatinstalled (required before submitting patches)- Basic familiarity with C and the SM64 source layout
Workflow overview
Start from the master branch
Always begin from a clean
master branch. Enhancement patches are generated as diffs against master, so starting from any other commit will produce patches that cannot be applied cleanly by others.Make your changes
Edit, add, or delete source files however you like. You can touch as many files as necessary, but keeping each patch focused on a single feature makes it easier to apply, review, and revert.Do not run
git add or git commit. The create_patch.sh script handles staging internally and resets the index afterwards — committing beforehand will include your commit in the diff baseline rather than capturing your working-tree changes.Format your code
Before generating the patch, run
format.sh to apply clang-format to all modified C source files. This keeps the patch consistent with the rest of the codebase and avoids spurious whitespace-only hunks.format.sh uses the .clang-format configuration file at the repository root, so the style is applied consistently without any extra flags.Generate the patch file
Run Internally, the script runs:It stages every untracked and modified file, captures the full diff, then resets the index — leaving your working tree unchanged.
tools/create_patch.sh with the desired output path. By convention, patches are stored in enhancements/ and named after the feature they add.The .patch file format
Patches use the standard unified diff format produced bygit diff -p. Each file change begins with a header like:
+ are additions and lines prefixed with - are removals. New files appear with --- /dev/null as the source path. The patch is applied with patch -p1, which strips the leading a/ and b/ path prefixes.
Because
create_patch.sh uses git add . before diffing, all untracked files in the repository will appear in the patch, not only the files you intentionally modified. Clean up any temporary or build artefacts before running the script.Applying and reverting
Once you have a.patch file, applying and reverting it use the same two scripts described on the Enhancements page:
[Y/N] confirmation before touching any files. Applying runs patch -p1 < patch_file and reverting runs patch -p1 -R < patch_file.
Best practices
Keep each patch focused on one feature
Keep each patch focused on one feature
A patch that does one thing is much easier for others to understand, apply selectively, and review for correctness. If you find yourself writing a patch that fixes a bug and adds a new feature, split it into two separate
.patch files.Do not patch generated files
Do not patch generated files
The build system generates files such as
build/*/assets/mario_anim_data.c, build/*/assets/demo_data.c, and the MIO0 compressed segments. These files are rebuilt from source every time make runs. Including them in a patch will cause conflicts on any machine where the build directory differs.Similarly, avoid patching binary files (textures, audio) unless the patch intentionally replaces an asset, and document that clearly.Use clang-format before every patch
Use clang-format before every patch
Run
./format.sh on all modified files before calling create_patch.sh. Patches that mix style changes with functional changes are harder to review and may conflict with future formatting cleanups in the main repository.Write descriptive file-level comments
Write descriptive file-level comments
Add a
@file Doxygen comment at the top of any new .c file you create. Existing files in the codebase follow this pattern, and it makes the purpose of your addition immediately clear to readers of the patch diff.Guard optional code with defines where appropriate
Guard optional code with defines where appropriate
If your patch adds behaviour that some users might want to disable, wrap it in a preprocessor define rather than requiring them to edit the source. Declare the define in
include/config.h alongside the existing BUGFIX_* and ENABLE_* defines.Contributing patches upstream
If your enhancement is generally useful, consider submitting it to the project repository as a pull request.Write a README entry
Add a section to
enhancements/README.md describing the patch: what it does, any setup required (scripts, emulator settings), and how to use any new functions it exposes. Follow the style of the existing entries.Test on multiple versions
Where possible, verify that the patch applies and builds cleanly against the
us, eu, jp, sh, and cn versions. Note any version restrictions in the README entry if the patch only makes sense for a subset.Open a pull request
Push your branch to a fork of
n64decomp/sm64 on GitHub and open a pull request. Include:- The
.patchfile inenhancements/ - Any companion files (
.jsscripts, binary assets) referenced by the patch - The
enhancements/README.mdupdate - A clear description of the feature and any emulator or hardware requirements