summaryrefslogtreecommitdiffhomepage
path: root/src/demorec.c
diff options
context:
space:
mode:
authorMichael Smith <mikesmiffy128@gmail.com>2023-05-16 22:12:57 +0100
committerMichael Smith <mikesmiffy128@gmail.com>2023-05-16 23:00:24 +0100
commitcba9387c361c3d33dcf1b21ff0e5beb4b0a81ade (patch)
treec3b590a682447959a41c0d90f690e59b23365a3d /src/demorec.c
parent182b36609acc44d3338f64ca3975e1604b50f619 (diff)
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
Diffstat (limited to 'src/demorec.c')
-rw-r--r--src/demorec.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/demorec.c b/src/demorec.c
index bbcc317..ee57c12 100644
--- a/src/demorec.c
+++ b/src/demorec.c
@@ -168,9 +168,10 @@ static void hook_stop_cb(const struct con_cmdargs *args) {
// instance).
static inline bool find_demorecorder(void) {
#ifdef _WIN32
+ const uchar *insns = (const uchar *)orig_stop_cb;
// The "stop" command calls the virtual function demorecorder.IsRecording(),
// so just look for the load of the "this" pointer into ECX
- for (uchar *p = (uchar *)orig_stop_cb; p - (uchar *)orig_stop_cb < 32;) {
+ for (const uchar *p = insns; p - insns < 32;) {
if (p[0] == X86_MOVRMW && p[1] == X86_MODRM(0, 1, 5)) {
void **indirect = mem_loadptr(p + 2);
demorecorder = *indirect;
@@ -188,7 +189,8 @@ static inline bool find_demorecorder(void) {
// original "StopRecording" demorecorder function.
static inline bool find_recmembers(void *stoprecording) {
#ifdef _WIN32
- for (uchar *p = (uchar *)stoprecording; p - (uchar *)stoprecording < 128;) {
+ const uchar *insns = (uchar *)stoprecording;
+ for (const uchar *p = insns; p - insns < 128;) {
// m_nDemoNumber = 0 -> mov dword ptr [<reg> + off], 0
// XXX: might end up wanting constants for the MRM field masks?
if (p[0] == X86_MOVMIW && (p[1] & 0xC0) == 0x80 &&
@@ -212,7 +214,8 @@ static inline bool find_recmembers(void *stoprecording) {
// "StartRecording" demorecorder function.
static inline bool find_demoname(void *startrecording) {
#ifdef _WIN32
- for (uchar *p = (uchar *)startrecording; p - (uchar *)startrecording < 32;) {
+ const uchar *insns = (uchar *)startrecording;
+ for (const uchar *p = insns; p - insns < 32;) {
// the function immediately calls Q_strncpy and copies into a buffer
// offset from `this` - look for a LEA instruction some time *before*
// the first call takes place