From af370088fc178996a46ee508aaa1a2c46318bbf2 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Fri, 26 Dec 2025 23:12:11 +0000 Subject: Move to static trampolines and type-safe hooks For some reason the DLL got a tiny little bit bigger again but that's fine. This will make orig_ calls more efficient in the inline case, and also make it harder to screw up and hook the wrong thing by mistake. Self-explanatory-ish, apart from the fact it's a fairly large API change of course. And it relies on some more bonkers assembler directive hackery. But it works! The only complaint one might have is that the featsetup functions no longer take an explicit string which occasionally yields slightly less perfect error messages, but I've decided this isn't really a problem and makes the API nicer to use. It's a tradeoff, innit. --- src/nosleep.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nosleep.c') diff --git a/src/nosleep.c b/src/nosleep.c index 3ac4069..a170781 100644 --- a/src/nosleep.c +++ b/src/nosleep.c @@ -36,8 +36,8 @@ DEF_CVAR_UNREG(engine_no_focus_sleep, static void **vtable; typedef void (*VCALLCONV SleepUntilInput_func)(void *this, int timeout); -static SleepUntilInput_func orig_SleepUntilInput; -static void VCALLCONV hook_SleepUntilInput(void *this, int timeout) { +DEF_VTABLE_HOOK(SleepUntilInput_func, SleepUntilInput) +static void VCALLCONV hookdest_SleepUntilInput(void *this, int timeout) { orig_SleepUntilInput(this, con_getvari(engine_no_focus_sleep)); } @@ -54,14 +54,14 @@ INIT { errmsg_errorx("couldn't make virtual table writable"); return FEAT_FAIL; } - orig_SleepUntilInput = (SleepUntilInput_func)hook_vtable(vtable, - vtidx_SleepUntilInput, (void *)&hook_SleepUntilInput); + hook_SleepUntilInput(vtable, vtidx_SleepUntilInput, + &hookdest_SleepUntilInput); con_unhide(&engine_no_focus_sleep->base); return FEAT_OK; } END { - unhook_vtable(vtable, vtidx_SleepUntilInput, (void *)orig_SleepUntilInput); + unhook_SleepUntilInput(vtable, vtidx_SleepUntilInput); } // vi: sw=4 ts=4 noet tw=80 cc=80 -- cgit v1.2.3-54-g00ecf