Seregon/ShadPKG

A tool for deriving PKG packet encryption keys for ps4 written in c++

C++/47.3 KB/No license
common/config.cpp
ShadPKG / common / config.cpp
1// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3 
4#include <cassert>
5#include <fstream>
6#include <string>
7#include <fmt/core.h>
8#include <fmt/xchar.h> // for wstring support
9 
10#include "common/path_util.h"
11#include "config.h"
12#include "logging/formatter.h"
13#include "version.h"
14 
15namespace Config {
16 
17static bool isNeo = false;
18static bool isFullscreen = false;
19static std::string fullscreenMode = "borderless";
20static bool playBGM = false;
21static bool isTrophyPopupDisabled = false;
22static int BGMvolume = 50;
23static bool enableDiscordRPC = false;
24static u32 screenWidth = 1280;
25static u32 screenHeight = 720;
26static s32 gpuId = -1; // Vulkan physical device index. Set to negative for auto select
27static std::string logFilter;
28static std::string logType = "async";
29static std::string userName = "shadPS4";
30static std::string updateChannel;
31static std::string chooseHomeTab;
32static u16 deadZoneLeft = 2.0;
33static u16 deadZoneRight = 2.0;
34static std::string backButtonBehavior = "left";
35static bool useSpecialPad = false;
36static int specialPadClass = 1;
37static bool isMotionControlsEnabled = true;
38static bool isDebugDump = false;
39static bool isShaderDebug = false;
40static bool isShowSplash = false;
41static bool isAutoUpdate = false;
42static bool isNullGpu = false;
43static bool shouldCopyGPUBuffers = false;
44static bool shouldDumpShaders = false;
45static bool shouldPatchShaders = true;
46static u32 vblankDivider = 1;
47static bool vkValidation = false;
48static bool vkValidationSync = false;
49static bool vkValidationGpu = false;
50static bool vkCrashDiagnostic = false;
51static bool vkHostMarkers = false;
52static bool vkGuestMarkers = false;
53static bool rdocEnable = false;
54static s16 cursorState = HideCursorState::Idle;
55static int cursorHideTimeout = 5; // 5 seconds (default)
56static bool separateupdatefolder = false;
57static bool compatibilityData = false;
58static bool checkCompatibilityOnStartup = false;
59static std::string trophyKey;
60 
61// Gui
62static bool load_game_size = true;
63std::vector<std::filesystem::path> settings_install_dirs = {};
64std::filesystem::path settings_addon_install_dir = {};
65std::filesystem::path save_data_path = {};
66u32 main_window_geometry_x = 400;
67u32 main_window_geometry_y = 400;
68u32 main_window_geometry_w = 1280;
69u32 main_window_geometry_h = 720;
70u32 mw_themes = 0;
71u32 m_icon_size = 36;
72u32 m_icon_size_grid = 69;
73u32 m_slider_pos = 0;
74u32 m_slider_pos_grid = 0;
75u32 m_table_mode = 0;
76u32 m_window_size_W = 1280;
77u32 m_window_size_H = 720;
78std::vector<std::string> m_pkg_viewer;
79std::vector<std::string> m_elf_viewer;
80std::vector<std::string> m_recent_files;
81std::string emulator_language = "en";
82 
83// Language
84u32 m_language = 1; // english
85 
86std::string getTrophyKey() {
87 return "";
88}
89 
90void setTrophyKey(std::string key) {
91 trophyKey = key;
92}
93 
94bool GetLoadGameSizeEnabled() {
95 return load_game_size;
96}
97 
98std::filesystem::path GetSaveDataPath() {
99 if (save_data_path.empty()) {
100 return Common::FS::GetUserPath(Common::FS::PathType::SaveDataDir);
101 }
102 return save_data_path;
103}
104 
105void setLoadGameSizeEnabled(bool enable) {
106 load_game_size = enable;
107}
108 
109bool isNeoModeConsole() {
110 return isNeo;
111}
112 
113bool getIsFullscreen() {
114 return isFullscreen;
115}
116 
117std::string getFullscreenMode() {
118 return fullscreenMode;
119}
120 
121bool getisTrophyPopupDisabled() {
122 return isTrophyPopupDisabled;
123}
124 
125bool getPlayBGM() {
126 return playBGM;
127}
128 
129int getBGMvolume() {
130 return BGMvolume;
131}
132 
133bool getEnableDiscordRPC() {
134 return enableDiscordRPC;
135}
136 
137u16 leftDeadZone() {
138 return deadZoneLeft;
139}
140 
141u16 rightDeadZone() {
142 return deadZoneRight;
143}
144 
145s16 getCursorState() {
146 return cursorState;
147}
148 
149int getCursorHideTimeout() {
150 return cursorHideTimeout;
151}
152 
153u32 getScreenWidth() {
154 return screenWidth;
155}
156 
157u32 getScreenHeight() {
158 return screenHeight;
159}
160 
161s32 getGpuId() {
162 return gpuId;
163}
164 
165std::string getLogFilter() {
166 return logFilter;
167}
168 
169std::string getLogType() {
170 return logType;
171}
172 
173std::string getUserName() {
174 return userName;
175}
176 
177std::string getUpdateChannel() {
178 return updateChannel;
179}
180 
181std::string getChooseHomeTab() {
182 return chooseHomeTab;
183}
184 
185std::string getBackButtonBehavior() {
186 return backButtonBehavior;
187}
188 
189bool getUseSpecialPad() {
190 return useSpecialPad;
191}
192 
193int getSpecialPadClass() {
194 return specialPadClass;
195}
196 
197bool getIsMotionControlsEnabled() {
198 return isMotionControlsEnabled;
199}
200 
201bool debugDump() {
202 return isDebugDump;
203}
204 
205bool collectShadersForDebug() {
206 return isShaderDebug;
207}
208 
209bool showSplash() {
210 return isShowSplash;
211}
212 
213bool autoUpdate() {
214 return isAutoUpdate;
215}
216 
217bool nullGpu() {
218 return isNullGpu;
219}
220 
221bool copyGPUCmdBuffers() {
222 return shouldCopyGPUBuffers;
223}
224 
225bool dumpShaders() {
226 return shouldDumpShaders;
227}
228 
229bool patchShaders() {
230 return shouldPatchShaders;
231}
232 
233bool isRdocEnabled() {
234 return rdocEnable;
235}
236 
237u32 vblankDiv() {
238 return vblankDivider;
239}
240 
241bool vkValidationEnabled() {
242 return vkValidation;
243}
244 
245bool vkValidationSyncEnabled() {
246 return vkValidationSync;
247}
248 
249bool vkValidationGpuEnabled() {
250 return vkValidationGpu;
251}
252 
253bool getVkCrashDiagnosticEnabled() {
254 return vkCrashDiagnostic;
255}
256 
257bool getVkHostMarkersEnabled() {
258 return vkHostMarkers;
259}
260 
261bool getVkGuestMarkersEnabled() {
262 return vkGuestMarkers;
263}
264 
265void setVkCrashDiagnosticEnabled(bool enable) {
266 vkCrashDiagnostic = enable;
267}
268 
269void setVkHostMarkersEnabled(bool enable) {
270 vkHostMarkers = enable;
271}
272 
273void setVkGuestMarkersEnabled(bool enable) {
274 vkGuestMarkers = enable;
275}
276 
277bool getSeparateUpdateEnabled() {
278 return separateupdatefolder;
279}
280 
281bool getCompatibilityEnabled() {
282 return compatibilityData;
283}
284 
285bool getCheckCompatibilityOnStartup() {
286 return checkCompatibilityOnStartup;
287}
288 
289void setGpuId(s32 selectedGpuId) {
290 gpuId = selectedGpuId;
291}
292 
293void setScreenWidth(u32 width) {
294 screenWidth = width;
295}
296 
297void setScreenHeight(u32 height) {
298 screenHeight = height;
299}
300 
301void setDebugDump(bool enable) {
302 isDebugDump = enable;
303}
304 
305void setCollectShaderForDebug(bool enable) {
306 isShaderDebug = enable;
307}
308 
309void setShowSplash(bool enable) {
310 isShowSplash = enable;
311}
312 
313void setAutoUpdate(bool enable) {
314 isAutoUpdate = enable;
315}
316 
317void setNullGpu(bool enable) {
318 isNullGpu = enable;
319}
320 
321void setCopyGPUCmdBuffers(bool enable) {
322 shouldCopyGPUBuffers = enable;
323}
324 
325void setDumpShaders(bool enable) {
326 shouldDumpShaders = enable;
327}
328 
329void setVkValidation(bool enable) {
330 vkValidation = enable;
331}
332 
333void setVkSyncValidation(bool enable) {
334 vkValidationSync = enable;
335}
336 
337void setRdocEnabled(bool enable) {
338 rdocEnable = enable;
339}
340 
341void setVblankDiv(u32 value) {
342 vblankDivider = value;
343}
344 
345void setIsFullscreen(bool enable) {
346 isFullscreen = enable;
347}
348 
349void setFullscreenMode(std::string mode) {
350 fullscreenMode = mode;
351}
352 
353void setisTrophyPopupDisabled(bool disable) {
354 isTrophyPopupDisabled = disable;
355}
356 
357void setPlayBGM(bool enable) {
358 playBGM = enable;
359}
360 
361void setBGMvolume(int volume) {
362 BGMvolume = volume;
363}
364 
365void setEnableDiscordRPC(bool enable) {
366 enableDiscordRPC = enable;
367}
368 
369void setCursorState(s16 newCursorState) {
370 cursorState = newCursorState;
371}
372 
373void setCursorHideTimeout(int newcursorHideTimeout) {
374 cursorHideTimeout = newcursorHideTimeout;
375}
376 
377void setLanguage(u32 language) {
378 m_language = language;
379}
380 
381void setNeoMode(bool enable) {
382 isNeo = enable;
383}
384 
385void setLogType(const std::string& type) {
386 logType = type;
387}
388 
389void setLogFilter(const std::string& type) {
390 logFilter = type;
391}
392 
393void setUserName(const std::string& type) {
394 userName = type;
395}
396 
397void setUpdateChannel(const std::string& type) {
398 updateChannel = type;
399}
400void setChooseHomeTab(const std::string& type) {
401 chooseHomeTab = type;
402}
403 
404void setBackButtonBehavior(const std::string& type) {
405 backButtonBehavior = type;
406}
407 
408void setUseSpecialPad(bool use) {
409 useSpecialPad = use;
410}
411 
412void setSpecialPadClass(int type) {
413 specialPadClass = type;
414}
415 
416void setIsMotionControlsEnabled(bool use) {
417 isMotionControlsEnabled = use;
418}
419 
420void setSeparateUpdateEnabled(bool use) {
421 separateupdatefolder = use;
422}
423 
424void setCompatibilityEnabled(bool use) {
425 compatibilityData = use;
426}
427 
428void setCheckCompatibilityOnStartup(bool use) {
429 checkCompatibilityOnStartup = use;
430}
431 
432void setMainWindowGeometry(u32 x, u32 y, u32 w, u32 h) {
433 main_window_geometry_x = x;
434 main_window_geometry_y = y;
435 main_window_geometry_w = w;
436 main_window_geometry_h = h;
437}
438 
439bool addGameInstallDir(const std::filesystem::path& dir) {
440 if (std::find(settings_install_dirs.begin(), settings_install_dirs.end(), dir) ==
441 settings_install_dirs.end()) {
442 settings_install_dirs.push_back(dir);
443 return true;
444 }
445 return false;
446}
447 
448void removeGameInstallDir(const std::filesystem::path& dir) {
449 auto iterator = std::find(settings_install_dirs.begin(), settings_install_dirs.end(), dir);
450 if (iterator != settings_install_dirs.end()) {
451 settings_install_dirs.erase(iterator);
452 }
453}
454 
455void setAddonInstallDir(const std::filesystem::path& dir) {
456 settings_addon_install_dir = dir;
457}
458 
459void setMainWindowTheme(u32 theme) {
460 mw_themes = theme;
461}
462 
463void setIconSize(u32 size) {
464 m_icon_size = size;
465}
466 
467void setIconSizeGrid(u32 size) {
468 m_icon_size_grid = size;
469}
470 
471void setSliderPosition(u32 pos) {
472 m_slider_pos = pos;
473}
474 
475void setSliderPositionGrid(u32 pos) {
476 m_slider_pos_grid = pos;
477}
478 
479void setTableMode(u32 mode) {
480 m_table_mode = mode;
481}
482 
483void setMainWindowWidth(u32 width) {
484 m_window_size_W = width;
485}
486 
487void setMainWindowHeight(u32 height) {
488 m_window_size_H = height;
489}
490 
491void setPkgViewer(const std::vector<std::string>& pkgList) {
492 m_pkg_viewer.resize(pkgList.size());
493 m_pkg_viewer = pkgList;
494}
495 
496void setElfViewer(const std::vector<std::string>& elfList) {
497 m_elf_viewer.resize(elfList.size());
498 m_elf_viewer = elfList;
499}
500 
501void setRecentFiles(const std::vector<std::string>& recentFiles) {
502 m_recent_files.resize(recentFiles.size());
503 m_recent_files = recentFiles;
504}
505 
506void setEmulatorLanguage(std::string language) {
507 emulator_language = language;
508}
509 
510void setGameInstallDirs(const std::vector<std::filesystem::path>& settings_install_dirs_config) {
511 settings_install_dirs = settings_install_dirs_config;
512}
513 
514void setSaveDataPath(const std::filesystem::path& path) {
515 save_data_path = path;
516}
517 
518u32 getMainWindowGeometryX() {
519 return main_window_geometry_x;
520}
521 
522u32 getMainWindowGeometryY() {
523 return main_window_geometry_y;
524}
525 
526u32 getMainWindowGeometryW() {
527 return main_window_geometry_w;
528}
529 
530u32 getMainWindowGeometryH() {
531 return main_window_geometry_h;
532}
533 
534const std::vector<std::filesystem::path>& getGameInstallDirs() {
535 return settings_install_dirs;
536}
537 
538std::filesystem::path getAddonInstallDir() {
539 if (settings_addon_install_dir.empty()) {
540 // Default for users without a config file or a config file from before this option existed
541 return Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "addcont";
542 }
543 return settings_addon_install_dir;
544}
545 
546u32 getMainWindowTheme() {
547 return mw_themes;
548}
549 
550u32 getIconSize() {
551 return m_icon_size;
552}
553 
554u32 getIconSizeGrid() {
555 return m_icon_size_grid;
556}
557 
558u32 getSliderPosition() {
559 return m_slider_pos;
560}
561 
562u32 getSliderPositionGrid() {
563 return m_slider_pos_grid;
564}
565 
566u32 getTableMode() {
567 return m_table_mode;
568}
569 
570u32 getMainWindowWidth() {
571 return m_window_size_W;
572}
573 
574u32 getMainWindowHeight() {
575 return m_window_size_H;
576}
577 
578std::vector<std::string> getPkgViewer() {
579 return m_pkg_viewer;
580}
581 
582std::vector<std::string> getElfViewer() {
583 return m_elf_viewer;
584}
585 
586std::vector<std::string> getRecentFiles() {
587 return m_recent_files;
588}
589 
590std::string getEmulatorLanguage() {
591 return emulator_language;
592}
593 
594u32 GetLanguage() {
595 return m_language;
596}
597 
598void setDefaultValues() {
599 isNeo = false;
600 isFullscreen = false;
601 isTrophyPopupDisabled = false;
602 playBGM = false;
603 BGMvolume = 50;
604 enableDiscordRPC = true;
605 screenWidth = 1280;
606 screenHeight = 720;
607 logFilter = "";
608 logType = "async";
609 userName = "shadPS4";
610 if (Common::isRelease) {
611 updateChannel = "Release";
612 } else {
613 updateChannel = "Nightly";
614 }
615 chooseHomeTab = "General";
616 cursorState = HideCursorState::Idle;
617 cursorHideTimeout = 5;
618 backButtonBehavior = "left";
619 useSpecialPad = false;
620 specialPadClass = 1;
621 isDebugDump = false;
622 isShaderDebug = false;
623 isShowSplash = false;
624 isAutoUpdate = false;
625 isNullGpu = false;
626 shouldDumpShaders = false;
627 vblankDivider = 1;
628 vkValidation = false;
629 vkValidationSync = false;
630 vkValidationGpu = false;
631 vkCrashDiagnostic = false;
632 vkHostMarkers = false;
633 vkGuestMarkers = false;
634 rdocEnable = false;
635 emulator_language = "en";
636 m_language = 1;
637 gpuId = -1;
638 separateupdatefolder = false;
639 compatibilityData = false;
640 checkCompatibilityOnStartup = false;
641}
642 
643} // namespace Config