Swiftly Core
APIISwiftlyCore is the central entry point for all plugin
services in SwiftlyS2. Core refers to the ISwiftlyCore instance every plugin
receives.
How Core Is Provided
APIBasePlugin takes ISwiftlyCore in its constructor and exposes
it as the protected Core property:
public sealed class MyPlugin : BasePlugin
{
public MyPlugin(ISwiftlyCore core) : base(core)
{
}
public override void Load(bool hotReload)
{
Core.Logger.LogInformation("Plugin loaded. Hot reload: {HotReload}", hotReload);
}
public override void Unload()
{
Core.Logger.LogInformation("Plugin unloaded.");
}
}Pass ISwiftlyCore (or the specific services you need) into helper classes
rather than reaching for a static/global reference.
Core Services at a Glance
| Property | Service |
|---|---|
Core.Event | APIIEventSubscriber - framework event subscription (client/map/entity lifecycle) |
Core.GameEvent | APIIGameEventService - game event (EventPlayerDeath, etc.) hook/fire APIs |
Core.NetMessage | APIINetMessageService - net message send/hook APIs |
Core.GameHooks | APIIGameHooks - virtual-function style hooks grouped by category |
Core.Engine | APIIEngineService - console commands, particle effects |
Core.Game | APIIGameService - game-specific actions, e.g. grenade projectiles |
Core.Helpers | APIIHelpers - misc helper utilities |
Core.Command | APIICommandService - command registration and aliasing |
Core.ConsoleOutput | APIIConsoleOutputService - console output access |
Core.EntitySystem | APIIEntitySystemService - entity creation and querying |
Core.ConVar | APIIConVarService - ConVar creation, lookup and value access |
Core.Configuration | APIIPluginConfigurationService - plugin configuration file initialization/binding |
Core.GameData | APIIGameDataService - per-plugin signature/offset lookup |
Core.PlayerManager | APIIPlayerManagerService - player lookup and server-wide player actions |
Core.Memory | APIIMemoryService - unmanaged function resolution and hooking |
Core.Scheduler | APIISchedulerService - main-thread dispatch, delayed and repeating tasks |
Core.Database | APIIDatabaseService - database connection access |
Core.Translation, Core.Localizer | APIITranslationService, APIILocalizer - player and server localization |
Core.Permission | APIIPermissionManager - permission checks and assignment |
Core.Registrator | APIIRegistratorService - registers attribute-decorated instances beyond the plugin itself |
Core.MenusAPI | APIIMenuManagerAPI - menu building and display |
Core.CommandLine | APIICommandLine - server command-line argument access |
Core.GameFileSystem | APIIGameFileSystem - game virtual file system access |
Core.PluginManager | APIIPluginManager - plugin discovery/metadata lookup |
Core.StringTable | APIIStringTableService - string table access |
Core.Profiler | APIIContextedProfilerService - profiling scopes and timers |
Core.Trace | APIITraceManager - trace/diagnostics manager |
Core.Logger, Core.LoggerFactory | Standard Microsoft.Extensions.Logging logger |
Full member list for any of these: APIISwiftlyCore.
Runtime paths follow the same pattern: Core.PluginPath (current plugin's directory), Core.PluginDataDirectory (per-plugin data directory), Core.CSGODirectory (game/csgo), Core.GameFilesDirectory and Core.GameDirectory (game root).
Thread Awareness
Core.IsGameThread reports whether the current call is on the game thread:
public void EnsureMainThreadAction(Action action)
{
if (Core.IsGameThread)
{
action();
return;
}
Core.Scheduler.NextTick(action);
}Many game-facing APIs are thread-unsafe ([ThreadUnsafe]). Off the game
thread, use their Async counterpart or hand the call to Core.Scheduler
first. See Thread Safety.
Registering Attribute Handlers on Other Classes
Your plugin class is registered for attribute discovery automatically. Any other class needs Core.Registrator.Register(instance) - see Using Attributes for a full worked example and the complete attribute list.