From c0d4714cb304394f19cac5b71d704aa6b2c27dd5 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Sun, 20 Mar 2022 20:05:42 +0000 Subject: 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. --- src/con_.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'src/con_.c') 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)) { -- cgit v1.2.3