aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-08-02 14:43:19 +0100
committerGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-08-02 14:43:19 +0100
commit0d905d7998a031c2d7a1cdc5d0d1148b55b610a2 (patch)
treeea73c7cadd583a8c95b4a7ba6edaa10e99067098 /src
parentf2f9f18a893527ee80260a2d57bca3023f8fd44f (diff)
downloadsst-0d905d7998a031c2d7a1cdc5d0d1148b55b610a2.tar.gz
sst-0d905d7998a031c2d7a1cdc5d0d1148b55b610a2.zip
Make additional use of untyped command callbacks
Diffstat (limited to 'src')
-rw-r--r--src/chatrate.c12
-rw-r--r--src/dbg.c4
-rw-r--r--src/ent.c5
-rw-r--r--src/gameserver.c5
-rw-r--r--src/l4d1democompat.c5
-rw-r--r--src/l4daddon.c5
-rw-r--r--src/l4dwarp.c6
-rw-r--r--src/portalisg.c3
8 files changed, 18 insertions, 27 deletions
diff --git a/src/chatrate.c b/src/chatrate.c
index ba14ea1..9c1f40c 100644
--- a/src/chatrate.c
+++ b/src/chatrate.c
@@ -32,18 +32,16 @@ static uchar *patchedbyte;
// So, instead of adding 0.66 to the current time, we subtract it, and that
// means we can always chat immediately.
-static inline bool find_ratelimit_insn(con_cmdcb say_cb) {
- // Find the add instruction
- uchar *insns = (uchar *)say_cb;
- for (uchar *p = insns; p - insns < 128;) {
+static inline bool find_ratelimit_insn(const uchar *insns) {
+ for (const uchar *p = insns; p - insns < 128;) {
// find FADD
if (p[0] == X86_FLTBLK5 && p[1] == X86_MODRM(0, 0, 5)) {
- patchedbyte = p + 1;
+ patchedbyte = (uchar *)p + 1;
return true;
}
// Portal 2, L4D2 2125-2134, L4D:S all use SSE2, so try finding ADDSD
if (p[0] == X86_PFX_REPN && p[1] == X86_2BYTE & p[2] == X86_2B_ADD) {
- patchedbyte = p + 2;
+ patchedbyte = (uchar *)p + 2;
return true;
}
NEXT_INSN(p, "chat rate limit");
@@ -72,7 +70,7 @@ static inline void unpatch_ratelimit_insn() {
INIT {
struct con_cmd *cmd_say = con_findcmd("say");
if_cold (!cmd_say) return FEAT_INCOMPAT; // should never happen!
- if (!find_ratelimit_insn(cmd_say->cb)) {
+ if (!find_ratelimit_insn(cmd_say->cb_insns)) {
errmsg_errorx("couldn't find chat rate limit instruction");
return FEAT_INCOMPAT;
}
diff --git a/src/dbg.c b/src/dbg.c
index af995ce..aa21edf 100644
--- a/src/dbg.c
+++ b/src/dbg.c
@@ -93,9 +93,9 @@ DEF_CCMD_HERE(sst_dbg_getcmdcb, "Get the address of a command callback", 0) {
}
#ifdef _WIN32
con_msg("addr: %p\nghidra: %p\n", (void *)thecmd->cb_insns,
- (void *)dbg_toghidra((void *)thecmd->cb_insns)); // ugh
+ (void *)dbg_toghidra(thecmd->cb_insns)); // ugh
#else
- con_msg("addr: %p\n", (void *)thecmd->cb);
+ con_msg("addr: %p\n", (void *)thecmd->cb_insns);
#endif
}
diff --git a/src/ent.c b/src/ent.c
index 14e0788..e4ae4c8 100644
--- a/src/ent.c
+++ b/src/ent.c
@@ -71,8 +71,7 @@ struct CEntityFactoryDictionary {
#ifdef _WIN32 // TODO(linux): this'll be different too, leaving out for now
static struct CEntityFactoryDictionary *entfactorydict = 0;
-static inline bool find_entfactorydict(con_cmdcb dumpentityfactories_cb) {
- const uchar *insns = (const uchar *)dumpentityfactories_cb;
+static inline bool find_entfactorydict(const uchar *insns) {
for (const uchar *p = insns; p - insns < 64;) {
// EntityFactoryDictionary() is inlined, and returns a static, which is
// lazy-inited (trivia: this was old MSVC, so it's not thread-safe like
@@ -172,7 +171,7 @@ INIT {
#ifdef _WIN32 // TODO(linux): above
struct con_cmd *dumpentityfactories = con_findcmd("dumpentityfactories");
if_cold (!dumpentityfactories ||
- !find_entfactorydict(dumpentityfactories->cb)) {
+ !find_entfactorydict(dumpentityfactories->cb_insns)) {
errmsg_warnx("server entity factories unavailable");
}
#endif
diff --git a/src/gameserver.c b/src/gameserver.c
index 6f3d394..5cd8b0c 100644
--- a/src/gameserver.c
+++ b/src/gameserver.c
@@ -35,13 +35,12 @@ static struct CGameServer *sv;
int gameserver_spawncount() { return GetSpawnCount(sv); }
-static bool find_sv(con_cmdcb pause_cb) {
+static bool find_sv(const uchar *insns) {
#ifdef _WIN32
// The last thing pause does is call BroadcastPrintf with 4 args including
// `this`, all on the stack since it's varargs. 2 of the args are pushed
// immediately before `this`, so we can just look for 3 back-to-back pushes
// and a call.
- const uchar *insns = (const uchar *)pause_cb;
int pushes = 0;
for (const uchar *p = insns; p - insns < 256;) {
if (*p == X86_PUSHIW || *p >= X86_PUSHEAX && *p <= X86_PUSHEDI) {
@@ -68,7 +67,7 @@ static bool find_sv(con_cmdcb pause_cb) {
INIT {
struct con_cmd *pause = con_findcmd("pause");
- if_cold (!find_sv(pause->cb)) {
+ if_cold (!find_sv(pause->cb_insns)) {
errmsg_errorx("couldn't find game server object");
return FEAT_INCOMPAT;
}
diff --git a/src/l4d1democompat.c b/src/l4d1democompat.c
index 1cfe959..105b812 100644
--- a/src/l4d1democompat.c
+++ b/src/l4d1democompat.c
@@ -50,9 +50,8 @@ static GetHostVersion_func orig_GetHostVersion;
typedef void (*VCALLCONV ReadDemoHeader_func)(void *);
static ReadDemoHeader_func orig_ReadDemoHeader;
-static inline bool find_ReadDemoHeader(con_cmdcb listdemo_cb) {
+static inline bool find_ReadDemoHeader(const uchar *insns) {
// Find the call to ReadDemoHeader in the listdemo callback
- const uchar *insns = (const uchar *)listdemo_cb;
for (const uchar *p = insns; p - insns < 192;) {
if (p[0] == X86_LEA && p[1] == X86_MODRM(2, 1, 4) && p[2] == 0x24 &&
p[7] == X86_CALL && p[12] == X86_LEA &&
@@ -138,7 +137,7 @@ static int hook_midpoint() {
INIT {
struct con_cmd *cmd_listdemo = con_findcmd("listdemo");
if_cold (!cmd_listdemo) return FEAT_INCOMPAT; // should never happen!
- if_cold (!find_ReadDemoHeader(cmd_listdemo->cb)) {
+ if_cold (!find_ReadDemoHeader(cmd_listdemo->cb_insns)) {
errmsg_errorx("couldn't find ReadDemoHeader function");
return FEAT_INCOMPAT;
}
diff --git a/src/l4daddon.c b/src/l4daddon.c
index fd344ce..0f5fbe7 100644
--- a/src/l4daddon.c
+++ b/src/l4daddon.c
@@ -156,9 +156,8 @@ static inline bool find_FS_MAFAS() {
return false;
}
-static inline bool find_addonvecsz(con_cmdcb show_addon_metadata_cb) {
+static inline bool find_addonvecsz(const uchar *insns) {
#ifdef _WIN32
- const uchar *insns = (const uchar*)show_addon_metadata_cb;
// show_addon_metadata immediately checks if s_vecAddonMetadata.m_Size is 0,
// so we can just grab it from the CMP instruction
for (const uchar *p = insns; p - insns < 32;) {
@@ -224,7 +223,7 @@ static inline void try_fix_broken_addon_check() {
INIT {
struct con_cmd *show_addon_metadata = con_findcmd("show_addon_metadata");
if_cold (!show_addon_metadata) return FEAT_INCOMPAT; // shouldn't happen!
- if_cold (!find_addonvecsz(show_addon_metadata->cb)) {
+ if_cold (!find_addonvecsz(show_addon_metadata->cb_insns)) {
errmsg_errorx("couldn't find pointer to addon list");
return FEAT_INCOMPAT;
}
diff --git a/src/l4dwarp.c b/src/l4dwarp.c
index 462239d..8db87c9 100644
--- a/src/l4dwarp.c
+++ b/src/l4dwarp.c
@@ -26,7 +26,6 @@
#include "ent.h"
#include "feature.h"
#include "gamedata.h"
-#include "gametype.h"
#include "intdefs.h"
#include "langext.h"
#include "mem.h"
@@ -268,9 +267,8 @@ DEF_CCMD_HERE_UNREG(sst_l4d_previewwarp, "Visualise bot warp unstuck logic "
}
}
-static bool find_EntityPlacementTest(con_cmdcb z_add_cb) {
+static bool find_EntityPlacementTest(const uchar *insns) {
#ifdef _WIN32
- const uchar *insns = (const uchar *)z_add_cb;
for (const uchar *p = insns; p - insns < 0x300;) {
// Find 0, 0x200400B and 1 being pushed to the stack
if (p[0] == X86_PUSHI8 && p[1] == 0 &&
@@ -314,7 +312,7 @@ static bool init_filter() {
INIT {
struct con_cmd *z_add = con_findcmd("z_add");
- if (!z_add || !find_EntityPlacementTest(z_add->cb)) {
+ if (!z_add || !find_EntityPlacementTest(z_add->cb_insns)) {
errmsg_errorx("couldn't find EntityPlacementTest function");
return FEAT_INCOMPAT;
}
diff --git a/src/portalisg.c b/src/portalisg.c
index ffa80f2..b9a85d9 100644
--- a/src/portalisg.c
+++ b/src/portalisg.c
@@ -36,8 +36,7 @@ static con_cmdcbv2 disconnect_cb;
DEF_FEAT_CCMD_HERE(sst_portal_resetisg,
"Remove \"ISG\" state and disconnect from the server", 0) {
- struct con_cmdargs disconnect_args = {0};
- disconnect_cb(&disconnect_args);
+ disconnect_cb(&(struct con_cmdargs){0});
*isg_flag = false;
}