Skip to content

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.

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.

Window.Options only needs a title, which also tells the window apart from your others.

  • size is how big it starts the first time. min_size and max_size limit it. Zero lets ImGui pick, or means no limit.
  • flags are ImGui’s window flags, ImGuiWindowFlags.
  • no_close leaves out its close button, and keep_on_escape stops Esc closing it.
  • icon gives it a tile on the hub, the overlay’s bar, which opens and closes it. It’s a Lucide icon’s name, like "gauge".
  • settings makes 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.

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);
});

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());

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; },
}));

Other languages add one like any slot’s object, see Slots of your own.

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");
});

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.

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 });

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);

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);

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.

The file and folder dialogs are in Settings and files, since what the player picks is the plugin’s to use.

Made with ♥ by Asgard