# sergeantserk/horsemenu architecture

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

- Interactive diagram: https://gitdiagram.com/sergeantserk/horsemenu
- Repository: https://github.com/sergeantserk/horsemenu

## Overview

##### Main Components
- Core Subsystem: Located in the "src/core" directory, this includes several key modules:
- Command handling (e.g., various command types such as BoolCommand, ColorCommand, etc.)
- Hooking mechanisms (e.g., BaseHook, DetourHook, VMTHook, and related hooking infrastructure)
- Memory and file management (pattern scanning, memory patching, file manager)
- Logging and error handling (“logger”)
- Renderer and settings management
- Game-Specific Subsystem: Found in "src/game", it implements functionality dedicated to the RDR2 game environment.
- Backend logic for game-specific manipulations (features like player commands, network features, and map editor functions)
- Frontend/UI elements for mod menu display (menus, submenus, chat display, overlays with ImGui widgets)
- Game hooks – specific hooks for detecting/overriding native calls, interfacing with the game’s engine (hooks components for anticheat, GUI integration, etc.)
- Feature implementations for custom functionalities (teleports, self-modifications, players, vehicles, world features, etc.)
- Utility and Common Functions: Under “src/util” and “src/common”, these modules provide more generic functionalities that are reused across the application (e.g., helper functions, network utilities, storage, vehicle spawner, etc.)
- Build and Dependency Management:
- CMake configuration (CMakeLists.txt, cmake directory) manages project building.
- Dependencies such as the Vulkan library under “deps” and integration cmake modules (async-logger, imgui, json, etc.)

##### Relationships and Interactions
- The mod menu (frontend) communicates with the core and game-specific subsystems. For instance, UI actions in the mod frontend (menus/submenus) trigger command functions that modify game state.
- The core subsystem provides services such as logging, hooking, and memory management which are consumed by both the frontend and game-specific components.
- The hooking logic intercepts game routines. It is often integrated with backend elements to run custom scripts, alter game events, or enhance gameplay behavior.
- Utility functions offer common functionality that may be used by both core and game layers, such as mathematical computations, network interactions, or storage handling.

##### Architectural Patterns and Design Principles
- Modular design: The project is clearly divided into separate modules (core, game, and util), which fosters separation of concerns.
- Layered approach: The architecture separates low-level functionalities (hooking, memory operations, logging) from high-level application logic (UI display, gameplay modifications, feature modules).
- Extensibility: With dedicated directories for commands, features (further subdivided into players, network, self, etc.), and hooking, new functionalities can be added as isolated modules.
- Use of CMake for cross-platform builds indicates reliance on standard build methodologies and dependency management best practices.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External entry point
    PreStep["Mod Injector/Entry Point"]:::external

    %% Core Subsystem
    subgraph "Core Subsystem"
        CoreCommands["Command Handling Module"]:::core
        CoreHooking["Hooking Mechanisms"]:::core
        CoreMemory["Memory Management"]:::core
        CoreFile["File Management"]:::core
        CoreLogger["Logging and Error Handling"]:::core
        CoreRenderer["Renderer"]:::core
        CoreSettings["Settings Management"]:::core
    end

    %% Game-Specific Subsystem
    subgraph "Game-Specific Subsystem"
        GameBackend["Backend Logic"]:::game
        GameFrontend["Frontend/UI Elements"]:::game
        GameHooks["Game Hooks"]:::game
    end

    %% Utility & Common Functions
    subgraph "Utility & Common Functions"
        UtilModule["Utility Module (src/util)"]:::util
        Common["Common Functions (src/common.cpp & src/common.hpp)"]:::util
    end

    %% Build and Dependency Management
    subgraph "Build and Dependency Management"
        BuildCMake["CMake Build Configuration"]:::build
    end

    %% Interactions
    PreStep -->|"injects"| GameFrontend

    GameFrontend -->|"triggers_commands"| CoreCommands
    GameFrontend -->|"displays_UI"| GameHooks
    CoreCommands -->|"executes_hooks"| CoreHooking
    CoreHooking -->|"modifies_memory"| CoreMemory
    GameBackend -->|"affects_game_state"| GameHooks

    %% Logging connections
    CoreCommands -->|"logs_to"| CoreLogger
    CoreHooking -->|"logs_to"| CoreLogger
    CoreMemory -->|"logs_to"| CoreLogger
    CoreFile -->|"logs_to"| CoreLogger
    GameBackend -->|"logs_to"| CoreLogger

    %% Utility usage
    CoreCommands -->|"calls_utilities"| UtilModule
    CoreMemory -->|"calls_utilities"| UtilModule
    GameBackend -->|"calls_utilities"| UtilModule

    %% Build dependencies
    BuildCMake -->|"builds_CoreCommands"| CoreCommands
    BuildCMake -->|"builds_CoreHooking"| CoreHooking
    BuildCMake -->|"builds_GameBackend"| GameBackend
    BuildCMake -->|"builds_UtilModule"| UtilModule

    %% Click Events
    click CoreCommands "https://github.com/sergeantserk/horsemenu/tree/master/src/core/commands"
    click CoreHooking "https://github.com/sergeantserk/horsemenu/tree/master/src/core/hooking"
    click CoreMemory "https://github.com/sergeantserk/horsemenu/tree/master/src/core/memory"
    click CoreFile "https://github.com/sergeantserk/horsemenu/tree/master/src/core/filemgr"
    click CoreLogger "https://github.com/sergeantserk/horsemenu/tree/master/src/core/logger"
    click CoreRenderer "https://github.com/sergeantserk/horsemenu/tree/master/src/core/renderer"
    click CoreSettings "https://github.com/sergeantserk/horsemenu/tree/master/src/core/settings"
    click GameBackend "https://github.com/sergeantserk/horsemenu/tree/master/src/game/backend"
    click GameFrontend "https://github.com/sergeantserk/horsemenu/tree/master/src/game/frontend"
    click GameHooks "https://github.com/sergeantserk/horsemenu/tree/master/src/game/hooks"
    click UtilModule "https://github.com/sergeantserk/horsemenu/tree/master/src/util"
    click Common "https://github.com/sergeantserk/horsemenu/blob/master/src/common.cpp"
    click BuildCMake "https://github.com/sergeantserk/horsemenu/blob/master/CMakeLists.txt"

    %% Style Definitions
    classDef core fill:#f4cccc,stroke:#b45f06,stroke-width:2px;
    classDef game fill:#c9daf8,stroke:#1155cc,stroke-width:2px;
    classDef util fill:#d9ead3,stroke:#38761d,stroke-width:2px;
    classDef build fill:#ead1dc,stroke:#b45f06,stroke-width:2px;
    classDef external fill:#fff2cc,stroke:#bf9000,stroke-width:2px;
```
