# thephrozenkeep/d2moo architecture

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

- Interactive diagram: https://gitdiagram.com/thephrozenkeep/d2moo
- Repository: https://github.com/thephrozenkeep/d2moo

## Overview

#### Purpose and execution model
D2MOO is a Windows C++ reimplementation of Diablo II DLL functionality, primarily version 1.10f, coupled to Detours-based runtime patching for modding. It requires original game binaries/assets; it is not a standalone game. The executable-side entry point is `source/Game/src/Main.cpp`; rebuilt subsystem DLLs expose original-style ordinals, while patch DLLs intercept selected functions in the original process.

#### Build, deployment, and patch boundary
CMake composes the DLL projects, launcher/debug setup, external dependencies, and patch targets: `CMakeLists.txt`, `source/CMakeLists.txt`, `D2.Detours.patches/CMakeLists.txt`. `external/D2.Detours` is the central runtime-hooking dependency. Patch definitions are version-specific and map hooks to game modules, notably `D2.Detours.patches/1.10f/D2Common.patch.cpp` and `D2.Detours.patches/1.10f/D2Game.patch.cpp`. Direct replacement is intended only provisionally for D2Common; other rebuilt DLLs are generally consumed through patches.

#### Shared ABI and platform foundation
`source/D2CommonDefinitions/include` establishes cross-module primitive types, constants, DLL/import metadata, build configuration, packets, and reconstructed layouts. `source/Fog` supplies shared runtime services—memory, errors/logging, strings, queues/sockets, file-format support, and system abstractions—used as the lower-level compatibility layer. Key paths: `source/D2CommonDefinitions/include/D2Dll.h`, `source/Fog/src/Fog.cpp`, `source/Fog/src/Mem/Mem.cpp`.

#### Core game simulation: D2Common
D2Common is the largest reusable gameplay/data layer and the most mature replacement target. It owns data-table loading and lookup, unit/item/stat state, collision and dungeon generation, random seeds, paths, quests, and text. Its flow is data tables and world state → unit/path/dungeon operations → D2Game orchestration. Key paths: `source/D2Common/src/DataTbls/DataTbls.cpp`, `source/D2Common/src/Drlg/DrlgDrlg.cpp`, `source/D2Common/src/Path/AStar.cpp`.

#### Game orchestration: D2Game
D2Game implements server/gameplay-side lifecycle and updates: game/client/task/event control, unit creation and messaging, player progression/save/trade, monster spawning/AI, items, missiles, skills, objects, and per-act quests. It consumes D2Common structures/tables and emits gameplay state and packet-oriented behavior. Key paths: `source/D2Game/src/GAME/Game.cpp`, `source/D2Game/src/UNIT/SUnit.cpp`, `source/D2Game/src/AI/AiThink.cpp`.

#### Client-facing compatibility modules
Several reconstructed DLLs represent game-facing boundaries rather than a single application UI: rendering and tile/textures (`source/D2Gfx/src/D2Gfx.cpp`, `source/D2CMP/src/D2CMP.cpp`); interface controls/resources (`source/D2Win/src/D2WinMain.cpp`); localization/string tables (`source/D2Lang/src/D2StrTable.cpp`); archive/file access (`source/D2Hell/src/Archive.cpp`, `source/Storm/src/Storm.cpp`); and network client/server packet surfaces (`source/D2Net/src/Client.cpp`, `source/D2Net/src/Server.cpp`). These preserve DLL APIs around original assets and game process behavior.

#### Debugging and observability
An optional injected debugger is enabled by `-debug` or `D2_DEBUGGER=1`. It is a D3D9/ImGui overlay integrated through patch hooks, not a separate service. Key paths: `source/D2Debugger/src/D2Debugger.cpp`, `source/D2Debugger/src/D2Debugger.imgui.d3d9.cpp`, `D2.Detours.patches/1.10f/D2Debugger.patch.cpp`. External UI dependencies include `external/imgui`; no cloud infrastructure or hosted service is present.

