summaryrefslogtreecommitdiffstats
path: root/src/hl2h.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/hl2h.cpp')
-rw-r--r--src/hl2h.cpp34
1 files changed, 9 insertions, 25 deletions
diff --git a/src/hl2h.cpp b/src/hl2h.cpp
index ebb9b14..375cd5a 100644
--- a/src/hl2h.cpp
+++ b/src/hl2h.cpp
@@ -131,32 +131,16 @@ static int g_modified_logged = 0;
131// GetName, GetHelpText, IsRegistered, GetDLLIdentifier; ConVar then adds 131// GetName, GetHelpText, IsRegistered, GetDLLIdentifier; ConVar then adds
132// SetValue(const char*), SetValue(float), SetValue(int) -> slot 11. 132// SetValue(const char*), SetValue(float), SetValue(int) -> slot 11.
133bool cvar_set_int(const char *name, int value) { 133bool cvar_set_int(const char *name, int value) {
134 if (!name) 134 if (!name || !g_iface.engine)
135 return false; 135 return false;
136 if (g_iface.cvar) { 136 // Use the stable IVEngineClient ClientCmd slot rather than poking ConVar's
137 using FindVarFn = void *(*)(void *, const char *); 137 // vtable; the installed VEngineCvar004 layout differs enough to crash.
138 void *var = vfunc<FindVarFn>(g_iface.cvar, 12)(g_iface.cvar, name); 138 char cmd[96];
139 if (var) { 139 snprintf(cmd, sizeof(cmd), "%s %d", name, value);
140 using GetNameFn = const char *(*)(void *); 140 using CmdFn = void (*)(void *, const char *);
141 const char *got = vfunc<GetNameFn>(var, 5)(var); 141 vfunc<CmdFn>(g_iface.engine, 7)(g_iface.engine, cmd);
142 if (got && strcmp(got, name) == 0) { 142 logd("cvar: command '%s'", cmd);
143 using SetIntFn = void (*)(void *, int); 143 return true;
144 vfunc<SetIntFn>(var, 11)(var, value);
145 return true;
146 }
147 }
148 }
149 // Fallback for an engine that does not expose VEngineCvar004: ClientCmd
150 // slot 7. Cheat-protected cvars may still be rejected.
151 if (g_iface.engine) {
152 char cmd[96];
153 snprintf(cmd, sizeof(cmd), "%s %d", name, value);
154 using CmdFn = void (*)(void *, const char *);
155 vfunc<CmdFn>(g_iface.engine, 7)(g_iface.engine, cmd);
156 logd("cvar: fallback command '%s'", cmd);
157 return true;
158 }
159 return false;
160} 144}
161 145
162void note_modified(const CUserCmd *cmd, int flags, const float *vel) { 146void note_modified(const CUserCmd *cmd, int flags, const float *vel) {