A static recompilation of Devil's Third (US, WUP-P-ADNE, title 0005000010177600, update v16) to native x86-64 Windows code, built with nWiiURecomp.
This project contains no game files or assets. The executable (code/DevilsThirdGame-WiiU-Shipping.rpx) is read in place from your own dump. Everything derived from it, the manifest in nWiiURecomp/work/ and the C++ in generated/, stays on your machine. Never commit or share those.
| Path | What it is |
|---|---|
nWiiURecomp/ |
Clone of the tool, plus the Devil's Third patches listed below (uncommitted, on main). |
nWiiURecomp/configs/devils-third-us-v16.toml |
Game profile. It pins the RPX SHA-256 and holds the [hle_hooks] table. Upstream .gitignore ignores *.toml, so use git add -f to commit it. |
generated/ |
Output of nwiiu-recompile: 4,218 shards of 512 blocks, ~2.16M blocks, ~11M PPC instructions, ~1.7 GB. |
recompile.sh |
One-shot pipeline: build the tool, analyze, recompile, build the native exe. |
MSYS2 UCRT64 with:
pacman -S --needed mingw-w64-ucrt-x86_64-{gcc,cmake,ninja,pkgconf,shaderc,sdl3,openssl,zlib}./recompile.sh "/path/to/0005000010177600_v16" 20The headless interpreter is the quickest way to find the next boot blocker:
nWiiURecomp/build/nWiiURecomp/nwiiu-run.exe "<dump>/code/DevilsThirdGame-WiiU-Shipping.rpx" --config nWiiURecomp/configs/devils-third-us-v16.toml --max-instructions 200000000 --save-root nWiiURecomp/work/saveUpstream only validates Wind Waker HD. Devil's Third (Unreal Engine 3) needed the following:
-
Exports relocations (
execution_image.cpp). Devil's Third exports symbols. The fix-ups that target itsSHT_RPL_EXPORTStable (loader metadata at0xC0000000) are now skipped instead of being rejected. -
ISA coverage. Added to the shared semantics, the interpreter and the lifter:
fdivs(lifter validator gap),ps_div,ps_mr,ps_abs,ps_nabs,ps_res,psq_lx/stx/lux/stux,lfdu,lfdx,lfdux,stfdx,stfdux,nand,eqv,addme[o],subfme[o],sync,eieio, andmfspr/mtsprfor XER, UGQR0-7 and GQR0-7. -
Real GQR state (
CPUContext::gqr). Paired-single quantized loads and stores now decode the GQR's type and 6-bit signed scale, instead of hard-coding GQR2-5. Devil's Third reprograms GQR6 and GQR7. Limitation: the extern-C module ABI (nwiiu_static_cpu_state) does not carry GQRs yet. The standalonedevilsthird-nativepath is not affected. -
MEM2 heap placement (
cafe_coreinit.cpp). The heap was fixed at0x10520000, which is the end of WWHD's BSS. It now starts at the first 64 KiB boundary after the image's data, or at WWHD's address if that is higher. Devil's Third's BSS ends at0x1065D6AC. -
Tests. Assertions that encoded the old "unsupported" behaviour were replaced with positive tests for the new forms.
native_fixture.cppwas normalized to LF, becausecore.autocrlf=truebroke the golden comparison. -
Boot and HLE (
cafe_coreinit_extra.cpp,cafe_stubs.cpp, both new).- The loader now parses the RPX function exports and calls
__preinit_user(&mem1, &fg, &mem2)before the entry point. UE3 uses it to callOSGetMemBoundandMEMAdjustExpHeap, then builds its own block heap over MEM2. - The top 32 MiB of MEM2 is now reserved for the runtime's own allocations (GHS mutexes, locked cache, shared font), because UE3 claims everything
OSGetMemBoundreports. - New coreinit HLE:
- OSFastMutex/OSFastCond, OSCond, semaphores, OSWaitEventWithTimeout.
- OSJoinThread, OSDetachThread, OSSetThreadPriority, OSSuspendThread.
- Alarm cancels, OSAddAtomic64, calendar/tick conversion.
- The block heap (MEMInitBlockHeap and friends), MEMAdjustExpHeap, the locked cache (
LC*), the system message queue, and the IM/MCP/BSP queries.
- FS additions: the async variants (via queue or callback),
*WithPos, FSMakeDir/Remove/Rename, and/vol/save/common. - zlib125 is mapped onto host zlib.
- Offline stubs for nsysnet, nlibcurl, nn_ac/act/fp/ndm, plus audio, keyboard and input.
OSDynLoad_FindExportgives each erreula/swkbd name its own logged slot.
- The loader now parses the RPX function exports and calls
-
Scheduler: callbacks run in their own stack frame (
machine.cpp). Guest callbacks (the AX audio frame callback, FS async callbacks) used to start at the interrupted thread'sr1. If the interrupted function had just runstw r0,4(r1), the callback's prologue overwrote that saved LR with the callback-return trampoline (OSExitThread). The thread then "returned" into thread exit later on, so UE3's game thread exited andmaincalled_Exit(0)a few seconds after boot. Callbacks now start 1 KiB below the interruptedr1. -
Latte TEX destination swizzle (
latte_shader.cpp). Texture fetches now honourDST_SEL_X..W. They used to overwrite the whole destination register, which turned Bink's 3-plane YUV shader output green. -
GX2 robustness.
GX2CalcSurfaceSizeAndAlignmentapproximates MSAA, 3D and uncommon tile modes instead of refusing them.GX2CopySurfacebyte-copies same-layout levels and skips anything else. GX2 handler and renderer exceptions are logged once (GX2-SKIP,RENDER-SKIP) rather than ending the run. -
GPU texture cache.
GX2Invalidatenow evicts Vulkan-path textures as well as SDL ones, so streamed textures such as movie frames get re-uploaded. -
Speed.
getenvwas being called on every guest memory write and every dispatch. Those checks are now cached, and a one-entry thread-local page cache sits in front of the page map. The native exe went from about 4M to about 100M guest instructions per second. -
Boot past the logos.
KBDGetKeyreturns 1 ("no key"). The game drains keys withwhile (KBDGetKey(...) == 0), so the old 0 was an endless loop: 492M calls per 100B instructions.UCReadSysConfiganswers any key: language, country, EULA and initial launch with US-console values, and everything else with zeros, logged once each.GX2ClearColoron a format the CPU path can't fill no longer throws. The throw dropped the renderer's clear too.
-
Latte shader translation (
latte_shader.cpp).- Vertex fetch decodes every common
SQ_DATA_FORMAT, including10_10_10_2, with norm/int/scaled conversion and endian swap. - ALU sources support relative (
AR) addressing. - New ops:
SETE/GE/NE_DX10,TRUNC,CEIL,MOVA*, the integer bit and min/max ops,SIN,COS, andCUBE.CUBEworks, but cube textures are still sampled as 2D. - Control flow gains
LOOP_START*/LOOP_END/LOOP_BREAK/LOOP_CONTINUE, plusALU_BREAK/ALU_CONTINUE.
- Vertex fetch decodes every common
-
Renderer (
wwhd_renderer.h,wwhd_gpu.h).- Correctness:
- Blend state comes from
GX2SetColorControl/GX2SetBlendControl. - Render targets are sampled through a GPU copy.
- Adds RGBA16/RGBA16F textures.
- Constant (stride-0) attributes are supported.
- Scan targets are render targets. As
STATICtextures they came out black.
- Blend state comes from
- Performance:
- Translated shaders are cached by content hash.
- Command buffers are batched per frame.
- Vertex and index data go through a 64 MiB arena instead of per-draw Vulkan buffers.
- Each draw decodes only the vertex range it indexes, instead of the whole multi-MB UE3 dynamic buffer: about 7 ms → well under 1 ms per draw.
- The 2D presenter shares the SDL_GPU device (
SDL_CreateGPURenderer), so scan-out is a GPU copy rather than a full-frame readback. - Validation layers are off unless
NWIIU_GPU_DEBUGis set. - Vsync is off unless
NWIIU_VSYNC=1.
- Correctness:
-
Guest-side speed.
OSBlockMove,OSBlockSetandDCZeroRangeare bulk operations; they used to go one checked byte at a time.- With a host renderer attached,
GX2ClearColor/GX2ClearBuffersExandGX2CopyColorBufferToScanBufferno longer mirror their work into guest memory. That was about 15% of a frame.NWIIU_CPU_SURFACES=1restores it.
-
PC controls and glyphs (
pc_input.h,pc_glyphs.h, new).- Controls:
- Keyboard, mouse and SDL gamepads are mapped onto the GamePad, including real analog sticks: WASD on the left stick, mouse-look on the right.
- The stick-emulation button bits are set too, so menus navigate by stick.
VPADReadused to write the button masks into the stick fields.
- Glyphs: Wii U button-icon textures can be swapped, by pixel hash, for generated key-caps. Each key-cap is labelled with the PC key bound to that button, so no artwork is shipped or read.
- Controls:
Test status on Windows:
-
Pass:
executor_test,cafe_runtime_testandlatte_shader_test. -
Fail because the tests are stale. Each one asserts the strict WWHD behaviour that a later change here deliberately relaxed:
gx2_runtime_test: GX2 errors are now logged (GX2-SKIP), and odd surface formats get an approximate size.latte_surface_test: the same surface approximation.cafe_coreinit_test: the expanded-heap free-size query.
They need updating to the new expectations.
-
machine_testis stale too: the audio-callback case runs its callback in a fresh frame below a test stack that has nothing mapped there. -
Fail for environmental reasons, not code:
cafe_filesystem_testneeds symlink privileges.recompile_cli_testshells out with POSIX syntax.
-
Analysis: 103,815 functions, 6,253 unresolved control-flow records (indirect jumps). Unresolved targets fall back to the interpreter at runtime.
-
Recompile: every block lifts.
-
Native build:
nWiiURecomp/build-native/devilsthird-native.exe(620 MB) links with MinGW GCC 16 and copies its runtime DLLs next to itself. A fullrecompile.shrun takes about 12 minutes at-j20; the previous per-shard-dispatcher layout made a 1.46 GB exe in about 65. -
Boot: every import resolves. The game plays the logo movies, loads the
D3Startmap, and shows the Scaleform brightness-calibration screen, about 4 minutes after launch. Pressing A on that screen leads into the in-engine intro cutscene: 3D scenes with lighting, fog and motion blur, plus the location-title text. That cutscene runs into the campaign prologue (the Guantanamo Bay riot), which plays as an in-engine cutscene too. In that run, fewer than 0.2% of draws failed; most of those were shaders usingCUBE, which is now translated. -
Frame rate, as fps on this machine:
Scene Cores on one thread ( NWIIU_PARALLEL=0)Parallel cores (default) Calibration / title UI ~13–15 36–44 Intro cutscene and the scenes after it 4–8 42–47 Prologue riot (level geometry, many characters) 15–23 not measured yet The renderer takes about 15% of a frame; the rest is guest CPU work. With parallel cores the three Wii U cores run on three host threads, and guest time follows the wall clock, so the game runs at its real speed. The game has no vsync wait.
-
Not implemented yet: alarms never fire, audio is silent, the network is offline, and erreula/swkbd are logging stubs.
The renderer is no longer the limit, so the remaining levers are guest-side:
- Done: the three guest cores on three host threads (
NWIIU_PARALLEL, on by default inrun.sh/run.bat). Imports and scheduler state sit behind one HLE lock,stwcx.is a host compare-exchange on flat guest memory, and the main thread doubles as the worker that runs the GX2-issuing guest thread, so SDL stays on it. - Done: guest time follows the wall clock in parallel mode. If every core is idle,
NWIIU_IDLE_SKIP=1jumps ahead to the next timer, which was the old behaviour. - Done: compact lifted code. Shards are block tables with flat memory access and one instruction-count add per block, and the executor chains straight from block to block. That cut the exe from 1.46 GB to 620 MB and lifted parallel mode from 30–40 to 42–47 fps.
- Next: profile the parallel build to see which core is the bottleneck now.
- Then: the game's own frame cap, if one shows up now that time is real.
run.sh loads controls.ini. Every binding is documented in that file and can be edited.
- Mouse: click in the window to capture it, then it drives the camera (right stick); F1 releases it.
- Fullscreen: F11 toggles it.
- Controller: any controller SDL knows works alongside the keyboard, using the Pro Controller's positional layout.
Default bindings:
| PC | Wii U | PC | Wii U | |
|---|---|---|---|---|
| WASD | left stick | Mouse | right stick | |
| Left Alt (hold) | walk | Left Shift | L-stick click | |
| Left mouse | ZR | Right mouse | ZL | |
| Middle mouse / V | R-stick click | E / Q | R / L | |
| Space | B | Left Ctrl / C | A | |
| R | Y | F | X | |
| 1 / 2 / wheel | D-pad | Arrows | D-pad | |
| Enter | A | Esc / Backspace | B | |
| Tab / P | Plus | M | Minus |
The game's own Options → Controls screen decides what each pad button does. These bindings only choose which PC input presses which pad button.
Glyphs. On-screen prompts can show PC keys instead of Wii U buttons:
- Run once with
NWIIU_TEXTURE_DUMP=<dir>while a prompt is on screen. - Find the icon among the dumped
<hash>_<w>x<h>_<fmt>.bmpfiles. - Add
<hash> = ZR, or whichever button it shows, toglyphs.ini(or the file named byNWIIU_GLYPHS).
That texture is then drawn as a key-cap labelled with the key bound to that button, for example LMB. The table ships empty, because no screen with button prompts has been reached yet.
On Windows, put your dump's path on the first line of dump.txt next to run.bat and double-click run.bat. Or pass the path as an argument:
run.bat "D:\path\to\0005000010177600_v16"The build copies its runtime DLLs (libstdc++, SDL3, shaderc, zlib, ...) next to the exe, so MSYS2 is not needed to play. From bash:
./run.sh "/path/to/0005000010177600_v16"NWIIU_PARALLEL=0 falls back to running all cores on one thread.
Or by hand:
export PATH=/c/msys64/ucrt64/bin:$PATH
D="/path/to/0005000010177600_v16"
NWIIU_WINDOW_TITLE="Devil's Third" nWiiURecomp/build-native/devilsthird-native.exe "$D/code/DevilsThirdGame-WiiU-Shipping.rpx" --max-instructions 1000000000000 --save-root nWiiURecomp/work/save --windowDebug environment variables added for this title:
| Variable | Effect |
|---|---|
NWIIU_HLE_STATS=1 |
Per-import call counts, printed at exit. |
NWIIU_HLE_TAIL_THREAD=<hex> |
The last 256 imports one OSThread called (with lr, r3, r4), printed at exit. |
NWIIU_STUB_MISSING=1 |
Turn unimplemented imports into a logged return 0. |
NWIIU_HEAP_TRACE=1 |
Log block-heap allocations and frees. |
NWIIU_GX2_STRICT=1 / NWIIU_RENDER_STRICT=1 |
Make GX2 and renderer exceptions fatal again. |
NWIIU_NO_VPAD=1 |
Report the GamePad as disconnected. |
NWIIU_VPAD_TRACE=1 |
Log the first VPADRead caller. |
NWIIU_FRAME_DUMP=<dir> (+ _INTERVAL) |
Dump presented frames as BMP. |
NWIIU_SHADER_TRACE=1 + NWIIU_SHADER_DUMP=<dir> |
Dump raw and translated shaders. |
NWIIU_DRAW_STATS=1 |
Every 50 swaps: wall time, render time, fps, the render split by event (clear/draw/scan/swap), and per-outcome draw counts. |
NWIIU_PARALLEL=0/1 |
Cores on one host thread / on three (default 1 in the launchers). NWIIU_PARALLEL_WORKERS (0–2), NWIIU_PARALLEL_PUMP_US (how often SDL is pumped), NWIIU_PARALLEL_TRACE (logs GX2 threads moving to the main worker). |
NWIIU_IDLE_SKIP=1 |
In parallel mode, jump guest time to the next sleeper when every core is idle. |
NWIIU_FLAT_MEMORY=1 |
Flat host-backed guest memory without parallel cores (parallel implies it). |
NWIIU_SAMPLE_PROFILE=1 (+ NWIIU_SAMPLE_DELAY=<s>) |
Sampling profiler. At exit it prints the hottest guest threads, PCs and thread+PC pairs, naming HLE imports. |
NWIIU_THREAD_DUMP=1 (+ _FILE=<path>) |
Scheduler snapshot of every guest thread: state, wait object, pc, lr, stack chain. |
NWIIU_HLE_TAIL_THREAD=<hex>[,<hex>...] |
As above, for several threads at once. |
NWIIU_AUTO_START=1 / NWIIU_AUTO_A_AFTER=<swap> |
Pulse Plus from boot, or A from a given frame, to walk through screens unattended. |
NWIIU_TEXTURE_DUMP=<dir> |
Write each distinct sampled texture (≤512²) once, named by the hash glyphs.ini uses. |
NWIIU_CONTROLS=<file> / NWIIU_GLYPHS=<file> |
Control bindings and glyph table (default ./controls.ini, ./glyphs.ini). |
NWIIU_VSYNC=1 |
Present with vsync (off by default, so the frame rate is uncapped). |
NWIIU_GPU_DEBUG=1 |
Create the SDL_GPU device in debug mode (Vulkan validation). |
NWIIU_SEPARATE_RENDERER=1 |
Use a separate SDL Vulkan renderer for presentation (the old readback path). |
NWIIU_CPU_SURFACES=1 |
Mirror colour clears and scan copies into guest memory again. |
- Game-specific
[hle_hooks](for example memcpy/memset fast paths) can be found with Ghidra + GhidraRPXLoader andnWiiUAnalyzer/Ghidra/ExportWiiUProfile.java.