kh2-multiplayer

Created: March 23, 2026
Last commit: April 3, 2026
C++94.5%
Python2.3%
CMake1.6%
PowerShell1.5%
KH2multiplayerDLL-injectionIPCENetWindowsOpenKHMultiplayer networkingGame memory manipulationInter-process communication (IPC)Memory offsetsArchitecture design / runtime modesKH2FMKingdom Hearts II Final Mixkh2coopkh2coop_injectkh2coop_fake_simIn-process DLL injectionReadProcessMemoryWriteProcessMemoryRPMWPMInputMailboxCMakePowerShellPSpwshKH2Offsets.hpppointer_map_v1.mdkh2coop_inject (DLL)kh2coop_fake_sim.exe (test harness)restart-kh2.ps1 (PowerShell script)ENet (networking library)InputMailbox (Shared memory IPC)KH2Offsets.hpp (memory offsets header)pointer_map_v1.md (offset map document)
README.md

KH2 Multiplayer

Kingdom Hearts II Final Mix multiplayer mod. Player-controlled friend party members (Donald, Goofy) via in-process DLL injection with full animation, movement, and camera support.

Start here

What you wantWhere to go
Understand the projectThis file, then docs/kh2_three_client_coop_design.md
Build and test the inject DLLdocs/DEVELOPMENT_WORKFLOW.md
Navigate the codebasedocs/CODEBASE_MAP.md
Continue friend control workdocs/HANDOFF_FRIEND_CONTROL.md
Check milestone progressdocs/IMPLEMENTATION_BACKLOG.md
Look up memory offsetsdocs/pointer_map_v1.md + runtime/include/kh2coop/KH2Offsets.hpp
Understand RE methodologydocs/LESSONS_LEARNED.md

What works today

Friend entity control (M3 — in progress)

  • Press F5 in-game to take control of Donald (Friend1)
  • Left stick moves Donald with proportional walk/run speed
  • Camera follows Donald, right stick orbits
  • Idle/walk/run animations match stick input (loops correctly at any distance from Sora)
  • Sora frozen in place while controlling Donald
  • Facing persists when stick is released

Networking layer (M0-M2 — complete)

  • Binary codec for all domain types with little-endian framing
  • Host-authoritative session server: version gating, slot assignment, snapshot broadcast
  • ENet transport with heartbeat, 3-client integration tested
  • Server-side fake physics for protocol testing without KH2

Runtime bridge (M1-M2 — complete)

  • Attaches to live KH2 via ReadProcessMemory/WriteProcessMemory
  • Entity discovery, room/actor/HP state reads, camera retargeting
  • Shared-memory IPC (InputMailbox) between runtime and inject DLL

Architecture

Two runtime modes on shared infrastructure:

  1. Campaign Co-op — up to 3 players share one host-authoritative session, each controlling a party slot (Sora, Donald, Goofy) with independent cameras.
  2. Public Realm (planned) — persistent characters, public hubs, party-formed instances.

See docs/ARCHITECTURE_MODES.md for the full breakdown.

                    ┌──────────────────┐
                    │   KH2 Process    │
                    │  ┌────────────┐  │     shared memory
                    │  │ inject DLL │◄─┼──── (InputMailbox) ◄── runtime process
                    │  └────────────┘  │                         │
                    │   hooks entity   │                         │ ENet
                    │   update loop    │                    ┌────▼────┐
                    └──────────────────┘                    │ server  │
                                                           └─────────┘

Quick start

# Build everything
cmake -B build -S . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
cmake --build build --config Release

# Run E2E test (no KH2 needed)
.\build\tests\Release\kh2coop_fake_sim.exe

# Build just the inject DLL
cmake --build build --target kh2coop_inject --config Release

# Restart KH2 + rebuild DLL
.\scripts\restart-kh2.ps1

See docs/DEVELOPMENT_WORKFLOW.md for the full inject/test loop.

Documentation

DocPurpose
docs/CODEBASE_MAP.mdWhat's in each directory, key source files
docs/DEVELOPMENT_WORKFLOW.mdBuild/inject/test loop
docs/HANDOFF_FRIEND_CONTROL.mdCurrent state of friend control: hooks, structs, addresses
docs/LESSONS_LEARNED.mdHard-won RE and hooking insights
docs/IMPLEMENTATION_BACKLOG.mdFull milestone tracking (M0-M8, Tracks A-D)
docs/pointer_map_v1.mdConfirmed memory offsets
docs/kh2_three_client_coop_design.mdOriginal 3-client co-op design
docs/ARCHITECTURE_MODES.mdCampaignCoop vs PublicRealm architecture
docs/INPUT_RE_SESSION.mdFull Ghidra trace of the KH2 input pipeline
docs/OPENKH_REFERENCE.mdGuide to the sibling OpenKH repository
docs/ACCEPTANCE_TESTS.mdPass/fail criteria for each milestone
docs/KH2_CONTROL_CLI.mdkh2ctl command reference
AGENTS.mdAI agent rules (CE/Ghidra usage, swarm coordination)