diff options
author | Michael Smith <mikesmiffy128@gmail.com> | 2022-05-16 21:07:41 +0100 |
---|---|---|
committer | Michael Smith <mikesmiffy128@gmail.com> | 2022-05-16 22:15:46 +0100 |
commit | 278b61bc3f2018515e26fd6b45410aded8b6417e (patch) | |
tree | 39a860b66c3d88e91359f48dbf937c0c71d61833 | |
parent | e8843dba3eb1c7a67f6ff7b920046ae36a12acd0 (diff) |
Clean up some random bits and bobs
-rw-r--r-- | src/build/mkentprops.c | 14 | ||||
-rw-r--r-- | src/con_.c | 6 | ||||
-rw-r--r-- | src/con_.h | 6 | ||||
-rw-r--r-- | src/demorec.c | 20 | ||||
-rw-r--r-- | src/engineapi.c | 1 | ||||
-rw-r--r-- | src/hook.c | 6 | ||||
-rw-r--r-- | src/mem.h | 5 |
7 files changed, 25 insertions, 33 deletions
diff --git a/src/build/mkentprops.c b/src/build/mkentprops.c index e99873b..321b954 100644 --- a/src/build/mkentprops.c +++ b/src/build/mkentprops.c @@ -148,23 +148,23 @@ F( " for (int needclasses = %d; class; class = class->next) {", nclasses) // ever have more than a few classes/properties? F( " %sif (!strcmp(class->name, \"%s\")) {", else1, c->name) _( " struct SendTable *st = class->table;") - // XXX: christ this is all awful :( F( " int needprops = %d;", c->props.sz) -_( " for (struct SendProp *p = st->props; (char *)p -") -_( " (char *)st->props < st->nprops * sz_SendProp;") +_( " for (struct SendProp *p = st->props;") +_( " mem_diff(p, st->props) < st->nprops * sz_SendProp;") _( " p = mem_offset(p, sz_SendProp)) {") +_( " const char *varname = mem_loadptr(mem_offset(p, off_SP_varname));") char *else2 = ""; for (struct prop **pp = c->props.data; pp - c->props.data < c->props.sz; ++pp) { -F( " %sif (!strcmp(*(const char **)mem_offset(p, off_SP_varname), \"%s\")) {", - else2, (*pp)->propname) // ugh +F( " %sif (!strcmp(varname, \"%s\")) {", else2, (*pp)->propname) F( " has_%s = true;", (*pp)->varname) // from AM L4D2 SDK headers: // > SENDPROP_VECTORELEM makes [offset] negative to start with so we // > can detect that and set the SPROP_IS_VECTOR_ELEM flag. // apparently if we're loaded via VDF, it hasn't been flipped back - // yet. just calling abs() on it as an easy solution. -F( " %s = abs(*(int *)mem_offset(p, off_SP_offset));", (*pp)->varname) + // yet. just calling abs() on everything as an easy solution. +F( " %s = abs(*(int *)mem_offset(p, off_SP_offset));", + (*pp)->varname) _( " if (!--needprops) break;") _( " }") else2 = "else "; @@ -497,13 +497,11 @@ SETTER(int, 2, con_setvari) #undef SETTER con_cmdcb con_getcmdcb(const struct con_cmd *cmd) { - if (cmd->use_newcmdiface || !cmd->use_newcb) return 0; - return cmd->cb; + return !cmd->use_newcmdiface && cmd->use_newcb ? cmd->cb : 0; } con_cmdcbv1 con_getcmdcbv1(const struct con_cmd *cmd) { - if (cmd->use_newcmdiface || cmd->use_newcb) return 0; - return cmd->cb_v1; + return !cmd->use_newcmdiface && !cmd->use_newcb ? cmd->cb_v1 : 0; } // vi: sw=4 ts=4 noet tw=80 cc=80 @@ -141,12 +141,12 @@ struct con_var { // ConVar in engine float fval; int ival; bool hasmin; - // bool hasmax; // better packing here, might break engine ABI + // bool hasmax; // better packing here, would break engine ABI float minval; - bool hasmax; // just sticking to sdk position for now + bool hasmax; // just sticking to sdk position float maxval; /* - * Our quickly-chucked in optional callback - doesn't match the engine!! + * Our quickly-chucked-in optional callback - doesn't match the engine!! * Also has to be manually set in code, although that's probably fine anyway * as it's common to only want a cvar to do something if the feature * succesfully init-ed. diff --git a/src/demorec.c b/src/demorec.c index c8871bd..5c79384 100644 --- a/src/demorec.c +++ b/src/demorec.c @@ -351,6 +351,8 @@ static bool find_WriteMessages(void) { return false; } +DECL_VFUNC_DYN(int, GetEngineBuildNumber) + bool demorec_custom_init(void) { if (!has_vtidx_GetEngineBuildNumber || !has_vtidx_RecordPacket) { con_warn("demorec: custom: missing gamedata entries for this engine\n"); @@ -363,22 +365,8 @@ bool demorec_custom_init(void) { // > otherwise it's 12 bits // > there might be some other l4d2 versions where it's 11 but idk // So here we have to figure out the network protocol version! - void *clientiface; - uint buildnum; - // TODO(compat): probably expose VEngineClient/VEngineServer some other way - // if it's useful elsewhere later!? - if (clientiface = factory_engine("VEngineClient013", 0)) { - typedef uint (*VCALLCONV GetEngineBuildNumber_func)(void *this); - buildnum = (*(GetEngineBuildNumber_func **)clientiface)[ - vtidx_GetEngineBuildNumber](clientiface); - } - // add support for other interfaces here: - // else if (clientiface = factory_engine("VEngineClient0XX", 0)) { - // ... - // } - else { - return false; - } + // NOTE: assuming engclient != null as GEBN index relies on client version + int buildnum = VCALL(engclient, GetEngineBuildNumber); // condition is redundant until other GetEngineBuildNumber offsets are added // if (GAMETYPE_MATCHES(L4D2)) { nbits_msgtype = 6; diff --git a/src/engineapi.c b/src/engineapi.c index ec3d857..15c780a 100644 --- a/src/engineapi.c +++ b/src/engineapi.c @@ -102,7 +102,6 @@ bool engineapi_init(int pluginver) { gamedata_init(); con_init(); if (!gameinfo_init()) { con_disconnect(); return false; } - if (has_vtidx_GetAllServerClasses && has_sz_SendProp && has_off_SP_varname && has_off_SP_offset) { initentprops(VCALL(srvdll, GetAllServerClasses)); @@ -85,7 +85,9 @@ nosp: con_warn("hook_inline: out of trampoline space\n"); // pad with original bytes so we can do an 8-byte atomic write memcpy(jmp + 5, func + 5, 3); *(volatile uvlong *)func = *(uvlong *)jmp; // (assuming function is aligned) - FlushInstructionCache(GetCurrentProcess(), func, len); + // -1 is the current process, and it's a constant in the WDK, so it's + // assumed we can safely avoid the useless GetCurrentProcess call + FlushInstructionCache((void *)-1, func, len); return trampoline; } @@ -95,7 +97,7 @@ void unhook_inline(void *orig) { int off = mem_load32(p + len + 1); uchar *q = p + off + 5; memcpy(q, p, 5); // XXX: not atomic atm! (does any of it even need to be?) - FlushInstructionCache(GetCurrentProcess(), q, 5); + FlushInstructionCache((void *)-1, q, 5); } #else @@ -68,6 +68,11 @@ static inline void mem_storeptr(void *to, const void *val) { * to any pointer type */ static inline void *mem_offset(void *p, int off) { return (char *)p + off; } +/* returns the offset in bytes from one pointer to another (p - q) */ +static inline ssize mem_diff(const void *p, const void *q) { + return (char *)p - (char *)q; +} + #endif // vi: sw=4 ts=4 noet tw=80 cc=80 |