Files
WeirdUtils/src/console.zig
T
MarcelineVQ 2aaa089c76 Add module control API, bigcursor with fractional scaling, shared mutex
Module control API:
- Three cdecl exports: WeirdUtils_IsModuleActive, WeirdUtils_DisableModule, WeirdUtils_DisableAll
- C header include/weirdutils_api.h for runtime DLL discovery
- All modules gain pub module_name, isActive(), shared mutex via src/mutex.zig
- build.zig refactored to module_list array of ModuleDesc

Bigcursor:
- D3D9 vtable hooks on SetCursorProperties/ShowCursor
- Scale2x/Scale3x pixel-art upscalers in pure Zig (replaces 12K-line hqx C)
- Bilinear resampler for fractional scales (1.0-4.0, default 1.2)
- Win32 cursor via CreateIconIndirect bypasses D3D9 32x32 limit
- FNV-1a hash cache for ~16 cursor bitmaps
- Lua API: SetCursorScale(n) / GetCursorScale()
- CVar cursorScale for Config.wtf persistence (tenths)

Other:
- Add dpslog module stub
- Docs and README updates
2026-03-06 13:27:35 -08:00

66 lines
1.8 KiB
Zig

//! Debug console - compiles out entirely in non-Debug builds.
//!
//! Usage from any module:
//! const con = @import("../console.zig"); // or appropriate relative path
//! con.print("[markers] loaded\n");
//! con.fmt("[markers] pos = {d}, {d}, {d}\n", .{ x, y, z });
const std = @import("std");
const builtin = @import("builtin");
const debug = builtin.mode == .Debug;
const WINAPI = std.builtin.CallingConvention.winapi;
const win = if (debug) struct {
extern "kernel32" fn AllocConsole() callconv(WINAPI) i32;
extern "kernel32" fn FreeConsole() callconv(WINAPI) i32;
extern "kernel32" fn SetConsoleTitleA(title: [*:0]const u8) callconv(WINAPI) i32;
extern "kernel32" fn GetStdHandle(nStdHandle: u32) callconv(WINAPI) ?*anyopaque;
extern "kernel32" fn WriteConsoleA(
hOut: *anyopaque,
buf: [*]const u8,
len: u32,
written: ?*u32,
reserved: ?*anyopaque,
) callconv(WINAPI) i32;
const STD_OUTPUT_HANDLE: u32 = 0xFFFFFFF5;
var handle: ?*anyopaque = null;
} else void;
pub fn init() void {
if (debug) {
_ = win.AllocConsole();
_ = win.SetConsoleTitleA("weirdutils");
win.handle = win.GetStdHandle(win.STD_OUTPUT_HANDLE);
print("[weirdutils] Console attached\n");
}
}
pub fn deinit() void {
if (debug) {
if (win.handle != null) {
print("[weirdutils] Detaching\n");
_ = win.FreeConsole();
win.handle = null;
}
}
}
pub fn print(msg: []const u8) void {
if (debug) {
if (win.handle) |h| {
_ = win.WriteConsoleA(h, msg.ptr, @intCast(msg.len), null, null);
}
}
}
pub fn fmt(comptime f: []const u8, args: anytype) void {
if (debug) {
var buf: [512]u8 = undefined;
const msg = std.fmt.bufPrint(&buf, f, args) catch return;
print(msg);
}
}