Main entry points: [`D2.Detours.patches/1.10f/D2Game.patch.cpp`](https://github.com/thephrozenkeep/d2moo/blob/master/D2.Detours.patches/1.10f/D2Game.patch.cpp) (1.10f patch DLLs), [`source/D2Common/src/Drlg/DrlgDrlg.cpp`](https://github.com/thephrozenkeep/d2moo/blob/master/source/D2Common/src/Drlg/DrlgDrlg.cpp) (World, paths & dungeons), [`CMakeLists.txt`](https://github.com/thephrozenkeep/d2moo/blob/master/CMakeLists.txt) (CMake build), [`source/D2Game/src/GAME/Game.cpp`](https://github.com/thephrozenkeep/d2moo/blob/master/source/D2Game/src/GAME/Game.cpp) (Game lifecycle)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_build["Build &amp; Injection"]
  node_cmake["CMake build<br/>build orchestration<br/>[CMakeLists.txt]"]
  node_detours{{"Detours runtime<br/>hooking dependency<br/>[D2.Detours]"}}
  node_patches["1.10f patch DLLs<br/>versioned hooks<br/>[D2Game.patch.cpp]"]
  node_game_process{{"Original game process<br/>host runtime"}}
  node_debugger["Injected debug overlay<br/>D3D9 ImGui debugger<br/>[D2Debugger.cpp]"]
end

subgraph group_foundation["Shared Foundation"]
  node_abi["Shared DLL ABI<br/>layouts and exports<br/>[D2Dll.h]"]
  node_fog["Fog runtime services<br/>compatibility runtime<br/>[Fog.cpp]"]
end

subgraph group_simulation["Game Simulation"]
  node_data_tables[("Data tables<br/>game data loading<br/>[DataTbls.cpp]")]
  node_world_sim["World, paths &amp; dungeons<br/>D2Common simulation<br/>[DrlgDrlg.cpp]"]
  node_d2game_lifecycle["Game lifecycle<br/>D2Game orchestration<br/>[Game.cpp]"]
  node_gameplay_systems["Gameplay systems<br/>D2Game rules<br/>[AiThink.cpp]"]
end

subgraph group_compat["Compatibility DLLs"]
  node_rendering["Rendering &amp; assets<br/>graphics DLLs<br/>[D2Gfx.cpp]"]
  node_ui["Game interface<br/>UI DLL<br/>[D2WinMain.cpp]"]
  node_localization["Localization<br/>string-table DLL<br/>[D2StrTable.cpp]"]
  node_archive_io["Archive &amp; file access<br/>storage DLLs<br/>[Archive.cpp]"]
  node_network["Network packet surface<br/>network DLL<br/>[Client.cpp]"]
end

node_cmake -->|"builds with"| node_detours
node_cmake -->|"builds"| node_patches
node_cmake -->|"builds"| node_fog
node_cmake -->|"builds replacement"| node_world_sim
node_cmake -->|"builds replacement"| node_d2game_lifecycle
node_patches -->|"uses"| node_detours
node_patches -->|"injects into"| node_game_process
node_patches -.->|"hooks D2Common"| node_world_sim
node_patches -.->|"hooks D2Game"| node_d2game_lifecycle
node_abi -->|"shared ABI"| node_fog
node_abi -->|"shared ABI"| node_world_sim
node_abi -->|"shared ABI"| node_d2game_lifecycle
node_fog -->|"runtime services"| node_data_tables
node_fog -->|"runtime services"| node_world_sim
node_data_tables -->|"data and text"| node_world_sim
node_world_sim -->|"world state"| node_d2game_lifecycle
node_d2game_lifecycle -->|"updates"| node_gameplay_systems
node_gameplay_systems -->|"packet-oriented state"| node_network
node_archive_io -->|"game resources"| node_data_tables
node_archive_io -->|"assets"| node_rendering
node_localization -->|"strings"| node_ui
node_rendering -->|"game-facing API"| node_game_process
node_ui -->|"game-facing API"| node_game_process
node_network -->|"game-facing API"| node_game_process
node_debugger -->|"overlay hook"| node_patches
node_debugger -->|"renders in process"| node_game_process

click node_cmake "https://github.com/thephrozenkeep/d2moo/blob/master/CMakeLists.txt"
click node_detours "https://github.com/thephrozenkeep/d2moo/blob/master/external/D2.Detours"
click node_patches "https://github.com/thephrozenkeep/d2moo/blob/master/D2.Detours.patches/1.10f/D2Game.patch.cpp"
click node_abi "https://github.com/thephrozenkeep/d2moo/blob/master/source/D2CommonDefinitions/include/D2Dll.h"
click node_fog "https://github.com/thephrozenkeep/d2moo/blob/master/source/Fog/src/Fog.cpp"
click node_data_tables "https://github.com/thephrozenkeep/d2moo/blob/master/source/D2Common/src/DataTbls/DataTbls.cpp"
click node_world_sim "https://github.com/thephrozenkeep/d2moo/blob/master/source/D2Common/src/Drlg/DrlgDrlg.cpp"
click node_d2game_lifecycle "https://github.com/thephrozenkeep/d2moo/blob/master/source/D2Game/src/GAME/Game.cpp"
click node_gameplay_systems "https://github.com/thephrozenkeep/d2moo/blob/master/source/D2Game/src/AI/AiThink.cpp"
click node_rendering "https://github.com/thephrozenkeep/d2moo/blob/master/source/D2Gfx/src/D2Gfx.cpp"
click node_ui "https://github.com/thephrozenkeep/d2moo/blob/master/source/D2Win/src/D2WinMain.cpp"
click node_localization "https://github.com/thephrozenkeep/d2moo/blob/master/source/D2Lang/src/D2StrTable.cpp"
click node_archive_io "https://github.com/thephrozenkeep/d2moo/blob/master/source/D2Hell/src/Archive.cpp"
click node_network "https://github.com/thephrozenkeep/d2moo/blob/master/source/D2Net/src/Client.cpp"
click node_debugger "https://github.com/thephrozenkeep/d2moo/blob/master/source/D2Debugger/src/D2Debugger.cpp"

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_cmake,node_detours,node_patches,node_game_process,node_debugger toneBlue
class node_abi,node_fog toneAmber
class node_data_tables,node_world_sim,node_d2game_lifecycle,node_gameplay_systems toneMint
class node_rendering,node_ui,node_localization,node_archive_io,node_network toneRose
```

## Components

### Build & Injection

- [CMake build](https://github.com/thephrozenkeep/d2moo/blob/master/CMakeLists.txt): build orchestration · Builds replacement DLLs, patch targets, and launcher setup. · `CMakeLists.txt`
- [Detours runtime](https://github.com/thephrozenkeep/d2moo/blob/master/external/D2.Detours): hooking dependency · Runtime interception layer used by patch DLLs. · `external/D2.Detours`
- [1.10f patch DLLs](https://github.com/thephrozenkeep/d2moo/blob/master/D2.Detours.patches/1.10f/D2Game.patch.cpp): versioned hooks · Maps replacement hooks into original game modules. · `D2.Detours.patches/1.10f/D2Game.patch.cpp`
- **Original game process**: host runtime · Supplies required original binaries and assets.
- [Injected debug overlay](https://github.com/thephrozenkeep/d2moo/blob/master/source/D2Debugger/src/D2Debugger.cpp): D3D9 ImGui debugger · Optional -debug or D2_DEBUGGER=1 observability overlay. · `source/D2Debugger/src/D2Debugger.cpp`

### Shared Foundation

- [Shared DLL ABI](https://github.com/thephrozenkeep/d2moo/blob/master/source/D2CommonDefinitions/include/D2Dll.h): layouts and exports · Defines cross-module types, packets, layouts, and import metadata. · `source/D2CommonDefinitions/include/D2Dll.h`
- [Fog runtime services](https://github.com/thephrozenkeep/d2moo/blob/master/source/Fog/src/Fog.cpp): compatibility runtime · Provides memory, logging, strings, queues, sockets, and system abstractions. · `source/Fog/src/Fog.cpp`

### Game Simulation

- [Data tables](https://github.com/thephrozenkeep/d2moo/blob/master/source/D2Common/src/DataTbls/DataTbls.cpp): game data loading · Loads and looks up game tables and text data. · `source/D2Common/src/DataTbls/DataTbls.cpp`
- [World, paths & dungeons](https://github.com/thephrozenkeep/d2moo/blob/master/source/D2Common/src/Drlg/DrlgDrlg.cpp): D2Common simulation · Maintains units, stats, collision, RNG, paths, and dungeon generation. · `source/D2Common/src/Drlg/DrlgDrlg.cpp`
- [Game lifecycle](https://github.com/thephrozenkeep/d2moo/blob/master/source/D2Game/src/GAME/Game.cpp): D2Game orchestration · Coordinates games, clients, tasks, events, units, and messaging. · `source/D2Game/src/GAME/Game.cpp`
- [Gameplay systems](https://github.com/thephrozenkeep/d2moo/blob/master/source/D2Game/src/AI/AiThink.cpp): D2Game rules · Implements progression, items, skills, monsters, AI, missiles, and quests. · `source/D2Game/src/AI/AiThink.cpp`

### Compatibility DLLs

- [Rendering & assets](https://github.com/thephrozenkeep/d2moo/blob/master/source/D2Gfx/src/D2Gfx.cpp): graphics DLLs · Provides rendering, tiles, textures, and compositing APIs. · `source/D2Gfx/src/D2Gfx.cpp`
- [Game interface](https://github.com/thephrozenkeep/d2moo/blob/master/source/D2Win/src/D2WinMain.cpp): UI DLL · Provides interface controls and resources. · `source/D2Win/src/D2WinMain.cpp`
- [Localization](https://github.com/thephrozenkeep/d2moo/blob/master/source/D2Lang/src/D2StrTable.cpp): string-table DLL · Exposes localized string-table APIs. · `source/D2Lang/src/D2StrTable.cpp`
- [Archive & file access](https://github.com/thephrozenkeep/d2moo/blob/master/source/D2Hell/src/Archive.cpp): storage DLLs · Reads game archives and file resources. · `source/D2Hell/src/Archive.cpp`
- [Network packet surface](https://github.com/thephrozenkeep/d2moo/blob/master/source/D2Net/src/Client.cpp): network DLL · Provides client/server packet compatibility APIs. · `source/D2Net/src/Client.cpp`

## Connections

- CMake build → Detours runtime: builds with
- CMake build → 1.10f patch DLLs: builds
- CMake build → Fog runtime services: builds
- CMake build → World, paths & dungeons: builds replacement
- CMake build → Game lifecycle: builds replacement
- 1.10f patch DLLs → Detours runtime: uses
- 1.10f patch DLLs → Original game process: injects into
- 1.10f patch DLLs → World, paths & dungeons: hooks D2Common
- 1.10f patch DLLs → Game lifecycle: hooks D2Game
- Shared DLL ABI → Fog runtime services: shared ABI
- Shared DLL ABI → World, paths & dungeons: shared ABI
- Shared DLL ABI → Game lifecycle: shared ABI
- Fog runtime services → Data tables: runtime services
- Fog runtime services → World, paths & dungeons: runtime services
- Data tables → World, paths & dungeons: data and text
- World, paths & dungeons → Game lifecycle: world state
- Game lifecycle → Gameplay systems: updates
- Gameplay systems → Network packet surface: packet-oriented state
- Archive & file access → Data tables: game resources
- Archive & file access → Rendering & assets: assets
- Localization → Game interface: strings
- Rendering & assets → Original game process: game-facing API
- Game interface → Original game process: game-facing API
- Network packet surface → Original game process: game-facing API
- Injected debug overlay → 1.10f patch DLLs: overlay hook
- Injected debug overlay → Original game process: renders in process
