diablodiab / libretro-scummvm-backend

libretro backend for scummvm
6 stars 8 forks source link

The command line use in ScummVM Core does not allow to load a game configuration correctly #24

Open schmurtzm opened 2 years ago

schmurtzm commented 2 years ago

Hi,

Related to this discord conversation on ScummVM discord. I've discovered that if you use -p command arg then in many cases you can't load the config initially defined in the scummvm.ini thanks to the launcher UI of ScummVM.

To reproduce : you configure your keymaps for grim from the launcher / main Menu, then run it by command line -> your keymap is not applied.

Some explanations from the ScummVM dev community :

What you are describing is the difference bewteen game ID and target. The target is the name that is assigned to a game when it is added to ScummVM. If you add the same game twice it will have two different target names. You can see that name in the scummvm.ini file and in the ScummVM game options (confusingly labeled ID). The game ID on the other hand is a unique identifier for a game supported by ScummVM. For grim the game ID is grim:grim (the first grim being the engine name). The target can be anything (since the user can change it in the Game Options) but by default is grim-win for the Windows version. Both the game ID and the target can be used on the command line. But if you have added a game to ScummVM and changed some settings, only the target will use those settings. After all you could have added the game twice (same game ID but two different target names) with different settings. And in the case of the game ID, if it is not ambiguous (no game with the same ID in another engine) you can omit the engine name. So indeed both grim:grim and grim work. Also when using the target on the command line, you don't need to specify the path to the game files. But if you use the game ID, you need to also specify the path. On the other hand using the game ID works even if the game has not been added to ScummVM.

So the recommended way from ScummVM is to add the games in the launcher (it will populate scummvm.ini with targets) and then run games by command line with scummvm TargetName

For example with grim, after adding game from the launcher, your scummvm.ini contains this :

[grim-win]
description=Grim Fandango (Windows/English)
mute=false
check_gamedata=false
path=/mnt/SDCARD/SCUMMVM/GRIM
engineid=grim
gameid=grim
language=en
platform=windows
guioptions=sndNoMIDI gameOption1 gameOption2 lang_English

So to launch the game with by taking into account these settings, you must run it with the target in parameter : scummvm grim-win and not as expected (because this won't load your settings, since manually specifying a game via command line basically creates a "temporary target") scummvm -p /mnt/SDCARD/SCUMMVM/GRIM grim:grim

What I recommend it to create a new kind of core shortcut ".target" . For example "Grim_Fandango.target" which contain the text "grim-win". It could be easily parsed in the same way as the game ID before :


      else if (strstr(game->path, ".target") != NULL) {

         FILE * gamefile = fopen(game->path, "r");
         if (gamefile == NULL)
         {
            log_cb(RETRO_LOG_ERROR, "[scummvm] Failed to load given game file.\n");
            free(path);
            return false;
         }

         // Load the file data.
         char filedata[400];
         if (fgets(filedata, 400, gamefile) == NULL)
         {
            fclose(gamefile);
            log_cb(RETRO_LOG_ERROR, "[scummvm] Failed to load contents of game file.\n");
            free(path);
            return false;
         }

         // Create a command line parameters using -p and the game name.
         sprintf(buffer, " %s", filedata);
         fclose(gamefile);
         parse_command_params(buffer);
      }

This can be done from the launcher manually but as we use a core, it could be nice to add a core option to scan a folder and add all the game in the launcher automatically , for example :

      else if (strstr(game->path, ".scan") != NULL) {
         // Use auto-detect to launch the game from the given directory.
         sprintf(buffer, "-p \"%s\" -a --recursive", gamedir);
         parse_command_params(buffer);
      }

And then the shortcuts could be created automatically from the result of targets in the scummvm.ini file but it is another story ;)

schmurtzm commented 2 years ago

Implemented here : https://github.com/schmurtzm/libretro-scummvm-miyoo-backend/blob/main/libretro.cpp#L368

For now the scan of sub-directories can crash but the .target shortcut files works great.

schmurtzm commented 2 years ago

ScummVM command line documentation has been updated with more details, the commit : https://github.com/scummvm/scummvm/commit/8a8c00f0725a7c14580796ec9a1613cdcea9f0c3#diff-64f34d61912363d4043e21cce39314689b7adbf6dec090134b443c45a4daf996

And the readable new documentation : https://docs.scummvm.org/en/latest/advanced_topics/command_line.html

Thanks to the ScummVM team which is very reactive and involved ! :)

So it confirms that the best way for the core is to add all games in the Launcher UI and then launch games thanks to their target name.

schmurtzm commented 2 years ago

Here a script that I've created to import automatically the games from scummvm.ini in a front end like retroarch, emulatationstation...or Onion ;) https://github.com/OnionUI/Onion/blob/main/static/packages/Emu/SCUMM%20(ScummVM)/Emu/SCUMMVM/import_gamelist.sh

It just scan the scummvm.ini file and create .target files : very similar to .scummvm files but the core is running it in a different way.