summaryrefslogtreecommitdiff
path: root/src/hud.c
diff options
context:
space:
mode:
authorGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-12-26 23:12:11 +0000
committerGravatar Michael Smith <mikesmiffy128@gmail.com> 2026-02-16 19:11:24 +0000
commitaf370088fc178996a46ee508aaa1a2c46318bbf2 (patch)
treecf1f6c01ad7c101d3fd4abb44835d9deb600e30d /src/hud.c
parent40f9d989df2c1ff2f567656ccbdbfc0d97e34a77 (diff)
downloadsst-af370088fc178996a46ee508aaa1a2c46318bbf2.tar.gz
sst-af370088fc178996a46ee508aaa1a2c46318bbf2.zip
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.
Diffstat (limited to 'src/hud.c')
-rw-r--r--src/hud.c9
1 files changed, 4 insertions, 5 deletions
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);
}
}