# SwitchWakerHD ## What it is SwitchWakerHD is an unofficial native port of a 2013 Wii U adventure game (title ID `00050000-10143500` USA or `00050000-10143600` Europe, version 0) to the Switch (homebrew). The game's PowerPC code is translated to C ahead of time by a static recompiler, the Cafe OS libraries the game uses are reimplemented natively, and its GX2 graphics are drawn with deko3d, the Switch's own GPU API. There is no CPU emulation and no GPU command emulation. It is a fork of [ZeldaWWHDRecomp](https://github.com/ZeldaWWHDRecomp/ZeldaWWHDRecomp), which runs the same recompilation on macOS, Linux, Windows and Android. Those platforms still build from this repository; their instructions are in the upstream README, kept as [docs/upstream-README.md](docs/upstream-README.md). How the recompilation works: [docs/how-it-works.md](docs/how-it-works.md). ## What you need - **Your own legally obtained copy of the game**: the USA version (title `00050000-10143500`) or the European one (title `00050000-10143600`, in its five languages), version 0 (the disc or eShop release without the update), dumped from your own Wii U. The runtime checks `code/cking.rpx` against those versions at startup. - **This repository contains no game code, assets, keys or data.** The NRO you build contains the game's code recompiled from your dump, and the shader caches are made from the game's shaders: they are for your own use only; do not share them. - **No release binaries are provided** for the Switch, precisely because they carry the recompiled game. ## Build for the Switch **The short way** (step-by-step guide for players: [INSTALL.md](INSTALL.md)): `python3 tools/switch/make_sd.py --image game.wux` (or `--wua game.wua`, or `--game-dir `) checks the game version, recompiles, builds the NRO and lays out `build/sd/switch/wwhd/` for the SD card. On Windows it builds with a native devkitPro, no Docker or WSL needed (INSTALL.md); elsewhere in Docker or Podman. The steps it runs, by hand: Requirements: Python 3 with `pycryptodome` (for the extractor), and Docker or Podman (the Switch toolchain runs in the `devkitpro/devkita64` image). On the Mac also the Xcode command line tools. ```sh git clone https://github.com/centollOS/SwitchWakerHD switchwakerhd && cd switchwakerhd # 1. extract your dump into game/ (game.wux with game.key next to it, plus your common key; # a Cemu .wua or an already extracted folder works too: docs/upstream-README.md) python3 tools/wudextract.py game.wux extract game # -> game/code, game/content, game/meta # 2. recompile the game code to C (build/gen/, stays on your machine) python3 tools/recomp/recomp.py game/code/cking.rpx build/gen # 3. build the NRO tools/switch/build.sh # -> build/switch-dk/wwhd.nro ``` `WWHD_JOBS=` limits parallel compiles (the generated code needs a lot of memory per file); `WWHD_DEKO3D_DEBUG_LIB=ON` links deko3d's debug library (`wwhd_dk_debug.nro`: every GPU call checked, readable errors). Details, architecture and the history of the port: [docs/switch-port.md](docs/switch-port.md); the renderer: [docs/deko3d-plan.md](docs/deko3d-plan.md). ### The shader cache The renderer compiles each game shader with uam the first time it is drawn (about 70 ms on the console, in a background thread; until then its draws are skipped, so on a first start some textures stay black for a while) and keeps the result in `shadercache_dksh_local.bin`, so a shader is compiled once per console. A `shadercache_dksh.bin` next to the NRO is loaded whole at start-up. **The first start** (docs/background-shaders-plan.md) prepares about three quarters of the game's shaders behind a loading screen, with no computer and nothing shipped: the title screen runs hidden and records its GPU states into `shader_manifest.bin`, the console reads its own game files' shader programs (`platform/shader_scan_switch.cpp`, upstream shaderprep's extractor in C++), speculates variants by family (`shader_list_switch.cpp`) and translates them the way a draw would (`gfx/deko translate_listed`); the worker compiles them at full speed behind the card (about 19 minutes on a stock console: 73.6% of a whole-game harvest's shader pairs), or gently in the background after B (core 0 only, a 50% duty cycle: the game keeps ~30 fps). **Prepare graphics** (settings menu, Switch tab; docs/prepare-graphics-plan.md) warps through every place for the rest; experimental. For developers, the console also writes `shader_manifest.bin` as it plays: for each shader variant, the program's hash and size, the GPU registers and the vertex fetch layout it was translated with (identifiers, no game code). `make_sd.py --shaders shader_manifest.bin` builds `shadercache_dksh.bin` from it on the computer: the programs come from the player's own dump (every shader archive, with upstream's `tools/shaderprep.py` extractor), `tools/switch/dksh_cache translate` runs the same Latte decompiler as the runtime (the result is byte-identical to the console's), and speculative variants (programs of the same family with the recorded states) cover places not visited yet. Details and measurements: [docs/shader-cache-from-dump-plan.md](docs/shader-cache-from-dump-plan.md). Neither file is ever shipped. ```sh tools/switch/dksh_cache/build.sh build build/shadercache_dksh.bin # a GLSL list, as before ``` ### Debug server (developers) For development there is a debug server: from the computer, over the local network, you can deploy a new build and restart the game without touching the console, follow the log as it is written, take screenshots, press buttons and warp. It is **off by default**: players never need it and the game opens no network port unless it is turned on in the options menu (**Switch** tab, **Debug** section, *Debug server (network)*; it starts at the next start). It has no password, so use it only on your own network. ```sh echo > build/switch_host.txt # once; the log prints the address tools/switch/build.sh && tools/switch/wwhd_debug.py deploy # upload, check, restart (~10 s) tools/switch/wwhd_debug.py log # the log, live tools/switch/wwhd_debug.py shot # PNG of the next frame tools/switch/wwhd_debug.py press A # also hold, release, stick, warp ``` `deploy` restarts the game, so start it from the HOME-screen icon (forwarder). Every command and the protocol: [docs/debug-server.md](docs/debug-server.md). Developer and test variables (`WWHD_*`: traces, renderer switches) go in a `[dev]` section at the end of `settings.ini`, one `NAME=value` per line, read at the next start; the menu keeps that section as it is. Over the debug server: `get settings.ini`, edit, `put` it back and `reload` ([docs/debug-server.md](docs/debug-server.md)). ## Install on the Switch ### What you need - A Switch running custom firmware (Atmosphère) with the Homebrew Menu. - The NRO you built and, optionally, the shader cache. - Your extracted game (`code/`, `content/`, `meta/`). ### Copy the files The SD card must end up like this: ``` sdmc:/switch/wwhd/ ├── wwhd.nro the game ├── shadercache_dksh.bin compiled shaders (optional, see above) ├── game/ your extracted game: code/, content/, meta/ └── (created by the game: save/, settings.ini, logs/, shader caches, captures/) ``` Put the SD card in the computer (or mount it over USB with hekate's *Tools → USB Tools → SD Card*) and copy the files. ### Start the game - Open the Homebrew Menu **in title mode**: hold **R** while starting any installed game, then pick **SwitchWakerHD**. Opened from the album (applet mode) the game has far too little memory. - Or install the HOME-screen icon (forwarder), which always starts it in title mode: [tools/switch/forwarder/INSTALL.md](tools/switch/forwarder/INSTALL.md). - Controllers act as the Wii U GamePad, in Off-TV Play: the console's screen shows the game at full resolution, and its touch screen is the GamePad's. The game goes straight from the title to the save list (no controller question) and into play. ### Saves, settings and updates - Saves: `sdmc:/switch/wwhd/save/`. Back up this folder. - Save states: `sdmc:/switch/wwhd/states/`. - Settings from the options menu: `settings.ini`. An `env.txt` from an earlier build is converted into it at the first start and renamed `env.txt.old`. - To update, replace `wwhd.nro` (and `shadercache_dksh.bin` if you rebuilt it). Saves, settings and caches stay. - Logs, if something goes wrong: `logs/`, one `wwhd__