swiftlys2/docs/api/releases/features/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, 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

PropertyService
Core.EventAPIIEventSubscriber - framework event subscription (tick/world update, client, entity, map lifecycle)
Core.GameEventAPIIGameEventService - game event (EventPlayerDeath, etc.) hook/fire APIs
Core.NetMessageAPIINetMessageService - net message send/hook APIs
Core.GameHooksAPIIGameHooks - hooks grouped by category (controller, items, movement, pawn, weapons, entities, datamaps)
Core.EngineAPIIEngineService - server/map queries, command execution, particle effects
Core.GameAPIIGameService - match state and round control, e.g. grenade projectiles
Core.HelpersAPIIHelpers - weapon/item lookups by definition index or classname
Core.CommandAPIICommandService - command registration/aliasing, client command and chat hooks
Core.ConsoleOutputAPIIConsoleOutputService - writing to the server console and console output filtering
Core.EntitySystemAPIIEntitySystemService - entity creation and querying
Core.ConVarAPIIConVarService - ConVar creation, lookup, client replication and query
Core.ConfigurationAPIIPluginConfigurationService - plugin configuration file initialization/binding
Core.GameDataAPIIGameDataService - per-plugin signature, offset and patch lookup
Core.PlayerManagerAPIIPlayerManagerService - player lookup and server-wide player actions
Core.MemoryAPIIMemoryService - unmanaged function resolution and hooking
Core.ExtensionAPIIExtensionService - loading and unloading native extensions, and the pointer registry shared with them
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.MenuAPIIMenuService - the component-based menu framework
Core.MenusAPIAPIIMenuManagerAPI - the classic menu API ([Obsolete], use Core.Menu instead)
Core.CommandLineAPIICommandLine - server command-line argument access
Core.GameFileSystemAPIIGameFileSystem - game virtual file system access
Core.PluginManagerAPIIPluginManager - loading/unloading/reloading other plugins, status and metadata lookup
Core.StringTableAPIIStringTableService - string table access
Core.ProfilerAPIIContextedProfilerService - named recordings and custom duration metrics
Core.TraceAPIITraceManager - shape and line collision traces
Core.Logger, Core.LoggerFactoryStandard 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.