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

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

kalaposfos13
Copy link
Contributor

@kalaposfos13 kalaposfos13 commented Jan 12, 2025

Syntax: shadps4 <options> <game> -- <game arg 1> <game arg 2> ...
Works for both SDL and Qt versions, but there's no GUI for it.
You can pass up to 32 arguments to a game (untested)
Tested with Knack 2 (needs only one argument): ./build/shadps4 CUSA08014 -- "-w=10 -cursoroff -region=a -2160p"

@ngoquang2708
Copy link
Contributor

There is a common pattern used in Linux, that everything after a -- get passed to the child/guest app.

@kalaposfos13
Copy link
Contributor Author

Now the above example looks like this:
./build/shadps4 CUSA08014 -- "-w=10 -cursoroff -region=a -2160p"
The automatic "last argument is the game" still works, but now it is the last argument before --, if there are game arguments. I can't verify that multiple arguments work, as I don't have a game that uses that that I also inspected with Ghidra.

@ngoquang2708
Copy link
Contributor

It should not have the double quote though. But that seem hard to do.

@kalaposfos13
Copy link
Contributor Author

The quotes are intentional, the game expects one string argument with all the options in it. If there weren't quotes, they would be split into multiple arguments, of which the game will ignore all but the first one.

@ArjixWasTaken
Copy link

I suggest updating the description of the PR.

@Foul-Tarnished
Copy link

Does Knack actually accept a custom resolution as an argument and use it ?

Is there any documented games launch arguments ?

@ngoquang2708
Copy link
Contributor

This doesn't work with -g or --game:

bash$ ./Shadps4-sdl.AppImage -f true --game CUSA03173 -- "abc"
Unknown argument: --, see --help for info.

If you use -- without passing args for game, it will crash:

bash$ ./Shadps4-sdl.AppImage -f true --game CUSA03173 -- 
terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string: construction from null is not valid
Aborted (core dumped)

@kalaposfos13
Copy link
Contributor Author

kalaposfos13 commented Jan 13, 2025

@ngoquang2708 The above errors have been fixed.
Tested with:
./build/shadps4 -g CUSA03173 -- abc def
and
./build/shadps4 -g CUSA03173 --

src/main.cpp Outdated
@@ -37,6 +38,10 @@ int main(int argc, char* argv[]) {
std::cout << "Usage: shadps4 [options] <elf or eboot.bin path>\n"
"Options:\n"
" -g, --game <path|ID> Specify game path to launch\n"
" -ga, --game-with-arg <path|ID> <arg>\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not needed anymore.

@ngoquang2708
Copy link
Contributor

Look in to this, I think we can do it better by extract CLI parsing logic to a common file share between Qt and CLI versions. In the future, we can easily port it to use boost 's program_options. But that should be left for another PR I suppose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants