aboutsummaryrefslogtreecommitdiff
path: root/src/autojump.c
diff options
context:
space:
mode:
authorGravatar Michael Smith <mikesmiffy128@gmail.com> 2024-09-25 18:25:08 +0100
committerGravatar Michael Smith <mikesmiffy128@gmail.com> 2024-09-28 18:28:13 +0100
commitbc9198ba9b654117118a06399d4dbf273262501d (patch)
tree73572d7807797ff22333aeefffae19a708bdd9af /src/autojump.c
parenta62d7366a6061c1873b87ead944e2521f589b0c7 (diff)
downloadsst-bc9198ba9b654117118a06399d4dbf273262501d.tar.gz
sst-bc9198ba9b654117118a06399d4dbf273262501d.zip
Create and use macros to define accessor functions
Avoids the need to manually mess around with mem_offset() and gamedata off_ and sz_ values as often, because that's kind of annoying. Should also make the codebase a little less confusing for new players.
Diffstat (limited to 'src/autojump.c')
-rw-r--r--src/autojump.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/autojump.c b/src/autojump.c
index 64ed436..bc6739f 100644
--- a/src/autojump.c
+++ b/src/autojump.c
@@ -14,6 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
+#include "accessor.h"
#include "con_.h"
#include "engineapi.h"
#include "errmsg.h"
@@ -32,6 +33,8 @@ REQUIRE_GAMEDATA(off_mv)
REQUIRE_GAMEDATA(vtidx_CheckJumpButton)
REQUIRE_GLOBAL(factory_client) // note: server will never be null
+DEF_ACCESSORS(struct CMoveData *, mv)
+
DEF_CVAR(sst_autojump, "Jump upon hitting the ground while holding space", 0,
CON_REPLICATE | CON_DEMO | CON_HIDDEN)
@@ -44,7 +47,7 @@ typedef bool (*VCALLCONV CheckJumpButton_func)(void *);
static CheckJumpButton_func origsv, origcl;
static bool VCALLCONV hooksv(void *this) {
- struct CMoveData *mv = mem_loadptr(mem_offset(this, off_mv));
+ struct CMoveData *mv = get_mv(this);
int idx = handleidx(mv->playerhandle);
if (con_getvari(sst_autojump) && mv->firstrun && !justjumped[idx]) {
mv->oldbuttons &= ~IN_JUMP;
@@ -55,7 +58,7 @@ static bool VCALLCONV hooksv(void *this) {
}
static bool VCALLCONV hookcl(void *this) {
- struct CMoveData *mv = mem_loadptr(mem_offset(this, off_mv));
+ struct CMoveData *mv = get_mv(this);
// FIXME: this will stutter in the rare case where justjumped is true.
// currently doing clientside justjumped handling makes multiplayer
// prediction in general wrong, so this'll need more work to do totally
@@ -66,7 +69,7 @@ static bool VCALLCONV hookcl(void *this) {
}
static bool unprot(void *gm) {
- void **vtable = *(void ***)gm;
+ void **vtable = mem_loadptr(gm);
bool ret = os_mprot(vtable + vtidx_CheckJumpButton, sizeof(void *),
PAGE_READWRITE);
if (!ret) errmsg_errorsys("couldn't make virtual table writable");