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, which only that constructor assigns:
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 (tick/world update, client, entity, map lifecycle) |
Core.GameEvent | APIIGameEventService - game event (EventPlayerDeath, etc.) hook/fire APIs |
Core.NetMessage | APIINetMessageService - net message send/hook APIs |
Core.GameHooks | APIIGameHooks - hooks grouped by category (controller, items, movement, pawn, weapons, entities, datamaps) |
Core.Engine | APIIEngineService - server/map queries, command execution, particle effects |
Core.Game | APIIGameService - match state and round control, e.g. grenade projectiles |
Core.Helpers | APIIHelpers - weapon/item lookups by definition index or classname |
Core.Command | APIICommandService - command registration/aliasing, client command and chat hooks |
Core.ConsoleOutput | APIIConsoleOutputService - writing to the server console and console output filtering |
Core.EntitySystem | APIIEntitySystemService - entity creation and querying |
Core.ConVar | APIIConVarService - ConVar creation, lookup, client replication and query |
Core.Configuration | APIIPluginConfigurationService - plugin configuration file initialization/binding |
Core.GameData | APIIGameDataService - per-plugin signature, offset and patch lookup |
Core.PlayerManager | APIIPlayerManagerService - player lookup and server-wide player actions |
Core.Memory | APIIMemoryService - unmanaged function resolution and hooking |
Core.Extension | APIIExtensionService - loading and unloading native extensions, and the pointer registry shared with them |
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.Menu | APIIMenuService - the component-based menu framework |
Core.MenusAPI | APIIMenuManagerAPI - the classic menu API ([Obsolete], use Core.Menu instead) |
Core.CommandLine | APIICommandLine - server command-line argument access |
Core.GameFileSystem | APIIGameFileSystem - game virtual file system access |
Core.PluginManager | APIIPluginManager - loading/unloading/reloading other plugins, status and metadata lookup |
Core.StringTable | APIIStringTableService - string table access |
Core.Profiler | APIIContextedProfilerService - named recordings and custom duration metrics |
Core.Trace | APIITraceManager - shape and line collision traces |
Core.Logger, Core.LoggerFactory | Standard Microsoft.Extensions.Logging logger |
Full member list for any of these: APIISwiftlyCore.
Core.Menu is the component-based menu framework described in Menu System. It replaces Core.MenusAPI, which is [Obsolete] and documented in Menus for plugins that still use it.
Runtime paths are exposed on Core as well: Core.PluginPath (current plugin's directory), Core.PluginDataDirectory (per-plugin data directory, created by the framework if needed), Core.GameFilesDirectory (game/csgo) and Core.GameDirectory (game root). Core.CSGODirectory points at game/csgo too, but it is [Obsolete] - use Core.GameFilesDirectory instead.
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.