Skip to content

Files

sdk.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. JS and Lua plugins get it too.

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

try sdk.vfs.put("C:/Games/Example/config/difficulty.ini", "[Game]\nDifficulty=Hard\n");
try sdk.vfs.putDir("C:/Games/Example/saves");
// later, a save the game wrote there
const save = try sdk.vfs.readAlloc(allocator, "C:/Games/Example/saves/slot1.sav");
defer allocator.free(save);

A virtual file hides a real one at the same path. Files the game creates in a putDir folder are virtual too. sdk.vfs.remove(path) takes one away, and everything you put goes when your plugin stops.

watch calls you on the thread doing the I/O, which waits for you. Set reply to redirect or refuse an open, or refuse a write. A read’s data can be changed in place.

fn onFile(self: *Plugin, event: sdk.vfs.Event, reply: *sdk.vfs.Reply) void {
_ = self;
if (event.kind == .open and std.mem.endsWith(u8, event.path, "/intro.bik")) {
reply.refuse(.not_found);
}
}
// in start
self.watch = try sdk.vfs.watch(.{
.kinds = .{ .open = true },
.pattern = "C:/Games/Example/movies/*",
}, self, onFile);
// in stop, or let it go with the plugin
self.watch.unwatch();

event.file is the same for every handle to one open file. event.requested is what the game asked for, and event.path where it really is. Existence checks only come with .queries = true, and DLL loads only with .loader = true. The loader holds a lock then, so don’t wait on other threads.

If file_io is off in the settings, calls fail with error.Unavailable.

Made with ♥ by Asgard