# Gormiti: The Lords of Nature! (Wii) decompilation A matching decompilation of *Gormiti: The Lords of Nature!* for the Wii (Climax, 2010). The aim is C and C++ source that the original Metrowerks CodeWarrior compiler, run with the original flags, turns into object code identical to the shipped game, function by function. The source also has to be readable, in a form a programmer on the original team could have written. - **Progress:** [docs/progress.md](docs/progress.md), regenerated from the build at every merge, with each function's status. - **Exceptions and rulings:** [docs/exceptions.md](docs/exceptions.md). - **Working guide (for people and AI agents):** [AGENTS.md](AGENTS.md). ## How it works The game survives as three ELF builds (Final, Release and Debug) with full DWARF 2 debug information and their CodeWarrior link maps. These files name every function, compile unit, type, member and local, and they record source line order, so the reconstruction starts from the original's structure. - [decomp-toolkit](https://github.com/encounter/decomp-toolkit) splits the Final build into one object per original translation unit (`config/GORMITI/symbols.txt`, `splits.txt`). - Each unit is either compiled from `src/` (`Matching` in `configure.py`) or taken from the split assembly. Every build therefore links a complete game. - **The byte gate.** The linked DOL must hash to `1ee4a081a067879913c917b865980a2500067eb8`, the DOL derived from the Final ELF. A function counts as matched only when the whole binary, linked with that function compiled from source, still hashes to the target. - **Honesty rules.** Identical bytes are not enough: a rule checker rejects fake code (dummy locals, `volatile` carriers, offset casts, assembly bodies, padded vtables). [docs/progress.md](docs/progress.md) leads with the count of functions *matched under the rules* and gives the plain byte count beside it. - [objdiff](https://github.com/encounter/objdiff) scores every function against the target. The project's own tools (`tools/c/`, written in C) cover the inner loop: briefing, matching, classifying walls, checking rules and gating. What the binary contains: the Climax engine and game code, RenderWare Graphics 3.7, FMOD Ex and the FMOD Event system, Bullet Physics 2.74, zlib 1.2.3, Mobiclip, and Nintendo's RVL SDK, HBM and BTE with the Metrowerks MSL, runtime and MetroTRK. The vendor libraries are furthest along; most of the game code is still open. ## Repository layout | path | contents | |---|---| | `src/`, `include/` | reconstructed source and headers, at the paths the game's DWARF gives (relative to the original `Z:\Gormiti\Code\Main\`) | | `config/GORMITI/` | decomp-toolkit configuration, the hash contract (`build.sha1`), the score baseline | | `configure.py` | the unit table: which units link from source, and the flags for each (read by `build/tools/configure.exe`, not by Python) | | `tools/c/` | the project's tools, in C, built with CMake ([docs/tools.md](docs/tools.md) lists every command) | | `.claude/skills/` | the workflow skills AGENTS.md uses (`decomp-code-rules`, `matcher`, `wall-identifier`, `helper-recovery`, `permute`, `orchestrator`) | | `docs/` | setup, toolchain and compiler profiles, tools, progress, exceptions, porting notes | | `orig/` | where your own copies of the game files go (only [orig/INVENTORY.md](orig/INVENTORY.md) is tracked) | **Not in this repository:** game files (ELFs, DOL, link maps, disc images), the CodeWarrior compilers and other downloaded binaries. The setup step below fetches the tools. You must supply the game files. ## Getting started Requirements: Windows 10 or 11, Git, CMake 3.25 or later on `PATH` (or `SHSM_CMAKE` set to `cmake.exe`), Visual Studio 2022 with the "Desktop development with C++" workload, and about 3 GB of free disk space (a full build with its indexes, plus the gate's private rebuild). The tools and build run on Windows only for now. 1. **Clone** the repository. 2. **Add the game files.** Put `GormitiFinal.elf`, `GormitiRelease.elf` and `GormitiDebug.elf` in `orig/GORMITI/`, and `GormitiFinal.MAP`, `GormitiRelease.MAP` and `GormitiDebug.MAP` in `orig/GORMITI/MAP/`. Sizes and SHA-1 hashes are in [orig/INVENTORY.md](orig/INVENTORY.md). The project does not provide these files. 3. **Set up** (from a Command Prompt or PowerShell in the repository root): ``` tools\bootstrap.cmd ``` This runs three steps, which you can also run one at a time: - `tools\build_c.cmd` builds the C tools into `build/tools/`. - `build\tools\doctor.exe --fix toolchain orig` installs the toolchain and checks the game files. - It downloads the pinned decomp-toolkit, objdiff-cli, ninja, sjiswrap and binutils into `tools/bin/`, and the CodeWarrior compilers (the decomp.dev compiler set) into `tools/compilers/`. - It checks every downloaded file against its pinned hash and refuses any that differs. - It checks the game files against the inventory, then derives the target `orig/GORMITI/sys/main.dol`. - `build\tools\configure.exe` writes `build.ninja`. It is safe to rerun: anything already in place with the right hash is kept. 4. **Build the game:** ``` tools/bin/ninja.exe ``` The first build splits the ELF, compiles every unit and writes the objdiff report. 5. **Run the gate:** ``` build/tools/gate.exe ``` It rebuilds from scratch in `build/gate/tree` and ends with `GATE OK 1ee4a081… units=… functions=…`. `build/tools/doctor.exe` checks the environment at any time: pins, compilers, game files, hash contract, generated files and optional components. Each line names the fix for anything it finds missing. ## Working on a function Run everything from the repository root. Each tool prints its options with `--help`. ``` build/tools/pick.exe close # what to work on next build/tools/brief.exe # one-page briefing: identity, status, twins, context, listing build/tools/match.exe main/ # compile the unit with its flags, score, show the diff build/tools/wall.exe main/ # classify why a function does not match build/tools/check_rules.exe --units main/ # the honesty rules build/tools/gate.exe # before every commit ``` Units are named `main/`, for example `main/libs/ZLib/src/adler32`. When a unit is complete and passes the rules, flip it to `Matching` in `configure.py` and gate. [AGENTS.md](AGENTS.md) covers the workflow, the reference sources and their order of trust, the code rules and the rulings made so far. ## Working with AI agents The project is set up for agent-driven work: - **[AGENTS.md](AGENTS.md)** is the agent guide. It covers the goal, the gate, the rules, the reference sources and which model to use for what. Claude Code, Codex and other agents that read `AGENTS.md` pick it up from the repository root. - **`.claude/skills/`** holds the workflow skills: `matcher` reconstructs, `wall-identifier` diagnoses, `helper-recovery` restores inline helpers, `permute` runs bounded permuter searches, `orchestrator` runs parallel lanes, and `decomp-code-rules` is the rule catalogue. Claude Code loads them automatically. Other agents can be pointed at each `SKILL.md`. - **Parallel lanes.** `build/tools/slot.exe new --branch ` creates a worktree beside the checkout (`-wt/slotN`). The worktree links to the checkout's tools, compilers and game files, so nothing is copied twice. `build/tools/merge_lane.exe` rebases a lane, gates it, checks it for regressions and merges it. Remove slots with `slot.exe remove`, never with `git worktree remove` (AGENTS.md, "Repository hygiene"). ## Working from several machines Everything machine-specific is either ignored by Git or rebuilt on demand, so a second machine needs only the setup steps above: - Tools, compilers and game files are never committed. The setup step restores the tools from their pinned releases; copy the game files over yourself. - `build/` (objects, the split assembly, the indexes under `build/index/`, the score history) is derived. Tools that need an index rebuild it when it is missing or stale. - The shared state lives in the repository: `configure.py`, `config/GORMITI/`, the source, the baseline report, [docs/progress.md](docs/progress.md) and [docs/exceptions.md](docs/exceptions.md). Pull before you start, and gate before you push. - No paths are fixed. These environment variables cover what differs between machines: | variable | effect | |---|---| | `SHSM_CMAKE` | full path to `cmake.exe` when CMake is not on `PATH` | | `SHSM_WT_BASE` | where `slot.exe` puts lane worktrees (default: `-wt` beside the checkout) | | `SHSM_CACHE_DIR` | location of the shared compile cache (`configure.exe --objcache`) | | `SHSM_DOWNLOAD_TOOL_MIRROR` | fetch the pinned tools from a local or internal mirror instead of their release URLs | (The `SHSM_` prefix comes from the sibling project the tools were ported from.) There is no public CI, because the build needs game files that cannot be distributed. The gate on your own machine is the check, and a change is ready when `build/tools/gate.exe` prints `GATE OK`. ## Contributing Fork the repository, work on a branch, and open a pull request against `main`. Before you open it: - `build/tools/gate.exe` passes from a clean tree. - `build/tools/check_rules.exe --units main/` reports no `[match]` finding in the units you flipped, or the exception is recorded in [docs/exceptions.md](docs/exceptions.md). - Source you based on another public project names it in a `// Reference:` header comment. - No game files, compilers, decompiler output or vendor source without a licence. ## Acknowledgements [decomp-toolkit](https://github.com/encounter/decomp-toolkit), [objdiff](https://github.com/encounter/objdiff), [dtk-template](https://github.com/encounter/dtk-template), [decomp-permuter](https://github.com/simonlindholm/decomp-permuter) and [decomp.dev](https://decomp.dev); the public Wii and GameCube decompilations used as references, among them [zeldaret/tp](https://github.com/zeldaret/tp), [ogws](https://github.com/doldecomp/ogws) and [Petari](https://github.com/SMGCommunity/Petari); and the Silent Hill: Shattered Memories decompilation, which shares this game's engine family, middleware builds and tooling. ## Licence The project's own work (reconstructed source, headers, configuration, tools, skills and documentation) is released under [CC0 1.0](LICENSE), except where a file states otherwise. Files that carry their own licence header keep it: the Broadcom BTE stack (Apache 2.0), Bullet Physics and zlib (zlib licence), and the third-party code in `tools/c/third_party/` (SQLite, Capstone, PCRE2, zlib-ng, each with its own licence file). This project is not affiliated with or endorsed by the game's publisher, developer or rights holders, or by Nintendo. It contains no game data. *Gormiti* is a trademark of its owner.