aboutsummaryrefslogtreecommitdiff
path: root/src/portalcolours.c
diff options
context:
space:
mode:
authorGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-04-16 02:13:01 +0100
committerGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-04-16 21:31:20 +0100
commit4fddfa831d2a33ab3eee7ceb5f181c82d5aa78d2 (patch)
treef62a0fc1a0b3d7ffcd7967b98885453636309686 /src/portalcolours.c
parent5c805aac744df43dd96f70bc7e39337d9c3a966a (diff)
downloadsst-4fddfa831d2a33ab3eee7ceb5f181c82d5aa78d2.tar.gz
sst-4fddfa831d2a33ab3eee7ceb5f181c82d5aa78d2.zip
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.
Diffstat (limited to 'src/portalcolours.c')
-rw-r--r--src/portalcolours.c14
1 files changed, 8 insertions, 6 deletions
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;