swiftlys2/docs/api/ai/

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

PropertyService
Core.EventAPIIEventSubscriber - framework event subscription (client/map/entity lifecycle)
Core.GameEventAPIIGameEventService - game event (EventPlayerDeath, etc.) hook/fire APIs
Core.NetMessageAPIINetMessageService - net message send/hook APIs
Core.GameHooksAPIIGameHooks - virtual-function style hooks grouped by category
Core.EngineAPIIEngineService - console commands, particle effects
Core.GameAPIIGameService - game-specific actions, e.g. grenade projectiles
Core.HelpersAPIIHelpers - misc helper utilities
Core.CommandAPIICommandService - command registration and aliasing
Core.ConsoleOutputAPIIConsoleOutputService - console output access
Core.EntitySystemAPIIEntitySystemService - entity creation and querying
Core.ConVarAPIIConVarService - ConVar creation, lookup and value access
Core.ConfigurationAPIIPluginConfigurationService - plugin configuration file initialization/binding
Core.GameDataAPIIGameDataService - per-plugin signature/offset lookup
Core.PlayerManagerAPIIPlayerManagerService - player lookup and server-wide player actions
Core.MemoryAPIIMemoryService - unmanaged function resolution and hooking
Core.SchedulerAPIISchedulerService - main-thread dispatch, delayed and repeating tasks
Core.DatabaseAPIIDatabaseService - database connection access
Core.Translation, Core.LocalizerAPIITranslationService, APIILocalizer - player and server localization
Core.PermissionAPIIPermissionManager - permission checks and assignment
Core.RegistratorAPIIRegistratorService - registers attribute-decorated instances beyond the plugin itself
Core.MenusAPIAPIIMenuManagerAPI - menu building and display
Core.CommandLineAPIICommandLine - server command-line argument access
Core.GameFileSystemAPIIGameFileSystem - game virtual file system access
Core.PluginManagerAPIIPluginManager - plugin discovery/metadata lookup
Core.StringTableAPIIStringTableService - string table access
Core.ProfilerAPIIContextedProfilerService - profiling scopes and timers
Core.TraceAPIITraceManager - trace/diagnostics manager
Core.Logger, Core.LoggerFactoryStandard 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.