From cba9387c361c3d33dcf1b21ff0e5beb4b0a81ade Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Tue, 16 May 2023 22:12:57 +0100 Subject: Do some pedantic spring cleaning - Use const in more places where it makes sense - not absolutely everywhere because it can get a bit annoying - Make all the instruction search loops a bit more readable by casting the function pointer into a temporary variable to loop over - Add a few more doc comments and fix a typo or two - Make that RTTI thing flexibly-sized, finally - Don't include gamedata.h in vcall.h for no reason; consequently include gamedata.h in a bunch of places where it was implictly pulled in before - Fix dbg_toghidra() and ent_getedict() having mismatched return types between their headers and respective source files - Remove that one broken, hacky, secret Portal non-feature that probably nobody even ended up using; it can be implemented properly later if required --- src/ac.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/ac.c') diff --git a/src/ac.c b/src/ac.c index 01b969f..c379326 100644 --- a/src/ac.c +++ b/src/ac.c @@ -27,6 +27,7 @@ #include "errmsg.h" #include "event.h" #include "feature.h" +#include "gamedata.h" #include "intdefs.h" #include "mem.h" #include "os.h" @@ -242,10 +243,8 @@ static bool find_DispatchInputEvent(void) { return false; } void *cgame; - GetDesktopResolution_func GetDesktopResolution = - VFUNC(gameuifuncs, GetDesktopResolution); - for (uchar *p = (uchar *)GetDesktopResolution; - p - (uchar *)GetDesktopResolution < 16;) { + const uchar *insns = (const uchar*)VFUNC(gameuifuncs, GetDesktopResolution); + for (const uchar *p = insns; p - insns < 16;) { if (p[0] == X86_MOVRMW && p[1] == X86_MODRM(0, 1, 5)) { void **indirect = mem_loadptr(p + 2); cgame = *indirect; @@ -255,10 +254,8 @@ static bool find_DispatchInputEvent(void) { } errmsg_errorx("couldn't find pointer to CGame instance"); return false; -ok: DispatchAllStoredGameMessages_func DispatchAllStoredGameMessages = - VFUNC(cgame, DispatchAllStoredGameMessages); - for (uchar *p = (uchar *)DispatchAllStoredGameMessages; - p - (uchar *)DispatchAllStoredGameMessages < 128;) { +ok: insns = (const uchar *)VFUNC(cgame, DispatchAllStoredGameMessages); + for (const uchar *p = insns; p - insns < 128;) { if (p[0] == X86_CALL) { orig_DispatchInputEvent = (DispatchInputEvent_func)(p + 5 + mem_loadoffset(p + 1)); -- cgit v1.2.3