# talhamudo/nfsu2recomp architecture

> Architecture diagram of the GitHub repository talhamudo/nfsu2recomp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/talhamudo/nfsu2recomp
- Repository: https://github.com/talhamudo/nfsu2recomp

## Overview

NFSU2Recomp is a native Apple Silicon port of Need for Speed: Underground 2, combining an ahead-of-time x86-to-C lifter with a runtime that emulates the game’s Win32 and DirectX-facing interfaces. The player selects a game installation and options in the launcher, then starts the engine; lifted game code runs through runtime services for memory, system APIs, graphics, input and audio. The launcher also supports mods, portable copies and save management. Some runtime files are unsampled, so those subsystem links rely on README descriptions rather than inspected call sites.

Main entry points: [`launcher/Model.swift`](https://github.com/talhamudo/nfsu2recomp/blob/main/launcher/Model.swift) (Launcher model), [`runtime/dispatch.c`](https://github.com/talhamudo/nfsu2recomp/blob/main/runtime/dispatch.c) (Call dispatch and thunks), [`runtime/boot.c`](https://github.com/talhamudo/nfsu2recomp/blob/main/runtime/boot.c) (Engine entry), [`launcher/main.swift`](https://github.com/talhamudo/nfsu2recomp/blob/main/launcher/main.swift) (Launcher UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_launcher["Launcher and player setup"]
  node_launcher_ui["Launcher UI<br/>[main.swift]"]
  node_launcher_model["Launcher model<br/>[Model.swift]"]
  node_game_install["Game discovery<br/>[Game.swift]"]
  node_settings["Settings<br/>[Settings.swift]"]
  node_mods["Mod management<br/>[Mods.swift]"]
  node_portable["Portable copy<br/>[Portable.swift]"]
  node_save_management[("Save management<br/>[SaveStore.swift]")]
  node_save_archive["Save archives and views<br/>[SaveArchive.swift]"]
end

subgraph group_translation["Static translation"]
  node_function_discovery["Function discovery<br/>[genall.py]"]
  node_x86_lifter["x86-to-C lifter<br/>[lift.py]"]
  node_lifted_game["Generated game code<br/>[genall.py]"]
end

subgraph group_runtime["Native game runtime"]
  node_engine_boot["Engine entry<br/>[boot.c]"]
  node_cpu_memory["CPU and guest memory<br/>[cpu.h]"]
  node_dispatch["Call dispatch and thunks<br/>[dispatch.c]"]
  node_win32["Win32 services<br/>[win32.c]"]
  node_file_resources["Files and resources<br/>[fileio.c]"]
  node_graphics_com["Direct3D COM bridge<br/>[com.c]"]
  node_shader_effects["Shader and effects support<br/>[d3dx_hle.c]"]
  node_input["Controller input<br/>[xtinput.c]"]
  node_audio_input_com["Audio and input COM<br/>[vsemu.c]"]
end

subgraph group_extensions["Game extensions"]
  node_enhancements["HD enhancements<br/>[enhance.c]"]
end

node_player(("Player"))
node_game_files["Player game installation"]

node_player -->|"opens"| node_launcher_ui
node_launcher_ui -->|"uses"| node_launcher_model
node_launcher_model -->|"checks installation"| node_game_install
node_launcher_model -->|"loads options"| node_settings
node_launcher_model -->|"manages mods"| node_mods
node_launcher_model -->|"creates copy"| node_portable
node_launcher_model -.->|"manages saves"| node_save_management
node_save_management -.->|"archives saves"| node_save_archive
node_game_files -->|"is selected"| node_game_install
node_launcher_ui -->|"starts engine"| node_engine_boot
node_function_discovery -->|"invokes"| node_x86_lifter
node_x86_lifter -->|"translates functions"| node_lifted_game
node_lifted_game -->|"runs in"| node_engine_boot
node_engine_boot -->|"initializes guest"| node_cpu_memory
node_engine_boot -->|"runs guest code"| node_dispatch
node_dispatch -->|"accesses state"| node_cpu_memory
node_dispatch -->|"dispatches APIs"| node_win32
node_win32 -.->|"uses file services"| node_file_resources
node_dispatch -->|"dispatches COM calls"| node_graphics_com
node_graphics_com -->|"uses effect HLE"| node_shader_effects
node_graphics_com -.->|"enables HD features"| node_enhancements
node_dispatch -.->|"routes input"| node_input
node_dispatch -.->|"dispatches COM calls"| node_audio_input_com

click node_launcher_ui "https://github.com/talhamudo/nfsu2recomp/blob/main/launcher/main.swift"
click node_launcher_model "https://github.com/talhamudo/nfsu2recomp/blob/main/launcher/Model.swift"
click node_game_install "https://github.com/talhamudo/nfsu2recomp/blob/main/launcher/Game.swift"
click node_settings "https://github.com/talhamudo/nfsu2recomp/blob/main/launcher/Settings.swift"
click node_mods "https://github.com/talhamudo/nfsu2recomp/blob/main/launcher/Mods.swift"
click node_portable "https://github.com/talhamudo/nfsu2recomp/blob/main/launcher/Portable.swift"
click node_save_management "https://github.com/talhamudo/nfsu2recomp/blob/main/launcher/SaveStore.swift"
click node_save_archive "https://github.com/talhamudo/nfsu2recomp/blob/main/launcher/SaveArchive.swift"
click node_function_discovery "https://github.com/talhamudo/nfsu2recomp/blob/main/tools/lifter/genall.py"
click node_x86_lifter "https://github.com/talhamudo/nfsu2recomp/blob/main/tools/lifter/lift.py"
click node_lifted_game "https://github.com/talhamudo/nfsu2recomp/blob/main/tools/lifter/genall.py"
click node_engine_boot "https://github.com/talhamudo/nfsu2recomp/blob/main/runtime/boot.c"
click node_cpu_memory "https://github.com/talhamudo/nfsu2recomp/blob/main/runtime/cpu.h"
click node_dispatch "https://github.com/talhamudo/nfsu2recomp/blob/main/runtime/dispatch.c"
click node_win32 "https://github.com/talhamudo/nfsu2recomp/blob/main/runtime/win32.c"
click node_file_resources "https://github.com/talhamudo/nfsu2recomp/blob/main/runtime/fileio.c"
click node_graphics_com "https://github.com/talhamudo/nfsu2recomp/blob/main/runtime/com.c"
click node_shader_effects "https://github.com/talhamudo/nfsu2recomp/blob/main/runtime/d3dx_hle.c"
click node_input "https://github.com/talhamudo/nfsu2recomp/blob/main/runtime/xtinput.c"
click node_audio_input_com "https://github.com/talhamudo/nfsu2recomp/blob/main/runtime/vsemu.c"
click node_enhancements "https://github.com/talhamudo/nfsu2recomp/blob/main/runtime/enhance.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_launcher_ui,node_launcher_model,node_game_install,node_settings,node_mods,node_portable,node_save_management,node_save_archive toneBlue
class node_function_discovery,node_x86_lifter,node_lifted_game toneAmber
class node_engine_boot,node_cpu_memory,node_dispatch,node_win32,node_file_resources,node_graphics_com,node_shader_effects,node_input,node_audio_input_com toneMint
class node_enhancements toneRose
class node_player,node_game_files toneIndigo
```

## Components

### Launcher and player setup

- [Launcher UI](https://github.com/talhamudo/nfsu2recomp/blob/main/launcher/main.swift): `launcher/main.swift`
- [Launcher model](https://github.com/talhamudo/nfsu2recomp/blob/main/launcher/Model.swift): `launcher/Model.swift`
- [Game discovery](https://github.com/talhamudo/nfsu2recomp/blob/main/launcher/Game.swift): `launcher/Game.swift`
- [Settings](https://github.com/talhamudo/nfsu2recomp/blob/main/launcher/Settings.swift): `launcher/Settings.swift`
- [Mod management](https://github.com/talhamudo/nfsu2recomp/blob/main/launcher/Mods.swift): `launcher/Mods.swift`
- [Portable copy](https://github.com/talhamudo/nfsu2recomp/blob/main/launcher/Portable.swift): `launcher/Portable.swift`
- [Save management](https://github.com/talhamudo/nfsu2recomp/blob/main/launcher/SaveStore.swift): `launcher/SaveStore.swift`
- [Save archives and views](https://github.com/talhamudo/nfsu2recomp/blob/main/launcher/SaveArchive.swift): `launcher/SaveArchive.swift`

### Static translation

- [Function discovery](https://github.com/talhamudo/nfsu2recomp/blob/main/tools/lifter/genall.py): `tools/lifter/genall.py`
- [x86-to-C lifter](https://github.com/talhamudo/nfsu2recomp/blob/main/tools/lifter/lift.py): `tools/lifter/lift.py`
- [Generated game code](https://github.com/talhamudo/nfsu2recomp/blob/main/tools/lifter/genall.py): `tools/lifter/genall.py`

### Native game runtime

- [Engine entry](https://github.com/talhamudo/nfsu2recomp/blob/main/runtime/boot.c): `runtime/boot.c`
- [CPU and guest memory](https://github.com/talhamudo/nfsu2recomp/blob/main/runtime/cpu.h): `runtime/cpu.h`
- [Call dispatch and thunks](https://github.com/talhamudo/nfsu2recomp/blob/main/runtime/dispatch.c): `runtime/dispatch.c`
- [Win32 services](https://github.com/talhamudo/nfsu2recomp/blob/main/runtime/win32.c): `runtime/win32.c`
- [Files and resources](https://github.com/talhamudo/nfsu2recomp/blob/main/runtime/fileio.c): `runtime/fileio.c`
- [Direct3D COM bridge](https://github.com/talhamudo/nfsu2recomp/blob/main/runtime/com.c): `runtime/com.c`
- [Shader and effects support](https://github.com/talhamudo/nfsu2recomp/blob/main/runtime/d3dx_hle.c): `runtime/d3dx_hle.c`
- [Controller input](https://github.com/talhamudo/nfsu2recomp/blob/main/runtime/xtinput.c): `runtime/xtinput.c`
- [Audio and input COM](https://github.com/talhamudo/nfsu2recomp/blob/main/runtime/vsemu.c): `runtime/vsemu.c`

### Game extensions

- [HD enhancements](https://github.com/talhamudo/nfsu2recomp/blob/main/runtime/enhance.c): `runtime/enhance.c`

### Other components

- **Player**
- **Player game installation**

## Connections

- Player → Launcher UI: opens
- Launcher UI → Launcher model: uses (evidence: `launcher/main.swift`)
- Launcher model → Game discovery: checks installation (evidence: `launcher/Model.swift`)
- Launcher model → Settings: loads options (evidence: `launcher/Model.swift`)
- Launcher model → Mod management: manages mods (evidence: `launcher/Model.swift`)
- Launcher model → Portable copy: creates copy (evidence: `launcher/Model.swift`)
- Launcher model → Save management: manages saves
- Save management → Save archives and views: archives saves
- Player game installation → Game discovery: is selected
- Launcher UI → Engine entry: starts engine
- Function discovery → x86-to-C lifter: invokes (evidence: `tools/lifter/genall.py`)
- x86-to-C lifter → Generated game code: translates functions (evidence: `tools/lifter/genall.py`)
- Generated game code → Engine entry: runs in
- Engine entry → CPU and guest memory: initializes guest
- Engine entry → Call dispatch and thunks: runs guest code
- Call dispatch and thunks → CPU and guest memory: accesses state
- Call dispatch and thunks → Win32 services: dispatches APIs
- Win32 services → Files and resources: uses file services
- Call dispatch and thunks → Direct3D COM bridge: dispatches COM calls
- Direct3D COM bridge → Shader and effects support: uses effect HLE (evidence: `runtime/com.c`)
- Direct3D COM bridge → HD enhancements: enables HD features
- Call dispatch and thunks → Controller input: routes input
- Call dispatch and thunks → Audio and input COM: dispatches COM calls
