FBaseCVar *GetCVar(AActor *activator, const char *cvarname) { FBaseCVar *cvar = FindCVar(cvarname, nullptr); // Either the cvar doesn't exist, or it's for a mod that isn't loaded, so return nullptr. if (cvar == nullptr || (cvar->GetFlags() & CVAR_IGNORE)) { return nullptr; } else { // For userinfo cvars, redirect to GetUserCVar if (cvar->GetFlags() & CVAR_USERINFO) { if (activator == nullptr || activator->player == nullptr) { return nullptr; } return GetUserCVar(int(activator->player - players), cvarname); } return cvar; } }
FBaseCVar *FindCVar (const char *var_name, FBaseCVar **prev) { FBaseCVar *var; FBaseCVar *dummy; if (var_name == NULL) return NULL; if (prev == NULL) prev = &dummy; var = CVars; *prev = NULL; while (var) { if (stricmp (var->GetName (), var_name) == 0) break; *prev = var; var = var->m_Next; } return var; }
FBaseCVar::FBaseCVar (const char *var_name, DWORD flags, void (*callback)(FBaseCVar &)) { FBaseCVar *var; var = FindCVar (var_name, NULL); m_Callback = callback; Flags = 0; Name = NULL; if (var_name) { C_AddTabCommand (var_name); Name = copystring (var_name); m_Next = CVars; CVars = this; } if (var) { ECVarType type; UCVarValue value; value = var->GetFavoriteRep (&type); ForceSet (value, type); if (var->Flags & CVAR_AUTO) delete var; else var->~FBaseCVar(); Flags = flags; } else { Flags = flags | CVAR_ISDEFAULT; } }
void userinfo_t::Reset() { // Clear this player's userinfo. TMapIterator<FName, FBaseCVar *> it(*this); TMap<FName, FBaseCVar *>::Pair *pair; while (it.NextPair(pair)) { delete pair->Value; } Clear(); // Create userinfo vars for this player, initialized to their defaults. for (FBaseCVar *cvar = CVars; cvar != NULL; cvar = cvar->GetNext()) { if ((cvar->GetFlags() & (CVAR_USERINFO|CVAR_IGNORE)) == CVAR_USERINFO) { ECVarType type; FName cvarname(cvar->GetName()); FBaseCVar *newcvar; // Some cvars have different types for their shadow copies. switch (cvarname.GetIndex()) { case NAME_Skin: type = CVAR_Int; break; case NAME_Gender: type = CVAR_Int; break; case NAME_PlayerClass: type = CVAR_Int; break; default: type = cvar->GetRealType(); break; } newcvar = C_CreateCVar(NULL, type, cvar->GetFlags() & CVAR_MOD); newcvar->SetGenericRepDefault(cvar->GetGenericRepDefault(CVAR_String), CVAR_String); Insert(cvarname, newcvar); } } }
void D_SetupUserInfo () { int i; userinfo_t *coninfo; // Reset everybody's userinfo to a default state. for (i = 0; i < MAXPLAYERS; i++) { players[i].userinfo.Reset(); } // Initialize the console player's user info coninfo = &players[consoleplayer].userinfo; for (FBaseCVar *cvar = CVars; cvar != NULL; cvar = cvar->GetNext()) { if ((cvar->GetFlags() & (CVAR_USERINFO|CVAR_IGNORE)) == CVAR_USERINFO) { FBaseCVar **newcvar; FName cvarname(cvar->GetName()); switch (cvarname.GetIndex()) { // Some cvars don't copy their original value directly. case NAME_Team: coninfo->TeamChanged(team); break; case NAME_Skin: coninfo->SkinChanged(skin); break; case NAME_Gender: coninfo->GenderChanged(gender); break; case NAME_PlayerClass: coninfo->PlayerClassChanged(playerclass); break; // The rest do. default: newcvar = coninfo->CheckKey(cvarname); (*newcvar)->SetGenericRep(cvar->GetGenericRep(CVAR_String), CVAR_String); break; } } } R_BuildPlayerTranslation(consoleplayer); }
void FBaseCVar::ListVars (const char *filter, bool plain) { FBaseCVar *var = CVars; int count = 0; while (var) { if (CheckWildcards (filter, var->GetName())) { DWORD flags = var->GetFlags(); UCVarValue val; val = var->GetGenericRep (CVAR_String); if (plain) { // plain formatting does not include user-defined cvars if (!(flags & CVAR_UNSETTABLE)) { ++count; Printf ("%s : %s\n", var->GetName(), var->GetGenericRep(CVAR_String).String); } } else { ++count; Printf ("%c%c%c%c%c %s = %s\n", flags & CVAR_ARCHIVE ? 'A' : ' ', flags & CVAR_USERINFO ? 'U' : flags & CVAR_SERVERINFO ? 'S' : flags & CVAR_AUTO ? 'C' : ' ', flags & CVAR_NOSET ? '-' : flags & CVAR_LATCH ? 'L' : flags & CVAR_UNSETTABLE ? '*' : ' ', flags & CVAR_MOD ? 'M' : ' ', flags & CVAR_IGNORE ? 'X' : ' ', var->GetName(), var->GetGenericRep (CVAR_String).String); } } var = var->m_Next; } Printf ("%d cvars\n", count); }
void FGameConfigFile::DoGlobalSetup () { if (SetSection ("GlobalSettings.Unknown")) { ReadCVars (CVAR_GLOBALCONFIG); } if (SetSection ("GlobalSettings")) { ReadCVars (CVAR_GLOBALCONFIG); } if (SetSection ("LastRun")) { const char *lastver = GetValueForKey ("Version"); if (lastver != NULL) { double last = atof (lastver); if (last < 123.1) { FBaseCVar *noblitter = FindCVar ("vid_noblitter", NULL); if (noblitter != NULL) { noblitter->ResetToDefault (); } } if (last < 202) { // Make sure the Hexen hotkeys are accessible by default. if (SetSection ("Hexen.Bindings")) { SetValueForKey ("\\", "use ArtiHealth"); SetValueForKey ("scroll", "+showscores"); SetValueForKey ("0", "useflechette"); SetValueForKey ("9", "use ArtiBlastRadius"); SetValueForKey ("8", "use ArtiTeleport"); SetValueForKey ("7", "use ArtiTeleportOther"); SetValueForKey ("6", "use ArtiEgg"); SetValueForKey ("5", "use ArtiInvulnerability"); } } if (last < 204) { // The old default for vsync was true, but with an unlimited framerate // now, false is a better default. FBaseCVar *vsync = FindCVar ("vid_vsync", NULL); if (vsync != NULL) { vsync->ResetToDefault (); } } if (last < 206) { // spc_amp is now a float, not an int. if (spc_amp > 16) { spc_amp = spc_amp / 16.f; } } if (last < 207) { // Now that snd_midiprecache works again, you probably don't want it on. FBaseCVar *precache = FindCVar ("snd_midiprecache", NULL); if (precache != NULL) { precache->ResetToDefault(); } } if (last < 208) { // Weapon sections are no longer used, so tidy up the config by deleting them. const char *name; size_t namelen; bool more; more = SetFirstSection(); while (more) { name = GetCurrentSection(); if (name != NULL && (namelen = strlen(name)) > 12 && strcmp(name + namelen - 12, ".WeaponSlots") == 0) { more = DeleteCurrentSection(); } else { more = SetNextSection(); } } } if (last < 209) { // menu dimming is now a gameinfo option so switch user override off FBaseCVar *dim = FindCVar ("dimamount", NULL); if (dim != NULL) { dim->ResetToDefault (); } } } } }
void C_ReadCVars (BYTE **demo_p) { char *ptr = *((char **)demo_p); char *breakpt; if (*ptr++ != '\\') return; if (*ptr == '\\') { // compact mode TArray<FBaseCVar *> cvars; FBaseCVar *cvar; DWORD filter; ptr++; breakpt = strchr (ptr, '\\'); *breakpt = 0; filter = strtoul (ptr, NULL, 16); *breakpt = '\\'; ptr = breakpt + 1; FilterCompactCVars (cvars, filter); while (cvars.Pop (cvar)) { UCVarValue val; breakpt = strchr (ptr, '\\'); if (breakpt) *breakpt = 0; val.String = ptr; cvar->ForceSet (val, CVAR_String); if (breakpt) { *breakpt = '\\'; ptr = breakpt + 1; } else break; } } else { char *value; while ( (breakpt = strchr (ptr, '\\')) ) { *breakpt = 0; value = breakpt + 1; if ( (breakpt = strchr (value, '\\')) ) *breakpt = 0; cvar_set (ptr, value); *(value - 1) = '\\'; if (breakpt) { *breakpt = '\\'; ptr = breakpt + 1; } else { break; } } } *demo_p += strlen (*((char **)demo_p)) + 1; }
static const char *SetServerVar (char *name, ECVarType type, BYTE **stream, bool singlebit) { FBaseCVar *var = FindCVar (name, NULL); UCVarValue value; if (singlebit) { if (var != NULL) { int bitdata; int mask; value = var->GetFavoriteRep (&type); if (type != CVAR_Int) { return NULL; } bitdata = ReadByte (stream); mask = 1 << (bitdata & 31); if (bitdata & 32) { value.Int |= mask; } else { value.Int &= ~mask; } } } else { switch (type) { case CVAR_Bool: value.Bool = ReadByte (stream) ? 1 : 0; break; case CVAR_Int: value.Int = ReadLong (stream); break; case CVAR_Float: value.Float = ReadFloat (stream); break; case CVAR_String: value.String = ReadString (stream); break; default: break; // Silence GCC } } if (var) { var->ForceSet (value, type); } if (type == CVAR_String) { delete[] value.String; } if (var == &teamplay) { // Put players on teams if teamplay turned on for (int i = 0; i < MAXPLAYERS; ++i) { if (playeringame[i]) { UpdateTeam (i, players[i].userinfo.GetTeam(), true); } } } if (var) { value = var->GetGenericRep (CVAR_String); return value.String; } return NULL; }
void FGameConfigFile::DoGlobalSetup () { if (SetSection ("GlobalSettings.Unknown")) { ReadCVars (CVAR_GLOBALCONFIG); } if (SetSection ("GlobalSettings")) { ReadCVars (CVAR_GLOBALCONFIG); } if (SetSection ("LastRun")) { const char *lastver = GetValueForKey ("Version"); if (lastver != NULL) { double last = atof (lastver); if (last < 123.1) { FBaseCVar *noblitter = FindCVar ("vid_noblitter", NULL); if (noblitter != NULL) { noblitter->ResetToDefault (); } } if (last < 202) { // Make sure the Hexen hotkeys are accessible by default. if (SetSection ("Hexen.Bindings")) { SetValueForKey ("\\", "use ArtiHealth"); SetValueForKey ("scroll", "+showscores"); SetValueForKey ("0", "useflechette"); SetValueForKey ("9", "use ArtiBlastRadius"); SetValueForKey ("8", "use ArtiTeleport"); SetValueForKey ("7", "use ArtiTeleportOther"); SetValueForKey ("6", "use ArtiPork"); SetValueForKey ("5", "use ArtiInvulnerability2"); } } if (last < 204) { // The old default for vsync was true, but with an unlimited framerate // now, false is a better default. FBaseCVar *vsync = FindCVar ("vid_vsync", NULL); if (vsync != NULL) { vsync->ResetToDefault (); } } if (last < 206) { // spc_amp is now a float, not an int. if (spc_amp > 16) { spc_amp = spc_amp / 16.f; } } if (last < 207) { // Now that snd_midiprecache works again, you probably don't want it on. FBaseCVar *precache = FindCVar ("snd_midiprecache", NULL); if (precache != NULL) { precache->ResetToDefault(); } } if (last < 208) { // Weapon sections are no longer used, so tidy up the config by deleting them. const char *name; size_t namelen; bool more; more = SetFirstSection(); while (more) { name = GetCurrentSection(); if (name != NULL && (namelen = strlen(name)) > 12 && strcmp(name + namelen - 12, ".WeaponSlots") == 0) { more = DeleteCurrentSection(); } else { more = SetNextSection(); } } } if (last < 209) { // menu dimming is now a gameinfo option so switch user override off FBaseCVar *dim = FindCVar ("dimamount", NULL); if (dim != NULL) { dim->ResetToDefault (); } } if (last < 210) { if (SetSection ("Hexen.Bindings")) { // These 2 were misnamed in earlier versions SetValueForKey ("6", "use ArtiPork"); SetValueForKey ("5", "use ArtiInvulnerability2"); } } if (last < 213) { auto var = FindCVar("snd_channels", NULL); if (var != NULL) { // old settings were default 32, minimum 8, new settings are default 128, minimum 64. UCVarValue v = var->GetGenericRep(CVAR_Int); if (v.Int < 64) var->ResetToDefault(); } } if (last < 214) { FBaseCVar *var = FindCVar("hud_scale", NULL); if (var != NULL) var->ResetToDefault(); var = FindCVar("st_scale", NULL); if (var != NULL) var->ResetToDefault(); var = FindCVar("hud_althudscale", NULL); if (var != NULL) var->ResetToDefault(); var = FindCVar("con_scale", NULL); if (var != NULL) var->ResetToDefault(); var = FindCVar("con_scaletext", NULL); if (var != NULL) var->ResetToDefault(); var = FindCVar("uiscale", NULL); if (var != NULL) var->ResetToDefault(); } if (last < 215) { // Previously a true/false boolean. Now an on/off/auto tri-state with auto as the default. FBaseCVar *var = FindCVar("snd_hrtf", NULL); if (var != NULL) var->ResetToDefault(); } if (last < 216) { FBaseCVar *var = FindCVar("gl_texture_hqresize", NULL); if (var != NULL) { auto v = var->GetGenericRep(CVAR_Int); switch (v.Int) { case 1: gl_texture_hqresizemode = 1; gl_texture_hqresizemult = 2; break; case 2: gl_texture_hqresizemode = 1; gl_texture_hqresizemult = 3; break; case 3: gl_texture_hqresizemode = 1; gl_texture_hqresizemult = 4; break; case 4: gl_texture_hqresizemode = 2; gl_texture_hqresizemult = 2; break; case 5: gl_texture_hqresizemode = 2; gl_texture_hqresizemult = 3; break; case 6: gl_texture_hqresizemode = 2; gl_texture_hqresizemult = 4; break; case 7: gl_texture_hqresizemode = 3; gl_texture_hqresizemult = 2; break; case 8: gl_texture_hqresizemode = 3; gl_texture_hqresizemult = 3; break; case 9: gl_texture_hqresizemode = 3; gl_texture_hqresizemult = 4; break; case 10: gl_texture_hqresizemode = 4; gl_texture_hqresizemult = 2; break; case 11: gl_texture_hqresizemode = 4; gl_texture_hqresizemult = 3; break; case 12: gl_texture_hqresizemode = 4; gl_texture_hqresizemult = 4; break; case 18: gl_texture_hqresizemode = 4; gl_texture_hqresizemult = 5; break; case 19: gl_texture_hqresizemode = 4; gl_texture_hqresizemult = 6; break; case 13: gl_texture_hqresizemode = 5; gl_texture_hqresizemult = 2; break; case 14: gl_texture_hqresizemode = 5; gl_texture_hqresizemult = 3; break; case 15: gl_texture_hqresizemode = 5; gl_texture_hqresizemult = 4; break; case 16: gl_texture_hqresizemode = 5; gl_texture_hqresizemult = 5; break; case 17: gl_texture_hqresizemode = 5; gl_texture_hqresizemult = 6; break; case 20: gl_texture_hqresizemode = 6; gl_texture_hqresizemult = 2; break; case 21: gl_texture_hqresizemode = 6; gl_texture_hqresizemult = 3; break; case 22: gl_texture_hqresizemode = 6; gl_texture_hqresizemult = 4; break; case 23: gl_texture_hqresizemode = 6; gl_texture_hqresizemult = 5; break; case 24: gl_texture_hqresizemode = 6; gl_texture_hqresizemult = 6; break; case 0: default: gl_texture_hqresizemode = 0; gl_texture_hqresizemult = 1; break; } } } if (last < 217) { auto var = FindCVar("vid_scalemode", NULL); UCVarValue newvalue; newvalue.Int = 2; if (var != NULL) { UCVarValue v = var->GetGenericRep(CVAR_Int); if (v.Int == 3) var->SetGenericRep(newvalue, CVAR_Int); } } } } }