Replace -ga with --; increase max argument count to 32; and add logging

This commit is contained in:
kalaposfos13 2025-01-12 13:50:17 +01:00
parent b328641f81
commit 439db029d3
6 changed files with 50 additions and 45 deletions

View File

@ -52,7 +52,7 @@ Linker::Linker() : memory{Memory::Instance()} {}
Linker::~Linker() = default; Linker::~Linker() = default;
void Linker::Execute(const std::string arg) { void Linker::Execute(const std::vector<std::string> args) {
if (Config::debugDump()) { if (Config::debugDump()) {
DebugDump(); DebugDump();
} }
@ -101,7 +101,7 @@ void Linker::Execute(const std::string arg) {
memory->SetupMemoryRegions(fmem_size, use_extended_mem1, use_extended_mem2); memory->SetupMemoryRegions(fmem_size, use_extended_mem1, use_extended_mem2);
main_thread.Run([this, module, arg](std::stop_token) { main_thread.Run([this, module, args](std::stop_token) {
Common::SetCurrentThreadName("GAME_MainThread"); Common::SetCurrentThreadName("GAME_MainThread");
LoadSharedLibraries(); LoadSharedLibraries();
@ -109,9 +109,11 @@ void Linker::Execute(const std::string arg) {
EntryParams params{}; EntryParams params{};
params.argc = 1; params.argc = 1;
params.argv[0] = "eboot.bin"; params.argv[0] = "eboot.bin";
if (!arg.empty()) { if (!args.empty()) {
params.argc = 2; params.argc = args.size() + 1;
params.argv[1] = arg.c_str(); for (int i = 0; i < args.size() && i < 32; i++) {
params.argv[i + 1] = args[i].c_str();
}
} }
params.entry_addr = module->GetEntryAddress(); params.entry_addr = module->GetEntryAddress();
RunMainEntry(&params); RunMainEntry(&params);

View File

@ -49,7 +49,7 @@ class Linker;
struct EntryParams { struct EntryParams {
int argc; int argc;
u32 padding; u32 padding;
const char* argv[3]; const char* argv[32];
VAddr entry_addr; VAddr entry_addr;
}; };
@ -143,7 +143,7 @@ public:
void Relocate(Module* module); void Relocate(Module* module);
bool Resolve(const std::string& name, Loader::SymbolType type, Module* module, bool Resolve(const std::string& name, Loader::SymbolType type, Module* module,
Loader::SymbolRecord* return_info); Loader::SymbolRecord* return_info);
void Execute(const std::string arg = ""); void Execute(const std::vector<std::string> args = std::vector<std::string>());
void DebugDump(); void DebugDump();
private: private:

View File

@ -98,7 +98,7 @@ Emulator::~Emulator() {
Config::saveMainWindow(config_dir / "config.toml"); Config::saveMainWindow(config_dir / "config.toml");
} }
void Emulator::Run(const std::filesystem::path& file, const std::string arg) { void Emulator::Run(const std::filesystem::path& file, const std::vector<std::string> args) {
// Applications expect to be run from /app0 so mount the file's parent path as app0. // Applications expect to be run from /app0 so mount the file's parent path as app0.
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance(); auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
const auto game_folder = file.parent_path(); const auto game_folder = file.parent_path();
@ -151,6 +151,15 @@ void Emulator::Run(const std::filesystem::path& file, const std::string arg) {
if (const auto raw_attributes = param_sfo->GetInteger("ATTRIBUTE")) { if (const auto raw_attributes = param_sfo->GetInteger("ATTRIBUTE")) {
psf_attributes.raw = *raw_attributes; psf_attributes.raw = *raw_attributes;
} }
if (!args.empty()) {
int argc = args.size() > 32 ? 32 : args.size();
for (int i = 0; i < argc; i++) {
LOG_INFO(Loader, "Game argument {}: {}", i, args[i]);
}
if (args.size() > 32) {
LOG_ERROR(Loader, "Too many game arguments, only passing the first 32");
}
}
} }
const auto pic1_path = mnt->GetHostPath("/app0/sce_sys/pic1.png"); const auto pic1_path = mnt->GetHostPath("/app0/sce_sys/pic1.png");
@ -238,7 +247,7 @@ void Emulator::Run(const std::filesystem::path& file, const std::string arg) {
} }
#endif #endif
linker->Execute(arg); linker->Execute(args);
window->InitTimers(); window->InitTimers();
while (window->IsOpen()) { while (window->IsOpen()) {

View File

@ -25,7 +25,8 @@ public:
Emulator(); Emulator();
~Emulator(); ~Emulator();
void Run(const std::filesystem::path& file, const std::string arg = ""); void Run(const std::filesystem::path& file,
const std::vector<std::string> args = std::vector<std::string>());
void UpdatePlayTime(const std::string& serial); void UpdatePlayTime(const std::string& serial);
private: private:

View File

@ -29,7 +29,7 @@ int main(int argc, char* argv[]) {
bool has_game_argument = false; bool has_game_argument = false;
std::string game_path; std::string game_path;
std::string game_arg; 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 = {
@ -39,8 +39,9 @@ int main(int argc, char* argv[]) {
"Options:\n" "Options:\n"
" -g, --game <path|ID> Specify game path to launch\n" " -g, --game <path|ID> Specify game path to launch\n"
" -ga, --game-with-arg <path|ID> <arg>\n" " -ga, --game-with-arg <path|ID> <arg>\n"
" Run a game executable with one argument " " -- ... Parameters passed to the game ELF. "
"passed to it.\n" "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" " -p, --patch <patch_file> Apply specified patch file\n"
" -f, --fullscreen <true|false> Specify window initial fullscreen " " -f, --fullscreen <true|false> Specify window initial fullscreen "
"state. Does not overwrite the config file.\n" "state. Does not overwrite the config file.\n"
@ -62,19 +63,6 @@ int main(int argc, char* argv[]) {
}}, }},
{"--game", [&](int& i) { arg_map["-g"](i); }}, {"--game", [&](int& i) { arg_map["-g"](i); }},
{"-ga",
[&](int& i) {
if (i + 2 < argc) {
game_path = argv[++i];
game_arg = argv[++i];
has_game_argument = true;
} else {
std::cerr << "Error: Missing argument for -ga/--game-with-arg\n";
exit(1);
}
}},
{"--game-with-arg", [&](int& i) { arg_map["-ga"](i); }},
{"-p", {"-p",
[&](int& i) { [&](int& i) {
if (i + 1 < argc) { if (i + 1 < argc) {
@ -139,6 +127,15 @@ int main(int argc, char* argv[]) {
auto it = arg_map.find(cur_arg); auto it = arg_map.find(cur_arg);
if (it != arg_map.end()) { if (it != arg_map.end()) {
it->second(i); // Call the associated lambda function it->second(i); // Call the associated lambda function
} else if (std::string(argv[i + 1]) == "--") {
if (!has_game_argument) {
game_path = argv[i];
has_game_argument = true;
}
for (int j = i + 2; j < argc; j++) {
game_args.push_back(argv[j]);
}
break;
} else if (i == argc - 1 && !has_game_argument) { } else if (i == argc - 1 && !has_game_argument) {
// Assume the last argument is the game file if not specified via -g/--game // Assume the last argument is the game file if not specified via -g/--game
game_path = argv[i]; game_path = argv[i];
@ -183,7 +180,7 @@ int main(int argc, char* argv[]) {
// Run the emulator with the resolved eboot path // Run the emulator with the resolved eboot path
Core::Emulator emulator; Core::Emulator emulator;
emulator.Run(eboot_path, game_arg); emulator.Run(eboot_path, game_args);
return 0; return 0;
} }

View File

@ -33,7 +33,7 @@ int main(int argc, char* argv[]) {
bool has_command_line_argument = argc > 1; bool has_command_line_argument = argc > 1;
bool show_gui = false, has_game_argument = false; bool show_gui = false, has_game_argument = false;
std::string game_path; std::string game_path;
std::string game_arg = ""; 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 = {
@ -44,9 +44,9 @@ int main(int argc, char* argv[]) {
" No arguments: Opens the GUI.\n" " No arguments: Opens the GUI.\n"
" -g, --game <path|ID> Specify <eboot.bin or elf path> or " " -g, --game <path|ID> Specify <eboot.bin or elf path> or "
"<game ID (CUSAXXXXX)> to launch\n" "<game ID (CUSAXXXXX)> to launch\n"
" -ga, --game-with-arg <path|ID> <arg>\n" " -- ... Parameters passed to the game ELF. "
" Run a game executable with one argument " "Needs to be at the end of the line, and everything after \"--\" is a "
"passed to it.\n" "game argument.\n"
" -p, --patch <patch_file> Apply specified patch file\n" " -p, --patch <patch_file> Apply specified patch file\n"
" -s, --show-gui Show the GUI\n" " -s, --show-gui Show the GUI\n"
" -f, --fullscreen <true|false> Specify window initial fullscreen " " -f, --fullscreen <true|false> Specify window initial fullscreen "
@ -72,19 +72,6 @@ int main(int argc, char* argv[]) {
}}, }},
{"--game", [&](int& i) { arg_map["-g"](i); }}, {"--game", [&](int& i) { arg_map["-g"](i); }},
{"-ga",
[&](int& i) {
if (i + 2 < argc) {
game_path = argv[++i];
game_arg = argv[++i];
has_game_argument = true;
} else {
std::cerr << "Error: Missing argument for -ga/--game-with-arg\n";
exit(1);
}
}},
{"--game-with-arg", [&](int& i) { arg_map["-ga"](i); }},
{"-p", {"-p",
[&](int& i) { [&](int& i) {
if (i + 1 < argc) { if (i + 1 < argc) {
@ -144,6 +131,15 @@ int main(int argc, char* argv[]) {
auto it = arg_map.find(cur_arg); auto it = arg_map.find(cur_arg);
if (it != arg_map.end()) { if (it != arg_map.end()) {
it->second(i); // Call the associated lambda function it->second(i); // Call the associated lambda function
} else if (std::string(argv[i + 1]) == "--") {
if (!has_game_argument) {
game_path = argv[i];
has_game_argument = true;
}
for (int j = i + 2; j < argc; j++) {
game_args.push_back(argv[j]);
}
break;
} else if (i == argc - 1 && !has_game_argument) { } else if (i == argc - 1 && !has_game_argument) {
// Assume the last argument is the game file if not specified via -g/--game // Assume the last argument is the game file if not specified via -g/--game
game_path = argv[i]; game_path = argv[i];
@ -198,7 +194,7 @@ int main(int argc, char* argv[]) {
// Run the emulator with the resolved game path // Run the emulator with the resolved game path
Core::Emulator emulator; Core::Emulator emulator;
emulator.Run(game_file_path.string(), game_arg); emulator.Run(game_file_path.string(), game_args);
if (!show_gui) { if (!show_gui) {
return 0; // Exit after running the emulator without showing the GUI return 0; // Exit after running the emulator without showing the GUI
} }