summaryrefslogtreecommitdiffhomepage
path: root/src/con_.c
diff options
context:
space:
mode:
authorMichael Smith <mikesmiffy128@gmail.com>2022-03-20 20:05:42 +0000
committerMichael Smith <mikesmiffy128@gmail.com>2022-03-20 20:09:53 +0000
commitc0d4714cb304394f19cac5b71d704aa6b2c27dd5 (patch)
tree252a0880c6e2fbff9a506ad049b03691eaf1094e /src/con_.c
parent254c7be6edd17a3c33e9152097264f5b159b1b45 (diff)
Support deferring cvar registration
This allows stuff to be registered conditionally. Unfortunately cmeta is now truly the worst thing of all time, but cleaning it up isn't a huge priority. On the plus side, codegen actually got simpler.
Diffstat (limited to 'src/con_.c')
-rw-r--r--src/con_.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/con_.c b/src/con_.c
index e58c040..ab1cd1e 100644
--- a/src/con_.c
+++ b/src/con_.c
@@ -396,6 +396,15 @@ static void fillvts(void) {
*pi++ = (void *)&GetSplitScreenPlayerSlot;
}
+void con_reg(void *cmd_or_var) {
+ if (GAMETYPE_MATCHES(Portal2)) {
+ VCALL(_con_iface, RegisterConCommand_p2, cmd_or_var);
+ }
+ else {
+ VCALL(_con_iface, RegisterConCommand, cmd_or_var);
+ }
+}
+
bool con_init(void *(*f)(const char *, int *), int plugin_ver) {
int ifacever; // for error messages
if (_con_iface = f("VEngineCvar007", 0)) {
@@ -409,11 +418,8 @@ bool con_init(void *(*f)(const char *, int *), int plugin_ver) {
_con_colourmsgf = VFUNC(_con_iface, ConsoleColorPrintf_p2);
dllid = VCALL0(_con_iface, AllocateDLLIdentifier_p2);
_gametype_tag |= _gametype_tag_Portal2;
- fillvts();
- regcmds(VFUNC(_con_iface, RegisterConCommand_p2));
- return true;
}
- if (VCALL(_con_iface, FindCommand, "l4d2_snd_adrenaline")) {
+ else if (VCALL(_con_iface, FindCommand, "l4d2_snd_adrenaline")) {
_con_colourmsgf = VFUNC(_con_iface, ConsoleColorPrintf_l4d);
dllid = VCALL0(_con_iface, AllocateDLLIdentifier);
// while we're here, also distinguish Survivors, the stupid Japanese
@@ -428,22 +434,21 @@ bool con_init(void *(*f)(const char *, int *), int plugin_ver) {
else {
_gametype_tag |= _gametype_tag_L4D2;
}
- fillvts();
- regcmds(VFUNC(_con_iface, RegisterConCommand));
- return true;
}
- if (VCALL(_con_iface, FindVar, "z_difficulty")) {
+ else if (VCALL(_con_iface, FindVar, "z_difficulty")) {
_con_colourmsgf = VFUNC(_con_iface, ConsoleColorPrintf_l4d);
dllid = VCALL0(_con_iface, AllocateDLLIdentifier);
_gametype_tag |= _gametype_tag_L4D1;
- fillvts(); // XXX: is this all kinda dupey? maybe rearrange one day.
- regcmds(VFUNC(_con_iface, RegisterConCommand));
- return true;
}
- con_warn("sst: error: game \"%s\" is unsupported (using "
- "VEngineCvar007)\n", gameinfo_title);
- ifacever = 7;
- goto e;
+ else {
+ con_warn("sst: error: game \"%s\" is unsupported (using "
+ "VEngineCvar007)\n", gameinfo_title);
+ ifacever = 7;
+ goto e;
+ }
+ fillvts();
+ regcmds();
+ return true;
}
if (_con_iface = f("VEngineCvar004", 0)) {
// TODO(compat): are there any cases where 004 is incompatible? could
@@ -455,7 +460,7 @@ bool con_init(void *(*f)(const char *, int *), int plugin_ver) {
if (plugin_ver == 3) _gametype_tag |= _gametype_tag_2013;
else _gametype_tag |= _gametype_tag_OrangeBox;
fillvts();
- regcmds(VFUNC(_con_iface, RegisterConCommand));
+ regcmds();
return true;
}
if (f("VEngineCvar003", 0)) {