# daxcess/lcvr architecture

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

- Interactive diagram: https://gitdiagram.com/daxcess/lcvr
- Repository: https://github.com/daxcess/lcvr

## Overview

##### Project Type and Purpose
- This is a game mod designed to provide VR support (hand movement, motion-based controls, etc.) for Lethal Company.
- It leverages BepInEx as the mod loader and uses Unity’s OpenXR plugin so that it works with various VR headsets and controllers.
- It must interact seamlessly with the vanilla game (even supporting multiplayer with non-VR players) and includes code for input handling, patching various game components, networking, and UI.

##### Key Components
a. BepInEx Mod Loader Environment:
– Represent BepInEx as the entry point for the mod. Indicate its role in loading both “LCVR.dll” (the main mod assembly) and “LCVR.Preload.dll” (located in the Preloader folder) at startup.
– Show BepInEx’s internal “plugins” and “patchers” directories where these assemblies and runtime dependencies are placed.

b. Preloader Component:
– This is found under the Preloader directory and is critical for early initialization. It sets up environment configurations (like patching or loading runtime-necessary DLLs such as openxr_loader.dll and UnityOpenXR.dll).

c. Core Mod Components (Inside the “Source” Directory):
– Group the different namespaces/modules as independent components. For example:
- Input: Contains various scripts for handling VR input (e.g., actions, key remapping, finger curler, turning providers).
- Networking: Manages multiplayer compatibility (modules like Channel, NetworkSystem, etc.).
- Patches: A large group containing multiple subcomponents (BuildingPatches, CameraPatches, CarPatches, etc.) that modify the base game’s behavior through Harmony patching.
- Items: Custom VR items (VRBeltBagItem, VRKnife, etc.) with each file handling behavior for specific items.
- UI: Contains classes for VR UI elements (MainMenu, VRHUD, Keyboard, Settings, etc.).
- Physics: Manages interactions within the game world (e.g., Car interactions, Door, ElevatorButton, etc.).
- Other Utility Modules: Logger, Compatibility, Experiments, and ThirdParty integrations (like the MRTK support scripts).

d. External Dependencies and Runtime Libraries:
– Make note of external DLLs that are essential for VR functionality (UnityEngine.SpatialTracking.dll, Unity.XR.CoreUtils.dll, etc.).

e. Asset Bundle:
– Represent the asset bundle (named “lethalcompanyvr”) that supplies game assets essential for the mod’s functionality.

##### Showing Relationships and Data Flow
– Begin with the BepInEx mod loader, which then loads the Preloader.
– The Preloader initializes the runtime environment (load runtime DLLs, set up OpenXR) and then passes control to the main mod code (LCVR.dll).

##### Architectural Patterns and Design Principles
- Modularity: The code is highly modular with specialized folders for distinct functionalities (input, patches, items, UI).
- Patching and AOP: The widespread use of patch files (grouped in Source/Patches) implies an aspect-oriented approach to modify the game on the fly.
- Dependency on External Systems: There is a clear dependency on Unity’s OpenXR and BepInEx, which is important to highlight for understanding integration points.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Loader and Initialization Layer
    subgraph "Loader and Initialization"
        BEP["BepInEx Mod Loader"]:::loader
        PREASM["Preloader Assembly"]:::loader
        PRELOAD["Preload.cs"]:::loader
        PREUTIL["Preload Utils"]:::loader
    end

    %% Core Mod Components Layer
    subgraph "Core Mod Components"
        LCVR["LCVR.dll"]:::core
        INPUT["VR Input Module"]:::core
        NET["Networking Module"]:::core
        PATCH["Patching Subsystem"]:::core
        ITEMS["VR Items Module"]:::core
        UI["VR UI Module"]:::core
        PHYS["Physics & Interaction Module"]:::core
        UTIL["Utilities/Compatibility"]:::core
        OPENXR["OpenXR Integration"]:::core
        THIRD["3rd Party Integrations (MRTK)"]:::core
        ASSET["Asset Management Module"]:::core
    end

    %% External Systems Layer
    subgraph "External Systems"
        RUNTIME["Runtime Dependencies"]:::external
        OXR["Unity OpenXR"]:::external
        BASE["Lethal Company (Base Game)"]:::external
        ASSET_BUNDLE["Asset Bundle (lethalcompanyvr)"]:::external
    end

    %% Relationships: Initialization Flow
    BEP -->|"loads"| PREASM
    PREASM -->|"initializes"| PRELOAD
    PREASM -->|"initializes"| PREUTIL
    PREASM -->|"passesControlTo"| LCVR

    %% Relationships: Core Mod Component Flow
    LCVR -->|"handles"| INPUT
    LCVR -->|"handles"| NET
    LCVR -->|"handles"| PATCH
    LCVR -->|"handles"| ITEMS
    LCVR -->|"handles"| UI
    LCVR -->|"handles"| PHYS
    LCVR -->|"handles"| UTIL
    LCVR -->|"handles"| OPENXR
    LCVR -->|"handles"| THIRD
    LCVR -->|"handles"| ASSET

    %% Relationships: Interaction with External Systems
    PRELOAD -->|"loads"| RUNTIME
    INPUT -->|"capturesInputTo"| BASE
    PATCH -->|"modifies"| BASE
    UI -->|"rendersOn"| BASE
    NET -->|"syncsWith"| BASE
    UTIL -->|"logsFor"| BASE
    OPENXR -->|"integratesWith"| RUNTIME
    ASSET -->|"manages"| ASSET_BUNDLE

    %% Click Events for Component Mapping
    click LCVR "https://github.com/daxcess/lcvr/blob/main/LCVR.csproj"
    click PREASM "https://github.com/daxcess/lcvr/blob/main/Preloader/LCVR.Preload.csproj"
    click PRELOAD "https://github.com/daxcess/lcvr/blob/main/Preloader/Preload.cs"
    click PREUTIL "https://github.com/daxcess/lcvr/blob/main/Preloader/Utils.cs"
    click INPUT "https://github.com/daxcess/lcvr/tree/main/Source/Input"
    click NET "https://github.com/daxcess/lcvr/tree/main/Source/Networking"
    click PATCH "https://github.com/daxcess/lcvr/tree/main/Source/Patches"
    click ITEMS "https://github.com/daxcess/lcvr/tree/main/Source/Items"
    click UI "https://github.com/daxcess/lcvr/tree/main/Source/UI"
    click PHYS "https://github.com/daxcess/lcvr/tree/main/Source/Physics"
    click UTIL "https://github.com/daxcess/lcvr/blob/main/Source/Logger.cs"
    click OPENXR "https://github.com/daxcess/lcvr/blob/main/Source/OpenXR.cs"
    click THIRD "https://github.com/daxcess/lcvr/tree/main/Source/ThirdParty/MRTK"
    click ASSET "https://github.com/daxcess/lcvr/blob/main/Source/Assets/AssetManager.cs"

    %% Styles
    classDef loader fill:#ffcccb,stroke:#aa0000,stroke-width:2px;
    classDef core fill:#add8e6,stroke:#00008b,stroke-width:2px;
    classDef external fill:#c1e1c5,stroke:#2e8b57,stroke-width:2px;
```
