OpenTTD Source  14.0-RC3
settings.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
24 #include "stdafx.h"
25 #include <charconv>
26 #include "settings_table.h"
27 #include "debug.h"
28 #include "currency.h"
29 #include "network/network.h"
30 #include "network/network_func.h"
31 #include "network/core/config.h"
32 #include "command_func.h"
33 #include "console_func.h"
34 #include "genworld.h"
35 #include "window_func.h"
36 #include "company_func.h"
37 #include "rev.h"
38 #include "error.h"
39 #include "gamelog.h"
40 #include "settings_func.h"
41 #include "ini_type.h"
42 #include "ai/ai_config.hpp"
43 #include "game/game_config.hpp"
44 #include "newgrf_config.h"
45 #include "base_media_base.h"
46 #include "fios.h"
47 #include "fileio_func.h"
48 #include "settings_cmd.h"
49 
50 #include "table/strings.h"
51 
52 #include "safeguards.h"
53 
58 std::string _config_file;
59 std::string _private_file;
60 std::string _secrets_file;
61 
63 
74 static auto &GenericSettingTables()
75 {
76  static const SettingTable _generic_setting_tables[] = {
77  _difficulty_settings,
78  _economy_settings,
79  _game_settings,
80  _gui_settings,
81  _linkgraph_settings,
82  _locale_settings,
83  _multimedia_settings,
84  _network_settings,
85  _news_display_settings,
86  _pathfinding_settings,
87  _script_settings,
88  _world_settings,
89  };
90  return _generic_setting_tables;
91 }
92 
96 static auto &PrivateSettingTables()
97 {
98  static const SettingTable _private_setting_tables[] = {
99  _network_private_settings,
100  };
101  return _private_setting_tables;
102 }
103 
107 static auto &SecretSettingTables()
108 {
109  static const SettingTable _secrets_setting_tables[] = {
110  _network_secrets_settings,
111  };
112  return _secrets_setting_tables;
113 }
114 
115 typedef void SettingDescProc(IniFile &ini, const SettingTable &desc, const char *grpname, void *object, bool only_startup);
116 typedef void SettingDescProcList(IniFile &ini, const char *grpname, StringList &list);
117 
118 static bool IsSignedVarMemType(VarType vt)
119 {
120  switch (GetVarMemType(vt)) {
121  case SLE_VAR_I8:
122  case SLE_VAR_I16:
123  case SLE_VAR_I32:
124  case SLE_VAR_I64:
125  return true;
126  }
127  return false;
128 }
129 
133 class ConfigIniFile : public IniFile {
134 private:
135  inline static const IniGroupNameList list_group_names = {
136  "bans",
137  "newgrf",
138  "servers",
139  "server_bind_addresses",
140  };
141 
142 public:
143  ConfigIniFile(const std::string &filename) : IniFile(list_group_names)
144  {
145  this->LoadFromDisk(filename, NO_DIRECTORY);
146  }
147 };
148 
156 enum IniFileVersion : uint32_t {
162 
166 
168 };
169 
171 
179 size_t OneOfManySettingDesc::ParseSingleValue(const char *str, size_t len, const std::vector<std::string> &many)
180 {
181  /* check if it's an integer */
182  if (isdigit(*str)) return std::strtoul(str, nullptr, 0);
183 
184  size_t idx = 0;
185  for (auto one : many) {
186  if (one.size() == len && strncmp(one.c_str(), str, len) == 0) return idx;
187  idx++;
188  }
189 
190  return (size_t)-1;
191 }
192 
199 std::optional<bool> BoolSettingDesc::ParseSingleValue(const char *str)
200 {
201  if (strcmp(str, "true") == 0 || strcmp(str, "on") == 0 || strcmp(str, "1") == 0) return true;
202  if (strcmp(str, "false") == 0 || strcmp(str, "off") == 0 || strcmp(str, "0") == 0) return false;
203 
204  return std::nullopt;
205 }
206 
214 static size_t LookupManyOfMany(const std::vector<std::string> &many, const char *str)
215 {
216  const char *s;
217  size_t r;
218  size_t res = 0;
219 
220  for (;;) {
221  /* skip "whitespace" */
222  while (*str == ' ' || *str == '\t' || *str == '|') str++;
223  if (*str == 0) break;
224 
225  s = str;
226  while (*s != 0 && *s != ' ' && *s != '\t' && *s != '|') s++;
227 
228  r = OneOfManySettingDesc::ParseSingleValue(str, s - str, many);
229  if (r == (size_t)-1) return r;
230 
231  SetBit(res, (uint8_t)r); // value found, set it
232  if (*s == 0) break;
233  str = s + 1;
234  }
235  return res;
236 }
237 
246 template<typename T>
247 static int ParseIntList(const char *p, T *items, size_t maxitems)
248 {
249  size_t n = 0; // number of items read so far
250  bool comma = false; // do we accept comma?
251 
252  while (*p != '\0') {
253  switch (*p) {
254  case ',':
255  /* Do not accept multiple commas between numbers */
256  if (!comma) return -1;
257  comma = false;
258  [[fallthrough]];
259 
260  case ' ':
261  p++;
262  break;
263 
264  default: {
265  if (n == maxitems) return -1; // we don't accept that many numbers
266  char *end;
267  unsigned long v = std::strtoul(p, &end, 0);
268  if (p == end) return -1; // invalid character (not a number)
269  if (sizeof(T) < sizeof(v)) v = Clamp<unsigned long>(v, std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
270  items[n++] = v;
271  p = end; // first non-number
272  comma = true; // we accept comma now
273  break;
274  }
275  }
276  }
277 
278  /* If we have read comma but no number after it, fail.
279  * We have read comma when (n != 0) and comma is not allowed */
280  if (n != 0 && !comma) return -1;
281 
282  return ClampTo<int>(n);
283 }
284 
293 static bool LoadIntList(const char *str, void *array, int nelems, VarType type)
294 {
295  unsigned long items[64];
296  int i, nitems;
297 
298  if (str == nullptr) {
299  memset(items, 0, sizeof(items));
300  nitems = nelems;
301  } else {
302  nitems = ParseIntList(str, items, lengthof(items));
303  if (nitems != nelems) return false;
304  }
305 
306  switch (type) {
307  case SLE_VAR_BL:
308  case SLE_VAR_I8:
309  case SLE_VAR_U8:
310  for (i = 0; i != nitems; i++) ((byte*)array)[i] = items[i];
311  break;
312 
313  case SLE_VAR_I16:
314  case SLE_VAR_U16:
315  for (i = 0; i != nitems; i++) ((uint16_t*)array)[i] = items[i];
316  break;
317 
318  case SLE_VAR_I32:
319  case SLE_VAR_U32:
320  for (i = 0; i != nitems; i++) ((uint32_t*)array)[i] = items[i];
321  break;
322 
323  default: NOT_REACHED();
324  }
325 
326  return true;
327 }
328 
338 std::string ListSettingDesc::FormatValue(const void *object) const
339 {
340  const byte *p = static_cast<const byte *>(GetVariableAddress(object, this->save));
341 
342  std::string result;
343  for (size_t i = 0; i != this->save.length; i++) {
344  int64_t v;
345  switch (GetVarMemType(this->save.conv)) {
346  case SLE_VAR_BL:
347  case SLE_VAR_I8: v = *(const int8_t *)p; p += 1; break;
348  case SLE_VAR_U8: v = *(const uint8_t *)p; p += 1; break;
349  case SLE_VAR_I16: v = *(const int16_t *)p; p += 2; break;
350  case SLE_VAR_U16: v = *(const uint16_t *)p; p += 2; break;
351  case SLE_VAR_I32: v = *(const int32_t *)p; p += 4; break;
352  case SLE_VAR_U32: v = *(const uint32_t *)p; p += 4; break;
353  default: NOT_REACHED();
354  }
355  if (i != 0) result += ',';
356  result += std::to_string(v);
357  }
358  return result;
359 }
360 
361 std::string OneOfManySettingDesc::FormatSingleValue(uint id) const
362 {
363  if (id >= this->many.size()) {
364  return std::to_string(id);
365  }
366  return this->many[id];
367 }
368 
369 std::string OneOfManySettingDesc::FormatValue(const void *object) const
370 {
371  uint id = (uint)this->Read(object);
372  return this->FormatSingleValue(id);
373 }
374 
375 std::string ManyOfManySettingDesc::FormatValue(const void *object) const
376 {
377  uint bitmask = (uint)this->Read(object);
378  if (bitmask == 0) {
379  return {};
380  }
381 
382  std::string result;
383  for (uint id : SetBitIterator(bitmask)) {
384  if (!result.empty()) result += '|';
385  result += this->FormatSingleValue(id);
386  }
387  return result;
388 }
389 
395 size_t IntSettingDesc::ParseValue(const char *str) const
396 {
397  char *end;
398  size_t val = std::strtoul(str, &end, 0);
399  if (end == str) {
400  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
401  msg.SetDParamStr(0, str);
402  msg.SetDParamStr(1, this->GetName());
403  _settings_error_list.push_back(msg);
404  return this->def;
405  }
406  if (*end != '\0') {
407  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_TRAILING_CHARACTERS);
408  msg.SetDParamStr(0, this->GetName());
409  _settings_error_list.push_back(msg);
410  }
411  return val;
412 }
413 
414 size_t OneOfManySettingDesc::ParseValue(const char *str) const
415 {
416  size_t r = OneOfManySettingDesc::ParseSingleValue(str, strlen(str), this->many);
417  /* if the first attempt of conversion from string to the appropriate value fails,
418  * look if we have defined a converter from old value to new value. */
419  if (r == (size_t)-1 && this->many_cnvt != nullptr) r = this->many_cnvt(str);
420  if (r != (size_t)-1) return r; // and here goes converted value
421 
422  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
423  msg.SetDParamStr(0, str);
424  msg.SetDParamStr(1, this->GetName());
425  _settings_error_list.push_back(msg);
426  return this->def;
427 }
428 
429 size_t ManyOfManySettingDesc::ParseValue(const char *str) const
430 {
431  size_t r = LookupManyOfMany(this->many, str);
432  if (r != (size_t)-1) return r;
433  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
434  msg.SetDParamStr(0, str);
435  msg.SetDParamStr(1, this->GetName());
436  _settings_error_list.push_back(msg);
437  return this->def;
438 }
439 
440 size_t BoolSettingDesc::ParseValue(const char *str) const
441 {
443  if (r.has_value()) return *r;
444 
445  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
446  msg.SetDParamStr(0, str);
447  msg.SetDParamStr(1, this->GetName());
448  _settings_error_list.push_back(msg);
449  return this->def;
450 }
451 
458 {
459  return this->get_title_cb != nullptr ? this->get_title_cb(*this) : this->str;
460 }
461 
467 {
468  return this->get_help_cb != nullptr ? this->get_help_cb(*this) : this->str_help;
469 }
470 
476 void IntSettingDesc::SetValueDParams(uint first_param, int32_t value) const
477 {
478  if (this->set_value_dparams_cb != nullptr) {
479  this->set_value_dparams_cb(*this, first_param, value);
480  } else if (this->IsBoolSetting()) {
481  SetDParam(first_param++, value != 0 ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
482  } else {
483  if ((this->flags & SF_GUI_DROPDOWN) != 0) {
484  SetDParam(first_param++, this->str_val - this->min + value);
485  } else {
486  SetDParam(first_param++, this->str_val + ((value == 0 && (this->flags & SF_GUI_0_IS_SPECIAL) != 0) ? 1 : 0));
487  }
488  SetDParam(first_param++, value);
489  }
490 }
491 
498 void IntSettingDesc::MakeValueValidAndWrite(const void *object, int32_t val) const
499 {
500  this->MakeValueValid(val);
501  this->Write(object, val);
502 }
503 
513 void IntSettingDesc::MakeValueValid(int32_t &val) const
514 {
515  /* We need to take special care of the uint32_t type as we receive from the function
516  * a signed integer. While here also bail out on 64-bit settings as those are not
517  * supported. Unsigned 8 and 16-bit variables are safe since they fit into a signed
518  * 32-bit variable
519  * TODO: Support 64-bit settings/variables; requires 64 bit over command protocol! */
520  switch (GetVarMemType(this->save.conv)) {
521  case SLE_VAR_NULL: return;
522  case SLE_VAR_BL:
523  case SLE_VAR_I8:
524  case SLE_VAR_U8:
525  case SLE_VAR_I16:
526  case SLE_VAR_U16:
527  case SLE_VAR_I32: {
528  /* Override the minimum value. No value below this->min, except special value 0 */
529  if (!(this->flags & SF_GUI_0_IS_SPECIAL) || val != 0) {
530  if (!(this->flags & SF_GUI_DROPDOWN)) {
531  /* Clamp value-type setting to its valid range */
532  val = Clamp(val, this->min, this->max);
533  } else if (val < this->min || val > (int32_t)this->max) {
534  /* Reset invalid discrete setting (where different values change gameplay) to its default value */
535  val = this->def;
536  }
537  }
538  break;
539  }
540  case SLE_VAR_U32: {
541  /* Override the minimum value. No value below this->min, except special value 0 */
542  uint32_t uval = (uint32_t)val;
543  if (!(this->flags & SF_GUI_0_IS_SPECIAL) || uval != 0) {
544  if (!(this->flags & SF_GUI_DROPDOWN)) {
545  /* Clamp value-type setting to its valid range */
546  uval = ClampU(uval, this->min, this->max);
547  } else if (uval < (uint)this->min || uval > this->max) {
548  /* Reset invalid discrete setting to its default value */
549  uval = (uint32_t)this->def;
550  }
551  }
552  val = (int32_t)uval;
553  return;
554  }
555  case SLE_VAR_I64:
556  case SLE_VAR_U64:
557  default: NOT_REACHED();
558  }
559 }
560 
566 void IntSettingDesc::Write(const void *object, int32_t val) const
567 {
568  void *ptr = GetVariableAddress(object, this->save);
569  WriteValue(ptr, this->save.conv, (int64_t)val);
570 }
571 
577 int32_t IntSettingDesc::Read(const void *object) const
578 {
579  void *ptr = GetVariableAddress(object, this->save);
580  return (int32_t)ReadValue(ptr, this->save.conv);
581 }
582 
590 void StringSettingDesc::MakeValueValid(std::string &str) const
591 {
592  if (this->max_length == 0 || str.size() < this->max_length) return;
593 
594  /* In case a maximum length is imposed by the setting, the length
595  * includes the '\0' termination for network transfer purposes.
596  * Also ensure the string is valid after chopping of some bytes. */
597  std::string stdstr(str, this->max_length - 1);
598  str.assign(StrMakeValid(stdstr, SVS_NONE));
599 }
600 
606 void StringSettingDesc::Write(const void *object, const std::string &str) const
607 {
608  reinterpret_cast<std::string *>(GetVariableAddress(object, this->save))->assign(str);
609 }
610 
616 const std::string &StringSettingDesc::Read(const void *object) const
617 {
618  return *reinterpret_cast<std::string *>(GetVariableAddress(object, this->save));
619 }
620 
630 static void IniLoadSettings(IniFile &ini, const SettingTable &settings_table, const char *grpname, void *object, bool only_startup)
631 {
632  const IniGroup *group;
633  const IniGroup *group_def = ini.GetGroup(grpname);
634 
635  for (auto &desc : settings_table) {
636  const SettingDesc *sd = GetSettingDesc(desc);
637  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
638  if (sd->startup != only_startup) continue;
639 
640  /* For settings.xx.yy load the settings from [xx] yy = ? */
641  std::string s{ sd->GetName() };
642  auto sc = s.find('.');
643  if (sc != std::string::npos) {
644  group = ini.GetGroup(s.substr(0, sc));
645  if (group == nullptr) group = group_def;
646  s = s.substr(sc + 1);
647  } else {
648  group = group_def;
649  }
650 
651  const IniItem *item = nullptr;
652  if (group != nullptr) item = group->GetItem(s);
653  if (item == nullptr && group != group_def && group_def != nullptr) {
654  /* For settings.xx.yy load the settings from [settings] yy = ? in case the previous
655  * did not exist (e.g. loading old config files with a [settings] section */
656  item = group_def->GetItem(s);
657  }
658  if (item == nullptr) {
659  /* For settings.xx.zz.yy load the settings from [zz] yy = ? in case the previous
660  * did not exist (e.g. loading old config files with a [yapf] section */
661  sc = s.find('.');
662  if (sc != std::string::npos) {
663  if (group = ini.GetGroup(s.substr(0, sc)); group != nullptr) item = group->GetItem(s.substr(sc + 1));
664  }
665  }
666 
667  sd->ParseValue(item, object);
668  }
669 }
670 
671 void IntSettingDesc::ParseValue(const IniItem *item, void *object) const
672 {
673  size_t val = (item == nullptr) ? this->def : this->ParseValue(item->value.has_value() ? item->value->c_str() : "");
674  this->MakeValueValidAndWrite(object, (int32_t)val);
675 }
676 
677 void StringSettingDesc::ParseValue(const IniItem *item, void *object) const
678 {
679  std::string str = (item == nullptr) ? this->def : item->value.value_or("");
680  this->MakeValueValid(str);
681  this->Write(object, str);
682 }
683 
684 void ListSettingDesc::ParseValue(const IniItem *item, void *object) const
685 {
686  const char *str = (item == nullptr) ? this->def : item->value.has_value() ? item->value->c_str() : nullptr;
687  void *ptr = GetVariableAddress(object, this->save);
688  if (!LoadIntList(str, ptr, this->save.length, GetVarMemType(this->save.conv))) {
689  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_ARRAY);
690  msg.SetDParamStr(0, this->GetName());
691  _settings_error_list.push_back(msg);
692 
693  /* Use default */
694  LoadIntList(this->def, ptr, this->save.length, GetVarMemType(this->save.conv));
695  }
696 }
697 
710 static void IniSaveSettings(IniFile &ini, const SettingTable &settings_table, const char *grpname, void *object, bool)
711 {
712  IniGroup *group_def = nullptr, *group;
713 
714  for (auto &desc : settings_table) {
715  const SettingDesc *sd = GetSettingDesc(desc);
716  /* If the setting is not saved to the configuration
717  * file, just continue with the next setting */
718  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
719  if (sd->flags & SF_NOT_IN_CONFIG) continue;
720 
721  /* XXX - wtf is this?? (group override?) */
722  std::string s{ sd->GetName() };
723  auto sc = s.find('.');
724  if (sc != std::string::npos) {
725  group = &ini.GetOrCreateGroup(s.substr(0, sc));
726  s = s.substr(sc + 1);
727  } else {
728  if (group_def == nullptr) group_def = &ini.GetOrCreateGroup(grpname);
729  group = group_def;
730  }
731 
732  IniItem &item = group->GetOrCreateItem(s);
733 
734  if (!item.value.has_value() || !sd->IsSameValue(&item, object)) {
735  /* The value is different, that means we have to write it to the ini */
736  item.value.emplace(sd->FormatValue(object));
737  }
738  }
739 }
740 
741 std::string IntSettingDesc::FormatValue(const void *object) const
742 {
743  int64_t i;
744  if (IsSignedVarMemType(this->save.conv)) {
745  i = this->Read(object);
746  } else {
747  i = (uint32_t)this->Read(object);
748  }
749  return std::to_string(i);
750 }
751 
752 std::string BoolSettingDesc::FormatValue(const void *object) const
753 {
754  bool val = this->Read(object) != 0;
755  return val ? "true" : "false";
756 }
757 
758 bool IntSettingDesc::IsSameValue(const IniItem *item, void *object) const
759 {
760  int32_t item_value = (int32_t)this->ParseValue(item->value->c_str());
761  int32_t object_value = this->Read(object);
762  return item_value == object_value;
763 }
764 
765 bool IntSettingDesc::IsDefaultValue(void *object) const
766 {
767  int32_t object_value = this->Read(object);
768  return this->def == object_value;
769 }
770 
771 void IntSettingDesc::ResetToDefault(void *object) const
772 {
773  this->Write(object, this->def);
774 }
775 
776 std::string StringSettingDesc::FormatValue(const void *object) const
777 {
778  const std::string &str = this->Read(object);
779  switch (GetVarMemType(this->save.conv)) {
780  case SLE_VAR_STR: return str;
781 
782  case SLE_VAR_STRQ:
783  if (str.empty()) {
784  return str;
785  }
786  return fmt::format("\"{}\"", str);
787 
788  default: NOT_REACHED();
789  }
790 }
791 
792 bool StringSettingDesc::IsSameValue(const IniItem *item, void *object) const
793 {
794  /* The ini parsing removes the quotes, which are needed to retain the spaces in STRQs,
795  * so those values are always different in the parsed ini item than they should be. */
796  if (GetVarMemType(this->save.conv) == SLE_VAR_STRQ) return false;
797 
798  const std::string &str = this->Read(object);
799  return item->value->compare(str) == 0;
800 }
801 
802 bool StringSettingDesc::IsDefaultValue(void *object) const
803 {
804  const std::string &str = this->Read(object);
805  return this->def == str;
806 }
807 
808 void StringSettingDesc::ResetToDefault(void *object) const
809 {
810  this->Write(object, this->def);
811 }
812 
813 bool ListSettingDesc::IsSameValue(const IniItem *, void *) const
814 {
815  /* Checking for equality is way more expensive than just writing the value. */
816  return false;
817 }
818 
820 {
821  /* Defaults of lists are often complicated, and hard to compare. */
822  return false;
823 }
824 
826 {
827  /* Resetting a list to default is not supported. */
828  NOT_REACHED();
829 }
830 
840 static void IniLoadSettingList(IniFile &ini, const char *grpname, StringList &list)
841 {
842  const IniGroup *group = ini.GetGroup(grpname);
843 
844  if (group == nullptr) return;
845 
846  list.clear();
847 
848  for (const IniItem &item : group->items) {
849  if (!item.name.empty()) list.push_back(item.name);
850  }
851 }
852 
862 static void IniSaveSettingList(IniFile &ini, const char *grpname, StringList &list)
863 {
864  IniGroup &group = ini.GetOrCreateGroup(grpname);
865  group.Clear();
866 
867  for (const auto &iter : list) {
868  group.GetOrCreateItem(iter).SetValue("");
869  }
870 }
871 
878 void IniLoadWindowSettings(IniFile &ini, const char *grpname, void *desc)
879 {
880  IniLoadSettings(ini, _window_settings, grpname, desc, false);
881 }
882 
889 void IniSaveWindowSettings(IniFile &ini, const char *grpname, void *desc)
890 {
891  IniSaveSettings(ini, _window_settings, grpname, desc, false);
892 }
893 
899 bool SettingDesc::IsEditable(bool do_command) const
900 {
901  if (!do_command && !(this->flags & SF_NO_NETWORK_SYNC) && _networking && !_network_server && !(this->flags & SF_PER_COMPANY)) return false;
902  if (do_command && (this->flags & SF_NO_NETWORK_SYNC)) return false;
903  if ((this->flags & SF_NETWORK_ONLY) && !_networking && _game_mode != GM_MENU) return false;
904  if ((this->flags & SF_NO_NETWORK) && _networking) return false;
905  if ((this->flags & SF_NEWGAME_ONLY) &&
906  (_game_mode == GM_NORMAL ||
907  (_game_mode == GM_EDITOR && !(this->flags & SF_SCENEDIT_TOO)))) return false;
908  if ((this->flags & SF_SCENEDIT_ONLY) && _game_mode != GM_EDITOR) return false;
909  return true;
910 }
911 
917 {
918  if (this->flags & SF_PER_COMPANY) return ST_COMPANY;
919  return (this->flags & SF_NOT_IN_SAVE) ? ST_CLIENT : ST_GAME;
920 }
921 
927 {
928  assert(this->IsIntSetting());
929  return static_cast<const IntSettingDesc *>(this);
930 }
931 
937 {
938  assert(this->IsStringSetting());
939  return static_cast<const StringSettingDesc *>(this);
940 }
941 
942 void PrepareOldDiffCustom();
943 void HandleOldDiffCustom(bool savegame);
944 
945 
947 static void ValidateSettings()
948 {
949  /* Do not allow a custom sea level with the original land generator. */
953  }
954 }
955 
956 static void AILoadConfig(const IniFile &ini, const char *grpname)
957 {
958  const IniGroup *group = ini.GetGroup(grpname);
959 
960  /* Clean any configured AI */
961  for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
963  }
964 
965  /* If no group exists, return */
966  if (group == nullptr) return;
967 
969  for (const IniItem &item : group->items) {
971 
972  config->Change(item.name);
973  if (!config->HasScript()) {
974  if (item.name != "none") {
975  Debug(script, 0, "The AI by the name '{}' was no longer found, and removed from the list.", item.name);
976  continue;
977  }
978  }
979  if (item.value.has_value()) config->StringToSettings(*item.value);
980  c++;
981  if (c >= MAX_COMPANIES) break;
982  }
983 }
984 
985 static void GameLoadConfig(const IniFile &ini, const char *grpname)
986 {
987  const IniGroup *group = ini.GetGroup(grpname);
988 
989  /* Clean any configured GameScript */
991 
992  /* If no group exists, return */
993  if (group == nullptr || group->items.empty()) return;
994 
995  const IniItem &item = group->items.front();
996 
998 
999  config->Change(item.name);
1000  if (!config->HasScript()) {
1001  if (item.name != "none") {
1002  Debug(script, 0, "The GameScript by the name '{}' was no longer found, and removed from the list.", item.name);
1003  return;
1004  }
1005  }
1006  if (item.value.has_value()) config->StringToSettings(*item.value);
1007 }
1008 
1013 {
1014  if (const IniGroup *group = ini.GetGroup("misc"); group != nullptr) {
1015  /* Load old setting first. */
1016  if (const IniItem *item = group->GetItem("graphicsset"); item != nullptr && item->value) BaseGraphics::ini_data.name = *item->value;
1017  }
1018 
1019  if (const IniGroup *group = ini.GetGroup("graphicsset"); group != nullptr) {
1020  /* Load new settings. */
1021  if (const IniItem *item = group->GetItem("name"); item != nullptr && item->value) BaseGraphics::ini_data.name = *item->value;
1022 
1023  if (const IniItem *item = group->GetItem("shortname"); item != nullptr && item->value && item->value->size() == 8) {
1024  BaseGraphics::ini_data.shortname = BSWAP32(std::strtoul(item->value->c_str(), nullptr, 16));
1025  }
1026 
1027  if (const IniItem *item = group->GetItem("extra_version"); item != nullptr && item->value) BaseGraphics::ini_data.extra_version = std::strtoul(item->value->c_str(), nullptr, 10);
1028 
1029  if (const IniItem *item = group->GetItem("extra_params"); item != nullptr && item->value) {
1030  auto &extra_params = BaseGraphics::ini_data.extra_params;
1031  extra_params.resize(lengthof(GRFConfig::param));
1032  int count = ParseIntList(item->value->c_str(), &extra_params.front(), extra_params.size());
1033  if (count < 0) {
1034  SetDParamStr(0, BaseGraphics::ini_data.name);
1035  ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_ARRAY, WL_CRITICAL);
1036  count = 0;
1037  }
1038  extra_params.resize(count);
1039  }
1040  }
1041 }
1042 
1049 static GRFConfig *GRFLoadConfig(const IniFile &ini, const char *grpname, bool is_static)
1050 {
1051  const IniGroup *group = ini.GetGroup(grpname);
1052  GRFConfig *first = nullptr;
1053  GRFConfig **curr = &first;
1054 
1055  if (group == nullptr) return nullptr;
1056 
1057  uint num_grfs = 0;
1058  for (const IniItem &item : group->items) {
1059  GRFConfig *c = nullptr;
1060 
1061  std::array<uint8_t, 4> grfid_buf;
1062  MD5Hash md5sum;
1063  std::string_view item_name = item.name;
1064  bool has_md5sum = false;
1065 
1066  /* Try reading "<grfid>|" and on success, "<md5sum>|". */
1067  auto grfid_pos = item_name.find("|");
1068  if (grfid_pos != std::string_view::npos) {
1069  std::string_view grfid_str = item_name.substr(0, grfid_pos);
1070 
1071  if (ConvertHexToBytes(grfid_str, grfid_buf)) {
1072  item_name = item_name.substr(grfid_pos + 1);
1073 
1074  auto md5sum_pos = item_name.find("|");
1075  if (md5sum_pos != std::string_view::npos) {
1076  std::string_view md5sum_str = item_name.substr(0, md5sum_pos);
1077 
1078  has_md5sum = ConvertHexToBytes(md5sum_str, md5sum);
1079  if (has_md5sum) item_name = item_name.substr(md5sum_pos + 1);
1080  }
1081 
1082  uint32_t grfid = grfid_buf[0] | (grfid_buf[1] << 8) | (grfid_buf[2] << 16) | (grfid_buf[3] << 24);
1083  if (has_md5sum) {
1084  const GRFConfig *s = FindGRFConfig(grfid, FGCM_EXACT, &md5sum);
1085  if (s != nullptr) c = new GRFConfig(*s);
1086  }
1087  if (c == nullptr && !FioCheckFileExists(std::string(item_name), NEWGRF_DIR)) {
1088  const GRFConfig *s = FindGRFConfig(grfid, FGCM_NEWEST_VALID);
1089  if (s != nullptr) c = new GRFConfig(*s);
1090  }
1091  }
1092  }
1093  std::string filename = std::string(item_name);
1094 
1095  if (c == nullptr) c = new GRFConfig(filename);
1096 
1097  /* Parse parameters */
1098  if (item.value.has_value() && !item.value->empty()) {
1099  int count = ParseIntList(item.value->c_str(), c->param.data(), c->param.size());
1100  if (count < 0) {
1101  SetDParamStr(0, filename);
1102  ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_ARRAY, WL_CRITICAL);
1103  count = 0;
1104  }
1105  c->num_params = count;
1106  }
1107 
1108  /* Check if item is valid */
1109  if (!FillGRFDetails(c, is_static) || HasBit(c->flags, GCF_INVALID)) {
1110  if (c->status == GCS_NOT_FOUND) {
1111  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_NOT_FOUND);
1112  } else if (HasBit(c->flags, GCF_UNSAFE)) {
1113  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNSAFE);
1114  } else if (HasBit(c->flags, GCF_SYSTEM)) {
1115  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_SYSTEM);
1116  } else if (HasBit(c->flags, GCF_INVALID)) {
1117  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_INCOMPATIBLE);
1118  } else {
1119  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNKNOWN);
1120  }
1121 
1122  SetDParamStr(0, filename.empty() ? item.name.c_str() : filename);
1123  ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_GRF, WL_CRITICAL);
1124  delete c;
1125  continue;
1126  }
1127 
1128  /* Check for duplicate GRFID (will also check for duplicate filenames) */
1129  bool duplicate = false;
1130  for (const GRFConfig *gc = first; gc != nullptr; gc = gc->next) {
1131  if (gc->ident.grfid == c->ident.grfid) {
1132  SetDParamStr(0, c->filename);
1133  SetDParamStr(1, gc->filename);
1134  ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_DUPLICATE_GRFID, WL_CRITICAL);
1135  duplicate = true;
1136  break;
1137  }
1138  }
1139  if (duplicate) {
1140  delete c;
1141  continue;
1142  }
1143 
1144  if (is_static) {
1145  /* Mark file as static to avoid saving in savegame. */
1146  SetBit(c->flags, GCF_STATIC);
1147  } else if (++num_grfs > NETWORK_MAX_GRF_COUNT) {
1148  /* Check we will not load more non-static NewGRFs than allowed. This could trigger issues for game servers. */
1149  ShowErrorMessage(STR_CONFIG_ERROR, STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED, WL_CRITICAL);
1150  break;
1151  }
1152 
1153  /* Add item to list */
1154  *curr = c;
1155  curr = &c->next;
1156  }
1157 
1158  return first;
1159 }
1160 
1161 static IniFileVersion LoadVersionFromConfig(const IniFile &ini)
1162 {
1163  const IniGroup *group = ini.GetGroup("version");
1164  if (group == nullptr) return IFV_0;
1165 
1166  auto version_number = group->GetItem("ini_version");
1167  /* Older ini-file versions don't have this key yet. */
1168  if (version_number == nullptr || !version_number->value.has_value()) return IFV_0;
1169 
1170  uint32_t version = 0;
1171  std::from_chars(version_number->value->data(), version_number->value->data() + version_number->value->size(), version);
1172 
1173  return static_cast<IniFileVersion>(version);
1174 }
1175 
1176 static void AISaveConfig(IniFile &ini, const char *grpname)
1177 {
1178  IniGroup &group = ini.GetOrCreateGroup(grpname);
1179  group.Clear();
1180 
1181  for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
1183  std::string name;
1184  std::string value = config->SettingsToString();
1185 
1186  if (config->HasScript()) {
1187  name = config->GetName();
1188  } else {
1189  name = "none";
1190  }
1191 
1192  group.CreateItem(name).SetValue(value);
1193  }
1194 }
1195 
1196 static void GameSaveConfig(IniFile &ini, const char *grpname)
1197 {
1198  IniGroup &group = ini.GetOrCreateGroup(grpname);
1199  group.Clear();
1200 
1202  std::string name;
1203  std::string value = config->SettingsToString();
1204 
1205  if (config->HasScript()) {
1206  name = config->GetName();
1207  } else {
1208  name = "none";
1209  }
1210 
1211  group.CreateItem(name).SetValue(value);
1212 }
1213 
1218 static void SaveVersionInConfig(IniFile &ini)
1219 {
1220  IniGroup &group = ini.GetOrCreateGroup("version");
1221  group.GetOrCreateItem("version_string").SetValue(_openttd_revision);
1222  group.GetOrCreateItem("version_number").SetValue(fmt::format("{:08X}", _openttd_newgrf_version));
1223  group.GetOrCreateItem("ini_version").SetValue(std::to_string(INIFILE_VERSION));
1224 }
1225 
1230 {
1231  const GraphicsSet *used_set = BaseGraphics::GetUsedSet();
1232  if (used_set == nullptr) return;
1233 
1234  IniGroup &group = ini.GetOrCreateGroup("graphicsset");
1235  group.Clear();
1236 
1237  group.GetOrCreateItem("name").SetValue(used_set->name);
1238  group.GetOrCreateItem("shortname").SetValue(fmt::format("{:08X}", BSWAP32(used_set->shortname)));
1239 
1240  const GRFConfig *extra_cfg = used_set->GetExtraConfig();
1241  if (extra_cfg != nullptr && extra_cfg->num_params > 0) {
1242  group.GetOrCreateItem("extra_version").SetValue(fmt::format("{}", extra_cfg->version));
1243  group.GetOrCreateItem("extra_params").SetValue(GRFBuildParamList(extra_cfg));
1244  }
1245 }
1246 
1247 /* Save a GRF configuration to the given group name */
1248 static void GRFSaveConfig(IniFile &ini, const char *grpname, const GRFConfig *list)
1249 {
1250  IniGroup &group = ini.GetOrCreateGroup(grpname);
1251  group.Clear();
1252  const GRFConfig *c;
1253 
1254  for (c = list; c != nullptr; c = c->next) {
1255  std::string key = fmt::format("{:08X}|{}|{}", BSWAP32(c->ident.grfid),
1258  }
1259 }
1260 
1261 /* Common handler for saving/loading variables to the configuration file */
1262 static void HandleSettingDescs(IniFile &generic_ini, IniFile &private_ini, IniFile &secrets_ini, SettingDescProc *proc, SettingDescProcList *proc_list, bool only_startup = false)
1263 {
1264  proc(generic_ini, _misc_settings, "misc", nullptr, only_startup);
1265 #if defined(_WIN32) && !defined(DEDICATED)
1266  proc(generic_ini, _win32_settings, "win32", nullptr, only_startup);
1267 #endif /* _WIN32 */
1268 
1269  /* The name "patches" is a fallback, as every setting should sets its own group. */
1270 
1271  for (auto &table : GenericSettingTables()) {
1272  proc(generic_ini, table, "patches", &_settings_newgame, only_startup);
1273  }
1274  for (auto &table : PrivateSettingTables()) {
1275  proc(private_ini, table, "patches", &_settings_newgame, only_startup);
1276  }
1277  for (auto &table : SecretSettingTables()) {
1278  proc(secrets_ini, table, "patches", &_settings_newgame, only_startup);
1279  }
1280 
1281  proc(generic_ini, _currency_settings, "currency", &_custom_currency, only_startup);
1282  proc(generic_ini, _company_settings, "company", &_settings_client.company, only_startup);
1283 
1284  if (!only_startup) {
1285  proc_list(private_ini, "server_bind_addresses", _network_bind_list);
1286  proc_list(private_ini, "servers", _network_host_list);
1287  proc_list(private_ini, "bans", _network_ban_list);
1288  }
1289 }
1290 
1300 static void RemoveEntriesFromIni(IniFile &ini, const SettingTable &table)
1301 {
1302  for (auto &desc : table) {
1303  const SettingDesc *sd = GetSettingDesc(desc);
1304 
1305  /* For settings.xx.yy load the settings from [xx] yy = ? */
1306  std::string s{ sd->GetName() };
1307  auto sc = s.find('.');
1308  if (sc == std::string::npos) continue;
1309 
1310  IniGroup *group = ini.GetGroup(s.substr(0, sc));
1311  if (group == nullptr) continue;
1312  s = s.substr(sc + 1);
1313 
1314  group->RemoveItem(s);
1315  }
1316 }
1317 
1341 bool IsConversionNeeded(const ConfigIniFile &ini, const std::string &group, const std::string &old_var, const std::string &new_var, const IniItem **old_item)
1342 {
1343  *old_item = nullptr;
1344 
1345  const IniGroup *igroup = ini.GetGroup(group);
1346  /* If the group doesn't exist, there is nothing to convert. */
1347  if (igroup == nullptr) return false;
1348 
1349  const IniItem *tmp_old_item = igroup->GetItem(old_var);
1350  const IniItem *new_item = igroup->GetItem(new_var);
1351 
1352  /* If the old item doesn't exist, there is nothing to convert. */
1353  if (tmp_old_item == nullptr) return false;
1354 
1355  /* If the new item exists, it means conversion was already done. We only
1356  * do the conversion the first time, and after that these settings are
1357  * independent. This allows users to freely change between older and
1358  * newer clients without breaking anything. */
1359  if (new_item != nullptr) return false;
1360 
1361  *old_item = tmp_old_item;
1362  return true;
1363 }
1364 
1369 void LoadFromConfig(bool startup)
1370 {
1371  ConfigIniFile generic_ini(_config_file);
1372  ConfigIniFile private_ini(_private_file);
1373  ConfigIniFile secrets_ini(_secrets_file);
1374 
1375  if (!startup) ResetCurrencies(false); // Initialize the array of currencies, without preserving the custom one
1376 
1377  IniFileVersion generic_version = LoadVersionFromConfig(generic_ini);
1378 
1379  if (startup) {
1380  GraphicsSetLoadConfig(generic_ini);
1381  }
1382 
1383  /* Before the split of private/secrets, we have to look in the generic for these settings. */
1384  if (generic_version < IFV_PRIVATE_SECRETS) {
1385  HandleSettingDescs(generic_ini, generic_ini, generic_ini, IniLoadSettings, IniLoadSettingList, startup);
1386  } else {
1387  HandleSettingDescs(generic_ini, private_ini, secrets_ini, IniLoadSettings, IniLoadSettingList, startup);
1388  }
1389 
1390  /* Load basic settings only during bootstrap, load other settings not during bootstrap */
1391  if (!startup) {
1392  if (generic_version < IFV_LINKGRAPH_SECONDS) {
1395  }
1396 
1397  /* Move use_relay_service from generic_ini to private_ini. */
1398  if (generic_version < IFV_NETWORK_PRIVATE_SETTINGS) {
1399  const IniGroup *network = generic_ini.GetGroup("network");
1400  if (network != nullptr) {
1401  const IniItem *use_relay_service = network->GetItem("use_relay_service");
1402  if (use_relay_service != nullptr) {
1403  if (use_relay_service->value == "never") {
1404  _settings_client.network.use_relay_service = UseRelayService::URS_NEVER;
1405  } else if (use_relay_service->value == "ask") {
1406  _settings_client.network.use_relay_service = UseRelayService::URS_ASK;
1407  } else if (use_relay_service->value == "allow") {
1408  _settings_client.network.use_relay_service = UseRelayService::URS_ALLOW;
1409  }
1410  }
1411  }
1412  }
1413 
1414  const IniItem *old_item;
1415 
1416  if (generic_version < IFV_GAME_TYPE && IsConversionNeeded(generic_ini, "network", "server_advertise", "server_game_type", &old_item)) {
1417  auto old_value = BoolSettingDesc::ParseSingleValue(old_item->value->c_str());
1418  _settings_client.network.server_game_type = old_value.value_or(false) ? SERVER_GAME_TYPE_PUBLIC : SERVER_GAME_TYPE_LOCAL;
1419  }
1420 
1421  if (generic_version < IFV_AUTOSAVE_RENAME && IsConversionNeeded(generic_ini, "gui", "autosave", "autosave_interval", &old_item)) {
1422  static std::vector<std::string> _old_autosave_interval{"off", "monthly", "quarterly", "half year", "yearly"};
1423  auto old_value = OneOfManySettingDesc::ParseSingleValue(old_item->value->c_str(), old_item->value->size(), _old_autosave_interval);
1424 
1425  switch (old_value) {
1426  case 0: _settings_client.gui.autosave_interval = 0; break;
1427  case 1: _settings_client.gui.autosave_interval = 10; break;
1428  case 2: _settings_client.gui.autosave_interval = 30; break;
1429  case 3: _settings_client.gui.autosave_interval = 60; break;
1430  case 4: _settings_client.gui.autosave_interval = 120; break;
1431  default: break;
1432  }
1433  }
1434 
1435  /* Persist the right click close option from older versions. */
1436  if (generic_version < IFV_RIGHT_CLICK_CLOSE && IsConversionNeeded(generic_ini, "gui", "right_mouse_wnd_close", "right_click_wnd_close", &old_item)) {
1437  auto old_value = BoolSettingDesc::ParseSingleValue(old_item->value->c_str());
1438  _settings_client.gui.right_click_wnd_close = old_value.value_or(false) ? RCC_YES : RCC_NO;
1439  }
1440 
1441  _grfconfig_newgame = GRFLoadConfig(generic_ini, "newgrf", false);
1442  _grfconfig_static = GRFLoadConfig(generic_ini, "newgrf-static", true);
1443  AILoadConfig(generic_ini, "ai_players");
1444  GameLoadConfig(generic_ini, "game_scripts");
1445 
1447  IniLoadSettings(generic_ini, _old_gameopt_settings, "gameopt", &_settings_newgame, false);
1448  HandleOldDiffCustom(false);
1449 
1450  ValidateSettings();
1452 
1453  /* Display scheduled errors */
1455  if (FindWindowById(WC_ERRMSG, 0) == nullptr) ShowFirstError();
1456  }
1457 }
1458 
1461 {
1462  ConfigIniFile generic_ini(_config_file);
1463  ConfigIniFile private_ini(_private_file);
1464  ConfigIniFile secrets_ini(_secrets_file);
1465 
1466  IniFileVersion generic_version = LoadVersionFromConfig(generic_ini);
1467 
1468  /* If we newly create the private/secrets file, add a dummy group on top
1469  * just so we can add a comment before it (that is how IniFile works).
1470  * This to explain what the file is about. After doing it once, never touch
1471  * it again, as otherwise we might be reverting user changes. */
1472  if (IniGroup *group = private_ini.GetGroup("private"); group != nullptr) group->comment = "; This file possibly contains private information which can identify you as person.\n";
1473  if (IniGroup *group = secrets_ini.GetGroup("secrets"); group != nullptr) group->comment = "; Do not share this file with others, not even if they claim to be technical support.\n; This file contains saved passwords and other secrets that should remain private to you!\n";
1474 
1475  if (generic_version == IFV_0) {
1476  /* Remove some obsolete groups. These have all been loaded into other groups. */
1477  generic_ini.RemoveGroup("patches");
1478  generic_ini.RemoveGroup("yapf");
1479  generic_ini.RemoveGroup("gameopt");
1480 
1481  /* Remove all settings from the generic ini that are now in the private ini. */
1482  generic_ini.RemoveGroup("server_bind_addresses");
1483  generic_ini.RemoveGroup("servers");
1484  generic_ini.RemoveGroup("bans");
1485  for (auto &table : PrivateSettingTables()) {
1486  RemoveEntriesFromIni(generic_ini, table);
1487  }
1488 
1489  /* Remove all settings from the generic ini that are now in the secrets ini. */
1490  for (auto &table : SecretSettingTables()) {
1491  RemoveEntriesFromIni(generic_ini, table);
1492  }
1493  }
1494 
1495  if (generic_version < IFV_REMOVE_GENERATION_SEED) {
1496  IniGroup *game_creation = generic_ini.GetGroup("game_creation");
1497  if (game_creation != nullptr) {
1498  game_creation->RemoveItem("generation_seed");
1499  }
1500  }
1501 
1502  /* These variables are migrated from generic ini to private ini now. */
1503  if (generic_version < IFV_NETWORK_PRIVATE_SETTINGS) {
1504  IniGroup *network = generic_ini.GetGroup("network");
1505  if (network != nullptr) {
1506  network->RemoveItem("use_relay_service");
1507  }
1508  }
1509 
1510  HandleSettingDescs(generic_ini, private_ini, secrets_ini, IniSaveSettings, IniSaveSettingList);
1511  GraphicsSetSaveConfig(generic_ini);
1512  GRFSaveConfig(generic_ini, "newgrf", _grfconfig_newgame);
1513  GRFSaveConfig(generic_ini, "newgrf-static", _grfconfig_static);
1514  AISaveConfig(generic_ini, "ai_players");
1515  GameSaveConfig(generic_ini, "game_scripts");
1516 
1517  SaveVersionInConfig(generic_ini);
1518  SaveVersionInConfig(private_ini);
1519  SaveVersionInConfig(secrets_ini);
1520 
1521  generic_ini.SaveToDisk(_config_file);
1522  private_ini.SaveToDisk(_private_file);
1523  secrets_ini.SaveToDisk(_secrets_file);
1524 }
1525 
1531 {
1532  StringList list;
1533 
1535  for (const IniGroup &group : ini.groups) {
1536  if (group.name.compare(0, 7, "preset-") == 0) {
1537  list.push_back(group.name.substr(7));
1538  }
1539  }
1540 
1541  return list;
1542 }
1543 
1550 GRFConfig *LoadGRFPresetFromConfig(const char *config_name)
1551 {
1552  std::string section("preset-");
1553  section += config_name;
1554 
1556  GRFConfig *config = GRFLoadConfig(ini, section.c_str(), false);
1557 
1558  return config;
1559 }
1560 
1567 void SaveGRFPresetToConfig(const char *config_name, GRFConfig *config)
1568 {
1569  std::string section("preset-");
1570  section += config_name;
1571 
1573  GRFSaveConfig(ini, section.c_str(), config);
1574  ini.SaveToDisk(_config_file);
1575 }
1576 
1581 void DeleteGRFPresetFromConfig(const char *config_name)
1582 {
1583  std::string section("preset-");
1584  section += config_name;
1585 
1587  ini.RemoveGroup(section);
1588  ini.SaveToDisk(_config_file);
1589 }
1590 
1597 void IntSettingDesc::ChangeValue(const void *object, int32_t newval) const
1598 {
1599  int32_t oldval = this->Read(object);
1600  this->MakeValueValid(newval);
1601  if (this->pre_check != nullptr && !this->pre_check(newval)) return;
1602  if (oldval == newval) return;
1603 
1604  this->Write(object, newval);
1605  if (this->post_callback != nullptr) this->post_callback(newval);
1606 
1607  if (this->flags & SF_NO_NETWORK) {
1609  _gamelog.Setting(this->GetName(), oldval, newval);
1610  _gamelog.StopAction();
1611  }
1612 
1614 
1615  if (_save_config) SaveToConfig();
1616 }
1617 
1625 static const SettingDesc *GetSettingFromName(const std::string_view name, const SettingTable &settings)
1626 {
1627  /* First check all full names */
1628  for (auto &desc : settings) {
1629  const SettingDesc *sd = GetSettingDesc(desc);
1630  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
1631  if (sd->GetName() == name) return sd;
1632  }
1633 
1634  /* Then check the shortcut variant of the name. */
1635  std::string short_name_suffix = std::string{ "." }.append(name);
1636  for (auto &desc : settings) {
1637  const SettingDesc *sd = GetSettingDesc(desc);
1638  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
1639  if (sd->GetName().ends_with(short_name_suffix)) return sd;
1640  }
1641 
1642  return nullptr;
1643 }
1644 
1650 void GetSaveLoadFromSettingTable(SettingTable settings, std::vector<SaveLoad> &saveloads)
1651 {
1652  for (auto &desc : settings) {
1653  const SettingDesc *sd = GetSettingDesc(desc);
1654  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
1655  saveloads.push_back(sd->save);
1656  }
1657 }
1658 
1665 static const SettingDesc *GetCompanySettingFromName(std::string_view name)
1666 {
1667  static const std::string_view company_prefix = "company.";
1668  if (name.starts_with(company_prefix)) name.remove_prefix(company_prefix.size());
1669  return GetSettingFromName(name, _company_settings);
1670 }
1671 
1678 const SettingDesc *GetSettingFromName(const std::string_view name)
1679 {
1680  for (auto &table : GenericSettingTables()) {
1681  auto sd = GetSettingFromName(name, table);
1682  if (sd != nullptr) return sd;
1683  }
1684  for (auto &table : PrivateSettingTables()) {
1685  auto sd = GetSettingFromName(name, table);
1686  if (sd != nullptr) return sd;
1687  }
1688  for (auto &table : SecretSettingTables()) {
1689  auto sd = GetSettingFromName(name, table);
1690  if (sd != nullptr) return sd;
1691  }
1692 
1693  return GetCompanySettingFromName(name);
1694 }
1695 
1705 CommandCost CmdChangeSetting(DoCommandFlag flags, const std::string &name, int32_t value)
1706 {
1707  if (name.empty()) return CMD_ERROR;
1708  const SettingDesc *sd = GetSettingFromName(name);
1709 
1710  if (sd == nullptr) return CMD_ERROR;
1712  if (!sd->IsIntSetting()) return CMD_ERROR;
1713 
1714  if (!sd->IsEditable(true)) return CMD_ERROR;
1715 
1716  if (flags & DC_EXEC) {
1717  sd->AsIntSetting()->ChangeValue(&GetGameSettings(), value);
1718  }
1719 
1720  return CommandCost();
1721 }
1722 
1731 CommandCost CmdChangeCompanySetting(DoCommandFlag flags, const std::string &name, int32_t value)
1732 {
1733  if (name.empty()) return CMD_ERROR;
1734  const SettingDesc *sd = GetCompanySettingFromName(name);
1735 
1736  if (sd == nullptr) return CMD_ERROR;
1737  if (!sd->IsIntSetting()) return CMD_ERROR;
1738 
1739  if (flags & DC_EXEC) {
1741  }
1742 
1743  return CommandCost();
1744 }
1745 
1753 bool SetSettingValue(const IntSettingDesc *sd, int32_t value, bool force_newgame)
1754 {
1755  const IntSettingDesc *setting = sd->AsIntSetting();
1756  if ((setting->flags & SF_PER_COMPANY) != 0) {
1757  if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) {
1758  return Command<CMD_CHANGE_COMPANY_SETTING>::Post(setting->GetName(), value);
1759  }
1760 
1761  setting->ChangeValue(&_settings_client.company, value);
1762  return true;
1763  }
1764 
1765  /* If an item is company-based, we do not send it over the network
1766  * (if any) to change. Also *hack*hack* we update the _newgame version
1767  * of settings because changing a company-based setting in a game also
1768  * changes its defaults. At least that is the convention we have chosen */
1769  if (setting->flags & SF_NO_NETWORK_SYNC) {
1770  if (_game_mode != GM_MENU) {
1771  setting->ChangeValue(&_settings_newgame, value);
1772  }
1773  setting->ChangeValue(&GetGameSettings(), value);
1774  return true;
1775  }
1776 
1777  if (force_newgame) {
1778  setting->ChangeValue(&_settings_newgame, value);
1779  return true;
1780  }
1781 
1782  /* send non-company-based settings over the network */
1783  if (!_networking || (_networking && _network_server)) {
1784  return Command<CMD_CHANGE_SETTING>::Post(setting->GetName(), value);
1785  }
1786  return false;
1787 }
1788 
1793 {
1794  Company *c = Company::Get(cid);
1795  for (auto &desc : _company_settings) {
1796  const IntSettingDesc *int_setting = GetSettingDesc(desc)->AsIntSetting();
1797  int_setting->MakeValueValidAndWrite(&c->settings, int_setting->def);
1798  }
1799 }
1800 
1805 {
1806  const void *old_object = &Company::Get(_current_company)->settings;
1807  const void *new_object = &_settings_client.company;
1808  for (auto &desc : _company_settings) {
1809  const SettingDesc *sd = GetSettingDesc(desc);
1810  uint32_t old_value = (uint32_t)sd->AsIntSetting()->Read(old_object);
1811  uint32_t new_value = (uint32_t)sd->AsIntSetting()->Read(new_object);
1812  if (old_value != new_value) Command<CMD_CHANGE_COMPANY_SETTING>::SendNet(STR_NULL, _local_company, sd->GetName(), new_value);
1813  }
1814 }
1815 
1823 bool SetSettingValue(const StringSettingDesc *sd, std::string value, bool force_newgame)
1824 {
1825  assert(sd->flags & SF_NO_NETWORK_SYNC);
1826 
1827  if (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ && value.compare("(null)") == 0) {
1828  value.clear();
1829  }
1830 
1831  const void *object = (_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game;
1832  sd->AsStringSetting()->ChangeValue(object, value);
1833  return true;
1834 }
1835 
1842 void StringSettingDesc::ChangeValue(const void *object, std::string &newval) const
1843 {
1844  this->MakeValueValid(newval);
1845  if (this->pre_check != nullptr && !this->pre_check(newval)) return;
1846 
1847  this->Write(object, newval);
1848  if (this->post_callback != nullptr) this->post_callback(newval);
1849 
1850  if (_save_config) SaveToConfig();
1851 }
1852 
1853 /* Those 2 functions need to be here, else we have to make some stuff non-static
1854  * and besides, it is also better to keep stuff like this at the same place */
1855 void IConsoleSetSetting(const char *name, const char *value, bool force_newgame)
1856 {
1857  const SettingDesc *sd = GetSettingFromName(name);
1858  if (sd == nullptr) {
1859  IConsolePrint(CC_ERROR, "'{}' is an unknown setting.", name);
1860  return;
1861  }
1862 
1863  bool success = true;
1864  if (sd->IsStringSetting()) {
1865  success = SetSettingValue(sd->AsStringSetting(), value, force_newgame);
1866  } else if (sd->IsIntSetting()) {
1867  const IntSettingDesc *isd = sd->AsIntSetting();
1868  size_t val = isd->ParseValue(value);
1869  if (!_settings_error_list.empty()) {
1870  IConsolePrint(CC_ERROR, "'{}' is not a valid value for this setting.", value);
1871  _settings_error_list.clear();
1872  return;
1873  }
1874  success = SetSettingValue(isd, (int32_t)val, force_newgame);
1875  }
1876 
1877  if (!success) {
1878  if (_network_server) {
1879  IConsolePrint(CC_ERROR, "This command/variable is not available during network games.");
1880  } else {
1881  IConsolePrint(CC_ERROR, "This command/variable is only available to a network server.");
1882  }
1883  }
1884 }
1885 
1886 void IConsoleSetSetting(const char *name, int value)
1887 {
1888  const SettingDesc *sd = GetSettingFromName(name);
1889  assert(sd != nullptr);
1890  SetSettingValue(sd->AsIntSetting(), value);
1891 }
1892 
1898 void IConsoleGetSetting(const char *name, bool force_newgame)
1899 {
1900  const SettingDesc *sd = GetSettingFromName(name);
1901  if (sd == nullptr) {
1902  IConsolePrint(CC_ERROR, "'{}' is an unknown setting.", name);
1903  return;
1904  }
1905 
1906  const void *object = (_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game;
1907 
1908  if (sd->IsStringSetting()) {
1909  IConsolePrint(CC_INFO, "Current value for '{}' is '{}'.", sd->GetName(), sd->AsStringSetting()->Read(object));
1910  } else if (sd->IsIntSetting()) {
1911  std::string value = sd->FormatValue(object);
1912  const IntSettingDesc *int_setting = sd->AsIntSetting();
1913  IConsolePrint(CC_INFO, "Current value for '{}' is '{}' (min: {}{}, max: {}).",
1914  sd->GetName(), value, (sd->flags & SF_GUI_0_IS_SPECIAL) ? "(0) " : "", int_setting->min, int_setting->max);
1915  }
1916 }
1917 
1918 static void IConsoleListSettingsTable(const SettingTable &table, const char *prefilter)
1919 {
1920  for (auto &desc : table) {
1921  const SettingDesc *sd = GetSettingDesc(desc);
1922  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
1923  if (prefilter != nullptr && sd->GetName().find(prefilter) == std::string::npos) continue;
1924  IConsolePrint(CC_DEFAULT, "{} = {}", sd->GetName(), sd->FormatValue(&GetGameSettings()));
1925  }
1926 }
1927 
1933 void IConsoleListSettings(const char *prefilter)
1934 {
1935  IConsolePrint(CC_HELP, "All settings with their current value:");
1936 
1937  for (auto &table : GenericSettingTables()) {
1938  IConsoleListSettingsTable(table, prefilter);
1939  }
1940  for (auto &table : PrivateSettingTables()) {
1941  IConsoleListSettingsTable(table, prefilter);
1942  }
1943  for (auto &table : SecretSettingTables()) {
1944  IConsoleListSettingsTable(table, prefilter);
1945  }
1946 
1947  IConsolePrint(CC_HELP, "Use 'setting' command to change a value.");
1948 }
IFV_NETWORK_PRIVATE_SETTINGS
@ IFV_NETWORK_PRIVATE_SETTINGS
4 PR#10762 Move use_relay_service to private settings.
Definition: settings.cpp:161
ShowFirstError
void ShowFirstError()
Show the first error of the queue.
Definition: error_gui.cpp:335
SaveLoad::version_to
SaveLoadVersion version_to
Save/load the variable before this savegame version.
Definition: saveload.h:703
IniFileVersion
IniFileVersion
Ini-file versions.
Definition: settings.cpp:156
CC_INFO
static const TextColour CC_INFO
Colour for information lines.
Definition: console_type.h:27
SetSettingValue
bool SetSettingValue(const IntSettingDesc *sd, int32_t value, bool force_newgame)
Top function to save the new value of an element of the Settings struct.
Definition: settings.cpp:1753
FormatArrayAsHex
std::string FormatArrayAsHex(std::span< const byte > data)
Format a byte array into a continuous hex string.
Definition: string.cpp:88
ClientSettings
All settings that are only important for the local client.
Definition: settings_type.h:634
AIConfig
Definition: ai_config.hpp:16
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:339
StringSettingDesc::MakeValueValid
void MakeValueValid(std::string &str) const
Make the value valid given the limitations of this setting.
Definition: settings.cpp:590
RemoveEntriesFromIni
static void RemoveEntriesFromIni(IniFile &ini, const SettingTable &table)
Remove all entries from a settings table from an ini-file.
Definition: settings.cpp:1300
SLE_VAR_STR
@ SLE_VAR_STR
string pointer
Definition: saveload.h:636
SF_SCENEDIT_TOO
@ SF_SCENEDIT_TOO
This setting can be changed in the scenario editor (only makes sense when SF_NEWGAME_ONLY is set).
Definition: settings_internal.h:24
command_func.h
IniItem::SetValue
void SetValue(const std::string_view value)
Replace the current value with another value.
Definition: ini_load.cpp:32
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
Definition: error_gui.cpp:367
StringSettingDesc::pre_check
PreChangeCheck * pre_check
Callback to check for the validity of the setting.
Definition: settings_internal.h:331
ErrorMessageData::SetDParamStr
void SetDParamStr(uint n, const char *str)
Set a rawstring parameter.
Definition: error_gui.cpp:146
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:28
GetSettingFromName
static const SettingDesc * GetSettingFromName(const std::string_view name, const SettingTable &settings)
Given a name of setting, return a setting description from the table.
Definition: settings.cpp:1625
GraphicsSetLoadConfig
static void GraphicsSetLoadConfig(IniFile &ini)
Load BaseGraphics set selection and configuration.
Definition: settings.cpp:1012
ScheduleErrorMessage
void ScheduleErrorMessage(ErrorList &datas)
Schedule a list of errors.
Definition: error_gui.cpp:452
ValidateSettings
static void ValidateSettings()
Checks if any settings are set to incorrect values, and sets them to correct values in that case.
Definition: settings.cpp:947
SetDefaultCompanySettings
void SetDefaultCompanySettings(CompanyID cid)
Set the company settings for a new company to their default values.
Definition: settings.cpp:1792
CmdChangeSetting
CommandCost CmdChangeSetting(DoCommandFlag flags, const std::string &name, int32_t value)
Network-safe changing of settings (server-only).
Definition: settings.cpp:1705
StringSettingDesc::IsSameValue
bool IsSameValue(const IniItem *item, void *object) const override
Check whether the value in the Ini item is the same as is saved in this setting in the object.
Definition: settings.cpp:792
BaseSet::shortname
uint32_t shortname
Four letter short variant of the name.
Definition: base_media_base.h:64
CUSTOM_SEA_LEVEL_MIN_PERCENTAGE
static const uint CUSTOM_SEA_LEVEL_MIN_PERCENTAGE
Minimum percentage a user can specify for custom sea level.
Definition: genworld.h:48
IniLoadWindowSettings
void IniLoadWindowSettings(IniFile &ini, const char *grpname, void *desc)
Load a WindowDesc from config.
Definition: settings.cpp:878
BaseGraphics::Ini::shortname
uint32_t shortname
unique key for base set
Definition: base_media_base.h:285
_gamelog
Gamelog _gamelog
Gamelog instance.
Definition: gamelog.cpp:31
GRFLoadConfig
static GRFConfig * GRFLoadConfig(const IniFile &ini, const char *grpname, bool is_static)
Load a GRF configuration.
Definition: settings.cpp:1049
currency.h
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
ST_GAME
@ ST_GAME
Game setting.
Definition: settings_internal.h:61
_network_server
bool _network_server
network-server is active
Definition: network.cpp:60
BaseSet::name
std::string name
The name of the base set.
Definition: base_media_base.h:61
IniItem
A single "line" in an ini file.
Definition: ini_type.h:23
SettingDesc::save
SaveLoad save
Internal structure (going to savegame, parts to config).
Definition: settings_internal.h:78
SettingDesc::GetType
SettingType GetType() const
Return the type of the setting.
Definition: settings.cpp:916
SaveToConfig
void SaveToConfig()
Save the values to the configuration file.
Definition: settings.cpp:1460
PrepareOldDiffCustom
void PrepareOldDiffCustom()
Prepare for reading and old diff_custom by zero-ing the memory.
Definition: settings_sl.cpp:25
_old_vds
VehicleDefaultSettings _old_vds
Used for loading default vehicles settings from old savegames.
Definition: settings.cpp:57
IniGroup::GetItem
const IniItem * GetItem(const std::string &name) const
Get the item with the given name.
Definition: ini_load.cpp:52
SettingDesc::IsEditable
bool IsEditable(bool do_command=false) const
Check whether the setting is editable in the current gamemode.
Definition: settings.cpp:899
IniGroup
A group within an ini file.
Definition: ini_type.h:34
SF_SCENEDIT_ONLY
@ SF_SCENEDIT_ONLY
This setting can only be changed in the scenario editor.
Definition: settings_internal.h:25
ST_CLIENT
@ ST_CLIENT
Client setting.
Definition: settings_internal.h:63
LG_ORIGINAL
@ LG_ORIGINAL
The original landscape generator.
Definition: genworld.h:20
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1099
HandleOldDiffCustom
void HandleOldDiffCustom(bool savegame)
Reading of the old diff_custom array and transforming it to the new format.
Definition: settings_sl.cpp:36
GameSettings::difficulty
DifficultySettings difficulty
settings related to the difficulty
Definition: settings_type.h:617
ErrorList
std::list< ErrorMessageData > ErrorList
Define a queue with errors.
Definition: error.h:62
StrMakeValid
static void StrMakeValid(T &dst, const char *str, const char *last, StringValidationSettings settings)
Copies the valid (UTF-8) characters from str up to last to the dst.
Definition: string.cpp:114
GRFConfig::filename
std::string filename
Filename - either with or without full path.
Definition: newgrf_config.h:156
IniGroup::RemoveItem
void RemoveItem(const std::string &name)
Remove the item with the given name.
Definition: ini_load.cpp:90
SLE_VAR_NULL
@ SLE_VAR_NULL
useful to write zeros in savegame.
Definition: saveload.h:635
LookupManyOfMany
static size_t LookupManyOfMany(const std::vector< std::string > &many, const char *str)
Find the set-integer value MANYofMANY type in a string.
Definition: settings.cpp:214
fileio_func.h
ST_COMPANY
@ ST_COMPANY
Company setting.
Definition: settings_internal.h:62
GCS_NOT_FOUND
@ GCS_NOT_FOUND
GRF file was not found in the local cache.
Definition: newgrf_config.h:37
base_media_base.h
GRFConfig::ident
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
Definition: newgrf_config.h:154
BoolSettingDesc::FormatValue
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
Definition: settings.cpp:752
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
_network_bind_list
StringList _network_bind_list
The addresses to bind on.
Definition: network.cpp:68
IniLoadFile::GetOrCreateGroup
IniGroup & GetOrCreateGroup(const std::string &name)
Get the group with the given name, and if it doesn't exist create a new group.
Definition: ini_load.cpp:147
StringSettingDesc::Read
const std::string & Read(const void *object) const
Read the string from the the actual setting.
Definition: settings.cpp:616
GRFConfig::status
GRFStatus status
NOSAVE: GRFStatus, enum.
Definition: newgrf_config.h:165
IniGroup::items
std::list< IniItem > items
all items in the group
Definition: ini_type.h:35
ClampU
constexpr uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
Definition: math_func.hpp:150
StringSettingDesc::post_callback
PostChangeCallback * post_callback
Callback when the setting has been changed.
Definition: settings_internal.h:332
ConvertHexToBytes
bool ConvertHexToBytes(std::string_view hex, std::span< uint8_t > bytes)
Convert a hex-string to a byte-array, while validating it was actually hex.
Definition: string.cpp:730
ListSettingDesc::ResetToDefault
void ResetToDefault(void *object) const override
Reset the setting to its default value.
Definition: settings.cpp:825
SettingDesc::flags
SettingFlag flags
Handles how a setting would show up in the GUI (text/currency, etc.).
Definition: settings_internal.h:76
IFV_GAME_TYPE
@ IFV_GAME_TYPE
2 PR#9515 Convert server_advertise to server_game_type.
Definition: settings.cpp:159
SaveLoad::conv
VarType conv
Type of the variable to be saved; this field combines both FileVarType and MemVarType.
Definition: saveload.h:700
NetworkSettings::use_relay_service
UseRelayService use_relay_service
Use relay service?
Definition: settings_type.h:333
_private_file
std::string _private_file
Private configuration file of OpenTTD.
Definition: settings.cpp:59
newgrf_config.h
gamelog.h
fios.h
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:371
SettingDesc::IsSameValue
virtual bool IsSameValue(const IniItem *item, void *object) const =0
Check whether the value in the Ini item is the same as is saved in this setting in the object.
StringSettingDesc::FormatValue
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
Definition: settings.cpp:776
IntSettingDesc::pre_check
PreChangeCheck * pre_check
Callback to check for the validity of the setting.
Definition: settings_internal.h:219
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:369
genworld.h
SettingDesc::AsStringSetting
const struct StringSettingDesc * AsStringSetting() const
Get the setting description of this setting as a string setting.
Definition: settings.cpp:936
CC_DEFAULT
static const TextColour CC_DEFAULT
Default colour of the console.
Definition: console_type.h:23
ManyOfManySettingDesc::ParseValue
size_t ParseValue(const char *str) const override
Convert a string representation (external) of an integer-like setting to an integer.
Definition: settings.cpp:429
ConfigIniFile
IniFile to store a configuration.
Definition: settings.cpp:133
IniGroup::Clear
void Clear()
Clear all items in the group.
Definition: ini_load.cpp:98
Debug
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:618
GCF_INVALID
@ GCF_INVALID
GRF is unusable with this version of OpenTTD.
Definition: newgrf_config.h:30
LinkGraphSettings::recalc_interval
uint16_t recalc_interval
time (in days) between subsequent checks for link graphs to be calculated.
Definition: settings_type.h:568
ScriptConfig::Change
void Change(std::optional< const std::string > name, int version=-1, bool force_exact_match=false)
Set another Script to be loaded in this slot.
Definition: script_config.cpp:21
ReadValue
int64_t ReadValue(const void *ptr, VarType conv)
Return a signed-long version of the value of a setting.
Definition: saveload.cpp:791
IniSaveSettings
static void IniSaveSettings(IniFile &ini, const SettingTable &settings_table, const char *grpname, void *object, bool)
Save the values of settings to the inifile.
Definition: settings.cpp:710
SettingDesc::ParseValue
virtual void ParseValue(const IniItem *item, void *object) const =0
Parse/read the value from the Ini item into the setting associated with this object.
StringSettingDesc
String settings.
Definition: settings_internal.h:308
ListSettingDesc::ParseValue
void ParseValue(const IniItem *item, void *object) const override
Parse/read the value from the Ini item into the setting associated with this object.
Definition: settings.cpp:684
COMPANY_FIRST
@ COMPANY_FIRST
First company, same as owner.
Definition: company_type.h:22
SettingType
SettingType
Type of settings for filtering.
Definition: settings_internal.h:60
NETWORK_MAX_GRF_COUNT
static const uint NETWORK_MAX_GRF_COUNT
Maximum number of GRFs that can be sent.
Definition: config.h:92
IniLoadFile::RemoveGroup
void RemoveGroup(const std::string &name)
Remove the group with the given name.
Definition: ini_load.cpp:175
StringSettingDesc::ChangeValue
void ChangeValue(const void *object, std::string &newval) const
Handle changing a string value.
Definition: settings.cpp:1842
GetGRFPresetList
StringList GetGRFPresetList()
Get the list of known NewGrf presets.
Definition: settings.cpp:1530
GRFConfig::version
uint32_t version
NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown.
Definition: newgrf_config.h:162
GetVarMemType
constexpr VarType GetVarMemType(VarType type)
Get the NumberType of a setting.
Definition: saveload.h:732
SF_GUI_0_IS_SPECIAL
@ SF_GUI_0_IS_SPECIAL
A value of zero is possible and has a custom string (the one after "strval").
Definition: settings_internal.h:18
GLAT_SETTING
@ GLAT_SETTING
Setting changed.
Definition: gamelog.h:21
IFV_0
@ IFV_0
0 All versions prior to introduction.
Definition: settings.cpp:157
Gamelog::Setting
void Setting(const std::string &name, int32_t oldval, int32_t newval)
Logs change in game settings.
Definition: gamelog.cpp:413
IntSettingDesc::str_val
StringID str_val
(Translated) first string describing the value.
Definition: settings_internal.h:217
IntSettingDesc::MakeValueValidAndWrite
void MakeValueValidAndWrite(const void *object, int32_t value) const
Make the value valid and then write it to the setting.
Definition: settings.cpp:498
CommandCost
Common return value for all commands.
Definition: command_type.h:23
BSWAP32
static uint32_t BSWAP32(uint32_t x)
Perform a 32 bits endianness bitswap on x.
Definition: bitmath_func.hpp:345
SetBitIterator
Iterable ensemble of each set bit in a value.
Definition: bitmath_func.hpp:282
settings_func.h
GCF_UNSAFE
@ GCF_UNSAFE
GRF file is unsafe for static usage.
Definition: newgrf_config.h:24
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:147
CC_HELP
static const TextColour CC_HELP
Colour for help lines.
Definition: console_type.h:26
IntSettingDesc::MakeValueValid
void MakeValueValid(int32_t &value) const
Make the value valid given the limitations of this setting.
Definition: settings.cpp:513
BaseGraphics::Ini::extra_params
std::vector< uint32_t > extra_params
parameters for the extra GRF
Definition: base_media_base.h:287
SettingDesc::startup
bool startup
Setting has to be loaded directly at startup?.
Definition: settings_internal.h:77
GCF_SYSTEM
@ GCF_SYSTEM
GRF file is an openttd-internal system grf.
Definition: newgrf_config.h:23
IntSettingDesc
Base integer type, including boolean, settings.
Definition: settings_internal.h:148
IniGroup::GetOrCreateItem
IniItem & GetOrCreateItem(const std::string &name)
Get the item with the given name, and if it doesn't exist create a new item.
Definition: ini_load.cpp:66
SettingDesc::GetName
constexpr const std::string & GetName() const
Get the name of this setting.
Definition: settings_internal.h:87
IniItem::value
std::optional< std::string > value
The value of this item.
Definition: ini_type.h:25
IFV_LINKGRAPH_SECONDS
@ IFV_LINKGRAPH_SECONDS
3 PR#10610 Store linkgraph update intervals in seconds instead of days.
Definition: settings.cpp:160
GRFIdentifier::md5sum
MD5Hash md5sum
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF)
Definition: newgrf_config.h:85
GameConfig
Definition: game_config.hpp:15
SF_NETWORK_ONLY
@ SF_NETWORK_ONLY
This setting only applies to network games.
Definition: settings_internal.h:21
IniLoadSettingList
static void IniLoadSettingList(IniFile &ini, const char *grpname, StringList &list)
Loads all items from a 'grpname' section into a list The list parameter can be a nullptr pointer,...
Definition: settings.cpp:840
StringSettingDesc::ResetToDefault
void ResetToDefault(void *object) const override
Reset the setting to its default value.
Definition: settings.cpp:808
IniFile::SaveToDisk
bool SaveToDisk(const std::string &filename)
Save the Ini file's data to the disk.
Definition: ini.cpp:46
SettingDesc::FormatValue
virtual std::string FormatValue(const void *object) const =0
Format the value of the setting associated with this object.
IntSettingDesc::def
int32_t def
default value given when none is present
Definition: settings_internal.h:211
AIConfig::GetConfig
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Definition: ai_config.cpp:20
SecretSettingTables
static auto & SecretSettingTables()
List of all the secrets setting tables.
Definition: settings.cpp:107
CmdChangeCompanySetting
CommandCost CmdChangeCompanySetting(DoCommandFlag flags, const std::string &name, int32_t value)
Change one of the per-company settings.
Definition: settings.cpp:1731
StringSettingDesc::ParseValue
void ParseValue(const IniItem *item, void *object) const override
Parse/read the value from the Ini item into the setting associated with this object.
Definition: settings.cpp:677
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:55
CompanyProperties::settings
CompanySettings settings
settings specific for each company
Definition: company_base.h:118
GetVariableAddress
void * GetVariableAddress(const void *object, const SaveLoad &sld)
Get the address of the variable.
Definition: saveload.h:1253
IntSettingDesc::min
int32_t min
minimum values
Definition: settings_internal.h:212
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:50
StringList
std::vector< std::string > StringList
Type for a list of strings.
Definition: string_type.h:60
SyncCompanySettings
void SyncCompanySettings()
Sync all company settings in a multiplayer game.
Definition: settings.cpp:1804
IntSettingDesc::Write
void Write(const void *object, int32_t value) const
Set the value of a setting.
Definition: settings.cpp:566
safeguards.h
SF_NO_NETWORK_SYNC
@ SF_NO_NETWORK_SYNC
Do not synchronize over network (but it is saved if SF_NOT_IN_SAVE is not set).
Definition: settings_internal.h:29
IniLoadSettings
static void IniLoadSettings(IniFile &ini, const SettingTable &settings_table, const char *grpname, void *object, bool only_startup)
Load values from a group of an IniFile structure into the internal representation.
Definition: settings.cpp:630
ScriptConfig::StringToSettings
void StringToSettings(const std::string &value)
Convert a string which is stored in the config file or savegames to custom settings of this Script.
Definition: script_config.cpp:141
DifficultySettings::quantity_sea_lakes
byte quantity_sea_lakes
the amount of seas/lakes
Definition: settings_type.h:112
settings
fluid_settings_t * settings
FluidSynth settings handle.
Definition: fluidsynth.cpp:21
GameSettings
All settings together for the game.
Definition: settings_type.h:616
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:59
OneOfManySettingDesc::many_cnvt
OnConvert * many_cnvt
callback procedure when loading value mechanism fails
Definition: settings_internal.h:284
GetSettingDesc
static constexpr const SettingDesc * GetSettingDesc(const SettingVariant &desc)
Helper to convert the type of the iterated settings description to a pointer to it.
Definition: settings_internal.h:382
DeleteGRFPresetFromConfig
void DeleteGRFPresetFromConfig(const char *config_name)
Delete a NewGRF configuration by preset name.
Definition: settings.cpp:1581
IniLoadFile::GetGroup
const IniGroup * GetGroup(const std::string &name) const
Get the group with the given name.
Definition: ini_load.cpp:119
ErrorMessageData
The data of the error message.
Definition: error.h:31
VehicleDefaultSettings
Default settings for vehicles.
Definition: settings_type.h:598
error.h
IntSettingDesc::ChangeValue
void ChangeValue(const void *object, int32_t newvalue) const
Handle changing a value.
Definition: settings.cpp:1597
GameSettings::linkgraph
LinkGraphSettings linkgraph
settings for link graph calculations
Definition: settings_type.h:628
IFV_AUTOSAVE_RENAME
@ IFV_AUTOSAVE_RENAME
5 PR#11143 Renamed values of autosave to be in minutes.
Definition: settings.cpp:163
ResetCurrencies
void ResetCurrencies(bool preserve_custom)
Will fill _currency_specs array with default values from origin_currency_specs Called only from newgr...
Definition: currency.cpp:159
OneOfManySettingDesc::FormatValue
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
Definition: settings.cpp:369
IniSaveSettingList
static void IniSaveSettingList(IniFile &ini, const char *grpname, StringList &list)
Saves all items from a list into the 'grpname' section The list parameter can be a nullptr pointer,...
Definition: settings.cpp:862
stdafx.h
settings_table.h
IntSettingDesc::GetHelp
StringID GetHelp() const
Get the help text of the setting.
Definition: settings.cpp:466
NEWGRF_DIR
@ NEWGRF_DIR
Subdirectory for all NewGRFs.
Definition: fileio_type.h:117
_grfconfig_static
GRFConfig * _grfconfig_static
First item in list of static GRF set up.
Definition: newgrf_config.cpp:166
ParseIntList
static int ParseIntList(const char *p, T *items, size_t maxitems)
Parse an integerlist string and set each found value.
Definition: settings.cpp:247
ManyOfManySettingDesc::FormatValue
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
Definition: settings.cpp:375
LoadGRFPresetFromConfig
GRFConfig * LoadGRFPresetFromConfig(const char *config_name)
Load a NewGRF configuration by preset-name.
Definition: settings.cpp:1550
IntSettingDesc::ResetToDefault
void ResetToDefault(void *object) const override
Reset the setting to its default value.
Definition: settings.cpp:771
OneOfManySettingDesc::ParseValue
size_t ParseValue(const char *str) const override
Convert a string representation (external) of an integer-like setting to an integer.
Definition: settings.cpp:414
SettingDesc::IsStringSetting
virtual bool IsStringSetting() const
Check whether this setting is an string type setting.
Definition: settings_internal.h:102
OneOfManySettingDesc::many
std::vector< std::string > many
possible values for this type
Definition: settings_internal.h:283
SlIsObjectCurrentlyValid
bool SlIsObjectCurrentlyValid(SaveLoadVersion version_from, SaveLoadVersion version_to)
Checks if some version from/to combination falls within the range of the active savegame version.
Definition: saveload.h:1242
_secrets_file
std::string _secrets_file
Secrets configuration file of OpenTTD.
Definition: settings.cpp:60
GenericSettingTables
static auto & GenericSettingTables()
List of all the generic setting tables.
Definition: settings.cpp:74
BoolSettingDesc::ParseValue
size_t ParseValue(const char *str) const override
Convert a string representation (external) of an integer-like setting to an integer.
Definition: settings.cpp:440
Gamelog::StartAction
void StartAction(GamelogActionType at)
Stores information about new action, but doesn't allocate it Action is allocated only when there is a...
Definition: gamelog.cpp:65
Gamelog::StopAction
void StopAction()
Stops logging of any changes.
Definition: gamelog.cpp:74
BoolSettingDesc::ParseSingleValue
static std::optional< bool > ParseSingleValue(const char *str)
Find whether a string was a boolean true or a boolean false.
Definition: settings.cpp:199
IntSettingDesc::str_help
StringID str_help
(Translated) string with help text; gui only.
Definition: settings_internal.h:216
NetworkSettings::server_game_type
ServerGameType server_game_type
Server type: local / public / invite-only.
Definition: settings_type.h:311
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:51
rev.h
WC_GAME_OPTIONS
@ WC_GAME_OPTIONS
Game options window; Window numbers:
Definition: window_type.h:619
GRFConfig::flags
uint8_t flags
NOSAVE: GCF_Flags, bitset.
Definition: newgrf_config.h:164
IntSettingDesc::GetTitle
StringID GetTitle() const
Get the title of the setting.
Definition: settings.cpp:457
IConsoleListSettings
void IConsoleListSettings(const char *prefilter)
List all settings and their value to the console.
Definition: settings.cpp:1933
IniGroup::comment
std::string comment
comment for group
Definition: ini_type.h:38
FioCheckFileExists
bool FioCheckFileExists(const std::string &filename, Subdirectory subdir)
Check whether the given file exists.
Definition: fileio.cpp:126
IniGroup::name
std::string name
name of group
Definition: ini_type.h:37
IniFile
Ini file that supports both loading and saving.
Definition: ini_type.h:88
GRFConfig::param
std::array< uint32_t, 0x80 > param
GRF parameters.
Definition: newgrf_config.h:167
IntSettingDesc::IsSameValue
bool IsSameValue(const IniItem *item, void *object) const override
Check whether the value in the Ini item is the same as is saved in this setting in the object.
Definition: settings.cpp:758
SF_NO_NETWORK
@ SF_NO_NETWORK
This setting does not apply to network games; it may not be changed during the game.
Definition: settings_internal.h:22
SettingDesc
Properties of config file settings.
Definition: settings_internal.h:71
BaseGraphics::Ini::extra_version
uint32_t extra_version
version of the extra GRF
Definition: base_media_base.h:286
PrivateSettingTables
static auto & PrivateSettingTables()
List of all the private setting tables.
Definition: settings.cpp:96
GameCreationSettings::land_generator
byte land_generator
the landscape generator
Definition: settings_type.h:344
GRFBuildParamList
std::string GRFBuildParamList(const GRFConfig *c)
Build a string containing space separated parameter values, and terminate.
Definition: newgrf_config.cpp:729
NO_DIRECTORY
@ NO_DIRECTORY
A path without any base directory.
Definition: fileio_type.h:126
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
GUISettings::autosave_interval
uint32_t autosave_interval
how often should we do autosaves?
Definition: settings_type.h:160
GraphicsSetSaveConfig
static void GraphicsSetSaveConfig(IniFile &ini)
Save BaseGraphics set selection and configuration.
Definition: settings.cpp:1229
IntSettingDesc::max
uint32_t max
maximum values
Definition: settings_internal.h:213
SF_NEWGAME_ONLY
@ SF_NEWGAME_ONLY
This setting cannot be changed in a game.
Definition: settings_internal.h:23
ScriptConfig::SettingsToString
std::string SettingsToString() const
Convert the custom settings to a string that can be stored in the config file or savegames.
Definition: script_config.cpp:163
IntSettingDesc::str
StringID str
(translated) string with descriptive text; gui and console
Definition: settings_internal.h:215
GRFConfig::next
struct GRFConfig * next
NOSAVE: Next item in the linked list.
Definition: newgrf_config.h:174
IniGroup::CreateItem
IniItem & CreateItem(const std::string &name)
Create an item with the given name.
Definition: ini_load.cpp:81
GameConfig::GetConfig
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Definition: game_config.cpp:18
IntSettingDesc::Read
int32_t Read(const void *object) const
Read the integer from the the actual setting.
Definition: settings.cpp:577
IniSaveWindowSettings
void IniSaveWindowSettings(IniFile &ini, const char *grpname, void *desc)
Save a WindowDesc to config.
Definition: settings.cpp:889
ListSettingDesc::def
const char * def
default value given when none is present
Definition: settings_internal.h:354
ScriptConfig::SSS_FORCE_NEWGAME
@ SSS_FORCE_NEWGAME
Get the newgame Script config.
Definition: script_config.hpp:96
FGCM_NEWEST_VALID
@ FGCM_NEWEST_VALID
Find newest Grf, ignoring Grfs with GCF_INVALID set.
Definition: newgrf_config.h:195
IntSettingDesc::IsBoolSetting
virtual bool IsBoolSetting() const
Check whether this setting is a boolean type setting.
Definition: settings_internal.h:233
IFV_REMOVE_GENERATION_SEED
@ IFV_REMOVE_GENERATION_SEED
7 PR#11927 Remove "generation_seed" from configuration.
Definition: settings.cpp:165
settings_cmd.h
IniFile::IniFile
IniFile(const IniGroupNameList &list_group_names={})
Create a new ini file with given group names.
Definition: ini.cpp:37
StringSettingDesc::max_length
uint32_t max_length
Maximum length of the string, 0 means no maximum length.
Definition: settings_internal.h:330
SetDParamStr
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:352
SaveLoad::version_from
SaveLoadVersion version_from
Save/load the variable starting from this savegame version.
Definition: saveload.h:702
IntSettingDesc::SetValueDParams
void SetValueDParams(uint first_param, int32_t value) const
Set the DParams for drawing the value of the setting.
Definition: settings.cpp:476
company_func.h
CC_ERROR
static const TextColour CC_ERROR
Colour for error lines.
Definition: console_type.h:24
SLE_VAR_STRQ
@ SLE_VAR_STRQ
string pointer enclosed in quotes
Definition: saveload.h:637
IntSettingDesc::FormatValue
std::string FormatValue(const void *object) const override
Format the value of the setting associated with this object.
Definition: settings.cpp:741
ListSettingDesc::IsSameValue
bool IsSameValue(const IniItem *item, void *object) const override
Check whether the value in the Ini item is the same as is saved in this setting in the object.
Definition: settings.cpp:813
SVS_NONE
@ SVS_NONE
Allow nothing and replace nothing.
Definition: string_type.h:45
IntSettingDesc::ParseValue
virtual size_t ParseValue(const char *str) const
Convert a string representation (external) of an integer-like setting to an integer.
Definition: settings.cpp:395
StringSettingDesc::Write
void Write(const void *object, const std::string &str) const
Write a string to the actual setting.
Definition: settings.cpp:606
IConsoleGetSetting
void IConsoleGetSetting(const char *name, bool force_newgame)
Output value of a specific setting to the console.
Definition: settings.cpp:1898
IniLoadFile::groups
std::list< IniGroup > groups
all groups in the ini
Definition: ini_type.h:53
network.h
CommandHelper
Definition: command_func.h:93
window_func.h
IniItem::name
std::string name
The name of this item.
Definition: ini_type.h:24
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:300
StringSettingDesc::def
std::string def
Default value given when none is present.
Definition: settings_internal.h:329
_network_ban_list
StringList _network_ban_list
The banned clients.
Definition: network.cpp:70
ClientSettings::network
NetworkSettings network
settings related to the network
Definition: settings_type.h:636
GRFIdentifier::grfid
uint32_t grfid
GRF ID (defined by Action 0x08)
Definition: newgrf_config.h:84
SaveVersionInConfig
static void SaveVersionInConfig(IniFile &ini)
Save the version of OpenTTD to the ini file.
Definition: settings.cpp:1218
SF_NOT_IN_SAVE
@ SF_NOT_IN_SAVE
Do not save with savegame, basically client-based.
Definition: settings_internal.h:27
GRFConfig::num_params
uint8_t num_params
Number of used parameters.
Definition: newgrf_config.h:168
ListSettingDesc::FormatValue
std::string FormatValue(const void *object) const override
Convert an integer-array (intlist) to a string representation.
Definition: settings.cpp:338
IntSettingDesc::post_callback
PostChangeCallback * post_callback
Callback when the setting has been changed.
Definition: settings_internal.h:220
config.h
GetCompanySettingFromName
static const SettingDesc * GetCompanySettingFromName(std::string_view name)
Given a name of setting, return a company setting description of it.
Definition: settings.cpp:1665
TimerGameConst< struct Calendar >::SECONDS_PER_DAY
static constexpr int SECONDS_PER_DAY
approximate seconds per day, not for precise calculations
Definition: timer_game_common.h:153
LinkGraphSettings::recalc_time
uint16_t recalc_time
time (in days) for recalculating each link graph component.
Definition: settings_type.h:567
ListSettingDesc::IsDefaultValue
bool IsDefaultValue(void *object) const override
Check whether the value is the same as the default value.
Definition: settings.cpp:819
GetGameSettings
GameSettings & GetGameSettings()
Get the settings-object applicable for the current situation: the newgame settings when we're in the ...
Definition: settings_type.h:659
ClientSettings::company
CompanySettings company
default values for per-company settings
Definition: settings_type.h:637
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:328
SaveLoad::length
uint16_t length
(Conditional) length of the variable (eg. arrays) (max array size is 65536 elements).
Definition: saveload.h:701
BaseMedia< GraphicsSet >::GetUsedSet
static const GraphicsSet * GetUsedSet()
Return the used set.
Definition: base_media_func.h:394
FGCM_EXACT
@ FGCM_EXACT
Only find Grfs matching md5sum.
Definition: newgrf_config.h:192
SF_GUI_DROPDOWN
@ SF_GUI_DROPDOWN
The value represents a limited number of string-options (internally integer) presented as dropdown.
Definition: settings_internal.h:19
Clamp
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:79
IntSettingDesc::IsDefaultValue
bool IsDefaultValue(void *object) const override
Check whether the value is the same as the default value.
Definition: settings.cpp:765
SettingDesc::IsIntSetting
virtual bool IsIntSetting() const
Check whether this setting is an integer type setting.
Definition: settings_internal.h:96
_network_host_list
StringList _network_host_list
The servers we know.
Definition: network.cpp:69
console_func.h
IFV_RIGHT_CLICK_CLOSE
@ IFV_RIGHT_CLICK_CLOSE
6 PR#10204 Add alternative right click to close windows setting.
Definition: settings.cpp:164
_config_file
std::string _config_file
Configuration file of OpenTTD.
Definition: settings.cpp:58
WC_ERRMSG
@ WC_ERRMSG
Error message; Window numbers:
Definition: window_type.h:110
CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY
static const uint CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY
Value for custom sea level in difficulty settings.
Definition: genworld.h:47
SF_PER_COMPANY
@ SF_PER_COMPANY
This setting can be different for each company (saved in company struct).
Definition: settings_internal.h:26
IniLoadFile::LoadFromDisk
void LoadFromDisk(const std::string &filename, Subdirectory subdir)
Load the Ini file's data from the disk.
Definition: ini_load.cpp:187
StringSettingDesc::IsDefaultValue
bool IsDefaultValue(void *object) const override
Check whether the value is the same as the default value.
Definition: settings.cpp:802
IFV_PRIVATE_SECRETS
@ IFV_PRIVATE_SECRETS
1 PR#9298 Moving of settings from openttd.cfg to private.cfg / secrets.cfg.
Definition: settings.cpp:158
Company
Definition: company_base.h:129
game_config.hpp
SetWindowClassesDirty
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
Definition: window.cpp:3112
FindGRFConfig
const GRFConfig * FindGRFConfig(uint32_t grfid, FindGRFConfigMode mode, const MD5Hash *md5sum, uint32_t desired_version)
Find a NewGRF in the scanned list.
Definition: newgrf_config.cpp:690
FillGRFDetails
bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir)
Find the GRFID of a given grf, and calculate its md5sum.
Definition: newgrf_config.cpp:324
ini_type.h
_settings_error_list
static ErrorList _settings_error_list
Errors while loading minimal settings.
Definition: settings.cpp:62
LoadFromConfig
void LoadFromConfig(bool startup)
Load the values from the configuration files.
Definition: settings.cpp:1369
GraphicsSet
All data of a graphics set.
Definition: base_media_base.h:260
SaveGRFPresetToConfig
void SaveGRFPresetToConfig(const char *config_name, GRFConfig *config)
Save a NewGRF configuration with a preset name.
Definition: settings.cpp:1567
DebugReconsiderSendRemoteMessages
void DebugReconsiderSendRemoteMessages()
Reconsider whether we need to send debug messages to either NetworkAdminConsole or IConsolePrint.
Definition: debug.cpp:268
network_func.h
GetSaveLoadFromSettingTable
void GetSaveLoadFromSettingTable(SettingTable settings, std::vector< SaveLoad > &saveloads)
Get the SaveLoad for all settings in the settings table.
Definition: settings.cpp:1650
INIFILE_VERSION
const uint16_t INIFILE_VERSION
Current ini-file version of OpenTTD.
Definition: settings.cpp:170
GUISettings::right_click_wnd_close
RightClickClose right_click_wnd_close
close window with right click
Definition: settings_type.h:172
ScriptConfig::HasScript
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
Definition: script_config.cpp:126
IsConversionNeeded
bool IsConversionNeeded(const ConfigIniFile &ini, const std::string &group, const std::string &old_var, const std::string &new_var, const IniItem **old_item)
Check whether a conversion should be done, and based on what old setting information.
Definition: settings.cpp:1341
LoadIntList
static bool LoadIntList(const char *str, void *array, int nelems, VarType type)
Load parsed string-values into an integer-array (intlist)
Definition: settings.cpp:293
WriteValue
void WriteValue(void *ptr, VarType conv, int64_t val)
Write the value of a setting.
Definition: saveload.cpp:815
_settings_newgame
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
Definition: settings.cpp:56
GCF_STATIC
@ GCF_STATIC
GRF file is used statically (can be used in any MP game)
Definition: newgrf_config.h:25
OneOfManySettingDesc::ParseSingleValue
static size_t ParseSingleValue(const char *str, size_t len, const std::vector< std::string > &many)
Find the index value of a ONEofMANY type in a string separated by |.
Definition: settings.cpp:179
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:635
WL_CRITICAL
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
Definition: error.h:27
debug.h
_grfconfig_newgame
GRFConfig * _grfconfig_newgame
First item in list of default GRF set up.
Definition: newgrf_config.cpp:165
IFV_MAX_VERSION
@ IFV_MAX_VERSION
Highest possible ini-file version.
Definition: settings.cpp:167
SettingDesc::AsIntSetting
const struct IntSettingDesc * AsIntSetting() const
Get the setting description of this setting as an integer setting.
Definition: settings.cpp:926
ai_config.hpp
ScriptConfig::GetName
const std::string & GetName() const
Get the name of the Script.
Definition: script_config.cpp:131
SF_NOT_IN_CONFIG
@ SF_NOT_IN_CONFIG
Do not save to config file.
Definition: settings_internal.h:28
IConsolePrint
void IConsolePrint(TextColour colour_code, const std::string &string)
Handle the printing of text entered into the console or redirected there by any other means.
Definition: console.cpp:91
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103