OpenClonk
C4Config.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* Game configuration as stored in registry */
19 
20 #ifndef INC_C4Config
21 #define INC_C4Config
22 
23 #include "config/C4Constants.h"
24 #include "lib/C4InputValidation.h"
26 
27 #define C4DEFAULT_FONT_NAME "Endeavour"
28 enum { CFG_MaxString = 1024, CFG_MaxEditorMRU = 8 };
29 
30 
32 {
33 public:
34  enum { ConfigResetSafetyVal = 42 };
35 
36  char Name[CFG_MaxString + 1];
37  char Language[CFG_MaxString + 1]; // entered by user in frontend options (may contain comma separated list or long language descriptions)
38  char LanguageEx[CFG_MaxString + 1]; // full fallback list composed by frontend options (condensed comma separated list)
40  int32_t AlwaysDebug; // if set: turns on debugmode whenever engine is started
41  int32_t OpenScenarioInGameMode; // When the program arguments include a scenario path, open the game regularly
43  int32_t RXFontSize;
48  int32_t FPS;
49  int32_t DefRec;
50  int32_t MMTimer; // use multimedia-timers
51  int32_t ScrollSmooth; // view movement smoothing
52  int32_t ConfigResetSafety; // safety value: If this value is screwed, the config got corrupted and must be reset
53  // Determined at run-time
62  bool FirstStart;
63  int32_t DebugRec; // if defined, the external file is used for debugrec writing. Otherwise read/check
64  int32_t DebugRecWrite; // if defined, an external file is used for debugrec writing (replays only)
66 
67 public:
68  static int GetLanguageSequence(const char *source, char *target);
69  void DefaultLanguage();
70  bool CreateSaveFolder(const char *directory, const char *language_title);
71  void DeterminePaths();
72  void CompileFunc(StdCompiler *compiler);
73 
74 private:
75  struct
76  {
77  char PlayerPath[CFG_MaxString + 1];
78  } Adopt;
79 };
80 
82 {
83 public:
84  int32_t AutoFileReload;
87  int32_t MaxScriptMRU; // maximum number of remembered elements in recently used scripts
88  int32_t DebugShapeTextures; // if nonzero, show messages about loaded shape textures
89  bool ShowHelp; // show help buttons and descriptions in editor
91  void CompileFunc(StdCompiler *compiler);
92  void AddRecentlyEditedScenario(const char *filename);
93 };
94 
96 {
97 public:
102  int32_t UpperBoard;
103  int32_t ShowClock;
104  int32_t ResX,ResY;
105  int32_t WindowX,WindowY;
106  int32_t RefreshRate; // monitor vertical refresh rate
107  int32_t Windowed; // 0: fullscreen, 1: windowed, 2: fullscreen in game, windowed in menu
108  int32_t ShowCrewNames; // show player name above clonks?
109  int32_t ShowCrewCNames; // show clonk names above clonks?
110  int32_t PXSGfx; // show PXS-graphics (instead of sole pixels)
111  int32_t Gamma; // gamma value
112  int32_t Monitor; // monitor index to play on
113  int32_t MaxRefreshDelay; // minimum time after which graphics should be refreshed (ms)
114  int32_t NoOffscreenBlits; // if set, all blits to non-primary-surfaces are emulated
115  int32_t MultiSampling; // multisampling samples
116  int32_t AutoFrameSkip; // if true, gfx frames are skipped when they would slow down the game
117  int32_t DebugOpenGL; // if true, enables OpenGL debugging
118  int32_t MouseCursorSize; // size in pixels
119 
120  void CompileFunc(StdCompiler *compiler);
121 };
122 
124 {
125 public:
126  int32_t RXSound;
127  int32_t RXMusic;
128  int32_t FEMusic;
129  int32_t FESamples;
130  int32_t Verbose; // show music files names
131  int32_t MusicVolume;
132  int32_t SoundVolume;
133  void CompileFunc(StdCompiler *compiler);
134 };
135 
137 {
138 public:
139  int32_t ControlRate;
140  int32_t ControlPreSend;
141  int32_t Lobby;
142  int32_t NoRuntimeJoin;
154  int32_t EnableUPnP;
155  int32_t ControlMode;
162  // For the mod database.
165 #ifdef WITH_AUTOMATIC_UPDATE
166  char UpdateServerAddress[CFG_MaxString+1];
167  int32_t AutomaticUpdate;
168  int32_t LastUpdateTime;
169 #endif
170  int32_t AsyncMaxWait;
171  int32_t PacketLogging;
172 public:
173  void CompileFunc(StdCompiler *compiler);
174  const char *GetLeagueServerAddress();
175  const char *GetModDatabaseServerAddress();
177  void SetLeagueLoginData(const char *server_name, const char *player_name, const char *account, const char *login_token);
178  bool GetLeagueLoginData(const char *server_name, const char *player_name, StdStrBuf *account, StdStrBuf *login_token) const;
179 };
180 
182 {
183 public:
184  // config for do-not-show-this-msg-again-messages
193  int32_t AlphabeticalSorting; // if set, Folder.txt-sorting is ignored in scenario selection
195  void CompileFunc(StdCompiler *compiler);
196 };
197 
199 {
200 public:
201  int32_t CountdownTime;
202  int32_t AllowPlayerSave; // whether save-to-disk function is enabled for player resources
203  void CompileFunc(StdCompiler *compiler);
204 };
205 
207 {
208 public:
210  char Nick[CFG_MaxString + 1];
213  void CompileFunc(StdCompiler *compiler);
215 };
216 
217 const int C4ConfigMaxGamepads = 4;
218 
220 {
221 public:
222  int32_t Button[C4MaxKey];
223  uint32_t AxisMin[6], AxisMax[6];
224  bool AxisCalibrated[6];
225  void CompileFunc(StdCompiler *compiler, bool buttons_only = false);
226  void ResetButtons(); // reset all buttons to default
227  void Reset(); // reset all buttons and axis calibration to default
228 };
229 
231 {
232 public:
234  int32_t MouseAutoScroll; // auto scroll strength
236 
237  void CompileFunc(StdCompiler *compiler);
238  void ResetKeys(); // reset all keys to default
239 };
240 
242 {
243 public:
244  char KeyPath[CFG_MaxString + 1]; // absolute path; environment variables are stored and only expanded upon evaluation
245  int32_t WasRegistered;
246  void CompileFunc(StdCompiler *compiler);
247 };
248 
249 class C4Config
250 {
251 public:
252  C4Config();
253  ~C4Config();
254 public:
266  bool ConfigLoaded; // true if config has been successfully loaded
267  StdStrBuf ConfigFilename; // set for configs loaded from a nondefault config file
268 public:
269  const char* GetSubkeyPath(const char *subkey);
270  void Default();
271  bool Save();
272  bool Load(const char *config_file = nullptr);
273  bool Init();
274  bool Registered();
275  const char *AtExePath(const char *filename);
276  const char *AtTempPath(const char *filename);
277  const char *AtTempUpdatePath(const char *filename);
278  const char *AtNetworkPath(const char *filename);
279  const char *AtScreenshotPath(const char *filename);
280  const char *AtUserDataPath(const char *filename);
281  const char *AtUserDataRelativePath(const char *filename);
282  const char *AtSystemDataPath(const char *filename);
283  const char *AtSystemDataRelativePath(const char *filename);
284  const char *AtRelativePath(const char *filename); // Returns ASDRP or AUDRP depending on location
285  const char *GetRegistrationData(const char* field) { return ""; }
286  void ForceRelativePath(StdStrBuf *filename); // try AtRelativePath; force GetC4Filename if not possible
287  void CompileFunc(StdCompiler *compiler);
289  bool RemoveModule(const char *path, char *modules);
290  bool IsModule(const char *path, char *modules);
291  bool AddModule(const char *path, char *modules);
292  void GetConfigFileName(StdStrBuf &filename, const char *config_file);
294  const char *MakeTempUpdateFolder();
295 
296  static void ExpandEnvironmentVariables(char *path, size_t max_length);
297 };
298 
299 extern C4Config Config;
300 
301 #endif // INC_C4Config
@ CFG_MaxEditorMRU
Definition: C4Config.h:28
@ CFG_MaxString
Definition: C4Config.h:28
const int C4ConfigMaxGamepads
Definition: C4Config.h:217
C4Config Config
Definition: C4Config.cpp:930
const int C4MaxKey
Definition: C4Constants.h:30
#define _MAX_PATH_LEN
int32_t MouseAutoScroll
Definition: C4Config.h:234
C4PlayerControlAssignmentSets UserSets
Definition: C4Config.h:235
int32_t GamepadGuiControl
Definition: C4Config.h:233
void CompileFunc(StdCompiler *compiler)
Definition: C4Config.cpp:269
char RecentlyEditedSzenarios[CFG_MaxEditorMRU][CFG_MaxString+1]
Definition: C4Config.h:90
void CompileFunc(StdCompiler *compiler)
Definition: C4Config.cpp:83
char AltTodoFilename[CFG_MaxString+1]
Definition: C4Config.h:86
void AddRecentlyEditedScenario(const char *filename)
Definition: C4Config.cpp:97
int32_t MaxScriptMRU
Definition: C4Config.h:87
int32_t AutoFileReload
Definition: C4Config.h:84
char TodoFilename[CFG_MaxString+1]
Definition: C4Config.h:85
int32_t DebugShapeTextures
Definition: C4Config.h:88
bool AxisCalibrated[6]
Definition: C4Config.h:224
void CompileFunc(StdCompiler *compiler, bool buttons_only=false)
Definition: C4Config.cpp:231
uint32_t AxisMax[6]
Definition: C4Config.h:223
uint32_t AxisMin[6]
Definition: C4Config.h:223
int32_t Button[C4MaxKey]
Definition: C4Config.h:222
void ResetButtons()
Definition: C4Config.cpp:257
StdCopyStrBuf ExePath
Definition: C4Config.h:54
char Participants[CFG_MaxString+1]
Definition: C4Config.h:39
char ConfigUserPath[CFG_MaxString+1]
Definition: C4Config.h:44
char SystemDataPath[CFG_MaxString+1]
Definition: C4Config.h:58
char Name[CFG_MaxString+1]
Definition: C4Config.h:36
int32_t ScrollSmooth
Definition: C4Config.h:51
StdStrBuf ScreenshotFolder
Definition: C4Config.h:45
StdCopyStrBuf TempPath
Definition: C4Config.h:55
char LanguageEx[CFG_MaxString+1]
Definition: C4Config.h:38
char DebugRecExternalFile[_MAX_PATH_LEN]
Definition: C4Config.h:65
@ ConfigResetSafetyVal
Definition: C4Config.h:34
void DeterminePaths()
Definition: C4Config.cpp:469
int32_t FPS
Definition: C4Config.h:48
char Language[CFG_MaxString+1]
Definition: C4Config.h:37
bool GamepadEnabled
Definition: C4Config.h:61
char UserDataPath[CFG_MaxString+1]
Definition: C4Config.h:56
void DefaultLanguage()
Definition: C4Config.cpp:774
int32_t DefRec
Definition: C4Config.h:49
void CompileFunc(StdCompiler *compiler)
Definition: C4Config.cpp:45
int32_t DebugRecWrite
Definition: C4Config.h:64
int32_t OpenScenarioInGameMode
Definition: C4Config.h:41
int32_t AlwaysDebug
Definition: C4Config.h:40
char TempUpdatePath[CFG_MaxString+1]
Definition: C4Config.h:60
int32_t ConfigResetSafety
Definition: C4Config.h:52
int32_t MMTimer
Definition: C4Config.h:50
char ModsDataPath[CFG_MaxString+1]
Definition: C4Config.h:57
StdStrBuf ModsFolder
Definition: C4Config.h:46
char MissionAccess[CFG_MaxString+1]
Definition: C4Config.h:47
int32_t DebugRec
Definition: C4Config.h:63
char RXFontName[CFG_MaxString+1]
Definition: C4Config.h:42
bool FirstStart
Definition: C4Config.h:62
bool CreateSaveFolder(const char *directory, const char *language_title)
Definition: C4Config.cpp:636
int32_t RXFontSize
Definition: C4Config.h:43
char ScreenshotPath[CFG_MaxString+1]
Definition: C4Config.h:59
static int GetLanguageSequence(const char *source, char *target)
Definition: C4Config.cpp:817
int32_t ResX
Definition: C4Config.h:104
int32_t Gamma
Definition: C4Config.h:111
int32_t ResY
Definition: C4Config.h:104
int32_t RefreshRate
Definition: C4Config.h:106
int32_t DebugOpenGL
Definition: C4Config.h:117
int32_t AutoFrameSkip
Definition: C4Config.h:116
int32_t WindowY
Definition: C4Config.h:105
int32_t VerboseObjectLoading
Definition: C4Config.h:100
int32_t WindowX
Definition: C4Config.h:105
int32_t MenuTransparency
Definition: C4Config.h:101
int32_t MultiSampling
Definition: C4Config.h:115
int32_t MaxRefreshDelay
Definition: C4Config.h:113
int32_t PXSGfx
Definition: C4Config.h:110
int32_t NoOffscreenBlits
Definition: C4Config.h:114
int32_t Windowed
Definition: C4Config.h:107
int32_t SplitscreenDividers
Definition: C4Config.h:98
void CompileFunc(StdCompiler *compiler)
Definition: C4Config.cpp:122
int32_t UpperBoard
Definition: C4Config.h:102
int32_t ShowCrewNames
Definition: C4Config.h:108
int32_t ShowStartupMessages
Definition: C4Config.h:99
int32_t ShowCrewCNames
Definition: C4Config.h:109
int32_t MouseCursorSize
Definition: C4Config.h:118
int32_t ShowClock
Definition: C4Config.h:103
int32_t Monitor
Definition: C4Config.h:112
const char * AtSystemDataRelativePath(const char *filename)
Definition: C4Config.cpp:735
const char * AtSystemDataPath(const char *filename)
Definition: C4Config.cpp:593
const char * GetRegistrationData(const char *field)
Definition: C4Config.h:285
C4ConfigGeneral General
Definition: C4Config.h:255
C4ConfigNetwork Network
Definition: C4Config.h:259
C4ConfigStartup Startup
Definition: C4Config.h:264
bool Registered()
Definition: C4Config.cpp:795
void ForceRelativePath(StdStrBuf *filename)
Definition: C4Config.cpp:751
bool AddModule(const char *path, char *modules)
Definition: C4Config.cpp:868
const char * AtRelativePath(const char *filename)
Definition: C4Config.cpp:741
bool IsModule(const char *path, char *modules)
Definition: C4Config.cpp:873
const char * AtExePath(const char *filename)
Definition: C4Config.cpp:579
bool IsCorrupted()
Definition: C4Config.h:288
void CleanupTempUpdateFolder()
Definition: C4Config.cpp:901
bool RemoveModule(const char *path, char *modules)
Definition: C4Config.cpp:878
C4ConfigIRC IRC
Definition: C4Config.h:261
const char * AtTempPath(const char *filename)
Definition: C4Config.cpp:600
const char * AtUserDataPath(const char *filename)
Definition: C4Config.cpp:586
C4ConfigGamepad Gamepads[C4ConfigMaxGamepads]
Definition: C4Config.h:262
const char * MakeTempUpdateFolder()
Definition: C4Config.cpp:911
bool Save()
Definition: C4Config.cpp:439
bool Init()
Definition: C4Config.cpp:801
const char * GetSubkeyPath(const char *subkey)
Definition: C4Config.cpp:806
C4ConfigSecurity Security
Definition: C4Config.h:265
const char * AtTempUpdatePath(const char *filename)
Definition: C4Config.cpp:922
C4ConfigLobby Lobby
Definition: C4Config.h:260
static void ExpandEnvironmentVariables(char *path, size_t max_length)
Definition: C4Config.cpp:883
C4ConfigControls Controls
Definition: C4Config.h:263
bool Load(const char *config_file=nullptr)
Definition: C4Config.cpp:327
void GetConfigFileName(StdStrBuf &filename, const char *config_file)
Definition: C4Config.cpp:303
const char * AtScreenshotPath(const char *filename)
Definition: C4Config.cpp:615
StdStrBuf ConfigFilename
Definition: C4Config.h:267
void Default()
Definition: C4Config.cpp:296
const char * AtUserDataRelativePath(const char *filename)
Definition: C4Config.cpp:729
const char * AtNetworkPath(const char *filename)
Definition: C4Config.cpp:607
C4ConfigDeveloper Developer
Definition: C4Config.h:256
bool ConfigLoaded
Definition: C4Config.h:266
C4ConfigGraphics Graphics
Definition: C4Config.h:257
void CompileFunc(StdCompiler *compiler)
Definition: C4Config.cpp:850
C4ConfigSound Sound
Definition: C4Config.h:258
int32_t AllowAllChannels
Definition: C4Config.h:214
char Channel[CFG_MaxString+1]
Definition: C4Config.h:212
void CompileFunc(StdCompiler *compiler)
Definition: C4Config.cpp:210
char Nick[CFG_MaxString+1]
Definition: C4Config.h:210
char RealName[CFG_MaxString+1]
Definition: C4Config.h:211
char Server[CFG_MaxString+1]
Definition: C4Config.h:209
void CompileFunc(StdCompiler *compiler)
Definition: C4Config.cpp:204
int32_t AllowPlayerSave
Definition: C4Config.h:202
int32_t CountdownTime
Definition: C4Config.h:201
int32_t MasterServerActive
Definition: C4Config.h:148
int32_t UseAlternateModDatabaseServer
Definition: C4Config.h:163
int32_t AsyncMaxWait
Definition: C4Config.h:170
void CompileFunc(StdCompiler *compiler)
Definition: C4Config.cpp:159
ValidatedStdCopyStrBuf< C4InVal::VAL_Comment > Comment
Definition: C4Config.h:146
char WorkPath[CFG_MaxString+1]
Definition: C4Config.h:145
bool GetLeagueLoginData(const char *server_name, const char *player_name, StdStrBuf *account, StdStrBuf *login_token) const
Definition: C4Config.cpp:712
int32_t MasterServerSignUp
Definition: C4Config.h:147
const char * GetModDatabaseServerAddress()
Definition: C4Config.cpp:675
int32_t MasterKeepPeriod
Definition: C4Config.h:149
int32_t MasterReferencePeriod
Definition: C4Config.h:150
StdCopyStrBuf LastLeagueServer
Definition: C4Config.h:161
int32_t MaxResSearchRecursion
Definition: C4Config.h:144
int32_t PortUDP
Definition: C4Config.h:153
StdCopyStrBuf LastLeagueLoginToken
Definition: C4Config.h:161
void CheckPortsForCollisions()
Definition: C4Config.cpp:685
int32_t MaxLoadFileSize
Definition: C4Config.h:157
const char * GetLeagueServerAddress()
Definition: C4Config.cpp:661
char AlternateModDatabaseServerAddress[CFG_MaxString+1]
Definition: C4Config.h:164
int32_t NoReferenceRequest
Definition: C4Config.h:143
char LastPassword[CFG_MaxString+1]
Definition: C4Config.h:158
int32_t ControlPreSend
Definition: C4Config.h:140
int32_t ControlRate
Definition: C4Config.h:139
void SetLeagueLoginData(const char *server_name, const char *player_name, const char *account, const char *login_token)
Definition: C4Config.cpp:702
int32_t PacketLogging
Definition: C4Config.h:171
int32_t EnableUPnP
Definition: C4Config.h:154
char PuncherAddress[CFG_MaxString+1]
Definition: C4Config.h:160
int32_t LeagueServerSignUp
Definition: C4Config.h:151
int32_t PortRefServer
Definition: C4Config.h:153
StdCopyStrBuf LastLeagueAccount
Definition: C4Config.h:161
int32_t PortDiscovery
Definition: C4Config.h:153
int32_t UseAlternateServer
Definition: C4Config.h:152
char AlternateServerAddress[CFG_MaxString+1]
Definition: C4Config.h:159
int32_t NoRuntimeJoin
Definition: C4Config.h:142
StdCopyStrBuf LastLeaguePlayerName
Definition: C4Config.h:161
ValidatedStdCopyStrBuf< C4InVal::VAL_NameAllowEmpty > Nick
Definition: C4Config.h:156
int32_t PortTCP
Definition: C4Config.h:153
int32_t ControlMode
Definition: C4Config.h:155
int32_t Lobby
Definition: C4Config.h:141
void CompileFunc(StdCompiler *compiler)
Definition: C4Config.cpp:219
char KeyPath[CFG_MaxString+1]
Definition: C4Config.h:244
int32_t WasRegistered
Definition: C4Config.h:245
int32_t RXSound
Definition: C4Config.h:126
int32_t FEMusic
Definition: C4Config.h:128
int32_t FESamples
Definition: C4Config.h:129
int32_t Verbose
Definition: C4Config.h:130
void CompileFunc(StdCompiler *compiler)
Definition: C4Config.cpp:148
int32_t SoundVolume
Definition: C4Config.h:132
int32_t MusicVolume
Definition: C4Config.h:131
int32_t RXMusic
Definition: C4Config.h:127
int32_t HideMsgStartDedicated
Definition: C4Config.h:188
int32_t HideMsgGfxBitDepthChange
Definition: C4Config.h:186
int32_t HideMsgIRCDangerous
Definition: C4Config.h:192
int32_t HideMsgPlrNoTakeOver
Definition: C4Config.h:190
int32_t AlphabeticalSorting
Definition: C4Config.h:193
int32_t LastPortraitFolderIdx
Definition: C4Config.h:194
int32_t HideMsgNoOfficialLeague
Definition: C4Config.h:191
int32_t HideMsgPlrTakeOver
Definition: C4Config.h:189
void CompileFunc(StdCompiler *compiler)
Definition: C4Config.cpp:836
int32_t HideMsgMMTimerChange
Definition: C4Config.h:187
int32_t HideMsgGfxEngineChange
Definition: C4Config.h:185