El'Garnan Plugin Architecture
Relevant source files
The following files were used as context for generating this wiki page:
The El'Garnan Plugin Architecture provides a modular framework for extending game launcher functionality. It enables the project to load, validate, and manage external assemblies (DLLs) that implement specific game-launching logic and user interfaces. The system handles the entire lifecycle of a plugin, including dependency resolution, asynchronous initialization, and graphical rendering.
Sources: El'GarnanPluginSystem/CoreFunctions.cs, El'GarnanPluginSystem/Interfaces/pluginbase.cs
Core Components
The architecture relies on three primary components to manage extensibility: the Plugin Manager, the Plugin Interface, and the Base Implementation.
CoreFunctions (The Plugin Manager)
CoreFunctions acts as the central orchestrator for the system. It monitors a specified directory for plugin assemblies and manages a ConcurrentDictionary of loaded plugins. It handles asynchronous initialization and provides events for loading, unloading, and errors.
Sources: El'GarnanPluginSystem/CoreFunctions.cs:11-30
IGamePlugin Interface
The IGamePlugin interface defines the contract that all modules must follow. It requires metadata such as PluginId, Name, and Version, and specifies methods for lifecycle management like InitializeAsync() and ShutdownAsync().
Sources: Plugins/FFXIV/Elgarnan.xml:225-250
GamePluginBase
This abstract class provides a default implementation of the IGamePlugin and INotificationService interfaces. It manages the internal state transition of a plugin and includes a SemaphoreSlim named LaunchLock to ensure only one launch operation occurs at a time.
Sources: El'GarnanPluginSystem/Interfaces/pluginbase.cs:13-30
The diagram above shows the relationship between the management core and the plugin implementations.
Sources: El'GarnanPluginSystem/CoreFunctions.cs, El'GarnanPluginSystem/Interfaces/pluginbase.cs, Gameplugins.Plugin.FFXIV/FFXIVGamePlugin.cs
Plugin Lifecycle and Status
Each plugin maintains a state tracked by the PluginStatus enumeration. GamePluginBase handles these transitions during initialization and shutdown sequences.
| Status | Description |
|---|---|
Uninitialized | The default state before InitializeAsync is called. |
Initializing | The plugin is currently running its setup logic. |
Ready | The plugin is successfully validated and available for use. |
Failed | An error occurred during initialization or validation. |
Reloading | The plugin is being reset, typically during a hot reload. |
Disabled | The plugin is manually or automatically turned off. |
Sources: El'GarnanPluginSystem/Interfaces/pluginbase.cs:20-25, Plugins/FFXIV/Elgarnan.xml:253-285
Loading and Validation Logic
The system uses a custom PluginLoadContext to isolate assembly loading. Validation occurs in two stages: dependency checking and configuration validation.
- Assembly Discovery:
CoreFunctionsscans the plugins directory for*.dllfiles. - Context Creation: A new
PluginLoadContextis instantiated for the file path to prevent dependency conflicts. - Dependency Validation: The system checks if required libraries (like
ImGui.NETorVeldrid) are present in the base directory or plugin folder. - Version Check: It compares the assembly version against the
MinVersionrequired by the plugin. - Initialization: If validation passes,
InitializeAsyncis executed.
Sources: El'GarnanPluginSystem/CoreFunctions.cs:81-125, El'GarnanPluginSystem/Models/plugindependency.cs:5-23
This flowchart illustrates the verification steps performed before a plugin is activated.
Sources: El'GarnanPluginSystem/CoreFunctions.cs:85-115
UI Rendering Architecture
The system supports ImGui-based rendering for plugin interfaces. It utilizes a standalone window managed by ImGuiPluginRenderer which uses Veldrid and SDL2.
- Plugin UI Support: Plugins indicate support by setting
SupportsImGuito true. - Rendering Loop: The renderer pumps SDL2 events and updates the ImGui context at approximately 60 FPS.
- Integration:
CoreFunctions.RenderPluginInterfaces()iterates through all loaded plugins and calls their specificRenderImGui()methods within the frame.
Sources: El'GarnanPluginSystem/Interfaces/renderbase.cs:33-70, El'GarnanPluginSystem/CoreFunctions.cs:255-265
Notification System
The architecture includes a built-in notification queue. Plugins can call ShowNotification(), which enqueues a PluginNotification object. If ImGui is supported, the base class automatically renders these as popups or lists in the UI.
Sources: El'GarnanPluginSystem/Interfaces/pluginbase.cs:188-215
Hot Reload
If enabled, the CoreFunctions class uses FileSystemWatcher to monitor changes to plugin DLLs. When a file is modified, the system:
- Acquires a reload lock.
- Unloads the existing plugin instance.
- Re-scans and loads the new assembly.
- Triggers the
PluginReloadedevent.
Sources: El'GarnanPluginSystem/CoreFunctions.cs:135-165
Summary
The El'Garnan Plugin Architecture isolates game-specific logic from the core launcher through a robust assembly loading and interface system. By combining GamePluginBase for state management and CoreFunctions for lifecycle orchestration, it provides a stable environment for dynamic extensions. The integration of Veldrid and ImGui allows these plugins to provide complex user interfaces while maintaining high performance.
Sources: El'GarnanPluginSystem/CoreFunctions.cs, El'GarnanPluginSystem/Interfaces/pluginbase.cs