A scripting runtime for GTA VI running under VIctory: an in-game F8 console, Lua resources you start, stop and restart while you play, and native calls that cannot crash the game.
Everything ships in two files and needs nothing installed: Lua, Dear ImGui and the table of the game's natives are built into the runtime.
It needs a VIctory build that loads host DLLs through VICTORY_LOAD_DLLS, such as
VIctory-NVIDIA.
- Copy
vi-scripting.exeand thevi-scriptingfolder next tovictory.exe. - Start
vi-scripting.exeinstead ofvictory.exe. It starts the game with the runtime loaded and passes its own arguments on tovictory.exe. - Press F8 in game.
On the first start the runtime writes vi-scripting/autoexec.cfg and the example resources in
vi-scripting/resources/[examples]: hello, timeofday, noclip (F9 flies, the camera gives the
way), imgui (F7 opens a window that sets the clock) and esp (F6 boxes and names the player and the
closest vehicle). Its log is vi-scripting/logs/vi-scripting.log, and vi-scripting/types holds the annotations
an editor reads to complete the API (API.md).
F8 opens and closes it. While it is open the game gets no keyboard, mouse or XInput pad input. Up and Down walk the
history, Tab completes command and resource names, ^1..^9 in printed text are colors (^0 resets).
| Command | What it does |
|---|---|
start <resource>... |
Start resources, and what they depend on |
stop <resource>... |
Stop resources, and what depends on them |
restart <resource>... |
Stop and start again; resources that depended on them come back too |
ensure <resource>... |
Start, or restart when already running |
refresh |
Look for new resources |
resources |
List the resources, their state, script time and memory |
lua <code> |
Run Lua in the console's own state and print what it returns |
native <name> [args...] |
Call a native and print what it returns: native GET_CLOCK_HOURS |
natives <filter> |
Search the natives by name or namespace |
status |
Game build, natives bound, script tick, overlay |
perf |
What the runtime cost the game since the last perf: its tick, its natives, its overlay |
keys |
The keys resources bound to commands |
drawcheck [fov reading] |
Compare where the runtime draws points of the world with where the game puts them |
exec <file> |
Run the commands of a file of the vi-scripting folder |
help, clear |
Commands registered by resources run the same way. autoexec.cfg holds commands run when the game starts,
one per line. Any tool can drop a vi-scripting/run.cfg: its commands run at the next script tick, then the
file is deleted.
The Resources window profiles every running resource: its own script time per tick (average and worst over the last 120 ticks, with a graph), its Lua memory and its native calls per tick. Time a resource spends in another resource's export or event handler counts for that other resource.
A resource is a folder under vi-scripting/resources. Folders named [like this] only group resources.
manifest.lua is optional:
description 'What this resource does'
version '1.0.0'
dependency 'hello'
scripts {
'main.lua',
'client/*.lua',
}Without a manifest, every .lua file at the root of the folder runs, in name order. Each resource runs in its
own Lua 5.4 state.
RegisterCommand('pos', function(source, args, raw)
local coords = GetEntityCoords(PlayerPedId(), false)
print(('^2You are at^0 %.2f, %.2f, %.2f'):format(coords.x, coords.y, coords.z))
end)
AddEventHandler('onResourceStart', function(resource)
if resource == GetCurrentResourceName() then
print('started')
end
end)
CreateThread(function()
while true do
Wait(1000)
TriggerEvent('demo:second', GetClockHours())
end
end)The essentials; API.md has every function and value.
Wait(ms) |
Let the game run, come back in ms (0: next tick) |
CreateThread(fn), CreateThreadNow(fn), SetTimeout(ms, fn) |
Script threads |
AddEventHandler(name, fn), RemoveEventHandler(handler), TriggerEvent(name, ...) |
Events, across every resource |
exports('name', fn), exports.resource:name(...) |
Functions other resources call |
RegisterCommand(name, fn), ExecuteCommand(line) |
Console commands |
GetCurrentResourceName(), GetResourceState(name), LoadResourceFile(resource, path) |
Resources |
IsKeyDown(key) |
A key held down ('W', 'F9', 'SPACE', 'SHIFT', 'PAGEUP'...); always false while the console is open |
RegisterKeyMapping(command, description, 'keyboard', key) |
A key that runs a command; +command runs on press and -command on release |
BlockGameKeyboard(on) |
The game gets no keyboard while any resource asks it; a stopped resource lets go |
Notify(text, seconds) |
A note in the corner of the screen |
Draw.Text(x, y, text, color), Draw.Line, Draw.BoundingBox(entity, color)... |
Shapes and text drawn over the game, on the screen or in the world |
ImGui.Begin(name), ImGui.Button(label), ImGui.SliderFloat(...)... |
Dear ImGui windows; ImGui.SetInteractive(true) gives them the mouse and keyboard |
vector3(x, y, z), joaat(text), NativeBuffer(size), GetNativeInfo(name) |
Helpers |
InvokeNative(hash or name, ...) |
A native by its 64-bit hash or name |
Scripting.Wait, Scripting.CreateThread, ... |
The same functions under one table |
The runtime raises onResourceStarting, onResourceStart and onResourceStop with the resource's name.
Values passed through events, exports and commands may be nil, booleans, numbers, strings, tables, vectors and
entities.
Every native is a global, by its name (GET_ENTITY_COORDS) or in PascalCase (GetEntityCoords). Before a native
reaches the game its arguments are checked against the native table, their count and their types: a wrong call is a
Lua error at the script's line, and the game never sees it. What a native writes behind a pointer comes back after its
result: local visible, x, y = GetScreenCoordFromWorldCoord(coords).
API.md has the whole API, how each native type converts, and how to set up an editor with the annotations
the runtime writes to vi-scripting/types.
- A native that faults is caught: the call becomes a Lua error, the engine lock it held is released, and the console says where it faulted.
SET_ENTITY_COORDSon a ped waits for the ped's update jobs, and from where scripts run that wait can freeze the game: the runtime reads the jobs first and refuses the call for that tick when it would wait.- A native that holds the game's thread more than 4 ms is reported in the console (
perfsums them up). - A script that runs for more than a second without
Waitis stopped with an error. - Errors in a thread, an event handler or a command stop that thread only.
- Events, exports and commands calling one another more than 16 deep are refused.
- Each resource's Lua state is limited to 256 MiB. There is no
io,os.exit,os.execute,dofile,loadfile,requireor binary chunk loading.
The toolchain is pinned in rust-toolchain.toml (MSVC target).
cargo test --workspace
cargo xtask dist # dist/vi-scripting.exe and dist/vi-scripting/vi_scripting_runtime.dll
cargo xtask install <game folder> # dist, then copied next to victory.exe
cargo xtask smoke # the release runtime started against VIctory's cached game image
cargo run -p vi-scripting-runtime --example preview # the console drawn without the game, as a PNGcrates/runtime/data/natives.json is the natives.json of the dist branch of
ragetools/vi-natives, embedded as it is: cargo xtask natives <clone or natives.json> replaces it and runs the tests that check it.
| Crate | |
|---|---|
crates/runtime |
vi_scripting_runtime.dll: hooks, natives, Lua, console |
crates/launcher |
vi-scripting.exe |
crates/xtask |
The tasks above |
- The script tick is found by its code in game build 1794606036 (Xbox Series 1.0.2.1). On another build the console still opens, but scripts do not run.
- Natives run on the game's script thread at the end of its script update, as no particular game script: natives that need a script of their own may refuse or fault.
- Lua is the only scripting language for now; the resource system keeps languages apart so others can join.