Matoking / protontricks

A wrapper that does winetricks things for Proton enabled games, requires Winetricks.
GNU General Public License v3.0
1.66k stars 37 forks source link

Failed to run an additional exe while the game is running #133

Closed zainin closed 2 years ago

zainin commented 2 years ago

Describe the bug While running the game try to run another exe (for modding, tweaking the game etc). The command fails without any useful errors.

To Reproduce Steps to reproduce the behavior:

  1. Run a game (in this example Genesis Noir)
  2. After it's started run the tweak to enable ultrawide fix
    $ protontricks -v --no-bwrap -c 'wine /home/zainin/game-tweaks/Genesis\ Noir\ Ultrawide\ 1.1a.exe' 735290
    protontricks (INFO): Found Steam directory at /home/zainin/.steam/steam. You can also define Steam directory manually using $STEAM_DIR
    protontricks (INFO): Using default Steam Runtime at /home/zainin/.steam/root/ubuntu12_32/steam-runtime
    protontricks (INFO): WINETRICKS environment variable is not available. Searching from $PATH.
    protontricks (INFO): Found 2 Steam library folders
    protontricks (INFO): Skipping empty appmanifest /home/zainin/Steam/steamapps/appmanifest_212070.acf
    protontricks (INFO): Currently logged-in Steam user: thexsinner
    protontricks (INFO): Found 0 Steam shortcuts running using Steam compatibility tools
    protontricks (INFO): Found active compatibility tool: Proton 6.3
    protontricks (INFO): Active compatibility tool is a Proton installation
    protontricks (INFO): WINE environment variable is not available. Setting WINE environment variable to Proton bundled version
    protontricks (INFO): WINESERVER environment variable is not available. Setting WINESERVER environment variable to Proton bundled version
    protontricks (INFO): Using separately installed Steam Runtime: Steam Linux Runtime - Soldier
    protontricks (INFO): Created Steam Runtime Wine binary directory at /home/zainin/.cache/protontricks/proton/Proton 6.3/bin
    protontricks (INFO): Attempting to run command wine /home/zainin/game-tweaks/Genesis\ Noir\ Ultrawide\ 1.1a.exe
    $ echo $?
    248

    The exe doesn't start and Protontricks fails without any errors.

Expected behavior Additional exe starts without any issues.

System (please complete the following information):

Additional context

This used to work with the previous Proton version - I can't remember the exact version.

If I'm trying to run the exe without Protontricks it fails with this error on the current Proton version:

$ STEAM_COMPAT_DATA_PATH=/media/storage-ext/SteamLibrary/steamapps/compatdata/735290 /media/storage-ext/SteamLibrary/steamapps/common/Proton\ 6.3/proton run ~/game-tweaks/Genesis\ Noir\ Ultrawide\ 1.1a.exe
Traceback (most recent call last):
  File "/media/storage-ext/SteamLibrary/steamapps/common/Proton 6.3/proton", line 1288, in <module>
    g_session.init_session(sys.argv[1] != "runinprefix")
  File "/media/storage-ext/SteamLibrary/steamapps/common/Proton 6.3/proton", line 1100, in init_session
    g_compatdata.setup_prefix()
  File "/media/storage-ext/SteamLibrary/steamapps/common/Proton 6.3/proton", line 654, in setup_prefix
    steamdir = os.environ["STEAM_COMPAT_CLIENT_INSTALL_PATH"]
  File "/usr/lib/python3.10/os.py", line 679, in __getitem__
    raise KeyError(key) from None
KeyError: 'STEAM_COMPAT_CLIENT_INSTALL_PATH'

With STEAM_COMPAT_CLIENT_INSTALL_PATH=~/.steam set the exe starts as expected if I start it directly with Proton:

$ STEAM_COMPAT_CLIENT_INSTALL_PATH=~/.steam STEAM_COMPAT_DATA_PATH=/media/storage-ext/SteamLibrary/steamapps/compatdata/735290 /media/storage-ext/SteamLibrary/steamapps/common/Proton\ 6.3/proton run ~/game-tweaks/Genesis\ Noir\ Ultrawide\ 1.1a.exe

If I pass this variable to Protontricks it doesn't seem to make any difference.

Matoking commented 2 years ago

I can reproduce a crash when the game is already running and another EXE is launched at the same point, at which point it will crash with a floating point exception.

I was able to fix this at least to some degree by searching the system for an existing Proton process, checking what environment variables it has, and using the same values for WINEESYNC and WINEFSYNC to better replicate its runtime configuration. My guess is that otherwise communication with wineserver fails and causes the process to crash.

As a workaround, could you try whether the following works?

$ protontricks -c bash <appid>
$ # cd to the directory with the executable
$ WINEFSYNC=1 WINEESYNC=1 wine <exe path>

You might have to adjust both values depending on what your system uses. Here's how I searched for the environment variables:

$ ps aux | grep wineserver
$ # Get the PID for Proton's wineserver process, the second column in the output
$ xargs -0 -L1 -a /proc/<pid>/environ

You should be able to find WINEESYNC and WINEFSYNC on the list.


One solution would probably be for Protontricks to do automatically, but that might take some time to develop and have some problems of its own.

zainin commented 2 years ago

Well, that seems a bit obvious in hindsight - I used to run this with WINEESYNC=1 before and it stopped working after the system upgrade, which, surprise, brings fsync support. The latest Proton enables fsync automatically from what I've seen.

The workaround with running bash works fine.

In the end, on the latest kernel with fsync patches this command works as expected:

$ WINEFSYNC=1 protontricks --no-bwrap -c 'wine tweak.exe' <appid>

Before adding an automatic solution it might be a good idea to document these two variables, maybe even enable WINEFSYNC by default on the latest kernel?

And just in case someone else stumbles on this reports and wonders about the --no-bwrap option - in my experience it's required to use this option if the tweak you're using depends on modifying your game's memory.

Sorry for taking up your time with this report, I should've tested it properly first.

Matoking commented 2 years ago

Thanks for the report, there is an actual issue here that I hadn't found myself before this: Wine processes launched by Protontricks may crash due to not using the same configuration options as Steam. This also applies when the user has set custom launch options, as that is the usual place for disabling esync/fsync. Ideally, the user wouldn't need to apply the configuration in two different places.

The variables are not documented directly, but are instead set by the Proton launch script. In Proton 6.3 they're automatically set to 1, meaning either esync or fsync is always used if supported unless explicitly disabled. Protontricks could do the same, but the defaults might depend on the Proton version and be a headache to maintain, so I'll have to look into that first.

Copying a few environment variables from a running wineserver is a fairly generic solution by comparison, so I'll start with that. I've already done some work in the replicate_runtime branch, and I'll close this issue once I've merged that into master.