# ned3y2k/zephyr_loader architecture

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

- Interactive diagram: https://gitdiagram.com/ned3y2k/zephyr_loader
- Repository: https://github.com/ned3y2k/zephyr_loader

## Overview

##### Main Components

a) Core Emulation Layer:
- CD-ROM Emulator (CdRom.cpp/h)
- CD File System (CdFs.cpp/h)
- CD Audio Player (CdAudioPlayer.cpp/h)

b) Audio Subsystem:
- DirectSound Implementation (MyDirectSound.cpp/h)
- Audio File Handlers:
- OGG Support (OggFile.cpp/h)
- Wave Support (WaveFile.cpp/h)
- Generic Sound Interface (SoundFile.cpp/h)

c) Hook System:
- Windows API Hooks:
- File API (hooker_fileapi.cpp/h)
- WinMM (hooker_winmm.cpp/h)
- User32 (hooker_user32.cpp/h)
- OLE32 (hooker_ole32.cpp)
- Time Functions (hooker_time.cpp/h)

d) Loader Component:
- Separate executable for launching the game

**[Game Application]**
- ↓
**[Hook Layer (Detours)]**
- ↓
**[Emulation Layer]**
- ↙     ↓     ↘
**[CDFS] [CD-ROM] [CD Audio]**
- ↓     ↓         ↓
**[File System] [Disk Management] [Audio System]**
- ↓
**[Physical Storage]**

##### Important Relationships

- Hook system intercepting Windows API calls
- CD-ROM emulator's interaction with both file system and audio
- Audio pipeline from CD Audio → DirectSound
- File system redirection from virtual to physical paths

##### Technical Details

- Supported formats (OGG, WAV)
- External dependencies (libogg, libvorbis, Detours)
- Virtual directory structure
- Hook points for Windows APIs

##### Implementation Notes

- The separation between real and emulated components
- The hook system's central role
- The audio subsystem's complexity
- File system virtualization

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core["Core Components"]
        Loader["Loader"]:::core
        DiskEmulator["Disk Emulator DLL"]:::core
        TestFramework["Test Framework"]:::core
    end

    subgraph FileSystem["File System Layer"]
        CDFS["CD Filesystem"]:::filesystem
        CDRom["CD-ROM Interface"]:::filesystem
        FileUtil["File Utilities"]:::filesystem
    end

    subgraph Audio["Audio System"]
        CDAudio["CD Audio Player"]:::audio
        DirectSound["DirectSound"]:::audio
        subgraph AudioFormats["Audio Format Support"]
            OGG["OGG/Vorbis Player"]:::audio
            WAVE["Wave Support"]:::audio
        end
    end

    subgraph Hooks["Hooking System"]
        FileAPIHook["File API Hooks"]:::hook
        WinMMHook["WinMM Hooks"]:::hook
        TimeHook["Time Hooks"]:::hook
        User32Hook["User32 Hooks"]:::hook
        OLE32Hook["OLE32 Hooks"]:::hook
    end

    subgraph External["External Systems"]
        GameExe["Game Executable\n(Zephyr.exe)"]:::external
        WinAPI["Windows APIs"]:::external
        AudioOut["Audio Output"]:::external
        RealFS["Real Filesystem"]:::external
    end

    %% Relationships
    Loader --> GameExe
    GameExe --> DiskEmulator
    DiskEmulator --> CDFS
    DiskEmulator --> CDAudio
    DiskEmulator --> Hooks

    CDFS --> CDRom
    CDRom --> FileUtil
    FileUtil --> RealFS

    CDAudio --> DirectSound
    CDAudio --> OGG
    CDAudio --> WAVE
    DirectSound --> AudioOut

    Hooks --> WinAPI
    FileAPIHook --> WinAPI
    WinMMHook --> WinAPI
    TimeHook --> WinAPI
    User32Hook --> WinAPI
    OLE32Hook --> WinAPI

    %% Click Events
    click Loader "https://github.com/ned3y2k/Zephyr_Loader/blob/main/Loader/Loader.cpp"
    click DiskEmulator "https://github.com/ned3y2k/Zephyr_Loader/blob/main/DiskEmulator/dllmain.cpp"
    click TestFramework "https://github.com/ned3y2k/Zephyr_Loader/tree/main/TestDiskEmulator"
    click CDAudio "https://github.com/ned3y2k/Zephyr_Loader/blob/main/DiskEmulator/CdAudioPlayer.cpp"
    click CDFS "https://github.com/ned3y2k/Zephyr_Loader/blob/main/DiskEmulator/CdFs.cpp"
    click CDRom "https://github.com/ned3y2k/Zephyr_Loader/blob/main/DiskEmulator/CdRom.cpp"
    click FileUtil "https://github.com/ned3y2k/Zephyr_Loader/blob/main/DiskEmulator/file.util.cpp"
    click FileAPIHook "https://github.com/ned3y2k/Zephyr_Loader/blob/main/DiskEmulator/hooker_fileapi.cpp"
    click WinMMHook "https://github.com/ned3y2k/Zephyr_Loader/blob/main/DiskEmulator/hooker_winmm.cpp"
    click TimeHook "https://github.com/ned3y2k/Zephyr_Loader/blob/main/DiskEmulator/hooker_time.cpp"
    click User32Hook "https://github.com/ned3y2k/Zephyr_Loader/blob/main/DiskEmulator/hooker_user32.cpp"
    click OLE32Hook "https://github.com/ned3y2k/Zephyr_Loader/blob/main/DiskEmulator/hooker_ole32.cpp"
    click DirectSound "https://github.com/ned3y2k/Zephyr_Loader/blob/main/DiskEmulator/MyDirectSound.cpp"
    click OGG "https://github.com/ned3y2k/Zephyr_Loader/blob/main/DiskEmulator/OggFile.cpp"
    click WAVE "https://github.com/ned3y2k/Zephyr_Loader/blob/main/DiskEmulator/WaveFile.cpp"

    %% Styling
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef filesystem fill:#2ecc71,stroke:#27ae60,color:white
    classDef audio fill:#e67e22,stroke:#d35400,color:white
    classDef hook fill:#e74c3c,stroke:#c0392b,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white
```
