nfsu2-xbox-port

nfsu2-xbox-port is a native PC port of Need for Speed: Underground 2 for Apple Silicon Macs with 60 or 120 fps and higher resolutions.

README

NFS Underground 2 for Mac

Need for Speed: Underground 2 (EA Black Box, 2004), the original Xbox version, running natively on Apple Silicon Macs.

What it is

The game's own program, translated from the Xbox's x86 code into C and compiled for your Mac. It is not an emulator: there is no virtual Xbox, the game runs as a normal Mac app, with the disc's own cars, city, music, text and movies. On top of that it has the things that make it play well on a Mac: 60 or 120 fps, a 16:10 picture without black bars, up to 4x the Xbox's resolution, bloom, ambient occlusion and a settings menu over the game.

Almost everything here is other people's work, and this is their port as much as ours:

  • nfsu2-sw by antoxa2584x made the game run outside the Xbox, with xboxrecomp by sp00nz, which translates Xbox games to C and stands in for the Xbox's hardware and system.
  • nfsu2-ios by myUdav4iik brought it to Apple devices, with a Metal renderer.
  • NFSU2Deadware by LeoDeadware made it a Mac game: the frame rate, 16:10, the resolution, the effects, and the idea of building the game on the player's own Mac.

This project puts them together without changing the game's look (no HD texture packs, no translation), adds the settings menu and the installer, and keeps the same style as the other ports in this series (NFS Hot Pursuit 2, ProStreet).

Status: races, free roam in the city, the menus, Quick Race and saves work at 60 and 120 fps on an M1 Pro with a gamepad.

  • It is an experiment, worked on when time allows; it is not actively supported.
  • The game has not been played from start to finish on it; long Career sessions are untested.
  • Apple Silicon and macOS 15 or newer only, and only the Xbox USA disc (the European and Japanese editions have another program and would need their own build).

How it was made, step by step: docs/PORTING.md. Changes per version: CHANGELOG.md.

Install and play

