UI
The UI is Dear ImGui. Its calls are the imgui area, named like Dear ImGui’s own, and they only work while something’s drawing, like a window’s draw or a threads.onDraw callback. Keys and the mouse are on Keybinds and input.
Windows
Section titled “Windows”ui.addWindow(options, draw) gives you a window on the overlay. It starts closed. Its close button, Esc, its tile on the hub and your plugin’s Settings button all work with no code of yours, and it goes when your plugin does.
draw runs on the render thread between the window’s Begin and End, so you only draw what’s in it.
import { Wraith } from "wraith";
const imgui = Wraith.imgui();const speed = { value: 1 };
const window = Wraith.ui().addWindow({ title: "Speed", icon: "gauge", settings: true }, () => { imgui.SliderFloat("Speed", speed, 0.5, 5); if (imgui.Button("Reset")) speed.value = 1;});Calls that change a value, like SliderFloat or Checkbox, take a box like { value: 1 }. Autocomplete on imgui. shows them all. Text is imgui.TextUnformatted, and Wraith.ui() has a few extras like inputText, which takes and gives a string.
local Wraith = require("wraith").Wraith
local imgui = Wraith.imgui()local speed = { value = 1 }
local window = Wraith.ui():addWindow({ title = "Speed", icon = "gauge", settings = true }, function() imgui:SliderFloat("Speed", speed, 0.5, 5) if imgui:Button("Reset") then speed.value = 1 endend)Calls that change a value, like SliderFloat or Checkbox, take a box like { value = 1 }. Text is imgui:TextUnformatted, and Wraith.ui() has a few extras like inputText, which takes and gives a string.
Window? window;float speed = 1;
// in Startvar imgui = ImGui.Instance;
window = Ui.Instance.AddWindow(new Window.Options { Title = "Speed", Icon = "gauge", Settings = true }, () =>{ imgui.SliderFloat("Speed", ref speed, 0.5f, 5); if (imgui.Button("Reset")) speed = 1;});Keep the window in a field. Text is TextUnformatted, and Ui.Instance has a few extras like InputText, which takes and gives a string.
static Wraith::Window window;static float speed = 1;
// in startwindow = wraith::api().ui().addWindow({.title = sal::String::of("Speed"), .icon = sal::String::of("gauge"), .settings = true}, sal::keep<Wraith::Window::Draw>([] { auto imgui = wraith::api().imgui(); imgui.SliderFloat("Speed", &speed, 0.5f, 5); if (imgui.Button("Reset")) speed = 1;}));ImGui’s calls take C strings, like Dear ImGui’s own. Text is TextUnformatted, and ui() has a few extras like inputText, which takes and gives a string.
use std::sync::Mutex;
use salamander::Str;use wraith::{Window, WindowDraw, WindowOptions};
static SPEED: Mutex<f32> = Mutex::new(1.0);
fn add_window() -> Window { let options = WindowOptions { title: Str::new("Speed"), icon: Str::new("gauge"), settings: true, ..Default::default() }; wraith::api().ui().add_window(options, WindowDraw::keep(|| { let imgui = wraith::api().imgui(); let mut speed = SPEED.lock().unwrap(); imgui.slider_float(c"Speed".as_ptr().cast(), &mut *speed, 0.5, 5.0); if imgui.button(c"Reset".as_ptr().cast()) { *speed = 1.0; } }))}ImGui’s calls take C strings, like c"Speed". Text is text_unformatted, and ui() has a few extras like input_text, which takes and gives a &str.
The draw is a method of yours, and sdk.ui has Zig’s own ImGui calls.
speed: f32 = 1,window: W.Window = undefined,
fn drawSpeed(self: *Plugin) void { _ = sdk.ui.slider("Speed", &self.speed, 0.5, 5); if (sdk.ui.button("Reset")) self.speed = 1;}
// in startself.window = ctx.wraith.ui().addWindow(.{ .title = "Speed", .icon = "gauge", .settings = true }, .init(self, drawSpeed));The SDK has windows of its own too, which are Zig only. One’s a struct with a window field and a draw method, kept in your plugin struct since it mustn’t move.
const SpeedWindow = struct { window: sdk.ui.Window = .{ .title = "Speed" }, speed: f32 = 1,
pub fn draw(self: *SpeedWindow) void { _ = sdk.ui.slider("Speed", &self.speed, 0.5, 5); }};
// in starttry ctx.addWindow(&self.speed_window);// Its tile on the hub, and the Settings button, both open ittry ctx.hubButton("Speed", "gauge", &self.speed_window.window.open);ctx.settingsWindow(&self.speed_window.window.open);sdk.ui.Window has size, min_size, max_size, flags, closable and close_on_escape, and its open field is whether it’s open.
static Wraith_Window window;static float speed = 1;
static void draw_speed(uintptr_t self) { (void)self; Wraith_ImGui imgui = Wraith_Api_imgui(w); Wraith_ImGui_SliderFloat(imgui, "Speed", &speed, 0.5f, 5); if (Wraith_ImGui_Button(imgui, "Reset")) speed = 1;}
static const Wraith_Window_Draw_table draw_speed_table = { SAL_TABLE(Wraith_Window_Draw), .call = draw_speed };
/* in start */Wraith_Window_Options options = { .title = SAL_STR("Speed"), .icon = SAL_STR("gauge"), .settings = true };window = Wraith_Ui_addWindow(Wraith_Api_ui(w), options, (Wraith_Window_Draw){ 0, &draw_speed_table });Text is Wraith_ImGui_TextUnformatted, and Wraith_Ui has a few extras like Wraith_Ui_inputText, which takes and gives a string.
Window.Options only needs a title, which also tells the window apart from your others.
sizeis how big it starts the first time.min_sizeandmax_sizelimit it. Zero lets ImGui pick, or means no limit.flagsare ImGui’s window flags,ImGuiWindowFlags.no_closeleaves out its close button, andkeep_on_escapestops Esc closing it.icongives it a tile on the hub, the overlay’s bar, which opens and closes it. It’s a Lucide icon’s name, like"gauge".settingsmakes your plugin’s Settings button on the Mods page open it.
The Window you get back has isOpen, setOpen, focus to open it and bring it to the front, setUnsaved for a dot in its title, and remove.
window.setOpen(true);if (window.isOpen()) window.setUnsaved(true);Flags are Wraith.ImGuiWindowFlags, like flags: Wraith.ImGuiWindowFlags.AlwaysAutoResize.
window:setOpen(true)if window:isOpen() then window:setUnsaved(true) endFlags are Wraith.ImGuiWindowFlags, like flags = Wraith.ImGuiWindowFlags.AlwaysAutoResize.
The options are Title, Size, MinSize, MaxSize, Flags, NoClose, KeepOnEscape, Menu and Settings.
window.SetOpen(true);if (window.IsOpen()) window.SetUnsaved(true);static Wraith::Window window;
// in startwindow.setOpen(true);if (window.isOpen()) window.setUnsaved(true);Flags are Wraith::ImGuiWindowFlags, like .flags = Wraith::ImGuiWindowFlags::AlwaysAutoResize.
use wraith::Window;
fn open(window: Window) { window.set_open(true); if window.is_open() { window.set_unsaved(true); }}Flags are ImGuiWindowFlags, like flags: ImGuiWindowFlags::ALWAYS_AUTO_RESIZE.
self.window.setOpen(true);if (self.window.isOpen()) self.window.setUnsaved(true);With an sdk.ui.Window, set its fields, or call show, focus or close, like self.speed_window.window.focus().
static Wraith_Window window;
/* in start */Wraith_Window_setOpen(window, true);if (Wraith_Window_isOpen(window)) Wraith_Window_setUnsaved(window, true);Flags are Wraith_ImGuiWindowFlags, like .flags = Wraith_ImGuiWindowFlags_AlwaysAutoResize.
Drawing without a window
Section titled “Drawing without a window”threads.onDraw runs once a frame on the render thread, inside ImGui’s frame. Draw lists from ui.foregroundDrawList() and ui.backgroundDrawList() draw over everything or behind the windows, for markers and labels. imgui.Begin and imgui.End work there too, for a window you run yourself. End goes after every Begin, even when it gives false.
import { Wraith } from "wraith";
Wraith.threads().onDraw(() => { Wraith.ui().foregroundDrawList()?.AddCircle({ x: 100, y: 100 }, 6, 0xff00ff00);});local Wraith = require("wraith").Wraith
Wraith.threads():onDraw(function() Wraith.ui():foregroundDrawList():AddCircle({ x = 100, y = 100 }, 6, 0xff00ff00)end)drawing = Threads.Instance.OnFrame(() =>{ Ui.Instance.ForegroundDrawList()?.AddCircle(new ImVec2 { X = 100, Y = 100 }, 6, 0xff00ff00);});Begin takes a pointer for its close flag, so it needs unsafe code. A window from AddWindow doesn’t.
auto drawing = wraith::api().threads().onDraw(sal::keep<Wraith::Threads::Draw>([] { wraith::api().ui().foregroundDrawList().AddCircle({100, 100}, 6, 0xff00ff00);}));use wraith::{ImVec2, ThreadsDraw};
let drawing = wraith::api() .threads() .on_draw(ThreadsDraw::keep(|| { wraith::api().ui().foreground_draw_list().add_circle(ImVec2 { x: 100.0, y: 100.0 }, 6.0, 0xff00ff00); })) .ok()?;fn drawMarker(self: *Plugin) void { _ = self; sdk.ui.getForegroundDrawList().addCircle(.{ 100, 100 }, 6, sdk.ui.rgba(0, 255, 0, 255), 2);}
// in startself.marker = try ctx.onDraw(self, drawMarker);static void draw_marker(uintptr_t self) { (void)self; Wraith_ImDrawList_AddCircle(Wraith_Ui_foregroundDrawList(Wraith_Api_ui(w)), (Wraith_ImVec2){ 100, 100 }, 6, 0xff00ff00);}
static const Wraith_Threads_Draw_table draw_marker_table = { SAL_TABLE(Wraith_Threads_Draw), .call = draw_marker };
/* in start */Wraith_Threads_Subscription drawing;Wraith_Threads_onDraw(Wraith_Api_threads(w), (Wraith_Threads_Draw){ 0, &draw_marker_table }, &drawing);The menu and the Settings button
Section titled “The menu and the Settings button”Your plugin gets a Settings button in the overlay’s Mods window. Without any code it opens your settings in Wraith’s Settings.
For more than settings can show, give a window of your own settings: true, like above. ui.onOpenSettings is for anything else the button should do.
import { Wraith } from "wraith";
Wraith.ui().onOpenSettings(() => window.focus());local Wraith = require("wraith").Wraith
Wraith.ui():onOpenSettings(function() window:focus() end)Ui.Instance.OnOpenSettings(() => window!.Focus());static Wraith::Window window;
// in startwraith::api().ui().onOpenSettings(sal::keep<Wraith::Ui::OpenSettings>([] { window.focus(); }));use std::sync::OnceLock;
use wraith::{UiOpenSettings, Window};
static WINDOW: OnceLock<Window> = OnceLock::new();
fn on_settings() { wraith::api().ui().on_open_settings(UiOpenSettings::keep(|| { if let Some(window) = WINDOW.get() { window.focus(); } }));}fn openSettings(self: *Plugin) void { self.window.focus();}
// in startctx.wraith.ui().onOpenSettings(.init(self, openSettings));For an sdk.ui.Window, ctx.settingsWindow(&self.speed_window.window.open) does it.
static Wraith_Window window;
static void open_settings(uintptr_t self) { (void)self; Wraith_Window_focus(window);}
static const Wraith_Ui_OpenSettings_table open_settings_table = { SAL_TABLE(Wraith_Ui_OpenSettings), .call = open_settings };
/* in start */Wraith_Ui_onOpenSettings(Wraith_Api_ui(w), (Wraith_Ui_OpenSettings){ 0, &open_settings_table });For something players open often, give it a tile on the hub, the overlay’s bar. A window’s icon does it for you, a Lucide icon’s name like "user" from lucide.dev/icons. For anything else, add a Wraith.HubButton to the hub slot: its describe gives the tile’s title, icon and order, isOpen lights it, and click runs when it’s clicked.
import { Wraith } from "wraith";import { implement } from "salamander";
let stats = false;Wraith.ui().contributeTo("hub", implement("Wraith.HubButton", { describe() { return { title: "Stats", icon: "chart-column" }; }, isOpen() { return stats; }, click() { stats = !stats; },}));local Wraith = require("wraith").Wraithlocal sal = require("salamander")
local stats = falseWraith.ui():contributeTo("hub", sal.implement("Wraith.HubButton", { describe = function(self) return { title = "Stats", icon = "chart-column" } end, isOpen = function(self) return stats end, click = function(self) stats = not stats end,}))// A tile that opens and closes a window, or anything with a `bool`try ctx.hubButton("Stats", "chart-column", &self.stats_window.window.open);Other languages add one like any slot’s object, see Slots of your own.
Game values
Section titled “Game values”ui.editStruct(type, address) draws a struct from your schemas as controls, read from the game each frame and written as they’re changed.
import { Wraith } from "wraith";
const ui = Wraith.ui();
ui.addWindow({ title: "Money", icon: "coins" }, () => { if (!ui.editStruct("GameStateManager", 0)) Wraith.imgui().TextUnformatted("Load a save first");});local Wraith = require("wraith").Wraith
local ui = Wraith.ui()
ui:addWindow({ title = "Money", icon = "coins" }, function() if not ui:editStruct("GameStateManager", 0) then Wraith.imgui():TextUnformatted("Load a save first") endend)var ui = Ui.Instance;
money = ui.AddWindow(new Window.Options { Title = "Money", Icon = "coins" }, () =>{ if (!ui.EditStruct("GameStateManager", 0)) ImGui.Instance.TextUnformatted("Load a save first");});auto money = wraith::api().ui().addWindow({.title = sal::String::of("Money"), .icon = sal::String::of("coins")}, sal::keep<Wraith::Window::Draw>([] { if (!wraith::api().ui().editStruct("GameStateManager", 0)) wraith::api().imgui().TextUnformatted("Load a save first");}));use salamander::Str;use wraith::{WindowDraw, WindowOptions};
let options = WindowOptions { title: Str::new("Money"), icon: Str::new("coins"), ..Default::default() };let money = wraith::api().ui().add_window(options, WindowDraw::keep(|| { if !wraith::api().ui().edit_struct("GameStateManager", 0) { wraith::api().imgui().text_unformatted(c"Load a save first".as_ptr().cast()); }}));fn drawMoney(self: *Plugin) void { if (!self.ctx.wraith.ui().editStruct("GameStateManager", 0)) sdk.ui.text("Load a save first", .{});}
// in startself.money = ctx.wraith.ui().addWindow(.{ .title = "Money", .icon = "coins" }, .init(self, drawMoney));static void draw_money(uintptr_t self) { (void)self; if (!Wraith_Ui_editStruct(Wraith_Api_ui(w), SAL_STR("GameStateManager"), 0)) Wraith_ImGui_TextUnformatted(Wraith_Api_imgui(w), "Load a save first");}
static const Wraith_Window_Draw_table draw_money_table = { SAL_TABLE(Wraith_Window_Draw), .call = draw_money };
/* in start */Wraith_Window_Options options = { .title = SAL_STR("Money"), .icon = SAL_STR("coins") };Wraith_Window money = Wraith_Ui_addWindow(Wraith_Api_ui(w), options, (Wraith_Window_Draw){ 0, &draw_money_table });The type’s name is looked for in your plugin’s namespace first, like other names given as text. Labels, ranges and the rest come from the schema’s annotations. Pass 0 to use the struct’s [Instance], or the address of one you found. It gives false when your schemas don’t have the type, or the game hasn’t made it yet. Usually tagging the struct [Tweak("..")] is enough, and it shows in the Tweaks window without any code.
Toasts
Section titled “Toasts”ui.toast(toast) pops up a short message in the corner, and gives its id. ui.updateToast(id, toast) changes it, and ui.dismissToast(id) takes it away. A Toast has a style, which is info, success, warning or failure, a title, its text and seconds. A title that’s empty shows your plugin’s name, and seconds of 0 keeps it up till it’s clicked.
import { Wraith } from "wraith";
Wraith.ui().toast({ style: "success", title: "My Plugin", text: "Done!", seconds: 4 });local Wraith = require("wraith").Wraith
Wraith.ui():toast({ style = "success", title = "My Plugin", text = "Done!", seconds = 4 })Ui.Instance.Toast(new Toast { Style = Toast.Kind.Success, Title = "My Plugin", Text = "Done!", Seconds = 4 });wraith::api().ui().toast({.style = Wraith::Toast::Kind::success, .title = sal::String::of("My Plugin"), .text = sal::String::of("Done!"), .seconds = 4});use salamander::Str;use wraith::{Toast, ToastKind};
wraith::api().ui().toast(Toast { style: ToastKind::SUCCESS, title: Str::new("My Plugin"), text: Str::new("Done!"), seconds: 4.0, ..Default::default() });_ = ctx.wraith.ui().toast(.{ .style = .success, .title = "My Plugin", .text = "Done!", .seconds = 4 });Wraith_Toast toast = { .style = Wraith_Toast_Kind_success, .title = SAL_STR("My Plugin"), .text = SAL_STR("Done!"), .seconds = 4 };Wraith_Ui_toast(Wraith_Api_ui(w), toast);Screen size
Section titled “Screen size”ui.displaySize() is the game window’s size in pixels, and zero outside a frame. Draw lists work in screen pixels from the game window’s corner.
import { Wraith } from "wraith";
const ui = Wraith.ui();const size = ui.displaySize();const red = Wraith.imgui().ColorConvertFloat4ToU32({ x: 1, w: 1 });ui.foregroundDrawList()?.AddLineEx({ x: 0, y: 0 }, size, red, 2, 0);local Wraith = require("wraith").Wraith
local ui = Wraith.ui()local size = ui:displaySize()local red = Wraith.imgui():ColorConvertFloat4ToU32({ x = 1, w = 1 })ui:foregroundDrawList():AddLineEx({ x = 0, y = 0 }, size, red, 2, 0)var ui = Ui.Instance;var size = ui.DisplaySize();var red = ImGui.Instance.ColorConvertFloat4ToU32(new ImVec4 { X = 1, W = 1 });ui.ForegroundDrawList()?.AddLineEx(new ImVec2(), size, red, 2, ImDrawFlags.None);auto ui = wraith::api().ui();auto size = ui.displaySize();auto red = wraith::api().imgui().ColorConvertFloat4ToU32({.x = 1, .w = 1});ui.foregroundDrawList().AddLineEx({0, 0}, size, red, 2, Wraith::ImDrawFlags::None);use wraith::{ImDrawFlags, ImVec2, ImVec4};
let ui = wraith::api().ui();let size = ui.display_size();let red = wraith::api().imgui().color_convert_float4_to_u32(ImVec4 { x: 1.0, w: 1.0, ..Default::default() });ui.foreground_draw_list().add_line_ex(ImVec2::default(), size, red, 2.0, ImDrawFlags::NONE);sdk.ui.getDisplaySize() gives it too. In the Workbench, which is a window of its own, the main window doesn’t start at 0,0, so add sdk.ui.getMainViewportPos() when you place things yourself.
const size = sdk.ui.getDisplaySize();const corner = sdk.ui.getMainViewportPos();sdk.ui.getWindowDrawList().addLine(corner, .{ corner[0] + size[0], corner[1] + size[1] }, sdk.ui.rgba(255, 0, 0, 255), 2);Wraith_Ui ui = Wraith_Api_ui(w);Wraith_ImVec2 size = Wraith_Ui_displaySize(ui);uint32_t red = Wraith_ImGui_ColorConvertFloat4ToU32(Wraith_Api_imgui(w), (Wraith_ImVec4){ .x = 1, .w = 1 });Wraith_ImDrawList_AddLineEx(Wraith_Ui_foregroundDrawList(ui), (Wraith_ImVec2){ 0, 0 }, size, red, 2, Wraith_ImDrawFlags_None);Over the world
Section titled “Over the world”To draw something where it is in the game, like a label over a character, you need the game’s camera. display.gameView() gives a Display.View with its viewMatrix and projection, row-vector matrices the way Direct3D has them: clip space is [x y z 1] * view * projection, the camera looks down +z, and depth goes from 0 to 1. known is false till the game’s plugin has said, and again if it stops saying for a second.
The game’s plugin claims the view’s lease with display.claimView(), then sets it with display.setView(view, projection) each frame, once the camera’s where it’ll be drawn from, after the free camera has moved it. The Unity plugin does it for every Unity game. If the game’s camera is the other way round, like OpenGL’s, turn it round before setting it.
import { Wraith } from "wraith";
const view = Wraith.display().gameView();if (view.known) drawOverWorld(view.viewMatrix, view.projection);local Wraith = require("wraith").Wraith
local view = Wraith.display():gameView()if view.known then draw_over_world(view.viewMatrix, view.projection) endvar view = Display.Instance.GameView();if (view.Known) DrawOverWorld(view.ViewMatrix, view.Projection);void draw_over_world(const Wraith::Mat4& view, const Wraith::Mat4& projection);
// in startauto view = wraith::api().display().gameView();if (view.known) draw_over_world(view.viewMatrix, view.projection);use wraith::Mat4;
fn draw_over_world(view: &Mat4, projection: &Mat4) {}
fn draw() { let view = wraith::api().display().game_view(); if view.known { draw_over_world(&view.view_matrix, &view.projection); }}ctx.wraith.display().gameView() works as in other languages. The SDK’s sdk.display.view() is a Zig helper on top, which is null when it’s not known. Its project puts a point in the world on screen, or gives null if it’s behind the camera.
const view = sdk.display.view() orelse return;const size = sdk.ui.getDisplaySize();if (view.project(head, size)) |at| sdk.ui.getBackgroundDrawList().addCircle(at, 6, sdk.ui.rgba(255, 255, 255, 255), 2);void draw_over_world(const Wraith_Mat4 *view, const Wraith_Mat4 *projection);
/* in start */Wraith_Display_View view = Wraith_Display_gameView(Wraith_Api_display(w));if (view.known) draw_over_world(&view.viewMatrix, &view.projection);Wraith matches the overlay to how the game’s picture is encoded, SDR or HDR, from what the game tells its swap chain. If it joined the game late it missed that, and a 10-bit swap chain could be either, so it takes it as SDR. The plugin holding the view can say with display.setColorSpace, hdr10 for HDR or srgb for SDR, and again whenever it changes. What the game sets on its swap chain itself still wins, and it goes with the lease. The Unreal plugin asks the game’s settings, for one.
For moving, turning or scaling something of yours, ui.addGizmo() gives handles Wraith draws with the game’s camera. place it each tick where your thing is, show it, and moved() gives where it’s been dragged to since you last asked. Only one gizmo shows at a time, the one shown last.
Picking files and folders
Section titled “Picking files and folders”The file and folder dialogs are in Settings and files, since what the player picks is the plugin’s to use.
wraith.io · Mods on the Hub · Get Wraith
Made with ♥ by Asgard
