Fix Outline Lua API calls on safe core V5
This commit is contained in:
+11
-18
@@ -4,7 +4,7 @@
|
|||||||
//! and a Lua C callback for `/wu outline` commands.
|
//! and a Lua C callback for `/wu outline` commands.
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const hook = @import("zhook");
|
const lua = @import("../lua.zig");
|
||||||
const logging = @import("../logging.zig");
|
const logging = @import("../logging.zig");
|
||||||
const tracker = @import("tracker.zig");
|
const tracker = @import("tracker.zig");
|
||||||
const model_hook = @import("model_hook.zig");
|
const model_hook = @import("model_hook.zig");
|
||||||
@@ -74,28 +74,21 @@ pub fn isEnabled() bool {
|
|||||||
/// OutlineCommand() → returns (enabled: bool)
|
/// OutlineCommand() → returns (enabled: bool)
|
||||||
/// OutlineCommand("on") → enable outlines
|
/// OutlineCommand("on") → enable outlines
|
||||||
/// OutlineCommand("off") → disable outlines
|
/// OutlineCommand("off") → disable outlines
|
||||||
pub fn outlineCommand(L: *anyopaque) callconv(.c) u32 {
|
pub fn outlineCommand(L: lua.State) callconv(.c) u32 {
|
||||||
const nargs = hook.call(fn (usize) callconv(hook.cc.fastcall) i32, 0x6F3070, .{@intFromPtr(L)}); // lua_gettop
|
const nargs = lua.gettop(L);
|
||||||
|
|
||||||
if (nargs >= 1) {
|
if (nargs >= 1 and lua.isstring(L, 1)) {
|
||||||
// Check if first arg is a string
|
if (lua.tostring(L, 1)) |s| {
|
||||||
const is_str = hook.call(fn (usize, u32) callconv(hook.cc.fastcall) u32, 0x6F3510, .{ @intFromPtr(L), 1 }); // lua_isstring
|
const span = std.mem.span(s);
|
||||||
if (is_str != 0) {
|
if (eql(span, "on") or eql(span, "enable")) {
|
||||||
const str_ptr = hook.call(fn (usize, u32) callconv(hook.cc.fastcall) u32, 0x6F3690, .{ @intFromPtr(L), 1 }); // lua_tostring
|
setEnabled(true);
|
||||||
if (str_ptr != 0) {
|
} else if (eql(span, "off") or eql(span, "disable")) {
|
||||||
const s: [*:0]const u8 = @ptrFromInt(str_ptr);
|
setEnabled(false);
|
||||||
const span = @import("std").mem.span(s);
|
|
||||||
if (eql(span, "on") or eql(span, "enable")) {
|
|
||||||
setEnabled(true);
|
|
||||||
} else if (eql(span, "off") or eql(span, "disable")) {
|
|
||||||
setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push current state as boolean
|
lua.pushboolean(L, if (isEnabled()) 1 else 0);
|
||||||
hook.call(fn (usize, u32) callconv(hook.cc.fastcall) void, 0x6F39F0, .{ @intFromPtr(L), @as(u32, if (isEnabled()) 1 else 0) }); // lua_pushboolean
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user