diff options
author | Michael Smith <mikesmiffy128@gmail.com> | 2022-04-30 00:23:31 +0100 |
---|---|---|
committer | Michael Smith <mikesmiffy128@gmail.com> | 2022-04-30 00:34:47 +0100 |
commit | 1a5c55eb89c22e8822ec057a3731a6d753f13859 (patch) | |
tree | fa09dd757a1966649119f70717bd11d679c0f179 /src/autojump.c | |
parent | 1aaedffd8c68614936c59d4681e6dc111cb32691 (diff) |
Centralise engine access, add Portal FOV changer
- A bunch of stuff is now defined in one header, engineapi.h
- engineapi.c is responsible for setting up any interfaces/stuff that's
used in more than one place
- mkgamedata is pretty much rewritten and now supports nested
conditionals
- gamedata variables no longer have the gamedata_ prefix because it was
just annoyingly long all the time
- vcall macros are somewhat revamped and support dynamic (gamedata)
indices
- Portal 1 FOV can be set anywhere from 75-120 using fov_desired -
tested in both the main versions currently used by runners
- A few typos were also fixed ("intput," "writeable," "indexes")
Diffstat (limited to 'src/autojump.c')
-rw-r--r-- | src/autojump.c | 47 |
1 files changed, 14 insertions, 33 deletions
diff --git a/src/autojump.c b/src/autojump.c index a8d7ee2..9d4e513 100644 --- a/src/autojump.c +++ b/src/autojump.c @@ -17,7 +17,7 @@ #include <stdbool.h> #include "con_.h" -#include "factory.h" +#include "engineapi.h" #include "gamedata.h" #include "intdefs.h" #include "hook.h" @@ -28,34 +28,17 @@ DEF_CVAR(sst_autojump, "Jump upon hitting the ground while holding space", 0, CON_REPLICATE | CON_DEMO | CON_HIDDEN) -struct vec3f { float x, y, z; }; -struct CMoveData { - bool firstrun : 1, gamecodemoved : 1; - ulong playerhandle; - int impulse; - struct vec3f viewangles, absviewangles; - int buttons, oldbuttons; - float mv_forward, mv_side, mv_up; - float maxspeed, clmaxspeed; - struct vec3f vel, angles, oldangles; - float out_stepheight; - struct vec3f out_wishvel, out_jumpvel; - struct vec3f constraint_centre; - float constraint_radius, constraint_width, constraint_speedfactor; - struct vec3f origin; -}; - #define IN_JUMP 2 #define NIDX 256 // *completely* arbitrary lol static bool justjumped[NIDX] = {0}; static inline int handleidx(ulong h) { return h & (1 << 11) - 1; } static void *gmsv = 0, *gmcl = 0; -typedef bool (VCALLCONV *CheckJumpButton_f)(void *); -static CheckJumpButton_f origsv, origcl; +typedef bool (*VCALLCONV CheckJumpButton_func)(void *); +static CheckJumpButton_func origsv, origcl; static bool VCALLCONV hook(void *this) { - struct CMoveData **mvp = mem_offset(this, gamedata_off_mv), *mv = *mvp; + struct CMoveData **mvp = mem_offset(this, off_mv), *mv = *mvp; // use 0 idx for client side, as server indices start at 1 // FIXME: does this account for splitscreen??? int i = this == gmsv ? handleidx(mv->playerhandle) : 0; @@ -65,9 +48,9 @@ static bool VCALLCONV hook(void *this) { static bool unprot(void *gm) { void **vtable = *(void ***)gm; - bool ret = os_mprot(vtable + gamedata_vtidx_CheckJumpButton, - sizeof(void *), PAGE_EXECUTE_READWRITE); - if (!ret) con_warn("autojump: couldn't make memory writeable\n"); + bool ret = os_mprot(vtable + vtidx_CheckJumpButton, sizeof(void *), + PAGE_EXECUTE_READWRITE); + if (!ret) con_warn("autojump: couldn't make memory writable\n"); return ret; } @@ -77,7 +60,7 @@ bool autojump_init(void) { con_warn("autojump: missing required factories\n"); return false; } - if (!gamedata_has_vtidx_CheckJumpButton || !gamedata_has_off_mv) { + if (!has_vtidx_CheckJumpButton || !has_off_mv) { con_warn("autojump: missing gamedata entries for this engine\n"); return false; } @@ -94,20 +77,18 @@ bool autojump_init(void) { return false; } if (!unprot(gmcl)) return false; - origsv = (CheckJumpButton_f)hook_vtable(*(void ***)gmsv, - gamedata_vtidx_CheckJumpButton, (void *)&hook); - origcl = (CheckJumpButton_f)hook_vtable(*(void ***)gmcl, - gamedata_vtidx_CheckJumpButton, (void *)&hook); + origsv = (CheckJumpButton_func)hook_vtable(*(void ***)gmsv, + vtidx_CheckJumpButton, (void *)&hook); + origcl = (CheckJumpButton_func)hook_vtable(*(void ***)gmcl, + vtidx_CheckJumpButton, (void *)&hook); sst_autojump->base.flags &= ~CON_HIDDEN; return true; } void autojump_end(void) { - unhook_vtable(*(void ***)gmsv, gamedata_vtidx_CheckJumpButton, - (void *)origsv); - unhook_vtable(*(void ***)gmcl, gamedata_vtidx_CheckJumpButton, - (void *)origcl); + unhook_vtable(*(void ***)gmsv, vtidx_CheckJumpButton, (void *)origsv); + unhook_vtable(*(void ***)gmcl, vtidx_CheckJumpButton, (void *)origcl); } // vi: sw=4 ts=4 noet tw=80 cc=80 |