From 8a669bc96ffdb9d0f6f54e464da11e3375c80a55 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Thu, 17 Apr 2025 01:39:10 +0100 Subject: Add type-safety to virtual calls and accessors This probably should have been the design from the start. It's still possible to use void pointers, and this is done in a couple of places for simplicity, but wherever possible, we have actual structs for things now. Additionally, in places where vtables are fiddled with, e.g. vtable hooks, we have actual struct definitions with vtable pointers so there's need for pointer-casting horror. --- src/l4daddon.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/l4daddon.c') diff --git a/src/l4daddon.c b/src/l4daddon.c index 8e61e05..d05cc80 100644 --- a/src/l4daddon.c +++ b/src/l4daddon.c @@ -54,7 +54,7 @@ static char last_mission[128] = {0}, last_gamemode[128] = {0}; static int last_addonvecsz = 0; static bool last_disallowaddons = false; -DECL_VFUNC_DYN(void, ManageAddonsForActiveSession) +DECL_VFUNC_DYN(struct VEngineClient, void, ManageAddonsForActiveSession) // Crazy full name: FileSystem_ManageAddonsForActiveSession. Hence the acronym. // Note: the 4th parameter was first added in 2.2.0.4 (21 Oct 2020), but we @@ -141,8 +141,7 @@ e: orig_FS_MAFAS(disallowaddons, mission, gamemode, ismutation); static inline bool find_FS_MAFAS() { #ifdef _WIN32 - const uchar *insns = (const uchar *)VFUNC(engclient, - ManageAddonsForActiveSession); + const uchar *insns = engclient->vtable[vtidx_ManageAddonsForActiveSession]; // CEngineClient::ManageAddonsForActiveSession just calls FS_MAFAS for (const uchar *p = insns; p - insns < 32;) { if (p[0] == X86_CALL) { -- cgit v1.2.3-54-g00ecf