nitanmarcel/ScriptHookVZig
Write GTA V mods using Zig
Develop GTA V mods with the help of Zig
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;
}