From 4fddfa831d2a33ab3eee7ceb5f181c82d5aa78d2 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Wed, 16 Apr 2025 02:13:01 +0100 Subject: Rework API for inline hooking This both simplifies and complicates things, but probably hopefully maybe simplifies things overall. Certainly in cases like the L4D1 demo thing where there's 3 inline hooks at once, it seems simpler to be able to batch the fallible stuff to avoid rollbacks. In cases where you only need one hook, it's a bit more verbose, but what can you do. Thanks bill for discussing this with me pretty exhaustively and giving a lot of good input. I think both of us still kind of hate it actually. --- src/portalcolours.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/portalcolours.c') diff --git a/src/portalcolours.c b/src/portalcolours.c index 7779cb3..24224c1 100644 --- a/src/portalcolours.c +++ b/src/portalcolours.c @@ -87,6 +87,9 @@ static bool find_UTIL_Portal_Color(void *base) { orig_UTIL_Portal_Color = (UTIL_Portal_Color_func)mem_offset(base, 0x1AA810); if (!memcmp((void *)orig_UTIL_Portal_Color, x, sizeof(x))) return true; // SteamPipe (7197370) - almost sure to break in a later update! + // TODO(compat): this has indeed been broken for ages. + // TODO(compat): we also still don't have 4104. really need to do this + // properly some time soon, it seems. static const uchar y[] = HEXBYTES(55, 8B, EC, 8B, 45, 0C, 83, E8, 00, 74, 24, 48, 74, 16, 48, 8B, 45, 08, 74, 08, C7, 00, FF, FF); orig_UTIL_Portal_Color = (UTIL_Portal_Color_func)mem_offset(base, 0x234C00); @@ -100,12 +103,11 @@ INIT { errmsg_errorx("couldn't find UTIL_Portal_Color"); return FEAT_INCOMPAT; } - orig_UTIL_Portal_Color = (UTIL_Portal_Color_func)hook_inline( - (void *)orig_UTIL_Portal_Color, (void *)&hook_UTIL_Portal_Color); - if_cold (!orig_UTIL_Portal_Color) { - errmsg_errorsys("couldn't hook UTIL_Portal_Color"); - return FEAT_INCOMPAT; - } + struct hook_inline_featsetup_ret h = hook_inline_featsetup( + (void *)orig_UTIL_Portal_Color, (void **)&orig_UTIL_Portal_Color, + "UTIL_Portal_Color"); + if_cold (h.err) return h.err; + hook_inline_commit(h.prologue, (void *)&hook_UTIL_Portal_Color); sst_portal_colour0->cb = &colourcb; sst_portal_colour1->cb = &colourcb; sst_portal_colour2->cb = &colourcb; -- cgit v1.2.3-54-g00ecf