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

@ -99,7 +99,7 @@ Emulator::~Emulator() {
Config::saveMainWindow(config_dir / "config.toml");
}
void Emulator::Run(const std::filesystem::path& file) {
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.
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
const auto game_folder = file.parent_path();
@ -152,6 +152,15 @@ void Emulator::Run(const std::filesystem::path& file) {
if (const auto raw_attributes = param_sfo->GetInteger("ATTRIBUTE")) {
psf_attributes.raw = *raw_attributes;
}
if (!args.empty()) {
int argc = std::min<int>(args.size(), 32);
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");
@ -239,7 +248,7 @@ void Emulator::Run(const std::filesystem::path& file) {
}
#endif
linker->Execute();
linker->Execute(args);
window->InitTimers();
while (window->IsOpen()) {