1 // Copyright (c) 2012- PPSSPP Project.
2 
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0 or later versions.
6 
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 // GNU General Public License 2.0 for more details.
11 
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
14 
15 // Official git repository and contact information can be found at
16 // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17 
18 #pragma once
19 
20 #include <string>
21 #include <map>
22 #include <vector>
23 
24 #include "ppsspp_config.h"
25 
26 #include "Common/CommonTypes.h"
27 #include "Common/File/Path.h"
28 #include "Core/ConfigValues.h"
29 
30 extern const char *PPSSPP_GIT_VERSION;
31 
32 enum ChatPositions {
33 	BOTTOM_LEFT = 0,
34 	BOTTOM_CENTER = 1,
35 	BOTOM_RIGHT = 2,
36 	TOP_LEFT = 3,
37 	TOP_CENTER = 4,
38 	TOP_RIGHT = 5,
39 	CENTER_LEFT = 6,
40 	CENTER_RIGHT = 7,
41 };
42 
43 namespace http {
44 	class Download;
45 	class Downloader;
46 }
47 
48 struct UrlEncoder;
49 
50 struct ConfigTouchPos {
51 	float x;
52 	float y;
53 	float scale;
54 	// Note: Show is not used for all settings.
55 	bool show;
56 };
57 
58 struct ConfigCustomButton {
59 	uint64_t key;
60 	int image;
61 	int shape;
62 	bool toggle;
63 };
64 
65 struct Config {
66 public:
67 	Config();
68 	~Config();
69 
70 	// Whether to save the config on close.
71 	bool bSaveSettings;
72 	bool bFirstRun;
73 	bool bGameSpecific = false;
74 	bool bUpdatedInstanceCounter = false;
75 
76 	int iRunCount; // To be used to for example check for updates every 10 runs and things like that.
77 
78 	bool bAutoRun;  // start immediately
79 	bool bBrowse; // when opening the emulator, immediately show a file browser
80 
81 	// General
82 	bool bScreenshotsAsPNG;
83 	bool bUseFFV1;
84 	bool bDumpFrames;
85 	bool bDumpVideoOutput;
86 	bool bDumpAudio;
87 	bool bSaveLoadResetsAVdumping;
88 	bool bEnableLogging;
89 	bool bDumpDecryptedEboot;
90 	bool bFullscreenOnDoubleclick;
91 
92 	// These four are Win UI only
93 	bool bPauseOnLostFocus;
94 	bool bTopMost;
95 	bool bIgnoreWindowsKey;
96 	bool bRestartRequired;
97 
98 	std::string sFont;
99 
100 	bool bPauseWhenMinimized;
101 
102 	// Not used on mobile devices.
103 	bool bPauseExitsEmulator;
104 
105 	bool bPauseMenuExitsEmulator;
106 
107 	// Core
108 	bool bIgnoreBadMemAccess;
109 
110 	bool bFastMemory;
111 	int iCpuCore;
112 	bool bCheckForNewVersion;
113 	bool bForceLagSync;
114 	bool bFuncReplacements;
115 	bool bHideSlowWarnings;
116 	bool bHideStateWarnings;
117 	bool bPreloadFunctions;
118 	uint32_t uJitDisableFlags;
119 
120 	bool bSeparateSASThread;
121 	bool bSeparateIOThread;
122 	int iIOTimingMethod;
123 	int iLockedCPUSpeed;
124 	bool bAutoSaveSymbolMap;
125 	bool bCacheFullIsoInRam;
126 	int iRemoteISOPort;
127 	std::string sLastRemoteISOServer;
128 	int iLastRemoteISOPort;
129 	bool bRemoteISOManual;
130 	bool bRemoteShareOnStartup;
131 	std::string sRemoteISOSubdir;
132 	bool bRemoteDebuggerOnStartup;
133 	bool bMemStickInserted;
134 	int iMemStickSizeGB;
135 	bool bLoadPlugins;
136 
137 	int iScreenRotation;  // The rotation angle of the PPSSPP UI. Only supported on Android and possibly other mobile platforms.
138 	int iInternalScreenRotation;  // The internal screen rotation angle. Useful for vertical SHMUPs and similar.
139 
140 	std::string sReportHost;
141 	std::vector<std::string> recentIsos;
142 	std::vector<std::string> vPinnedPaths;
143 	std::string sLanguageIni;
144 
145 	bool bDiscordPresence;  // Enables setting the Discord presence to the current game (or menu)
146 
147 	// GFX
148 	int iGPUBackend;
149 	std::string sFailedGPUBackends;
150 	std::string sDisabledGPUBackends;
151 	// We have separate device parameters for each backend so it doesn't get erased if you switch backends.
152 	// If not set, will use the "best" device.
153 	std::string sVulkanDevice;
154 	std::string sD3D11Device;  // Windows only
155 	std::string sCameraDevice;
156 	std::string sMicDevice;
157 
158 	bool bSoftwareRendering;
159 	bool bHardwareTransform; // only used in the GLES backend
160 	bool bSoftwareSkinning;  // may speed up some games
161 	bool bVendorBugChecksEnabled;
162 
163 	int iRenderingMode; // 0 = non-buffered rendering 1 = buffered rendering
164 	int iTexFiltering; // 1 = auto , 2 = nearest , 3 = linear , 4 = auto max quality
165 	int iBufFilter; // 1 = linear, 2 = nearest
166 	int iSmallDisplayZoomType;  // Used to fit display into screen 0 = stretch, 1 = partial stretch, 2 = auto scaling, 3 = manual scaling.
167 	float fSmallDisplayOffsetX; // Along with Y it goes from 0.0 to 1.0, XY (0.5, 0.5) = center of the screen
168 	float fSmallDisplayOffsetY;
169 	float fSmallDisplayZoomLevel; //This is used for zoom values, both in and out.
170 	bool bImmersiveMode;  // Mode on Android Kitkat 4.4 that hides the back button etc.
171 	bool bSustainedPerformanceMode;  // Android: Slows clocks down to avoid overheating/speed fluctuations.
172 	bool bIgnoreScreenInsets;  // Android: Center screen disregarding insets if this is enabled.
173 	bool bVSync;
174 	int iFrameSkip;
175 	int iFrameSkipType;
176 	int iFastForwardMode; // See FastForwardMode in ConfigValues.h.
177 	bool bAutoFrameSkip;
178 
179 	bool bEnableCardboardVR; // Cardboard Master Switch
180 	int iCardboardScreenSize; // Screen Size (in %)
181 	int iCardboardXShift; // X-Shift of Screen (in %)
182 	int iCardboardYShift; // Y-Shift of Screen (in %)
183 
184 	int iWindowX;
185 	int iWindowY;
186 	int iWindowWidth;  // Windows and other windowed environments
187 	int iWindowHeight;
188 
189 	bool bVertexCache;
190 	bool bTextureBackoffCache;
191 	bool bTextureSecondaryCache;
192 	bool bVertexDecoderJit;
193 	bool bFullScreen;
194 	bool bFullScreenMulti;
195 	int iInternalResolution;  // 0 = Auto (native), 1 = 1x (480x272), 2 = 2x, 3 = 3x, 4 = 4x and so on.
196 	int iAnisotropyLevel;  // 0 - 5, powers of 2: 0 = 1x = no aniso
197 	int bHighQualityDepth;
198 	bool bReplaceTextures;
199 	bool bSaveNewTextures;
200 	bool bIgnoreTextureFilenames;
201 	int iTexScalingLevel; // 0 = auto, 1 = off, 2 = 2x, ..., 5 = 5x
202 	int iTexScalingType; // 0 = xBRZ, 1 = Hybrid
203 	bool bTexDeposterize;
204 	bool bTexHardwareScaling;
205 	int iFpsLimit1;
206 	int iFpsLimit2;
207 	int iMaxRecent;
208 	int iCurrentStateSlot;
209 	int iRewindFlipFrequency;
210 	bool bUISound;
211 	bool bEnableStateUndo;
212 	std::string sStateLoadUndoGame;
213 	std::string sStateUndoLastSaveGame;
214 	int iStateUndoLastSaveSlot;
215 	int iAutoLoadSaveState; // 0 = off, 1 = oldest, 2 = newest, >2 = slot number + 3
216 	bool bEnableCheats;
217 	bool bReloadCheats;
218 	int iCwCheatRefreshRate;
219 	float fCwCheatScrollPosition;
220 	float fGameListScrollPosition;
221 	int iBloomHack; //0 = off, 1 = safe, 2 = balanced, 3 = aggressive
222 	bool bBlockTransferGPU;
223 	bool bDisableSlowFramebufEffects;
224 	bool bFragmentTestCache;
225 	int iSplineBezierQuality; // 0 = low , 1 = Intermediate , 2 = High
226 	bool bHardwareTessellation;
227 
228 	std::vector<std::string> vPostShaderNames; // Off for chain end (only Off for no shader)
229 	std::map<std::string, float> mPostShaderSetting;
230 	bool bShaderChainRequires60FPS;
231 	std::string sTextureShaderName;
232 	bool bGfxDebugOutput;
233 	bool bGfxDebugSplitSubmit;
234 	int iInflightFrames;
235 	bool bRenderDuplicateFrames;
236 
237 	// Sound
238 	bool bEnableSound;
239 	int iAudioBackend;
240 	int iGlobalVolume;
241 	int iReverbVolume;
242 	int iAltSpeedVolume;
243 	bool bExtraAudioBuffering;  // For bluetooth
244 	std::string sAudioDevice;
245 	bool bAutoAudioDevice;
246 
247 	// UI
248 	bool bShowDebuggerOnLoad;
249 	int iShowFPSCounter;
250 	bool bShowRegionOnGameIcon;
251 	bool bShowIDOnGameIcon;
252 	float fGameGridScale;
253 	bool bShowOnScreenMessages;
254 	int iBackgroundAnimation;  // enum BackgroundAnimation
255 
256 	// TODO: Maybe move to a separate theme system.
257 	uint32_t uItemStyleFg;
258 	uint32_t uItemStyleBg;
259 	uint32_t uItemFocusedStyleFg;
260 	uint32_t uItemFocusedStyleBg;
261 	uint32_t uItemDownStyleFg;
262 	uint32_t uItemDownStyleBg;
263 	uint32_t uItemDisabledStyleFg;
264 	uint32_t uItemDisabledStyleBg;
265 	uint32_t uItemHighlightedStyleFg;
266 	uint32_t uItemHighlightedStyleBg;
267 
268 	uint32_t uButtonStyleFg;
269 	uint32_t uButtonStyleBg;
270 	uint32_t uButtonFocusedStyleFg;
271 	uint32_t uButtonFocusedStyleBg;
272 	uint32_t uButtonDownStyleFg;
273 	uint32_t uButtonDownStyleBg;
274 	uint32_t uButtonDisabledStyleFg;
275 	uint32_t uButtonDisabledStyleBg;
276 	uint32_t uButtonHighlightedStyleFg;
277 	uint32_t uButtonHighlightedStyleBg;
278 
279 	uint32_t uHeaderStyleFg;
280 	uint32_t uInfoStyleFg;
281 	uint32_t uInfoStyleBg;
282 	uint32_t uPopupTitleStyleFg;
283 	uint32_t uPopupStyleFg;
284 	uint32_t uPopupStyleBg;
285 
286 	bool bLogFrameDrops;
287 	bool bShowDebugStats;
288 	bool bShowAudioDebug;
289 	bool bShowGpuProfile;
290 
291 	//Analog stick tilting
292 	//the base x and y tilt. this inclination is treated as (0,0) and the tilt input
293 	//considers this orientation to be equal to no movement of the analog stick.
294 	float fTiltBaseX, fTiltBaseY;
295 	int iTiltOrientation;
296 	//whether the x axes and y axes should invert directions (left becomes right, top becomes bottom.)
297 	bool bInvertTiltX, bInvertTiltY;
298 	//the sensitivity of the tilt in the x direction
299 	int iTiltSensitivityX;
300 	//the sensitivity of the tilt in the Y direction
301 	int iTiltSensitivityY;
302 	//the deadzone radius of the tilt
303 	float fDeadzoneRadius;
304 	// deadzone skip
305 	float fTiltDeadzoneSkip;
306 	//type of tilt input currently selected: Defined in TiltEventProcessor.h
307 	//0 - no tilt, 1 - analog stick, 2 - D-Pad, 3 - Action Buttons (Tri, Cross, Square, Circle)
308 	int iTiltInputType;
309 
310 	// The three tabs.
311 	bool bGridView1;
312 	bool bGridView2;
313 	bool bGridView3;
314 
315 	// Right analog binding
316 	int iRightAnalogUp;
317 	int iRightAnalogDown;
318 	int iRightAnalogLeft;
319 	int iRightAnalogRight;
320 	int iRightAnalogPress;
321 	bool bRightAnalogCustom;
322 	bool bRightAnalogDisableDiagonal;
323 
324 	// Motion gesture controller
325 	bool bGestureControlEnabled;
326 	int iSwipeUp;
327 	int iSwipeDown;
328 	int iSwipeLeft;
329 	int iSwipeRight;
330 	float fSwipeSensitivity;
331 	float fSwipeSmoothing;
332 	int iDoubleTapGesture;
333 
334 	// Disable diagonals
335 	bool bDisableDpadDiagonals;
336 	bool bGamepadOnlyFocused;
337 	// Control Style
338 	int iTouchButtonStyle;
339 	int iTouchButtonOpacity;
340 	int iTouchButtonHideSeconds;
341 	// Auto rotation speed
342 	float fAnalogAutoRotSpeed;
343 
344 	// Snap touch control position
345 	bool bTouchSnapToGrid;
346 	int iTouchSnapGridSize;
347 
348 	// Floating analog stick (recenters on thumb on press).
349 	bool bAutoCenterTouchAnalog;
350 
351 	//space between PSP buttons
352 	//the PSP button's center (triangle, circle, square, cross)
353 	ConfigTouchPos touchActionButtonCenter;
354 	float fActionButtonSpacing;
355 	//radius of the D-pad (PSP cross)
356 	// int iDpadRadius;
357 	//the D-pad (PSP cross) position
358 	ConfigTouchPos touchDpad;
359 	float fDpadSpacing;
360 	ConfigTouchPos touchStartKey;
361 	ConfigTouchPos touchSelectKey;
362 	ConfigTouchPos touchFastForwardKey;
363 	ConfigTouchPos touchLKey;
364 	ConfigTouchPos touchRKey;
365 	ConfigTouchPos touchAnalogStick;
366 	ConfigTouchPos touchRightAnalogStick;
367 
368 	ConfigTouchPos touchCombo0;
369 	ConfigTouchPos touchCombo1;
370 	ConfigTouchPos touchCombo2;
371 	ConfigTouchPos touchCombo3;
372 	ConfigTouchPos touchCombo4;
373 	ConfigTouchPos touchCombo5;
374 	ConfigTouchPos touchCombo6;
375 	ConfigTouchPos touchCombo7;
376 	ConfigTouchPos touchCombo8;
377 	ConfigTouchPos touchCombo9;
378 
379 	float fLeftStickHeadScale;
380 	float fRightStickHeadScale;
381 	bool bHideStickBackground;
382 
383 	// Controls Visibility
384 	bool bShowTouchControls;
385 
386 	bool bShowTouchCircle;
387 	bool bShowTouchCross;
388 	bool bShowTouchTriangle;
389 	bool bShowTouchSquare;
390 
391 	ConfigCustomButton CustomKey0;
392 	ConfigCustomButton CustomKey1;
393 	ConfigCustomButton CustomKey2;
394 	ConfigCustomButton CustomKey3;
395 	ConfigCustomButton CustomKey4;
396 	ConfigCustomButton CustomKey5;
397 	ConfigCustomButton CustomKey6;
398 	ConfigCustomButton CustomKey7;
399 	ConfigCustomButton CustomKey8;
400 	ConfigCustomButton CustomKey9;
401 
402 	// Ignored on iOS and other platforms that lack pause.
403 	bool bShowTouchPause;
404 
405 	bool bHapticFeedback;
406 
407 	// We also use the XInput settings as analog settings on other platforms like Android.
408 	float fAnalogDeadzone;
409 	float fAnalogInverseDeadzone;
410 	float fAnalogSensitivity;
411 	// convert analog stick circle to square
412 	bool bAnalogIsCircular;
413 
414 
415 	float fAnalogLimiterDeadzone;
416 
417 	bool bMouseControl;
418 	bool bMapMouse; // Workaround for mapping screen:|
419 	bool bMouseConfine; // Trap inside the window.
420 	float fMouseSensitivity;
421 	float fMouseSmoothing;
422 
423 	bool bSystemControls;
424 
425 	// Use the hardware scaler to scale up the image to save fillrate. Similar to Windows' window size, really.
426 	int iAndroidHwScale;  // 0 = device resolution. 1 = 480x272 (extended to correct aspect), 2 = 960x544 etc.
427 
428 	// Risky JIT optimizations
429 	bool bDiscardRegsOnJRRA;
430 
431 	// SystemParam
432 	std::string sNickName;
433 	std::string sMACAddress;
434 	int iLanguage;
435 	int iTimeFormat;
436 	int iDateFormat;
437 	int iTimeZone;
438 	bool bDayLightSavings;
439 	int iButtonPreference;
440 	int iLockParentalLevel;
441 	bool bEncryptSave;
442 	bool bSavedataUpgrade;
443 
444 	// Networking
445 	std::string proAdhocServer;
446 	bool bEnableWlan;
447 	bool bEnableAdhocServer;
448 	bool bEnableUPnP;
449 	bool bUPnPUseOriginalPort;
450 	bool bForcedFirstConnect;
451 	int iPortOffset;
452 	int iMinTimeout;
453 	int iWlanAdhocChannel;
454 	bool bWlanPowerSave;
455 	bool bEnableNetworkChat;
456 	//for chat position , moveable buttons is better than this
457 	int iChatButtonPosition;
458 	int iChatScreenPosition;
459 
460 	bool bEnableQuickChat;
461 	std::string sQuickChat0;
462 	std::string sQuickChat1;
463 	std::string sQuickChat2;
464 	std::string sQuickChat3;
465 	std::string sQuickChat4;
466 
467 	int iPSPModel;
468 	int iFirmwareVersion;
469 	bool bBypassOSKWithKeyboard;
470 
471 	// Debugger
472 	int iDisasmWindowX;
473 	int iDisasmWindowY;
474 	int iDisasmWindowW;
475 	int iDisasmWindowH;
476 	int iGEWindowX;
477 	int iGEWindowY;
478 	int iGEWindowW;
479 	int iGEWindowH;
480 	int iConsoleWindowX;
481 	int iConsoleWindowY;
482 	int iFontWidth;
483 	int iFontHeight;
484 	bool bDisplayStatusBar;
485 	bool bShowBottomTabTitles;
486 	bool bShowDeveloperMenu;
487 	bool bShowAllocatorDebug;
488 	// Double edged sword: much easier debugging, but not accurate.
489 	bool bSkipDeadbeefFilling;
490 	bool bFuncHashMap;
491 	bool bDebugMemInfoDetailed;
492 	bool bDrawFrameGraph;
493 
494 	// Volatile development settings
495 	bool bShowFrameProfiler;
496 
497 	// Various directories. Autoconfigured, not read from ini.
498 	Path currentDirectory;  // The directory selected in the game browsing window.
499 	Path defaultCurrentDirectory;  // Platform dependent, initialized at startup.
500 
501 	Path memStickDirectory;
502 	Path flash0Directory;
503 	Path internalDataDirectory;
504 	Path appCacheDirectory;
505 
506 	// Data for upgrade prompt
507 	std::string upgradeMessage;  // The actual message from the server is currently not used, need a translation mechanism. So this just acts as a flag.
508 	std::string upgradeVersion;
509 	std::string dismissedVersion;
510 
511 	void Load(const char *iniFileName = nullptr, const char *controllerIniFilename = nullptr);
512 	bool Save(const char *saveReason);
513 	void Reload();
514 	void RestoreDefaults();
515 
516 	//per game config managment, should maybe be in it's own class
517 	void changeGameSpecific(const std::string &gameId = "", const std::string &title = "");
518 	bool createGameConfig(const std::string &game_id);
519 	bool deleteGameConfig(const std::string& pGameId);
520 	bool loadGameConfig(const std::string &game_id, const std::string &title);
521 	bool saveGameConfig(const std::string &pGameId, const std::string &title);
522 	void unloadGameConfig();
523 	Path getGameConfigFile(const std::string &gameId);
524 	bool hasGameConfig(const std::string &game_id);
525 
526 	void SetSearchPath(const Path &path);
527 	const Path FindConfigFile(const std::string &baseFilename);
528 
529 	void UpdateIniLocation(const char *iniFileName = nullptr, const char *controllerIniFilename = nullptr);
530 
531 	// Utility functions for "recent" management
532 	void AddRecent(const std::string &file);
533 	void RemoveRecent(const std::string &file);
534 	void CleanRecent();
535 
536 	static void DownloadCompletedCallback(http::Download &download);
537 	void DismissUpgrade();
538 
539 	void ResetControlLayout();
540 
541 	void GetReportingInfo(UrlEncoder &data);
542 
543 	bool IsPortrait() const;
544 	int NextValidBackend();
545 	bool IsBackendEnabled(GPUBackend backend, bool validate = true);
546 
547 protected:
548 	void LoadStandardControllerIni();
549 
550 private:
551 	bool reload_ = false;
552 	std::string gameId_;
553 	std::string gameIdTitle_;
554 	Path iniFilename_;
555 	Path controllerIniFilename_;
556 	Path searchPath_;
557 };
558 
559 std::map<std::string, std::pair<std::string, int>> GetLangValuesMapping();
560 std::string CreateRandMAC();
561 
562 // TODO: Find a better place for this.
563 extern http::Downloader g_DownloadManager;
564 extern Config g_Config;
565 
566