Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing Config class to resolve isFullscreen flag from CLI arguments #1349

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
23 changes: 23 additions & 0 deletions src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static std::string logFilter;
static std::string logType = "async";
static std::string userName = "shadPS4";
static std::string updateChannel;
static std::string patchFile = "";
static std::string backButtonBehavior = "left";
static bool useSpecialPad = false;
static int specialPadClass = 1;
Expand Down Expand Up @@ -139,6 +140,10 @@ std::string getUpdateChannel() {
return updateChannel;
}

std::string getPatchFile() {
return patchFile;
}

std::string getBackButtonBehavior() {
return backButtonBehavior;
}
Expand Down Expand Up @@ -307,6 +312,10 @@ void setUpdateChannel(const std::string& type) {
updateChannel = type;
}

void setPatchFile(const std::string& fileName) {
patchFile = fileName;
}

void setBackButtonBehavior(const std::string& type) {
backButtonBehavior = type;
}
Expand Down Expand Up @@ -483,6 +492,7 @@ void load(const std::filesystem::path& path) {
}
isShowSplash = toml::find_or<bool>(general, "showSplash", true);
isAutoUpdate = toml::find_or<bool>(general, "autoUpdate", false);
backButtonBehavior = toml::find_or<std::string>(general, "backButtonBehavior", "left");
}

if (data.contains("Input")) {
Expand Down Expand Up @@ -565,6 +575,18 @@ void load(const std::filesystem::path& path) {
m_language = toml::find_or<int>(settings, "consoleLanguage", 1);
}
}

void loadArgs(int& argc, char* argv[]) {
for (int i = 0; i < argc; i++) {
const std::string arg = argv[i];
if (arg == "-p") {
patchFile = argv[i + 1];
} else if (arg == "-f" || arg == "--fullscreen") {
isFullscreen = true;
}
}
}

void save(const std::filesystem::path& path) {
toml::value data;

Expand Down Expand Up @@ -668,6 +690,7 @@ void setDefaultValues() {
} else {
updateChannel = "Nightly";
}
patchFile = "";
cursorState = HideCursorState::Idle;
cursorHideTimeout = 5;
backButtonBehavior = "left";
Expand Down
5 changes: 5 additions & 0 deletions src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum HideCursorState : s16 { Never, Idle, Always };

void load(const std::filesystem::path& path);
void save(const std::filesystem::path& path);
void loadArgs(int& argc, char* argv[]);

bool isNeoMode();
bool isFullscreenMode();
Expand All @@ -24,6 +25,8 @@ std::string getLogFilter();
std::string getLogType();
std::string getUserName();
std::string getUpdateChannel();
std::string getPatchFile();
std::string getBackButtonBehavior();

s16 getCursorState();
int getCursorHideTimeout();
Expand Down Expand Up @@ -62,6 +65,8 @@ void setLanguage(u32 language);
void setNeoMode(bool enable);
void setUserName(const std::string& type);
void setUpdateChannel(const std::string& type);
void setPatchFile(const std::string& fileName);
void setBackButtonBehavior(const std::string& type);

void setCursorState(s16 cursorState);
void setCursorHideTimeout(int newcursorHideTimeout);
Expand Down
10 changes: 9 additions & 1 deletion src/emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
#include "common/logging/log.h"
#ifdef ENABLE_QT_GUI
#include <QtCore>
#include "common/memory_patcher.h"
#endif
#include "common/assert.h"
#include "common/discord_rpc_handler.h"
#include "common/elf_info.h"
#include "common/memory_patcher.h"
#include "common/ntapi.h"
#include "common/path_util.h"
#include "common/polyfill_thread.h"
Expand Down Expand Up @@ -256,6 +256,14 @@ void Emulator::Run(const std::filesystem::path& file) {
std::exit(0);
}

void Emulator::Run(int& argc, char* argv[]) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is argc a reference?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I don't know. I'll pass by value instead

// Load config options from arguments
Config::loadArgs(argc, argv);
MemoryPatcher::patchFile = Config::getPatchFile();

this->Run(argv[1]);
}

void Emulator::LoadSystemModules(const std::filesystem::path& file) {
constexpr std::array<SysModules, 13> ModulesToLoad{
{{"libSceNgs2.sprx", &Libraries::Ngs2::RegisterlibSceNgs2},
Expand Down
1 change: 1 addition & 0 deletions src/emulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Emulator {
~Emulator();

void Run(const std::filesystem::path& file);
void Run(int& argc, char* argv[]);
void UpdatePlayTime(const std::string& serial);

private:
Expand Down
11 changes: 1 addition & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later

#include <fmt/core.h>
#include "common/memory_patcher.h"
#include "emulator.h"

#ifdef _WIN32
Expand All @@ -24,16 +23,8 @@ int main(int argc, char* argv[]) {
return -1;
}

for (int i = 0; i < argc; i++) {
std::string curArg = argv[i];
if (curArg == "-p") {
std::string patchFile = argv[i + 1];
MemoryPatcher::patchFile = patchFile;
}
}

Core::Emulator emulator;
emulator.Run(argv[1]);
emulator.Run(argc, argv);

return 0;
}
10 changes: 1 addition & 9 deletions src/qt_gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later

#include "common/config.h"
#include "common/memory_patcher.h"
#include "core/file_sys/fs.h"
#include "emulator.h"
#include "game_install_dialog.h"
Expand Down Expand Up @@ -45,14 +44,7 @@ int main(int argc, char* argv[]) {
// Check for command line arguments
if (has_command_line_argument) {
Core::Emulator emulator;
for (int i = 0; i < argc; i++) {
std::string curArg = argv[i];
if (curArg == "-p") {
std::string patchFile = argv[i + 1];
MemoryPatcher::patchFile = patchFile;
}
}
emulator.Run(argv[1]);
emulator.Run(argc, argv);
}

// Run the Qt application
Expand Down
Loading