# Static recompilation Static recompilation takes a program compiled for one machine (e.g., a console game's ARM or MIPS code), translates its machine code into source code (usually C) with a tool, then compiles that source into a native program for another machine. The translation happens ONCE, ahead of time. Not while you play. That's what made the Switch 2 remake of Ocarina of Time playable natively on Windows within days of its release. ## Three ways to run a console game on PC 1. **Emulation**: a program pretends to be the console and translates every instruction and graphics call while the game runs. Works for (almost) every game, but you pay for it in performance 2. **Decompilation**: people rewrite the game as readable, human-written C, function by function, until it compiles to a byte-identical copy of the original. Then it can be ported anywhere. The best possible result, but it takes YEARS per game (e.g., Ship of Harkinian for the N64 Ocarina of Time) 3. **Static recompilation**: a tool translates the machine code automatically. The output is valid C, but nobody would call it readable. You get native speed in weeks, not years Think of it like this: emulation is a live interpreter, decompilation is a human translator rewriting the book, and static recompilation is a machine translation of the book, printed once, then fixed by hand where it's wrong. ## How it works Here's how Hookshot does it for the Switch 2 Ocarina of Time: 1. **CPU code**: a script reads every ARM64 instruction of the game executable and writes equivalent C. A regular C compiler then optimizes everything for x86 2. **The console's OS**: the game asks the Switch 2 system software for files, memory, threads, sound and controller input. A host layer answers those calls with Windows (or [[Linux]]) equivalents. The game thinks it's still on the console 3. **Graphics**: the game's calls to NVN2 (Nintendo's graphics API) are recorded and replayed on Vulkan 4. **Shaders**: the GPU shaders, compiled for the console's NVIDIA GPU, get converted to SPIR-V (Vulkan's shader format) by a shader recompiler borrowed from the Eden emulator Once the game is a regular PC program, adding DLSS, FSR, frame generation, ultrawide, or a mouse camera is ordinary PC graphics work. Emulators struggle with that. ## Why it works so well for some consoles - **No self-modifying code.** Static recompilation only works if all the code is known in advance. Console games are usually plain compiled executables without a JIT, so they're good candidates - **Years of emulator research.** The hard part (documenting the OS, the graphics API, the shader formats) was already done by emulator projects. Hookshot reuses parts of Eden, suyu, and Mesa - **Known CPU architectures.** ARM64 and MIPS are well documented, and the translation is mostly mechanical ## The hard parts - **Finding ALL the code.** Function pointers, virtual calls, and jump tables hide code from a naive scan. Miss one, and the program crashes when it gets there - **Each game has its quirks.** Hookshot needed game-specific fixes for Ocarina's fog, exposure, and foliage culling - **One build only.** The generated code is tied to exact addresses, so a game update means regenerating it. That's why Hookshot only accepts one specific version of the game - **Code mods die.** Mods that replace files still work; patches to the game's code don't, unless you rebuild - **Legal limits.** The output contains the game, so it can never be shared. Every player has to build it from their own dump ## It's a repeatable technique This is NOT a one-off hack. The translator, the OS layer, the graphics layer, and the shader pipeline carry over to the next game. Only the game-specific fixes have to be redone. A few examples: - **N64Recomp** (2024): Zelda: Majora's Mask, natively on PC - **XenonRecomp** (2025): Sonic Unleashed, recompiled from the Xbox 360 version - **Hookshot** and **NX2navi** (November 2026): Zelda: Ocarina of Time (Switch 2) - The Hookshot developer is also working on **BlueShell** (Mario Kart World) and **Skybound** (Tears of the Kingdom), with the same tooling Expect more of these. Each one still needs weeks of per-game debugging, but the expensive groundwork only has to be done once per console. ## References - N64Recomp: https://github.com/N64Recomp/N64Recomp - XenonRecomp: https://github.com/hedge-dev/XenonRecomp - Ship of Harkinian (decompilation, for comparison): https://github.com/HarbourMasters/Shipwright ## Related - [[Linux]]