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"
25 #include "control/C4PlayerControl.h"
26 
27 #define C4DEFAULT_FONT_NAME "Endeavour"
28 enum { CFG_MaxString  = 1024, CFG_MaxEditorMRU = 8 };
29 
30 class C4ConfigGeneral
31 {
32 public:
33 	enum { ConfigResetSafetyVal = 42 };
34 
35 	char Name[CFG_MaxString+1];
36 	char Language[CFG_MaxString+1]; // entered by user in frontend options (may contain comma separated list or long language descriptions)
37 	char LanguageEx[CFG_MaxString+1]; // full fallback list composed by frontend options (condensed comma separated list)
38 	char Participants[CFG_MaxString+1];
39 	int32_t  AlwaysDebug; // if set: turns on debugmode whenever engine is started
40 	int32_t  OpenScenarioInGameMode; // When the program arguments include a scenario path, open the game regularly
41 	char RXFontName[CFG_MaxString+1];
42 	int32_t  RXFontSize;
43 	char ConfigUserPath[CFG_MaxString + 1];
44 	StdStrBuf ScreenshotFolder;
45 	char MissionAccess[CFG_MaxString+1];
46 	int32_t FPS;
47 	int32_t DefRec;
48 	int32_t MMTimer;  // use multimedia-timers
49 	int32_t ScrollSmooth; // view movement smoothing
50 	int32_t ConfigResetSafety; // safety value: If this value is screwed, the config got corrupted and must be reset
51 	// Determined at run-time
52 	StdCopyStrBuf ExePath;
53 	StdCopyStrBuf TempPath;
54 	char UserDataPath[CFG_MaxString+1];
55 	char SystemDataPath[CFG_MaxString+1];
56 	char ScreenshotPath[CFG_MaxString+1];
57 	char TempUpdatePath[CFG_MaxString+1];
58 	bool GamepadEnabled;
59 	bool FirstStart;
60 	int32_t DebugRec;
61 	// if defined, the external file is used for debugrec writing. Otherwise read/check
62 	int32_t DebugRecWrite;
63 	// if defined, an external file is used for debugrec writing (replays only)
64 	char DebugRecExternalFile[_MAX_PATH+1];
65 
66 public:
67 	static int GetLanguageSequence(const char *strSource, char *strTarget);
68 	void DefaultLanguage();
69 	bool CreateSaveFolder(const char *strDirectory, const char *strLanguageTitle);
70 	void DeterminePaths();
71 	void CompileFunc(StdCompiler *pComp);
72 
73 private:
74 	struct
75 	{
76 		char PlayerPath[CFG_MaxString+1];
77 	} Adopt;
78 };
79 
80 class C4ConfigDeveloper
81 {
82 public:
83 	int32_t AutoFileReload;
84 	char TodoFilename[CFG_MaxString + 1];
85 	char AltTodoFilename[CFG_MaxString + 1];
86 	int32_t MaxScriptMRU; // maximum number of remembered elements in recently used scripts
87 	int32_t DebugShapeTextures; // if nonzero, show messages about loaded shape textures
88 	bool ShowHelp; // show help buttons and descriptions in editor
89 	char RecentlyEditedSzenarios[CFG_MaxEditorMRU][CFG_MaxString + 1];
90 	void CompileFunc(StdCompiler *pComp);
91 	void AddRecentlyEditedScenario(const char *fn);
92 };
93 
94 class C4ConfigGraphics
95 {
96 public:
97 	int32_t SplitscreenDividers;
98 	int32_t ShowStartupMessages;
99 	int32_t VerboseObjectLoading;
100 	int32_t MenuTransparency;
101 	int32_t UpperBoard;
102 	int32_t ShowClock;
103 	int32_t ResX,ResY;
104 	int32_t WindowX,WindowY;
105 	int32_t RefreshRate;	// monitor vertical refresh rate
106 	int32_t Windowed; // 0: fullscreen, 1: windowed, 2: fullscreen in game, windowed in menu
107 	int32_t ShowCrewNames; // show player name above clonks?
108 	int32_t ShowCrewCNames; // show clonk names above clonks?
109 	int32_t PXSGfx;     // show PXS-graphics (instead of sole pixels)
110 	int32_t Gamma; // gamma value
111 	int32_t Currency;   // default wealth symbolseb
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 *pComp);
121 };
122 
123 class C4ConfigSound
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 *pComp);
134 };
135 
136 class C4ConfigNetwork
137 {
138 public:
139 	int32_t ControlRate;
140 	int32_t ControlPreSend;
141 	int32_t Lobby;
142 	int32_t NoRuntimeJoin;
143 	int32_t NoReferenceRequest;
144 	int32_t MaxResSearchRecursion;
145 	char WorkPath[CFG_MaxString+1];
146 	ValidatedStdCopyStrBuf<C4InVal::VAL_Comment> Comment;
147 	int32_t MasterServerSignUp;
148 	int32_t MasterServerActive;
149 	int32_t MasterKeepPeriod;
150 	int32_t MasterReferencePeriod;
151 	int32_t LeagueServerSignUp;
152 	int32_t UseAlternateServer;
153 	int32_t PortTCP,PortUDP,PortDiscovery,PortRefServer;
154 	int32_t EnableUPnP;
155 	int32_t ControlMode;
156 	ValidatedStdCopyStrBuf<C4InVal::VAL_NameAllowEmpty> Nick;
157 	int32_t MaxLoadFileSize;
158 	char LastPassword[CFG_MaxString+1];
159 	char AlternateServerAddress[CFG_MaxString+1];
160 	char PuncherAddress[CFG_MaxString+1];
161 	StdCopyStrBuf LastLeagueServer, LastLeaguePlayerName, LastLeagueAccount, LastLeagueLoginToken;
162 #ifdef WITH_AUTOMATIC_UPDATE
163 	char UpdateServerAddress[CFG_MaxString+1];
164 	int32_t AutomaticUpdate;
165 	int32_t LastUpdateTime;
166 #endif
167 	int32_t AsyncMaxWait;
168 	int32_t PacketLogging;
169 public:
170 	void CompileFunc(StdCompiler *pComp);
171 	const char *GetLeagueServerAddress();
172 	void CheckPortsForCollisions();
173 	void SetLeagueLoginData(const char *szServer, const char *szPlayerName, const char *szAccount, const char *szLoginToken);
174 	bool GetLeagueLoginData(const char *szServer, const char *szPlayerName, StdStrBuf *pAccount, StdStrBuf *pLoginToken) const;
175 };
176 
177 class C4ConfigStartup
178 {
179 public:
180 	// config for do-not-show-this-msg-again-messages
181 	int32_t HideMsgGfxEngineChange;
182 	int32_t HideMsgGfxBitDepthChange;
183 	int32_t HideMsgMMTimerChange;
184 	int32_t HideMsgStartDedicated;
185 	int32_t HideMsgPlrTakeOver;
186 	int32_t HideMsgPlrNoTakeOver;
187 	int32_t HideMsgNoOfficialLeague;
188 	int32_t HideMsgIRCDangerous;
189 	int32_t AlphabeticalSorting; // if set, Folder.txt-sorting is ignored in scenario selection
190 	int32_t LastPortraitFolderIdx;
191 	void CompileFunc(StdCompiler *pComp);
192 };
193 
194 class C4ConfigLobby
195 {
196 public:
197 	int32_t CountdownTime;
198 	int32_t AllowPlayerSave; // whether save-to-disk function is enabled for player resources
199 	void CompileFunc(StdCompiler *pComp);
200 };
201 
202 class C4ConfigIRC
203 {
204 public:
205 	char Server[CFG_MaxString+1];
206 	char Nick[CFG_MaxString+1];
207 	char RealName[CFG_MaxString+1];
208 	char Channel[CFG_MaxString+1];
209 	void CompileFunc(StdCompiler *pComp);
210 	int32_t AllowAllChannels;
211 };
212 
213 const int C4ConfigMaxGamepads = 4;
214 
215 class C4ConfigGamepad
216 {
217 public:
218 	int32_t Button[C4MaxKey];
219 	uint32_t AxisMin[6], AxisMax[6];
220 	bool AxisCalibrated[6];
221 	void CompileFunc(StdCompiler *pComp, bool fButtonsOnly=false);
222 	void ResetButtons(); // reset all buttons to default
223 	void Reset(); // reset all buttons and axis calibration to default
224 };
225 
226 class C4ConfigControls
227 {
228 public:
229 	int32_t GamepadGuiControl;
230 	int32_t MouseAutoScroll; // auto scroll strength
231 	C4PlayerControlAssignmentSets UserSets;
232 
233 	void CompileFunc(StdCompiler *pComp);
234 	void ResetKeys(); // reset all keys to default
235 };
236 
237 class C4ConfigSecurity
238 {
239 public:
240 	char KeyPath[CFG_MaxString + 1]; // absolute path; environment variables are stored and only expanded upon evaluation
241 	int32_t WasRegistered;
242 	void CompileFunc(StdCompiler *pComp);
243 };
244 
245 class C4Config
246 {
247 public:
248 	C4Config();
249 	~C4Config();
250 public:
251 	C4ConfigGeneral   General;
252 	C4ConfigDeveloper Developer;
253 	C4ConfigGraphics  Graphics;
254 	C4ConfigSound     Sound;
255 	C4ConfigNetwork   Network;
256 	C4ConfigLobby     Lobby;
257 	C4ConfigIRC       IRC;
258 	C4ConfigGamepad   Gamepads[C4ConfigMaxGamepads];
259 	C4ConfigControls  Controls;
260 	C4ConfigStartup   Startup;
261 	C4ConfigSecurity  Security;
262 	bool fConfigLoaded; // true if config has been successfully loaded
263 	StdStrBuf ConfigFilename; // set for configs loaded from a nondefault config file
264 public:
265 	const char* GetSubkeyPath(const char *strSubkey);
266 	void Default();
267 	bool Save();
268 	bool Load(const char *szConfigFile = nullptr);
269 	bool Init();
270 	bool Registered();
271 	const char *AtExePath(const char *szFilename);
272 	const char *AtTempPath(const char *szFilename);
273 	const char *AtTempUpdatePath(const char *szFilename);
274 	const char *AtNetworkPath(const char *szFilename);
275 	const char *AtScreenshotPath(const char *szFilename);
276 	const char *AtUserDataPath(const char *szFilename);
277 	const char *AtUserDataRelativePath(const char *szFilename);
278 	const char *AtSystemDataPath(const char *szFilename);
279 	const char *AtSystemDataRelativePath(const char *szFilename);
280 	const char *AtRelativePath(const char *szFilename); // Returns ASDRP or AUDRP depending on location
GetRegistrationData(const char * strField)281 	const char *GetRegistrationData(const char* strField) { return ""; }
282 	void ForceRelativePath(StdStrBuf *sFilename); // try AtRelativePath; force GetC4Filename if not possible
283 	void CompileFunc(StdCompiler *pComp);
IsCorrupted()284 	bool IsCorrupted() { return (General.ConfigResetSafety != C4ConfigGeneral::ConfigResetSafetyVal) || !Graphics.ResX; }
285 	bool RemoveModule(const char *szPath, char *szModules);
286 	bool IsModule(const char *szPath, char *szModules);
287 	bool AddModule(const char *szPath, char *szModules);
288 	void GetConfigFileName(StdStrBuf &filename, const char *szConfigFile);
289 	void CleanupTempUpdateFolder();
290 	const char *MakeTempUpdateFolder();
291 
292 	static void ExpandEnvironmentVariables(char *strPath, size_t iMaxLen);
293 };
294 
295 extern C4Config Config;
296 
297 #endif // INC_C4Config
298