# volpestyle/kh2-multiplayer architecture

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

- Interactive diagram: https://gitdiagram.com/volpestyle/kh2-multiplayer
- Repository: https://github.com/volpestyle/kh2-multiplayer

## Overview

KH2 Multiplayer is a Kingdom Hearts II co-op mod: each player streams their own character, while the host owns shared enemies, rooms, and story state. The principal path runs from game hooks and bridges through the runtime’s network client to a session relay, then back to each runtime to apply remote-player and enemy state. The README documents the gameplay authority model and supported features; source-index references support selected internal links. Unsampled modules are included only where the README or tree identifies a meaningful subsystem, so some internal flows are omitted.

Main entry points: [`runtime/src/RuntimeMain.cpp`](https://github.com/volpestyle/kh2-multiplayer/blob/main/runtime/src/RuntimeMain.cpp) (Runtime orchestration), [`common/src/NetworkClient.cpp`](https://github.com/volpestyle/kh2-multiplayer/blob/main/common/src/NetworkClient.cpp) (Network client), [`server/src/SessionHost.cpp`](https://github.com/volpestyle/kh2-multiplayer/blob/main/server/src/SessionHost.cpp) (Session relay), [`runtime/src/GameBridgePC.cpp`](https://github.com/volpestyle/kh2-multiplayer/blob/main/runtime/src/GameBridgePC.cpp) (PC game bridge)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_game["Game integration"]
  node_inject["Inject hooks<br/>[DllMain.cpp]"]
  node_bridge["PC game bridge<br/>[GameBridgePC.cpp]"]
  node_runtime["Runtime orchestration<br/>[RuntimeMain.cpp]"]
end

subgraph group_sync["Gameplay synchronization"]
  node_avatar["Avatar bridge<br/>[AvatarBridge.hpp]"]
  node_input["Input mailbox<br/>[InputMailbox.hpp]"]
  node_replicas["Replica application"]
  node_combat["Enemy and combat sync<br/>[EnemySync.cpp]"]
end

subgraph group_network["Network session"]
  node_protocol["Message protocol<br/>[Protocol.hpp]"]
  node_codec["Packet codec<br/>[Codec.hpp]"]
  node_client["Network client<br/>[NetworkClient.cpp]"]
  node_transport["Transport<br/>[Transport.hpp]"]
  node_relay["Session relay<br/>[SessionHost.cpp]"]
end

subgraph group_world["World and recovery"]
  node_progress["Progress mirroring<br/>[ProgressMirror.hpp]"]
  node_resync["World resync<br/>[ResyncProtocol.hpp]"]
  node_recovery["Client recovery<br/>[ClientRecovery.hpp]"]
end

subgraph group_diagnostics["Diagnostics"]
  node_desync["Desync collection"]
  node_capture["Relay capture<br/>[DesyncCapture.cpp]"]
end

node_player(("Player"))
node_kh2["KH2 process"]

node_player -->|"plays locally"| node_kh2
node_inject -->|"hooks"| node_kh2
node_bridge -->|"bridges memory"| node_kh2
node_runtime -->|"uses"| node_bridge
node_runtime -->|"pumps"| node_client
node_runtime -->|"streams avatars"| node_avatar
node_runtime -->|"exchanges input"| node_input
node_runtime -->|"applies snapshots"| node_replicas
node_replicas -->|"applies state"| node_bridge
node_client -->|"encodes packets"| node_codec
node_client -->|"sends traffic"| node_transport
node_client -->|"connects"| node_relay
node_relay -->|"forwards traffic"| node_client
node_relay -->|"version-gates"| node_protocol
node_client -->|"exchanges messages"| node_protocol
node_runtime -->|"synchronizes combat"| node_combat
node_runtime -->|"syncs progress"| node_progress
node_runtime -->|"requests recovery"| node_resync
node_runtime -->|"coordinates recovery"| node_recovery
node_runtime -->|"collects reports"| node_desync
node_relay -->|"captures evidence"| node_capture

click node_inject "https://github.com/volpestyle/kh2-multiplayer/blob/main/inject/src/DllMain.cpp"
click node_bridge "https://github.com/volpestyle/kh2-multiplayer/blob/main/runtime/src/GameBridgePC.cpp"
click node_runtime "https://github.com/volpestyle/kh2-multiplayer/blob/main/runtime/src/RuntimeMain.cpp"
click node_avatar "https://github.com/volpestyle/kh2-multiplayer/blob/main/common/include/kh2coop/AvatarBridge.hpp"
click node_input "https://github.com/volpestyle/kh2-multiplayer/blob/main/common/include/kh2coop/InputMailbox.hpp"
click node_replicas "https://github.com/volpestyle/kh2-multiplayer/blob/main/runtime/include/kh2coop/ReplicaController.hpp"
click node_combat "https://github.com/volpestyle/kh2-multiplayer/blob/main/inject/src/EnemySync.cpp"
click node_protocol "https://github.com/volpestyle/kh2-multiplayer/blob/main/common/include/kh2coop/Protocol.hpp"
click node_codec "https://github.com/volpestyle/kh2-multiplayer/blob/main/common/include/kh2coop/Codec.hpp"
click node_client "https://github.com/volpestyle/kh2-multiplayer/blob/main/common/src/NetworkClient.cpp"
click node_transport "https://github.com/volpestyle/kh2-multiplayer/blob/main/common/include/kh2coop/Transport.hpp"
click node_relay "https://github.com/volpestyle/kh2-multiplayer/blob/main/server/src/SessionHost.cpp"
click node_progress "https://github.com/volpestyle/kh2-multiplayer/blob/main/common/include/kh2coop/ProgressMirror.hpp"
click node_resync "https://github.com/volpestyle/kh2-multiplayer/blob/main/common/include/kh2coop/ResyncProtocol.hpp"
click node_recovery "https://github.com/volpestyle/kh2-multiplayer/blob/main/common/include/kh2coop/ClientRecovery.hpp"
click node_desync "https://github.com/volpestyle/kh2-multiplayer/blob/main/runtime/src/DesyncCollector.cpp"
click node_capture "https://github.com/volpestyle/kh2-multiplayer/blob/main/server/src/DesyncCapture.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_inject,node_bridge,node_runtime toneBlue
class node_avatar,node_input,node_replicas,node_combat toneAmber
class node_protocol,node_codec,node_client,node_transport,node_relay toneMint
class node_progress,node_resync,node_recovery toneRose
class node_desync,node_capture,node_player,node_kh2 toneIndigo
```

## Components

### Game integration

- [Inject hooks](https://github.com/volpestyle/kh2-multiplayer/blob/main/inject/src/DllMain.cpp): `inject/src/DllMain.cpp`
- [PC game bridge](https://github.com/volpestyle/kh2-multiplayer/blob/main/runtime/src/GameBridgePC.cpp): `runtime/src/GameBridgePC.cpp`
- [Runtime orchestration](https://github.com/volpestyle/kh2-multiplayer/blob/main/runtime/src/RuntimeMain.cpp): `runtime/src/RuntimeMain.cpp`

### Gameplay synchronization

- [Avatar bridge](https://github.com/volpestyle/kh2-multiplayer/blob/main/common/include/kh2coop/AvatarBridge.hpp): `common/include/kh2coop/AvatarBridge.hpp`
- [Input mailbox](https://github.com/volpestyle/kh2-multiplayer/blob/main/common/include/kh2coop/InputMailbox.hpp): `common/include/kh2coop/InputMailbox.hpp`
- [Replica application](https://github.com/volpestyle/kh2-multiplayer/blob/main/runtime/include/kh2coop/ReplicaController.hpp): `runtime/include/kh2coop/ReplicaController.hpp`
- [Enemy and combat sync](https://github.com/volpestyle/kh2-multiplayer/blob/main/inject/src/EnemySync.cpp): `inject/src/EnemySync.cpp`

### Network session

- [Message protocol](https://github.com/volpestyle/kh2-multiplayer/blob/main/common/include/kh2coop/Protocol.hpp): `common/include/kh2coop/Protocol.hpp`
- [Packet codec](https://github.com/volpestyle/kh2-multiplayer/blob/main/common/include/kh2coop/Codec.hpp): `common/include/kh2coop/Codec.hpp`
- [Network client](https://github.com/volpestyle/kh2-multiplayer/blob/main/common/src/NetworkClient.cpp): `common/src/NetworkClient.cpp`
- [Transport](https://github.com/volpestyle/kh2-multiplayer/blob/main/common/include/kh2coop/Transport.hpp): `common/include/kh2coop/Transport.hpp`
- [Session relay](https://github.com/volpestyle/kh2-multiplayer/blob/main/server/src/SessionHost.cpp): `server/src/SessionHost.cpp`

### World and recovery

- [Progress mirroring](https://github.com/volpestyle/kh2-multiplayer/blob/main/common/include/kh2coop/ProgressMirror.hpp): `common/include/kh2coop/ProgressMirror.hpp`
- [World resync](https://github.com/volpestyle/kh2-multiplayer/blob/main/common/include/kh2coop/ResyncProtocol.hpp): `common/include/kh2coop/ResyncProtocol.hpp`
- [Client recovery](https://github.com/volpestyle/kh2-multiplayer/blob/main/common/include/kh2coop/ClientRecovery.hpp): `common/include/kh2coop/ClientRecovery.hpp`

### Diagnostics

- [Desync collection](https://github.com/volpestyle/kh2-multiplayer/blob/main/runtime/src/DesyncCollector.cpp): `runtime/src/DesyncCollector.cpp`
- [Relay capture](https://github.com/volpestyle/kh2-multiplayer/blob/main/server/src/DesyncCapture.cpp): `server/src/DesyncCapture.cpp`

### Other components

- **Player**
- **KH2 process**

## Connections

- Player → KH2 process: plays locally (evidence: `README.md`)
- Inject hooks → KH2 process: hooks (evidence: `README.md`)
- PC game bridge → KH2 process: bridges memory (evidence: `README.md`)
- Runtime orchestration → PC game bridge: uses (evidence: `runtime/src/RuntimeMain.cpp`)
- Runtime orchestration → Network client: pumps (evidence: `runtime/src/RuntimeMain.cpp`)
- Runtime orchestration → Avatar bridge: streams avatars (evidence: `runtime/src/RuntimeMain.cpp`)
- Runtime orchestration → Input mailbox: exchanges input (evidence: `runtime/src/RuntimeMain.cpp`)
- Runtime orchestration → Replica application: applies snapshots (evidence: `runtime/src/RuntimeMain.cpp`)
- Replica application → PC game bridge: applies state (evidence: `runtime/include/kh2coop/ReplicaController.hpp`)
- Network client → Packet codec: encodes packets
- Network client → Transport: sends traffic
- Network client → Session relay: connects (evidence: `README.md`)
- Session relay → Network client: forwards traffic (evidence: `README.md`)
- Session relay → Message protocol: version-gates
- Network client → Message protocol: exchanges messages
- Runtime orchestration → Enemy and combat sync: synchronizes combat (evidence: `README.md`)
- Runtime orchestration → Progress mirroring: syncs progress (evidence: `README.md`)
- Runtime orchestration → World resync: requests recovery (evidence: `runtime/src/RuntimeMain.cpp`)
- Runtime orchestration → Client recovery: coordinates recovery (evidence: `runtime/src/RuntimeMain.cpp`)
- Runtime orchestration → Desync collection: collects reports (evidence: `runtime/src/RuntimeMain.cpp`)
- Session relay → Relay capture: captures evidence
