fixed read-only CVar registration keeping the existing value

This commit is contained in:
myT 2022-10-23 05:23:27 +02:00
parent c8c9bef131
commit be0746dfc4
5 changed files with 19 additions and 4 deletions

View file

@ -77,6 +77,8 @@ chg: with r_backend GL3, depth fade with MSAA now requires GLSL 4.00 at a minimu
chg: with r_backend GL3, alpha to coverage now requires GLSL 4.00 at a minimum
fix: registration of a read-only CVar would keep the existing value
fix: the Direct3D projection transform didn't perfectly match the OpenGL version
fix: /video was writing incorrect audio stream lengths to the .avi file headers

View file

@ -452,7 +452,7 @@ void Com_StartupVariable( const char *match )
if ( !match || !strcmp( s, match ) ) {
Cvar_Set( s, Cmd_Argv(2) );
cvar_t* cv = Cvar_Get( s, "", 0 );
cv->flags |= CVAR_USER_CREATED;
cv->flags |= CVAR_USER_CREATED | CVAR_CMDLINE_CREATED;
}
}
}

View file

@ -422,7 +422,10 @@ cvar_t* Cvar_Get( const char *var_name, const char *var_value, int flags )
cvar_modifiedFlags |= flags;
}
const qbool cmdLineCreated = (var->flags & CVAR_CMDLINE_CREATED) != 0;
var->flags |= flags;
var->flags &= ~CVAR_CMDLINE_CREATED;
// only allow one non-empty reset string without a warning
// KHB 071110 no, that's wrong for several reasons, notably vm changes caused by pure
if ((flags & CVAR_ROM) || !var->resetString[0]) {
@ -443,6 +446,12 @@ cvar_t* Cvar_Get( const char *var_name, const char *var_value, int flags )
Z_Free( s );
}
// CVAR_INIT doesn't allow CVar registration to override the command-line value
// (even if CVAR_ROM is also set)
if (cmdLineCreated && (flags & CVAR_INIT) != 0) {
return var;
}
/* KHB note that this is #if 0'd in the 132 code, but is actually REQUIRED for correctness
consider a cgame that sets a CVAR_ROM client version:
you connect to a v1 server, load the v1 cgame, and set the ROM version to v1
@ -452,11 +461,13 @@ cvar_t* Cvar_Get( const char *var_name, const char *var_value, int flags )
i'm preserving this incorrect behavior FOR NOW for compatability, because
game\ai_main.c(1352): trap_Cvar_Register( &mapname, "mapname", "", CVAR_SERVERINFO | CVAR_ROM );
breaks every single mod except CPMA otherwise, but it IS wrong, and critically so
myT: we don't care about other mods and keeping it broken is not acceptable at all
*/
// CVAR_ROM always overrides
if (flags & CVAR_ROM) {
Cvar_Set2( var_name, var_value, qtrue );
}
*/
return var;
}

View file

@ -662,7 +662,9 @@ default values.
#define CVAR_CHEAT 512 // can not be changed if cheats are disabled
#define CVAR_NORESTART 1024 // do not clear when a cvar_restart is issued
#define CVAR_SERVER_CREATED 2048 // cvar was created by a server the client connected to.
#define CVAR_SERVER_CREATED 2048 // cvar was created by a server the client connected to
#define CVAR_CMDLINE_CREATED 4096 // cvar was created through the command-line (+set)
#define CVAR_NONEXISTENT 0xFFFFFFFF // Cvar doesn't exist.
#define MAX_CVAR_VALUE_STRING 256

View file

@ -547,7 +547,7 @@ static const cvarTableItem_t sv_cvars[] =
// systeminfo vars
{ NULL, "sv_cheats", "0", CVAR_SYSTEMINFO | CVAR_ROM, CVART_BOOL, NULL, NULL, "enables cheat commands and changing cheat cvars" },
{ &sv_serverid, "sv_serverid", "0", CVAR_SYSTEMINFO | CVAR_ROM, CVART_INTEGER, NULL, NULL, "server session identifier" },
{ &sv_pure, "sv_pure", SV_PURE_DEFAULT, CVAR_SYSTEMINFO | CVAR_ROM, CVART_BOOL, NULL, NULL, "disables native code and forces client pk3s to match the server's" },
{ &sv_pure, "sv_pure", SV_PURE_DEFAULT, CVAR_SYSTEMINFO | CVAR_ROM | CVAR_INIT, CVART_BOOL, NULL, NULL, "disables native code and forces client pk3s to match the server's" },
{ NULL, "sv_paks", "", CVAR_SYSTEMINFO | CVAR_ROM, CVART_STRING, NULL, NULL, "checksums of the paks you're allowed to load data from" },
{ NULL, "sv_pakNames", "", CVAR_SYSTEMINFO | CVAR_ROM, CVART_STRING, NULL, NULL, "names of the paks you're allowed to load data from" },
{ NULL, "sv_referencedPaks", "", CVAR_SYSTEMINFO | CVAR_ROM, CVART_STRING, NULL, NULL, "checksums of the paks you might need to download" },