CLI: Add argument to pass an argument to the game (#2135)

This commit is contained in:
kalaposfos13 2025-01-18 13:21:08 +01:00 committed by GitHub
parent 1ea5f8f092
commit 3b92cd1c1a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 61 additions and 9 deletions

View file

@ -33,6 +33,7 @@ int main(int argc, char* argv[]) {
bool has_command_line_argument = argc > 1;
bool show_gui = false, has_game_argument = false;
std::string game_path;
std::vector<std::string> game_args{};
// Map of argument strings to lambda functions
std::unordered_map<std::string, std::function<void(int&)>> arg_map = {
@ -43,6 +44,9 @@ int main(int argc, char* argv[]) {
" No arguments: Opens the GUI.\n"
" -g, --game <path|ID> Specify <eboot.bin or elf path> or "
"<game ID (CUSAXXXXX)> to launch\n"
" -- ... Parameters passed to the game ELF. "
"Needs to be at the end of the line, and everything after \"--\" is a "
"game argument.\n"
" -p, --patch <patch_file> Apply specified patch file\n"
" -s, --show-gui Show the GUI\n"
" -f, --fullscreen <true|false> Specify window initial fullscreen "
@ -131,6 +135,20 @@ int main(int argc, char* argv[]) {
// Assume the last argument is the game file if not specified via -g/--game
game_path = argv[i];
has_game_argument = true;
} else if (std::string(argv[i]) == "--") {
if (i + 1 == argc) {
std::cerr << "Warning: -- is set, but no game arguments are added!\n";
break;
}
for (int j = i + 1; j < argc; j++) {
game_args.push_back(argv[j]);
}
break;
} else if (i + 1 < argc && std::string(argv[i + 1]) == "--") {
if (!has_game_argument) {
game_path = argv[i];
has_game_argument = true;
}
} else {
std::cerr << "Unknown argument: " << cur_arg << ", see --help for info.\n";
return 1;
@ -181,7 +199,7 @@ int main(int argc, char* argv[]) {
// Run the emulator with the resolved game path
Core::Emulator emulator;
emulator.Run(game_file_path.string());
emulator.Run(game_file_path.string(), game_args);
if (!show_gui) {
return 0; // Exit after running the emulator without showing the GUI
}