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

Allow to pass arguments for scripts to run before and after a game is launched #3691

Closed
casasfernando opened this issue Apr 9, 2024 · 5 comments
Labels
feature-request New feature needs to be implemented.

Comments

@casasfernando
Copy link
Contributor

casasfernando commented Apr 9, 2024

Problem description

I need to use a pre-launch/post-exit scripts (#3565 - #2507) with my games to be able to do some work for the games to run correctly in my environment and then clean up after the game exits.
At the moment is only possible to select the pre-launch/post-exit script but I couldn't find a way to also pass some arguments to the scripts, like the game name or game prefix path, or any other arbitrary one.
Without this I will have to keep separate scripts for each game since all would require a little twist specific to the game.

Feature description

I would like to be able to pass arguments to the scripts so I can only have on pre-launch and one post-launch or even just one script that can run differently accordingly to the arguments passed that would be different if the script is executed before launching the game or after it exits.
In terms of implementation it can be something similar to what Windows does with shortcuts, that means full script path in double quotes, followed by arguments. E.g.: "/path/to/pre-launch/script.sh" arg0 arg1 argX
Another, I think better, option would be to have something similar to the wrapper command in the same settings page, where there are two fields: wrapper and arguments. In this case it would be script and arguments.

Alternatives

I tried to check if the application is passing any game related information in the environment variables or default arguments when running the scripts but it doesn't.
Having some information through environment variables or even default arguments, containing the game name and/or the game prefix path would be a nice to have.

Additional information

No response

@casasfernando casasfernando added the feature-request New feature needs to be implemented. label Apr 9, 2024
@casasfernando
Copy link
Contributor Author

casasfernando commented May 11, 2024

I've looked into the code and came up with the following patch to pass some additional useful information (game title and executable path) to the pre/post launch script using environment variables. It gets the job done and it is a very small code change that will add more possibilities and convenience for the scripts (e.g: using only one script for several different games and execute different actions depending on the game title or executable file):

diff --git a/src/backend/launcher.ts b/src/backend/launcher.ts
index 2835cfff..5f7f8ad1 100644
--- a/src/backend/launcher.ts
+++ b/src/backend/launcher.ts
@@ -1368,7 +1368,9 @@ async function runScriptForGame(
   scriptPath: string
 ): Promise<boolean | string> {
   return new Promise((resolve, reject) => {
-    const child = spawn(scriptPath, { cwd: gameInfo.install.install_path })
+    var scriptEnv = { GAMEINFO_TITLE: gameInfo.title , GAMEINFO_EXEC: gameInfo.install.executable };
+    Object.assign(scriptEnv, process.env);
+    const child = spawn(scriptPath, { cwd: gameInfo.install.install_path , env: scriptEnv })
 
     child.stdout.on('data', (data) => {
       appendGamePlayLog(gameInfo, data.toString())

This wouldn't fulfill the feature request completely but it's a good step forward.
Would you be interested in a PR?

Thanks

@OlegAckbar
Copy link

@casasfernando I have the same issue and I would be interested in such PR.

@casasfernando
Copy link
Contributor Author

I will submit this and hopefully it will get approved and merged.
Fingers crossed.

@Morbiuzx
Copy link

I would like to be able to pass arguments to the scripts

I would like that too, in my case I made a script to record the screen or activate an instant replay feature depending on the argument I pass to it, this works nice in lutris or steam, but whenever I try to pass an argument to a script in heroic it stays in "launching" forever.

@arielj
Copy link
Collaborator

arielj commented Aug 11, 2024

this was included in the 2.15.0 release

@arielj arielj closed this as completed Aug 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature needs to be implemented.
Projects
None yet
Development

No branches or pull requests

4 participants