You need an Apple Silicon Mac with macOS 15 or newer and your own disc image (ISO) of the USA Xbox release of Need for Speed: Underground 2. Nothing of the game is included: the installer builds it on your Mac from your disc.

  1. Download NFS-Underground-2-<version>.dmg from Releases, open it and drag NFS Underground 2 Installer to Applications.
  2. Open it. The installer isn't notarized by Apple, so the first time macOS refuses. Close that message (don't move it to the Trash), go to System Settings > Privacy & Security, scroll to the message about it, click Open Anyway and confirm.
  3. Apple's Command Line Tools. The game is compiled with them. If they aren't installed, macOS offers to install them: click Install, and the installer goes on by itself when they are there.
  4. Choose your disc image. The installer copies the game's files (2.6 GB) into ~/Library/Application Support/NFS Underground 2, checks that it is the USA disc, translates the game's program to C and compiles it. On an M1 Pro that takes about 4 minutes, once. A window shows how far it is.
  5. NFS Underground 2 is put in Applications (in ~/Applications when Applications isn't writable) and opens. Play it from there. You can delete the disc image and the installer afterwards; opening the installer again offers Play or Rebuild.
Controls

A controller works as on the Xbox: anything macOS knows (Xbox, PlayStation, MFi), with rumble. Connect it before or while the game runs.

The keyboard drives the game when no controller is connected (Settings > Input can make it always or never):

KeyXbox controllerIn the game
ArrowsD-pad and left stickmenus, steering
A / Dleft stick left / rightsteering
W / Sright / left triggergas / brake and reverse
EnterA and Startselect, "press Start", pause
Esc, BackspaceBback
Space / Left ShiftX / Y
Q / EWhite / Black
Tab / PBack / Start
I J K Lright stick

The keys can't be changed yet. The controller's buttons are the game's own Xbox layout. A modern pad's bumpers stand in for the original controller's White and Black buttons: LB is White, RB is Black (as in xemu). A press shorter than one of the game's frames is still seen once.

The settings menu
ControllerKeyboard and mouse
Open and closeBack + Start togetherF1 (on a MacBook fn+F1, unless the F-keys are set as standard keys) or Cmd+,
Choose a settingD-pad or left stick up/downarrows up/down, or the mouse
Change itD-pad or left stick left/right, Aarrows left/right, Enter, or click the arrows
Change pageLB / RBQ / E, Tab
CloseBEsc

While the menu is open the game gets no input. Under the list, the chosen setting says what it does, where you will see it (races and the city, the whole picture, the menus...) and, after a change, whether it was applied at once or needs a restart. At the bottom: Reset page, Close and Quit Game.

PageSettingChoicesApplies
DisplayDisplayWindow, Full Screenat once (F11 also switches it, for this run)
Resolution Scale1x, 1.5x, 2x, 2.5x, 4x (default)at once
Frame Rate60 fps (default), 120 fps, 30 fps (the Xbox's)after a restart (the row says "restart")
GraphicsAnti-Aliasing, Anisotropic Filtering, Square Pixels, Car ReflectionsOn/Off, Off-16xat once
Draw DistanceNormal (the original), Far (x2)at once
GammaOriginal, Modern (brighter), Warmat once
EffectsBloom (default), Bloom + Ambient Occlusion, Offat once
Motion BlurOff (default), Onat once
AudioMaster Volume0-100% (50% default)at once
InputVibrationOff, 10-100%at once
Keyboard as ControllerWithout a controller (default), Always, Offafter a restart
AdvancedPerformance Overlayframes per second and the slowest frame, top leftat once (also Cmd+Option+F)
Logsopens the logs folder in Finder

Resolution Scale, the Graphics on/off rows and Vibration are the same settings as the game's own Options > Video and Options > Gameplay; changing them in either place changes both. The game's own sliders for music, speech and effects are in its Options > Audio.

Saving and quitting

The game saves the way it always did: in its menus (Career saves, profiles). To quit, use Quit Game in the settings menu (it asks first), Cmd+Q, or close the window. Progress since your last save in the game is lost, as when an Xbox is switched off.

Your files

Everything is in ~/Library/Application Support/NFS Underground 2/:

FolderWhat
game/the disc's files, and the game's saves (UDATA/)
player/settings.ini (the settings menu), nfsu2x_options.txt (the game's Options rows)
saves/, cache/the runtime's
logs/nfsu2.log (the last five runs) and install.log

To remove the game, delete NFS Underground 2 from Applications and this folder.

Screenshots

The freeway into the city at night, 119 fpsThe Bayview sign above the freeway
The freeway at night, 120 fps (the counter top left)The Bayview sign
Nitrous at 158 mph with motion blurThe plaza with its fountains, in free roam
Nitrous at 158 mph, with motion blurThe plaza's fountains, in free roam
The settings menu, Display pageThe settings menu, Graphics page
The settings menu: DisplayThe settings menu: Graphics

Taken on an M1 Pro (3456 x 2234), Resolution Scale 4x.

How it works

The Xbox runs the game's program, an x86 file called default.xbe, on an Intel CPU with Microsoft's kernel and an NVIDIA graphics chip. A Mac has none of these, so:

  • The program is translated once. A translator written in Python (xboxrecomp's) reads default.xbe, finds its functions (about 20,000) and writes each as a C function. Apple's compiler turns that C into ARM code for your Mac. This happens on your Mac, from your disc, when you install: the download holds none of the game.
  • A runtime stands in for the Xbox. What the game asked of the Xbox's kernel (threads, files, saves, timers) is done by xboxrecomp's runtime with macOS. The memory layout is the Xbox's own, so the game's pointers work unchanged.
  • Graphics: the game still talks to the Xbox's graphics chip (it writes the chip's command lists). The runtime reads those commands and nfsu2-ios's Metal renderer draws them on your Mac's GPU, at a higher resolution, then cuts the picture to 16:10. NFSU2Deadware's code adds bloom, ambient occlusion and the frame pacing there.
  • Sound: the Xbox's audio chip is emulated (code from the xemu emulator) and played through SDL.
  • Hand-written parts: a few dozen functions are replaced by hand (nfsu2-sw): the movie decoder, the frame-rate limit, the extra rows in the game's Options, and the places where a straight translation of the Xbox code doesn't work.

Architecture

From your disc to the app (once, when you install)
flowchart LR
    ISO["your disc image<br/>(Xbox, USA)"] -->|"import, SHA-1 check"| GAME["the disc's files<br/>Application Support"]
    GAME -->|"default.xbe"| LIFT["xboxrecomp's translator<br/>(Python + Capstone)"]
    LIFT --> C["the game's code as C<br/>83 files"]
    C --> CLANG["clang<br/>(Command Line Tools)"]
    KIT["installer kit: the runtime, the Mac host<br/>and the settings menu, compiled; SDL"] --> CLANG
    CLANG --> APP["NFS Underground 2.app<br/>(icon from the disc's title image)"]
While you play
flowchart TB
    subgraph mac["Mac host (engine/src/apple, engine/src/overlay)"]
        EV["main thread: window, keyboard,<br/>controllers (SDL)"]
        MENU["settings menu (Dear ImGui)"]
        PLAYER["player folder, settings.ini"]
    end
    subgraph game["the game (translated to C)"]
        CODE["the game's functions<br/>+ hand-written overrides (nfsu2-sw)"]
    end
    subgraph runtime["Xbox runtime (xboxrecomp)"]
        KRN["kernel: threads, files, saves, timers"]
        PAD["controller (USB pad)"]
        APU["audio chip (from xemu)"]
        PB["graphics command lists"]
    end
    EV --> PAD --> CODE
    EV -->|"Back+Start, F1"| MENU
    CODE --> KRN
    CODE --> APU --> OUT["SDL sound"]
    CODE --> PB --> MTL["Metal renderer (nfsu2-ios)<br/>+ effects (NFSU2Deadware)"]
    MENU -->|"drawn over the frame"| MTL
    MTL --> SCREEN["your screen"]
The repository
FolderWhat
engine/everything the game is built from: the runtime (xboxrecomp/), the game's overrides and the Mac host (src/), the settings menu (src/overlay/), Dear ImGui and the font (third_party/)
installer/, mac/the installer app and the scripts it runs on the player's Mac (import, build, icon, app)
tools/for developers: dependencies, release build, boot check, play, the installer kit and DMG, publish check
tests/dmg_no_game_code.sh: the DMG holds no game code or data
docs/how the port was made, how engine/ was put together (upstream-patches/), screenshots

Everything the port is built from is in this repository; nothing is downloaded at build time but SDL's pinned source and Capstone (pip). The repository and the DMG hold no game files and no translated code.

Build from source (macOS, Apple Silicon)
brew install cmake ninja
python3 -m venv .venv && .venv/bin/pip install 'capstone<6'
python3 mac/import_disc.py <your .iso> game/extracted   # your disc's files
tools/build_deps.sh                   # SDL3 + sdl2-compat for macOS 15+ -> build/deps
tools/build_release.sh                # translate (engine/gen) + build -> build/release/nfsu2_recomp
tools/relift.sh                       # re-translate after a seed change, check the stubs (stubcheck.py), build
tools/smoke.sh                        # boot check: 75 s, START presses, the settings menu, the last frame not black
tools/play.sh                         # play this build (its own player folder)
tools/make_dmg.sh                     # the installer DMG, checked by tests/dmg_no_game_code.sh

Diagnostics. Environment variables: NFSU2_GAME_DIR=<folder> (the game's files; no player folder then), NFSU2_FPS_CAP=30|60|120 (wins over the menu for that run), RECOMP_FPS_LOG=1, RECOMP_GL_DUMP=<prefix>,<frames> (frame dumps), NFSU2_SMOKE_SECONDS=<n>, NFSU2_OVERLAY_SCRIPT="<s>:open,<s>:next,..." with NFSU2_OVERLAY_SHOT=<prefix> (scripted menu steps and screenshots). The installer: NFSU2_IMPORT_ISO=<iso>, NFSU2_INSTALL_DIR=<folder>, NFSU2_NO_UI=1.

Thanks

To everyone whose work this is built on:

ProjectAuthorWhat it gives this portLicense
nfsu2-swantoxa2584x (Anton Artemov)the game's translation and everything it needs to run: seeds, overrides, the Options rows, moviesno license file; used here with credit, under this project's GPL-3.0-or-later
nfsu2-iosmyUdav4iikthe Apple host and the Metal rendererno license file; as above
xboxrecompsp00nzthe Xbox translator and runtimeMIT
xemuxemu teamthe audio chip and graphics parts in xboxrecompLGPL-2.1-or-later
NFSU2DeadwareLeoDeadwarethe Mac engine patches (frame rate, 16:10, resolution, effects), the installer's idea, kit, import and iconMIT
SpeedBreakerproject(u)the idea and the style of these Mac ports, the settings menu's designGPL-3.0
Dear ImGuiOmar Cornutdraws the settings menuMIT
RobotoGooglethe settings menu's fontApache-2.0
CapstoneCapstone teamreads the x86 code for the translatorBSD-3-Clause
SDL, sdl2-compatSDL teamwindow, input, controllers, soundZlib

The license texts are in LICENSES/ and in the installer (Contents/Resources/kit/licenses/); details in THIRD_PARTY_NOTICES.md.

License

GPL-3.0-or-later (LICENSE, NOTICE). The files of nfsu2-sw and nfsu2-ios keep their authorship; how engine/ was made from them is in docs/upstream-patches/, and later changes are in this repository's history. If you reuse this code, keep the credit to those projects and their links, as we do. NFSU2Deadware's patches and scripts stay under the MIT License, xboxrecomp's xemu parts under the LGPL-2.1 (the installer links them on your Mac, so they can be relinked with your own versions).

Legal notice

Unofficial fan project, not affiliated with or endorsed by Electronic Arts or Microsoft. Need for Speed and Underground are trademarks of Electronic Arts Inc.; Xbox is a trademark of Microsoft. This repository and its releases contain no game code and no game data: you need your own legally obtained copy of the game, and the game is built from it on your own Mac.