-
-
Notifications
You must be signed in to change notification settings - Fork 0
Installation
| Component | Minimum |
|---|---|
| .NET SDK | 8.0 |
| Runtime | .NET NativeAOT (plugin side) |
| Host OS | Windows / Linux / macOS |
Plugins are compiled with
PublishAot=trueand export unmanaged entry points. Cross-platform plugins must be built separately for each target OS.
<PackageReference Include="NativePluginKit" Version="1.2.0" />If you are working inside the same solution:
<ProjectReference Include="..\NativePluginKit\NativePluginKit.csproj" />git submodule add https://github.com/GoWelkinDev/NativePluginKit.gitIn your client's initialization code, build a HostApiTable and create a PluginLoader:
using NativePluginKit.Loader;
using NativePluginKit.Loader.Constants;
var api = HostApiBridgeBuilder.Create(
freeString: ptr => Marshal.FreeCoTaskMem(ptr),
transition: (pathPtr, fadeOut) => { /* ... */ },
getCurrentScenePath: () => IntPtr.Zero,
printLog: ptr => { /* ... */ },
printWarning: ptr => { /* ... */ },
printError: ptr => { /* ... */ },
logDebug: ptr => { /* ... */ },
getCharacterImagePath: ptr => IntPtr.Zero,
getExecutableDirectory: () => IntPtr.Zero,
getPluginsDirectory: () => IntPtr.Zero,
getTimeSinceStartup: () => 0,
registerEvent: (t, cb, ud) => true,
unregisterEvent: (t, cb, ud) => true,
getCurrentTimelineName: () => IntPtr.Zero,
isBattle: () => 0,
startTimeline: (ptr, battle) => { },
endTimeline: skip => { },
sendSignal: ptr => { },
// Cards, Entity — see HostApiBridgeBuilder.Create full signature
/* ... */
);
var loader = new PluginLoader(
logAction: msg => Console.WriteLine(msg),
apiTable: api,
apiVersion: new Version(1, 0, 0));
loader.LoadPluginsFromDirectory(
Path.Combine(AppContext.BaseDirectory, "plugins"));The Create method takes 70+ parameters. In real projects you should keep all delegate instances in static readonly fields to prevent GC collection — HostApiBridgeBuilder already stores strong references internally, but the lambdas themselves must not be ephemeral.
-
Create a new Class Library targeting
net8.0. -
Add the following to the
.csproj:<PropertyGroup> <TargetFramework>net8.0</TargetFramework> <Nullable>enable</Nullable> <PublishAot>true</PublishAot> <NativeLib>Shared</NativeLib> <IlcExportUnmanagedEntrypoints>true</IlcExportUnmanagedEntrypoints> <RuntimeIdentifier>win-x64</RuntimeIdentifier> <!-- or linux-x64 / osx-x64 --> <InvariantGlobalization>true</InvariantGlobalization> </PropertyGroup> <ItemGroup> <ProjectReference Include="..\NativePluginKit\NativePluginKit.csproj" /> <ProjectReference Include="..\NativePluginKit.SourceGenerators\NativePluginKit.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> <UnmanagedEntryPointsAssembly Include="NativePluginKit" /> </ItemGroup>
UnmanagedEntryPointsAssemblyis required so thatPlugin.GetPluginInfo(declared inNativePluginKit) is exported from the plugin DLL. -
Build:
dotnet publish -c Release -r win-x64
-
Copy the output
YourPlugin.dllinto<GameRoot>/plugins/.