# splitscreen-me/splitscreenme-nucleus architecture

> Architecture diagram of the GitHub repository splitscreen-me/splitscreenme-nucleus, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/splitscreen-me/splitscreenme-nucleus
- Repository: https://github.com/splitscreen-me/splitscreenme-nucleus

## Overview

##### Project Type & Purpose
- Nucleus Co-op is a Windows desktop “full-stack” tooling suite (C++ and C#/.NET) that lets users launch multiple instances of PC games, inject custom hooks, re-route input, and coordinate instances via LAN/online emulators to create synthetic split-screen gameplay.

##### Key Architectural Components
a. Solution & Modules
- NucleusCoop.sln – top‐level solution
- C++ Hook Libraries
– Nucleus.Hook: low-level WinAPI hooks (mouse, keyboard, focus, cursor)
– Nucleus.SHook: secondary hook module
- Injector
– Nucleus.Inject (.NET): launches games, injects hook DLLs
- UI / Orchestration
– NucleusCoopTool (WinForms/WPF + WebView2): main user interface, asset downloader, theme engine
- Core Logic Library
– NucleusGaming (.NET): game handlers, process management, window‐tiling, input multiplexing, caching, coop logic
- Launcher
– StartGame: specialized launcher for single game instances
- Third-Party Utilities
– EasyHook, AutoHotkey.Interop, WindowScrape, x360ce, ForceBindIP, GoldbergEmu, SmartSteamEmu, Steamless, XInputPlus, DarkReader (webview plugin), etc.

b. External Services & Files
- Local file system: game files, symlinked folders, handler scripts
- LAN/Online Emulation: Goldberg, Nemirtingas emulators for multiplayer emulation
- WebView2: for downloading game handlers and assets

##### Relationships & Data Flow
1. User interacts with NucleusCoopTool UI →
2. UI calls into NucleusGaming backend →
3. Backend orchestrates:
- Start or symlink game processes via StartGame or direct Process.Start →
- Invoke Nucleus.Inject to inject Nucleus.Hook/Nucleus.SHook DLLs into each process →
- Hook modules intercept raw input and window messages, filter by gamepad assignment, and communicate back to backend via named pipes or hook callbacks →
- Backend applies window management (resize, remove borders, reposition) →
- For multiplayer emulation, backend launches/configures external emulators (Goldberg, SmartSteamEmu, ForceBindIP) →
- UI reflects game state, player nicknames, division overlays (using WebView2 + DarkReader extension for theming)

##### Architectural Patterns & Design Principles
- Modular layered architecture:
- Presentation Layer (WinForms/WPF + WebView2)
- Application Layer (NucleusGaming orchestration)
- Infrastructure Layer (Injection, Hooking, External Utils)
- Plugin/Handler pattern: game‐specific logic lives in “handlers” (scripts or DLLs) loaded at runtime
- Dependency Injection / inversion of control via interfaces in NucleusGaming (IGameHandler, IGameInfo)
- Separation of concerns: native hooking isolated in C++ DLLs, high-level coop logic in managed .NET

##### Essential Details to Capture
- Named pipe or hook callback channel between Hook Modules and Core Backend
- Symlink / mutex-kill techniques for launching multiple instances
- Controller isolation via custom xinput DLLs or XInputPlus
- Window management (borderless, reposition, scaling)
- Emulation layer for multiplayer connectivity

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        UI["NucleusCoopTool (WinForms/WPF + WebView2)"]:::managed
    end

    %% Application Layer
    subgraph "Application Layer"
        Backend["NucleusGaming Library"]:::managed
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        Injector["Nucleus.Inject (.NET)"]:::managed
        Hook1["Nucleus.Hook (C++ native hooks)"]:::native
        Hook2["Nucleus.SHook (C++ secondary hook)"]:::native
        Launcher["StartGame Launcher"]:::native
    end

    %% External Tools
    subgraph "External Tools"
        easyhook["EasyHook"]:::external
        AutoHotkey["AutoHotkey.Interop"]:::external
        WindowScrape["WindowScrape"]:::external
        x360ce["x360ce Submodule"]:::external
        ForceBindIP["ForceBindIP"]:::external
        SmartSteamEmu["SmartSteamEmu"]:::external
        Goldberg["GoldbergEmu"]:::external
    end

    %% Other Components
    FileSys["Local File System\n(game files, handler scripts)"]:::infra
    GameProc["Game Process Executable"]:::infra

    %% Connections
    UI -->|"calls via HTTP/WebView2"| Backend
    Backend -->|"Process.Start / StartGame"| Launcher
    Backend -->|"invoke inject"| Injector
    Injector -->|"inject DLLs"| Hook1
    Injector -->|"inject DLLs"| Hook2
    Hook1 -->|"named pipes / callbacks"| Backend
    Hook2 -->|"named pipes / callbacks"| Backend
    Backend -->|"window management"| GameProc
    Backend -->|"launch/configure"| easyhook
    Backend -->|"launch/configure"| AutoHotkey
    Backend -->|"launch/configure"| WindowScrape
    Backend -->|"launch/configure"| x360ce
    Backend -->|"launch/configure"| ForceBindIP
    Backend -->|"launch/configure"| SmartSteamEmu
    Backend -->|"launch/configure"| Goldberg
    FileSys -->|"load handlers/scripts"| Backend

    %% Click Events
    click UI "https://github.com/splitscreen-me/splitscreenme-nucleus/tree/master/Master/NucleusCoopTool/"
    click Backend "https://github.com/splitscreen-me/splitscreenme-nucleus/tree/master/Master/NucleusGaming/"
    click Injector "https://github.com/splitscreen-me/splitscreenme-nucleus/tree/master/Master/Nucleus.Inject/"
    click Hook1 "https://github.com/splitscreen-me/splitscreenme-nucleus/tree/master/Master/Nucleus.Hook/"
    click Hook2 "https://github.com/splitscreen-me/splitscreenme-nucleus/tree/master/Master/Nucleus.SHook/"
    click Launcher "https://github.com/splitscreen-me/splitscreenme-nucleus/tree/master/Master/StartGame/"
    click easyhook "https://github.com/splitscreen-me/splitscreenme-nucleus/tree/master/Master/ThirdParty/easyhook/"
    click AutoHotkey "https://github.com/splitscreen-me/splitscreenme-nucleus/tree/master/Master/ThirdParty/AutoHotkey.Interop/"
    click WindowScrape "https://github.com/splitscreen-me/splitscreenme-nucleus/tree/master/Master/ThirdParty/WindowScrape/"
    click x360ce "https://github.com/splitscreen-me/splitscreenme-nucleus/tree/master/Submodules/x360ce/"

    %% Styles
    classDef managed fill:#AEDFF7,stroke:#0366D6,color:#000
    classDef native fill:#D4F7A1,stroke:#228B22,color:#000
    classDef external fill:#FDE68A,stroke:#B28704,color:#000
    classDef infra fill:#E5E7EB,stroke:#9CA3AF,color:#000
```
