Develop GTA V mods with the help of Zig
- Zig 0.12.0=>
- ScriptHookV v1.0.3179.0 and it's requirements
zig fetch git+https://github.com/nitanmarcel/ScriptHookVZig#{LastCommitHash} -- save
// Shared/Dynamic library is required
const lib = b.addSharedLibrary(.{
.name = "{name}",
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
// Add ScriptHookVZig as a dependency
const shvz_dep = b.dependency("shvz", .{});
// Import is as a module
lib.root_module.addImport("shvz", shvz_dep.module("shvz"));
// Save the dll
b.installArtifact(lib);
// Copy bin/{name}.dll (zig-0.13.0 and above) / lib/{name}.dll (zig-0.12.0) to the GTA root folder where ScriptHookV.dll is located and rename the library extension to .asi: {name}.dll -> {name}.asi
// import the module
const shvz = @import("shvz");
// Create the script main function
pub export fn scriptMain() void {}
pub const DLL_PROCESS_ATTACH: std.os.windows.DWORD = 1;
pub const DLL_THREAD_ATTACH: std.os.windows.DWORD = 2;
pub const DLL_THREAD_DETACH: std.os.windows.DWORD = 3;
pub const DLL_PROCESS_DETACH: std.os.windows.DWORD = 4;
/// Main entry point. Will be loaded by ScriptHookV.dll
pub fn DllMain(hInstance: std.os.windows.HINSTANCE, reason: std.os.windows.DWORD, lpReserved: std.os.windows.LPVOID) std.os.windows.BOOL {
_ = lpReserved;
switch (reason) {
DLL_PROCESS_ATTACH => {
// shvz.init() REQUIRED
// It handles opening the ScriptHookV.dll library and read symbols from it
shvz.init() catch |e| { };
// register the script's entry point
shvz.main.scriptRegister(hInstance, scriptMain);
},
DLL_PROCESS_DETACH => {
// Unregister the script's entry point
// Call this before shvz.deInit() to ensure taht we didn't unloaded ScriptHookV.dll library.
shvz.main.scriptUnregister(scriptMain);
// call shvz.deInit() REQUIRED
// Will close the loaded ScriptHookV.dll library freeing memory
shvz.deinit();
},
else => {},
}
return std.os.windows.TRUE;
}
- You can find a set of examples (C) and a readme in the ScriptHookV SDK archive and help on gtaforums.
- Natives are documented on Github Pages
- The example project in here only showcases the setup for this respective zig library.
- Alexander Blade - Script Hook V.
- Discord Zig - For guiding me with some things.
- c2z - Helped in the translation of over 6000 native methods from ScriptHookV sdk.
- alloc8or - Most of the native methods are pulled from his gta5-nativedb-data repo
- MIT