# yanpla/yanplaroles architecture

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

- Interactive diagram: https://gitdiagram.com/yanpla/yanplaroles
- Repository: https://github.com/yanpla/yanplaroles

## Overview

##### Project Nature and Main Purpose
- This is a game-modification (mod) project. Its core objective is to inject new gameplay elements into Among Us by defining new roles (like Janitor, Miner, Sheriff, etc.), special abilities (modifiers such as Captain and Guesser), and custom game behaviors via patches.

##### Analyzing the File Structure
- “Buttons” Directory – Contains role-specific interaction components (like RememberButton, Ignition logic, cleaning, etc.). This implies there is a UI or input layer that triggers role-specific actions.
- “Modifiers” Directory – Provides implementations for role modifiers (e.g., Captain, ExecutionerTarget, Guesser) that alter or extend gameplay.
- “Options” Directory – Contains classes to manage game options and modifier/role configuration. This suggests a configuration or settings layer.
- “Patches” Directory – Includes a variety of patch classes (e.g., CheckEndCriteriaPatch, EndGamePatch, VentPatches, etc.). These classes are likely method detours or runtime modifications that “hook” into the game logic.
- “Roles” Directory – Organizes the different role implementations into subdirectories (Crewmate, Impostor, Neutral). This clearly represents the core game mechanics extensions.
- Other files like Assets.cs, CustomRpc.cs, and yanplaRolesPlugin.cs indicate the entry point and integration with the game’s runtime environment.
- The solution (*.sln) and project (*.csproj) files reveal that this is a C# project developed with Visual Studio, typical for Unity mod development.

##### Identifying Main Components
a. Core Game Plugin:
– yanplaRolesPlugin.cs: Acts as the plugin entry point integrated via BepInEx.
– Custom RPC and game event hooks that manage mod-specific messaging and interactions.
b. Role Logic Components:
– “Roles” directory: Different directories for Crewmate, Impostor, and Neutral roles with their individual logic (for Sheriff, Snitch, Jester, etc.).
– “Modifiers” directory: Implements modifiers that tweak the behavior of roles.
c. UI / Interaction Layers:
– “Buttons” directory: Contains scripts mapping custom UI buttons and actions (e.g., cleaning, vent placing) to role abilities.
– “Options” directory: Manages configurable settings related to roles and modifiers.
d. Patches / Game Hooks:
– “Patches” directory: Contains classes that override or extend core game behavior (hooking into game start, ending criteria, and visible roles features).
e. External Dependencies:
– Libraries such as BepInEx, MiraAPI, Reactor, and dependencies referenced in the README.
f. Custom Game Data and Utilities:
– Files like Resources, Utils.cs, and the custom game over reasons file which support runtime decision making and state management.

##### Relationships and Interactions
- The Entry Point (yanplaRolesPlugin.cs) is loaded by BepInEx and initializes the mod.
- Once loaded, the Plugin registers all patches (in the Patches directory), which modify the behavior of the Among Us game at runtime.
- Role-specific logic (found in the Roles directory) is activated when game events occur, sometimes routed through custom UI buttons (in Buttons) that offer new interactions.
- Options and Modifiers allow for runtime configuration, influencing how roles respond to game events.
- External libraries are used throughout—ensuring that dependencies are annotated within the design (e.g., BepInEx for plugin management, MiraAPI for mod functions).

##### Architectural Patterns
- Plugin Architecture: Clear injection point using BepInEx.
- Aspect-oriented modifications: Patches act as aspects by interjecting behavior into the core game loops.
- Modular Design: Separation by concerns (Buttons for UI interactions, Roles for game logic, Patches for hooking into game execution, Options for configuration).

## Diagram (Mermaid)

```mermaid
flowchart TD
    PluginEntry["Plugin Entry (yanplaRolesPlugin)"]:::plugin
    Patches["Patches/Runtime Hooks"]:::patches
    RoleManagement["Role Management"]:::roles
    Crewmate["Crewmate Roles"]:::roles
    Impostor["Impostor Roles"]:::roles
    Neutral["Neutral Roles"]:::roles
    Modifiers["Role Modifiers"]:::modifiers
    Buttons["UI Buttons & Interactions"]:::ui
    Options["Game Options & Configurations"]:::options
    External["External Dependencies (BepInEx,MiraAPI,Reactor)"]:::external
    Utilities["Custom Game Data & Utilities"]:::utilities

    %% Relationships
    PluginEntry -->|"initializes"| Patches
    PluginEntry -->|"registers_UI"| Buttons
    PluginEntry -->|"configures"| Options
    PluginEntry -->|"depends_on"| External

    Patches -->|"invokes"| RoleManagement
    Patches -->|"applies_to"| Modifiers
    Patches -->|"depends_on"| External

    RoleManagement -->|"composed_of"| Crewmate
    RoleManagement -->|"composed_of"| Impostor
    RoleManagement -->|"composed_of"| Neutral
    RoleManagement -->|"utilizes"| Utilities
    RoleManagement -->|"triggered_by"| Buttons
    RoleManagement -->|"depends_on"| External

    Options -->|"customizes"| Modifiers

    %% Click Events
    click PluginEntry "https://github.com/yanpla/yanplaroles/blob/master/yanplaRolesPlugin.cs"
    click Crewmate "https://github.com/yanpla/yanplaroles/tree/master/Roles/Crewmate"
    click Impostor "https://github.com/yanpla/yanplaroles/tree/master/Roles/Impostor"
    click Neutral "https://github.com/yanpla/yanplaroles/tree/master/Roles/Neutral"
    click Modifiers "https://github.com/yanpla/yanplaroles/blob/master/Modifiers/Captain.cs"
    click Buttons "https://github.com/yanpla/yanplaroles/tree/master/Buttons/Janitor"
    click Options "https://github.com/yanpla/yanplaroles/blob/master/Options/GameOptions.cs"
    click Patches "https://github.com/yanpla/yanplaroles/blob/master/Patches/CheckEndCriteriaPatch.cs"
    click Utilities "https://github.com/yanpla/yanplaroles/blob/master/Assets.cs"

    %% Styles
    classDef plugin fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef patches fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef roles fill:#ccddff,stroke:#333,stroke-width:2px;
    classDef modifiers fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef ui fill:#ffffcc,stroke:#333,stroke-width:2px;
    classDef options fill:#ccffff,stroke:#333,stroke-width:2px;
    classDef external fill:#eeeeee,stroke:#333,stroke-width:2px,stroke-dasharray:5,5;
    classDef utilities fill:#ffddcc,stroke:#333,stroke-width:2px;
```
