# raicuparta/two-forks-vr architecture

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

- Interactive diagram: https://gitdiagram.com/raicuparta/two-forks-vr
- Repository: https://github.com/raicuparta/two-forks-vr

## Overview

##### Project Type & Purpose
- Two Forks VR is a Unity-based VR mod for the Firewatch game. It delivers full motion-control support by packaging:
- A .NET mod plugin (TwoForksVr) that Harmony-patches the original game at runtime via BepInEx.
- A console patcher tool (TwoForksVrPatcher) to prepare class data / metadata.
- A Unity-Editor project (UnityHelper) that builds AssetBundles for VR assets (models, UI, shaders).

##### High-Level Structure from the File Tree & README
- Top-Level Solution (.sln) contains three projects:
a. TwoForksVr (C# .NET plugin)
b. TwoForksVrPatcher (console app)
c. UnityHelper (Unity Editor project for AssetBundles)
- TwoForksVr/ModFiles: BepInEx loader files + openvr_mod.cfg + manifest.json + "CopyToGame" staging folder
- TwoForksVr/src: modular C# code grouped by VR subsystem (Input, Camera, LaserPointer, Locomotion, UI, PlayerBody, etc.)
- UnityHelper/Assets & /Editor: scripts and content to generate VR AssetBundles

##### Runtime Architecture & Interactions
- Firewatch.exe (Unity Player)
↓ (Injector)
- BepInEx Preloader
→ loads BepInEx.Core, reads BepInEx.cfg
→ discovers plugins in ModFiles/BepInEx/plugins/TwoForksVr.dll
- TwoForksVr.dll (plugin entry point – TwoForksVrMod)
→ uses Harmony to patch game methods (in Firewatch assemblies)
→ invokes VrAssetLoader to load AssetBundles from TwoForksVrAssets
→ initializes subsystems:
– VrInput (SteamVR_Input → BindingManager → IActionInput)
– VrCamera (overrides game cameras, injects OpenVR rendering)
– Locomotion (TeleportController, TurningController, patched Navigation)
– LaserPointer (VrLaser + PlayerTargetingPatches)
– PlayerBody (VR limb transforms, body renderer manager)
– UI (Static and Interactive UIs patched to world-space)
– Tools & Inventory (ToolPicker, Patches for Map, Compass, etc.)
– Settings menu extension (VrSettingsMenu)
– Liv SDK integration (LIV.cs, SDKBridge → mixed-reality capture)
- VR SDK Layer
→ OpenVR (SteamVR plugin) drives headset & controllers
→ openvr_fsr plugin (configurable via openvr_mod.cfg) can be injected

##### Build / Deployment Pipeline
- UnityHelper Project
– Editor scripts (CreateAssetBundles.cs) → outputs AssetBundles into TwoForksVrAssets/AssetBundles
- TwoForksVrPatcher
– Reads classdata.tpk and other metadata → packages or tweaks game IL as needed
- TwoForksVr Project
– Compiles plugin DLL + copies ModFiles (BepInEx loader, openvr_mod.cfg, asset bundles manifest)
– Packaging step (manifest.json, CopyToGame) prepares everything for the installer (RaiManager or itch.io)

##### Diagramming Guidance
- Development Tools (UnityHelper, TwoForksVrPatcher, TwoForksVr build)
- Firewatch Game + BepInEx Loader
- TwoForksVr Plugin
- VR Subsystems (Input, Camera, Locomotion, LaserPointer, UI, PlayerBody, Tools, Liv)
- VR SDK (OpenVR, openvr_fsr)

- Build outputs feed into ModFiles & AssetBundles
- Firewatch → BepInEx → TwoForksVr.dll
- TwoForksVr.dll → Harmony patches → game code
- TwoForksVr.dll → VrAssetLoader → AssetBundles → instantiate VR prefabs
- TwoForksVr.dll ↔ OpenVR & Liv SDK

c. Architectural Patterns & Principles:
- Plugin architecture via BepInEx + Harmony AOP patches
- Modular subsystem separation (one folder per VR subsystem)
- AssetBundle-driven resource loading
- Clear separation of development/build pipeline vs. runtime injection

d. Technologies & Frameworks:
- Unity Editor (2017/2018) for AssetBundles
- BepInEx (mod loader)
- Harmony (method patching)
- SteamVR OpenVR plugin (SteamVR_Input system)
- LIV SDK (mixed reality capture)
- .NET Core console for patcher

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Development & Build Tools"
        dev1("UnityHelper Editor Project"):::dev
        dev2("TwoForksVrPatcher Tool"):::dev
        dev3("TwoForksVr Plugin Build"):::dev
    end

    subgraph "Build Outputs"
        ab("AssetBundles"):::out
        meta("Metadata (classdata.tpk)"):::out
        dll("TwoForksVr.dll & ModFiles"):::out
    end

    subgraph "Runtime Injection"
        exe("Firewatch.exe (Unity Player)"):::run
        bep("BepInEx Preloader"):::run
        plug("TwoForksVr.dll Plugin"):::run
    end

    subgraph "VR Subsystems"
        input("VrInput"):::run
        cam("VrCamera"):::run
        loco("Locomotion"):::run
        laser("LaserPointer"):::run
        body("PlayerBody"):::run
        ui("UI"):::run
        tools("Tools & Inventory"):::run
        settings("Settings Menu Extension"):::run
    end

    subgraph "VR SDK Layer"
        openvr("OpenVR"):::ext
        fsr("openvr_fsr"):::ext
        liv("LIV SDK"):::ext
    end

    dev1 -->|"build AssetBundles"| ab
    dev2 -->|"generate metadata"| meta
    dev3 -->|"compile & package"| dll

    ab --> dll
    meta --> dll

    exe -->|"inject"| bep
    bep -->|"loads plugin"| plug

    plug -->|"load AssetBundles"| ab
    plug -->|"init subsystems"| input
    plug -->|"init subsystems"| cam
    plug -->|"init subsystems"| loco
    plug -->|"init subsystems"| laser
    plug -->|"init subsystems"| body
    plug -->|"init subsystems"| ui
    plug -->|"init subsystems"| tools
    plug -->|"init subsystems"| settings
    plug -->|"mixed-reality capture"| liv

    input -->|"reads input"| openvr
    cam -->|"renders to headset"| openvr
    cam -->|"optional FSR"| fsr

    classDef dev fill:#ADD8E6,stroke:#000;
    classDef out fill:#90EE90,stroke:#000;
    classDef run fill:#FFA500,stroke:#000;
    classDef ext fill:#DDA0DD,stroke:#000;

    click dev1 "https://github.com/raicuparta/two-forks-vr/blob/main/UnityHelper/Assets/Editor/CreateAssetBundles.cs"
    click dev2 "https://github.com/raicuparta/two-forks-vr/blob/main/TwoForksVrPatcher/Patcher.cs"
    click dev2 "https://github.com/raicuparta/two-forks-vr/blob/main/TwoForksVrPatcher/classdata.tpk"
    click dev3 "https://github.com/raicuparta/two-forks-vr/blob/main/TwoForksVr/TwoForksVr.csproj"
    click plug "https://github.com/raicuparta/two-forks-vr/blob/main/TwoForksVr/src/TwoForksVrMod.cs"
    click plug "https://github.com/raicuparta/two-forks-vr/blob/main/TwoForksVr/src/TwoForksVrBehavior.cs"
    click plug "https://github.com/raicuparta/two-forks-vr/blob/main/TwoForksVr/src/TwoForksVrPatch.cs"
    click ab "https://github.com/raicuparta/two-forks-vr/tree/main/TwoForksVr/TwoForksVrAssets/AssetBundles/"
    click input "https://github.com/raicuparta/two-forks-vr/tree/main/TwoForksVr/src/VrInput/"
    click cam "https://github.com/raicuparta/two-forks-vr/tree/main/TwoForksVr/src/VrCamera/"
    click loco "https://github.com/raicuparta/two-forks-vr/tree/main/TwoForksVr/src/Locomotion/"
    click laser "https://github.com/raicuparta/two-forks-vr/tree/main/TwoForksVr/src/LaserPointer/"
    click body "https://github.com/raicuparta/two-forks-vr/tree/main/TwoForksVr/src/PlayerBody/"
    click ui "https://github.com/raicuparta/two-forks-vr/tree/main/TwoForksVr/src/UI/"
    click tools "https://github.com/raicuparta/two-forks-vr/tree/main/TwoForksVr/src/Tools/"
    click settings "https://github.com/raicuparta/two-forks-vr/blob/main/TwoForksVr/src/Settings/VrSettingsMenu.cs"
    click liv "https://github.com/raicuparta/two-forks-vr/tree/main/TwoForksVr/src/Liv/"
```
