Repository navigation
Module System
The module system provides a structured runtime for building features as isolated, manageable units. Each module has metadata, lifecycle management, telemetry, and a management UI via /sfs. Built-ins use SFModuleBase; external plugins implement ISFModule from SF.Abstractions and are discovered from SF/modules/*/module.json. See External Plugins.
A module is a class that:
- Implements
ISFModule; built-ins can inheritSFModuleBase - Has an
[SFModule]attribute with metadata - A built-in is registered in
Program.csviacontainer.RegisterModule<T>()
| Model | Description |
|---|---|
MainThread |
Runs on the game's main thread via SFSynchronizationContext. Use for anything touching game state. |
BackgroundWorker |
Runs on a Task.Run thread pool thread. Use for I/O-heavy or network work. |
Hybrid |
Starts inline, can switch threads via Context.SwitchToMainThreadAsync(). |
| Policy | Behavior |
|---|---|
Manual |
Module stays stopped after fault or completion. User must /sfs start manually. |
OnFault |
Auto-restarts on unhandled exception. A circuit breaker disables auto-restart after 5 faults within 60 seconds. |
Created → Starting → Running → Stopping → Stopped
↓
Faulted
// 1. Container calls module.RunAsync(context)
// 2. SFModuleBase sets Context and Log, then:
OnStartingAsync() // Setup, allocate resources
↓
ExecuteAsync(token) // Main loop - runs until cancelled or throws
↓ (success)
OnCompletedAsync() // Clean completion
↓ (exception)
OnFaultedAsync(ex) // Handle fault, log, notify
↓ (always)
OnStoppingAsync() // Teardown
↓
OnStoppedAsync() // Final cleanup
↓
context.Dispose() // All registered disposables releasedBuilt-in modules are registered in Program.cs:
var container = new SFModuleContainer();
container.RegisterModule<DialogScraper>();
container.RegisterModule<BrightBinder>();
container.RegisterModule<NodShaker>();
// ...
await container.Run();Declared Dependencies must be registered and running before a module can start. Among eligible modules, Order (ascending), then DisplayName (alphabetical) determine startup order. Stop, restart and plugin unload are blocked when they would remove a provider required by running dependents.
| Command | Description |
|---|---|
/sfs |
Interactive dashboard dialog - shows all modules with state, uptime, load, and action buttons |
/sfs status [page] |
Quick status in chat (paginated, 6 per page) |
/sfs info <id> |
Detailed info dialog for a specific module |
/sfs start <id> |
Start a stopped module |
/sfs stop <id> |
Stop a running module |
/sfs restart <id> |
Restart a module |
/sfs plugins |
List loaded plugins |
/sfs plugin-load <id|path> |
Load a plugin by id or manifest path |
/sfs plugin-unload <id> |
Unload a plugin and its modules |
/sfs plugin-reload <id> |
Unload and load a plugin again |
Module can be resolved by id, display name, or partial match.
Each module automatically tracks:
- State - current lifecycle state
- Uptime - time since last start
- Load - duty cycle percentage (sync work / iteration period)
- Loop metrics - count, avg/max iteration time
-
Counters - custom named counters (e.g.,
commands.invoked) -
Details - custom key-value pairs (e.g.,
status=idle) - Heartbeat - last activity timestamp
- Faults - fault count, last exception info
- Memory - process memory snapshot (polled every 2s)
- Threads - start and last thread IDs
- Главная / Home
- Установка
- Архитектура и совместимость
- SA-MP R1, R3-1, R5-1
- Написание модулей
- Плагины и зависимости
- Жизненный цикл
- API модулей
- Потоки и время жизни
- Ранняя загрузка
- Конфигурация и ассеты