Files
WeirdUtils/src/lua.zig
T
MarcelineVQ 3c15c8650a Extract shared lua.zig and add DLL-side marker permission check
Move Lua C API wrappers from main.zig's lua struct into src/lua.zig
so both main.zig and markers.zig import from the same source. Remove
duplicate lapi struct from markers.zig.

Add DLL-side permission gating on WorldMarker/ClearWorldMarker: calls
WoW's IsPartyLeader (0x4e9130) and IsRaidOfficer (0x4bb910) C
functions directly. Requires party leader, raid leader, or raid
assist to place or clear markers. SetMarkerDef/ClearMarkerDef remain
ungated (addon validates sender before calling).
2026-03-02 12:59:38 -08:00

156 lines
4.5 KiB
Zig

//! WoW 1.12.1 Lua C API wrappers (all __fastcall, L in ECX)
const std = @import("std");
const fc: std.builtin.CallingConvention = .{ .x86_fastcall = .{} };
pub const State = *anyopaque;
pub fn getContext() State {
const f: *const fn () callconv(fc) State = @ptrFromInt(0x7040D0);
return f();
}
pub fn gettop(L: State) i32 {
const f: *const fn (State) callconv(fc) i32 = @ptrFromInt(0x6F3070);
return f(L);
}
pub fn settop(L: State, index: i32) void {
const f: *const fn (State, i32) callconv(fc) void = @ptrFromInt(0x6F3080);
f(L, index);
}
pub fn pop(L: State, n: i32) void {
settop(L, -n - 1);
}
pub fn pushvalue(L: State, index: i32) void {
const f: *const fn (State, i32) callconv(fc) void = @ptrFromInt(0x6F3350);
f(L, index);
}
pub fn remove(L: State, index: i32) void {
const f: *const fn (State, i32) callconv(fc) void = @ptrFromInt(0x6F30D0);
f(L, index);
}
pub fn insert(L: State, index: i32) void {
const f: *const fn (State, i32) callconv(fc) void = @ptrFromInt(0x6F31A0);
f(L, index);
}
pub fn typeOf(L: State, index: i32) i32 {
const f: *const fn (State, i32) callconv(fc) i32 = @ptrFromInt(0x6F3400);
return f(L, index);
}
pub fn typeName(L: State, tp: i32) [*:0]const u8 {
const f: *const fn (State, i32) callconv(fc) [*:0]const u8 = @ptrFromInt(0x6F3480);
return f(L, tp);
}
pub fn isnumber(L: State, index: i32) bool {
const f: *const fn (State, i32) callconv(fc) u32 = @ptrFromInt(0x6F34D0);
return f(L, index) != 0;
}
pub fn isstring(L: State, index: i32) bool {
const f: *const fn (State, i32) callconv(fc) u32 = @ptrFromInt(0x6F3510);
return f(L, index) != 0;
}
pub fn pushnil(L: State) void {
const f: *const fn (State) callconv(fc) void = @ptrFromInt(0x6F37F0);
f(L);
}
pub fn pushnumber(L: State, n: f64) void {
// __thiscall: ECX=L, f64 on stack [EBP+8]/[EBP+0xc], ret 8.
const f: *const fn (State, f64) callconv(.{ .x86_thiscall = .{} }) void = @ptrFromInt(0x6F3810);
f(L, n);
}
pub fn pushstring(L: State, s: [*:0]const u8) void {
const f: *const fn (State, [*:0]const u8) callconv(fc) void = @ptrFromInt(0x6F3890);
f(L, s);
}
pub fn pushboolean(L: State, b: i32) void {
const f: *const fn (State, i32) callconv(fc) void = @ptrFromInt(0x6F39F0);
f(L, b);
}
pub fn pushcclosure(L: State, func: usize, n: i32) void {
const f: *const fn (State, usize, i32) callconv(fc) void = @ptrFromInt(0x6F3920);
f(L, func, n);
}
pub fn tonumber(L: State, index: i32) f64 {
const f: *const fn (State, i32) callconv(fc) f64 = @ptrFromInt(0x6F3620);
return f(L, index);
}
pub fn tostring(L: State, index: i32) ?[*:0]const u8 {
const f: *const fn (State, i32) callconv(fc) ?[*:0]const u8 = @ptrFromInt(0x6F3690);
return f(L, index);
}
pub fn toboolean(L: State, index: i32) i32 {
const f: *const fn (State, i32) callconv(fc) i32 = @ptrFromInt(0x6F3660);
return f(L, index);
}
pub fn newtable(L: State) void {
const f: *const fn (State) callconv(fc) void = @ptrFromInt(0x6F3C90);
f(L);
}
pub fn settable(L: State, index: i32) void {
const f: *const fn (State, i32) callconv(fc) void = @ptrFromInt(0x6F3E20);
f(L, index);
}
pub fn gettable(L: State, index: i32) void {
const f: *const fn (State, i32) callconv(fc) void = @ptrFromInt(0x6F3A40);
f(L, index);
}
pub fn next(L: State, index: i32) i32 {
const f: *const fn (State, i32) callconv(fc) i32 = @ptrFromInt(0x6F4450);
return f(L, index);
}
pub fn pcall(L: State, nargs: i32, nresults: i32, errfunc: i32) i32 {
const f: *const fn (State, i32, i32, i32) callconv(fc) i32 = @ptrFromInt(0x6F41A0);
return f(L, nargs, nresults, errfunc);
}
pub fn luaError(L: State, msg: [*:0]const u8) void {
asm volatile (
\\push %[msg]
\\push %[L]
\\call *%[func]
\\add $8, %%esp
:
: [L] "r" (@intFromPtr(L)),
[msg] "r" (@intFromPtr(msg)),
[func] "r" (@as(u32, 0x6F4940)),
: .{ .eax = true, .ecx = true, .edx = true, .memory = true, .cc = true }
);
}
pub const LuaReg = extern struct {
name: ?[*:0]const u8,
func: usize,
};
pub fn openlib(L: State, libname: ?[*:0]const u8, funcs: [*]const LuaReg, nup: i32) void {
const f: *const fn (State, ?[*:0]const u8, [*]const LuaReg, i32) callconv(fc) void = @ptrFromInt(0x6F4DC0);
f(L, libname, funcs, nup);
}
pub fn checknumber(L: State, index: i32) f64 {
const f: *const fn (State, i32) callconv(fc) f64 = @ptrFromInt(0x6F4C80);
return f(L, index);
}