# k073l/localmultiplayer architecture

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

- Interactive diagram: https://gitdiagram.com/k073l/localmultiplayer
- Repository: https://github.com/k073l/localmultiplayer

## Overview

##### Project type and purpose
- This is a game-mod plugin project (“Local Multiplayer”) built on MelonLoader. It injects networking and UI/audio patches into an existing game (“Schedule I”) to enable local multiplayer (host/join) on a single machine.

##### File structure
- Top-level:
- LocalMultiplayer.sln – Visual Studio solution
- LocalMultiplayer/LocalMultiplayer.csproj – C# project for the mod
- LocalMultiplayer/Plugin.cs – entry point (IMelonMod)
- LocalMultiplayer/AudioComponent.cs & MenuComponent.cs – feature modules
- LocalMultiplayer/Patches/*.cs – Harmony/Melon patches into game methods
- build/ – MSBuild props, targets, pre/post-build scripts for IL2CPP vs Mono branches
- libs/ – any third-party DLLs if provided
- Build uses custom .props and .targets to pick the right MelonLoader runtime (Mono or IL2CPP).

##### Extract insights from the README
- Core functionality:
- Hosts or joins a game over port 7777
- Flags for window adjustments and offsets
- Auto-selection of last played or first save for hosting/joining

##### Main components
a. Game Process Instances
– Two separate “Schedule I.exe” processes (Host & Join)
b. MelonLoader Runtime
– .NET trampoline for injecting the plugin into each game instance
c. LocalMultiplayer Plugin
– Plugin.cs (initialization, command-line flag parsing)
– Patches (MultipassInitializePatch, SettingsApplyDisplaySettingsPatch)
– Components (MenuComponent, AudioComponent)
– Networking layer (host server or join client using TCP/UDP on port 7777)
d. External Dependencies
– MelonLoader (Mono or IL2CPP)
– Game engine (unmodified Schedule I code)
– OS windowing for window size/position adjustments
e. Build System
– MSBuild solution, build targets, pre/post-build events

##### Relationships and interactions
- At startup, Schedule I.exe launches under MelonLoader → plugin is loaded → Plugin.OnInitialize() reads CLI flags → applies patches to game methods.
- Host instance opens a listening socket on port 7777 → waits for client.
- Join instance attempts connection to localhost:7777 → on success, synchronizes game state via patched game loops.
- MenuComponent displays host/join UI overlay, AudioComponent routes audio events between instances.
- Settings patches adjust window position/size per flag.

##### Architectural patterns & design principles
- Plugin/injection architecture: decouples mod from game internals via MelonLoader hooks
- Separation of concerns:
- Plugin.cs for life-cycle and flag parsing
- Patch classes for IL weaving (method interception)
- Component classes for UI/audio feature logic
- Build scripts abstract platform differences (IL2CPP vs Mono)
- Event-driven communication: networking code responds to game events patched at key points.

##### Elements
- Clear labels for each block (e.g., “MelonLoader Runtime,” “MultipassInitializePatch,” “Networking”)
- From Initialization → Patch injection → Game engine
- Between Host and Join through the TCP/UDP socket
- From CLI flags → Plugin initialization
- Blue = Plugin core
- Green = Patches
- Orange = Feature components (UI/Audio)
- Gray = External systems (Game, MelonLoader, OS, Network)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Host Process Swimlane
    subgraph "Host Process"
        direction TB
        MLH["MelonLoader Runtime"]:::external
        PLH["Plugin Core\n(Plugin.cs)"]:::blue
        CLIH["CLI Flags"]:::external
        subgraph "Patches"
            direction TB
            InitH["MultipassInitializePatch"]:::green
            DispH["SettingsApplyDisplaySettingsPatch"]:::green
        end
        subgraph "Components"
            direction TB
            MenuH["MenuComponent"]:::orange
            AudioH["AudioComponent"]:::orange
        end
        NetH["Networking Server\n(TCP 7777)"]:::external
        GameH["Schedule I.exe\n(Game Engine)"]:::external
        OSH["OS Window Manager"]:::external
    end

    %% Join Process Swimlane
    subgraph "Join Process"
        direction TB
        MLJ["MelonLoader Runtime"]:::external
        PLJ["Plugin Core\n(Plugin.cs)"]:::blue
        CLIJ["CLI Flags"]:::external
        subgraph "Patches"
            direction TB
            InitJ["MultipassInitializePatch"]:::green
            DispJ["SettingsApplyDisplaySettingsPatch"]:::green
        end
        subgraph "Components"
            direction TB
            MenuJ["MenuComponent"]:::orange
            AudioJ["AudioComponent"]:::orange
        end
        NetJ["Networking Client\n(TCP 7777)"]:::external
        GameJ["Schedule I.exe\n(Game Engine)"]:::external
        OSJ["OS Window Manager"]:::external
    end

    %% Build Pipeline
    subgraph "Build Pipeline"
        direction TB
        SLN["LocalMultiplayer.sln"]:::external
        CSP["LocalMultiplayer.csproj"]:::external
        Props["conditions.props\npaths.props"]:::external
        EventsPre["preBuild.targets"]:::external
        EventsPost["postBuild.targets"]:::external
        TargetsIL["MelonIL2CPP.targets"]:::external
        TargetsMono["MelonMono.targets"]:::external
        DLL["LocalMultiplayer.dll"]:::external
        Mods["Mods Folder"]:::external
    end

    %% Build Flow
    SLN --> CSP --> Props --> EventsPre --> EventsPost --> TargetsIL
    Props --> TargetsMono
    TargetsIL --> DLL
    TargetsMono --> DLL
    DLL --> Mods

    %% Host Runtime Flow
    GameH --> MLH --> PLH
    CLIH --> PLH
    PLH --> InitH --> GameH
    PLH --> DispH --> OSH
    PLH --> MenuH --> GameH
    PLH --> AudioH --> GameH
    PLH --> NetH
    NetH -- "sync" --> NetJ

    %% Join Runtime Flow
    GameJ --> MLJ --> PLJ
    CLIJ --> PLJ
    PLJ --> InitJ --> GameJ
    PLJ --> DispJ --> OSJ
    PLJ --> MenuJ --> GameJ
    PLJ --> AudioJ --> GameJ
    PLJ --> NetJ
    NetJ -- "sync" --> NetH

    %% Click Events
    click SLN "https://github.com/k073l/localmultiplayer/blob/main/LocalMultiplayer.sln"
    click CSP "https://github.com/k073l/localmultiplayer/blob/main/LocalMultiplayer/LocalMultiplayer.csproj"
    click PLH "https://github.com/k073l/localmultiplayer/blob/main/LocalMultiplayer/Plugin.cs"
    click PLJ "https://github.com/k073l/localmultiplayer/blob/main/LocalMultiplayer/Plugin.cs"
    click MenuH "https://github.com/k073l/localmultiplayer/blob/main/LocalMultiplayer/MenuComponent.cs"
    click MenuJ "https://github.com/k073l/localmultiplayer/blob/main/LocalMultiplayer/MenuComponent.cs"
    click AudioH "https://github.com/k073l/localmultiplayer/blob/main/LocalMultiplayer/AudioComponent.cs"
    click AudioJ "https://github.com/k073l/localmultiplayer/blob/main/LocalMultiplayer/AudioComponent.cs"
    click InitH "https://github.com/k073l/localmultiplayer/blob/main/LocalMultiplayer/Patches/MultipassInitializePatch.cs"
    click InitJ "https://github.com/k073l/localmultiplayer/blob/main/LocalMultiplayer/Patches/MultipassInitializePatch.cs"
    click DispH "https://github.com/k073l/localmultiplayer/blob/main/LocalMultiplayer/Patches/SettingsApplyDisplaySettingsPatch.cs"
    click DispJ "https://github.com/k073l/localmultiplayer/blob/main/LocalMultiplayer/Patches/SettingsApplyDisplaySettingsPatch.cs"
    click Props "https://github.com/k073l/localmultiplayer/blob/main/build/conditions.props"
    click Props "https://github.com/k073l/localmultiplayer/blob/main/build/paths.props"
    click EventsPre "https://github.com/k073l/localmultiplayer/blob/main/build/events/preBuild.targets"
    click EventsPost "https://github.com/k073l/localmultiplayer/blob/main/build/events/postBuild.targets"
    click TargetsIL "https://github.com/k073l/localmultiplayer/blob/main/build/references/MelonIL2CPP.targets"
    click TargetsMono "https://github.com/k073l/localmultiplayer/blob/main/build/references/MelonMono.targets"
    click libs "https://github.com/k073l/localmultiplayer/tree/main/libs/"

    %% Styles
    classDef blue fill:#a4c2f4,stroke:#000,stroke-width:1px;
    classDef green fill:#b4e7b0,stroke:#000,stroke-width:1px;
    classDef orange fill:#f4b183,stroke:#000,stroke-width:1px;
    classDef external fill:#d9d9d9,stroke:#000,stroke-width:1px;
```
