Skip to content

Files

wraith.vfs sees the game’s files. Serve files that aren’t on disk, send the game somewhere else when it opens one, refuse a write, or just watch what it reads.

Paths use forward slashes, like C:/Game/data.pak. Backslashes work going in too, and case doesn’t matter.

vfs.put makes a file the game can open, read and list like any other. It hides a real file at the same path.

local wraith = require("wraith")
local vfs = wraith.vfs
vfs.put("C:/Games/Example/config/difficulty.ini", "[Game]\nDifficulty=Hard\n")

vfs.putDir(path) makes a folder. Files the game creates in it are virtual too, so its saves can live there without touching the disk. Read them back with vfs.read(path), which gives the bytes, or nil if there’s no such file.

vfs.remove(path) takes a file or folder away. Whatever the game already has open keeps working. Everything you put goes when your plugin stops. In a tweak, it goes when the tweak turns off.

vfs.watch calls you for what the game does with files that match pattern. * matches anything, slashes too, and ? any one character. Ask for the kinds you want: open, opened, failed, read, write and closed. For an open, return a path to open instead, or false to refuse it. For a write, return false to refuse it.

-- Use our own textures, wherever the game looks for them
local id = vfs.watch({ pattern = "C:/Games/Example/textures/*.dds", open = true }, function(event)
if event.kind == "open" then
return (event.path:gsub("/textures/", "/mods/textures/"))
end
end)
-- Keep the game from writing its log
vfs.watch({ pattern = "*/game.log", write = true }, function() return false end)
vfs.unwatch(id)

The event has path, where the file really is, and requested, what the game asked for. file is the same number for every handle to one open file. Pass data = true to get the bytes of reads and writes as data.

The game’s thread waits for your callback, so keep it quick. Existence checks only come with queries = true, and DLL loads only with loader = true. See the JS page for the details, which are the same.

Made with ♥ by Asgard