This commit is contained in:
georgemoralis 2025-06-12 11:59:46 +03:00
parent d81ae42b51
commit 1aa39e23c0

View File

@ -32,107 +32,109 @@ int main(int argc, char* argv[]) {
std::vector<std::string> game_args{}; std::vector<std::string> game_args{};
// Map of argument strings to lambda functions // Map of argument strings to lambda functions
std::unordered_map<std::string, std::function<void(int&)>> arg_map = std::unordered_map<std::string, std::function<void(int&)>> arg_map = {
{ {"-h", {"-h",
[&](int&) { [&](int&) {
std::cout << "Usage: shadps4 [options] <elf or eboot.bin path>\n" std::cout
"Options:\n" << "Usage: shadps4 [options] <elf or eboot.bin path>\n"
" -g, --game <path|ID> Specify game path to launch\n" "Options:\n"
" -- ... Parameters passed to the game ELF. " " -g, --game <path|ID> Specify game path to launch\n"
"Needs to be at the end of the line, and everything after \"--\" is a " " -- ... Parameters passed to the game ELF. "
"game argument.\n" "Needs to be at the end of the line, and everything after \"--\" is a "
" -p, --patch <patch_file> Apply specified patch file\n" "game argument.\n"
" -i, --ignore-game-patch Disable automatic loading of game patch\n" " -p, --patch <patch_file> Apply specified patch file\n"
" -f, --fullscreen <true|false> Specify window initial fullscreen " " -i, --ignore-game-patch Disable automatic loading of game patch\n"
"state. Does not overwrite the config file.\n" " -f, --fullscreen <true|false> Specify window initial fullscreen "
" --add-game-folder <folder> Adds a new game folder to the config.\n" "state. Does not overwrite the config file.\n"
" --set-addon-folder <folder> Sets the addon folder to the config.\n" " --add-game-folder <folder> Adds a new game folder to the config.\n"
" -h, --help Display this help message\n"; " --set-addon-folder <folder> Sets the addon folder to the config.\n"
exit(0); " -h, --help Display this help message\n";
}}, exit(0);
{"--help", [&](int& i) { arg_map["-h"](i); }}, }},
{"--help", [&](int& i) { arg_map["-h"](i); }},
{"-g", {"-g",
[&](int& i) { [&](int& i) {
if (i + 1 < argc) { if (i + 1 < argc) {
game_path = argv[++i]; game_path = argv[++i];
has_game_argument = true; has_game_argument = true;
} else { } else {
std::cerr << "Error: Missing argument for -g/--game\n"; std::cerr << "Error: Missing argument for -g/--game\n";
exit(1); exit(1);
} }
}}, }},
{"--game", [&](int& i) { arg_map["-g"](i); }}, {"--game", [&](int& i) { arg_map["-g"](i); }},
{"-p", {"-p",
[&](int& i) { [&](int& i) {
if (i + 1 < argc) { if (i + 1 < argc) {
MemoryPatcher::patchFile = argv[++i]; MemoryPatcher::patchFile = argv[++i];
} else { } else {
std::cerr << "Error: Missing argument for -p/--patch\n"; std::cerr << "Error: Missing argument for -p/--patch\n";
exit(1); exit(1);
} }
}}, }},
{"--patch", [&](int& i) { arg_map["-p"](i); }}, {"--patch", [&](int& i) { arg_map["-p"](i); }},
{"-i", [&](int&) { Core::FileSys::MntPoints::ignore_game_patches = true; }}, {"-i", [&](int&) { Core::FileSys::MntPoints::ignore_game_patches = true; }},
{"--ignore-game-patch", [&](int& i) { arg_map["-i"](i); }}, {"--ignore-game-patch", [&](int& i) { arg_map["-i"](i); }},
{"-f", {"-f",
[&](int& i) { [&](int& i) {
if (++i >= argc) { if (++i >= argc) {
std::cerr << "Error: Missing argument for -f/--fullscreen\n"; std::cerr << "Error: Missing argument for -f/--fullscreen\n";
exit(1); exit(1);
} }
std::string f_param(argv[i]); std::string f_param(argv[i]);
bool is_fullscreen; bool is_fullscreen;
if (f_param == "true") { if (f_param == "true") {
is_fullscreen = true; is_fullscreen = true;
} else if (f_param == "false") { } else if (f_param == "false") {
is_fullscreen = false; is_fullscreen = false;
} else { } else {
std::cerr << "Error: Invalid argument for -f/--fullscreen. Use 'true' or 'false'.\n"; std::cerr
exit(1); << "Error: Invalid argument for -f/--fullscreen. Use 'true' or 'false'.\n";
} exit(1);
// Set fullscreen mode without saving it to config file }
Config::setIsFullscreen(is_fullscreen); // Set fullscreen mode without saving it to config file
}}, Config::setIsFullscreen(is_fullscreen);
{"--fullscreen", [&](int& i) { arg_map["-f"](i); }}, }},
{"--add-game-folder", {"--fullscreen", [&](int& i) { arg_map["-f"](i); }},
[&](int& i) { {"--add-game-folder",
if (++i >= argc) { [&](int& i) {
std::cerr << "Error: Missing argument for --add-game-folder\n"; if (++i >= argc) {
exit(1); std::cerr << "Error: Missing argument for --add-game-folder\n";
} exit(1);
std::string config_dir(argv[i]); }
std::filesystem::path config_path = std::filesystem::path(config_dir); std::string config_dir(argv[i]);
std::error_code discard; std::filesystem::path config_path = std::filesystem::path(config_dir);
if (!std::filesystem::exists(config_path, discard)) { std::error_code discard;
std::cerr << "Error: File does not exist: " << config_path << "\n"; if (!std::filesystem::exists(config_path, discard)) {
exit(1); std::cerr << "Error: File does not exist: " << config_path << "\n";
} exit(1);
}
Config::addGameInstallDir(config_path); Config::addGameInstallDir(config_path);
Config::save(Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "config.toml"); Config::save(Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "config.toml");
std::cout << "Game folder successfully saved.\n"; std::cout << "Game folder successfully saved.\n";
exit(0); exit(0);
}, }},
{"--set-addon-folder", [&](int& i) { {"--set-addon-folder", [&](int& i) {
if (++i >= argc) { if (++i >= argc) {
std::cerr << "Error: Missing argument for --add-addon-folder\n"; std::cerr << "Error: Missing argument for --add-addon-folder\n";
exit(1); exit(1);
} }
std::string config_dir(argv[i]); std::string config_dir(argv[i]);
std::filesystem::path config_path = std::filesystem::path(config_dir); std::filesystem::path config_path = std::filesystem::path(config_dir);
std::error_code discard; std::error_code discard;
if (!std::filesystem::exists(config_path, discard)) { if (!std::filesystem::exists(config_path, discard)) {
std::cerr << "Error: File does not exist: " << config_path << "\n"; std::cerr << "Error: File does not exist: " << config_path << "\n";
exit(1); exit(1);
} }
Config::setAddonInstallDir(config_path); Config::setAddonInstallDir(config_path);
Config::save(Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "config.toml"); Config::save(Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "config.toml");
std::cout << "Addon folder successfully saved.\n"; std::cout << "Addon folder successfully saved.\n";
exit(0); exit(0);
}}; }}};
if (argc == 1) { if (argc == 1) {
int dummy = 0; // one does not simply pass 0 directly int dummy = 0; // one does not simply pass 0 directly