Skip to content

Writing Modules

Алексей . edited this page Oct 22, 2026 · 6 revisions

Create a net10.0 class library. The .NET 10 SDK supports the host's C# 14 baseline. Build x86 or AnyCPU for pure managed code; do not target x64. Native tools are unnecessary unless your plugin builds native components.

Project references

Reference the compiled SF.Abstractions.dll matching the installed host, not Runtime or linked host source files:

<Reference Include="SF.Abstractions" HintPath="$(SFAbstractionsPath)" Private="false" />

Pass -p:SFAbstractionsPath=C:\SDK\SF.Abstractions.dll to dotnet build. For packet models and bitstreams, also reference SF.Protocol through SFProtocolPath, with Private="false". If using logging extensions directly, use a compatible logging abstractions package without deploying its runtime asset. Package references are an option only for versions that have actually been published.

Entry point

using SFSharp.Abstractions.Modules;
using SFSharp.Abstractions.Modules.Lifecycle;

[SFModule("my-tools", "My Tools", ExecutionModel = ModuleExecutionModel.MainThread)]
public sealed class MyTools : SFModuleBase
{
    protected override async Task ExecuteAsync(CancellationToken cancellationToken)
    {
        Context.RegisterChatCommand("mytools", _ => Context.SF.Samp.Chat.Add("Ready"));
        await Task.Delay(Timeout.Infinite, cancellationToken);
    }
}

SFModuleBase is an optional helper in Abstractions. The required interface contract is Task RunAsync(IModuleContext context); you may implement it directly. Old default interface lifecycle methods are not the current API. A public parameterless constructor is required for discovered module classes.

The returned task owns the entire run. Returning immediately ends the module and releases its commands/resources. Override protected OnStartingAsync/OnStoppingAsync only when needed. Use RegisterAsyncChatCommand for asynchronous commands instead of async void.

Deployment and checks

Ship manifest.json, your entry DLL, assets and private dependencies under SF/modules/<folder>/. Do not ship host contract DLLs. Manifest documentation covers version ranges, autostart precedence and shared API dependencies. Check command execution, stop/start, unload and the logs in the game; a managed build is not native validation.

See the complete Russian project example, CommandEcho and SFModuleBase.

Clone this wiki locally