Setup
You need Node. Wraith gets found on its own, from the Wraith app’s install or your PATH. If there isn’t one, the first build downloads it.
Lua plugins need nothing installed and nothing built. Wraith runs your .lua files as they are.
You need the .NET 10 SDK. A C# plugin runs one of two ways, and you pick when you make it:
- NativeAOT compiles it into a native DLL, so players don’t need .NET. It needs the C++ build tools too, the Desktop development with C++ workload from the Visual Studio installer. Its DLL has .NET’s runtime in it, which can’t be unloaded, so once it’s loaded it stays on till the game closes. It can’t be turned off or reloaded, and neither can the plugins it depends on. To try a change, restart the game.
- CoreCLR has .NET run it, the game’s own if it has one, otherwise the installed .NET 10. Players need .NET 10 installed for games without their own. It reloads like a script.
The code is the same either way. Only its project file differs.
You need a C++20 compiler and CMake. The Desktop development with C++ workload from the Visual Studio installer has both, with MSVC. You also need the wraith launcher, which the Wraith app installs, since it makes the headers for Wraith’s API as the plugin builds.
Or build it with Zig instead of CMake, which compiles the C++ too. Then you need Zig, and nothing else. Check minimum_zig_version in Wraith’s build.zig.zon for which version.
You need Rust, from rustup, and the wraith launcher, which the Wraith app installs. It writes Wraith’s API as a crate your plugin depends on, and builds the plugin’s DLL with cargo.
For 32-bit games, add Rust’s 32-bit target too:
rustup target add i686-pc-windows-msvcYou need Zig. Check minimum_zig_version in Wraith’s build.zig.zon for which version.
You need a C11 compiler and CMake. The Desktop development with C++ workload from the Visual Studio installer has both, with MSVC. You also need the wraith launcher, which the Wraith app installs, since it makes the headers for Wraith’s API as the plugin builds.
Or build it with Zig instead of CMake, which compiles the C too. Then you need Zig, and nothing else. Check minimum_zig_version in Wraith’s build.zig.zon for which version.
Make a plugin
Section titled “Make a plugin”npm create @ratatoskr.io/plugin my-pluginIt asks a few questions, like the plugin’s name and which game it’s for. Pass --js to skip straight to JavaScript, or --yes to take the defaults.
With Wraith installed, wraith new does the same and also finds the game from its exe, so its id goes in wraith.json too.
wraith new my-plugin --language ts --game D:\Games\Kai\kai.execd my-pluginnpm installnpm run devwraith new my-plugin --language lua --game D:\Games\Kai\kai.exeIt writes wraith.json and main.lua, with the game’s id and exe found from the exe you give, or --engine for every game made with its game engine. It also writes the types your editor needs, and lists the folder for Wraith to load while you work on it.
Or make the folder yourself, with two files in it.
my-plugin/ wraith.json main.luawraith.json
{ "$schema": "https://hub.wraith.io/schema/v1/wraith.json", "id": "my-plugin", "kind": "plugin", "version": "0.1.0", "apiVersion": 3, "title": "My Plugin", "provider": "lua"}See the manifest for the other fields.
main.lua
local Wraith = require("wraith").Wraith
Wraith.log():info("Hello from " .. Wraith.memory():main().name)require("wraith") gives Wraith, your own namespace and your dependencies’ namespaces. None of them are globals, so take what you use into locals. See Plugin structure.
wraith new my-plugin --language cs --runtime aot --game D:\Games\Kai\kai.exe--runtime clr makes a CoreCLR one instead, and leaving it out asks. It checks you have the .NET SDK, then writes MyPlugin.csproj, Plugin.cs and a wraith.json for the game, and the C# for Wraith’s API in .wraith/cs. Give it the game’s exe and it builds for the game’s arch, 32 or 64-bit. It lists the plugin’s dist folder for Wraith to load while you work on it.
A NativeAOT one is a DLL, wraith_<id>_<arch>.dll, so its wraith.json says "provider": "native". A CoreCLR one says "provider": "clr", and .NET runs wraith_<id>.dll. Switching between them means changing both the project and the provider. For one that waits for a game’s own .NET, like one a mod loader starts later, see clrMode in the manifest.
Plugin.cs is your code. See Plugin structure.
The project makes the C# for Wraith’s API and your schemas with wraith sdk cs types on every build, so wraith has to be on your PATH, or the WRAITH environment variable set to a wraith.exe.
wraith new my_plugin --language cpp --game D:\Games\Kai\kai.exeIt checks you have CMake, then writes CMakeLists.txt, src/plugin.cpp and a wraith.json for the game, built for the game’s arch, 32 or 64-bit. --build zig makes a Zig build instead, with build.zig.
CMakeLists.txt
cmake_minimum_required(VERSION 3.21)project(my_plugin LANGUAGES CXX)
find_program(WRAITH wraith REQUIRED)execute_process(COMMAND "${WRAITH}" sdk cmake "${CMAKE_BINARY_DIR}/wraith.cmake" COMMAND_ERROR_IS_FATAL ANY)include("${CMAKE_BINARY_DIR}/wraith.cmake")
wraith_plugin(my_plugin CXX src/plugin.cpp)wraith_plugin is the whole build. As it builds, it has wraith write the headers for Wraith’s API and your schemas into the build folder, and writes them again whenever your schemas, a dependency’s or Wraith changes. Then it builds wraith_my_plugin_x64.dll, or _x86 for 32-bit, and puts it in dist with wraith.json and your schemas. -DWRAITH=<path> picks a wraith.exe that isn’t on your PATH.
src/plugin.cpp is your code. See Plugin structure.
wraith new my_plugin --language rust --game D:\Games\Kai\kai.exeIt checks you have cargo, then writes Cargo.toml, build.rs, src/lib.rs and a wraith.json for the game, and the Rust for Wraith’s API in .wraith/rust.
Cargo.toml
[package]name = "my_plugin"version = "0.1.0"edition = "2024"
[lib]crate-type = ["cdylib"]
[dependencies]salamander = { path = ".wraith/rust/salamander" }wraith = { path = ".wraith/rust/wraith" }.wraith/rust has the wraith crate, Wraith’s API with what makes your crate a plugin, salamander, which it’s built on, and schema.rs, your schemas. wraith sdk rust types writes it, for 32 and 64-bit both. build.rs runs that whenever your schemas, a dependency’s or Wraith changes, and the WRAITH environment variable can point at a wraith.exe that isn’t on your PATH.
src/lib.rs is your code. See Plugin structure.
wraith new my_plugin --language zig --game D:\Games\Kai\kai.exeIt checks you have Zig, runs zig init and fetches Wraith’s SDK, then writes build.zig, src/root.zig and a wraith.json for the game. Give it the game’s exe and it finds the game’s id, so the plugin loads in any copy of it, and only builds for the game’s arch, 32 or 64-bit. --engine makes it for every game made with the same game engine instead, and leaving --game out makes it for any game. Leave things out and it asks.
It also lists the plugin’s zig-out folder for Wraith to load while you work on it, so after zig build it’s in the Mods window.
By hand
mkdir my_plugincd my_pluginzig init --minimalzig fetch --save git+https://github.com/ratatoskr/wraithzig init --minimal makes just build.zig.zon and a stub build.zig, and zig fetch adds Wraith to the project. Everything Wraith needs comes along with it.
Then fill in these files.
build.zig
const std = @import("std");const wraith = @import("wraith");
pub fn build(b: *std.Build) void { const plugin: wraith.Plugin = .init(b, .{ .name = "my_plugin", .root_source_file = b.path("src/root.zig"), .target = b.standardTargetOptions(.{}), .optimize = b.standardOptimizeOption(.{}), }); plugin.install(b);}wraith.json
{ "$schema": "https://hub.wraith.io/schema/v1/wraith.json", "id": "my_plugin", "kind": "plugin", "version": "0.1.0", "apiVersion": 3, "title": "My Plugin", "provider": "native"}See the manifest for the other fields.
src/root.zig is your code. See Plugin structure.
wraith new my_plugin --language c --game D:\Games\Kai\kai.exeIt checks you have CMake, then writes CMakeLists.txt, src/plugin.c and a wraith.json for the game, built for the game’s arch, 32 or 64-bit. --build zig makes a Zig build instead, with build.zig.
Its CMakeLists.txt is the C++ one’s, with C for the language:
wraith_plugin(my_plugin C src/plugin.c)That makes wraith.h, Wraith’s API, wraith_plugin.h, what makes it a plugin, and schema.h, your schemas, in the build folder, and builds wraith_my_plugin_x64.dll into dist with wraith.json and your schemas.
src/plugin.c is your code. See Plugin structure.
Build and load
Section titled “Build and load”dev builds into dist/ and rebuilds every time you save. The first time, run the wraith dev add line it prints. A running game picks it up, and reloads it after each build.
There’s nothing to build.
wraith dev add my-pluginThen Refresh in the overlay’s Mods window. After each change, Reload on its row there.
dotnet publishwraith dev add distdist gets the DLL, wraith.json and your schemas. Refresh in the overlay’s Mods window. After that, dotnet publish and Reload on its row there for a CoreCLR one. A NativeAOT one shows as On till the game closes, with no Reload, so restart the game to try a change. While you’re working on it, CoreCLR is quicker, and the same code builds either way.
cmake -B buildcmake --build build --config Releasewraith dev add dist-A Win32 on the first line builds 32-bit. dist gets the DLL, wraith.json and your schemas. Refresh in the overlay’s Mods window. After that, cmake --build build --config Release and Reload on its row there.
With --build zig, it’s zig build and wraith dev add zig-out, like a Zig plugin.
wraith sdk rust buildwraith dev add distsdk rust build writes .wraith/rust again, runs cargo build for each arch in wraith.json, and puts wraith_my_plugin_x64.dll, wraith.json and your schemas in dist. Refresh in the overlay’s Mods window. After that, wraith sdk rust build and Reload on its row there. --debug builds a debug one.
Plain cargo build and cargo check work too, but leave the DLL in target under cargo’s name.
zig buildwraith dev add zig-outzig-out gets a DLL for each arch and wraith.json. Refresh in the overlay’s Mods window. After that, zig build and Reload on its row there.
-Dtarget=x86_64-windows builds just one arch, which is quicker while you’re working.
cmake -B buildcmake --build build --config Releasewraith dev add dist-A Win32 on the first line builds 32-bit. Refresh in the overlay’s Mods window. After that, cmake --build build --config Release and Reload on its row there.
With --build zig, it’s zig build and wraith dev add zig-out, like a Zig plugin.
Scripts
Section titled “Scripts”TypeScript plugins come with these npm scripts.
| Command | What it does |
|---|---|
npm run dev |
Builds on every change. Skips type checks for speed. |
npm run build |
Type checks and builds dist/ once. |
npm run types |
Refreshes the typings in .wraith/types for your editor. |
npm run pack |
Builds and zips it as <name>-<version>.zip. |
Packing it
Section titled “Packing it”For a Lua plugin, zip the folder when you want to share it. The hub wants the files inside a folder named after the plugin’s id, like my-plugin/main.lua. TypeScript plugins have npm run pack for this. For the others, zip what the build put in dist, or zig-out for a Zig build, the same way.
Editor
Section titled “Editor”Any editor that speaks TypeScript works, since the typings are plain .d.ts files. wraith.d.ts declares the "wraith" module your code imports from, and salamander.d.ts the "salamander" one.
The Wraith extension for VS Code is optional, but useful.
If autocomplete for Wraith or your own namespace stops working, run npm run types.
Any editor works. One with LuaLS, the lua-language-server, also gets completions and type checks for everything in Wraith. Run this in your plugin’s folder to give it Wraith’s types:
wraith sdk lua typesThey go in .wraith/types. wraith.lua is what require("wraith") gives, with your schemas/ types under your namespace, wraith_hooks.lua types the typed hooks, and salamander.lua is require("salamander"). It also makes a .luarc.json pointing there. If you already have one, add ".wraith/types" to its workspace.library.
In VS Code, install the Lua extension and the Wraith extension. The Wraith one runs that command for you when you open the folder and when you change a .sal file, so the types match the Wraith you have.
The types are only for your editor, so Wraith runs your plugin the same either way. Nothing else makes them again, so run the command again after you update Wraith, whose API they are, after changing your schemas/, or when a plugin you depend on changes its schemas. VS Code does the first two for you, but not the last, since that plugin’s folder isn’t open. If autocomplete for Wraith stops working or looks out of date, run Wraith: Update Lua types from the command palette, or the command above.
Any editor with C# support works, like Visual Studio, Rider, or VS Code with the C# Dev Kit. The C# for Wraith’s API is in .wraith/cs, and builds make it again, so after updating Wraith or changing a schema, build once and the editor catches up. wraith sdk cs types in the plugin’s folder does the same without building.
Any editor with C++ support works. The headers are in the build folder, in build/wraith_cpp, which CMake hands to the editor along with everything else, like through compile_commands.json or Visual Studio’s own CMake support.
Any editor with rust-analyzer works. It sees Wraith’s API through the wraith crate in .wraith/rust, which build.rs keeps up to date.
Any editor with Zig support works. The Wraith extension for VS Code is optional, but useful.
Any editor with C support works. The headers are in the build folder, in build/wraith_c, which CMake hands to the editor along with everything else, like through compile_commands.json or Visual Studio’s own CMake support.
The Wraith extension highlights your .sal schemas and has snippets for them.
wraith.io · Mods on the Hub · Get Wraith
Made with ♥ by Asgard
