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/hud.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/hud.c') diff --git a/src/hud.c b/src/hud.c index ef86c4d..87f40fc 100644 --- a/src/hud.c +++ b/src/hud.c @@ -96,8 +96,8 @@ static struct IPanel *toolspanel; static struct IScheme *scheme; typedef void (*VCALLCONV Paint_func)(struct IPanel *); -static Paint_func orig_Paint; -void VCALLCONV hook_Paint(struct IPanel *this) { +DEF_VTABLE_HOOK(Paint_func, Paint) +void VCALLCONV hookdest_Paint(struct IPanel *this) { if (this == toolspanel) { int width, height; hud_screensize(&width, &height); @@ -188,8 +188,7 @@ INIT { errmsg_errorsys("couldn't make virtual table writable"); return FEAT_FAIL; } - orig_Paint = (Paint_func)hook_vtable(toolspanel->vtable, vtidx_Paint, - (void *)&hook_Paint); + hook_Paint(toolspanel->vtable, vtidx_Paint, &hookdest_Paint); SetPaintEnabled(toolspanel, true); // 1 is the default, first loaded scheme. should always be sourcescheme.res scheme = GetIScheme(schememgr, (struct handlewrap){1}); @@ -199,7 +198,7 @@ INIT { END { // don't unhook toolspanel if exiting: it's already long gone! if_cold (sst_userunloaded) { - unhook_vtable(toolspanel->vtable, vtidx_Paint, (void *)orig_Paint); + unhook_Paint(toolspanel->vtable, vtidx_Paint); SetPaintEnabled(toolspanel, false); } } -- cgit v1.2.3-54-g00ecf