![Ninja Gaiden II Recompiled](docs/images/banner.png) # Ninja Gaiden II Recompiled **A PC port of Ninja Gaiden II by static recompilation.** A native Linux and Windows version of *Ninja Gaiden II* (Xbox 360, 2008), made by statically recompiling the game's own PowerPC code to run directly on a PC, not an emulator. It is built on the [ReXGlue SDK](https://github.com/rexglue/rexglue-sdk) and draws with its own Vulkan renderer, which takes over the game's Direct3D calls instead of emulating the Xbox 360 GPU. It plays at a steady 60 fps on modest hardware (the Steam Deck is the baseline) and adds PC options in the game's own menus: higher render resolutions, widescreen and ultrawide, anti-aliasing, keyboard and mouse, PlayStation, Nintendo and keyboard button prompts in the game's own style, and more. **You need your own copy of the game.** This project contains none of the game's data (graphics, sound, movies, text): on first start it asks for your disc image, Games on Demand package or extracted game, and installs it. It is made for the **World release** (title ID `544307D5`) with **Title Update 3**, which it asks for too. The downloadable content (Mission Mode, the costume packs) is supported and optional: it can be added on the first start or later. ## Features - Native Linux (AppImage) and Windows (x64) builds; Steam Deck friendly - Its own Vulkan renderer: render resolution up to 8x, anti-aliasing (MSAA up to 8x), anisotropic filtering, texture LOD bias, the game's bloom on, reduced or off - 16:9, 16:10, 21:9, 32:9 and 4:3: the 3D fills the screen, the HUD goes to the screen's corners, the menus and movies keep their own frame - Keyboard and mouse, with the keys' own pictures in the game's button prompts; Xbox, PlayStation and Nintendo prompts, following the controller in use. The PlayStation, Nintendo and keyboard buttons are made from the game's own (its discs, plates and ovals, relettered) - Options from alicenotmech's Master Edition, in the port's own versions: skip the death screen, chapter cards that go on by themselves, a HUD that fades out when not fighting (or hidden), no post-effects, smoother HUD and menus, a sharper font, hi-res shadows in fights; and its Modern Camera and OT/UT Free Camera themselves - Skip intro and skip any cutscene; cheats: infinite health, ninpo and ammo, unlock difficulties and costumes, all weapons and ninpo, all crystal skulls, max health and ninpo - Low input latency and frame pacing on the display's own refreshes (options) - Frame Interpolation (experimental): higher frame rates while the game logic stays at 60 Hz - 120 FPS and Variable (experimental): the game's renderer draws extra frames between its 60 Hz ticks - Mods: game files replaced by files in a mods folder, nothing of the game's changed - Render pipelines made in the background and remembered between sessions, so new areas don't stutter; the game's movies decoded on the PC (FFmpeg) - **RECOMP SETTINGS** on the title menu and in the in-game menu; **EXIT GAME** on the title menu ## Performance The Steam Deck is the baseline for optimization: changes are judged by whether it holds 60 fps in the game's heaviest scenes. Measured on a Steam Deck LCD in Game Mode, on battery, with sound, in Chapter 1's first fight (29 seconds each, the Deck's own performance overlay's frame log), the port at the Deck's default 1x render scale and Xenia Edge at its defaults (November 2026 builds): | | This port | Xenia Edge | |---|---|---| | Average fps | 60.0 | 55.4 | | 1% low | 57.4 | 20.3 | | 0.1% low | 55.5 | 17.9 | | Slowest frame | 18 ms | 56 ms | | Frames over 20 ms | 0 | 380 | | CPU load | 26% | 50% | | GPU load | 52% | 84% | | Whole Deck's power draw | 10 W | 22 W | The port holds 60 fps with no slow frame, while the emulator averages 55 fps and drops to 18. The port draws less than half the power, so a charge lasts about twice as long. ## Shaders The game's shaders are translated once, when the port is built, not while you play. All 663 of them are in the game's executable: the build converts each into a Vulkan shader (SPIR-V) and packs them into the program, so none is compiled at run time. What a GPU still has to make is pipelines: a shader together with the draw settings it is used with. This is the step that makes emulators stutter the first time an effect appears. Here: - At start, the port makes the pipelines of a list recorded by playing through the game (333 of them), in the background as the game starts. - A pipeline that wasn't on that list is made in the background when the game first needs it; the game doesn't wait, and the effect it belongs to can be missing for a frame or so (`async_pipelines = false` in `ng2.toml` waits instead). It is added to your own list (`ng2-pipelines.bin`) and made at every later start. - The GPU driver keeps the finished pipelines in its own cache, so later starts are quicker than the first one after installing. ## Getting started ### What you need These files, from your own console or discs. The first start asks for them in this order. 1. **The game**, World release (`544307D5`), in any one of these forms: - a disc image: `*.iso` - the Games on Demand package: the file in `544307D5/00007000` (named like `C1200E9B558D04454FA6`), with its `.data` folder next to it - an extracted copy: the folder with `default.xex` and the `.ng2` archives 2. **Title Update 3** (required): `TU_1A461UL_000000G000000.00000000000O4`, or the `default.xexp` taken from it. On a console it is in `Content/0000000000000000/544307D5/000B0000`. The port is built for this update and checks it; the Japanese release's Title Update 3 is refused. 3. **The DLC** (optional): the console's `544307D5/00000002` folder, with Mission Mode and the costume packs. It can also be added later, in the game folder's `dlc` folder. And a 64-bit PC with SSE4.2 (any from about 2009 on) and a GPU with Vulkan 1.3 drivers. The first start after installing takes longer to load: the render pipelines are made then and kept, and later starts are quicker. ### Linux and Steam Deck 1. Download `NinjaGaiden2-x86_64.AppImage` from the releases page and make it executable (`chmod +x`, or Properties → Allow executing). 2. Run it. On the first start it asks whether to keep everything next to the AppImage (portable mode, below), then for your copy of the game, Title Update 3 and, if you have it, the DLC folder. A disc image or package is copied once into the data folder (below). More DLC can go in the game folder's `dlc` folder later; it is installed on the next start. 3. On a Steam Deck, add the AppImage to Steam (Add a Non-Steam Game) to play it in Game Mode, and choose 16:10 in RECOMP SETTINGS → Display. Needs a 64-bit Linux with glibc 2.35 or newer (SteamOS, Ubuntu 22.04+, Debian 12, Fedora 36+), and Python 3. The first-start windows use `kdialog` (SteamOS and KDE desktops), or `qarma` or `zenity` where kdialog isn't installed (GNOME, Cinnamon, Xfce...). With none of them, start the AppImage from a terminal and it asks there. An extracted copy of the game next to the AppImage (`default.xex` beside it, or in a `game_files` or `game` folder there) is used without asking, as is `NG2_GAME_DIR`; Title Update 3's `default.xexp` goes next to `default.xex` and DLC in its `dlc` folder. ### Windows 1. Download `NinjaGaiden2-windows-x64.zip` from the releases page and extract it anywhere. 2. Run `ng2.exe`. The first time it asks about portable mode (below), then for the game, Title Update 3 and the DLC as on Linux; a disc image or package is copied into `%LOCALAPPDATA%\NinjaGaiden2\game`. Needs Windows 10 or 11 (64-bit). The Microsoft Visual C++ runtime DLLs are included. Both packages carry the game twice, for any PC with SSE4.2 and for one with AVX2 (most PCs since 2013, the Steam Deck): the faster one is used where the CPU has it. `NG2_NO_AVX2=1` keeps the other. ### RecompLauncher The packages carry a `recomplauncher.json`, so [RecompLauncher](https://recomplauncher.com) sets the game up from its own setup screen: your copy, Title Update 3 and, if you have it, the DLC folder. Everything is then kept in the game's `recompdata` folder there. Saves and settings from an earlier install in the usual places (below) are copied over once. With the launcher's setup skipped, the game asks on its first start as above. ### Where things are kept | | Linux | Windows | |---|---|---| | Copied game (from a disc image or package), saves, log (`ng2.log`) | `~/.local/share/ng2-recomp` | `%LOCALAPPDATA%\NinjaGaiden2` | | Settings (`ng2.toml`), the chosen game folder, the pipeline list (`ng2-pipelines.bin`) | `~/.config/ng2-recomp` | `%LOCALAPPDATA%\NinjaGaiden2` | **Portable mode:** with a file named `portable.txt` next to the AppImage (or `ng2.exe`), all of these go into a `userdata` folder next to it instead. The first start offers it. The folder must be writable (not inside Program Files). Delete `portable.txt` to go back. `NG2_GAME_DIR=` starts with that game folder instead of the remembered one (Linux; on Windows pass `--game_data_root=`). `NG2_UPLOAD_HOST=1` keeps all the data the game sends to the graphics card each frame in system memory, `=0` in the card's memory. Without it the game measures at start how fast it can write to the card, and on a slow link (a card on fewer PCIe lanes) keeps that data in system memory. ## Settings Everything is in the game's own menus: **RECOMP SETTINGS** on the title menu, and **Recomp Settings** in the in-game menu (Back, under Save Method). Changes apply at once and are saved; each defaults to the game's own behaviour. - **Graphics**: Render Scale (1x–8x, with the resolution it draws at, as "2x 2240x1168"); Anti-Aliasing (off, or 2x MSAA as on the console, 4x, 8x); Texture Filtering (the game's, or 4x–16x anisotropic); Texture LOD Bias (the game's, 0 or -1: less shimmer at higher render scales); Normal Map Filtering (the game's, or trilinear: normal maps filtered between their mip levels too, so no bands slide over lit surfaces); Shadows (the game's, or Hi-Res: the 1024x1024 shadow map in fights too, where the game drops to 512x512); Bloom (on, reduced, off); Post-Effects (off: no blur, no white flashes); Screen Shake (off: the camera doesn't shake on hits, finishers and explosions) - **Display**: Window Mode (windowed, borderless, fullscreen) and Window Size; Aspect Ratio (16:9, 16:10, 21:9, 32:9, 4:3); V-Sync (Off, FIFO, Mailbox, Adaptive; a mode the driver lacks falls back to FIFO); Frame Pacing (Timer, the game's own 60 Hz clock, or Auto: the game's frames on the display's own refreshes, measured from the frames reaching the screen, so no frame is shown twice for the drift on a screen a little off 60 Hz, as 59.94; it needs VK_KHR_present_wait, or on Windows, where the driver lacks it (AMD), it follows the monitor's own refreshes; else it runs as Timer). Timer is the default: use it on a variable-refresh display, G-Sync or FreeSync. In the Steam Deck's Game Mode (and any game run through gamescope) Auto acts as Timer: there it gave me uneven frame pacing. Input Latency Lowest there keeps the game's frames on the display's refreshes by itself, whichever Frame Pacing is set; Frame Rate (60 FPS, 120 FPS (Fixed) or Variable (VFR), experimental: the game's renderer draws extra frames between each of the game's 60 Hz ticks, from game state blended between the ticks; Variable draws as many as the display holds, up to its VFR FPS Limit, Match Refresh or 120 FPS; it turns Frame Interpolation off, and Frame Interpolation turns it off) - **Cheats**: Infinite Health; Infinite Ninpo (each cast's ninpo filled back); One Hit Kill (any hit that does damage kills the enemy); Instant Charge (Ultimate Techniques charge at once); Infinite Ammo (arrows and special shuriken aren't used up); Unlock Costumes; All Weapons and Ninpo (Level 1 or 3: every melee and projectile weapon, ninpo and ammo, given at a new game, a load and a stage's start; what it gives stays in the save when it's turned off, as items found); All Crystal Skulls; Max HP and Ninpo (the life and ninpo upgrades full while it's on; the save keeps your own) - **Interface**: HUD (shown, fading out when not fighting, hidden); Hi-Res Font (text drawn from glyphs twice the size, sharper above 720p; from the next start); Smooth HUD and Menus (the 2D always filtered); Show FPS; Button Prompts (Auto follows the device in use; Xbox, PlayStation, Nintendo, Keyboard); Mouse Sensitivity (0.25 to 8) - **Extras**: Skip Intro; Skip Cutscenes (any, watched or not); Skip Death Screen (straight to the game over menu); Auto Chapter Screen (chapter cards and mission briefings go on by themselves); More Blood (twice the blood sprays and stains) - **Gameplay**: Input Latency (Original, the default: each frame shown after the game's wait for the vblank, as on the console; Low: shown as soon as it is drawn, up to a refresh sooner (about 14 ms on a 165 Hz display); Lowest: also no finished frame waits for the screen, which needs VK_KHR_present_wait; under gamescope, as in the Steam Deck's Game Mode, that needs VK_EXT_present_timing, which SteamOS has from 3.10, and acts as Low without it); Unlock Difficulties (every path in New Game and Mission Mode, at once either way); Modern Camera (Master Edition's camera, from the modern versions of the game: a freer camera that follows less tightly); OT/UT Free Camera (the camera stays under your control during Obliteration Techniques, Ultimate Techniques and throws) - **Controls**: a table of the game's actions, each with two keys (or mouse buttons) and a controller button. Confirm on a cell, then press the key or the button (Ninpo and Wind Run take one button or two held together); X clears a cell, Y gives the row its defaults, and Default Controls brings everything back. A key or button given to an action leaves the one that had it. The sticks' clicks (L3, R3), which the game leaves unused, can be given to an action too. The sticks, the d-pad, START and BACK stay the controller's, and the menus keep A and B (Return and Backspace on the keyboard). The game's own prompts show the buttons chosen The game's own Options (camera, controller, sound, screen) are where they always were. Some settings have no menu entry; they go in `ng2.toml`: - `async_pipelines = false`: make render pipelines as they're needed instead of in the background (a new effect can stutter, but never appears a frame late) - `log_hitches = true`: log every frame that takes over 25 ms with what the renderer spent it on - `half_pixel_offset = false`: drop the console's half-pixel shift - `frame_pacing_phase = 5`: where in a refresh Frame Pacing Auto starts a frame (% of it) ## Mods Mods replace the game's files: models, motions, effects, stages, text, sounds. They go in a `mods` folder in the data folder (`~/.local/share/ng2-recomp/mods`, `%LOCALAPPDATA%\NinjaGaiden2\mods`, or `userdata/mods` in portable mode), one folder per mod: mods/ Ryu's New Look/ mod.toml files/ char/ryu_b/ryu_b.gmd A file in `files/` replaces the game's file with the same path (`files/char/ryu_b/ryu_b.gmd` is Ryu's in-game model, `char\ryu_b\ryu_b.gmd`). The game loads it in place of the one in its archives, so a mod never changes the game folder: delete the mod's folder and the game is as it was. `mod.toml` is optional: name = "Ryu's New Look" version = "1.0" enabled = true # false turns the mod off # One of the game's own files loaded in place of another (here his costume C model): [replace] 'char/ryu_b/ryu_b.gmd' = 'char/ryu_c/ryu_c.gmd' Mods are read at start, in their folders' name order: when two replace the same file, the first one's is used. The log (`ng2.log`) lists each mod and the files it brings. To find which file to replace, look in `game-files.txt` in the mods folder (every file's path, written by the game at its first start), or set `log_file_loads = true` in `ng2.toml`: the log then names every file the game loads. ## Controls A controller works as on the Xbox 360; a PlayStation or Nintendo controller too, with its own button prompts. The keyboard and mouse can be used at any time: the game follows whichever was touched last, and its prompts change to match (or stay on one set: Button Prompts, in Interface). The mouse moves the camera only while the keyboard and mouse are in use, and the pointer hides while a controller is. In the menus the mouse points and clicks: the left button confirms, the right one goes back, the wheel moves through a list (or cycles the slots on Load Game, the costumes and the New Game paths), and the arrows on screen can be clicked. Return and Backspace confirm and go back there too, and Delete deletes a save. | Key | Action | Key | Action | |---|---|---|---| | W A S D | move | mouse | camera | | left mouse, J | quick attack (X) | right mouse, K | strong attack (Y) | | Space | jump (A) | E | projectile (B) | | F | ninpo (Y + B) | C | wind run (A + X) | | Shift | block (LT) | Q, middle mouse | RT | | R | LB | V | RB | | Z / X | stick clicks | Tab / Escape | Back / Start | | arrows | d-pad | Return / Backspace | A / B | | Numpad 8 4 5 6 | camera (keys) | | | These are the defaults: RECOMP SETTINGS' Controls page sets each action's keys and controller button. ## Fixes to the original game Bugs the original game has too, fixed here: - Chapter 6, before the church: columns and spires flickered and some walls let Ryu walk through. Two overlapping rooms were both drawn, one with plain stand-ins for the other's detail; the stand-ins are now hidden while the detailed room is loaded ([#59](https://github.com/gamboozino/ng2recomp/issues/59), [#60](https://github.com/gamboozino/ng2recomp/issues/60)). - Chapter 6: going back to a room with IS Ninjas still around could crash. A reused object slot ran the old object's scripts from data the new room had already overwritten; the console's slower disc hid it ([#94](https://github.com/gamboozino/ng2recomp/issues/94)). ## Known issues - Some cutscenes may have slight audio delays. - Overlays and frame limiters that hook the game's presents (MSI Afterburner with RivaTuner, and the like) can upset frame pacing: if the game looks choppy at a steady 60 fps, close them completely (not only minimized) and try again. - Frame Interpolation (experimental): some objects or effects can flicker or judder. It is meant for displays above 60 Hz and adds a little input latency. It is off in cutscenes for now, which play at the game's own rate, until the problems it causes there are solved. Please report any issues with it. - 120 FPS and Variable (experimental) still have some issues: on quick moves like a jump or a fast turn, some elements of Ryu can look stuck in a different position for a moment. Variable is less smooth than 120 FPS (Fixed) for now. Please report any others. - Tested on a Linux desktop, the Steam Deck, under Proton and in a Windows 11 virtual machine; reports from other systems, and from real Windows PCs especially, are welcome. When reporting a graphics glitch, pressing **F7** while it is on screen records the next frames' drawing to `~/ng2-trace-` (Linux) or `C:\Users\\ng2-trace-` (Windows): attach that folder, zipped. For a crash or a freeze, attach the log (`ng2.log`, above). ## To do - A native audio engine - More gameplay settings - More visual settings - An Android port ## Building from source The build needs the game's code, so it starts from your own disc image. Requirements: clang 20+, CMake 3.25+, Ninja, Python 3, the Vulkan headers and loader, FFmpeg (libavformat, libavcodec, libswresample, libswscale). 1. Clone with its submodules: the ReXGlue SDK, XenosRecomp (the shader translator) and plume (the Vulkan layer of Unleashed Recompiled), each a fork with this port's changes on its `ng2` branch ([rexglue-sdk](https://github.com/gamboozino/rexglue-sdk), [XenosRecomp](https://github.com/gamboozino/XenosRecomp), [plume](https://github.com/gamboozino/plume)). Then build and install the SDK: git clone --recursive https://github.com/gamboozino/ng2recomp cd ng2recomp/thirdparty/rexglue-sdk cmake --preset linux-amd64 cmake --build out/build/linux-amd64 --config Release --target install cd ../.. (In a clone made without `--recursive`: `git submodule update --init --recursive`.) 2. Extract the disc (or the Games on Demand package) into `game_files/` and put Title Update 3's `default.xexp` next to `default.xex` (see [docs/title-update.md](docs/title-update.md)): python3 tools/xdvdfs_extract.py "Ninja Gaiden II (World).iso" game_files python3 tools/stfs_extract.py TU_1A461UL_000000G000000.00000000000O4 default.xexp game_files/default.xexp 3. Build. This generates about 560 MB of C++ from the game's code and translates its shaders (see [docs/shaders.md](docs/shaders.md)): cmake --preset linux-amd64-release cmake --build out/build/linux-amd64-release 4. Run it: out/build/linux-amd64-release/ng2 --game_data_root=game_files The AppImage, `packaging/appimage/build.sh`, builds the SDK and the game in an Ubuntu 22.04 container (Docker; `packaging/appimage/Dockerfile`; it also needs rsync, zsync (`zsyncmake`, for the `.zsync` updaters use) and [appimagetool](https://github.com/AppImage/appimagetool) on the PATH, or `APPIMAGETOOL=`), so it needs only glibc 2.35 and runs on SteamOS and other current distributions. It bundles a small FFmpeg with the movies' codecs and writes `out/appimage/NinjaGaiden2-x86_64.AppImage`. `packaging/appimage/build-local.sh` packs the native build instead, quicker but only for the machine that built it. The Windows build is cross-compiled from Linux after the native one: `packaging/windows/build.sh` (clang and lld against Microsoft's C runtime and Windows SDK from [xwin](https://github.com/Jake-Shadle/xwin), `xwin --accept-license splat --output ~/.xwin`). It builds the SDK for Windows, fetches FFmpeg's Windows build, and packs `out/windows/NinjaGaiden2-windows-x64.zip`. The 64-bit ARM Linux build is cross-compiled the same way, after the native one: `packaging/aarch64/build.sh` fetches FFmpeg 9.0.2's source and an Ubuntu 24.04 arm64 sysroot, builds the SDK, a small FFmpeg and the game, and puts them in `out/aarch64-dist`. Besides clang, lld and the LLVM tools it needs curl, bsdtar, Python 3.11 or newer, gpgv and the Ubuntu archive keyring in `/usr/share/keyrings` (`ubuntu-keyring` on Arch, `ubu-keyring` on Fedora). The device needs glibc 2.39 or newer (Ubuntu 24.04 and later; Armada on the AYN Odin 3 Ultra runs it). That build has no installer: copy `out/aarch64-dist` to the device, put the extracted game in `game_files/` inside it with Title Update 3's `default.xexp` next to `default.xex` (as in the build steps above) and DLC in `game_files/dlc/`, and run `./ng2`. Settings, saves and the log (`ng2.log`) go where the AppImage keeps them (the Linux column above; no portable mode). How it works: [docs/renderer-plan.md](docs/renderer-plan.md) (the renderer), [docs/menus.md](docs/menus.md) (the menus), [docs/shaders.md](docs/shaders.md). How to contribute: [CONTRIBUTING.md](CONTRIBUTING.md); the layout, tools and test rules, also for coding agents: [AGENTS.md](AGENTS.md). ## Support If you'd like to support the project: [GitHub Sponsors](https://github.com/sponsors/gamboozino) or [ko-fi.com/gamboozino](https://ko-fi.com/gamboozino) ## Credits - [ReXGlue SDK](https://github.com/rexglue/rexglue-sdk) by Tom Clay: the recompiler and Xbox 360 runtime this is built on, itself derived from [Xenia](https://xenia.jp) (BSD-3-Clause) - [Unleashed Recompiled](https://github.com/hedge-dev/UnleashedRecomp) by hedge-dev: the native renderer follows its Vulkan renderer (GPL-3.0) - [XenosRecomp](https://github.com/hedge-dev/XenosRecomp) by hedge-dev: the shader translator (MIT) - [plume](https://github.com/renderbag/plume) by renderbag: the Vulkan layer (MIT) - [Ninja Gaiden II Master Edition](https://github.com/alicenotmech/ng2-master-edition) by alicenotmech: its Modern Camera and OT/UT Free Camera, ported (MIT), and a reference for this port's own versions of some of its other options - [IzunaRecomp](https://github.com/YaibaKamikaze/IzunaRecomp) by The Izuna Project contributors: research on some optimizations, and the busy-wait loop detection of the recompiled code (MIT) - [Xenia Edge](https://github.com/has207/xenia-edge) by has207: a reference for how the game should look and behave, and its GPU traces for comparing frames with the native renderer - Banner lettering: RECOMPILED in Cinzel by Natanael Gama (SIL Open Font License) *Ninja Gaiden* is a trademark of Koei Tecmo. This project is not affiliated with or endorsed by Koei Tecmo or Team Ninja. ## License This project's code is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version (`GPL-3.0-or-later`; the text is in [LICENSE](LICENSE)). It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. The parts it is built from keep their own licenses: see [THIRD_PARTY.md](THIRD_PARTY.md).